Application Development 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: 

How to merge two internal table

Former Member
0 Kudos

How to merge two internal table. can this be done without loop

ITAB1

ITAB2

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Use like:

Append lines of itab1 to itab2.

pls reward points if helped.

Regards,

Renjith Michael.

3 REPLIES 3

Former Member
0 Kudos

Hi,

Use like:

Append lines of itab1 to itab2.

pls reward points if helped.

Regards,

Renjith Michael.

Former Member
0 Kudos

Hi,

use this code

APPEND LINES OF <itab1> [FROM <n1>] [TO <n2>] TO <itab2>.

Without the FROM and TO options, this statement appends the entire table <itab1> to <itab2>.

Reward points if useful

Regards,

Goutham.

Former Member
0 Kudos

HI,

check this sample code

TABLES : KNA1,KNVV.

SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-101.

select-options : p_kunnr like kna1-kunnr.

SELECTION-SCREEN : END OF BLOCK b1.

data :BEGIN OF T_KNA1 OCCURS 0,

KUNNR LIKE KNA1-KUNNR,

LAND1 LIKE KNA1-LAND1,

NAME1 LIKE KNA1-NAME1,

END OF T_KNA1.

DATA :BEGIN OF T_KNVV OCCURS 0,

KUNNR LIKE KNA1-KUNNR,

VKORG LIKE KNA1-VKORG

VTEWG LIKE KNA1-VTEWG,

END OF T_KNVV.

FINAL INTERNAL TABLE

DATA : BEGIN OF T_FINAL OCCURS 0,

KUNNR LIKE KNA1-KUNNR,

LAND1 LIKE KNA1-LAND1,

NAME1 LIKE KNA1-NAME1,

VKORG LIKE KNA1-VKORG

VTEWG LIKE KNA1-VTEWG,

END OF T_FINAL.

START-OF-SELECTION

SELECT KUNNR LAND1 NAME1 FROM KNA1 INTO TABLE T_KNA1 WHERE KUNNR IN P_KUNNR

IF SY-SUBRC = 0.

select KUNNR

VKORG VTEWG

from KNVV

into CORRESPONDING FIELDS OF table T_KNVV

for all entries in T_KNA1

where KUNNR = T_KNA1-KUNNR.

ENDIF.

LOOP AT T_KNA1.

MOVE T_KNA1-KUNNR TO T_FINAL-KUNNR.

MOVE T_KNA1-LAND1 TO T_FINAL-LAND1.

MOVE T_KNA1-NAME1 TO T_FINAL-NAME1.

READ TABLE T_KNVV WITH KEY KUNNR = T_KNA1-KUNNR.

IF SY-SUBRC = 0.

MOVE T_KNVV-VKORG TO T_FINAL-VKORG.

MOVE T_KNVV-VTEWG TO T_FINAL-VTEWG.

ENDIF.

APPEND T_FINAL.

CLEAR T_FINAL.

ENDLOOP.

LOOP AT T_FINAL.

WRITE: (FIELDS U WANT TO DISPLAY)

ENDLOOP.

Reward if helpful.

Thankyou,

Regards.