cancel
Showing results for 
Search instead for 
Did you mean: 

Transform one record from source to many records in BW routine

ikirilova1
Participant
0 Kudos

Hi gurus,

I have the following problem:

I have Material prices DSO, loading all price conditions for a material from A* tables in the ERP system. I need to use these prices as key figures in a query. In the same query I have 0PLANT. The problem is that in the source system our company manages most of standard prices only on sales organization level and there isn't direct connection to plant. Only for promotions we have material-plant prices. In the datasource there is a field for condition type on which I can easily say whether it is for promotion or not.

My idea is to create X number of records for conditions PB00 and VKP0 (X = the number of plants) and to change plant value in each of them. I imagine the following steps should be done in a loop:

1. Copy source data record

2. Change the plant in the copied record

3. Change internal ID if needed

I guess this could be done with start and/or end routines, but they are new to me and I will be very happy if someone could help me with the code or post helpful links about it.

Best regards,

Ivelina

Accepted Solutions (0)

Answers (1)

Answers (1)

Abhishek_Hazra
Active Contributor
0 Kudos

Hello ikirilova ,

I assume the table/provider you have shared the screenshot from does have 0SALESORG as well as you've mentioned that the prices are maintained on material/salesorg level. In that case, you can do the following in your start/end routine :

1. Make a local table with all fields except PLANT from source/result package where condition type = PB00 or VKP0.

2. Populate another local table combining this local table & 0PLANT masterdata table(/BI0/PPLANT) with based on Salesorg (0PLANT master data also has 0SALESORG as attribute). This new local table should have PLANT field populated from /BI0/PPLANT. (Here you get those x number of rows where x = number of plants per salesorg).

3. Append the lines from new local table to source/result package.

4. Delete the rows from source/result package where where condition type = PB00 or VKP0 and 0PLANT is initial.

Note: It is easier if you can use HANA transformations & are capable to use AMDP. 🙂

Best Regards,
Abhi

ikirilova1
Participant
0 Kudos

Thank you for the explanation, Abhishek!

The problem is I don't know how to do it in ABAP.

Abhishek_Hazra
Active Contributor
0 Kudos

Hi ikirilova,
Okay, below is a draft code for your solution, you can modify it based on your need further 🙂

TYPES : BEGIN OF ls_so,
       MATERIAL type /BI0/OIMATERIAL,
       SALESORG type /BI0/OISALESORG,
       KNART type /BI0/OIKNART,
       AMOUNT type /BI0/OIAMOUNT,
       CURRENCY type /BI0/OICURRENCY.
TYPES : END OF ls_so.
DATA : lt_so TYPE STANDARD TABLE OF ls_so.
DATA : lv_index TYPE i.
DATA : lt_src LIKE SOURCE_PACKAGE.
DATA : wa_src LIKE LINE OF lt_src.
DATA : lt_res LIKE SOURCE_PACKAGE.

TYPES : BEGIN OF ls_sp,
       SALESORG type /BI0/OISALESORG,
       PLANT type /BI0/OIPLANT.
TYPES : END OF ls_sp.
DATA : lt_sp TYPE STANDARD TABLE OF ls_sp.

LOOP AT SOURCE_PACKAGE ASSIGNING <SOURCE_FIELDS>.
IF <SOURCE_FIELDS>-KNART = 'VKP0' OR <SOURCE_FIELDS>-KNART = 'PB00'.

INSERT VALUE #(
MATERIAL = <SOURCE_FIELDS>-MATERIAL
SALESORG = <SOURCE_FIELDS>-SALESORG
KNART = <SOURCE_FIELDS>-KNART
AMOUNT = <SOURCE_FIELDS>-KNVAL
CURRENCY = <SOURCE_FIELDS>-DOC_CURRCY  )
INTO TABLE LT_SO.

ENDIF.
ENDLOOP.

IF LINES( SOURCE_PACKAGE ) > 0.
SELECT SALESORG PLANT
INTO TABLE LT_SP
FROM /BI0/PPLANT FOR ALL ENTRIES IN SOURCE_PACKAGE
WHERE SALESORG = SOURCE_PACKAGE-SALESORG AND OBJVERS = 'A'.
ENDIF.

MOVE-CORRESPONDING SOURCE_PACKAGE to LT_SRC.
DELETE LT_SRC WHERE KNART NE 'VKP0' AND KNART NE 'PB00'.

SORT LT_SP BY SALESORG.
SORT LT_SRC BY SALESORG.

LOOP AT LT_SP ASSIGNING FIELD-SYMBOL(<FS_SP>).

READ TABLE LT_SRC TRANSPORTING NO FIELDS WITH KEY SALESORG = <FS_SP>-SALESORG BINARY SEARCH.

IF SY-SUBRC = 0.
   LV_INDEX = SY-TABIX.

   LOOP AT LT_SRC INTO WA_SRC FROM LV_INDEX.
     IF WA_SRC-SALESORG NE <FS_SP>-SALESORG.
      EXIT.
     ENDIF.
     WA_SRC-PLANT = <FS_SP>-PLANT.
     INSERT WA_SRC INTO LT_RES INDEX 1.
   ENDLOOP.
ENDIF.

ENDLOOP.

APPEND LINES OF LT_RES TO SOURCE_PACKAGE.
DELETE SOURCE_PACKAGE WHERE PLANT = '' AND ( KNART = 'VKP0' OR KNART = 'PB00' ).


Best Regards,
Abhi