Today, I am going to discuss the basic of AMDP script and implement a SAP BW transformation logic using AMDP script.
First question is what is AMDP script and why we will use AMDP instead of normal AMAP script for different types of routine like Start End and expert routine.
AMDP is ABAP managed Database Procedure which used to run in HANA runtime. All the database logic push to the database level for execution. In the other hand the ABAP procedure execute the logic in the ABAP layer inside ABAP runtime environment .
Business transformation logic implemented in AMDP is faster than ABAP transformation because it is executed in database layer. But always it is not useful.
If we use ODP extractor for Data extraction in BW then ABAP transformation is useful as ODP extraction and transformation both done in ABAP environment and runtime. it is not a good idea to use AMDP script until the logic is too complex.When the existing ABAP rule Type is not sufficient, then only you can define SQL script.
When you create a AMDP script transformation a SAPHANApocedure created that is implemented by a method in AMDP Class.This generated class generated by BW and only edited in the ABAP development tool.
Lets discuss about few AMDP routines –
1. Create a transformation and create a end routine using AMDP script –
2. We can see the AMDP class method. Please check three variables for the script development –
inTab -Internal table contain incoming data.
outTab -Internal table contain output data.
errorTab -Table containing erroneous records.
3. Edit the code and activate. Now below given a sample of ABAP code and equivalent AMDP code.
This can be customized as per requirement basis –
ABAP Code –
*********** Start Transformation**********************************
SELECT MATERIAL PLANT NET_PRICE GROSS_PRICE /BIC/VALID_DATE
FROM
/BIC/APLB12
INTO CORRESPONDING FIELDS OF TABLE LT_PLB FOR ALL ENTRIES IN
RESULT_PACKAGE
WHERE MATERIAL = RESULT_PACKAGE-/BIC/ZMATERIAL
AND PLANT = RESULT_PACKAGE-PLANT.
LOOP at RESULT_PACKAGE ASSIGNING <result_fields>.
********* Start Polulate Data in Result ADSO************************
READ TABLE LT_PLB INTO WA_PLB
WITH KEY MATERIAL = <result_fields>-/BIC/ZMATERIAL
PLANT = <result_fields>-PLANT.
IF sy-subrc = 0.
<result_fields>-/BIC/TOTAL PRICE = WA_PLB-GROSS_PRICE + WA_PLB-NET_PRICE.
ENDIF.
********* End Polulate Data in Result ADSO***************************
Equivalent AMDP code is –
********* Start AMDP Script *****************************************
OUTTAB = SELECT
"/BIC/POORDER",
"/BIC/ORDER_LINE",
"/BIC/SCHEDULE_LINE",
"/BIC/CREATION_DATE",
"/BIC/ZMATERIAL",
"/BIC/0PLANT",
"/BIC/TOTAL_PRICE",
CURRENCY,
SQL_PROCEDURE_SOURCE_RECORD
FROM
(SELECT
P1."/BIC/POORDER",
P1."/BIC/ORDER_LINE",
P1."/BIC/SCHEDULE_LINE",
P1."/BIC/CREATION_DATE",
P1."/BIC/ZMATERIAL",
P1."/BIC/0PLANT",
(P2.GROSS_PRICE + P2.NET_PRICE) AS "/BIC/TOTAL_PRICE",
CURRENCY,
P1.SQL_PROCEDURE_SOURCE_RECORD
FROM : TEMP_TABLE P1 LEFT OUTER JOIN "/BIC/APLB12" P2 ON P1."/BIC/ZMATERIAL" = P2.MATERIAL
AND P1."/BIC/0PLANT" = P2.PLANT);
********** END OF AMDP SCRIPT ***************************************
4. Activate the AMDP script method and then the transformation .
5. Go to the Target data preview . You can see the calculated key figure /BIC/TOTAL_PRICE calculated using AMDP script.