How to substract one row data from another in a DSO in SAP BW

Scenario: The source data is coming in the form of ytd numbers. Below is an example of year to date (YTD) numbers:

ytd numbers.png

The user wants to see the monthly values instead of the YTD values, below is the data which the user wants to see in the report:

ytd numbers.png

Thus the monthly 2017.02 values are 2017.02 value – 2017.01 value.

Thus, the first month value will be as it is, the second month value will  be second month – first month, the third month value will be third month value – second month value.

Solution:

Load the source data as it is into a write optimized DSO. Then load this data to a standard DSO. The Standard DSO should have all the fields as key fields except Amount which will be data field.

Create one more key figure Amount MTD to store the MTD values. Add this key figure as data field in the DSO.

Below are the technical names in the DSO

  • Name of the Standard DSO: ZDSO
  • Name of the write-optimized DSO: ZWDSO

Key fields in ZDSO:

  • ZCUST – Customer
  • ZREG – Region
  • ZMAT – Material
  • 0CALMONTH – Calendar Month
  • ZACCNT – Account

Data Fields in ZDSO:

  • ZAMNT – Amount
  • ZAMNT_MTD – Amount MTD

 

In the start routine of ZDSO, write the below ABAP code:

start routine.PNG

Start Routine Declaration Part:

*Declaration of Structure and Internal Table.
TYPESBEGIN OF ty_wdso,
ZCUST TYPE /BIC/OIZREG,
ZREG TYPE /BIC/OIZREG,
ZMAT TYPE /BIC/OIZMAT,
ZMONTH TYPE /BI0/OICALMONTH,
 ZACCNT TYPE /BIC/OIZACCNT,
ZAMOUNT TYPE /BIC/OIZAMOUNT,
END OF ty_wdso.
DATA:ls_wdso TYPE ty_wdso.
DATA:ls_wdso1 TYPE ty_wdso.
DATA:ls_wdsob TYPE ty_wdso.
DATA:ls_wdsoc TYPE ty_wdso.
DATA:lt_wdso TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_01 TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_02 TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_03 TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_04 TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_05 TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_06 TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_07 TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_08 TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_09 TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_10 TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_11 TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_12 TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_01a TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_02a TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_03a TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_04a TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_05a TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_06a TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_07a TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_08a TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_09a TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_10a TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_11a TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_12a TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_01b TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_02b TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_03b TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_04b TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_05b TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_06b TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_07b TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_08b TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_09b TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_10b TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_11b TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA:lt_wdso_12b TYPE STANDARD TABLE OF ty_wdso.
DATA:lt_wdso_01c TYPE STANDARD TABLE OF ty_wdso.
DATA:lt_wdso_02c TYPE STANDARD TABLE OF ty_wdso.
DATA:lt_wdso_03c TYPE STANDARD TABLE OF ty_wdso.
DATA:lt_wdso_04c TYPE STANDARD TABLE OF ty_wdso.
DATA:lt_wdso_05c TYPE STANDARD TABLE OF ty_wdso.
DATA:lt_wdso_06c TYPE STANDARD TABLE OF ty_wdso.
DATA:lt_wdso_07c TYPE STANDARD TABLE OF ty_wdso.
DATA:lt_wdso_08c TYPE STANDARD TABLE OF ty_wdso.
DATA:lt_wdso_09c TYPE STANDARD TABLE OF ty_wdso.
DATA:lt_wdso_10c TYPE STANDARD TABLE OF ty_wdso.
DATA:lt_wdso_11c TYPE STANDARD TABLE OF ty_wdso.
DATA:lt_wdso_12c TYPE STANDARD TABLE OF ty_wdso.
CLASS-DATA ZSTATUS1 TYPE LENGTH 1.
CLASS-DATA ZSTATUS2 TYPE LENGTH 1.
CLASS-DATA ZSTATUS3 TYPE LENGTH 1.
CLASS-DATA ZSTATUS4 TYPE LENGTH 1.
CLASS-DATA ZSTATUS5 TYPE LENGTH 1.
CLASS-DATA ZSTATUS6 TYPE LENGTH 1.
CLASS-DATA ZSTATUS7 TYPE LENGTH 1.
CLASS-DATA ZSTATUS8 TYPE LENGTH 1.
CLASS-DATA ZSTATUS9 TYPE LENGTH 1.
CLASS-DATA ZSTATUS10 TYPE LENGTH 1.
CLASS-DATA ZSTATUS11 TYPE LENGTH 1.
DATAzcalmonth TYPE LENGTH 32.
DATAzcalmonth1 TYPE LENGTH 32.
DATAzmonth TYPE LENGTH 2.
DATAzyear TYPE LENGTH 4. 

 

Start Routine Part:

**********Calculate YTD -> MTD for each month*************
 *In source ZAMNT is YTD. MTD data is
 *not available in source. Below routine will
 *convert YTD value to MTD for every month and update it to Field
 *Amount MTD(ZAMNT_MTD).
 *//Declaration of Structure and Internal Table.
TYPESBEGIN OF ty_period,
zcalmonth TYPE LENGTH 32,
END OF ty_period.
DATAlt_zperiod TYPE TABLE OF ty_period.
DATAlt_zperiod1 TYPE TABLE OF ty_period.
DATAls_zperiod TYPE ty_period.
DATAls_source_package TYPE _ty_s_SC_1.
DATAlt_source_package TYPE TABLE OF _ty_s_SC_1.
DATAlr_zperiod TYPE RANGE OF ty_period-zcalmonth.
DATAlsr_zperiod LIKE LINE OF lr_zperiod.
*//Take the distinct values for month in Source package and get the
 *previous month for the months available in source package.Select the
 *data from
 *Table /BIC/AZWDSO00 for only previous month and add into internal
 *table and it will be
 *used in endroutine to derive the MTD Amount.
lt_source_package[] SOURCE_PACKAGE[].
SORT lt_source_package BY /BI0/0CALMONTH.
DELETE ADJACENT DUPLICATES FROM lt_source_package COMPARING
/BI0/0CALMONTH.
LOOP AT lt_source_package INTO ls_source_package.
zcalmonth1 ls_source_package-/BI0/0CALMONTH.
APPEND zcalmonth1 TO lt_zperiod.
zmonth ls_source_package-/BI0/0CALMONTH+5(2).
IF zmonth > 1.
zmonth zmonth 1.
ELSEIF ZMONTH 1.
zmonth ls_source_package-/BI0/0CALMONTH+6(1).
ENDIF.
zyear ls_source_package-/BI0/0CALMONTH+0(4).
IF zmonth < 10.
CONCATENATE '0' zmonth INTO zmonth.
CONCATENATE zyear '.' zmonth INTO zcalmonth.
ELSE.
CONCATENATE zyear '.' zmonth INTO zcalmonth.
ENDIF.
APPEND zcalmonth TO lt_zperiod.
APPEND zcalmonth TO lt_zperiod1.
ENDLOOP.
SORT lt_zperiod BY zcalmonth.
SORT lt_zperiod1 BY zcalmonth.
DELETE ADJACENT DUPLICATES FROM lt_zperiod COMPARING
zcalmonth.
DELETE ADJACENT DUPLICATES FROM lt_zperiod1 COMPARING
zcalmonth.
CLEAR ls_source_package.
DELETE SOURCE_PACKAGE WHERE /BIC/ZAMOUNT EQ 0.
*//Select the data from Table /BIC/AZWDSO00 into internal table for
 *the periods in internal table lt_zperiod.
