ABAP Development for Sales and Distribution in SAP (第1页)

第 1 页 / 共 265 页

第 2 页 / 共 265 页

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.

Dirk Herzog

ABAP Development for SAP NetWeaver BW (3rd Edition)

2012, 280 pp. (hardcover)

978-1-59229-424-4

Jürgen Schwaninger

ABAP Development for Materials Management in SAP

2011, 270 pp. (hardcover)

978-1-59229-373-5

Sergey Korolev

ABAP Development for Financial Accounting

2011, 252 pp. (hardcover)

978-1-59229-370-4

Rich Heilman, Thomas Jung

Next Generation ABAP Development (2nd Edition)

2011, 735 pp. (hardcover)

978-1-59229-352-0

第 3 页 / 共 265 页

Michael Koch

ABAP® Development for Sales

and Distribution in SAP®

Exits, BAdIs, and Enhancements

Bonn (cid:31) Boston

第 4 页 / 共 265 页

Dear Reader,

One size fits all? Not in today’s business climate! With this book, you have the

opportunity to walk along with two ABAP developers, Christine and Sean, as they

work together to find custom enhancements that meet a business’s SD custom

requirements. Thanks to the integration of practical instruction and a fictional busi-

ness case, you’ll feel as if an ABAP expert is standing by your side as you explore

each real-world scenario. Not only will you understand how to find the best way to

customize a system, you’ll also understand how to piece together different experi-

ence levels and knowledge bases to get the most out of your team.

I had the pleasure of working with Michael Koch on his first (and hopefully not last)

book. His enthusiasm for the project was extremely catching, and he even came up

with the unique idea of adding an illustration to the book! He constantly impressed

me as he juggled his consulting jobs (which of course give him the valuable experi-

ences and expertise we’re always looking for to write such a book!), with writing

and meeting the deadlines.

We at SAP PRESS are always eager to hear your opinion. What do you think about

ABAP Development for Sales and Distribution in SAP? As your comments and sugges-

tions are our most useful tools to help us make our books the best they can be, we

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

Thank you for purchasing a book from SAP PRESS!

Laura Korslund

Editor, SAP PRESS

Galileo Press

Boston, MA

publishing@galileo-press.com

http://www.sap-press.com

第 5 页 / 共 265 页

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. 3f8p-hc2x-bwym-n5jz

for personal use of

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

第 6 页 / 共 265 页

Imprint

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

Editor Laura Korslund

Acquisitions Editor Kelly Grace Harris

Copyeditor Julie McNamee

Cover Design Graham Geary

Photo Credit iStockphoto.com/Ceneri

Production E-Book Kelly O’Callaghan

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:

Koch, Michael.

ABAP development for sales and distribution in SAP : exits, BADIs, and

enhancements / Michael Koch. — 1st ed.

p. cm.

ISBN 978-1-59229-420-6 — ISBN 1-59229-420-0

1. SAP ERP. 2. Sales management—Computer programs. 3. Marketing—

Management—Computer programs. I. Title.

HF5438.4.K634 2013

658.800285’53—dc23

2012027202

ISBN 978-1-59229-420-6 (print)

ISBN 978-1-59229-603-3 (e-book)

ISBN 978-1-59229-604-0 (print and e-book)

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

1st edition 2012

第 7 页 / 共 265 页

Contents

Preface ....................................................................................................... 13

1 Introduction to Enhancements in Sales and Distribution ........ 19

1.1 Enhancing Standard SD Functionality .......................................... 20

1.1.1 Exits ............................................................................... 21

1.1.2 Projects .......................................................................... 31

1.2 Customer Routines ..................................................................... 32

1.3 The Enhancement and Switch Framework ................................... 34

1.3.1 Explicit Enhancements .................................................... 35

1.3.2 Implicit Enhancements ................................................... 38

1.3.3 The Switch Framework ................................................... 40

1.4 Comparison of Enhancement Methods ........................................ 41

1.5 Summary .................................................................................... 43

PART I Enhancements in Sales Order Processing

2 Validating Sales Order Data ..................................................... 47

2.1 Business Scenario ........................................................................ 47

2.2 Finding the Right Enhancement .................................................. 48

