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

Merging three internal tables

Former Member
0 Likes
1,525

Hi

i am havin records in three internal tables ..can any one gimme sme way to merge these three internal tables in to a single internal table

Arun

Hi

i am havin records in three internal tables ..can any one gimme sme way to merge these three internal tables in to a single internal table

Arun

5 REPLIES 5
Read only

Former Member
0 Likes
974

say 3 tables are Table1-Matnr, Table2-Belnr and Table3-Vblen

Now create a single table say itab_final with all 3 fields

like:

Types: begin of gs_table_final,

matnr type mara-matnr,

belnr type belnr,

vblen type vblen,

end of gs_table_final.

Data: itab_final type table of gs_table_final,

wa_final like line of gs_table_final.

Now logic will be:

loop will be on that table on which you are getting to set filter on all tables say table1.

loop at table1 into wa-table1.

wa_final-matnr = wa_table1-matnr.

read table2 into wa_table2.

wa_final-belnr = wa_table2-belnr.

read table3 into wa_table3.

wa_final-vblen = wa_table3-vblen.

append wa_final into itab_final.

clear wa_final.

endloop.

Please reward if its useful.

BR,

Alok

Read only

Former Member
0 Likes
974

hi,

suppose u have 3 tables: it_kna1, it_vbak, it_vbap.

data: begin of itab occurs 0,

kunnr like it_kna1-kunnr,

name1 like it_kna1-name1,

vbeln like it_vbak-vbeln,

erdat like it_vbak-erdat,

posnr like it_vbap-posnr,

end of itab.

then use inner join or for all entries to select the from 3 tables and store it in itab.

thanks,

raji.

Read only

ramoruamodisha
Explorer
0 Likes
974

Hi,

1. You first need to create a structure (4th Internal Table) containing all the fields from all the three internal tables that you need to display.

2. Loop at the first internal table and MOVE-CORRESPONDING FIELDS into the structure you created, i.e Fourth Internal table.

3. Loop at the second internal table and MOVE-CORRESPONDING FIELDS into the structure you created, i.e Fourth Internal table.

4. Loop at the third internal table and MOVE-CORRESPONDING FIELDS into the structure you created, i.e Fourth Internal table.

Then debug it, it should have all the data into the corresponding fieds of the 4th internal table - structure.

Try it out, rewards if it helped.

Ramorua

Read only

Former Member
0 Likes
974

Hi,

Check out this sample code :

Syntax for TWO TABLES JOIN:

select vbeln "sales order no

erdat "date

posnr "sales order item

netwt "net value

from vbak as a

inner join vbap as b on avbeln = bvbeln

into table itab

where vbeln in s_vbeln.

Conditions:

1.There must be one field common in both table(JUST LIKE VBELN in the above example)

2.If u using select-options u use IN operator in WHERE clause

Here itab means internal table.

syntax for Joining 3 tables

select vbeln

erdat

posnr

rfsta

from vbak as a

inner join vbap as b on avbeln = bvbeln

inner join vbup as c on avbeln = cvbeln

where vbeln in s_vbeln.

Thanks

Nayan

Read only

Former Member
0 Likes
974

if all 3 tables have the same structure/format

Look into this


APPEND LINES OF itab1 [FROM idx1] [TO idx2] TO itab2.