User exits

34
USER EXITS IBM G lobal Services © 2005 IBM C orporation 2 M arch-2005 U serExits | 8.01 Objectives The participants w ill be able to: D iscuss the procedure ofm odifying SAP Standard program through procedure SSC R (SAP Softw are C hange R egistration). Locate,code and im plem entFunction exits. D ifferentiate betw een C ALL FU N C TIO N and CALL CUSTO M ER -FU NC TIO N statements. Identify Projects and Enhancem ents and use the transactions C M O D and SM OD. 1

description

Use User Exit

Transcript of User exits

Page 1: User exits

USER EXITS

IBM Global Services

© 2005 IBM Corporation2 March-2005User Exits | 8.01

Objectives

The participants will be able to:

Discuss the procedure of modifying SAP Standard program through procedure SSCR (SAP Software Change Registration).

Locate, code and implement Function exits.

Differentiate between CALL FUNCTION and CALL CUSTOMER-FUNCTION statements.

Identify Projects and Enhancements and use the transactions CMOD and SMOD.

1

Page 2: User exits

IBM Global Services

© 2005 IBM Corporation3 March-2005User Exits | 8.01

Overview

If you try to change the SAP program “SAPMF02K”, you will be prompted to enter the access key for that object.

It mandatory for users to register all manual changes to SAP source coding and SAP Dictionary objects through a procedure called SSCR.

In certain situations, you may notice that the SAP Standard object does not exactly match the requirement of your client. So, you may feel to modify the SAP objects/code to match the requirement. But, this is not a good way of achieving the results. You should avoid making modifications/repairs to SAP objects/code whenever possible. There are other rational ways to incorporate your additional requirements to SAP standard code. The main reason for which you should refrain from altering SAP standard object is, any modified SAP code will be overwritten with upgraded versions of SAP.

Because of this problem, SAP has made it mandatory for users to register all manual changes to SAP source coding and SAP Dictionary objects through a procedure called SSCR (SAP Software Change Registration). Basically, SSCR involves you, the user, obtaining an access key from SAP to make changes to original SAP code.

If you tried to change the SAP program “SAPMF02K”, you would be prompted to enter the access key for that object.

2

Page 3: User exits

IBM Global Services

© 2005 IBM Corporation4 March-2005User Exits | 8.01

SAP Modification

After you enter the appropriate access key, you will be able to modify a SAP standard object. You should avoid making repairs to SAP objects/code.

After you enter the appropriate access key, you will be able to modify this program.

Note: Any changes you make to the program will be overwritten when the next SAP upgrade is installed.

3

Page 4: User exits

IBM Global Services

© 2005 IBM Corporation5 March-2005User Exits | 8.01

Obtaining Object Access Key

To obtain the access key for changing a SAPStandard object, either run transaction OSS1 orgo to the site www.service.sap.com.

You should avoid making modifications/repairs to SAP objects/code whenever possible. However if it is absolutely necessary to change a SAP standard program with the access key, then follow the below mentioned procedure.

Get the Installation No. of your SAP System and remember it. (Go to “System -> Status” tab in the menu bar of your SAP screen)

To obtain the access key for changing a SAP Standard object, either run transaction OSS1 or go to the site www.service.sap.com.

Give the SAPNet User ID and Password to logon to the OSS.

4

Page 5: User exits

IBM Global Services

© 2005 IBM Corporation6 March-2005User Exits | 8.01

Obtaining Object Access Key (Contd.)

Go to the registration tab

Go to Register Objects

5

Page 6: User exits

IBM Global Services

© 2005 IBM Corporation7 March-2005User Exits | 8.01

Obtaining Object Access Key (Contd.)

Select your server by matchinginstallation number.

Provide the Object name, SAPRelease and click on the ‘Register’ tab.

The Registration Key for the Object will be displayed.

Select your server by matching installation number. Provide the Object name, SAP Release and click on the ‘Register’ tab. The Registration Key for the Object will be displayed, use this key when you are

prompted for the object access key while attempting to change a SAP Standard object.

You can view your registration by selecting “Objects registered by Me” tab.

6

Page 7: User exits

IBM Global Services

© 2005 IBM Corporation8 March-2005User Exits | 8.01

Different Enhancement Techniques

SAP 3 Tier Architecture

PRESENTATION :

Field Exits (SAP would no longer support Field Exits)

Screen Exits

Menu Exits

APPLICATION:

Program exits ( Function Exits, BAdis, Business Transaction Events, Substitution Exits )

DATABASE