2.3 Implementing the Solution ......................................................... 51

2.3.1 Create a New Database Z Table ...................................... 52

2.3.2 Generate Table Maintenance .......................................... 52

2.3.3 Create Parameter Transaction ......................................... 52

2.3.4 Creating an Enhancement Point Implementation ............ 54

2.3.5 Implementing an Implicit Enhancement ........................ 56

2.3.6 Coding the User Exit ....................................................... 57

2.4 Summary .................................................................................... 59

7

第 8 页 / 共 265 页

Contents

3 Capturing and Saving Additional Data Fields in Sales Order

Processing ................................................................................. 61

3.1 Business Scenario ........................................................................ 61

3.2 Finding the Right Enhancement .................................................. 62

3.2.1 Using the Additional Data B Tab ..................................... 63

3.2.2 Using Implicit Enhancements ......................................... 63

3.2.3 Using Persistent Objects ................................................. 65

3.2.4 USEREXIT_SAVE_DOCUMENT ....................................... 65

3.3 Implementing the Solution ......................................................... 66

3.3.1 Declarations of Data Elements, Database Tables,

and Table Types .............................................................. 66

3.3.2 Create Persistency Classes for Survey Data ...................... 68

3.3.3 Create Database Table Lock Entries ................................ 71

3.3.4 Creating Modification and Implicit Enhancements

for a Custom Screen ....................................................... 71

3.3.5 Create the Implicit Enhancement for PBO Modules ........ 73

3.3.6 Create the Implicit Enhancement for Module PAI ........... 76

3.3.7 Adding Layout Changes to Screen 8309 of SAPMV45A ... 81

3.4 Summary .................................................................................... 82

4 Creating an SAP CRM Activity after SD Order Billing ............. 83

4.1 Business Scenario ........................................................................ 83

4.2 Finding the Right Enhancement .................................................. 84

4.3 Communication between SAP Systems via RFC ........................... 90

4.3.1 ABAP-to-ABAP Communications ................................... 90

4.3.2 Setting Up RFC Connections ........................................... 91

4.4 Implementing the Solution ......................................................... 93

4.4.1 Creating a New Function Group in the SAP CRM

System ........................................................................... 94

4.4.2 Creating an RFC Function Module in the SAP CRM

System ........................................................................... 94

4.4.3 Specify Function Module Parameters .............................. 95

4.4.4 Implement ABAP Logic to Create an Activity in

SAP CRM ....................................................................... 95

8

第 9 页 / 共 265 页

Contents

4.4.5 Create the Enhancement Point Implementation in

Function Module RV_INVOICE_REFRESH ....................... 97

4.5 Summary .................................................................................... 99

5 Filtering Pricing Data within a Web Service ............................ 101

5.1 Background on SOA and Enterprise Services ............................... 102

5.1.1 Service-Oriented Architectures ....................................... 102

5.1.2 Characteristics and Goals of SOA .................................... 102

5.1.3 Enterprise Services and Web Services ............................. 104

5.1.4 Finding Enterprise Services ............................................ 105

5.2 Business Scenario ........................................................................ 109

5.3 Finding the Right Enhancement .................................................. 111

5.4 Implementing the Solution ......................................................... 111

5.4.1 Locate the Web Service using Transaction SE80 .............. 112

5.4.2 Locate a Provider Class for the Web Service ................... 112

5.4.3 Locate and Implement the Outbound BAdI .................... 114

5.4.4 Find the Correct Outbound Parameter in the BAdI

Signature ........................................................................ 116

5.4.5 Implement ABAP Coding ................................................ 118

5.4.6 Testing the Enhanced Service ......................................... 119

5.5 Summary .................................................................................... 120

6 Using a Custom Field in SD Pricing ......................................... 121

6.1 Business Scenario ........................................................................ 121

6.2 Finding the Right Enhancement .................................................. 122

6.3 Implementing the Solution ......................................................... 123

6.3.1 Creating a New Customer Field for Table VBAK .............. 123

6.3.2 Adding a New Field to Pricing Communication

Structure KOMK ............................................................ 125

6.3.3 Creating a New Condition Table ..................................... 126

6.3.4 Maintaining USEREXIT_PRICING_PREPARE_TKOMK ...... 126

