SAP HANA Transformations_ Unlocking Processing with AMDP
SAP HANA Transformations_ Unlocking Processing with AMDP
Note: Some user defined formulas in transformations could prevent the code pushdown to HANA.
Key Differences:
Step 2: Create transformation between aDSO and Data Source. Create expert routine from
Edit Menu -> Routine -> Expert Routine.
Pop-up will ask for confirmation to replace standard transformation with expert routine. Click on the “Yes”
button.
System will ask for ABAP routine or AMDP script. Click on AMDP Script.
An AMDP Class will be generated with default method – PROCEDURE and with default interface –
IF_AMDP_MARKER_HDB
Step 3: Open ABAP development tools in Eclipse with BW on HANA system in ABAP perspective to change
the HANA SQL script.
Output :
Scenario 2: Update the Deletion Indicator in target DSO when
the records get deleted from Source system using SQL Script
If we build this logic in ABAP, we would need to match the target records (one by one) with source object data
for all data packages and update the deletion flag with X if a record is not present in source object. This could
lead to performance issue if the records are in high volume and the SQL script logic is much simpler than
writing the logic in ABAP.
In SQL, we can achieve this by using SQL functions:
1. First step is to declare the variable lv_count to store the count of entries in Target Table. This is required to
know if it is the first-time load in DSO or the successive loads.
Based on that we will build our logic.
For the first-time data load the value of LV_COUNT value will be zero. In this case, we need to transfer all the
source data as it is to Target DSO with deletion flag as blank as we don’t need to update the flag.
For the successive date loads, we need to compare the existing records in Target DSO with the latest
records coming from Source and update the deletion flag accordingly.
**say after first load, the record with field 1 = 500 got deleted from source system. In that case, we need to
update the flag with value = X.
We can declare the variable by using DECLARE statement.
Declare varchar(3);
2. For the successive loads, we need to compare the existing records in Target with Source as mentioned
above.
Here lv_count is variable and /BIC/AZSOURCE2 is target DSO and I have copied the content in temporary
table – It_target.
For this case, I have counted the number of records in Target DSO and put it in lv_count Variable.
**It_target is the temporary table declared to store the content of target DSO which would be used to
comapare the records in source package
If Lv_Count > 0 then
/* copying the latest record from source to temporary table it_zsource1*/
It_zsource1 will have:
It_zsource3 will have data shown below and this would be the final output which we need to load it in outTAB:
This will be the final output we required and assigned it to outTab:
Below else statement is for first time load when lv_count = 0 and transfers the records from source as it is to
target.
from :intab; */
it_zsource1 = select
sourcepackage."/BIC/ZFIELD1" as field1,
sourcepackage."/BIC/ZFIELD2" as field2,
sourcepackage."/BIC/ZFIELD3" as field3,
'' as zfield1
outTab =
select
field1 as "/BIC/ZFIELD1",
' ' "RECORDMODE",
field2 as "/BIC/ZFIELD2",
field3 as "/BIC/ZFIELD3",
flag as "/BIC/ZFLAGDEL",
'' "RECORD",
'' "SQL__PROCEDURE__SOURCE__RECORD"
from :it_zsource3;
else
outTab =
select "/BIC/ZFIELD1",
' ' "RECORDMODE",
"/BIC/ZFIELD2",
"/BIC/ZFIELD3",
' ' "/BIC/ZFLAGDEL",
' ' "RECORD",
' ' "SQL__PROCEDURE__SOURCE__RECORD"
from :intab;
end if;
errorTab = select
' ' "ERROR_TEXT",
' ' "SQL__PROCEDURE__SOURCE__RECORD"
from :outTab;
Key 1,Key2, Field 3 should hold the value from source table
Field 4x should hold the latest value for field 4 from lookup table based on dates.
Field 5x should hold the sum of all the values of Field 5 based on same keys.
Field 6x should hold the previous value of the latest transaction.
Solution:
In ABAP Routines, this would be very complex in reading the previous transactions and updated the value of
the field. But in SQL script, we can use windows functions with which the complex computations can be
done in a simpler way.
There are many windows functions available in SAP HANA SQL Script:
1. Rank Over () – Return rank within a partition, starting from 1
2. Row Number () – Returns a unique row number within a partition
3. Dense Rank () – Returns ranking values without gaps.
4. Percent Rank () – Returns relative rank of a row.
5. Lead () – Returns the value of the rows after current row.
6. Lag () – Returns the value of the rows before current row.
And many more are there.
In my scenario, I will use the windows function Rank () and Lead () to achieve the required output.
Define the It_lookup temporary table and copy the records from Lookup DSO.
Then, I have ranked the records using RANK() window function based on date in descending order and also
used the windows function LEAD () to get the next value after the latest transaction.
For requirement field5x : we need to sum the values field 5x for the same keys.
Inner join It_tab1 and It_tab2 where rank = 1
This is the required output. Hence assigning the fields from It_tab3 to Outtab:
Rating: 0 / 5 (0 votes)
SAP BW/4HANA BW (SAP Business Warehouse), BW SAP HANA Data Warehousing, BW SAP HANA Modeling
Tools (Eclipse), SAP BW/4HANA. permalink .