REFRESH:lt_wdso.
LOOP AT lt_zperiod INTO ls_zperiod.
zmonth ls_zperiod-zcalmonth+5(2).
IF zmonth '01'.
IF lt_wdso_01 IS INITIAL.
SELECT /BIC/ZCUST /BIC/ZREG /BIC/ZMAT /BI0/0CALMONTH
/BIC/ZACCNT /BIC/ZAMNT FROM /BIC/AZWDSO00 INTO TABLE
lt_wdso WHERE /BI0/0CALMONTH ls_zperiod-zcalmonth.
lt_wdso_01[] lt_wdso[].
REFRESHlt_wdso.
ENDIF.
ELSEIF zmonth '02'.
IF lt_wdso_02 IS INITIAL.
SELECT /BIC/ZCUST /BIC/ZREG /BIC/ZMAT /BI0/0CALMONTH
/BIC/ZACCNT /BIC/ZAMNT FROM /BIC/AZWDSO00 INTO TABLE
lt_wdso WHERE /BI0/0CALMONTH ls_zperiod-zcalmonth.
lt_wdso_02[] lt_wdso[].
REFRESHlt_wdso.
ENDIF.
ELSEIF zmonth '03'.
IF lt_wdso_03 IS INITIAL.
SELECT /BIC/ZCUST /BIC/ZREG /BIC/ZMAT /BI0/0CALMONTH
/BIC/ZACCNT /BIC/ZAMNT FROM /BIC/AZWDSO00 INTO TABLE
lt_wdso WHERE /BI0/0CALMONTH ls_zperiod-zcalmonth.
lt_wdso_03[] lt_wdso[].
REFRESHlt_wdso.
ENDIF.
ELSEIF zmonth '04'.
IF lt_wdso_04 IS INITIAL.
SELECT /BIC/ZCUST /BIC/ZREG /BIC/ZMAT /BI0/0CALMONTH
/BIC/ZACCNT /BIC/ZAMNT FROM /BIC/AZWDSO00 INTO TABLE
lt_wdso WHERE /BI0/0CALMONTH ls_zperiod-zcalmonth.
lt_wdso_04[] lt_wdso[].
REFRESHlt_wdso.
ENDIF.
ELSEIF zmonth '05'.
IF lt_wdso_05 IS INITIAL.
SELECT /BIC/ZCUST /BIC/ZREG /BIC/ZMAT /BI0/0CALMONTH
/BIC/ZACCNT /BIC/ZAMNT FROM /BIC/AZWDSO00 INTO TABLE
lt_wdso WHERE /BI0/0CALMONTH ls_zperiod-zcalmonth.
lt_wdso_05[] lt_wdso[].
REFRESHlt_wdso.
ENDIF.
ELSEIF zmonth '06'.
IF lt_wdso_06 IS INITIAL.
SELECT /BIC/ZCUST /BIC/ZREG /BIC/ZMAT /BI0/0CALMONTH
/BIC/ZACCNT /BIC/ZAMNT FROM /BIC/AZWDSO00 INTO TABLE
lt_wdso WHERE /BI0/0CALMONTH ls_zperiod-zcalmonth.
lt_wdso_06[] lt_wdso[].
REFRESHlt_wdso.
ENDIF.
ELSEIF zmonth '07'.
IF lt_wdso_07 IS INITIAL.
SELECT /BIC/ZCUST /BIC/ZREG /BIC/ZMAT /BI0/0CALMONTH
/BIC/ZACCNT /BIC/ZAMNT FROM /BIC/AZWDSO00 INTO TABLE
lt_wdso WHERE /BI0/0CALMONTH ls_zperiod-zcalmonth.
lt_wdso_07[] lt_wdso[].
REFRESHlt_wdso.
ENDIF.
ELSEIF zmonth '08'.
IF lt_wdso_08 IS INITIAL.
SELECT /BIC/ZCUST /BIC/ZREG /BIC/ZMAT /BI0/0CALMONTH
/BIC/ZACCNT /BIC/ZAMNT FROM /BIC/AZWDSO00 INTO TABLE
lt_wdso WHERE /BI0/0CALMONTH ls_zperiod-zcalmonth.
lt_wdso_08[] lt_wdso[].
REFRESHlt_wdso.
ENDIF.
ELSEIF zmonth '09'.
IF lt_wdso_09 IS INITIAL.
SELECT /BIC/ZCUST /BIC/ZREG /BIC/ZMAT /BI0/0CALMONTH
/BIC/ZACCNT /BIC/ZAMNT FROM /BIC/AZWDSO00 INTO TABLE
lt_wdso WHERE /BI0/0CALMONTH ls_zperiod-zcalmonth.
lt_wdso_09[] lt_wdso[].
REFRESHlt_wdso.
ENDIF.
ELSEIF zmonth '10'.
IF lt_wdso_10 IS INITIAL.
SELECT /BIC/ZCUST /BIC/ZREG /BIC/ZMAT /BI0/0CALMONTH
/BIC/ZACCNT /BIC/ZAMNT FROM /BIC/AZWDSO00 INTO TABLE
lt_wdso WHERE  /BI0/0CALMONTH ls_zperiod-zcalmonth.
lt_wdso_10[] lt_wdso[].
REFRESHlt_wdso.
ENDIF.
ELSEIF zmonth '11'.
IF lt_wdso_11 IS INITIAL.
SELECT /BIC/ZCUST /BIC/ZREG /BIC/ZMAT /BI0/0CALMONTH
/BIC/ZACCNT /BIC/ZAMNT FROM /BIC/AZWDSO00 INTO TABLE
lt_wdso WHERE /BI0/0CALMONTH ls_zperiod-zcalmonth.
lt_wdso_11[] lt_wdso[].
REFRESHlt_wdso.
ENDIF.
ELSEIF zmonth '12'.
IF lt_wdso_12 IS INITIAL.
SELECT /BIC/ZCUST /BIC/ZREG /BIC/ZMAT /BI0/0CALMONTH
/BIC/ZACCNT /BIC/ZAMNT FROM /BIC/AZWDSO00 INTO TABLE
lt_wdso WHERE /BI0/0CALMONTH ls_zperiod-zcalmonth.
lt_wdso_12[] lt_wdso[].
REFRESHlt_wdso.
ENDIF.
ENDIF.
ENDLOOP.
*BREAK-POINT.
IF lt_wdso_01a IS INITIAL.
IF lt_wdso_01 IS NOT INITIAL AND lt_wdso_02 IS NOT INITIAL.
  CLEARls_wdso,ls_wdso1.
  LOOP AT lt_wdso_01 INTO ls_wdso1.
 READ TABLE lt_wdso_02 WITH KEY /BIC/ZCUST =
  ls_wdso1-/BIC/ZCUST
  /BIC/ZREG ls_wdso1-/BIC/ZREG
  /BIC/ZMAT ls_wdso1-/BIC/ZMAT
  /BI0/0CALMONTHls_wdso1-/BIC/0CALMONTH
  /BIC/ZACCNT ls_wdso1-/BIC/ZACCNT
  /BIC/ZAMNT ls_wdso1-/BIC/ZAMNT
 TRANSPORTING NO FIELDS.
  IF SY-SUBRC 0.
  APPEND ls_wdso1 TO lt_wdso_01a.
  ELSE.
  APPEND ls_wdso1 TO lt_wdso_01b.
  ENDIF.
  ENDLOOP.