6.3.5 Maintaining the Access Sequence ................................... 128

6.3.6 Defining a New Condition Type ...................................... 129

6.3.7 Maintaining Condition Rates in Transaction VK11 .......... 129

6.4 Summary .................................................................................... 130

9

第 10 页 / 共 265 页

Contents

PART II Enhancements in Delivery Processing

7 Setting a Delivery Block on the Header Level .......................... 135

7.1 Business Scenario ........................................................................ 135

7.2 Finding the Right Enhancement .................................................. 136

7.3 Implementing the Solution ......................................................... 137

7.3.1 Locating the BAdI .......................................................... 137

7.3.2 Creating a BAdI Implementation .................................... 140

7.3.3 Adding Code to the Implementation .............................. 143

7.4 Summary .................................................................................... 144

8 Using a BAdI to Keep Track of Delivery KPIs ........................... 145

8.1 Business Scenario ........................................................................ 145

8.1.1 Current KPI Solution ...................................................... 145

8.1.2 To-Be Process for KPI Reporting ..................................... 146

8.2 Finding the Right Enhancement .................................................. 148

8.3 Implementing the Solution ......................................................... 150

8.3.1 Custom KPI Field Table Layouts ...................................... 150

8.3.2 Define Custom Table ZKPI_FIELDS ................................. 151

8.3.3 Generating a Table Maintenance for ZKPI_FIELDS .......... 154

8.3.4 Define Custom Table ZKPI_DATA ................................... 155

8.3.5 Implement ABAP Coding in Method SAVE_AND_

PUBLISH_DOCUMENT ................................................... 156

8.4 Summary .................................................................................... 161

9 Using a Customer Exit to Enhance the Outbound Delivery

Monitor ..................................................................................... 163

9.1 Business Scenario ........................................................................ 163

9.2 Finding the Right Enhancement .................................................. 165

9.3 Implementing the Solution ......................................................... 166

9.3.1 Implement the Customer Exit Routine ............................ 166

9.3.2 Add New Field Entries to Append Structure LIPOVZ ...... 168

9.3.3 Add Coding to Derive KPI Data and Calculate

Delivery Age .................................................................. 172

9.3.4 Testing the Enhanced Delivery Monitor ......................... 175

9.4 Summary .................................................................................... 175

10

第 11 页 / 共 265 页

Contents

PART III Enhancements in Billing

10 Invoice Splitting Using a VOFM Routine ................................. 179

10.1 Business Scenario ........................................................................ 179

10.2 Finding the Right Enhancement .................................................. 180

10.2.1 Understanding the Invoice Split ..................................... 180

10.2.2 Finding Exits or Enhancements ....................................... 181

10.2.3 Transfer Routines ............................................................ 182

10.3 Implementing the Solution ......................................................... 184

10.3.1 Copy the Existing VOFM Routine ................................... 184

10.3.2 Create an Implicit Enhancement within the Data

Transfer Routine ............................................................. 186

10.3.3 Add Custom ABAP Coding ............................................. 190

10.3.4 Apply Routine to Copy Control ...................................... 191

10.4 Summary .................................................................................... 192

11 Changing Invoice Reference and Numbering Range

during Document Creation ....................................................... 195

11.1 Business Scenario ........................................................................ 195

11.2 Finding the Right Enhancement .................................................. 198

11.3 Implementing the Solution ......................................................... 201

11.3.1 Define New Numbering Ranges ...................................... 201

11.3.2 Define the Cross-Reference Table ................................... 202

11.3.3 Implement Implicit Enhancements in RV60AFZC ............ 204

11.3.4 Add Coding to Establish Delivery Type ........................... 206

11.3.5 Implement an Implicit Enhancement in RV60AFZZ ......... 207

11.3.6 Add Coding to Amend the Numbering Range ................. 207

11.4 Summary .................................................................................... 208

PART IV Conclusion

12 Finding the Right Enhancement Technique ............................. 211

12.1 Techniques Used and How the Solution Was Found .................... 211

12.2 Solution Search Categories .......................................................... 213

12.3 Key Aspects When Implementing Enhancements ........................ 214