Append Structure

As per SAP’s 3 Tier Architecture, at the Presentation layer you had Field Exits, Screen Exits and Menu Exits. At the Application layer you had Program exits, at the Database layer you could Append structures to the existing SAP structures.

Function-Exits: These are the function modules created by SAP and activated by the customer (non-activated function-exits do not slow down the transaction).

Menu-Exits: These allow the customer to activate menu items and assign additional functionality to them.

Screen-Exits: These allow the customer to add additional fields to a screen and make entries.

7

Page 8: User exits

IBM Global Services

© 2005 IBM Corporation9 March-2005User Exits | 8.01

Information on existing User-Exits

Using transaction SPRO, one can information along with detailed documentation on the Exits available for areas of concern.

Using transaction SPRO, one can information along with detailed documentation on the Exits available for areas of concern.

This helps in using the proper exit and the relevant program to meet the requirement.

8

Page 9: User exits

IBM Global Services

© 2005 IBM Corporation10 March-2005User Exits | 8.01

Function-Exits

*----------------------------------*

* include zxf05u01. *

*----------------------------------*

This INCLUDE program is where you will write the customer-specific code.

call customer-function “001”...

function exit_sapmf02k_001.

include zxf05u01.

endfunction.

SAP Original Code “SAPMF02K”

Function Module INCLUDE Program

This INCLUDE program will not be overwritten with an SAP upgrade because it is not SAP

original code.

The concept of a function-exit involves various points in original SAP programs that have calls to specific function modules (EXIT_<program name>_xxx).

<program name>: name of program that the function module is called from

xxx: unique number for each function-exit within a particular program These function modules only contain an “INCLUDE” statement. It is in these INCLUDES that you will code the customer-specific program that

will be called from an original SAP program but will not be overwritten with SAP upgrades.

9

Page 10: User exits

IBM Global Services

© 2005 IBM Corporation11 March-2005User Exits | 8.01

Call Customer-Function Versus Call Function

The CALL CUSTOMER-FUNCTION statement will only execute the function module if the module is activated.

call function ‘EXIT_SAPMF02K_001 ’

Both of these CALL statements refer to the function module “EXIT_SAPMF02K_001”.

If you notice from the previous slide, the call to the function module for a function-exit is not the typical CALL FUNCTION “EXIT_SAPMF02K_001”; instead, it is a CALL CUSTOMER-FUNCTION ‘001'.

These two statements are similar in that they both call the same function module (EXIT_SAPMF02K_001).

The difference between the two calls is that the “CALL CUSTOMER-FUNCTION” statement will only execute the function module if the function module is activated (activating user-exits is covered in later slides).

With the “CALL FUNCTION” statement, the system will try to execute the code in the function module whether it is active or not.

The reason that SAP uses the CALL CUSTOMER-FUNCTION in its original code is that resources are not wasted if the customer has not utilized this particular user-exit functionality.

10

Page 11: User exits

IBM Global Services

© 2005 IBM Corporation12 March-2005User Exits | 8.01

Business Case Scenario

UPDATE LOG

Vendor #Vendor name

When the user updates a vendor record, you want to insert a record into an update log that contains the vendor number and name of the updated record.

As an example, assume that you want to create a log when a vendor record is updated.

The change vendor transaction is “FK02”. Using the “System->Status” menu path in this transaction, you can determine that

the program is “SAPMF02K”.

11

Page 12: User exits

IBM Global Services

© 2005 IBM Corporation13 March-2005User Exits | 8.01

Steps to Coding a Function-Exit

1. Locate Function-Exit(s)

2. Go to Function Module

3. Create INCLUDE Program

4. Code in INCLUDE Program

5. Activate Function-Exit

Steps to Coding a Function-Exit1. Locate Function-Exit in SAP Program (in our example, program

“SAPMF02K”).2. Go to Function Module associated with that Function-Exit3. Create INCLUDE Program that is used in the Function Module4. Code in the INCLUDE Program (in our example, the code would insert a

record into the update log)5. Activate the Function-Exit

Using our example with program “SAPMF02K”, these steps are covered in detail in the following slides.

12

Page 13: User exits

IBM Global Services

© 2005 IBM Corporation14 March-2005User Exits | 8.01

Locate Function-Exit(s)

Using transaction “SE38” (ABAP Editor), display the program “SAPMF02K”.

13

Page 14: User exits

IBM Global Services

© 2005 IBM Corporation15 March-2005User Exits | 8.01

Locate Function-Exit(s)

