Professional Documents
Culture Documents
REVISION HISTORY
Date
Prepared/Changed By
Authorized by
Description
27.03.2012
Baselined
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 2 of 33
Contents
1 2 3 4 5
Purpose ......................................................................................................... 4 Scope: ............................................................................................................ 4 Prerequisites ................................................................................................. 4 Introduction ................................................................................................... 4 Types of Enhancement................................................................................. 4
5.1 5.2 5.3 User Exit ......................................................................................................................... 4 Customer Exits: .............................................................................................................. 9 Business Add-Ins (BADI) .............................................................................................. 25
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 3 of 33
1 Purpose
The purpose of this guide is to understand the enhancement concept that can be used to add the custom features inside the standard SAP programs.
Scope:
This document explains that how to find the Enhancement and how to implement that enhancement for custom use.
Prerequisites
Before using this document, the respective consultant should be aware of the include programs, function module and the ABAP OOPS concepts and also some knowledge of module pool.
Introduction
Enhancement is a way provided by the SAP using which we can provide the additional functionality to the standard SAP programs. In other way we can say that enhancements are like the hooks in the standard program where we can attach our own code to provide the additional functionality.
Note:
We should always remember one thing that, enhancements are never referred to as a modification, i.e. it never alters the flow of the standard program. That's why we should never write such a code during the enhancements that can alter the flow of the standard program.
Types of Enhancement.
There are various types of enhancement technique that is provided by the SAP: User Exit Customer exit Business Add-Ins(BADI)
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 4 of 33
These are implemented in the form of subroutines and hence are also known as FORM EXITs. And these routines will be available in some include of the standard program that generally ends with the letter 'ZZ'(Eg MV45AFZZ). The user exits are generally collected in includes and attached to the standard program by the SAP. All User exit starts with the world USEREXIT. We generally write our all code in a include that will be present in the routine and will start with the letter 'Z'
Eg: Form Userexit_.. Include ZXXXXXX. EndForm. The problem that lies here is in finding the correct userexit and how to find it if one exists for the required purpose. Once the correct userexit is found the necessary customer code is inserted in the customer include starting with the z.. in the form routine.
5.1.1. HOW TO FIND USEREXITS There are number of ways to find the user exits a) One way is find the program name of your transaction and go to the SE38 transaction and look for the word userexit. (using Find option - ctrl+f) b) The other method of finding userexits is to find the include in case of SD/MM applications where the userexits are located, this can be found in the SAP reference IMG generally in the sub folder under SYSTEM MODIFICATION.(use Transaction SPRO) Eg: Go to SPRO transaction and click on the following options.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 5 of 33
Then using the following hierarchy you can get the user exit for the sales and distributions applications.
Each exit is provided with well documentation, using that you can find the one which will be suitable for your requirement.
c) To find userexits in SD module, go to object navigator (SE80) and select Package from the list and enter VMOD in it. All of the userexits in SD are contained in the development class VMOD. Press enter and you will find all the includes which contain userexits in SD for different functions like PRICING, ORDER PROCESSING etc. Select the userexit according to the requirement and read the comment inserted in it and start coding.
E.g. Let's take a scenario to add a validation in sale order creation (Tcode VA01), so that the quantity field for the line item should not be less than 2 units
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 6 of 33
Now you can see all the user exit available for the SD.(But you can modify only those subroutine which is already implemented or you have the access key to modify the routine) In our case we have to implement the MV45AFZZ which have already a z.. include in the routine so we dont need the access key . So we can write our code there.
As we can see that there is a include ZMV45AFZZ_SAVE_DOCUMENT_PREP. So double click on the include and write the following code there. data: lv_flag(1) type c.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 7 of 33
* exit if not SAVE if sy-ucomm ne SICH. leave to screen sy-dynnr. endif. * check line items clear lv_flag. loop at xvbap where updkz ne D. * This checks for quantity less than 2 * As xvbap-kwmeng is pack with 3 decimal we are comparing with 2000 if xvbap-kwmeng < 2000. message i000(fb) with quantity is less than 2. lv_flag = X. clear sy-ucomm. exit. endif. endloop. if lv_flag = X. leave to screen sy-dynnr. endif. Now start the transaction VA01 and create a sales document and give the value in the quantity field less than 2.(you will get the message as following, if everything is fine)
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 8 of 33
Note:
Certain application like Sales and distribution (SD) still provide this form of enhancement using userexit but this practice is no longer being followed for newer extensions. There is a disadvantage with the user exit that user have the access of all global data(tables, structures, and so forth) of the program and can modify them ,that can alter the flow of the standard program and may lead to errors in further process. And another disadvantage in the user exit is that, it requires the access key to implement the routines. And also if you want to deactivate your changes then you have to navigate to the code and you have to delete or comment your code. (To overcome these disadvantages SAP came up with a new concept called Customer exit)
There are three main types of customer exits: 1. Function Module Exits 2. Screen Exits 3. Menu exits
2: Menu Exit
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 9 of 33
It allows customer to add items to a pulldown menu in a standard SAP program. These items may be used to call add-on programs or custom screens. Format: +CUS (additional item in GUI status )
3 : Screen Exit:
It allows customer to add fields to a screen in an SAP program via a subscreen. The subscreen is called within the standard screens flow logic. Format: CALL CUSTOMER-SUBSCREEN CUSTSCR2
Before we go to find the customer exit function module we should know that in the main program we call the function module using the following statement: CALL CUSTOMER-FUNCTION XXX Here XXX is the three digit code. And the function module that will be called using this statement will be of following format: 'EXIT_YYYYYYY_XXX' Here YYYYYYY is the program name that is calling the function module and XXX is the three digit code same as in call function call statement.
There are some approaches to find the appropriate customer exit is following: 5.2.1.1: Using Debugger
This is the best approach to find the customer exit. Start the transaction in which you want to find out the exit. Before executing the transaction, start the dynamic debugger using '/h' . Now go to the debugger options 'breakpoint at statement' and set the break point at statement 'Call Customer Function '. Now use the f8 and your program flow will stop at the each exit that are the available for this transaction.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 10 of 33
Find out the appropriate exit for your requirement by looking the import and export parameter of the function module.( later discussed in example )
Eg:
Suppose you want to see the exits that are available for the transaction VA01. Go to the tcode VA01 then in menu select systemstatus.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 11 of 33
Click on the search option and give the "call customer-function" statement.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 12 of 33
So following are the customer exit that are available in your program.
Eg:
Suppose you want to see the user exits that are available for the transaction VA01 Go to the tcode SE93 and give the your tcode.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 13 of 33
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 14 of 33
So we can identify the user-exits by matching the first 4 letters of each user-exit name with the last four letters of the program name. In our case program name is SAPMV454 . So in the following list we can see that there are 4 exits available for us that are starting with " V454".
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 15 of 33
5.2.2 How to implement an exit: Following are the steps that we have to follow: First find out the customer exit by using any of the above described methods. Go to the CMOD and create a project. Go to the enhancement option and give the enhancement code that contain the user exit(enhancement code you can get from the SMOD transaction) Note: These enhancements can only be used in 1 project. Go to the Components screen (where the available customer exits are displayed). Choose your function module and implement the include present in that, for that you need to provide the package and transport request. Activate the include program. Go back to CMOD and activate the project.
5.2.2.1 E.g.: Let's take a scenario to add a validation in sales order creation (Tcode VA01), so that the quantity field for the line item should not be less than 2 units.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 16 of 33
Go to the transaction VA01 and get the technical information of the quantity field. By pressing F1 key after placing cursor on that field and then clicking on following icon.
After this you will see the complete detail of the field(here field element is "KWMENG" that is used in VBAP table) So we need to look in the VBAP table. Now start the debugger and set the break point at statement "call customerfunction" as following.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 17 of 33
Now break point will be set at all customer exit .here we will get a 'call function 003' which has the VBAP table as parameter. So we can use it for our requirment. Now go to SMOD transaction and get the enhancement code which is' V45A0003' in our case. Now go to CMOD transaction and create a project. Give the sort text and click the option 'enhancement assignments' and provide the enhancement code.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 18 of 33
It will redirect you to function module. There is an include in which you write your code and activate the include and the project and run the VA01 transaction again and give the quantity less than 2 you will see the following message.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 19 of 33
5.2.2.2 E.g. Before going to implement the screen exit we should know the following things : We can find the screen exit using SMOD transaction by selecting the Screen exit option.
Along with the screen exit we also need the table exit , using that we will add the field in table also that we want to be added in the screen. And also we need two function modules , one to fetch the data from the screen(it will be called in PBO) and another to display the data in the screen field(it will be called inPAI) All these function modules and table exit will be available in the component list of the screen enhancement.
Let's take a scenario for the screen exit, in which we want to add a field in item level data in the transaction ME22N. First find the screen exit from the above method in our case it is MM06E005.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 20 of 33
Click on Create and give the short description and click on the enhancement and give the enhancement code .
Now click on the component and you will see the following list . It will show the Function EXITs, Screen EXITs and few includes for the table. You can use the following table include to add your field in the table.(it will redirect you to se11).
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 21 of 33
Add your field here and activate it(it may take some extra time)
As we have seen that there are many screen exit but each have different screen no.(here 0101 is for the header and 0111 is for the item detail ) Because we need to add the field in the item detail, click on the 0111 screen and it will redirect you to the SE51. So add you field there(in our case 'potype'). For this provide the label and click on the button Dict./Program fields(or press f6).
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 22 of 33
Following window will appear give the 'EKPO_CI-POTYPE' in the table field option.(EKPO_CI table, POTYPE field)
After this we need to implement the two function modules 1. EXIT_SAPMM06E_016: To get the value from the screen field. 2. EXIT_SAPMM06E_018: To set the value to the screen field. For the example purpose, put the following line of code in EXIT_SAPMM06E_016. EKPO_CI-ZZPOTYP = ABCD.
Save your project and start the transaction, you will see your custom field there(in the Customer Data Tab).
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 23 of 33
Note:
Customer exits have several advantages over user exits as follows : It is more restricted than user exit , means that the Data variable that a user can use is fixed by the SAP in the form of importing and exporting parameters. By deactivating the project you can deactivate your changes, no need to remove or comment your code. Access key is not required for enhancement.
Still there are some disadvantage in the customer exits like : All users have to use the same function module.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 24 of 33
One enhancement can be used by only one project.(so to overcome this SAP comes with a new concept Business Add-Ins(BADI) which is based on the OOPS concepts)
There are three types of BADI: 1. Single Instance 2. Multiple Instance 3. Filter BADI
Single Instance: For single instance there will be only one implementation for given BADI. And also we need the access key to implement the BADI. Multiple Instances: For multiple instance we can provide more than one implementation and each will be executed one after the other. And execution order can be in any sequence. Filter BADI: In filter BADI we provide a filter condition. For filter BADI there will be multiple implementations but among them only few will be executed according the filter condition.
You can identify you BADI type using SE18 Transaction . Go to the Tcode SE18 and provide the BADI name and click on display.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 25 of 33
NOTE: Each BADI have one interface and one adapter class. We implement the interface and add custom code in the implementation of the interface method. Whereas adapter class is created by the enhancement management, which have the following task: Control:The adapter class calls the active implementations. Filtering:If a Business Add-In is to be executed only under certain conditions, the adapter class ensures that only certain implementations will be executed. (The adapter class method generated by add-in management decides if one or several active implementations should be called. If necessary, these implementations are subsequently executed. The application program ensures only that the adapter class method is called. The application program does not know which implementations are called.) 5.3.1 How to find the BADI: Using CL_EXITHANDLER class: Run your transaction for which you want to find the BADI. Start the debugger using '/h'. Put the break point at method GET_INSTANCE or GET_CLASS_NAME_BY_INTERFACE of class CL_EXITHANDLER. Use f8 it will stop at each BADI and you can get BADI name in EXIT_NAME parameter of the method.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 26 of 33
Using SE84: Go to the transaction SE84. Follow the following steps (Repository information systemenhancementdefinitions) Provide the package name and the list of all BADI will appear.
E.g. Suppose you want the BADI for VA01 transaction we know that package name is 'VA'. Go to the TCODE SE84 and follow the following steps(Repository information systemenhancementdefinitions)
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 27 of 33
Following list will come with all available BADI.Select your BADI and impliment it in SE19.
Using SE18: In the same way as privious Go to the SE18 and press f4 after selecting the BADI name radio button. Provide the package name and execute. You will get list of all BADI(if selection popup is not coming then click on the NEW SELECTION)
5.3.3 How to impmliment a BADI First find the your BADI using above methods. Go to the transaction SE19 and provide the BADI name and click on the implementation.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 28 of 33
It will ask for the implimentation name give the implementationm name.
A class will created with the interface . Select interface tab, select the your method and implement that. Come back and activate the implementation .
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 29 of 33
E.g. Let's take scenario that display an information message while user create a material for Material Group is 03.
First we need to find the BADI name, for this start the transaction MM10 and start the debugger. And navigate to the following steps.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 30 of 33
Press f8 check the method parameter exit_name, you will find a BADI with name BADI_MATERIAL_CHECK. Go to the transaction se19 and provide the BADI name and click on implementation.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 31 of 33
Give the sort description ,and go to the interface tab and click on the method CHECK_DATA.
It will ask for the package name, give the package name and write the following code there.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 32 of 33
Activate the method, come back and activate the implementation. Now to see your changes go to the transaction and create the Material for Material Group is 03.
HOW TO GUIDE
PROPRIETARY & CONFIDENTIAL
Page 33 of 33