Implicit Enhancement – Pre, Post and Overwrite-Exit in FORM

When you enhance a class you get clear options of adding Pre-exit, Post-exit and Overwrite exits. However in case of Implicit enhancement with FORM routines it not very clear how to implement these exits. In this blog I’ll show you how to implement Pre, Post and Overwrite-Exit in FORM using Implicit Enhancement technique.

For the purpose of this blog let’s consider this program and assume that this is SAP standard. We will enhance FORM print using Implicit Enhancement and add Pre, Post and Overwrite-Exits.

REPORT zenh_demo NO STANDARD PAGE HEADING .

*--------------------------------------------------------------------*
* Start of Selection
*--------------------------------------------------------------------*
START-OF-SELECTION.
  PERFORM print.

*--------------------------------------------------------------------*
* Print
*--------------------------------------------------------------------*
FORM print.
  WRITE : 'Original Code' .
ENDFORM .

Pre-Exit.

Open program in SE38, display mode, and click on Enhance button on toolbar. After this click on menu Edit->Enhancement Operation->Show Implicit Enhancement Options. You should now see enhancement options available in program similar to screen shot below.

implicit enhancement 01

To create Pre-exit, put cursor on line which is just under FORM print and use menu option Edit->Enhancement Operations->Create Implementation or press Ctrl+Shift+F8

This will prompt you to choose type of enhancement, choose Code.

type of enhancement

Specify Enhancement Implementation name, short text and save it.

enhancement name 02

System will now let you add code. I have added a write statement and my program now looks like this.

REPORT zenh_demo NO STANDARD PAGE HEADING .

*--------------------------------------------------------------------*
* Start of Selection
*--------------------------------------------------------------------*
START-OF-SELECTION.
  PERFORM print.

*--------------------------------------------------------------------*
* Print
*--------------------------------------------------------------------*
FORM print.
""""""""""""""""""""""""""""""""""$"$\SE:(1) Form PRINT, Start       A
*$*$-Start: (1)----------------------------------------------------$*$*
ENHANCEMENT 1  ZENH_DEMO.    "active version
  WRITE : 'Pre-Exit' COLOR COL_HEADING.
ENDENHANCEMENT.
*$*$-End:   (1)----------------------------------------------------$*$*
  WRITE : 'Original Code' .
ENDFORM .

Activate Enhancement and execute the program.
image004

Post-Exit

In very similar fashion you can implement Post-exit.

Click on Edit->Enhancement Operation->Show Implicit Enhancement Options. To create post-exit, put cursor on line just before ENDFORM which says ‘Form PRINT, End’ and click on menu option Edit->Enhancement Operations->Create Implementation or press Ctrl+Shift+F8.
System will prompt you form Enhancement implementation, you can choose existing implementation if you like and system will then let you add code. I have added code as shown below.

*--------------------------------------------------------------------*
* Print
*--------------------------------------------------------------------*
FORM print.
""""""""""""""""""""""""""""""""$"$\SE:(1) Form PRINT, Start        A
*$*$-Start: (1)----------------------------------------------------$*$*
ENHANCEMENT 1  ZENH_DEMO.    "active version
  WRITE : 'Pre-Exit' COLOR COL_HEADING.
ENDENHANCEMENT.
*$*$-End:   (1)----------------------------------------------------$*$*
  WRITE : 'Original Code' .
"""""""""""""""""""""""""""""""""$"$\SE:(2) Form PRINT, End         A
*$*$-Start: (2)----------------------------------------------------$*$*
ENHANCEMENT 2  ZENH_DEMO.    "active version
 WRITE: 'Post-Exit' COLOR COL_GROUP.
ENDENHANCEMENT.
*$*$-End:   (2)----------------------------------------------------$*$*
ENDFORM .

After activation and execution this is what I get

image005

Overwrite Exit

For this there no special option but with little trick you can achieve Overwrite Exit functionality.

We will add statement RETURN at the end of Pre-exit which we implemented earlier.
Open program in SE38, click on Enhance (Shift+F4) button, put cursor within code of Pre-exit and choose menu option Edit->Enhancement Operations->Change Implementation. System will now let you change code. I have changed code to add RETURN statement at the end.

*--------------------------------------------------------------------*
* Print
*--------------------------------------------------------------------*
FORM print.
""""""""""""""""""""""""""""""""""$"$\SE:(1) Form PRINT, Start       A
*$*$-Start: (1)---------------------------------------------------$*$*
ENHANCEMENT 1  ZENH_DEMO.    "active version
  WRITE : 'Overwrite-Exit' COLOR COL_HEADING.
  RETURN.
ENDENHANCEMENT.
*$*$-End:   (1)----------------------------------------------------$*$*
  WRITE : 'Original Code' .
""""""""""""""""""""""""""""""""""""$"$\SE:(2) Form PRINT, End       A
*$*$-Start: (2)----------------------------------------------------$*$*
ENHANCEMENT 2  ZENH_DEMO.    "active version
 WRITE: 'Post-Exit' COLOR COL_GROUP.
ENDENHANCEMENT.
*$*$-End:   (2)----------------------------------------------------$*$*
ENDFORM .

After activation I get this result.

image006

Pre-Exit is now effectively replacing original implementation and acting as Overwrite-Exit.

Leave a Reply