ABAP Development for Materials Management in SAP (第1页)

第 1 页 / 共 275 页

第 2 页 / 共 275 页

SAP® Essentials

Expert SAP knowledge for your day-to-day work

Whether you wish to expand your SAP knowledge, deepen it, or master a use

case, SAP Essentials provide you with targeted expert knowledge that helps sup-

port you in your day-to-day work. To the point, detailed, and ready to use.

SAP PRESS is a joint initiative of SAP and Galileo Press. The know-how offered by

SAP specialists combined with the expertise of the Galileo Press publishing house

offers the reader expert books in the field. SAP PRESS features first-hand informa-

tion and expert advice, and provides useful skills for professional decision-making.

SAP PRESS offers a variety of books on technical and business related topics for

the SAP user. For further information, please visit our website:

http://www.sap-press.com.

Martina Kaplan, Christian Oehler

Implementing SAP Enhancement Packages

2010, app. 220 pp.

978-1-59229-351-3

Michael Englbrecht, Michael Wegelin

SAP Interface Programming

2009, app. 405 pp.

978-1-59229-318-6

Harald Röser

SAP Controls Workshop: SAP PRESS Essentials 10

2005, app. 165 pp.

978-1-59229-073-4

Horst Keller

The Official ABAP Reference

2nd ed. 2005, app. 1,213 pp.

978-1-59229-039-0

第 3 页 / 共 275 页

Jürgen Schwaninger

ABAP™ Development for Materials

Management in SAP®: User Exits and BAdIs

Bonn (cid:31) Boston

第 4 页 / 共 275 页

Dear Reader,

Since the days of R/3, programmers have had the option to enhance and optimize

the SAP standard with individual and unique ABAP programs. However, it is no

longer enough to have the skills to implement a requirement in ABAP, especially

in a comprehensive functionality such as Materials Management in SAP ERP.

Programmers must take their education further by understanding how and where

to find the correct user exit for each project.

In his daily work, Jürgen Schwaninger is an SAP consultant and deals with the most

frequently made customer queries regarding user exits. Based on his amount of

experience, he knows the tried-and-tested solutions for these complex problems,

and has carefully selected the most helpful and concise examples from his repertoire,

which you can directly apply to your daily work. Not only does this book provide

helpful real-life tutorials, which show you the precise procedures and the respective

codings to achieve a solution, along with possible alternatives, this book also

provides you with systematic access to all user exits, BAdIs, and enhancement spots

in MM.

We welcome you to share any praise or critical comments that will help us improve

our books. Our number one goal is to provide accurate and useful information

to benefit you, the reader, and to improve and expand your skills. We encourage

you to visit our website at www.sap-press.com and share your feedback about this

work.

Thank you for purchasing a book from SAP PRESS!

Laura Korslund

Editor, SAP PRESS

Galileo Press

Boston, MA

laura.korslund@galileo-press.com

www.sap-press.com

第 5 页 / 共 275 页

Notes on Usage

This e-book is protected by copyright. By purchasing this e-book, you have agreed

to accept and adhere to the copyrights. You are entitled to use this e-book for

personal purposes. You may print and copy it, too, but also only for personal use.

Sharing an electronic or printed copy with others, however, is not permitted, neither

as a whole nor in parts. Of course, making them available on the Internet or in a

company network is illegal as well.

For detailed and legally binding usage conditions, please refer to the section Legal

Notes.

This e-book copy contains a digital watermark, a signature that indicates which

person may use this copy:

Copy No. t5bd-zshf-xrg2-43jm

for personal use of

Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618

第 6 页 / 共 275 页

Imprint

This e-book is a publication many contributed to, specifically:

Editor Stefan Proksch

English Edition Editor Laura Korslund

Translation Lemoine International, Inc., Salt Lake City, UT

Copyeditor Julie McNamee

Cover Design Graham Geary

Photo Credit iStockphoto.com/ValentynVolkov

Production E-Book Graham Geary

Typesetting E-Book Publishers’ Design and Production Services, Inc.

We hope that you liked this e-book. Please share your feedback with us and read

the Service Pages to find out how to contact us.

The Library of Congress has cataloged the printed edition as follows:

Schwaninger, Jürgen.

[ABAP-Programmierung für die SAP-Materialwirtschaft. English]

ABAP development for materials management in SAP : user exits and BAdis /

Jürgen Schwaninger. — 1st ed.

p. cm.

Includes index.

ISBN-13: 978-1-59229-373-5

ISBN-10: 1-59229-373-5

1. Materials management—Computer programs. 2. SAP ERP. 3. Object-oriented programming

(Computer science) I. Title.

TS161.S38713 2011