In program “SAPMF02K”, search for the string “call customer-function” in the main program to find all of the function-exit(s) in the program.

Search for the string “call customer-function” in the main program to find the function-exit(s) in the program.

14

Page 15: User exits

IBM Global Services

© 2005 IBM Corporation16 March-2005User Exits | 8.01

Locate Function-Exit(s)

Double-click anywhere on the call customer-function “001” statement to go to that line in the SAP program.

In program “SAPMF02K”, there is only one function-exit at line 83 of “MF02KFEX”.

If the string “call customer-function” is found, you will be able to determine where and how many function-exits there are in the program.

In program “SAPMF02K”, there is only one function-exit. Once your search has found a function-exit, you can go to it by double-clicking

on the specific function module call statement or the line number (in this example, “100”). By doing this, you will go to the area of the main program that contains the call statement (in this example, program “MF02KFEX”).

Note:This method may not find all the function exits in the program. If a function exits occurs in a function module “called” from the program, this method will not find it.

The best way to find User Exits available for a particular transaction is to run the Transaction in the Runtime Analysis tool (SE30). Then, in the analysis results screen ( where all program, function and method calls during the runtime of the transaction are displayed) search by the keyword ‘EXIT_’. Then Navigate to each Function Exit call by clicking the source code button after placing the cursor on it. From the Function Exit call, double click to go into the Function Exit. Then using table MODSAP find the enhancement related to it.

15

Page 16: User exits

IBM Global Services

© 2005 IBM Corporation17 March-2005User Exits | 8.01

Go to Function Module

Double-click on ‘001’ of the CALL CUSTOMER-FUNCTION “001” statement in the SAP program to go to the function module “EXIT_SAPMF02K_001”.

Once you are in the SAP program at the spot of the function-exit, you can go to the actual function module (EXIT_SAPMF02K_001) by double-clicking on ‘001’ of the “CALL CUSTOMER-FUNCTION” statement.

Note: An SAP program can have more than one function-exit. The difficulty comes in determining when these function-exits get executed in the course of the program.

For our example, assume that you know the above function-exit occurs when a vendor record is being saved (updated or inserted).

16

Page 17: User exits

IBM Global Services

© 2005 IBM Corporation18 March-2005User Exits | 8.01

Create INCLUDE Program

Double-click on the INCLUDE ZXF05U01 statement in the function module to create the INCLUDE program.

Notice that the only code in this function module is the INCLUDE statement. Double-click on the “INCLUDE” statement to create the INCLUDE program. When prompted that “Include ZXF05U01 does not exist. Do you want to create

the object?”, press the YES pushbutton. When prompted with the name of the INCLUDE program, press the green

checkmark button. For the attributes of the INCLUDE program, you will need to enter a title, the

program type (in this case, “I” for include), and an application.

17

Page 18: User exits

IBM Global Services

© 2005 IBM Corporation19 March-2005User Exits | 8.01

Code in INCLUDE Program

*------------------------------* INCLUDE ZXF05U01*------------------------------

if sy-uname = ‘SANGRAMC’.

endif.

Write code in the include program.

Whatever logic you add here will affect all SAP standard transaction where this particular User Exit is being called.

Put all your code within the username check, while you are at the middle of the user exit development. So, that your logic in the exit (which is incomplete now) does not affect others users in the system.

At the end of the development, when you have tested that your logic is correct, remove the username check. So, the additional logic (tested & verified now) is now triggered for all users in the system.

It is in this INCLUDE program that you will put your specific code (in our example, the code to insert a record in an update log).

Remember, because the SAP program “SAPMF02K” uses the “CALL CUSTOMER-FUNCTION” statement, the code in this INCLUDE program will not be executed until the function-exit is activated.

Notice the use of the “IF SY-UNAME = ‘SANGRAMC’ ... ENDIF” statements. This logic is used for testing your function-exit so that the only time the code within the “IF” statement is executed is when you are the user executing the appropriate transaction (in this example, transaction “FK02”).

18

Page 19: User exits

IBM Global Services

© 2005 IBM Corporation20 March-2005User Exits | 8.01

Activating Function-Exit

X

X

PROJECT 1

(can be activated/deactivated)

Enhancement 1

Enhancement2

FunctionExit

ScreenExit

FunctionExit

PROJECT 2

(can be activated/deactivated)

Enhancement3

FunctionExit

You do not actually activate a single function-exit; instead, you activate a PROJECT that will include your user-exit(s).

