The function exit is actually the customer exit. Here we need to use the statement CALL CUSTOMER-FUNCTION. Since we are writing our custom code inside a function module it is called function exit. This function module is a standard one so we can’t change anything in that function module. Inside this function module we have an include program starting with Z. We have to create this include and then we can write our own code. After that we need to implement this function module. Hence the function exit / customer exit is basically a function module which is provided by SAP and implemented by customer.
The name of the function module contains EXIT_, then the program name and then the three digit indicator in function exit. We can search the exact function module exit by using the program name (the program name is called the Enhancement) in transaction SMOD. We implement the function exit by creating a specific project in CMOD. Now if one function exit is already implemented in one project then we cannot implement that function exit into a new project. This is the main draw back in function / customer exit.
We have two standard DB tables like MODSAP & MODACT. Execute MODSAP by entering the enhancement name and we can get all function exits of this enhancement. Similarly execute MODACT by entering the project name and we get all the activated enhancement names.
In the following example we are working with the transaction XK02 – change vendor data. We need to generate an information message if the country of the vendor is not India. To do this we are heading the following step by step approach.
1. Go to XK02.
2. Mention a valid vendor and check Address.
3. Now we are in the address screen where the country is DE (Germany) for the existing vendor.
4. Now we modify the name by adding ‘Mr.’ and then save it. The vendor details have been saved successfully. At this stage we want this information pop up message.
5. Stay on that screen where we need to customize and go to System > Status.
6. Double click on the program name.
7. Now we are in that program at SE38.
8. Now find the statement CALL CUSTOMER-FUNCTION.
9. Choose the program name.
10. Now we are in the global search screen where customer functions are visible. One program can have more than one customer functions for different purpose.
11. Now double click on CALL CUSTOMER-FUNCTION ‘001’ and go to the exact location of the program.
12. Now double click on the ‘001’ and then we go into the function module (SE37) as follows.
13. Another way to find the function exit is to go to the attribute of the program.
14. Note down the package.
15. Go to SMOD.
16. Enter the program name into the Enhancement input field and display.
17. Click on Components.
18. Now we can see the name of Function modules, Programs, screens etc.
19. Now we have to write our own code into that include program. To do this go to CMOD transaction.
20. Create a new project at first.
21. Give the description and save it in a package or local.
22. Click on Enhancement Assignment.
23. Now mention the program name into the enhancement and hit enter.
24. Then click on components. Then double click on Exit.
25. The function module screen will come and then double click on the include program.
26. Create the program.
27. Now we can write our custom code as follows. Activate the program.
28. Go back and activate the project. Here we have Activate as well as deactivate option.
29. Finally go to XK02 > mention vendor with address > change something (delete the ‘Mr.’ text in the name) > save it. We can see the pop up information message comes as required.