12.4 There is No “Silver Bullet” ........................................................... 216

11

第 12 页 / 共 265 页

Contents

13 Future Outlook ......................................................................... 217

Appendices ..................................................................................... 221

A Exits and BAdIs in Sales and Distribution .............................................. 223

A.1 Sales Orders ................................................................................ 223

A.2 Deliveries .................................................................................... 232

A.3 Invoicing ..................................................................................... 238

A.4 Transport Documents .................................................................. 242

A.5 Shipment Costs ........................................................................... 246

B Code Listing for Class ZCL_SURVEY ...................................................... 249

C The Author ........................................................................................... 253

Index ......................................................................................................... 255

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

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

12

第 13 页 / 共 265 页

Preface

Today, SAP ERP counts for more than 65,000 installations worldwide. Experts

estimate that 90- 95% of these installations use Sales and Distribution (SD), so we

can assume that roughly 60,000 businesses around the globe use it. In other words,

SAP SD is a true ERP success story.

There are many reasons for this success, but one that repeatedly ranks the highest is

the level of configuration and customization that can be achieved within SD. Both

sales and distribution form integral parts of most modern businesses. Therefore, the

ability to mold the system to key business processes—where deemed necessary—

can be paramount. While configuration enables a business to add system settings

within the boundaries of the programming code defined by SAP, customization

goes deeper and requires additional code in ABAP, SAP’s programming language.

However, customization of standard software is often frowned upon. Experts per-

ceive any deviation from the standard as a potential heachache when it comes to

future upgrades. This leaves customers in a dilemma, as shown in the following

light-hearted illustration.

A Customer’s Enhancement Dilemma

13

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

第 14 页 / 共 265 页

Preface

Over the past 20 years, however, SAP has worked hard to allow its customers to

slightly adjust key processes if necessary, yet still remain on the upgrade path.

This is enabled by different kinds of technologies such as exits, business add-ins

(BAdIs), and the more recent introduction of the Enhancement Framework. These

technologies support ABAP code customizations and play a major role when modi-

fying SAP’s standard ABAP delivery.

About This Book

This book is predominantly based on my own consulting experience and tasks I

have worked on over the years. I have tried to include helpful, real-world examples

of varying difficulty and complexity.

Chapter 1 provides background information and comparisons of the different

enhancement techniques used in this book. After this, Chapter 2 through Chapter

11 will show you how to do the following:

EE Add new field validations for a sales order.

EE Capture additional data in custom fields within Transactions VA01/02.

EE Automatically create a SAP CRM activity after billing cancellation.

EE Filter pricing data within a SAP standard web service for order confirmation.

EE Add custom fields within SD pricing.

EE Set a delivery block from new validation within a code enhancement.

EE Use a BAdI to keep track of delivery KPIs within a little custom reporting system.

EE Enhance a standard delivery monitor report to include custom KPI data.

EE Split invoice items into separate documents by using a VOFM routine.

EE Change the reference field and numbering range while a new invoice is created.

Chapter 12 then summarizes the techniques and enhancement methods. Lastly,

Chapter 13 concludes with an outlook on ERP enhancements and their role in the

future.

Within the appendices you will find an overview of all SD-related exits and BAdIs,

as well as one of the longer coding examples (which can also be found online).

14

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

第 15 页 / 共 265 页

Preface

Who Benefits from This Book

This book will be beneficial to the following groups of people:

EE ABAP developers (beginner, intermediate)

EE SD consultants (all levels of experience)

EE Support consultants (all levels of experience)

EE SAP architects (all levels of experience)

EE Project team members who require a deeper understanding of how to enhance

standard SAP ERP

System Prerequisites

All examples in this book have been created and tested in a SAP ECC 6.06 system on

SAP NetWeaver AS ABAP 7.31. However, none of the shown examples require such

a recent release level (as of July 2012) and any SAP ECC 6.0 and SAP NetWeaver

AS ABAP 7.x and above will suffice. If you work on earlier releases, some of the

newer enhancement techniques such as BAdIs or the Enhancement Framework

might not be available.

If in doubt, refer to the overviews in Chapter 1 to check whether an enhancement

point or BAdI is available within the application release you are using.

Fictional Project