You do not actually activate a single function-exit; instead, you activate a PROJECT that will include your user-exit(s). To activate a PROJECT, you use transaction CMOD (menu path: Tools-> ABAP workbench-> Environment-> Enhancements-> Project management).

PROJECT - The highest level in the modification process. Projects are simply used to group together ENHANCEMENTS. It's purpose is to enable the modifier to activate a number of different enhancements that are related and to as ensure that other ENHANCEMENTS are not undesirably activated.

ENHANCEMENT - These are used to group together a collection of COMPONENTS that are inter-related. The naming convention for these usually corresponds to the program(s) in which the user-exits exist

Note:One SAP program may have more than one user-exit; each of these exits will usually be a part of the same ENHANCEMENT. [relationship with PROJECT = one to zero or one to one]

COMPONENTS - These are the actual modifications that may be used in the SAP system to help customize the system. This is the lowest level of the modification process and includes the various categories of user-exits. [relationship with ENHANCEMENT = one to zero or one to one]

19

Page 20: User exits

IBM Global Services

© 2005 IBM Corporation21 March-2005User Exits | 8.01

User-Exit Transactions

CMOD : This transaction allows you to create a PROJECT by identifying its ENHANCEMENT(S). After determining all of the ENHANCEMENTS that are part of the PROJECT, you will have to activate the PROJECT. You will still need to codeyour user-exit; therefore, you may want to wait until this step is completed before activating the PROJECT.

SMOD : This transaction allows you to create an ENHANCEMENT, which you willinclude in a PROJECT, by identifying its COMPONENT(S). In the case where SAPhas already created an ENHANCEMENT for its pre-defined user-exits, you will notneed to use transaction SMOD; instead, you should just use transaction CMOD.

CMOD - This transaction allows you to create a PROJECT by identifying its ENHANCEMENT(S). After determining all of the ENHANCEMENTS that are part the PROJECT, you will have to activate the PROJECT. You will still need to code your user-exit; therefore, you may want to wait until this step is completed before activating the PROJECT.

SMOD - This transaction allows you to create an ENHANCEMENT, which you will include in a PROJECT, by identifying its COMPONENT(S). In the case where SAP has already created an ENHANCEMENT for its pre-defined user-exits, you will not need to use transaction SMOD; instead, you should just use transaction CMOD.

You determine which enhancements should be included in a particular project using transaction CMOD. SAP comes with standard enhancements that include various user-exits. However, if these user-exits do not involve a transaction activity that you want to modify, you will have to create your own user-exit and enhancement using transaction SMOD.

Note:That to create your own function-exit, you will have to modify original SAP code to include the “CALL CUSTOMER-FUNCTION” statement that will execute your customer-specific code (remember: this code will be overwritten with an SAP upgrade).

20

Page 21: User exits

IBM Global Services

© 2005 IBM Corporation22 March-2005User Exits | 8.01

Transaction CMOD

In transaction CMOD, type in the name of your project and press the CREATE pushbutton.

In order for our example function-exit to execute, we need to activate it. Because we do not activate individual user-exits, we need to create a project

to activate using transaction CMOD. Another way to find components of an enhancement is to use the transaction

SMOD (Menu path: Tools-> ABAP workbench-> Utilities-> Enhancements-> Project Management).

Note:Once you are in transaction CMOD, form the initial screen (as above) you can display the relevant documentation by selecting the Documentation radio button.

21

Page 22: User exits

IBM Global Services

© 2005 IBM Corporation23 March-2005User Exits | 8.01

Transaction CMOD

Once you SAVE your project, you can add as many enhancements as you want by pressing the SAP enhancements pushbutton.

Next, you enter a short description and save the project. Then, you need to add enhancements to the project (press the “Enhancement

assignments’’ pushbutton).

22

Page 23: User exits

IBM Global Services

© 2005 IBM Corporation24 March-2005User Exits | 8.01

Transaction CMOD

Add the enhancements you want included in the project.

From the enhancements screen, you enter the appropriate enhancements (you can use the serachhelp to find particular enhancement).

Once you add the enhancements you want, you must save the project. After saving the project, you should green arrow back to the initial CMOD screen

so that you can activate the project.

23

Page 24: User exits

IBM Global Services

© 2005 IBM Corporation25 March-2005User Exits | 8.01

Transaction CMOD

After saving your project, you need to ACTIVATE it.

You must activate the project on the initial CMOD screen. You can always go back into transaction CMOD to activate/deactivate or delete a

particular project. After activating the project for our example, we can execute transaction “FK02”

and the code we have written in the function-exit INCLUDE program will be executed.

