Discover the use of the implicit enhancement option, including all possible areas where the enhancement can be used. Learn about the implementation of dynamic and static implicit enhancements with examples. You can also see how to add one new column in SAP List Viewer (ALV) of a standard report using implicit enhancement (without modification) as an example.
Key Concept
The
implicit enhancement is a new technology to enhance SAP’s standard objects such as includes, function modules, forms, global classes and all source code units. The enhancement option makes it possible to add your own functionality to standard SAP objects without changing the original object. The additional functionality you added to the system by enhancement does not create any problems while the system upgrades and can be available without making any adjustment.
In SAP standard code there are some predefined positions where you can add custom code implicitly without any special enhancement. No enhancement spot is required for this type of enhancement. Implicit enhancements are available from SAP NetWeaver Application Server (SAP NetWeaver AS) 7.0.
Sometimes you have requirements to set a default value for a standard field, or you have to add an extra column in the standard SAP List Viewer (ALV). Or you might have to include a custom include in standard code. All such requirements can be fulfilled by using implicit enhancements. Without using implicit enhancements, you have to modify the standard code, which can cause problems when upgrading your system.
Later in this article I explain how to add new column in a standard SAP report using an implicit enhancement. The output of the report shows salaries in different time units (e.g., annually, monthly, weekly, and daily). I will show you the way to add one more column to ALV of this report output. You will see that I will do three enhancements to achieve the required result. First, I add a field in the structure, then I do calculations for converting all time units to a single time unit (annually) and assign the value to that field, and finally add the entry in the field catalog of ALV to display the new column in the output.
I’ll show you how to implement implicit enhancements, but first let’s look at displaying implicit enhancement options and the various pieces of code in which they can be installed.
How to Display an Implicit Enhancement Option
Displaying an implicit enhancement option involves a three-step process:
- Open ABAP code and click the enhance icon from the toolbar or use shortcut key Shift+F4
- Follow menu path Edit > Enhancement Options > Show Implicit Enhancement Options
- You see a new line has been added in the code with an arrow sign on the left side. This is the position where you can add custom code by implementing an implicit enhancement.
Figure 1 displays the code before showing the implicit enhancement option and
Figure 2 shows it with the implicit enhancement option.
Figure 1
Before showing the implicit enhancement option
Figure 2
After showing the implicit enhancement option
Positions Available for Implicit Enhancement
Now I’ll show you all possible positions with screenprints where you can add custom code using an implicit enhancement implementation. Note that the implicit enhancement option is not available for some objects. For example, you can’t enhance the include LALFATOP and function module CONVERSION_EXIT_ALPHA_INPUT. Whenever you try to implement an implicit enhancement for an object like this, the system gives you a message that you can’t enhance the object. The implicit enhancement option is also not available at the end of a function module include.
Figure 3 shows an implicit enhancement option at the end of an include.
Figure 3
At the end of an include
Figure 4 shows an implicit enhancement option before TYPES END OF.
Figure 4
Before TYPES END OF
Figure 5 shows an implicit enhancement option before DATA END OF.
Figure 5
Before DATA END OF
Figure 6 shows an implicit enhancement option before CONSTANTS END OF.
Figure 6
Before CONSTANTS END OF
Figure 7 shows an implicit enhancement option before STATICS END OF.
Figure 7
Before STATICS END OF
Figure 8 shows an implicit enhancement option before the ENDINTERFACE.
Figure 8
Before ENDINTERFACE
Figure 9 shows an implicit enhancement option before the ENDCLASS in CLASS … IMPLEMENTATION.
Figure 9
Before ENDCLASS in CLASS … IMPLEMENTATION
Figures 10 and
11 show implicit enhancements at the end of the CHANGING, IMPORTING, and EXPORTING parameter list of a method. The method in
Figure 10 originally doesn’t have IMPORTING, EXPORTING, or CHANGING parameters, but the method in
Figure 11 originally has two parameters: IMPORTING and CHANGING.
Figure 10
Method without any parameter
Figure 11
Method with two parameters, IMPORTING and CHANGING
Figure 12 shows an implicit enhancement option at the end of a PUBLIC, PROTECTED, PRIVATE SECTION of a class.
Figure 12
At the end of a PUBLIC, PROTECTED, and PRIVATE SECTION of a class
Figure 13 shows an implicit enhancement option at the beginning and end of METHOD. This is placed after commands METHOD and before statements ENDMETHOD.
Figure 13
At the beginning and end of the method
Figure 14 shows an implicit enhancement option at the beginning and end of FUNCTION MODULE. It is placed after commands FUNCTION and before statements ENDFUNCTION.
Figure 14
At the beginning and end of FUNCTION MODULE
Figure 15 shows an implicit enhancement option at the beginning and end of FORM. It is placed after FORM commands and before ENDFORM statements.
Figure 15
At the beginning and end of FORM
Types of Enhancement
There are two types of implicit enhancements: declaration (static) and code (dynamic).
- Static (declaration) enhancement
- Data declaration is part of a static enhancement (e.g., structure definitions TYPES, DATA, CONSTANTS, and STATICS)
- PUBLIC, PROTECTED, PRIVATE and SECTION of a class, include, interface definition, and class implementation are also part of a static enhancement
- CHANGING, IMPORTING, and EXPORTING parameter list of a method
- There is no option for selecting a type of enhancement while implementing it, but it automatically goes into the static enhancement category
- Dynamic (code) enhancement
- All ABAP code other than declarations is considered a dynamic enhancement
- You can use dynamic enhancement for form, methods, and function modules
- You can select the type of enhancement while implementing, so you can place it in both declaration and code type
- If you want to place a form, local class, or method in an implicit enhancement you have to include these in the static type of enhancement. You can’t include it in a dynamic type.
- Data declarations are always static, even if you will place them in the dynamic part of the enhancement
Implementing Implicit Enhancements
Now I’ll show you how to implement an implicit enhancement with two examples: dynamic (code) and static (declaration) types of enhancements. In the first example, I’ll deal only with a dynamic (code) enhancement and in the second I will implement both a dynamic and a static enhancement. In the first example there will be two dynamic enhancements and in the second there will be a static enhancement in addition to two dynamic enhancements.
First Example: Method Enhancement (Dynamic)
Step 1. Execute standard program ABAP_OBJECTS_ENJOY_4. The output of the program before implementing an implicit enhancement is shown in
Figure 16.
Figure 16
Output of program before implementing enhancement
Step 2. Use transaction SE80 or SE38 and enter Program name ABAP_OBJECTS_ENJOY_4 (
Figure 17). Click the Change button and you get the screen in
Figure 18, which asks for the Access key.
Figure 17
Enter Program name and click the Change button (transaction SE38)
Figure 18
Click the Display button to open code in display mode
Because it is a standard program, you cannot make changes directly. The window in
Figure 18 appears and asks for an access key. If you give an access key to change any standard object it becomes a modification, which SAP does not recommend. Click the Display button to open the program in display mode (
Figure 19).
Figure 19
Click the enhance icon or press shortcut key (Shift+F4)
Step 3. Click the enhance icon as shown in the screen in
Figure 19. This brings up the screen in
Figure 20.
Figure 20
Screen view
Step 4. Follow menu path Edit > Enhancement Operations > Show Implicit Enhancement Options (
Figure 21).
Figure 21
Select Show Implicit Enhancement Options
Step 5. Go to method WRITE and you can see two options for an implicit enhancement (
Figure 22).
Figure 22
Two implicit enhancement points for method
Step 6. Right-click the first enhancement option and select Enhancement Implementation > Create Implementation (
Figure 23).
Figure 23
Select Create Implementation
Step 7. For METHOD, you can use both Declaration (static) and Code (dynamic) enhancements (
Figure 24). In this case, click the Code button.
Figure 24
Click the Code button
Step 8. Enter the Enhancement Implementation name and the Short Text (
Figure 25). Then click the green check mark icon.
Figure 25
Enter the Enhancement Implementation and Short Text
Step 9. Give the Package name and click the save icon (
Figure 26).
Figure 26
Save the entry
Step 10. Click the new icon to create a new transport request (
Figure 27).
Figure 27
Create a new transport request
Step 11. Enter the transport request’s Short Description and click the save icon (
Figure 28).
Figure 28
Enter the Short Description and save
Step 12. Now you can see the new transport request (
Figure 29). Click the green check mark icon.
Figure 29
The new transport request
Step 13. Now you can see a white line inside ENHANCEMENT 1 ... ENDENHANCEMENT (
Figure 30). Here you can add custom code.
Figure 30
Where you can add custom code
Step 14. Add code and Click the Enhancements button to activate the enhancement (
Figure 31).
Figure 31
Activate the enhancements
Step 15. The screen in
Figure 32 appears with the enhancement already selected. Click the green check mark icon.
Figure 32
Click the green check mark icon
Step 16. Now you are ready to test the enhancement.
The output of the program after implementing the first implicit enhancement option (After Start of Method) produces the new line at the start (
Figure 33).
Figure 33
Output of the program after the first enhancement implementation
Step 17. Now you are ready to go for the second enhancement. Right-click the second enhancement option in
Figure 22 and select Enhancement Implementation > Create Implementation (
Figure 34).
Figure 34
Select Create Implementation
Step 18. The screen in
Figure 35 appears. Click the Code button so the type of enhancement is a code enhancement.
Figure 35
Click the Code button
Step 19. The screen in
Figure 36 appears. Select the enhancement and click the green check mark icon.
Figure 36
Select the enhancement implementation and click the green check mark icon
Note
You noticed that when you implemented the first enhancement the system did not display the screen in Figure 36 because no enhancement implementation was available. This time the system is displaying a window for selecting the enhancement implementation. You can select an old (custom) enhancement implementation. In this case, you are selecting ZIE_WRITE. For some cases, you can see the standard enhancement implementation but you cannot include your custom implementation in the standard system.
Step 20. Now you can again see the line inside ENHANCEMENT 2 … ENDENHANCEMENT (
Figure 37). You can add custom code here.
Figure 37
Add custom code here
Step 21. Add code line as in
Figure 38 and activate the enhancement like you did in
Figure 31. After activation, when you execute the program you get output like that in
Figure 39.
Figure 38
Custom code inside enhancement
Figure 39
Output of program after both enhancement implementations
For checking your implemented enhancement, use transaction SE80 and follow menu path Open Package > Enhancements > Enhancement Implementations > ZIE_WRITE. Double-click ZIE_WRITE and you see the screen shown in
Figure 40. On the right side, you can see that both enhancement types are Dynamic because I used the Code option in
Figures 24 and
35.
Figure 40
Both enhancement implementations are Dynamic
Second Example: Structure Definition (Static) and Form (Dynamic) Enhancements
Here you have a standard transaction S_AHR_61015554 that shows the output in ALV. In this example, I add one more column in ALV, for which I need to do three implicit enhancements:
- Include a new field in an internal table
- Fill the new field with required data
- Add the field to the field catalog for display in ALV
For this example, the requirement is that the output is showing Minimum, Maximum, and Average Pay, but it is in different Time Units (e.g., Annually, Monthly, Daily, and Weekly). You have to convert all these time units to Annually and show it in separate column of ALV. The output of the report before doing the enhancement is shown in
Figure 41.
Figure 41
Report output pre-enhancement
Step 1. Add a column in the internal table disptable. Open program RPLCMP01 and display the implicit enhancement options using the same process used in the examples in
Figures 19 and
21. You can see the implicit enhancement point just before the END OF disputable (
Figure 42). Right-click this option and select Create Implementation.
Figure 42
Select Create Implementation
This time the system does not ask you to select Code or Declaration because you are including a field in an internal table, so it automatically marks this as a static (Declaration) enhancement.
Step 2. Enter the Enhancement Implementation name, some Short Text, and click the execute icon (
Figure 43). This time the system doesn’t ask for the selection of an old implicit enhancement, but prompts you to create a new implicit enhancement implementation.
Figure 43
Enter the Enhancement Implementation name and description
Step 3. Enter the name of the Package (e.g., ZFSL) and click the save icon (
Figure 44).
Figure 44
Enter the package name and click the save icon
Step 4. Create a new transport request using the new icon in
Figure 45 and save it to the same newly created request.
Figure 45
Create a new transport request
Step 5. Enter a Short Description for the request in the screen in
Figure 46 and click the save icon.
Figure 46
Enter a Short Description for the request
Step 6. Add an object to the created request and click the green check mark icon (
Figure 47).
Figure 47
Save the object in the selected request
Step 7. Place a line of code inside the enhancement (
Figure 48) and activate it as shown in the first example (
Figure 31 and
32). The code is:
DATA: zzpyavg LIKE t710-slmax.
" Average Pay Annually
Figure 48
Add a line of code
Note
Keep in mind that the system does not give an error message if you do not use a custom name space, but it can create a problem in the future when you upgrade your system and SAP adds a field with the same name.
You have added one more column to disptable and are ready to populate it with your calculations.
Step 8. Now create the enhancement implementation for FORM disptable_fill just before ENDFORM. Select Enhancement Implementation > Create Implementation (
Figure 49). In this enhancement, you need to do calculations.
Figure 49
Select Create Implementation
Step 9. Because this enhancement is in FORM, you can choose between a Declaration and Code option (
Figure 50). Click the Code button.
Figure 50
Select the Code option
Step 10. Select the same enhancement implementation you just created for the internal table enhancement (
Figure 51). After selecting this enhancement, click the green check mark icon.
Figure 51
Select the enhancement implementation
Note
Because you have already created an enhancement for this object, the system gives a list for selecting the enhancement. In this case, you select the old one, but you can also create a new one using the create icon. If you select the new icon the screen in Figure 43 appears.
Step 11. In the resulting screen, you can insert your own code inside ENHANCEMENT 2 (
Figure 52).
Figure 52
Add code here
The code in
Figure 53 allows you to calculate the required annual salary and assign it to a new added field zzpyavg. This standard report shows salaries in different time periods (e.g., monthly, daily, weekly), but management often wants to see it on an annual bases. This code allows you to convert all salaries annually and show them in one new column.
Figure 53
Code to add inside enhancement
Step 12. You have calculated the required data in one field of the internal table. Now you have to add this field into the field catalog for display in ALV. For this, enhance the FORM fieldcatalog_fill. Create the implementation just before ENDFORM (
Figure 54).
Figure 54
Select Create Implementation
Step 13. Select the Code option (
Figure 55).
Figure 55
Click the Code button
Step 14. Copy the code in
Figure 56 and paste it in the ENHANCEMENT 3 section of the screen in
Figure 57 and activate it as shown in the first example (
Figures 31 and
32). Now you are ready to test your enhancement.
Figure 56
Code for adding field catalog
Figure 57
Paste code in Figure 56 here
The output after implementing implicit enhancements is shown in
Figure 58. You can see a new column at the end with heading Avg. Annually.
Figure 58
The output after implementing implicit enhancements
Finally, if you go back to transaction SE80, you can see confirmation that you’ve done three enhancements, including two dynamic enhancements and one static enhancement (
Figure 59).
Figure 59
Two dynamic enhancements and one static enhancement
Faisal Altaf
Faisal Altaf is a certified development consultant. He has more than seven years of experience and currently is working with Al Yamamah Steel Industries Co., Saudi Arabia, as the SAP technical division head. He completed his MS in software engineering and intends to complete his Ph.D. in the field of SAP.
You may contact the author at
faisalatsap@gmail.com.
If you have comments about this article or publication, or would like to submit an article idea, please contact the
editor.