Well in our case I don't have any standard program so I am using a Z program & enhancing the code.
Before starting explicit enhancement we have to create:
1. Right click & create Enhancement Spot.
2. Give the name of Enhancement Spot
3. Now activate the enhancement spot
4. Right click Enhancement Spots & implement it.
5. Activate the implementation, Goto SE38 & place the cursor where enhancement is require.
6. Enter Enhancement implementation name in Enhancement Spot name & Package name.
7. Now enhancement-point will come in your code with Grey Fonts.
8. Select Enhance
9. Place the cursor on enhancement-point & create enhancement.
10. Give enhancement Implementation name.
11. Place your code & activate.
12. Now run the program you will find the enhancement.
Enhancement Section:
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-Section…End Enhancement-Section.
Note - Make sure that the code which has to be replaced is within the 'ENHANCEMENT-SECTION...' and 'END-ENHANCEMENT-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' and navigate to 'Edit' à 'Enhancement Operations' à 'Create Implementation'.
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:
Summary:
1. Here we deals with the enhancement of a 'Z' program it is possible to 'CREATE' an 'ENHANCEMENT-SECTION'. 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 customer’s 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,
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----------------------------------------------------------------$*$*