658.70285’536—dc22

2010042024

ISBN 978-1-59229-373-5 (print)

ISBN 978-1-59229-743-6 (e-book)

ISBN 978-1-59229-744-3 (print and e-book)

© 2011 by Galileo Press Inc., Boston (MA)

1st edition 2011

1st German edition published 2010 by Galileo Press, Bonn, Germany

第 7 页 / 共 275 页

Contents

Preface ....................................................................................................... 11

1 Introduction .............................................................................. 13

1.1 Objectives .................................................................................. 13

1.2 Structure and Content ................................................................. 13

1.3 Target Audience .......................................................................... 14

1.4 Prerequisites ............................................................................... 14

2 General Information on User Exits and BAdIs .......................... 17

2.1 Using User Exits .......................................................................... 17

2.1.1 Finding and Viewing Enhancements .............................. 18

2.1.2 Creating a Project and Assigning Enhancements ............. 18

2.1.3 Using Components of the Project ................................... 19

2.1.4 Activating and Deactivating Projects ............................. 21

2.2 Use of Classic BAdIs .................................................................... 22

2.2.1 Finding and Viewing Enhancements .............................. 22

2.2.2 Creating a BAdI Implementation .................................... 24

2.2.3 Working with Methods .................................................. 25

2.2.4 Activating and Deactivating BAdIs ................................. 27

2.2.5 Enhanced Editing Options .............................................. 28

2.3 Use of New BAdIs (Enhancement Spots) ..................................... 29

2.3.1 SAP Enhancement Framework ........................................ 29

2.3.2 Finding and Viewing Enhancement Spots ....................... 30

2.3.3 Creating Enhancement Implementations ........................ 31

2.3.4 Working with Methods .................................................. 33

2.3.5 Activating and Deactivating BAdIs ................................. 34

3 User Exits and BAdIs in Purchasing ......................................... 37

3.1 Customized Fields in Purchase Orders ......................................... 37

3.1.1 Overview of the Implementation .................................... 38

3.1.2 Implementation of Custom Purchase Order Data

and Function Group ....................................................... 42

7

第 8 页 / 共 275 页

Contents

3.1.3 Integration of Custom Fields into the BAdIs ................... 54

3.1.4 Integration of Customer Fields into the Business Logic ... 61

3.1.5 Initializing, Reading, and Updating Data ......................... 68

3.1.6 Display of Error Messages ............................................... 69

3.2 Customizing the Document Overview in Purchase

Requisitions or Purchase Orders .................................................. 72

3.2.1 Removal of a Standard Selection Variant ........................ 72

3.2.2 Inserting Custom Selection Variants ................................ 75

4 User Exits and BAdIs in External Services Management ......... 83

4.1 Prepopulating Account Assignment for Service Lines ................... 83

4.2 Input Check of the Service Lines ................................................. 86

4.2.1 Prepopulating Fields in EXIT_SAPLMLSP_030 ................ 87

4.2.2 Input Check in EXIT_SAPLMLSP_031 ............................. 88

4.3 Prepopulation of the Header Data in the Data Entry Sheet .......... 89

5 User Exits and BAdIs in Inventory Management ..................... 93

5.1 Custom Fields in Transaction MIGO ............................................ 93

5.1.1 Custom Fields: An Overview .......................................... 94

5.1.2 Preparations in the ABAP Dictionary .............................. 97

5.1.3 Preparation of the Function Group ................................. 98

5.1.4 Preparation and Status Management in

MB_MIGO_BADI ........................................................... 104

5.1.5 Activation of Custom Header Data ................................. 109

5.1.6 Activation of Custom Item Data ..................................... 112

5.1.7 Updating the Data .......................................................... 117

5.2 Other Functions of the BAdI MB_MIGO_BADI ........................... 118

5.2.1 Noting Custom Data ...................................................... 119

5.2.2 Input Checks in Transaction MIGO ................................. 123

5.3 Checking and Prepopulating Standard Fields ............................... 125

5.3.1 Prepopulation of Storage Location and Text ................... 125

5.3.2 Checking the Standard Fields ......................................... 126

5.4 Check of the Earliest Delivery Date ............................................. 127

5.5 Tolerance Limits for Scheduling Agreements ............................... 129

5.5.1 Overwriting Overdelivery Quantity ................................. 129

5.5.2 Overwriting Default Quantity ......................................... 132

8

第 9 页 / 共 275 页

Contents

5.6 Enhancement of Reservations ....................................................... 134

5.6.1 Prepopulating Fields ....................................................... 135

5.6.2 Checking Entries ............................................................. 137

6 User Exits and BAdIs in the Valuation and Account