ENDIF.
ENDIF.
IF lt_wdso_02a IS INITIAL.
IF lt_wdso_02 IS NOT INITIAL AND lt_wdso_03 IS NOT INITIAL.
  CLEARls_wdso,ls_wdso1.
  LOOP AT lt_wdso_02 INTO ls_wdso1.
 READ TABLE lt_wdso_03 WITH KEY /BIC/ZCUST =
  ls_wdso1-/BIC/ZCUST
  /BIC/ZREG ls_wdso1-/BIC/ZREG
  /BIC/ZMAT ls_wdso1-/BIC/ZMAT
  /BI0/0CALMONTHls_wdso1-/BIC/0CALMONTH
  /BIC/ZACCNT ls_wdso1-/BIC/ZACCNT
  /BIC/ZAMNT ls_wdso1-/BIC/ZAMNT
 TRANSPORTING NO FIELDS.
  IF SY-SUBRC 0.
  APPEND ls_wdso1 TO lt_wdso_02a.
  ELSE.
  APPEND ls_wdso1 TO lt_wdso_02b.
  ENDIF.
  ENDLOOP.
ENDIF.
ENDIF.
IF lt_wdso_03a IS INITIAL.
IF lt_wdso_03 IS NOT INITIAL AND lt_wdso_04 IS NOT INITIAL.
  CLEARls_wdso,ls_wdso1.
  LOOP AT lt_wdso_03 INTO ls_wdso1.
READ TABLE lt_wdso_04 WITH KEY  /BIC/ZCUST =
  ls_wdso1-/BIC/ZCUST
  /BIC/ZREG ls_wdso1-/BIC/ZREG
  /BIC/ZMAT ls_wdso1-/BIC/ZMAT
  /BI0/0CALMONTHls_wdso1-/BIC/0CALMONTH
  /BIC/ZACCNT ls_wdso1-/BIC/ZACCNT
  /BIC/ZAMNT ls_wdso1-/BIC/ZAMNT
   TRANSPORTING NO FIELDS.
  IF SY-SUBRC 0.
  APPEND ls_wdso1 TO lt_wdso_03a.
  ELSE.
  APPEND ls_wdso1 TO lt_wdso_03b.
  ENDIF.
  ENDLOOP.
ENDIF.
ENDIF.
IF lt_wdso_04a IS INITIAL.
IF lt_wdso_04 IS NOT INITIAL AND lt_wdso_05 IS NOT INITIAL.
  CLEARls_wdso,ls_wdso1.
  LOOP AT lt_wdso_04 INTO ls_wdso1.
 READ TABLE lt_wdso_05 WITH KEY  /BIC/ZCUST =
  ls_wdso1-/BIC/ZCUST
  /BIC/ZREG ls_wdso1-/BIC/ZREG
  /BIC/ZMAT ls_wdso1-/BIC/ZMAT
  /BI0/0CALMONTHls_wdso1-/BIC/0CALMONTH
  /BIC/ZACCNT ls_wdso1-/BIC/ZACCNT
  /BIC/ZAMNT ls_wdso1-/BIC/ZAMNT
  TRANSPORTING NO FIELDS.
  IF SY-SUBRC 0.
  APPEND ls_wdso1 TO lt_wdso_04a.
  ELSE.
  APPEND ls_wdso1 TO lt_wdso_04b.
  ENDIF.
  ENDLOOP.
ENDIF.
ENDIF.
IF lt_wdso_05a IS INITIAL.
IF lt_wdso_05 IS NOT INITIAL AND lt_wdso_06 IS NOT INITIAL.
  CLEARls_wdso,ls_wdso1.
  LOOP AT lt_wdso_05 INTO ls_wdso1.
 READ TABLE lt_wdso_06 WITH KEY  /BIC/ZCUST =
  ls_wdso1-/BIC/ZCUST
  /BIC/ZREG ls_wdso1-/BIC/ZREG
  /BIC/ZMAT ls_wdso1-/BIC/ZMAT
  /BI0/0CALMONTHls_wdso1-/BIC/0CALMONTH
  /BIC/ZACCNT ls_wdso1-/BIC/ZACCNT
  /BIC/ZAMNT ls_wdso1-/BIC/ZAMNT
  TRANSPORTING NO FIELDS.
  IF SY-SUBRC 0.
  APPEND ls_wdso1 TO lt_wdso_05a.
  ELSE.
  APPEND ls_wdso1 TO lt_wdso_05b.
  ENDIF.
  ENDLOOP.
ENDIF.
ENDIF.
IF lt_wdso_06a IS INITIAL.
IF lt_wdso_06 IS NOT INITIAL AND lt_wdso_07 IS NOT INITIAL.
  CLEARls_wdso,ls_wdso1.
  LOOP AT lt_wdso_06 INTO ls_wdso1.
READ TABLE lt_wdso_07 WITH KEY  /BIC/ZCUST =
  ls_wdso1-/BIC/ZCUST
  /BIC/ZREG ls_wdso1-/BIC/ZREG
  /BIC/ZMAT ls_wdso1-/BIC/ZMAT
  /BI0/0CALMONTHls_wdso1-/BIC/0CALMONTH
  /BIC/ZACCNT ls_wdso1-/BIC/ZACCNT
  /BIC/ZAMNT ls_wdso1-/BIC/ZAMNT
  TRANSPORTING NO FIELDS.
  IF SY-SUBRC 0.
  APPEND ls_wdso1 TO lt_wdso_06a.
  ELSE.
  APPEND ls_wdso1 TO lt_wdso_06b.
  ENDIF.
  ENDLOOP.
ENDIF.
ENDIF.
IF lt_wdso_07a IS INITIAL.
IF lt_wdso_07 IS NOT INITIAL AND lt_wdso_08 IS NOT INITIAL.
  CLEARls_wdso,ls_wdso1.
  LOOP AT lt_wdso_07 INTO ls_wdso1.
