Quantcast
Channel: Visual BI Solutions
Viewing all articles
Browse latest Browse all 989

Converting ABAP code into AMDP scripts in SAP BW transformations

$
0
0

With the advent of BW on HANA, “HANA push down” is used as a best practice. It pushes all the calculations, logics and joins to HANA, thereby making it faster. One of the places where HANA push down is possible is a BW transformation. There are few things that prevent the execution of BW transformation in HANA, the major reason being transformation routines – Start, End, Field, and Expert Routines. The entire list can be found here(section 1.2.7).

For a BW transformation with the ABAP routine to run on HANA, it should be converted to AMDP script. Unlike ABAP transformation, where row level processing is possible, in AMDP, data is processed as a package using an INSERT AS SELECT on the calculation scenario generated. In this blog, we will focus on tips and tricks used in converting ABAP code to AMDP scripts and concentrate on the most frequently used ABAP keywords.

1. Delete:

In ABAP, the DELETE statement is used to remove certain records from an internal table based on certain conditions. In the AMDP script, the DELETE statement is replaced by SELECT statements.

ABAP:

converting-abap-code-amdp-scripts-sap-bw-transformations

 

AMDP:

converting-abap-code-amdp-scripts-sap-bw-transformations

 

In ABAP, after the delete statement is executed the data is available in source_package, but in AMDP, it will be available in temp table (Table1, 2, 3…) and the same should be used for further processing.

2. IF-ELSE Statements

The IF-ELSE-ENDIF statements are used in ABAP to process different logical blocks of code based on different conditions. In AMDP code, the IF-ELSE statements can be replaced by CASE-END statements.

ABAP:

converting-abap-code-amdp-scripts-sap-bw-transformations

 

AMDP:

converting-abap-code-amdp-scripts-sap-bw-transformations

 

Example 2: Nested if-else can also be commonly seen as a part of ABAP code and CASE statements can be used to replace nested if-else statements as well. An example with nested CASE is shown below.

ABAP:

converting-abap-code-amdp-scripts-sap-bw-transformations

 

AMDP:

converting-abap-code-amdp-scripts-sap-bw-transformations

 

3. Sort, Delete adjacent duplicates and For all entries:

Sort and delete adjacent duplicates used in ABAP code are not compatible with AMDP scripts.

Sort statements can be replaced by the “ORDER BY” clause in AMDP. Just like the SORT statement, multiple fields can be used with the “ORDER BY” clause as well. The default sort order is ascending and if the sort order must be descending, then the order by clause needs the “DESC” addition.

ABAP:

converting-abap-code-amdp-scripts-sap-bw-transformations

 

AMDP:

converting-abap-code-amdp-scripts-sap-bw-transformations

 

Delete adjacent duplicates in ABAP is achieved in the AMDP script using the ROW_NUMBER() and OVER() functions. The “PARTITION BY” clause divides the data into groups and ROW_NUMBER() clause assigns a row number for the partitioned data. If the partition by clause is not used, then the entire set is considered as a single group of data.

For all entries:

In ABAP, FOR ALL ENTRIES statement is used to fetch corresponding data for all the records in the source or result package. The same functionality can be achieved using “LEFT OUTER JOIN” in the AMDP script.

ABAP:

converting-abap-code-amdp-scripts-sap-bw-transformations

 

AMDP:

converting-abap-code-amdp-scripts-sap-bw-transformations

 

An important point to be noted during joins in AMDP – If any table other than intab/outtab is to be used in AMDP join, then the table name must be specified in the ‘METHOD PROCEDURE’ statement along with the “USING” clause.

converting-abap-code-amdp-scripts-sap-bw-transformations

 

4. Loop and Read statements:

In ABAP, single record processing of data in the source and result packages is achieved with the help of LOOP-ENDLOOP and READ TABLE statements. Since LOOP-ENDLOOP along with READ statements are not compatible with AMDP script, subqueries are used to replace them.

(The fields that are populated in the subquery can be made use of in the main select).

Note: A calculated field cannot be used for the calculation of another field within the same SELECT. The calculation is to be carried out in the subquery and then the calculated field may be used for another calculation in the main select.

ABAP:

converting-abap-code-amdp-scripts-sap-bw-transformations

 

AMDP:

converting-abap-code-amdp-scripts-sap-bw-transformations

 

In the subsequent blog, some more commonly used ABAP functions and the tricks to convert them to AMDP script will be discussed.

 

Know more about Visual BI Solutions SAP BW Services offerings here.

Subscribe to our Newsletter

The post Converting ABAP code into AMDP scripts in SAP BW transformations appeared first on Visual BI Solutions.


Viewing all articles
Browse latest Browse all 989

Trending Articles