Assignment Area ....................................................................... 139

6.1 GR/IR Clearing Account .............................................................. 139

6.2 Overriding the Account Determination in the User Exit ............... 141

7 User Exits and BAdIs in Logistics Invoice Verification ............. 145

7.1 Custom Fields in Transaction MIRO ............................................ 145

7.1.1 Overview of the Solution via BAdI .................................. 146

7.1.2 BAdI in Detail — Customizations in the

ABAP Dictionary ............................................................ 148

7.1.3 Creating a Custom Dynpro with Table Control ............... 151

7.1.4 Preparation of the Data in the BAdI ............................... 154

7.1.5 Back to the Dynpro ........................................................ 158

7.2 Overriding Tolerance Checks ...................................................... 164

7.2.1 Tolerance Limits in Customizing ..................................... 165

7.2.2 Use of the Enhancement ................................................ 166

8 Validation and Substitution of Accounting Documents .......... 171

8.1 Validation of Accounting Documents .......................................... 172

8.1.1 Callup Points ................................................................. 172

8.1.2 Steps .............................................................................. 173

8.1.3 Example without Exit Routine ........................................ 174

8.1.4 Example with Exit Routine ............................................. 177

8.2 Substitution of Accounting Documents ....................................... 182

8.2.1 Substitution without Exit Routine ................................... 183

8.2.2 Substitution with Exit Routine ........................................ 185

8.2.3 Read Access to Data of the Source Document ................ 188

9

第 10 页 / 共 275 页

Contents

Appendices ..................................................................................... 193

A User Exits and BAdIs in SAP Materials Management ............................. 193

A.1 Purchasing .................................................................................. 194

A.1.1 Purchase Order Requisitions in General .......................... 194

A.1.2 Purchase Orders in General ............................................ 199

A.1.3 Outline Agreements (Scheduling Agreements/

Contracts) ...................................................................... 205

A.1.4 Pricing ............................................................................ 208

A.1.5 Commitment Functions .................................................. 210

A.1.6 Cross-Document ............................................................ 211

A.1.7 Vendor Evaluation .......................................................... 215

A.1.8 IDoc Processing .............................................................. 216

A.1.9 Logistics Information Systems ......................................... 218

A.1.10 Archiving ........................................................................ 218

A.2 External Services Management .................................................... 221

A.3 Inventory Management ............................................................... 227

A.3.1 Material Documents in General ...................................... 227

A.3.2 Goods Receipt ................................................................ 233

A.3.3 Reservations ................................................................... 235

A.3.4 Archiving ........................................................................ 236

A.4 Valuation and Account Assignment ............................................. 238

A.5 Logistics Invoice Verification ....................................................... 240

A.5.1 General .......................................................................... 240

A.5.2 Archiving ........................................................................ 254

A.5.3 Conventional Invoice Verification ................................... 254

B The Author ........................................................................................... 257

Index ......................................................................................................... 259

Service Pages ............................................................................................. I

Legal Notes ............................................................................................... III

10

第 11 页 / 共 275 页

Preface

Some things happen in a surprising way. Just like when the editor from SAP PRESS

asked whether I’d be interested in writing a book on user exits and BAdIs in Mate-

rials Management (MM). At that time, I had already started writing a small online

book on ABAP Debugger, but writing a proper book was something completely

different. However, over the many years of working as a logistics consultant and

developer, I have probably programmed hundreds of enhancements for custom-

ers, so I thought, why not?

More difficult than making this decision was deciding how the book should be

structured. From the start, it was clear that covering all enhancement options in

detail was impossible because there are so many options in SAP Materials Manage-

ment (which we will refer to in this book primarily as MM). On the other hand, I

didn’t want to create an incomplete overview of the available enhancements; there

are enough gaps already in the official documentation. To meet this challenge, this

book describes individually selected enhancements in detail in the main chapters,

with priority given particularly to the more complex and difficult enhancements.

All other user exits and BAdIs are given a structured and complete overview in

the Appendix.

Now that the book is complete, I would like to thank all those who helped me

implement this project. Kristina Noe and Philipp Grimm are especially mentioned

here. I would also like to thank Stefan Proksch from the SAP PRESS editorial office

in Germany very much for his tremendous help.

A special thank you goes to my family who gave me the necessary time on short

weekends to write this book.

Jürgen Schwaninger

Senior Logistics & ABAP Consultant

11

Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618

第 12 页 / 共 275 页

© 2013 by Galileo Press Inc., Boston (MA)

第 13 页 / 共 275 页

1 Introduction

The Materials Management functionality in SAP ERP, which in this book we’ll refer

to as Materials Management, or MM, is certainly among the largest of its type. The