READ TABLE lt_wdso_08 WITH KEY  /BIC/ZCUST =
  ls_wdso1-/BIC/ZCUST
  /BIC/ZREG ls_wdso1-/BIC/ZREG
  /BIC/ZMAT ls_wdso1-/BIC/ZMAT
  /BI0/0CALMONTHls_wdso1-/BIC/0CALMONTH
  /BIC/ZACCNT ls_wdso1-/BIC/ZACCNT
  /BIC/ZAMNT ls_wdso1-/BIC/ZAMNT
  TRANSPORTING NO FIELDS.
  IF SY-SUBRC 0.
  APPEND ls_wdso1 TO lt_wdso_07a.
  ELSE.
  APPEND ls_wdso1 TO lt_wdso_07b.
  ENDIF.
  ENDLOOP.
ENDIF.
ENDIF.
IF lt_wdso_08a IS INITIAL.
IF lt_wdso_08 IS NOT INITIAL AND lt_wdso_09 IS NOT INITIAL.
  CLEARls_wdso,ls_wdso1.
  LOOP AT lt_wdso_08 INTO ls_wdso1.
READ TABLE lt_wdso_09 WITH KEY / /BIC/ZCUST =
  ls_wdso1-/BIC/ZCUST
  /BIC/ZREG ls_wdso1-/BIC/ZREG
  /BIC/ZMAT ls_wdso1-/BIC/ZMAT
  /BI0/0CALMONTHls_wdso1-/BIC/0CALMONTH
  /BIC/ZACCNT ls_wdso1-/BIC/ZACCNT
  /BIC/ZAMNT ls_wdso1-/BIC/ZAMNT
 TRANSPORTING NO FIELDS.
  IF SY-SUBRC 0.
  APPEND ls_wdso1 TO lt_wdso_08a.
  ELSE.
  APPEND ls_wdso1 TO lt_wdso_08b.
  ENDIF.
  ENDLOOP.
ENDIF.
ENDIF.
IF lt_wdso_09a IS INITIAL.
IF lt_wdso_09 IS NOT INITIAL AND lt_wdso_10 IS NOT INITIAL.
  CLEARls_wdso,ls_wdso1.
  LOOP AT lt_wdso_09 INTO ls_wdso1.
READ TABLE lt_wdso_10 WITH KEY  /BIC/ZCUST =
  ls_wdso1-/BIC/ZCUST
  /BIC/ZREG ls_wdso1-/BIC/ZREG
  /BIC/ZMAT ls_wdso1-/BIC/ZMAT
  /BI0/0CALMONTHls_wdso1-/BIC/0CALMONTH
  /BIC/ZACCNT ls_wdso1-/BIC/ZACCNT
  /BIC/ZAMNT ls_wdso1-/BIC/ZAMNT
 TRANSPORTING NO FIELDS.
  IF SY-SUBRC 0.
  APPEND ls_wdso1 TO lt_wdso_09a.
  ELSE.
  APPEND ls_wdso1 TO lt_wdso_09b.
  ENDIF.
  ENDLOOP.
ENDIF.
ENDIF.
IF lt_wdso_10a IS INITIAL.
IF lt_wdso_10 IS NOT INITIAL AND lt_wdso_11 IS NOT INITIAL.
  CLEARls_wdso,ls_wdso1.
  LOOP AT lt_wdso_10 INTO ls_wdso1.

READ TABLE lt_wdso_11 WITH KEY  /BIC/ZCUST =
  ls_wdso1-/BIC/ZCUST
  /BIC/ZREG ls_wdso1-/BIC/ZREG
  /BIC/ZMAT ls_wdso1-/BIC/ZMAT
  /BI0/0CALMONTHls_wdso1-/BIC/0CALMONTH
  /BIC/ZACCNT ls_wdso1-/BIC/ZACCNT
  /BIC/ZAMNT ls_wdso1-/BIC/ZAMNT
TRANSPORTING NO FIELDS.
  IF SY-SUBRC 0.
  APPEND ls_wdso1 TO lt_wdso_10a.
  ELSE.
  APPEND ls_wdso1 TO lt_wdso_10b.
  ENDIF.
  ENDLOOP.
ENDIF.
ENDIF.
IF lt_wdso_11a IS INITIAL.
IF lt_wdso_11 IS NOT INITIAL AND lt_wdso_12 IS NOT INITIAL.
  CLEARls_wdso,ls_wdso1.
  LOOP AT lt_wdso_11 INTO ls_wdso1.
  READ TABLE lt_wdso_12 WITH KEY  /BIC/ZCUST =
  ls_wdso1-/BIC/ZCUST
  /BIC/ZREG ls_wdso1-/BIC/ZREG
  /BIC/ZMAT ls_wdso1-/BIC/ZMAT
  /BI0/0CALMONTHls_wdso1-/BIC/0CALMONTH
  /BIC/ZACCNT ls_wdso1-/BIC/ZACCNT
  /BIC/ZAMNT ls_wdso1-/BIC/ZAMNT
   TRANSPORTING NO FIELDS.
  IF SY-SUBRC 0.
  APPEND ls_wdso1 TO lt_wdso_11a.
  ELSE.
  APPEND ls_wdso1 TO lt_wdso_11b.
  ENDIF.
  ENDLOOP.
ENDIF.
ENDIF.
CLEARls_zperiod.
REFRESHlt_wdso_01C,lt_wdso_02C,lt_wdso_03C,lt_wdso_04C,lt_wdso_05C,
lt_wdso_06C,lt_wdso_07C,lt_wdso_08C,lt_wdso_09C,lt_wdso_10C,lt_wdso_11C
.
lt_wdso_01C[] lt_wdso_01b[].
lt_wdso_02C[] lt_wdso_02b[].
lt_wdso_03C[] lt_wdso_03b[].
lt_wdso_04C[] lt_wdso_04b[].
lt_wdso_05C[] lt_wdso_05b[].
lt_wdso_06C[] lt_wdso_06b[].
lt_wdso_07C[] lt_wdso_07b[].
lt_wdso_08C[] lt_wdso_08b[].
lt_wdso_09C[] lt_wdso_09b[].
lt_wdso_10C[] lt_wdso_10b[].
lt_wdso_11C[] lt_wdso_11b[].
LOOP AT lt_zperiod1 INTO ls_zperiod.
  lsr_zperiod-SIGN 'I'.
  lsr_zperiod-OPTION 'EQ'.
  lsr_zperiod-LOW ls_zperiod-zcalmonth.
  APPEND lsr_zperiod TO lr_zperiod.
