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

combine 2 internal table into 1 .

Former Member
0 Likes
1,288

hey

i have a case where there are 2 internal tables and i want to put all this data into one internal table. i need to write the code for it.

internal table 1 : F1 F2 F3 F4

internal table 2: F1 F2 F5 F6 F7 F8 F9

internal table 3 should have F1 to F9 with a condition that internal table1-F1 = internal table 2-F1 and internal table 1 - F2 = internal table 2-F2.

Please help me with this.

thanks

Laura.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,255

Hi,

Please try this.


LOOP AT ITAB1.
   LOOP AT ITAB2 WHERE F1 = ITAB1-F1
                   AND F2 = ITAB1-F2.     
     MOVE-CORRESPONDING ITAB1 TO ITAB3.
     MOVE-CORRESPONDING ITAB2 TO ITAB3.
     APPEND ITAB3.
   ENDLOOP.
ENDLOOP.

Please check the syntax.

Regards,

Ferry Lianto

hey

i have a case where there are 2 internal tables and i want to put all this data into one internal table. i need to write the code for it.

internal table 1 : F1 F2 F3 F4

internal table 2: F1 F2 F5 F6 F7 F8 F9

internal table 3 should have F1 to F9 with a condition that internal table1-F1 = internal table 2-F1 and internal table 1 - F2 = internal table 2-F2.

Please help me with this.

thanks

Laura.

12 REPLIES 12
Read only

Former Member
0 Likes
1,256

Hi,

Please try this.


LOOP AT ITAB1.
   LOOP AT ITAB2 WHERE F1 = ITAB1-F1
                   AND F2 = ITAB1-F2.     
     MOVE-CORRESPONDING ITAB1 TO ITAB3.
     MOVE-CORRESPONDING ITAB2 TO ITAB3.
     APPEND ITAB3.
   ENDLOOP.
ENDLOOP.

Please check the syntax.

Regards,

Ferry Lianto

Read only

0 Likes
1,255

mistake

Read only

0 Likes
1,255

kindly refer my below post..

Read only

0 Likes
1,255

kindly refer my below post..

Read only

0 Likes
1,255

mistake

Read only

0 Likes
1,255

Sort itab1 by F1 F2.

sort itab2 by F1 F2.

Loop at itab1 into wa1.

read table itab2 into wa2 with key F1 = wa1-F1 F2 = wa1-F2 binary search.

if sy-subrc = 0.

move corresponding wa2 to wa_final.

wa_final-F3 = wa1-F3.

wa_final-F4 = wa1-F4.

append wa_final to itab3.

endif.

endloop.

Read only

0 Likes
1,255

thanks ferry

problem solved. i have assigned points to all helpful answers.

Laura.

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,255

HI,

use the following code.

LOOP AT ITAB1 into WA1.

LOOP AT ITAB2 INTO WA2 WHERE f1 = WA1-f1 f2 = wa1-f2.

MOVE-CORRESPONDING WA1 to WA3.

MOVE-CORRESPONDING WA2 to WA3.

APPEND WA3 to ITAB3.

ENDLOOP.

ENDLOOP.

Regards,

Sesh

Message was edited by:

Seshatalpasai Madala

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,255

Hi,

loop at itab1 into wa1.

move-corresponding wa1 to wa3.

loop at itab2 into wa2 where f1 = wa1-f1 and f2 = wa1-f2.

move-corresponding wa2 to wa3.

append wa3 to itab3.

endloop.

endloop.

Read only

Former Member
0 Likes
1,255

Hi,

loop at itab3.

read table itab1 with key f1 = itab2-f1 and

f2 = itab2-f2.

if sy-subrc = 0.

itab3-f1 =itab1-f1.

.

.

.itab3-f4 = itab1-f4.

read table itab2 with key f1 = itab1-f1 and

f2 = itab1- f2.

itab3 -f5 = itab2-f5.

.

.

itab3-f9 = itab2-f9.

endif.

endloop.

Read only

Former Member
0 Likes
1,255

Try this code:

LOOP AT ITAB1.

READ TABLE ITAB2 WITH KEY F1 = ITAB1-F1

AND F2 = ITAB1-F2.

IF sy-subrc = 0.

MOVE-CORRESPONDING ITAB1 TO ITAB3.

MOVE-CORRESPONDING ITAB2 TO ITAB3.

APPEND ITAB3.

CLEAR ITAB3.

ENDIF.

ENDLOOP.

ENDLOOP.

Read only

Former Member
0 Likes
1,255

Hi,

do like this

sort itab2.

LOOP AT ITAB1.

read table ITAB2 with key F1 = ITAB1-F1

AND F2 = ITAB1-F2

binarysearch.

if sy-subrc = 0.

ITAB3 = ITAB1.

APPEND ITAB3.

else.

ITAB3 = ITAB1.

APPEND ITAB3.

ITAB3 = ITAB2.

APPEND ITAB3.

endif.

endloop.

regards

Shiva