Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

internaltable logic

Former Member
0 Likes
682

HI,

First internal table contains data like matnr, werks.

matnr werks

Ex: 1 cp01

second internal table contains data like vbeln ,matnr, open quantity.

vbeln matnr openquantity

1 1 20

2 1 30

4 1 50

third internal table contains data like matnr ,labst and insme from marc.

matnr labst insme

1 20 30

1 10 40

i need output in final internal table like

matnr werks openquantity labst insme

1 cp01 100 30 70

Please provide me best solution.

Thanks in advance,

Suresh.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
661

Hi,

Please use the below logic.

Loop at itab3 into Wa_itab3.

read table itab1 into wa_itab1 with key matnr = wa_itab3-matnr.

read table itab2 into wa_itab2 with key matnr = wa_itab3-matnr.

Write : wa_itab1-matnr,wa_itab1-werks,wa_itab2-openquantity,wa_itab3-labst,wa_itab1-insme.

endloop.

Regards,

Shan

5 REPLIES 5
Read only

Former Member
0 Likes
661

use all entries or inner join concept...

Read only

Former Member
0 Likes
661

Hi

create a final internal table with all the fields.

Fetch the records from first table

fetch the records froms econd table

fetch the records from third table

loop the first table

read second table with key as matnr

read third table with key as matnr

move all the entries to final table

end loop.

Read only

Former Member
0 Likes
662

Hi,

Please use the below logic.

Loop at itab3 into Wa_itab3.

read table itab1 into wa_itab1 with key matnr = wa_itab3-matnr.

read table itab2 into wa_itab2 with key matnr = wa_itab3-matnr.

Write : wa_itab1-matnr,wa_itab1-werks,wa_itab2-openquantity,wa_itab3-labst,wa_itab1-insme.

endloop.

Regards,

Shan

Read only

0 Likes
661

Hi,

You can use the below logic.

Count the number of records for all the 3 internals tables. Whichever is having maximum number of records, loop at that internal table and read the other two tables with key as matnr.

As per your example 2nd internal table has more number of records. So

Loop at ITAB2 into WA_TAB2.

Move corresponding values of WA_TAB2 to Final workarea (WA_FINAL).

Read table ITAB1 into WA_TAB1 with key matnr = WA_TAB2-matnr.

If sy-subrc = 0.

Move corresponding values of WA_TAB1 to Final workarea (WA_FINAL).

Endif.

Read table ITAB3 into WA_TAB3 with key matnr = WA_TAB2-matnr.

If sy-subrc = 0.

Move corresponding values of WA_TAB3 to Final workarea (WA_FINAL).

Endif.

Append WA_FINAL to IT_FINAL.

Endloop.

Edited by: Ravi Kiran P on Nov 12, 2008 1:39 PM

Read only

prasanth_kasturi
Active Contributor
0 Likes
661

hi,

try the following way.

sort the three internal tables by matnr.

as there may be multiple records loop is better to use



  loop at itab1.
    
    loop at itab2 where matnr = itab1-matnr.
      
      loop at itab3 where matnr = itab2-matnr.

      final-matnr = itab3-matnr.
      final-werks = itab1-werks.
      final-openqty = itab2-openqty.
      final-labst    = itab3-labst .
      final-insme = itab3-insme.
      collect final.                  " USE COLLECT STATEMNT

      endloop.
            
    endloop.
        
  endloop.

regards

Prasanth