cancel
Showing results for 
Search instead for 
Did you mean: 

End Routine in SAP BW

abhimanyu_sharma
Contributor
0 Kudos

hi experts,

i have filled internal table it_abc ( also created work area wa_abc of internal table it_abc) with records as:

opbel segment Amount
100   revenue 10
100   Vat     20

and in result_package , getting one records

opbel opupk amount revenue vat
100   1     100    ?       ?

In the result package i want to populate the value of revenue and vat.

Revenue and vat should be equal to

if wa_abc-segment = revenue
  <result_fields>-revenue = <result_fields>-amount * wa_abc-segment = 100 * 10
elseif wa_abc-segment = vat
  <result_fields>-vat= <result_fields>-amount * wa_abc-segment = 100 * 20

could you please provide your suggestion how to get the valye of revenue and vat in result_package?

matt
Active Contributor
0 Kudos

Please in future use the "code" button in the editor when typing code, or other information that needs formatting to make it readable. I've done it for you this time.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member586947
Contributor
0 Kudos
Hi Abhimanyu,

You have already stored the lookup data in it_abc. Create one more internal table as same as it_abc. For instance, I'm naming it as itab_vat.

Now follow the below steps.

After inserting the data in it_abc internal table with select statement, write the below code.

itab_vat[ ] = it_abc[ ].
Delete it_abc where segment NE 'revenue'. * It contains only Revenue information
Delete itab_vat where segment NE 'vat'. * It contains only vat information

SORT it_abc BY opbel.
SORT itab_vat BY opbel.
LOOP AT result_package ASSIGNING <RESULT_FIELDS>.
  Read table it_abc into wa_abc with key opbel = <result_fileds>-opbel
   BINARY SEARCH.
  IF sy-subrc EQ 0.
    <result_fields>-revenue = <result_fields>-amount * wa_abc-segment = 100 * 10.
  ENDIF.
  Read table itab_vat into wa_vat with key opbel = <result_fileds>-opbel
  BINARY SEARCH.
  IF sy-subrc EQ 0.
    <result_fields>-vat= <result_fields>-amount * wa_abc-segment = 100 * 20.
  ENDIF.
ENDLOOP.
matt
Active Contributor
0 Kudos

Please in future use the "code" button in the editor when typing code, or other information that needs formatting to make it readable. I've done it for you this time.

Concerning you answer. The internal tables it_vat and it_abc should be be sorted tables with non-unique key opbel and with a secondary non-unique key of segment.

data <table name> type sorted table of <type>
    with non-unique key opbel 
    with non-unique sorted key by_segment COMPONENTS segment.                                 

You should then use (e.g.)

DELETE TABLE it_vat WITH TABLE KEY by_segment COMPONENTS segment NE 'VAT'.

Read table <table name> into <work area> with TABLE KEY obpel = ....

This will make the processing more efficient. With standard tables, you will be scanning the internal table each time.

former_member586947
Contributor
0 Kudos

Hi Matthew,

Thanks for the information. Here, I have written only pseudo code to understand and address the current scenario. Hoping, Abhimanyu takes care of the code optimization..

Regards,

Satya.