24

Page 25: User exits

IBM Global Services

© 2005 IBM Corporation26 March-2005User Exits | 8.01

Transaction SMOD

With the name of the enhancement, you can display its components.

Another way to find components of an enhancement is to use the transaction SMOD (Menu path: Tools-> ABAP workbench-> Utilities-> Enhancements-> Definition).

Once you know the name of the enhancement, go into transaction SMOD and display the components of the appropriate enhancement.

25

Page 26: User exits

IBM Global Services

© 2005 IBM Corporation27 March-2005User Exits | 8.01

Transaction SMOD

In the case of enhancement “SAPMF02K”, there is only one user-exit – a function-exit using the function module “EXIT_SAPMF02K_001”.

As you can see, there is only one component to this enhancement, the function module “EXIT_SAPMF02K_001”.

You will still need to determine where this function module is called from within the main program, but notice that the short text does give you an indication.

Once you know the name of the function module, you can display it using the Function Library (transaction SE37) and proceed to the appropriate INCLUDE area where you will put the customer-specific code.

Again, you must follow all the steps to create a project, include the enhancement, and activate it.

26

Page 27: User exits

IBM Global Services

© 2005 IBM Corporation28 March-2005User Exits | 8.01

Additional Information

You can use table MODACT to find the Project an Enhancement is included in.

You can use table MODSAP to find the Enhancement for a Function Exit.

Component or Function Exit

27

Page 28: User exits

IBM Global Services

© 2005 IBM Corporation29 March-2005User Exits | 8.01

Summary

You should avoid making modifications/repairs to SAP objects/code whenever possible.

It mandatory for users to register all manual changes to SAP source coding and SAP Dictionary objects through a procedure called SSCR.

To obtain the access key for changing a SAP Standard object, either run transaction OSS1 or go to the site www.service.sap.com.

The concept of a function-exit involves various points in original SAP programs that have calls to specific function modules.

“CALL CUSTOMER-FUNCTION” statement will only execute a function module if the function module is activated.

CMOD : This transaction allows you to create a PROJECT by identifying its ENHANCEMENT(S).

SMOD : This transaction allows you to create an ENHANCEMENT, which you will include in a PROJECT, by identifying its COMPONENT(S).

1. Exercise on User-Exit (Function-Exit)

Implement an User-Exit that will fire whenever you change any Customer details. Code an Information message inside the User Exit code, so that when you run XD02 after Activating the Project (thus the User Exit) this message is displayed in a popup.

Solution: Steps :-1. Run transaction ‘XD02’. The Change Customer initial screen will appear.

28

Page 29: User exits

2. Select a customer number from the search help provided, and press the green ‘Continue’ button.

3. From the screen that appears, click on the Menu Item System Status.

29

Page 30: User exits

4. Double-click on the Program (GUI) name ‘SAPMF02D’.

5. Click the ‘Find’ button . 6. In the Search window, look for the string customer-function in the Main Program.

7. Double-click on the hit list.

8. Now double-click on CALL CUSTOMER-FUNCTION '001'.

30

Page 31: User exits

9. You’ll be taken inside the Function Module (Function-Exit) EXIT_SAPMF02D_001.

10. This is the User-Exit for Change Customer. Notice that there is an Include program in the User-Exit. Double-click on this Include program name.

11. There will be a pop-up asking you to create the Include ZXF04U01. Click ‘Yes’ and create the Include if it is not already created.

12. You can write your custom code within this Include program as shown below :-

31

Page 32: User exits

13. It is a good practice to write your User-Exit code within ‘IF SY-UNAME = ………… ENDIF’. This is to prevent inadvertent firing of the Exit by other users while you are still testing. After testing is complete, do not forget to remove the ‘IF ……… ENDIF’ before submitting the code to the client !Use your SAP user ID provided for the training. The User name should be written in Capital letters. E.g. IF SY-UNAME = ‘SANGRAMC’.

14. Activate the Include program.15. Now go to table MODSAP to find the Enhancement for the Function-Exit

EXIT_SAPMF02D_001. It is SAPMF02D in this case.

16. Now go to transaction CMOD and create a Project YXXPROJ. (Replace XX with the last 2 digits of your SAP User ID)

17. Include the Enhancement SAPMF02D in the Enhancement Assignment screen. Save and Activate the project. The components of Enhancement SAPMF02D will now be active.

18. Execute transaction ‘XD02’ again and the information message will be displayed when you change a Customer and press save.

32

Page 33: User exits

33