settings in Customizing are therefore especially comprehensive. The customer pro-

cesses are also extremely complex and multivariant in this area so that the limits

of customizing are reached sooner or later.

1.1 Objectives

To cope with the required processes, SAP provides a large number of user exits

and BAdIs in MM that allow you to implement highly individual requirements

and processes. This book shows you the options available and describes the exact

procedure for selecting enhancements so that you can use this technology to opti-

mize your processes.

First of all, you will learn how to generally deal with enhancements, BAdIs, and

enhancement spots so that you can easily understand the examples given in this

book. The use and programming of selected enhancements in ABAP are described

using step-by-step instructions. All ABAP listings are fully displayed with detailed

comments so that you can easily apply them in your own custom applications.

1.2 Structure and Content

If you don’t program enhancements very often, you can familiarize yourself with

the concepts of user exits, BAdIs, and enhancement spots in Chapter 2. The use and

activation of these enhancement options are described based on brief examples.

Chapters follow for each of the major areas in MM: Purchasing (Chapter 3),

External Services Management (Chapter 4), Inventory Management (Chapter 5),

Evaluation and Account Assignment Area (Chapter 6), and Logistics Invoice Veri-

fication (Chapter 7). The most important and most comprehensive enhancement

options are described using simple examples to avoid any unnecessary confusion.

13

Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618

第 14 页 / 共 275 页

1 Introduction

Because problems are rarely identical, examples are used that convey fundamen-

tal functions and options. With this knowledge, you can transfer your individual

requirement to the enhancement.

The book concludes with a brief look at the validation and substitution of account-

ing documents in Chapter 8. With regard to posting goods movements and incom-

ing invoices in MM, accounting documents are also automatically generated as

follow-on documents in SAP ERP Financials Financial Accounting, which we’ll

refer to as Financial Accounting, or FI. Users frequently want to add additional

data from MM to this FI document or use additional checks from the accounting

point of view. This technology can also be used as a replacement for possible avail-

able custom checks in user units or BAdIs because you can build up a central set

of rules in one place, regardless of whether a document comes from the Inventory

Management, the Logistics Invoice Verification, or the FI system itself.

Appendix A provides an overview of the user exits and BAdIs in in MM. The

Appendix is divided into the same areas as the chapters of this book. Areas that

have many enhancements are further structured so that you can quickly find all

available enhancements on a specific transaction or on a specific procedure.

1.3 Target Audience

This book is mainly aimed at MM consultants who only have a basic knowledge

of ABAP, but it’s also for experienced ABAP programmers who may have little

knowledge of MM. However, even if you are an experienced MM consultant and

programmer, you can use this book as a reference guide and perhaps even learn

one or two tricks.

Whichever group you belong to, rest assured that this book offers the necessary

coverage of ABAP and logistics without straying far from the fundamentals.

1.4 Prerequisites

Although this book is primarily aimed at consultants with little experience in pro-

gramming, you should have the fundamental ABAP knowledge at the SAP BC400

training level. The use of ABAP objects, unless absolutely necessary, has been

omitted. Nevertheless, there are individual BAdIs that have an object-oriented

approach, which must be kept in the programming.

14

© 2013 by Galileo Press Inc., Boston (MA)

第 15 页 / 共 275 页

Prerequisites 1.4

However, you don’t need any deep knowledge in object-oriented programming.

Knowledge of the essential basic concepts of object orientation is enough in these

cases. Some special features of object orientation in this book, such as interfaces

or upcast implementations, are only described briefly.

The examples can in principle be understood in each R/3 system from Release 4.6C,

or in an SAP ERP Central Component system from Release 5.0. Some enhance-

ments have only been introduced in a later release and are therefore only available

in more recent SAP systems. Appendix A provides the prerequisites for specific

enhancements.

15

Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618

第 16 页 / 共 275 页

© 2013 by Galileo Press Inc., Boston (MA)

第 17 页 / 共 275 页

2 General Information on

User Exits and BAdIs

You’ve possibly purchased this book because you already have a good understand-

ing of SAP components for Materials Management (MM), but you only have a

fundamental knowledge of ABAP programming. Perhaps you program more

frequently but have little contact with the latest technologies, such as the enhance-

ment spots that will gradually replace the classic BAdIs.

User exits, BAdIs, and enhancement spots fulfill the same purpose. When SAP

applications and programs run according to a predefined schema that doesn’t

always precisely fit in with your enterprise requirements, a navigation option is

provided with enhancements in positions selected by SAP, which you can use to

exit the standard coding. You can activate these navigation options, if necessary,

and assign your own ABAP code, which means you can change data provided in a