Software development doesn’t take place in a vacuum, and most of the time there

are underlying pains and purposes for it. The same goes for any enhancements to

SAP systems, which invariably often stem from business requirements. Therefore,

simply showcasing the most common exits and enhancements with instructions on

how to implement them doesn’t reach far enough. It’s important to tell a business

story. It’s equally important for IT professionals to realize this concept and have a

grasp of the business story behind a proposed change.

You’ll find that this book mirrors the “real world” as much as possible. Throughout

the course of this book, I have used stories and anecdotes from a fictional project

to better illustrate the discussed topics.

15

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

第 16 页 / 共 265 页

Preface

You’ll come across a junior ABAP developer and a senior SD consultant, who will

accompany you on your learning journey. So let’s meet the business, Sean, and

Christine…

The Byrell Corporation

Byrell Corporation has been trading for more than 50 years as a logistics business

with depots and warehouses in various locations on the British Isles. The company

has been growing steadily over the past 40 years, in particular in the past 20, which

among other things led to the board’s decision to implement SAP R/3 and replace

the various legacy systems previously in place. Apart from the traditional haulage

business, Byrell also offers storage and warehousing solutions, based on its SAP

systems and custom developments.

In 2004, Byrell decided to add SAP CRM alongside its SAP ERP system to offer its

customers a better integration of opportunity management and quotations.

Byrell envisages an upgrade to the latest SAP ECC Enhancement Pack in the near

future and has already instructed its SAP team to prepare for this.

Sean, Senior SD Consultant

Sean has been with the Byrell Corporation for more than 30 years now. He started

with Byrell when he was in his early twenties, working as a packer in the warehouse.

Over the years, his bosses recognized his technical aptitude and gave him the option

to cross over into IT, where he played a pivotal role in the implementation of SAP

R/3 3.1i in 1995. Since then, he has worked on other major upgrades, all the way

to the current SAP ECC 6.0 release. Apart from his upgrade project work, Sean

deals with smaller SD support and improvements, liaising between business and IT.

Sean acknowledges that SAP ERP has changed a lot since its first implementation

at Byrell back in 1995. He is well versed with how to enhance the SD module

using user exits, but newer enhancement methods such as business add-ins often

raise a few questions. He also realizes that over the same period of time, the ABAP

language has become more sophisticated. A lot of the code that he looks at during

his support work is not always understandable for him. For some time now, he

has vowed to refresh his ABAP knowledge, but work pressures and deadlines have

prevented this so far.

16

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

第 17 页 / 共 265 页

Preface

Sean’s role is to understand the functional side of new development requirements,

write specifications for Christine, and apply any necessary SD configuration, if

needed.

Christine, Junior ABAP Developer

Christine started at Byrell last year as part of the company’s graduate program. She

came straight from the university, where she studied computing. Christine’s first

real programming language was Java at college, which introduced her to object-

oriented (OO) programming right from the start. During some of her college and

university assignments, she also picked up XHTML, Cascading Style Sheets (CSS),

and a little bit of JavaScript. Christine loves coding and spends a lot of her spare

time in front of computers.

Last year after Christine started at Byrell, she was sent to a couple of introductory

ABAP training courses, which taught her all about report programming, screen

(Dynpro) development, and ABAP OO. She was delighted that there was such a

thing as object orientation in ABAP and has been using her new OO skills on many

occasions. Recently Christine has also attended a course on the SAP Enhancement

Framework, because her skills will be required to help Sean with some of the SD

development requests coming out of support issues. In addition, there is also an SAP

ECC upgrade project on the horizon, which might require some of Christine’s time.

Christine’s role is to provide technical consultancy input to new development

requirements and to create ABAP code per Sean’s functional specifications.

Acknowledgments

Working on this book has been rewarding, insightful and taxing, but most of all it

has been an extreme honor.

First of all, a big thank you goes out to the SAP Mentor initiative, which allowed

me to reach out and receive assistance from such great individuals as Mark “wolf

pack leader” Finnern, Matthias Steiner, and Thomas Jung, who helped me to get

in touch with the right people within SAP for this project. Most of all, I would like

to thank Martin Lang of SAP, who was instrumental in providing access to systems

