user exits

21
0007 - User Exits by Rich » Thu Mar 26, 2009 11:51 am User Exits. What Are they. User Exits are a method whereby the end user can add extra functionality or change to a certain degree the way that SAP performs certain functions. These user exits are created in various ways depending on where in the system they are, and in view of this, this topic has been split into various parts. Part One deals with normal user exits. These are user exits that have nothing to do with SD or the Validations, Substitutions and Rules used in FI. Part Two deals with User Exits in SD, and finally Part Three deals with the user exits available in the Validations etc in FI. 0007a - Standard User Exits by Rich » Thu Mar 26, 2009 11:51 am How are they implemented ? User Exits are implemented in such a way that unlike changes to SAP standard code, they will survive across upgrades and hot pack applications. They are also User Objects and can therefore be implemented without the need of requesting an SSCR from SAP. Within the standard SAP programs at key points are calls to function modules starting with 'EXIT_'. These function modules generally accept as input parameters structures containing for example the entire Order Header (VBAK) of the sales order just entered, or perhaps a table of the Order Items. These function calls are placed at points such as just before the Order is saved or just before it is printed and so on. These function modules contain a single include statement. The name of this include is in the User domain and starts with Z. This enables it to be edited without the need for an SSCR and also prevents it being overwritten during upgrades. Once this include has been created and activated, and the user exit is activated the User exit becomes functional. Implementing a User Exit.

Upload: maxblank

Post on 25-Apr-2017

274 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: User Exits

0007 - User Exits

by Rich » Thu Mar 26, 2009 11:51 am

User Exits. What Are they. User Exits are a method whereby the end user can add extra functionality or change to a certain degree the way that SAP performs certain functions. These user exits are created in various ways depending on where in the system they are, and in view of this, this topic has been split into various parts.

• Part One deals with normal user exits. These are user exits that have nothing to do with SD or the Validations, Substitutions and Rules used in FI. • Part Two deals with User Exits in SD, and finally • Part Three deals with the user exits available in the Validations etc in FI.

0007a - Standard User Exits

by Rich » Thu Mar 26, 2009 11:51 am

How are they implemented ? User Exits are implemented in such a way that unlike changes to SAP standard code, they will survive across upgrades and hot pack applications. They are also User Objects and can therefore be implemented without the need of requesting an SSCR from SAP. Within the standard SAP programs at key points are calls to function modules starting with 'EXIT_'. These function modules generally accept as input parameters structures containing for example the entire Order Header (VBAK) of the sales order just entered, or perhaps a table of the Order Items. These function calls are placed at points such as just before the Order is saved or just before it is printed and so on. These function modules contain a single include statement. The name of this include is in the User domain and starts with Z. This enables it to be edited without the need for an SSCR and also prevents it being overwritten during upgrades. Once this include has been created and activated, and the user exit is activated the User exit becomes functional. Implementing a User Exit.

Page 2: User Exits

User Exits are implemented using the transaction code 'CMOD'. Enter this in the command line and press the Enter key. This will then show the CMOD parameter screen:

User Exits are assigned a project name which begins with Z. Having entered the relevant name in the 'Project' field, click the Create (or Change) button as applicable. When you are creating a new project, the projects attribute screen will be displayed. This allows you to enter a title for the project and allows access to the Enhancements (User Exits) that you want to assign to the project and the components that you wish to use within those enhancements. This screen allows you to enter a description of the project. Once you have done this, click the save button. You will be asked as usual to assign a development class and create a transport. Once the transport has been created you can then go on to assign the enhancements that you wish to use to the project.

Page 3: User Exits