defined interface or completely integrate your custom functions here.

In this chapter, the various enhancement options are introduced and explained

using a step-by-step example. If you’ve already implemented numerous enhance-

ments in SAP systems, and you’re only searching for specific information on MM,

feel free to skip this chapter.

2.1 Using User Exits

User exits constitute the oldest SAP enhancement technology still in use today. In

this section, the main focus is on dealing fundamentally with user exits. To better

illustrate the technology, the following example shows how you can use and acti-

vate user exits: If a purchase requisition is converted into an order, this is logged in

the change documents of the purchase requisition using enhancement MM06E007.

17

Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618

第 18 页 / 共 275 页

2 General Information on User Exits and BAdIs

Concepts from the World of User Exits

Numerous concepts are important for understanding user exits:

EE Enhancement

Enhancements are provided by SAP and include one or several components that, as a

whole, allow for a defined functionality.

EE Components

Components are the elements of an enhancement that are ultimately used to custom-

ize the standard. Components can be exit modules or dynpros for custom-specific

fields.

EE Projects

Projects are created by the customer to include enhancements (and components). Proj-

ects can be activated and deactivated at any time. However, only components from

active projects can be actually carried out.

2.1.1 Finding and Viewing Enhancements

Finding the suitable enhancement for a planned project can be difficult. Lists of

enhancements are usually available in the SAP Implementation Guide (SAP Ref-

erence IMG in Customizing, Transaction SPRO). However, the Repository Info

System that you can find via Transaction SMOD in the Utilities • FIND menu can

also be a good starting point. You now also have this book for MM, and with it a

virtually complete overview on all the enhancements available (see Appendix A).

If you’ve found a promising enhancement, you can also view this in Transaction

SMOD. Besides the documentation, you can also take a brief look at the compo-

nents included here.

2.1.2 Creating a Project and Assigning Enhancements

To use the previously mentioned MM06E007 enhancement, you must first create a

project.

You can implement this via Transaction CMOD or via the Tools • ABAP Work-

bench • Utilities • Enhancements • Project Management menu path.

1. Choose a project name in this dialog box, for example, ZMM06E07 (see Figure

2.1), and then click Create.

18

© 2013 by Galileo Press Inc., Boston (MA)

Concepts from the World of User Exits
Numerous concepts are important for understanding user exits: EE Enhancement Enhancements are provided by SAP and include one or several components that, as a whole, allow for a defined functionality. EE Components Components are the elements of an enhancement that are ultimately used to custom- ize the standard. Components can be exit modules or dynpros for custom-specific fields. EE Projects Projects are created by the customer to include enhancements (and components). Proj- ects can be activated and deactivated at any time. However, only components from active projects can be actually carried out.

第 19 页 / 共 275 页

Using User Exits 2.1

Figure 2.1 Creating a Project

2. Enter a short text describing the project, and then click Enhancement Assign-

ment. Confirm the subsequent query and whether the project should be

saved.

3. Assign the MM06E007 enhancement to the project in the next screen (see Figure

2.2). Save the project again.

Figure 2.2 Adding an Enhancement

2.1.3 Using Components of the Project

After you’ve successfully created your project, you can use one component and

integrate custom ABAP code:

19

Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618

第 20 页 / 共 275 页

2 General Information on User Exits and BAdIs

1. Display the project again in Transaction CMOD, and then click the Compo-

nents button.

2. You can now only see one component here: EXIT_SAPMM06E_020. Double-click

this component to directly go to the Function Builder (Transaction SE37). Your

custom coding isn’t directly stored in the function module, however, because

it’s in the SAP name range. In fact, each exit automatically includes an include

statement for a Z include. In the example given, this is the ZXM06U50 include.

3. Double-click ZXM06U50 in the source text. You receive a brief note indicating

that includes, the names of which begin with “ZX...,” are reserved for user exits.

Because you are creating this kind of include, confirm the note via the [Enter]

key. When asked if the include should be created, choose Yes.

4. Copy the coding from Listing 2.1, and activate the include. Be sure to customize

the queried company code to your existing test data.

*&-----------------------------------------------------------*

*& Include ZXM06U50

*&-----------------------------------------------------------*

* Generate change

document in purchase requisition, if it is converted into

* a follow-on document. The parameter c_changedoc_for_req

* must be defined for this.

* i_ekko-bstyp “ Only if the follow-on document is a purchase order

* i_ekko-bukrs “ Only for company code 1000

IF i_ekko-bstyp = ‘F’

AND i_ekko-bukrs = ‘1000’.

* Generate change document

c_changedoc_for_req = ‘X’.

ENDIF.

Listing 2.1 Example — Generating a Change Document