where I could code and test the solutions for this book.

17

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

第 18 页 / 共 265 页

Preface

Moreover, this book would have never come to fruition without the initiative,

hard work, determination, trust, and patience of Kelly Harris and Laura Korslund

of SAP PRESS. Writing a book such as this is bound to come with a few ups and

downs. Kelly and Laura’s experience and assistance certainly helped in coping with

some of them.

I would also like to thank friends and colleagues, namely Peter Richardson, Zoe Gill,

Arpit Oberoi, Ben McGrail, Stefan Karaivanov, Thomas Otter, and Nick Watkins,

whose feedback, professional advice, criticism, and ideas were essential during

the entire duration of writing this book. In particular I would like to thank Cath

Laursen and Arran McMillan for their assistance with questions around SAP CRM.

Special thanks also go out to Stuart Trotter of Rockpool Children’s Books (http://

rockpoolchildrensbooks.com), who helped me to transfer my idea for the “SAP SD”

illustration from my brain and onto paper and screen.

Finally, I want to express my love and gratefulness to my wife Sally and our

beautiful daughters Milly and Hannah, who have all been helpful and supportive

throughout the realization of this project. Sally, Milly, and Hannah—a lot of this

book is also due to you! Thank you for giving me your understanding and patience

to fulfill this dream.

18

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

第 19 页 / 共 265 页

The Enhancement and Switch Framework, along with exits and routines, are

used to enhance SAP Sales and Distribution systems. In this chapter, you’ll

learn the differences between each of the enhancement techniques and where

to find them.

1 Introduction to Enhancements

in Sales and Distribution

Before introducing the different ways you can enhance the existing Sales and

Distribution (SD) functionality with ABAP code, you need to understand that any

customization applied to the SAP standard code should always be the last resort

and the end result of vigorous contemplation. Why?

SD is standard software, like many enterprise resource planning (ERP) solutions.

Most businesses introduced SD to reap the benefits of standard software. Here is

a non-exhaustive list of the typical benefits a business can gain from using SD:

EE Stability

EE Cost efficiency

EE Upgradability

EE Leveraging best practices

In other words, by creating custom code enhancements to your SD component, you

are introducing new software objects that might have a detrimental effect on some

or all of the benefits just listed. Therefore, it’s important to analyze, understand,

and communicate the potential impact of any code customization.

Before undertaking any custom enhancements using ABAP code, developers need

to consider the following five important questions:

1. Could SAP standard functionality solve your problem?