Locating The Enhancements For A Project. Unfortunately I have access to a 4.6C system only so therefore this description is based around that. To find enhancements for a particular program locate the Development Class for the relevant program. Run the transaction and on the first input screen click on the Status button. This provides the program name. Another method of finding the program name is to use transaction SE93 which is the Create/Modify Transaction transaction. Enter the transaction code and click display. In either case, cut the program name and then enter it into transaction SE38 – the ABAP program editor. Select the ‘Attributes’ radio button and click display. Note the Development Class. In 46C, go back to the CMOD main screen, enter the project name and select the ‘Enhancement Assignment’ radio button. Click the change button. This will display the enhancement assignment screen. Position the cursor in the first field and press the <F4> key. This will display the Input Help personal list window, a standard window that you should be familiar with. Click the ‘Information System’ button and enter the development class located above into the development class field. Click the green tick.

This will display a list of enhancements for that particular development category with a short description of what they do.

Page 4: User Exits

Select relevant description which will be transferred back to the Enhancement Assignment screen. For versions other than 46C, use transaction SE37 which is the Function Module editor, in the function module name field press the <F4> key and select further options. One of these will be the development class. Clicking the enhancement button provides information on the enhancement. The information displayed in this report includes whether the enhancement has been implemented, and is active. (Green things scattered throughout the report). Clicking the Exit name (In this case ‘EXIT_SAPLV60A_002’ will display the relevant function module: To create the enhancement, double click the Include name. This then takes you into SE38 where you can edit the include to your hearts content. Note, however, that when you try and create this include you will get a warning message displayed that the namespace you are trying to use belongs to SAP. Just click on the green tick and sail straight through.

• Return to 0007 - User Exits • Read 0007b - User Exits In SD • Read 0007c - User Exits In Validations, Substitutions And Rules.

0007b - User Exits In SD

by Rich » Thu Mar 26, 2009 11:52 am

User Exits In SD.

Page 5: User Exits

User Exits in the SD module are implemented in a very different manner. Essentially what SAP have done is to provide a series of includes that contain procedures that are called regardless of whether they have been implemented or not. No sophistication unlike the other User Exits mentioned above. The includes that you need to look at are:

MV45AFZ4 MV45AFZA MV45AFZB MV45AFZB_USEREXIT_CHECK_VBAK MV45AFZB_USEREXIT_FILL_VBAP_FR MV45AFZC MV45AFZD MV45AFZF MV45AFZH MV45AFZU MV45AFZZ MV45AFZZ_FCODE_KKON_REDIRECT MV45AFZZ_FCODE_PKON_REDIRECT MV45AFZZ_USEREXIT_FIELD_MODIFI

Each of these includes contains different procedures for different user exits. You will have to check each one to find the one that you require. You implement your Exit something like the following:

*---------------------------------------------------------------------* * FORM USEREXIT_SAVE_DOCUMENT * *---------------------------------------------------------------------* * This userexit can be used to save data in additional tables * * when a document is saved. * * * * If field T180-TRTYP contents 'H', the document will be * * created, else it will be changed. * * * * This form is called at from form BELEG_SICHERN, before COMMIT * * * *---------------------------------------------------------------------* FORM USEREXIT_SAVE_DOCUMENT. * Example: * CALL FUNCTION 'ZZ_EXAMPLE' * IN UPDATE TASK * EXPORTING * ZZTAB = ZZTAB.

Page 6: User Exits

*{ INSERT CADK903250 1 * Constants: c_Sales_Order type VbTyp value 'C', c_Order_Without_Charge type VbTyp value 'I', c_Transaction_Type_Add type TrTyp value 'H'. * * If Vbak-Vbtyp = c_Sales_Order or Vbak-Vbtyp = c_Order_Without_Charge. * * Creation or Change ?? * If t180-TrTyp = c_Transaction_Type_Add. * * Do NOT change the order of these calls. * Call Function 'Z_XXXXXXXXXXXXXXXXX' Exporting Vbak = Vbak Bsark = Vbkd-Bsark. Call Function 'Z_XXXXXXXXXXXXXXXXXXXXX' Starting New Task Vbak-Vbeln Exporting Vbak = Vbak Ship_To = Kuwev-Kunnr Delivery_Date = Rv45a-KetDat Delivery_Plant = Rv45a-Dwerk Tables Vbap = xVbap. EndIf. EndIf. *} INSERT ENDFORM.

• Return to 0007 - User Exits • Read 0007a - Standard User Exits • Read 0007c - User Exits In Validations, Substitutions And Rules.

Page 7: User Exits

0007c - User Exits In FI

by Rich » Thu Mar 26, 2009 11:52 am

User Exits In FI. User Exits in FI are implemented again in a different manner to both standard user exits and user exits in SD. The user exits are available for Substitutions, Validations and Rules which are specified either in transaction OB28 (for rules), or OBBH (for substitutions). There are 3 steps involved in setting up user exits in FI. These are:

• Creating the Module Pool and programming the user exit. • Specifying the Module Pool that will hold the user exits. • "Activating" the user exit.

Creating The Module Pool. SAP provide two programs that should be used to implement these user exits. These are RGGBS000 and RGGBR000 (for substitutions and rules respectively). The relevant program should be copied to a Z version of the program, ZRGGBR000 for example. The code in this module pool is like so:

PROGRAM RGGBR000 . *---------------------------------------------------------------------* * * * Regeln: EXIT-Formpool for Uxxx-Exits * * * * This formpool is used by SAP for demonstration purposes only. * * * * Note: If you define a new user exit, you have to enter your * * user exit in the form routine GET_EXIT_TITLES. * * * *---------------------------------------------------------------------* INCLUDE FGBBGD00. "Data types

Page 8: User Exits

*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!* * PLEASE INCLUDE THE FOLLOWING "TYPE-POOL" AND "TABLES" COMMANDS * * IF THE ACCOUNTING MODULE IS INSTALLED IN YOUR SYSTEM * *TYPE-POOLS: GB002. " TO BE INCLUDED IN *TABLES: BKPF, " ANY SYSTEM THAT * BSEG, " HAS 'FI' INSTALLED * COBL, * GLU1. *!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!* *----------------------------------------------------------------------* * FORM GET_EXIT_TITLES * *----------------------------------------------------------------------* * returns name and title of all available standard-exits * * every exit in this formpool has to be added to this form. * * You have to specify a parameter type in order to enable the * * code generation program to determine correctly how to * * generate the user exit call, i.e. how many and what kind of * * parameter(s) are used in the user exit. * * The following parameter types exist: * * * * TYPE Description Usage * * ------------------------------------------------------------ * * C_EXIT_PARAM_NONE Use no parameter Subst. and Valid. * * except B_RESULT * * C_EXIT_PARAM_CLASS Use a type as parameter Subst. and Valid * *----------------------------------------------------------------------* * --> EXIT_TAB table with exit-name and exit-titles * * structure: NAME(5), PARAM(1), TITEL(60) *----------------------------------------------------------------------* FORM GET_EXIT_TITLES TABLES ETAB. DATA: BEGIN OF EXITS OCCURS 50, NAME(5) TYPE C, PARAM LIKE C_EXIT_PARAM_NONE, TITLE(60) TYPE C, END OF EXITS. *!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * PLEASE DELETE THE FIRST '*' FORM THE BEGINING OF THE FOLLOWING LINES * * IF THE ACCOUNTING MODULE IS INSTALLED IN YOUR SYSTEM: * EXITS-NAME = 'U101'. EXITS-PARAM = C_EXIT_PARAM_CLASS. EXITS-TITLE = TEXT-100. "Posting date check

Page 9: User Exits

APPEND EXITS. EXITS-NAME = 'U100'. EXITS-PARAM = C_EXIT_PARAM_NONE. "Complete data used in exit. EXITS-TITLE = TEXT-101. "Posting date check APPEND EXITS. * forms for SAP_EIS EXITS-NAME = 'US001'. "single validation: only one EXITS-PARAM = C_EXIT_PARAM_NONE. "data record used EXITS-TITLE = TEXT-102. "Example EIS APPEND EXITS. EXITS-NAME = 'UM001'. "matrix validation: EXITS-PARAM = C_EXIT_PARAM_CLASS. "complete data used in exit. EXITS-TITLE = TEXT-103. "Example EIS APPEND EXITS. REFRESH ETAB. LOOP AT EXITS. ETAB = EXITS. APPEND ETAB. ENDLOOP. ENDFORM. *eject *----------------------------------------------------------------------* * FORM U100 * *----------------------------------------------------------------------* * Example of an exit for a boolean rule * * This exit can be used in FI for callup points 1,2 or 3. * *----------------------------------------------------------------------* * <-- B_RESULT T = True F = False * *----------------------------------------------------------------------* FORM U100 USING B_RESULT. *!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * PLEASE DELETE THE FIRST '*' FORM THE BEGINING OF THE FOLLOWING LINES * * IF THE ACCOUNTING MODULE IS INSTALLED IN YOUR SYSTEM: * * * IF SY-DATUM = BKPF-BUDAT. * B_RESULT = B_TRUE. * ELSE. * B_RESULT = B_FALSE.

Page 10: User Exits

* ENDIF. ENDFORM. *eject *----------------------------------------------------------------------* * FORM U101 * *----------------------------------------------------------------------* * Example of an exit using the complete data from one * * multi-line rule. * * This exit is intended for use from callup point 3, in FI. * * * * If account 400000 is used, then account 399999 must be posted * * to in another posting line. * *----------------------------------------------------------------------* * --> BOOL_DATA The complete posting data. * * <-- B_RESULT T = True F = False * *----------------------------------------------------------------------* *!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * PLEASE DELETE THE FIRST '*' FORM THE BEGINING OF THE FOLLOWING LINES * * IF THE ACCOUNTING MODULE IS INSTALLED IN YOUR SYSTEM: * *FORM u101 USING bool_data TYPE gb002_015 * CHANGING B_RESULT. * DATA: B_ACC_400000_USED LIKE D_BOOL VALUE 'F'. * * B_RESULT = B_TRUE. ** Has account 400000 has been used? * LOOP AT BOOL_DATA-BSEG INTO BSEG * WHERE HKONT = '0000400000'. * B_ACC_400000_USED = B_TRUE. * EXIT. * ENDLOOP. * ** Check that account 400000 has been used. * CHECK B_ACC_400000_USED = B_TRUE. * * B_RESULT = B_FALSE. * LOOP AT BOOL_DATA-BSEG INTO BSEG * WHERE HKONT = '0000399999'. * B_RESULT = B_TRUE. * EXIT. * ENDLOOP. *

Page 11: User Exits

*ENDFORM. *eject *----------------------------------------------------------------------* * FORM US001 *----------------------------------------------------------------------* * Example of an exit for a boolean rule in SAP-EIS * for aspect 001 (single validation). * one data record is transfered in structure CF<asspect> *---------------------------------------------------------------------- * Attention: for any FORM one has to make an entry in the * form GET_EXIT_TITLES at the beginning of this include *----------------------------------------------------------------------* * <-- B_RESULT T = True F = False * *----------------------------------------------------------------------* FORM US001 USING B_RESULT. *TABLES CF001. "table name aspect 001 * * IF ( CF001-SPART = '00000001' OR * CF001-GEBIE = '00000001' ) AND * CF001-ERLOS >= '1000000'. * ** further checks ... * * B_RESULT = B_TRUE. * ELSE. * ** further checks ... * * B_RESULT = B_FALSE. * ENDIF. ENDFORM. "US001 *eject *----------------------------------------------------------------------* * FORM UM001 *----------------------------------------------------------------------* * Example of an exit for a boolean rule in SAP-EIS * for aspect 001 (matrix validation). * Data is transfered in BOOL_DATA: * BOOL_DATA-CF<aspect> is intern table of structure CF<asspect> *----------------------------------------------------------------------

Page 12: User Exits

* Attention: for any FORM one has to make an entry in the * form GET_EXIT_TITLES at the beginning of this include *----------------------------------------------------------------------* * <-- B_RESULT T = True F = False * *----------------------------------------------------------------------* FORM UM001 USING BOOL_DATA "TYPE GB002_<boolean class of aspect 001> CHANGING B_RESULT. *DATA: LC_CF001 LIKE CF001. *DATA: LC_COUNT TYPE I. * B_RESULT = B_TRUE. * CLEAR LC_COUNT. * process data records in BOOL_DATA * LOOP AT BOOL_DATA-CF001 INTO LC_CF001. * IF LC_CF001-SPART = '00000001'. * ADD 1 TO LC_COUNT. * IF LC_COUNT >= 2. ** division '00000001' may only occur once ! * B_RESULT = B_FALSE. * EXIT. * ENDIF. * ENDIF. * ** further checks .... * * ENDLOOP. ENDFORM. "UM001

The first thing to do is to insert code that notifies the calling programs of the availability of the user exits. This is achieved in the form GET_EXIT_TITLES. Decide on the name for your user exit, which should start with 'U' (for a user defined user exit) and then a 3 digit unique number. Above the line 'REFRESH ETAB', make the following entries:

EXITS-NAME = 'U100'. EXITS-PARAM = C_EXIT_PARAM_NONE. "Complete data used in exit. EXITS-TITLE = TEXT-101. "Posting date check APPEND EXITS.

The NAME field should contain the user exit name that you will be using. The field PARAM defines the parameter type.

Page 13: User Exits

There are three values for this parameter, and are defined as constants: C_EXIT_PARAM_NONE: This constant means that no parameters are defined for this user exit. In truth, there is one parameter defined and that is a boolean flag that is used to specify whether there is an error in the data or not. A value of false for this parameter means that the data is valid(!) and a value of true means that there is an error. This parameter is valid for rules, validations and substitutions. C_EXIT_PARAM_FIELD: This constant is valid for substitutions only and means that one parameter can be defined for the user exit which is the field to be sustituted. C_EXIT_PARAM_CLASS valid for Rules, Validations and Substitutions, this parameter signifies that all the data (BKPF and BSEG data) will be passed as one parameter to the user exit. You will be passed a table containing all the relevant information. Have a look at the routine U101 to see how to access this data. The last thing to include before the append is a text sting which is used to display the title of the user exit in an upcoming transaction. Creating your user exit Once you've entered the above code into the right place in the form GET_EXIT_TITLES, it's time to write the user exit code itself. Base the form delcaration on the examples above, remembering to return b_true or b_false dependant on the result of your user exit. If you wish to display any messages in the user exit, make them informational ones. Any other types can cause problems with the correcting of fields otherwise. Don't forget to activate the changes. Specifying the module pool that holds the user exits. Having written the user exit code, you must now activate that code. This is not the same as activating a program. What you are doing here is telling SAP that there is code available and this is where it lives. Start transaction GCX2. This will then display a screen similar to the one shown here:

Page 14: User Exits
Page 15: User Exits

Change the screen into change mode by clicking this pencil as normal, and then enter the module pool name that you created in the steps above into the Ex. Prog Field. Save the changes and exit. "Activating" the User Exit. The next thing to do is to incorporate your user exit code into a validation rule. Start transaction OB28.

Page 16: User Exits
Page 17: User Exits

Select 'New Entries', and complete the input fields. (How to define the validation name is forth coming). Select the rule that you wish the user exit to be activated for (Note that these activations are company dependant).

Page 18: User Exits
Page 19: User Exits

Your user exit will appear essentially as a boolean variable in the rule that you have selected (or created). In the relevant step enter the user exit name either as part of a condition statement or on it's own. In the example below the user exit is called U102.

Page 20: User Exits
Page 21: User Exits