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 to internal table

Former Member
0 Kudos

Hi

i have 2 internal table with records. The 1st one called it_pbim it have MATNR and BDZEI . The 2nd internal table called it_pbhi and it have BDZEI and PLNMG. Now i need one internal table with above four fields and its respective records.

ie i need internal table with matnr bdzei plnmg in one table .

plz any one give soln.

Mohana

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Sort ITAB2 by BDZEI.

Loop at ITAB1.

ITAB3-MATNR = ITAB1-MATNR.

ITAB3-BDZEI = ITAB1- BDZEI.

Read ITAB2 with key BDZEI = ITAB1-BDZEI

binary search.

If sy-subrc = 0.

ITAB3-PLNMG = ITAB2-PLNMG.

endif.

endloop.

Shreekant

4 REPLIES 4

Former Member
0 Kudos

Hi,

Here is sample code -

SORT IT_PBIM BY MATNR.

SORT IT_PBHI NY BDZEI.

LOOP AT IT_PBIM.

L_tABIX = SY-TABIX.

READ TABLE IT_PBHI WITH KEY BDZEI = IT_PBIM-BDZEI.

IF SY-SUBRC EQ 0.

IT_PBIM-QTY = IT_PBHI-QTY.

MODIFY IT_PBIM INDEX L_TABIX TRANSPORTING QTY.

ENDIF.

ENDLOOP.

Hope this helps.

ashish

PS: I think you asked same question some time back and thread is still open.

Former Member
0 Kudos

Hi Mohana,

declare an internal table it_final with fields Matnr, bdzei, PLNMG.

loop at itab1 into wa1.

wa_final-matnr = wa1-matnr.

wa_final-bezei = wa1-bezei.

read table itab2 into wa2 with key bezei = wa1-bezei.

if sy-subrc = 0.

move wa2-PLNMG to wa_final-PLNMG.

endif.

append wa_final to it_final.

clear wa_final.

endloop.

<b><REMOVED BY MODERATOR></b>

Satish

Message was edited by:

Alvaro Tejada Galindo

Former Member
0 Kudos

Sort ITAB2 by BDZEI.

Loop at ITAB1.

ITAB3-MATNR = ITAB1-MATNR.

ITAB3-BDZEI = ITAB1- BDZEI.

Read ITAB2 with key BDZEI = ITAB1-BDZEI

binary search.

If sy-subrc = 0.

ITAB3-PLNMG = ITAB2-PLNMG.

endif.

endloop.

Shreekant

0 Kudos

DOnt forget for Sorting on ITAB2 and always use Binary search for read statements.

Shreekant