ENDLOOP.
DELETE lt_wdso_01C WHERE /BI0/0CALMONTH NOT IN lr_zperiod.
DELETE lt_wdso_02c WHERE /BI0/0CALMONTH  NOT IN lr_zperiod.
DELETE lt_wdso_03c WHERE /BI0/0CALMONTH  NOT IN lr_zperiod.
DELETE lt_wdso_04c WHERE /BI0/0CALMONTH  NOT IN lr_zperiod.
DELETE lt_wdso_05c WHERE /BI0/0CALMONTH  NOT IN lr_zperiod.
DELETE lt_wdso_06c WHERE /BI0/0CALMONTH  NOT IN lr_zperiod.
DELETE lt_wdso_07c WHERE /BI0/0CALMONTH  NOT IN lr_zperiod.
DELETE lt_wdso_08c WHERE /BI0/0CALMONTH  NOT IN lr_zperiod.
DELETE lt_wdso_09c WHERE /BI0/0CALMONTH  NOT IN lr_zperiod.
DELETE lt_wdso_10c WHERE /BI0/0CALMONTH  NOT IN lr_zperiod.
DELETE lt_wdso_11c WHERE /BI0/0CALMONTH  NOT IN lr_zperiod.
**********End of Start Routine*************

In the end routine of the transformation of the Standard DSO, write the below ABAP code:

End Routine:

 DATAlt_result_package TYPE TABLE OF _ty_s_TG_1.
DATAlt_new_result_package TYPE TABLE OF _ty_s_TG_1.
DATAlt_pre_result_package TYPE TABLE OF _ty_s_TG_1.
DATAls_pre_result_package TYPE _ty_s_TG_1.
DATAls_result_package TYPE _ty_s_TG_1.
DATARECORD TYPE RSARECORD.
DATAzcurperiod TYPE LENGTH 32.
DATAzcurmonth TYPE LENGTH 2.
DATAzcuryear TYPE LENGTH 5.
CLEAR ls_result_package.
REFRESHlt_result_package.
lt_result_package[] RESULT_PACKAGE[].
CLEAR:zmonth,zyear,zcalmonth.
LOOP AT lt_result_package INTO ls_result_package.
CLEAR ls_result_package-/BIC/ZAMNT_MTD.
zmonth ls_result_package-/BI0/0CALMONTH+5(2).
zyear ls_result_package-/BI0/0CALMONTH+0(4).
IF zmonth gt AND zmonth le 12 ).
zmonth zmonth 1.
IF zmonth < 10.
CONCATENATE '0' zmonth INTO zmonth.
CONCATENATE zyear '.' zmonth INTO zcalmonth.
ELSE.
CONCATENATE zyear '.' zmonth INTO zcalmonth.
ENDIF.
CLEARls_wdso.
 *//If the combination is available in previous month then do the
 *difference
 *//If the period is 01, then update the YTD value as MTD value for that
 *month.
   IF zmonth '01'.
    READ TABLE lt_wdso_03a INTO ls_wdso WITH KEY /BIC/ZCUST =
   ls_result_package-/BIC/ZCUST
  /BIC/ZREG ls_result_package-/BIC/ZREG
  /BIC/ZMAT ls_result_package-/BIC/ZMAT
  /BI0/0CALMONTH ls_result_package-/BI0/0CALMONTH
  /BIC/ZACCNT ls_result_package-/BIC/ZACCNT
  /BIC/ZAMNT ls_result_package-/BIC/ZAMNT
  TRANSPORTING /BIC/ZAMNT.
  IF SY-SUBRC 0.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT -
  ls_wdso-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ELSE.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ENDIF.
  ENDIF.
   IF zmonth '02'.
  READ TABLE lt_wdso_03a INTO ls_wdso WITH KEY /BIC/ZCUST =
   ls_result_package-/BIC/ZCUST
  /BIC/ZREG ls_result_package-/BIC/ZREG
  /BIC/ZMAT ls_result_package-/BIC/ZMAT
  /BI0/0CALMONTH ls_result_package-/BI0/0CALMONTH
  /BIC/ZACCNT ls_result_package-/BIC/ZACCNT
  /BIC/ZAMNT ls_result_package-/BIC/ZAMNT
  TRANSPORTING /BIC/ZAMNT.
  IF SY-SUBRC 0.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT -
  ls_wdso-/BIC/ZAMNT.
  ls_result_package-record RECORD.
  APPEND ls_result_package TO lt_new_result_package.
  ELSE.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT.
  ls_result_package-record RECORD.
  APPEND ls_result_package TO lt_new_result_package.
  ENDIF.
  ENDIF.
   IF zmonth '03'.
  READ TABLE lt_wdso_03a INTO ls_wdso WITH KEY /BIC/ZCUST =
   ls_result_package-/BIC/ZCUST
  /BIC/ZREG ls_result_package-/BIC/ZREG
  /BIC/ZMAT ls_result_package-/BIC/ZMAT
  /BI0/0CALMONTH ls_result_package-/BI0/0CALMONTH
  /BIC/ZACCNT ls_result_package-/BIC/ZACCNT
  /BIC/ZAMNT ls_result_package-/BIC/ZAMNT
  TRANSPORTING /BIC/ZAMNT.
  IF SY-SUBRC 0.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT -
  ls_wdso-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ELSE.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ENDIF.
  ENDIF.
   IF zmonth '04'.
     READ TABLE lt_wdso_03a INTO ls_wdso WITH KEY /BIC/ZCUST =
   ls_result_package-/BIC/ZCUST
  /BIC/ZREG ls_result_package-/BIC/ZREG
  /BIC/ZMAT ls_result_package-/BIC/ZMAT
  /BI0/0CALMONTH ls_result_package-/BI0/0CALMONTH
  /BIC/ZACCNT ls_result_package-/BIC/ZACCNT
  /BIC/ZAMNT ls_result_package-/BIC/ZAMNT
  TRANSPORTING /BIC/ZAMNT.
  IF SY-SUBRC 0.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT -
  ls_wdso-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ELSE.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ENDIF.
  ENDIF.
   IF zmonth '05'.
  READ TABLE lt_wdso_03a INTO ls_wdso WITH KEY /BIC/ZCUST =
   ls_result_package-/BIC/ZCUST
  /BIC/ZREG ls_result_package-/BIC/ZREG
  /BIC/ZMAT ls_result_package-/BIC/ZMAT
  /BI0/0CALMONTH ls_result_package-/BI0/0CALMONTH
  /BIC/ZACCNT ls_result_package-/BIC/ZACCNT
  /BIC/ZAMNT ls_result_package-/BIC/ZAMNT
 TRANSPORTING /BIC/ZAMNT.
  IF SY-SUBRC 0.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT -
  ls_wdso-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ELSE.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ENDIF.
  ENDIF.
   IF zmonth '06'.
  READ TABLE lt_wdso_03a INTO ls_wdso WITH KEY /BIC/ZCUST =
   ls_result_package-/BIC/ZCUST
  /BIC/ZREG ls_result_package-/BIC/ZREG
  /BIC/ZMAT ls_result_package-/BIC/ZMAT
  /BI0/0CALMONTH ls_result_package-/BI0/0CALMONTH
  /BIC/ZACCNT ls_result_package-/BIC/ZACCNT
  /BIC/ZAMNT ls_result_package-/BIC/ZAMNT
  TRANSPORTING /BIC/ZAMNT.
  IF SY-SUBRC 0.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT -
  ls_wdso-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ELSE.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ENDIF.
  ENDIF.
   IF zmonth '07'.
   READ TABLE lt_wdso_03a INTO ls_wdso WITH KEY /BIC/ZCUST =
   ls_result_package-/BIC/ZCUST
  /BIC/ZREG ls_result_package-/BIC/ZREG
  /BIC/ZMAT ls_result_package-/BIC/ZMAT
  /BI0/0CALMONTH ls_result_package-/BI0/0CALMONTH
  /BIC/ZACCNT ls_result_package-/BIC/ZACCNT
  /BIC/ZAMNT ls_result_package-/BIC/ZAMNT
  TRANSPORTING /BIC/ZAMNT.
  IF SY-SUBRC 0.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT -
  ls_wdso-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ELSE.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ENDIF.
  ENDIF.
   IF zmonth '08'.
   READ TABLE lt_wdso_03a INTO ls_wdso WITH KEY /BIC/ZCUST =
   ls_result_package-/BIC/ZCUST
  /BIC/ZREG ls_result_package-/BIC/ZREG
  /BIC/ZMAT ls_result_package-/BIC/ZMAT
  /BI0/0CALMONTH ls_result_package-/BI0/0CALMONTH
  /BIC/ZACCNT ls_result_package-/BIC/ZACCNT
  /BIC/ZAMNT ls_result_package-/BIC/ZAMNT
  TRANSPORTING /BIC/ZAMNT.
  IF SY-SUBRC 0.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT -
  ls_wdso-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ELSE.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ENDIF.
  ENDIF.
   IF zmonth '09'.
   READ TABLE lt_wdso_03a INTO ls_wdso WITH KEY /BIC/ZCUST =
   ls_result_package-/BIC/ZCUST
  /BIC/ZREG ls_result_package-/BIC/ZREG
  /BIC/ZMAT ls_result_package-/BIC/ZMAT
  /BI0/0CALMONTH ls_result_package-/BI0/0CALMONTH
  /BIC/ZACCNT ls_result_package-/BIC/ZACCNT
  /BIC/ZAMNT ls_result_package-/BIC/ZAMNT
  TRANSPORTING /BIC/ZAMNT.
  IF SY-SUBRC 0.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT -
  ls_wdso-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ELSE.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ENDIF.
  ENDIF.
   IF zmonth '10'.
   READ TABLE lt_wdso_03a INTO ls_wdso WITH KEY /BIC/ZCUST =
   ls_result_package-/BIC/ZCUST
  /BIC/ZREG ls_result_package-/BIC/ZREG
  /BIC/ZMAT ls_result_package-/BIC/ZMAT
  /BI0/0CALMONTH ls_result_package-/BI0/0CALMONTH
  /BIC/ZACCNT ls_result_package-/BIC/ZACCNT
  /BIC/ZAMNT ls_result_package-/BIC/ZAMNT
  TRANSPORTING /BIC/ZAMNT.
  IF SY-SUBRC 0.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT -
  ls_wdso-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ELSE.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ENDIF.
  ENDIF.
   IF zmonth '11'.
   READ TABLE lt_wdso_03a INTO ls_wdso WITH KEY /BIC/ZCUST =
   ls_result_package-/BIC/ZCUST
  /BIC/ZREG ls_result_package-/BIC/ZREG
  /BIC/ZMAT ls_result_package-/BIC/ZMAT
  /BI0/0CALMONTH ls_result_package-/BI0/0CALMONTH
  /BIC/ZACCNT ls_result_package-/BIC/ZACCNT
  /BIC/ZAMNT ls_result_package-/BIC/ZAMNT
  TRANSPORTING /BIC/ZAMNT.
  IF SY-SUBRC 0.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT -
  ls_wdso-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
  ELSE.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT.
  ls_result_package-record RECORD.
  APPEND ls_result_package TO lt_new_result_package.
  ENDIF.
  ENDIF.
