Enhancement Framework – Class Enhancement – How designed

By | May 5, 2014 | Enhancement Implementation | 12,854 | 2

Lets see in details how the Enhancement Framework Class Enhancements – pre, post and overwrite methods – are designed in the class context.

Design

It is important to understand how the class enhancement is designed. So, you can better understand it when you need to implement one. Read Enhancement Framework – Class Enhancement implementation to learn more on how to enhance a class.

When you create the class enhancement, Enhancement builder would create following objects:

  • Attribute – A new attribute would be created with name %_{implementation_name} in the class attributes
  • Local Class – A new local class would be created. This class name would be LCL_{implementation_name}
    • Attribute to refer to core Object. This would be referred as the CORE_OBJECT
    • CONSTRUCTOR method
    • Interface would implemented
  • Source Code Plugin implementations
    • Implementation 1 – This would define the local attribute to store the singletone object
    • Implementation 2 – This would define the Interface. This interface would be implemented in the Local Class. This would call the CONSTRUCTOR method defined in the local class
    • Implementation 3 – This would instantiate the singletone object. After that it would call the method which is part of the interface

Interface Name

System creates specific interface for each of the different type of methods – Pre, Post and Overwrite. Naming standards for the interface name is like:

  • Pre Exit – IPR_{implementation_name}
  • Post Exit – IPO_{implementation_name}
  • Overwrite Exit – IWO_{implementation_name}

All the methods which has Pre Exit, would be defined in the Interface for the Pre-Exit. The method would have all the parameters of the actual method which is being enhanced.

Various Artifacts

The attribute in the class – the one highlighted with arrow:

The Local Class is defined like:

 
**
** PROGRAM NAME - ZTEST_NP_MEREQ================EIMP
**
CLASS LCL_ZTEST_NP_MEREQ DEFINITION.
PUBLIC SECTION.
CLASS-DATA OBJ TYPE REF TO LCL_ZTEST_NP_MEREQ.
DATA CORE_OBJECT TYPE REF TO CL_MMPUR_MEREQ_DB_UTILITY .
 INTERFACES IPR_ZTEST_NP_MEREQ.
  METHODS:
   CONSTRUCTOR IMPORTING CORE_OBJECT
     TYPE REF TO CL_MMPUR_MEREQ_DB_UTILITY OPTIONAL.
ENDCLASS.
CLASS LCL_ZTEST_NP_MEREQ IMPLEMENTATION.
METHOD CONSTRUCTOR.
  ME->CORE_OBJECT = CORE_OBJECT.
ENDMETHOD.
 
METHOD IPR_ZTEST_NP_MEREQ~GET_EBAN.
*"------------------------------------------------------------------------*
*" Declaration of PRE-method, do not insert any comments here please!
*"
*"class-methods GET_EBAN
*"  importing
*"    !IM_BANFN type BANFN
*"  raising
*"    CX_MMPUR_NOT_FOUND .
*"------------------------------------------------------------------------*
 
## - New code goes here
 
ENDMETHOD.
ENDCLASS.
 

The source code implementation is like:

 
**
** PROGRAM - ZTEST_NP_MEREQ================E
**
ENHANCEMENT 1 .
  data %_ZTEST_NP_MEREQ type ref to OBJECT .
ENDENHANCEMENT.
ENHANCEMENT 2  .
INTERFACE IPR_ZTEST_NP_MEREQ .
 
  class-methods GET_EBAN
    importing
      !IM_BANFN type BANFN
    raising
      CX_MMPUR_NOT_FOUND .
ENDINTERFACE.
INCLUDE ZTEST_NP_MEREQ================EIMP .
ENDENHANCEMENT.
ENHANCEMENT 3 .
IF LCL_ZTEST_NP_MEREQ=>OBJ IS INITIAL.
   CREATE OBJECT LCL_ZTEST_NP_MEREQ=>OBJ .
ENDIF.
LCL_ZTEST_NP_MEREQ=>OBJ->IPR_ZTEST_NP_MEREQ~GET_EBAN( IM_BANFN = IM_BANFN   ).
ENDENHANCEMENT.
 

Debugging

When you debug the Method enhancement, you would see all of this in action.

Source Code plugin is called:

Pre method implementation would be called

Next Article

Enhancement Framework – Function Module Enhancement

Table of Content – Enhancement Framework

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

2 Comments

  • Alok

    Hi Naimesh,

    Good one.
    I have a requirement for adding field in existing tab in migo transaction.
    Is it possible for u to provide document for it.

    Regards
    Alok

  • Vamshi

    Hi Naimesh,

    Very nice articles.

    Thank you.

    Regards,
    Vamshi.

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.