2. Have you searched SAP Marketplace (http://service.sap.com) for SAP Notes, which

might help you with your problem?

19

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

第 20 页 / 共 265 页

1 Introduction to Enhancements in Sales and Distribution

3. Can the same be achieved using Customizing?

4. Is there already an existing customization object, in which the envisaged change

could be incorporated?

5. Have you discussed the problem with functional consultants and other team

members?

Important

You should only implement code customizations if you’re satisfied that the answers to

these questions do not suggest an alternative solution.

Routines, user exits, and customer exits (in some parts) leave a fair amount of

responsibility with the customer. User exits, for example, have no defined inter-

faces, meaning all fields and tables are available to the developer. Therefore, any

incorrect use of the available fields and tables can lead to undesired results.

It’s important for developers to explore alternatives before embarking on the imple-

mentation of any customer-defined routine or user exit. Developers must keep the

checkpoints in mind that were laid out in the introduction of this chapter before

proceeding with implementing an enhancement.

Tips & Tricks

For further information, refer to SAP Note 381348, “Using User Exit, Customer Exit,

VOFM in SD.”

1.1 Enhancing Standard SD Functionality

SAP offers more than one method or technology to customize and enhance its off-

the-shelf SD functionality. To give you an overview, Figure 1.1 shows a mind map

of these methods and technologies. A flag indicates that the particular method is

covered in this book.

As shown in the mind map, the main emphasis of this book is on exits, the Enhance-

ment Framework, and customer-defined routines. This is not to say that all other

techniques shown (Customizing, personalization, and business transaction events)

are of no importance. However, in terms of custom code enhancements, these

methods are not as relevant as exits, BAdIs, and customer-defined routines. Also,

20

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

Important
You should only implement code customizations if you’re satisfied that the answers to these questions do not suggest an alternative solution.
Tips & Tricks
For further information, refer to SAP Note 381348, “Using User Exit, Customer Exit, VOFM in SD.”

第 21 页 / 共 265 页

Enhancing Standard SD Functionality 1.1

there are situations where modifications cannot be avoided (see Chapter 2 and

Chapter 13 for details).

Kernel-based BAdIs

Implicit enhancements

Enhancement and Switch

Classic BAdIs

Framework

Explicit enhancements

Enhancement points

Enhancement sections

User exits Menu exits

Enhancing SD Exits

Customer exits Screen exits

Function module exits

Modifications

Customer-defined routines/rules VOFM tool

Customizing

Personalization

Business transaction events

Figure 1.1 SD Enhancements Mind Map

In the following sections, we introduce exits, the Enhancement Framework, and

customer-defined routines in more detail. This chapter will conclude with a com-

parison of enhancement techniques, which should help you make the right enhance-

ment choice in your own projects.

1.1.1 Exits

Up to SAP release 4.6, exits were the only way to truly enhance SAP standard cod-

ing. (From release 4.6A onward, business add-ins (BAdIs) were introduced, which

are discussed in Chapter 2, Section 2.3.)

SAP created exits when it developed the standard code and put these into places

where customers need more flexibility. Exits are empty or inactive when delivered

and can be completed by customers as needed. Exits provide the following advan-

tages, especially when compared to modifications:

21

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

第 22 页 / 共 265 页

1 Introduction to Enhancements in Sales and Distribution

EE Developed objects do not affect standard coding and are held separately, in their

own customer namespace.

EE During an upgrade project, most exits remain and do not affect the upgraded

system (there are some exceptions, see the comparison tables in Section 1.4 of

this chapter for details).

In the following sections, we’ll discuss the different types of exits and distinguish

them by explaining their implementation and features.

More often than not, user exits and customer exits are mixed up or even regarded

as the same thing. In fact, the differences between them are more evolutionary,

yet important to understand.

User Exits

User exits are preplanned exit routines in standard SD coding, which means SAP

has intentionally left them empty within the standard code. User exits can only

be found within the SD component. Historically, when regarded from a technical

perspective, user exits required modifications. However, this changed with the

emergence of the Enhancement Framework, which we’ll discuss in Section 1.3.

User exits are sometimes also referred to as form exits because they are actually

form subroutines.

Finding and Accessing User Exits

As an example, let’s find a user exit that is called just before a sales document is

saved. There are two different ways to find user exits:

EE Via the Implementation Guide (IMG)

Go to Sales And Distribution • System Modifications • User Exits • User

Exits In Sales • User Exits In Sales Document Processing. Click on the node

to open the ABAP Editor. In the Program field, enter “MV45AFZZ” as the name

of the include program that holds the crucial user exit in this case. Click on the

Display button to view the different form exit routines (see Figure 1.2).

EE Via the assigned package

You can also find all user exits by displaying all include programs within pack-

age VMOD. Run Transaction SE80, choose Package from the dropdown box,

enter “VMOD” as the name of the package, and press [Enter]. If you expand the

Includes folder, you can find all SD user exit include programs holding the dif-

ferent user exits (see Figure 1.3).

22

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

第 23 页 / 共 265 页

Enhancing Standard SD Functionality 1.1

Figure 1.2 Finding User Exits with the IMG

Figure 1.3 Include MV45AFZZ with User Exit USEREXIT_SAVE_DOCUMENT

23

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

第 24 页 / 共 265 页

1 Introduction to Enhancements in Sales and Distribution

Note

User exits are identified by the prefix USEREXIT.

In the past, the actual user exit coding had to be done using a modification, and it

was advisable to use include programs that were assigned to a module pool within

the customer’s namespace (beginning with Y* or Z*). Within this include program

is where you could code for any changes that you wanted to make to the system.

Example

This listing shows an example of a user exit using the include technique, which points to

a program with the customer namespace—in this case ZZ_USEREXIT_SAVE_DOCUMENT.

FORM USEREXIT_SAVE_DOCUMENT.

INCLUDE ZZ_USEREXIT_SAVE_DOCUMENT.

ENDFORM.

Note

These include programs are always processed during the program flow, and there is no

built-in way to switch them on or off.

Figure 1.4 Implicit Enhancement Placed within User Exit USEREXIT_MOVE_FIELD_TO_VBAK

24

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

Note
User exits are identified by the prefix USEREXIT.
Example
This listing shows an example of a user exit using the include technique, which points to a program with the customer namespace—in this case ZZ_USEREXIT_SAVE_DOCUMENT. FORM USEREXIT_SAVE_DOCUMENT. INCLUDE ZZ_USEREXIT_SAVE_DOCUMENT. ENDFORM.
Note
These include programs are always processed during the program flow, and there is no built-in way to switch them on or off.

第 25 页 / 共 265 页

Enhancing Standard SD Functionality 1.1

However, with the introduction of the SAP Enhancement Framework, it’s possible

to fill user exits with modification-free, switchable code enhancements. Figure 1.4

shows an implicit enhancement placed into form routine USEREXIT_MOVE_FIELD_

TO_VBAK using the Enhancement Framework.

Note

SAP’s Enhancement Framework and implicit enhancements are introduced in more

detail in Section 1.3.

Customer Exits

SAP Online Help describes customer exits as follows:

The enhancement concept allows you to add your own functionality to

SAP’s standard business applications without having to modify the original

applications. SAP creates customer exits for specific programs, screens,

and menus within standard applications. These exits do not contain any

functionality. Instead, the customer exits act as hooks. You can hang your own

add-on functionality onto these hooks.

Customer exits are part of SAP’s enhancement concept, which offers the following

advantages:

EE They don’t affect standard code.

EE Because customer exits are created within the customer’s namespace, no stan-

dard code is modified.

EE They don’t affect software upgrades.

EE Strict naming conventions prevent clashing development objects (customer

objects) or even loss of enhancements when the SAP standard code is upgraded.

EE They can be switched on or off.

EE They have defined exit interfaces.

Using Transaction CMOD, customers can switch individual customer exits on or

off, which can be very helpful if a specific enhancement is causing problems. A

green light indicates the exit is active. Figure 1.5 shows a Delivery Monitor user

exit with two function module exits assigned to it.

25

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

Note
SAP’s Enhancement Framework and implicit enhancements are introduced in more detail in Section 1.3.

第 26 页 / 共 265 页

1 Introduction to Enhancements in Sales and Distribution

Figure 1.5 Customer Exit V50Q0001 for Delivery Monitor with Two Active Function Module Exits

Tips & Tricks

The upcoming “Finding and Accessing Customer Exits” section shows how to find and

browse customer exits in more detail.

Customer exits wrap the enhancement functionality, which prevents any other

changes to global variables. Defined interfaces make a significant change to enhance-

ments and their overall stability (see Figure 1.6).

Figure 1.6 A Customer Exit with Strict Input/Output Parameters

Note

Although the function module exit was created by SAP, the include ZXVVFU08 resides

in the customer namespace.

26

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

Tips & Tricks
The upcoming “Finding and Accessing Customer Exits” section shows how to find and browse customer exits in more detail.
Note
Although the function module exit was created by SAP, the include ZXVVFU08 resides in the customer namespace.

第 27 页 / 共 265 页

Enhancing Standard SD Functionality 1.1

Types of Customer Exits

There are three types of customer exits:

EE Screen exits

Screen exits add fields to screens in applications. SAP creates screen exits by

placing special subscreen areas on a standard screen and calling a customer sub-

screen from the standard screen’s flow logic.

EE Menu exits

Menu exits add items to the dropdown menus in standard SAP applications. You

can use these menu items to call up your own screens or to trigger entire add-

on applications.

SAP creates menu exits by defining special menu items in the Menu Painter.

These special entries have function codes that begin with “+” (a plus sign). You

specify the menu item’s text when activating the item in an add-on project.

Figure 1.7 shows an assignment of a menu exit within sales activities to view

contact history.

Figure 1.7 Customer Menu Exit V43A3X1 Implemented and Showing as a Menu Item in

Transaction CV01N (Create Sales Activity)

27

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

返回ABAP参考资料列表