The user exit is checked to determine whether the follow-up document is a pur-

chase order (field i_ekko-bstyp = ‘F’) and whether the procedure is carried out

in company code 1000 (field i_ekko-bukrs). In this case, a change document is

generated. The field c_changedoc_for_req is therefore defined.

20

© 2013 by Galileo Press Inc., Boston (MA)

第 21 页 / 共 275 页

Using User Exits 2.1

Note

After you’ve created the include, you can see a green checkmark in the overview of the

components (see Figure 2.3). This indicates that the Z include exists but not that coding

exists in it.

Furthermore, you can always see a red dot next to the Project text in this view. This

indicates that your project isn’t yet active. Your coding is therefore not implemented.

Figure 2.3 Overview of Components

2.1.4 Activating and Deactivating Projects

You must now activate the project so that the user exit is actually implemented.

You can do this directly in the initial screen of Transaction CMOD (see Figure

2.4).

Figure 2.4 Activating and Deactivating the Projects

21

Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618

Note
After you’ve created the include, you can see a green checkmark in the overview of the components (see Figure 2.3). This indicates that the Z include exists but not that coding exists in it. Furthermore, you can always see a red dot next to the Project text in this view. This indicates that your project isn’t yet active. Your coding is therefore not implemented.

第 22 页 / 共 275 页

2 General Information on User Exits and BAdIs

1. Choose Project • Activate Project in the menu, or click the respective icon in

the initial view.

2. If the system doesn’t behave as expected, it may be sensible to deactivate the

project to maintain the standard behavior again. To do this, choose Project •

Deactivate Project in the menu or click the respective icon.

Several Enhancements in the Project?

Although you can assign several enhancements, you can only activate or deactivate proj-

ects as a unit. Only merge the enhancements if they also functionally belong together in

their implementation; that is, they implement a specific process.

2.2 Use of Classic BAdIs

Business Add-Ins (BAdIs) display the object-oriented variant of the user exits.

BAdIs were introduced with Basis Release 4.6D. The first enhancements are there-

fore available in R/3 Release 4.6B. However, many BAdIs in MM have only been

introduced with SAP R/3 Enterprise 4.7.

The example ME_HOLD_PO BAdI shows you how to use this technology. As you prob-

ably know, the Hold function allows you to temporarily save an incomplete pur-

chase order so that this can be further processed at a later stage. This BAdI allows

you to prohibit the Hold function when you create orders, if necessary.

With Release 6.0, the BAdI technology has been updated and integrated into

the enhancement framework (see Section 2.3, Use of New BAdIs [Enhancement

Spots]). Already existing BAdIs, now referred to as classic BAdIs, haven’t been

automatically migrated. Both worlds currently exist in parallel.

2.2.1 Finding and Viewing Enhancements

There are also overviews for BAdIs in the SAP IMG (SAP Reference IMG in Cus-

tomizing, Transaction SPRO). Alternatively, you can find a complete overview of

all BAdIs in Appendix A of this book.

You can display the definition of the BAdI via Transaction SE18. Since Basis Release

SAP ECC 6.0, you have the choice between searching for Enhancement Spots and

BAdI Name. Use the latter field to display the BAdI.

22

© 2013 by Galileo Press Inc., Boston (MA)

Several Enhancements in the Project?
Although you can assign several enhancements, you can only activate or deactivate proj- ects as a unit. Only merge the enhancements if they also functionally belong together in their implementation; that is, they implement a specific process.

第 23 页 / 共 275 页

Use of Classic BAdIs 2.2

Concepts from the World of BAdIs

With BAdIs, you must differentiate between their definition and implementation:

EE Definition

The definition of a BAdI is fundamentally only a blueprint that describes the BAdI

with all of the methods included. The definition doesn’t include any executable pro-

gram parts. You can find the definition of a BAdI in Transaction SE18.

EE Implementation

The implementation of a BAdI is necessary to use the definition. The implementation

therefore assumes the properties of the definition and consequently uses the blue-

print. You can find the implementation of a BAdI in Transaction SE19.

You can see two switches in the initial screen of the BAdI definition (see Figure

2.5).

Figure 2.5 Initial Screen of the BAdI Definition

1. Multiple Use

BAdIs with this switch can be implemented multiple times. All implementa-

tions will run directly after one another. However, the sequence cannot be

predicted. If you use several processes that use the same BAdI, you can clearly

23

Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618

Concepts from the World of BAdIs
With BAdIs, you must differentiate between their definition and implementation: EE Definition The definition of a BAdI is fundamentally only a blueprint that describes the BAdI with all of the methods included. The definition doesn’t include any executable pro- gram parts. You can find the definition of a BAdI in Transaction SE18. EE Implementation The implementation of a BAdI is necessary to use the definition. The implementation therefore assumes the properties of the definition and consequently uses the blue- print. You can find the implementation of a BAdI in Transaction SE19.

