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

Combining Internal Tables

Former Member
0 Likes
624

Plz any body send me the code for combining more than two internal

tables and filling into one final internal table

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
598

loop at itab1.

read table itab2 with key field1 = itab1-field1

field2 = itab1-field2.

read table itab3 with key field1 = itab1-field1

field3 = itab1-field3.

move-sorresponding itab1 to it_final.

move-sorresponding itab2 to it_final.

move-sorresponding itab3 to it_final.

append it_final.

clear it_final.

if sy-subrc = 0.

endif.

endloop.

Plz any body send me the code for combining more than two internal

tables and filling into one final internal table

4 REPLIES 4
Read only

Former Member
0 Likes
599

loop at itab1.

read table itab2 with key field1 = itab1-field1

field2 = itab1-field2.

read table itab3 with key field1 = itab1-field1

field3 = itab1-field3.

move-sorresponding itab1 to it_final.

move-sorresponding itab2 to it_final.

move-sorresponding itab3 to it_final.

append it_final.

clear it_final.

if sy-subrc = 0.

endif.

endloop.

Read only

anversha_s
Active Contributor
0 Likes
598

hi,

check this.

data : begin of itab1 occurs 0. "itab with work area.
key_field1 like ztable1-key_field1,
field1 like ztable1-field1,
field2 like ztable1-field2,
endof itab1. 

data : begin of itab2 occurs 0. "itab with work area.
key_field2 like ztable2-key_field2,
field3 like ztable2-field3,
field4 like ztable2-field4,
endof itab2. 

data : begin of itab_final occurs 0.
key_field1 like ztable1-key_field1,
field1 like ztable1-field1,
field2 like ztable1-field2,
field3 like ztable2-field3,
field4 like ztable2-field4,
endof itab_final. 


put the date final(merged) internal table
*****************************************
1. loop at itab1.
read table itab2 with key keyfield2 = itab1-keyfield1.
if sy-surc = 0.
itab_final-key_field1 = itab1-keyfield1
itab_final-field1 = itab1-field1.
itab_final-field2 = itab1-keyfield2.
itab_final-field3 = itab2-field2.
itab_final-field4 = itab2-keyfield2.
append itab_final.
clear itab_final.
endif.
endloop.

<b>or</b>

LOOP AT ITAB1.
MOVE-CORRESPONDING TO ITAB1 to ITAB_FINAL.
READ TABLE ITAB2 WITH KEY FILED1 = ITAB1-FIELD1.
if sy-subrc = 0.
MOVE-CORRESPONDING TO ITAB2 to ITAB_FINAL.
endif,
READ TABLE ITAB3 WITH KEY FILED1 = ITAB1-FIELD1.
if sy-subrc = 0.
MOVE-CORRESPONDING TO ITAB2 to ITAB_FINAL.
endif,
append itab_final.
clear itab_final.
endloop

Rgds

Anver

Read only

Former Member
0 Likes
598

Hi,

  loop at itab1.
              move-corresponding itab1 to it_final.
          read table itab2 with key field1 = itab1-field1.
            if sy-subrc eq 0.
              move-corresponding itab2 to it_final.
           endif.
 append it_final.
clear it_final.
 endloop

Read only

Former Member
0 Likes
598

hi ,

plz check the below code..

DATA:V_MATNR LIKE MARA-MATNR,

V_WERKS LIKE T001W-WERKS,

V_LGORT LIKE T001L-LGORT,

amount like vbap-kwmeng,

V_TAB LIKE SY-TABIX.

DATA:BEGIN OF IT_MAKT OCCURS 0,

MAKTX LIKE MAKT-MAKTX,

MATNR LIKE MAKT-MATNR,

END OF IT_MAKT.

DATA:BEGIN OF IT_MARD OCCURS 0,

WERKS LIKE MARC-WERKS,

MATNR LIKE MARA-MATNR,

LGORT LIKE MARD-LGORT,

LABST LIKE MARD-LABST,

INSME LIKE MARD-INSME,

RETME LIKE MARD-RETME,

UMLME LIKE MARD-UMLME,

END OF IT_MARD.

DATA: BEGIN OF IT_FINAL OCCURS 0,

WERKS LIKE MARD-WERKS LENGTH 5,

MAKTX LIKE MAKT-MAKTX LENGTH 5,

MATNR LIKE MARD-MATNR LENGTH 5,

LGORT LIKE MARD-LGORT LENGTH 5,

LABST LIKE MARD-LABST LENGTH 5,

INSME LIKE MARD-INSME LENGTH 5,

RETME LIKE MARD-RETME LENGTH 5,

UMLME LIKE MARD-UMLME LENGTH 5,

END OF IT_FINAL.

**********************************************************************

SELECT-OPTIONS:S_MATNR FOR MARD-MATNR,

S_WERKS FOR MARD-WERKS,

S_LGORT FOR MARD-LGORT.

******************************************************************

START-OF-SELECTION.

SELECT

WERKS

MATNR

LGORT

LABST

INSME

RETME

UMLME

FROM MARD

INTO TABLE IT_MARD

WHERE MATNR IN S_MATNR AND

WERKS IN S_WERKS AND

LGORT IN S_LGORT.

SELECT MAKTX

MATNR

FROM MAKT

INTO TABLE IT_MAKT

FOR ALL ENTRIES IN IT_MARD

WHERE MATNR = IT_MARD-MATNR.

*****************************************************************

END-OF-SELECTION.

MOVE: IT_MARD-WERKS TO IT_FINAL-WERKS,

IT_MARD-MATNR TO IT_FINAL-MATNR,

IT_MARD-LGORT TO IT_FINAL-LGORT,

IT_MARD-LABST TO IT_FINAL-LABST,

IT_MARD-INSME TO IT_FINAL-INSME,

IT_MARD-RETME TO IT_FINAL-RETME,

IT_MARD-UMLME TO IT_FINAL-UMLME.

loop at it_mard.

READ TABLE IT_MAKT WITH KEY MATNR = IT_mard-MATNR.

MOVE: IT_MAKT-MAKTX TO IT_FINAL-MAKTX.

APPEND IT_FINAL.

ENDLOOP.

Hope it helps you...

Regards,

sudha