ELSE.
  ls_result_package-/BIC/ZAMNT_MTD ls_result_package-/BIC/ZAMNT.
  APPEND ls_result_package TO lt_new_result_package.
ENDIF.
CLEARls_wdso.
ENDLOOP.
IF zstatus1 IS INITIAL.
IF lt_wdso_01a IS NOT INITIAL.
IF lt_wdso_01C IS NOT INITIAL.
CLEARls_wdsoc.
LOOP AT lt_wdso_01C INTO ls_wdsoc.
zcuryear ls_wdsoc-/BI0/0CALMONTH+0(5).
zcurmonth '02'.
CONCATENATE zcuryear zcurmonth INTO zcurperiod.
ls_pre_result_package-/BIC/ZCUST  ls_wdsoc-/BIC/ZCUST.
ls_pre_result_package-/BIC/ZREG ls_wdsoc-/BIC/ZREG.
ls_pre_result_package-/BIC/ZMAT ls_wdsoc-/BIC/ZMAT.
ls_pre_result_package-/BI0/0CALMONTH ls_wdsoc-/BI0/0CALMONTH.
ls_pre_result_package-/BIC/ZACCNT ls_wdsoc-/BIC/ZACCNT.
ls_pre_result_package-/BI0/0CALMONTH zcurperiod.
ls_pre_result_package-/BIC/ZAMNT 0.
ls_pre_result_package-/BIC/ZAMNT_MTD ls_wdsoc-/BIC/ZAMNT * -1.
APPEND ls_pre_result_package TO lt_pre_result_package.
ENDLOOP.
CLEAR zstatus1.
zstatus1 'X'.
ENDIF.
ENDIF.
ENDIF.
IF zstatus2 IS INITIAL.
IF lt_wdso_02a IS NOT INITIAL.
IF lt_wdso_02C IS NOT INITIAL.
CLEARls_wdsoc.
LOOP AT lt_wdso_02C INTO ls_wdsoc.
zcuryear ls_wdsoc-/BI0/0CALMONTH+0(5).
zcurmonth '03'.
CONCATENATE zcuryear zcurmonth INTO zcurperiod.
ls_pre_result_package-/BIC/ZCUST  ls_wdsoc-/BIC/ZCUST.
ls_pre_result_package-/BIC/ZREG ls_wdsoc-/BIC/ZREG.
ls_pre_result_package-/BIC/ZMAT ls_wdsoc-/BIC/ZMAT.
ls_pre_result_package-/BI0/0CALMONTH ls_wdsoc-/BI0/0CALMONTH.
ls_pre_result_package-/BIC/ZACCNT ls_wdsoc-/BIC/ZACCNT.
ls_pre_result_package-/BI0/0CALMONTH zcurperiod.
ls_pre_result_package-/BIC/ZAMNT 0.
ls_pre_result_package-/BIC/ZAMNT_MTD ls_wdsoc-/BIC/ZAMNT * -1.
APPEND ls_pre_result_package TO lt_pre_result_package.
ENDLOOP.
CLEAR zstatus2.
zstatus2 'X'.
ENDIF.
ENDIF.
ENDIF.
IF zstatus3 IS INITIAL.
IF lt_wdso_03a IS NOT INITIAL.
IF lt_wdso_03C IS NOT INITIAL.
CLEARls_wdsoc.
LOOP AT lt_wdso_03C INTO ls_wdsoc.
zcuryear ls_wdsoc-/BI0/0CALMONTH+0(5).
zcurmonth '04'.
CONCATENATE zcuryear zcurmonth INTO zcurperiod.
ls_pre_result_package-/BIC/ZCUST  ls_wdsoc-/BIC/ZCUST.
ls_pre_result_package-/BIC/ZREG ls_wdsoc-/BIC/ZREG.
ls_pre_result_package-/BIC/ZMAT ls_wdsoc-/BIC/ZMAT.
ls_pre_result_package-/BI0/0CALMONTH ls_wdsoc-/BI0/0CALMONTH.
ls_pre_result_package-/BIC/ZACCNT ls_wdsoc-/BIC/ZACCNT.
ls_pre_result_package-/BI0/0CALMONTH zcurperiod.
ls_pre_result_package-/BIC/ZAMNT 0.
ls_pre_result_package-/BIC/ZAMNT_MTD ls_wdsoc-/BIC/ZAMNT * -1.
APPEND ls_pre_result_package TO lt_pre_result_package.
ENDLOOP.
CLEAR zstatus3.
zstatus3 'X'.
ENDIF.
ENDIF.
ENDIF.
IF zstatus4 IS INITIAL.
IF lt_wdso_04a IS NOT INITIAL.
IF lt_wdso_04C IS NOT INITIAL.
CLEARls_wdsoc.
LOOP AT lt_wdso_04C INTO ls_wdsoc.
zcuryear ls_wdsoc-/BI0/0CALMONTH+0(5).
zcurmonth '05'.
CONCATENATE zcuryear zcurmonth INTO zcurperiod.
ls_pre_result_package-/BIC/ZCUST  ls_wdsoc-/BIC/ZCUST.
ls_pre_result_package-/BIC/ZREG ls_wdsoc-/BIC/ZREG.
ls_pre_result_package-/BIC/ZMAT ls_wdsoc-/BIC/ZMAT.
ls_pre_result_package-/BI0/0CALMONTH ls_wdsoc-/BI0/0CALMONTH.
ls_pre_result_package-/BIC/ZACCNT ls_wdsoc-/BIC/ZACCNT.
ls_pre_result_package-/BI0/0CALMONTH zcurperiod.
ls_pre_result_package-/BIC/ZAMNT 0.
ls_pre_result_package-/BIC/ZAMNT_MTD ls_wdsoc-/BIC/ZAMNT * -1.
APPEND ls_pre_result_package TO lt_pre_result_package.
ENDLOOP.
CLEAR zstatus4.
zstatus4 'X'.
ENDIF.
ENDIF.
ENDIF.
IF zstatus5 IS INITIAL.
IF lt_wdso_05a IS NOT INITIAL.
IF lt_wdso_05C IS NOT INITIAL.
CLEARls_wdsoc.
LOOP AT lt_wdso_05C INTO ls_wdsoc.
zcuryear ls_wdsoc-/BI0/0CALMONTH+0(5).
zcurmonth '06'.
CONCATENATE zcuryear zcurmonth INTO zcurperiod.
ls_pre_result_package-/BIC/ZCUST  ls_wdsoc-/BIC/ZCUST.
ls_pre_result_package-/BIC/ZREG ls_wdsoc-/BIC/ZREG.
ls_pre_result_package-/BIC/ZMAT ls_wdsoc-/BIC/ZMAT.
ls_pre_result_package-/BI0/0CALMONTH ls_wdsoc-/BI0/0CALMONTH.
ls_pre_result_package-/BIC/ZACCNT ls_wdsoc-/BIC/ZACCNT.
ls_pre_result_package-/BI0/0CALMONTH zcurperiod.
ls_pre_result_package-/BIC/ZAMNT 0.
ls_pre_result_package-/BIC/ZAMNT_MTD ls_wdsoc-/BIC/ZAMNT * -1.
APPEND ls_pre_result_package TO lt_pre_result_package.
ENDLOOP.
CLEAR zstatus5.
zstatus5 'X'.
ENDIF.
ENDIF.
ENDIF.
IF zstatus6 IS INITIAL.
IF lt_wdso_06a IS NOT INITIAL.
IF lt_wdso_06C IS NOT INITIAL.
CLEARls_wdsoc.
LOOP AT lt_wdso_06C INTO ls_wdsoc.
zcuryear ls_wdsoc-/BI0/0CALMONTH+0(5).
zcurmonth '07'.
CONCATENATE zcuryear zcurmonth INTO zcurperiod.
ls_pre_result_package-/BIC/ZCUST  ls_wdsoc-/BIC/ZCUST.
ls_pre_result_package-/BIC/ZREG ls_wdsoc-/BIC/ZREG.
ls_pre_result_package-/BIC/ZMAT ls_wdsoc-/BIC/ZMAT.
ls_pre_result_package-/BI0/0CALMONTH ls_wdsoc-/BI0/0CALMONTH.
ls_pre_result_package-/BIC/ZACCNT ls_wdsoc-/BIC/ZACCNT.
ls_pre_result_package-/BI0/0CALMONTH zcurperiod.
ls_pre_result_package-/BIC/ZAMNT 0.
ls_pre_result_package-/BIC/ZAMNT_MTD ls_wdsoc-/BIC/ZAMNT * -1.
APPEND ls_pre_result_package TO lt_pre_result_package.
ENDLOOP.
CLEAR zstatus6.
zstatus6 'X'.
ENDIF.
ENDIF.
ENDIF.
IF zstatus7 IS INITIAL.
IF lt_wdso_07a IS NOT INITIAL.
IF lt_wdso_07C IS NOT INITIAL.
CLEARls_wdsoc.
LOOP AT lt_wdso_07C INTO ls_wdsoc.
zcuryear ls_wdsoc-/BI0/0CALMONTH+0(5).
zcurmonth '08'.
CONCATENATE zcuryear zcurmonth INTO zcurperiod.
 ls_pre_result_package-/BIC/ZCUST  ls_wdsoc-/BIC/ZCUST.
