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

joining three internal tables into one internal table.

Former Member
0 Likes
4,273

Hi,

How can I join 3 internal table into one internal tables?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,888

sort itab1 by <fields>.

sort itab2 by <fields>.

sort itab3 by <fields>.

Loop at itab1.

read table itab2 with key <field> = itab1-<field>.

if sy-subrc = 0.

move itab2 data it_final.

endif.

read table itab3 with key <field> = itab1-<field>.

if sy-subrc = 0.

move itab3 data it_final.

endif.

move itab1 data it_final.

Endloop.

Hi,

How can I join 3 internal table into one internal tables?

8 REPLIES 8
Read only

Former Member
0 Likes
1,888

If you want to join 3 internal tables then the nested loops is the only solution.

However constraint with the nested loop will be you should have the mapping primary key for the nested loops.

Regards,

Kunjal

Read only

Former Member
0 Likes
1,889

sort itab1 by <fields>.

sort itab2 by <fields>.

sort itab3 by <fields>.

Loop at itab1.

read table itab2 with key <field> = itab1-<field>.

if sy-subrc = 0.

move itab2 data it_final.

endif.

read table itab3 with key <field> = itab1-<field>.

if sy-subrc = 0.

move itab3 data it_final.

endif.

move itab1 data it_final.

Endloop.

Read only

Former Member
0 Likes
1,888

Check this-

SELECT v1~vbeln AS vbeln

v2~posnr AS posnr

v2~matnr AS matnr

v2~werks AS werks

v2~meins AS meins

v2~lgort AS lgort

v2~kwmeng AS kwmeng

v3~lfsta AS lfsta

INTO TABLE t_items

FROM vbak AS v1

INNER JOIN vbap AS v2

ON v1vbeln = v2vbeln

INNER JOIN vbup AS v3

ON v2vbeln = v3vbeln

AND v2posnr = v3posnr

WHERE v1~vbeln IN s_vbeln

AND v1~auart IN r_auart "Sales order type should be 'ZOR'

AND v1~lifsk = ' ' "No delivery block

AND v1~vkorg IN s_vkorg "Sales organization

AND v1~vdatu IN s_vdatu "Requested delivery date

AND v2~abgru = ' ' "No reason of rejection

AND v2~lgort = c_lgort "Storage location = 1000

AND v2~vstel IN s_vstel "Shipping point

AND v3~lfsta <> 'C'. "Itme should be delivered

Regards,

Aparna Gaikwad

Read only

Former Member
0 Likes
1,888

Let us assume that u have three table as

it_table1,

it_table2,

it_table3 as three tables

and

wa_table1,

wa_table2,

wa_table3 as work areas

and you have to pass these three table data to it_final table which has wa_final as work area.

IMPORTANT THING IS ALL THE THREE HAVE SAME STRUCTURES.

CLEAR WA_TABLE1.

LOOP AT IT_TABLE1 INTO WA_TABLE1.

APPEND WA_TABLE1 TO IT_FINAL.

CLEAR WA_TABLE1.

ENDLOOP.

CLEAR WA_TABLE2.

LOOP AT IT_TABLE2 INTO WA_TABLE2.

APPEND WA_TABLE2 TO IT_FINAL.

CLEAR WA_TABLE2.

ENDLOOP.

CLEAR WA_TABLE3.

LOOP AT IT_TABLE3 INTO WA_TABLE3.

APPEND WA_TABLE3 TO IT_FINAL.

CLEAR WA_TABLE3.

ENDLOOP.

IF THREE TABLE STRUCTURE ARE DIFFERENT AND THEN U HAVE TO LOOK FOR COMMON FIELDS IN THREE INTERNAL TABLES

Read only

Former Member
0 Likes
1,888

Let us assume that u have three table as

it_table1,

it_table2,

it_table3 as three tables

and

wa_table1,

wa_table2,

wa_table3 as work areas

and you have to pass these three table data to it_final table which has wa_final as work area.

IMPORTANT THING IS ALL THE THREE HAVE SAME STRUCTURES.

CLEAR WA_TABLE1.

LOOP AT IT_TABLE1 INTO WA_TABLE1.

APPEND WA_TABLE1 TO IT_FINAL.

CLEAR WA_TABLE1.

ENDLOOP.

CLEAR WA_TABLE2.

LOOP AT IT_TABLE2 INTO WA_TABLE2.

APPEND WA_TABLE2 TO IT_FINAL.

CLEAR WA_TABLE2.

ENDLOOP.

CLEAR WA_TABLE3.

LOOP AT IT_TABLE3 INTO WA_TABLE3.

APPEND WA_TABLE3 TO IT_FINAL.

CLEAR WA_TABLE3.

ENDLOOP.

IF THREE TABLE STRUCTURE ARE DIFFERENT AND THEN U HAVE TO LOOK FOR COMMON FIELDS IN THREE INTERNAL TABLES

Read only

Former Member
0 Likes
1,888

This message was moderated.

Read only

0 Likes
1,888

Hi Nilesh,

Read will only be possible if you are sure that the tables you are reading contains only 1 record otherwise you will not get the complete data...

In case of multiple entries LOOP is the best possible option available.

Regards,

Kunjal

Read only

0 Likes
1,888

>

> Hi friend,

> Rather joining the internal table through the loops which may affect the performance, wat u can do is use read statement with for all entries,

> read itab1 into wa_itab for all entries in itab2 where <cond>

Wrong syntex with read.