第 24 页 / 共 275 页

2 General Information on User Exits and BAdIs

separate these. You can also deactivate an individual implementation without

influencing the other processes.

2. Filter-Depend

Some BAdIs use a filter that you must fill with values when the BAdI is imple-

mented. Typical filter values are, for example, a document type or a country.

The BAdI is only started when the filter value transferred during runtime cor-

responds with the value in your implementation.

In the Interface tab, you can see a list of the methods defined in the BAdI. These

methods for the runtime are ultimately called at positions in the program defined

by SAP.

1. Double-click the method name to navigate to the class interface, where you can

view the input and output parameters of the method.

2. Navigate again to the BAdI via Back ([F3]).

3. Click the Documentation button in the application bar to see a description of

the BAdI.

Numerous BAdIs also contain a sample coding that you can view by choosing the

GoTo • Sample Code • Display menu path, and then double-clicking a method.

You can use this coding as a template for custom enhancements.

2.2.2 Creating a BAdI Implementation

After you’ve learned the details about the BAdI, you can create an implementat ion.

1. Start Transaction SE19.

2. The initial screen and the steps to create an implementation differ depending

on the Basis release.

EE In a release prior to 7.0, you call your implementation, for example, Z_ME_

HOLD_PO, and click Create. In the dialog window that appears, you must now

specify the BAdI definition, that is, ME_HOLD_PO, and confirm the entry via

[Enter].

EE In a release greater or equal to Release 7.0, you choose the Classic BAdI

option in Create Implementation at the bottom of the screen, specify the

definition ME_HOLD_PO, and click Create Implementation (see Figure 2.6). In

the dialog window that appears, enter the name of the implementation, for

example, Z_ME_HOLD_PO, and confirm this entry via the [Enter] key.

24

© 2013 by Galileo Press Inc., Boston (MA)

第 25 页 / 共 275 页

Use of Classic BAdIs 2.2

Apart from this, there are no release differences worth mentioning with regard

to the implementation of BAdIs.

Figure 2.6 Creating an Implementation from Release 7.0

3. Enter a short text as a description of the intended function, and save the BAdI.

2.2.3 Working with Methods

You’ve now fundamentally prepared the BAdI implementation and can focus on

the contained methods.

1. Go to the Interface tab. You can now see the name of classes automatically cre-

ated and implemented (in the example given, ZCL_IM__ME_HOLD_PO), as well as

a list of the methods contained (see Figure 2.7).

25

Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618

第 26 页 / 共 275 页

2 General Information on User Exits and BAdIs

Figure 2.7 Interface of the BAdI Implementation

2. To fill a method with coding, you need to navigate to the list, and double-click

the method name IS_ALLOWED.

3. In the method, show the parameter interface by clicking Signature in the appli-

cation bar (see Figure 2.8).

In the example already given, the holding of the order is now prohibited for

document type NB (normal purchase order) as long as the document header is

still missing. The method obtains, among other things, the import parameter

IM_EKKO, which includes the document type in the field BSART, as well as a spe-

cial flag IM_HEADER_WITH_ERROR, which is set when the document header still

contains errors (i.e., a red traffic light icon is displayed in Transaction ME21N).

Implement the coding from Listing 2.2.

26

© 2013 by Galileo Press Inc., Boston (MA)

第 27 页 / 共 275 页

Use of Classic BAdIs 2.2

Figure 2.8 Method with Displayed Signature

METHOD if_ex_me_hold_po~is_allowed.

* Purchase orders may only be held for document type NB,

* if the document header doesn‘t contain any errors.

IF im_header_with_error IS NOT INITIAL AND

im_ekko-bsart = ’NB‘.

ch_allowed = space.

ENDIF.

ENDMETHOD.

Listing 2.2 Example — Prohibiting Holding

4. Save and activate the method, and navigate to the Interface tab of the BAdI

via Back ([F3]).

2.2.4 Activating and Deactivating BAdIs

You must now activate the enhancement as before with the user exits in the initial

screen of the BAdI, so that the BAdI is actually implemented.

27

Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618

第 28 页 / 共 275 页

2 General Information on User Exits and BAdIs

1. Ensure that you’re in the change mode of the BAdI. You can now activate the

BAdI via the menu Implementation • Activate or the respective icon in the

application bar.

2. Create an order with document type NB (Transaction ME21N). The Hold but-

ton is hidden as long as the purchase order header is incomplete.

