Skip to main content
Skip table of contents

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:

  1. Modifications to SAP development objects

  2. 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:

  1. Explicit Enhancements – Currently not used in HaloCORE

  2. 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 :

  1. 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.

  2. Class Enhancements – Pre/Post/Overwrite method

  3. 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:

  1. developer authorization

  2. developer key

  3. a transport request and a package to assign the enhancements 

Enhancement in Subroutine

  1. Use transaction SE38 or SE80 to display the subroutine. In this example, Subroutine "FILL" of Program "ZFORM_TEST" is enhanced. 

  2. 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:

    1_Implicit Options - Subroutine.jpg

    Implicit Options - Subroutine

  3. 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.

    2_Tool bar Subroutine.jpg

    Toolbar

  4. You will be prompted to choose the type of enhancement.

    Type of Enhancement Mode

  5. Click Code to create a code implementation.

  6. Enter the name in Enhancement Implementation and its short description in Short Text and then click OK.

    Create Enhancement Implementation

  7. The enhancement spot will be created in the appropriate place. 

    FORM

    CODE
    FORM 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

  8. The ABAP Editor will now look like below: 

    5_Enhancement tags1 Subroutine.jpg

    Enhancement tags

  9. 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:

    6 Source code at the beginning Subroutine.jpg

    Source code at the beginning

  10. Pretty-print, save and activate the code.

Enhancement in Function Module

To create an implicit enhancement in the function module, proceed as follows:

  1. 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.

  2. 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:

    7 Implicit Options FM.jpg

    Implicit Options - Function Module

  3. Place the cursor at the beginning/end of the function module and then click Create.

    8 Tool bar FM.png

    Tool bar

  4. You will be prompted to choose the type of enhancement.

    Type of Enhancement Mode

  5. Click Code to create a code implementation.

  6. Enter the name in Enhancement Implementation and its short description in Short Text and then click OK.

    Create Enhancement Implementation

  7. The enhancement point will be created in the appropriate place.

    FUNCTION

    CODE
    FUNCTION 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.
  8. The ABAP Editor will now look like below: 

    11 Enhancement tags FM.jpg

    Enhancement tags

  9. 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:

    12 Source code at the end FM.jpg

    Source code at the end

  10. 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.

  1. Call transaction SE24.

  2. Enter the class name and click Display.

    13 Method.jpg

    Method

  3. In this example, Method "GENERAL" of class "ZCL_DEMOCLASS" is enhanced.

    14 Selecting a method.jpg

    Selecting a method

  4. Click on the Code button to display the source code.

  5. 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:

    15 Implicit Options Method.jpg

    Implicit Options

  6. Place the cursor at the beginning/end of the method and then click Create.

    Type of Enhancement Mode

  7. Click Code to create a code implementation.

  8. Enter the name in Enhancement Implementation and its short description in Short Text and then click OK.

    Create Enhancement Implementation

  9. The enhancement spot will be created in the appropriate place.  

    Method

    CODE
    method 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.

  10. The ABAP Editor will now look like below: 

    18 Enhancement tags Method.jpg

    Enhancement tags

  11. 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:

    19 Source code at the begining Method.jpg

    Source code at the beginning

  12. 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:

  1. Pre-Exit Method: It is invoked at runtime before the original method code has been executed or triggered.

  2. Post-Exit Method: It is invoked at runtime after the original method code has been executed or triggered.

  3. 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.

  1. Call transaction SE24.

  2. Enter the class name and click Display.    

    1. In this example, Method "GENERAL" of class "ZCL_DEMOCLASS" is enhanced.

    2. Go to the menu, select Class > click Enhance.

  3. You will be asked for an enhancement name.

    20 Method.jpg

    Method

  4. In this example, Method "GENERAL" of class "ZCL_DEMOCLASS" is enhanced.

  5. Go to the menu, select Class > click Enhance.

  6. You will be asked for an enhancement name.

    Create Enhancement Implementation

  7. Enter the name in Enhancement Implementation and its short description in Short Text and then click OK.

  8. 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).

    22 Pre_Post_Overwrite Pre.jpg

    Pre/Post/Overwrite Methods

  9. 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.

    23 PreExit Pre.jpg

    Inserting PreExit Method

    24 PostExit Pre.jpg

    Inserting PostExit Method

    25 Overwrite Pre.jpg

    Inserting Overwrite Method

  10. 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: 

    26 Enhancement point Pre.jpg

    Enhancement spot

  11. Now, paste the source code into the enhancement spot. The ABAP Editor will be similar to the following:

    27 Source code implementation Pre.jpg

    Source code implementation in Post Method

  12. Pretty-print, save, and activate the code.

New Methods in Existing Classes

Follow this procedure to create a new method in an existing class. 

  1. Use transaction SE24 or SE80 to display the class. In this example, the class "ZCL_DEMOCLASS" is used.

  2. Press Enhance button.

  3. In Create Enhancement Implementation screen, enter the required details [enhancement name, description, and package] and click OK

    Create Enhancement Implementation screen

  4. Now, add method at the end of the method list with:

    1. Define a unique name with which the method is identified.

    2. Specify the type as an instance method or a static method (not instance-specific).

    3. Define the visibility of methods (Public, Private, Protected) for the user of the class.

    29 New Method_Existing Class.jpg

    New method

  5. Double-click on the new method and paste the code.

  6. 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).

  1. Use transaction SE24 to display the class. In this example, Method "GENERAL" of class "ZCL_DEMOCLASS" is enhanced.

  2. Press Enhance button and create an enhancement implementation. 

  3. Select a method and click on the Parameter button.

    30 Class Interface.jpg

    Class Interface

  4. Add parameters as instructed by the HaloCORE Installation documentation.

    Method Parameters

  5. Activate and Save the changes.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.