Appendix 2 - How to Apply Code Enhancements?
SAP provides a large set of customizing options enabling SAP customers to adapt SAP functionality to their needs. Customizing alone, however, cannot always fulfill all customers' requests for individual adjustments. In such cases, it may be required to enhance or change the standard SAP functionality by modifying the ABAP source code of the underlying development objects. There are two methods available for meeting SAP software adaptation needs:
Modifications to SAP development objects
Enhancements to SAP development objects
What are enhancements?
The enhancement is a concept of adding custom functionality to SAP's standard business applications without having to modify the original repository objects.
HaloCORE uses the Enhancement Framework to enhance the standard SAP delivered functionality by introducing new code. Enhancements generally only have minimal impact on software upgrades because they reside in their packages, which makes them reliable in an upgrade.
In contrast to enhancements in the Enhancement Framework, modifications change the SAP's standard objects. During an upgrade, SAP programs can be replaced by new versions and there is a risk of losing the functionality if SPAU activities are not performed properly.
Types of enhancements:
Explicit Enhancements – Currently not used in HaloCORE
Implicit Enhancements – Implicit enhancement spots are not explicitly created and delivered in the code but are automatically available at various predefined locations. These are used in HaloCORE.
What are Implicit Enhancements?
Implicit enhancement options are fixed points in compilation units – that is, points that remain intact even if the code is changed. The following are implicit enhancement options are used in HaloCORE :
At the beginning and the end of a procedure (FORM, FUNCTION, METHOD). That is, after commands FORM, FUNCTION, and METHOD, and before statements ENDFORM, ENDFUNCTION, and ENDMETHOD.
Class Enhancements – Pre/Post/Overwrite method
New methods in existing classes
General differences in the creation of enhancements
In pre-7.02 releases, the menu entries and toolbar buttons for creating enhancements are slightly different. The illustrations in this section are only indicative and may look different depending on the NetWeaver release you have.
The explanation presented in this section is solely for purposes of illustration. To demonstrate the techniques of enhancement, a basic level scenario is shown throughout this section. Please refer to the SAP Online Help (http://help.sap.com) to find an authoritative source of this content.
Prerequisites
Before you can create or modify enhancements, the following requirements must be met:
developer authorization
developer key
a transport request and a package to assign the enhancements
Enhancement in Subroutine
Use transaction SE38 or SE80 to display the subroutine. In this example, Subroutine "FILL" of Program "ZFORM_TEST" is enhanced.
Go to the menu, press Enhance button in the toolbar, and then select Edit > Enhancement Operations > Show Implicit Enhancement Options. Now, you will be able to see all implicit enhancement spots available within the code which are denoted by an additional line (””””) at the beginning and end of each function as seen below:
Implicit Options - Subroutine
Place the cursor on the generated line consisting of all double quotes at the start or end of the subroutine, as instructed by the HaloCORE installation manual, and then click Create.
Toolbar
You will be prompted to choose the type of enhancement.
Type of Enhancement Mode
Click Code to create a code implementation.
Enter the name in Enhancement Implementation and its short description in Short Text and then click OK.
Create Enhancement Implementation
The enhancement spot will be created in the appropriate place.
FORM
CODEFORM xxxxxx. [standard code] [standard code] [standard code] ENDFORM. FORM xxxxxx. """""""""""""""""""""""""""""""" [standard code] [standard code] [standard code] """""""""""""""""""""""""""""""" ENDFORM. FORM xxxxxx. ENHANCEMENT yyyyyy. * your code goes here ENDENHANCEMENT. [standard code] [standard code] [standard code] ENDFORM. FORM xxxxxx. [standard code] [standard code] [standard code] ENHANCEMENT yyyyyy. * your code goes here ENDENHANCEMENT. ENDFORM
The ABAP Editor will now look like below:
Enhancement tags
Now, paste the source code into the enhancement spot (that is, in between the ENHANCEMENT and ENDENHANCEMENT statements). The ABAP Editor will be similar to the following:
Source code at the beginning
Pretty-print, save and activate the code.
Enhancement in Function Module
To create an implicit enhancement in the function module, proceed as follows:
Use transaction SE80 or SE37 to display the Function Module. In this example, Function "ZDOC_READ_SPFLI_AIRP" of Function Module "ZFG_HALOCORE" is enhanced.
Go to the menu, press Enhance button in the toolbar, and then select Edit > Enhancement Operations > Show Implicit Enhancement Options. Now, you will be able to see all implicit enhancement spots available within the code which are denoted by an additional line (””””) at the beginning and end of each function as seen below:
Implicit Options - Function Module
Place the cursor at the beginning/end of the function module and then click Create.
Tool bar
You will be prompted to choose the type of enhancement.
Type of Enhancement Mode
Click Code to create a code implementation.
Enter the name in Enhancement Implementation and its short description in Short Text and then click OK.
Create Enhancement Implementation
The enhancement point will be created in the appropriate place.
FUNCTION
CODEFUNCTION xxxxxx. [standard code] [standard code] [standard code] ENDFUNCTION. FUNCTION xxxxxx. """""""""""""""""""""""""""""""" [standard code] [standard code] [standard code] """""""""""""""""""""""""""""""" ENDFUNCTION. FUNCTION xxxxxx. ENHANCEMENT yyyyyy. * your code goes here ENDENHANCEMENT. [standard code] [standard code] [standard code] ENDFUNCTION. FUNCTION xxxxxx. [standard code] [standard code] [standard code] ENHANCEMENT yyyyyy. * your code goes here ENDENHANCEMENT. ENDFUNCTION.
The ABAP Editor will now look like below:
Enhancement tags
Now, paste the source code into the enhancement spot (that is, in between the ENHANCEMENT and ENDENHANCEMENT statements). The ABAP Editor will be similar to the following:
Source code at the end
Pretty-print, save and activate the code.
Enhancement in Method
You can enhance the method of the class using the implicit enhancement spots. This is exactly the same as the enhancement spots on the Subroutines / Function Modules. The spots are available at the beginning of the method and the end of the method.
Call transaction SE24.
Enter the class name and click Display.
Method
In this example, Method "GENERAL" of class "ZCL_DEMOCLASS" is enhanced.
Selecting a method
Click on the Code button to display the source code.
Go to the menu, press Enhance button in the toolbar, and then select Edit > Enhancement Operations > Show Implicit Enhancement Options. Now, you will be able to see all implicit enhancement spots available within the code which are denoted by an additional line (””””) at the beginning and end of each function as seen below:
Implicit Options
Place the cursor at the beginning/end of the method and then click Create.
Type of Enhancement Mode
Click Code to create a code implementation.
Enter the name in Enhancement Implementation and its short description in Short Text and then click OK.
Create Enhancement Implementation
The enhancement spot will be created in the appropriate place.
Method
CODEmethod xxxxxx. [standard code] [standard code] [standard code] endmethod. method xxxxxx. """""""""""""""""""""""""""""""" [standard code] [standard code] [standard code] """""""""""""""""""""""""""""""" endmethod. method xxxxxx. ENHANCEMENT yyyyyy. * your code goes here ENDENHANCEMENT. [standard code] [standard code] [standard code] endmethod. method xxxxxx. [standard code] [standard code] [standard code] ENHANCEMENT yyyyyy. * your code goes here ENDENHANCEMENT. endmethod.
The ABAP Editor will now look like below:
Enhancement tags
Now, paste the source code into the enhancement spot (that is, in between the ENHANCEMENT and ENDENHANCEMENT statements). The ABAP Editor will be similar to the following:
Source code at the beginning
Save and activate the code.
Class Enhancements
To change the behavior of a method in a standard global class, you can use three different exits:
Pre-Exit Method: It is invoked at runtime before the original method code has been executed or triggered.
Post-Exit Method: It is invoked at runtime after the original method code has been executed or triggered.
Overwrite-Exit Method: It acts as a replacement at run time for the original method.
Pre-exit /Post-exit /Overwrite-exit Methods
Follow this procedure to implement enhancements (pre, post, and overwrite methods) of global classes.
Call transaction SE24.
Enter the class name and click Display.
In this example, Method "GENERAL" of class "ZCL_DEMOCLASS" is enhanced.
Go to the menu, select Class > click Enhance.
You will be asked for an enhancement name.
Method
In this example, Method "GENERAL" of class "ZCL_DEMOCLASS" is enhanced.
Go to the menu, select Class > click Enhance.
You will be asked for an enhancement name.
Create Enhancement Implementation
Enter the name in Enhancement Implementation and its short description in Short Text and then click OK.
Position the cursor on a method, via the menu Edit > Enhancement Operations > click Insert Pre-Method/Insert Post-Method/Insert Overwrite-Method (as per the requirement).
Pre/Post/Overwrite Methods
To the question "Access to Private/Protected Components of class ZCL_DEMOCLASS?", answer Yes. Now, you will be able to see the button(s) populated in Class Interface.
Inserting PreExit Method
Inserting PostExit Method
Inserting Overwrite Method
Click the PostExit button (indicated in the above figure) to add the enhancement code. In this example, PostExit Method is enhanced. Follow the same steps to enhance Pre or Overwrite method. The ABAP Editor will now look like below:
Enhancement spot
Now, paste the source code into the enhancement spot. The ABAP Editor will be similar to the following:
Source code implementation in Post Method
Pretty-print, save, and activate the code.
New Methods in Existing Classes
Follow this procedure to create a new method in an existing class.
Use transaction SE24 or SE80 to display the class. In this example, the class "ZCL_DEMOCLASS" is used.
Press Enhance button.
In Create Enhancement Implementation screen, enter the required details [enhancement name, description, and package] and click OK.
Create Enhancement Implementation screen
Now, add method at the end of the method list with:
Define a unique name with which the method is identified.
Specify the type as an instance method or a static method (not instance-specific).
Define the visibility of methods (Public, Private, Protected) for the user of the class.
New method
Double-click on the new method and paste the code.
Save and activate the method.
Adding Parameters to Methods
Follow this procedure to add parameters to methods (standard methods, or newly added as an enhancement).
Use transaction SE24 to display the class. In this example, Method "GENERAL" of class "ZCL_DEMOCLASS" is enhanced.
Press Enhance button and create an enhancement implementation.
Select a method and click on the Parameter button.
Class Interface
Add parameters as instructed by the HaloCORE Installation documentation.
Method Parameters
Activate and Save the changes.