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.