Vous êtes sur la page 1sur 12

Adding Explicit Enhancement to custom program

Introduction:
Enhancement Framework is the new paradigm to bring all enhancement techniques under one roof. It can also
be switched using Switch Framework. The following are different enhancement technologies available under this
framework.
Source Code Enhancement
Function Group Enhancement
Class Enhancement
Kernel-BADI Enhancement
Source Code enhancement
Whenever enhancement needs to be incorporated directly into the ABAP source code, this technology shall be
provided. Implementing this technology is also called as Source Code Plug-In. There are two types of Source
Code enhancements possible.
Implicit enhancement option
Explicit enhancement option
Explicit enhancement option
As implicit enhancements are predefined enhancements provided by SAP in the source code, the explicit
enhancements can be implemented by the customers or partners.
There are two types of Explicit Enhancement options available. For this, we now have two new ABAP
statements, viz.
1.
Enhancement
point
(Syntax
2. Enhancement section (Syntax - ENHANCEMENT-SECTION)

- ENHANCEMENT-POINT)

Enhancement section is used to replace a set of code or statements with the customer (custom code). In this
technique the original source code does not get executed but, the customer implementation (custom code) gets
executed.
Note - Explicit enhancements though can be placed anywhere in the source code but, not just anywhere except
some areas where SAP would allow (program allows).
STEP 1: Create a package in transaction SE80 (Object navigator) Name YDEV

STEP 2: Navigate to 'Enhancements' folder of your package. Package (YDEV) Enhancement.


Right click the 'Enhancements' 'Create' 'Enhancement Spot'.

Fill in the details in the 'Create Enhancement Spot' dialog.

And save it into created package. Observe the enhancement spot created under the 'Enhancement Spots'
folder.

STEP 3: 'Right Click' the spot created and 'Implement' it (Create an Implementation).

Fill in all the details in the 'Create Enhancement Implementation' dialog.

STEP 4: Now, we need to 'Activate' the enhancement spot. In addition with the Enhancement spot the
'Enhancement Implementation' will get activated.

STEP 5: Here we are applying enhancements to a CUSTOM program not a standard program to demonstrate
the functionality. So we create a simple program 'YDEV_CODE' (say) it is retrieving records from the database
table 'VBAK' (Sales Document Header) and displaying a few records.

Now, if the customer wants to replace the set of logic with his own logic (say) like retrieving records from
database table 'VBAP' (Sales Document Item) and then display a few records, he/she will create an
enhancement section which goes like,
Create a program YDEV_CODE.

OUTPUT

STEP 6: Right click the area which is appropriate to apply the enhancement

Note - Explicit enhancements though can be placed anywhere in the source code but, not just anywhere except
some areas where SAP would allow (program allows).

Now, in the 'Create Enhancement Option' fill in the details, here fill the name under 'Enhancement-section'
only. Then fill in the Enhancement Spot Implementation Name which we created earlier.

Now we are able to see program lines have Enhancement-SectionEnd Enhancement-Section.

Note - Make sure that the code which has to be replaced is within the 'ENHANCEMENT-SECTION...' and 'ENDENHANCEMENT-SECTION'.
STEP 7: Now to include the custom code in the program which will replace the original code, enable the
'Enhancement Mode' by clicking on the 'Spiral' button.

Place the cursor on the 'Enhancement-section'


Operations' 'Create Implementation'.

and

navigate

to

'Edit' 'Enhancement

Fill in the details for the 'Create Enhancement Implementation' dialog. Click on 'Create' button for the 'Select
or Create Enhancement Implementation' dialog.

STEP 8: Now, write the code within the 'ENHANCEMENT' and 'ENDENHANCEMENT' statements as the
replacement code.

STEP 9: Don't forget to 'Activate' the enhancement Switch the 'Enhancement' mode OFF and 'Activate'
the entire program.

STEP 10: Execute the transaction/program to find out the difference.


Before Enhancement:

After Enhancement:

10

Summary:
1. Here we deals with the enhancement of a 'Z' program it is possible to 'CREATE' an 'ENHANCEMENTSECTION'. But, in case of a 'STANDARD SAP' program there are certain places (provided by SAP) like
'ENHANCEMENT-POINT...' and 'ENHANCEMENT-SECTION...' where we can create implementations
based on customers business functionality.
2. There can be only one and only one 'ACTIVE' implementation for an 'ENHANCEMENT-SECTION'.
Source Code:
*&---------------------------------------------------------------------*
*& Report YDEV_CODE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT YDEV_CODE.
TABLES : VBAK, VBAP.
DATA : IT_VBAK TYPE STANDARD TABLE OF VBAK INITIAL SIZE 0,
WA_VBAK TYPE VBAK,
IT_VBAP TYPE STANDARD TABLE OF VBAP INITIAL SIZE 0,
WA_VBAP TYPE VBAP.
INITIALIZATION.
REFRESH : IT_VBAK,
IT_VBAP.
CLEAR : WA_VBAK,

11

WA_VBAP.
START-OF-SELECTION.
ENHANCEMENT-SECTION YDEV_ENHANCE_SECTION SPOTS YDEV_IMPLEMENT_SPOT .
SELECT *
FROM VBAP
INTO TABLE IT_VBAP[]
UP TO 15 ROWS.

WRITE: /02 'Sales Document',


20 'Date',
40 'Time',
65 'Name of Person'.
ULINE .
IF IT_VBAP[] IS NOT INITIAL.
LOOP AT IT_VBAP INTO WA_VBAP.
WRITE: /02 WA_VBAP-VBELN,
20 WA_VBAP-POSNR,
40 WA_VBAP-MATNR,
65 WA_VBAP-MATWA.
ENDLOOP.
ENDIF.
END-ENHANCEMENT-SECTION.
*$*$-Start: YDEV_ENHANCE_SECTION----------------------------------------------------------------$*$*
ENHANCEMENT 1 YDEV_IMPLEMENT_ENHC_SECTION. "active version
SELECT *
FROM VBAP
INTO TABLE IT_VBAP[]
UP TO 10 ROWS.

WRITE: /02 'Sales Document',


20 'Sales Item',
40 'Material Number',
65 'Material entered'.
ULINE .
IF IT_VBAP[] IS NOT INITIAL.
LOOP AT IT_VBAP INTO WA_VBAP.
WRITE: /02 WA_VBAP-VBELN,
20 WA_VBAP-POSNR,
40 WA_VBAP-MATNR,
65 WA_VBAP-MATWA.
ENDLOOP.
ENDIF.
ENDENHANCEMENT.
*$*$-End: YDEV_ENHANCE_SECTION----------------------------------------------------------------$*$*

12

Vous aimerez peut-être aussi