ls_pre_result_package-/BIC/ZREG ls_wdsoc-/BIC/ZREG.
ls_pre_result_package-/BIC/ZMAT ls_wdsoc-/BIC/ZMAT.
ls_pre_result_package-/BI0/0CALMONTH ls_wdsoc-/BI0/0CALMONTH.
ls_pre_result_package-/BIC/ZACCNT ls_wdsoc-/BIC/ZACCNT.
ls_pre_result_package-/BI0/0CALMONTH zcurperiod.
ls_pre_result_package-/BIC/ZAMNT 0.
ls_pre_result_package-/BIC/ZAMNT_MTD ls_wdsoc-/BIC/ZAMNT * -1.
APPEND ls_pre_result_package TO lt_pre_result_package.
ENDLOOP.
CLEAR zstatus7.
zstatus7 'X'.
ENDIF.
ENDIF.
ENDIF.
IF zstatus8 IS INITIAL.
IF lt_wdso_08a IS NOT INITIAL.
IF lt_wdso_08C IS NOT INITIAL.
CLEARls_wdsoc.
LOOP AT lt_wdso_08C INTO ls_wdsoc.
zcuryear ls_wdsoc-/BI0/0CALMONTH+0(5).
zcurmonth '09'.
CONCATENATE zcuryear zcurmonth INTO zcurperiod.
ls_pre_result_package-/BIC/ZCUST  ls_wdsoc-/BIC/ZCUST.
ls_pre_result_package-/BIC/ZREG ls_wdsoc-/BIC/ZREG.
ls_pre_result_package-/BIC/ZMAT ls_wdsoc-/BIC/ZMAT.
ls_pre_result_package-/BI0/0CALMONTH ls_wdsoc-/BI0/0CALMONTH.
ls_pre_result_package-/BIC/ZACCNT ls_wdsoc-/BIC/ZACCNT.
ls_pre_result_package-/BI0/0CALMONTH zcurperiod.
ls_pre_result_package-/BIC/ZAMNT 0.
ls_pre_result_package-/BIC/ZAMNT_MTD ls_wdsoc-/BIC/ZAMNT * -1.
APPEND ls_pre_result_package TO lt_pre_result_package.
ENDLOOP.
CLEAR zstatus8.
zstatus8 'X'.
ENDIF.
ENDIF.
ENDIF.
IF zstatus9 IS INITIAL.
IF lt_wdso_09a IS NOT INITIAL.
IF lt_wdso_09C IS NOT INITIAL.
CLEARls_wdsoc.
LOOP AT lt_wdso_09C INTO ls_wdsoc.
zcuryear ls_wdsoc-/BI0/0CALMONTH+0(5).
zcurmonth '10'.
CONCATENATE zcuryear zcurmonth INTO zcurperiod.
ls_pre_result_package-/BIC/ZCUST  ls_wdsoc-/BIC/ZCUST.
ls_pre_result_package-/BIC/ZREG ls_wdsoc-/BIC/ZREG.
ls_pre_result_package-/BIC/ZMAT ls_wdsoc-/BIC/ZMAT.
ls_pre_result_package-/BI0/0CALMONTH ls_wdsoc-/BI0/0CALMONTH.
ls_pre_result_package-/BIC/ZACCNT ls_wdsoc-/BIC/ZACCNT.
ls_pre_result_package-/BI0/0CALMONTH zcurperiod.
ls_pre_result_package-/BIC/ZAMNT 0.
ls_pre_result_package-/BIC/ZAMNT_MTD ls_wdsoc-/BIC/ZAMNT * -1.
APPEND ls_pre_result_package TO lt_pre_result_package.
ENDLOOP.
CLEAR zstatus9.
zstatus9 'X'.
ENDIF.
ENDIF.
ENDIF.
IF zstatus10 IS INITIAL.
IF lt_wdso_10a IS NOT INITIAL.
IF lt_wdso_10C IS NOT INITIAL.
CLEARls_wdsoc.
LOOP AT lt_wdso_10C INTO ls_wdsoc.
zcuryear ls_wdsoc-/BI0/0CALMONTH+0(5).
zcurmonth '11'.
CONCATENATE zcuryear zcurmonth INTO zcurperiod.
ls_pre_result_package-/BIC/ZCUST  ls_wdsoc-/BIC/ZCUST.
ls_pre_result_package-/BIC/ZREG ls_wdsoc-/BIC/ZREG.
ls_pre_result_package-/BIC/ZMAT ls_wdsoc-/BIC/ZMAT.
ls_pre_result_package-/BI0/0CALMONTH ls_wdsoc-/BI0/0CALMONTH.
ls_pre_result_package-/BIC/ZACCNT ls_wdsoc-/BIC/ZACCNT.
ls_pre_result_package-/BI0/0CALMONTH zcurperiod.
ls_pre_result_package-/BIC/ZAMNT 0.
ls_pre_result_package-/BIC/ZAMNT_MTD ls_wdsoc-/BIC/ZAMNT * -1.
APPEND ls_pre_result_package TO lt_pre_result_package.
ENDLOOP.
CLEAR zstatus10.
zstatus10 'X'.
ENDIF.
ENDIF.
ENDIF.
IF zstatus11 IS INITIAL.
IF lt_wdso_11a IS NOT INITIAL.
IF lt_wdso_11C IS NOT INITIAL.
CLEARls_wdsoc.
LOOP AT lt_wdso_11C INTO ls_wdsoc.
zcuryear ls_wdsoc-/BI0/0CALMONTH+0(5).
zcurmonth '12'.
ls_pre_result_package-/BIC/ZCUST  ls_wdsoc-/BIC/ZCUST.
ls_pre_result_package-/BIC/ZREG ls_wdsoc-/BIC/ZREG.
ls_pre_result_package-/BIC/ZMAT ls_wdsoc-/BIC/ZMAT.
ls_pre_result_package-/BI0/0CALMONTH ls_wdsoc-/BI0/0CALMONTH.
ls_pre_result_package-/BIC/ZACCNT ls_wdsoc-/BIC/ZACCNT.
ls_pre_result_package-/BI0/0CALMONTH zcurperiod.
ls_pre_result_package-/BIC/ZAMNT 0.
ls_pre_result_package-/BIC/ZAMNT_MTD ls_wdsoc-/BIC/ZAMNT * -1.
APPEND ls_pre_result_package TO lt_pre_result_package.
ENDLOOP.
CLEAR zstatus11.
zstatus11 'X'.
ENDIF.
ENDIF.
ENDIF.
CLEARls_result_package.
LOOP AT lt_pre_result_package INTO ls_result_package.
APPEND ls_result_package TO lt_new_result_package.
ENDLOOP.
CLEARls_result_package.
REFRESHRESULT_PACKAGE.
CLEARRECORD.
RECORD 0.
LOOP AT lt_new_result_package INTO ls_result_package.
RECORD RECORD + 1.
ls_result_package-record RECORD.
APPEND ls_result_package TO RESULT_PACKAGE.
ENDLOOP.

Save and activate the transformation. Load the data from ZWDSO to ZDSO.

Make sure you load all the months data to ZWDSO first.

The ABAP code may be performance intensive, hence it is recommended to load 2 months at a time to the standard DSO.

Please Note:

The logic will not work if you load in this fashion:

2017.01 to ZWDSO -> 2017.01 to ZDSO

2017.02 to ZWDSO -> 2017.02 to ZDSO

2017.03 to ZWDSO -> 2017.03 to ZDSO

Instead, you should load in following way:

2017.01, 2017.02, 2017.03 to ZWDSO

2017.01 to ZDSO

2017.02 to ZDSO

2017.03 to ZDSO

Activate the data in ZDSO.

 

Leave a Reply

Your email address will not be published.