30 May 2009

Calculation on data which is split into different packages

During the data load data is split by data packets and the start routine in update rule is applied packet by packet. It is hence not possible to do calculation in start routine which requires a group of the records as they
could be split in to different packets.

Solution1 :
In reference to the blog
https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/3f91f628-0b01-0010-9da8-9e7ca2cbb104

we have mark the infopackage to load the data only upto to PSA.Then we extract data of PSA , apply our logic for calculation and write back to PSA. After we can update data from PSA to data targets.
That is,
The ABAP for reading the PSA data and writing back to PSA is in four sections
a- Get the request number ( call FM : RSSM_API_REQUEST_GET )
b- Get data ( call FM : RSAR_ODS_API_GET )
c- Change Data ( Custom code to do the calculations that you want )
d- Write data back to PSA ( Call FM : RSAR_ODS_API_PUT )

Solution2:
If your loading data from and ODS to any data target. Then we follow this approach.
You can write a custom program to update the active table of the source ODS.
As active table is a flat table, you can easily do your calculations using a custom program and update the active table. Following is the program i tried for my requirment :

REPORT ZBW_SORTING_HR.

DATA: IT_RESULTS LIKE /BIC/AZPT_O0200 OCCURS 0 WITH HEADER LINE.
DATA: WA_TEMP LIKE /BIC/AZPT_O0200.
DATA: IT_SORTED1 LIKE /BIC/AZPT_O0200 OCCURS 0 WITH HEADER LINE.
DATA: KEY3(255) TYPE C,KEY1(255) TYPE C, KEY2(255) TYPE C.
DATA: END_DATE LIKE /BIC/AZPT_O0200-calday.
DATA: START_DATE LIKE /BIC/AZPT_O0200-calday.
clear : it_results.

SELECT * FROM /BIC/AZPT_O0200 INTO TABLE IT_RESULTS.

SORT it_results by
EMPLOYEE
CALDAY
REPTT
UNIT.

clear : wa_temp,it_sorted1.
clear : key1,key2,start_date,end_date.

LOOP AT IT_RESULTS INTO WA_TEMP.

CONCATENATE WA_TEMP-EMPLOYEE WA_TEMP-REPTT INTO KEY1.

IF KEY2 = KEY1.
END_DATE = WA_TEMP-CALDAY.
WA_TEMP-/BIC/ZDAY_TO = END_DATE.
WA_TEMP-/BIC/ZDAY_FROM = START_DATE.
ELSE.
START_DATE = WA_TEMP-CALDAY.
END_DATE = WA_TEMP-CALDAY.
WA_TEMP-/BIC/ZDAY_TO = END_DATE.
WA_TEMP-/BIC/ZDAY_FROM = START_DATE.

ENDIF.

KEY2 = KEY1.

APPEND WA_TEMP TO IT_SORTED1.
endloop.

UPDATE /BIC/AZPT_O0200 FROM TABLE IT_SORTED1.

20 May 2009

Templates for Start Routine

Following is the sample code for start routine in Transformation :

DATA: WA_TEMP TYPE DATA_PACKAGE_STRUCTURE, KEY1(255) TYPE C, KEY2(255)
TYPE C.
DATA: KEY3(255) TYPE C.
DATA: END_DATE LIKE DATA_PACKAGE-CALDAY.
DATA: START_DATE LIKE DATA_PACKAGE-CALDAY.

SORT DATA_PACKAGE BY
EMPLOYEE
CALDAY
REPTT
UNIT.

LOOP at DATA_PACKAGE INTO WA_TEMP.

CONCATENATE WA_TEMP-EMPLOYEE WA_TEMP-REPTT INTO KEY1.

IF KEY2 = KEY1.
END_DATE = WA_TEMP-CALDAY.
WA_TEMP-/BIC/ZDAY_TO = END_DATE.
WA_TEMP-/BIC/ZDAY_FROM = START_DATE.
ELSE.
START_DATE = WA_TEMP-CALDAY.
END_DATE = WA_TEMP-CALDAY.
WA_TEMP-/BIC/ZDAY_TO = END_DATE.
WA_TEMP-/BIC/ZDAY_FROM = START_DATE.

ENDIF.


KEY2 = KEY1.

MODIFY DATA_PACKAGE FROM WA_TEMP.

ENDLOOP.