3. If you want to recover the standard behavior of the purchase order transaction,

you can deactivate the BAdI again at any time via the menu Implementation •

Deactivate.

2.2.5 Enhanced Editing Options

For more complex BAdIs, you might need to create custom attributes or custom

types to have data available that applies to all methods. You can obtain more details

on how to use custom attributes in the examples given in Section 3.1, Customized

Fields in Purchase Orders, (ME_GUI_PO_CUST), in Chapter 3, and in Section 5.1, Cus-

tom Fields in Transaction MIGO, (MB_MIGO_BADI), in Chapter 5.

1. For this, navigate once again to the Interface tab of the BAdI (see Figure 2.9).

From this position, navigate by double-clicking the name of the implementing

class in the Class Builder.

Figure 2.9 Implementing Class in the Class Builder

2. In the Types tab, you can define custom data types to use within the class.

3. In the Attributes tab, you can create your own variables. As is normally the case

in classes, you can also specify the visibility as Private/Protected or Public.

28

© 2013 by Galileo Press Inc., Boston (MA)

第 29 页 / 共 275 页

Use of New BAdIs (Enhancement Spots) 2.3

You can fundamentally choose Private here because you’ll always remain with-

in the class in the BAdI programming.

4. In the Methods tab, you can also go to the individual methods to view or

change the coding.

2.3 Use of New BAdIs (Enhancement Spots)

With Release 7.0, the BAdIs have been included in SAP Enhancement Framework.

However, existing (classic) BAdIs haven’t automatically been migrated, but still

have the same status.

2.3.1 SAP Enhancement Framework

SAP Enhancement Framework will replace all customization options that exist to

date in the long term; that is, user exits and BAdIs, as well as modifications. Using

enhancement spots, which identify specific positions of a program or an interface,

you can then integrate enhancements at these positions. A distinction is made here

between explicit and implicit enhancement spots:

EE Explicit enhancement spots

Explicit enhancement spots are positions defined by a developer in advance

where enhancements are possible. These are also partly the new BAdIs, which

are integrated as enhancement points. One or several enhancement points are

combined into enhancement spots, which you can view in Transaction SE18.

EE Implicit enhancement spots

Implicit enhancement spots are positions in programs that can always be

enhanced. Such a position can be found, for example, behind the last line of a

program or include, or before the first and behind the last line of the implemen-

tation of a procedure. No additional enhancement spot exists for implicit

enhancement spots.

Enhancement or Modification?

Implicit enhancement spots are automatically available in all programs and their respec-

tive routines. In numerous cases, they are ideal options to customize an SAP program if

necessary. Nevertheless, the use of such an enhancement spot is officially still a modifica-

tion! Only explicit enhancement spots in the form of BAdIs can be used for the “official”

enhancement of SAP programs.

29

Personal Copy for Yang Meteor, user id a8103f58-81fe-4f49-acf6-cfb58959c618

Enhancement or Modification?
Implicit enhancement spots are automatically available in all programs and their respec- tive routines. In numerous cases, they are ideal options to customize an SAP program if necessary. Nevertheless, the use of such an enhancement spot is officially still a modifica- tion! Only explicit enhancement spots in the form of BAdIs can be used for the “official” enhancement of SAP programs.

第 30 页 / 共 275 页

2 General Information on User Exits and BAdIs

2.3.2 Finding and Viewing Enhancement Spots

Just like in the case of user exits and classic BAdIs, you can find enhancement spots

in SAP IMG (SAP Reference IMG in Customizing, Transaction SPRO) for MM or in

Appendix A of this book.

A brief example for the new BAdIs is also presented to introduce this technology

and its respective application. The example uses the ME_POHIST_DISP_CUST BAdI,

which can be found in the ES_BADI_ME_POHIST enhancement spot. The display of

the purchase order history can be customized using this enhancement.

Note

This section only discusses the differences in classic BAdIs. If you haven’t had any experi-

ence with classic BAdIs so far, you should first read Section 2.2, Use of Classic BAdIs.

1. You can again display the enhancement spots in Transaction SE18. Enter the

name of the enhancement spot and click Display.

2. You can see the BAdIs contained in the enhancement spot on the left-hand side.

Click the ME_POHIST_DISP_CUST BAdI to switch the view to this BAdI (see Figure

2.10).

Figure 2.10 Displaying an Enhancement Spot with Contained BAdIs

30

© 2013 by Galileo Press Inc., Boston (MA)

Note
This section only discusses the differences in classic BAdIs. If you haven’t had any experi- ence with classic BAdIs so far, you should first read Section 2.2, Use of Classic BAdIs.
返回ABAP参考资料列表