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

merge 2 internal table

Former Member
0 Likes
1,012

hi,

1st internal table contains 5 field from ekko - po header table

2nd internal table contains corresponding value from ekpo - po line item table.

now i want to merge this table into 3rd table.

please give me best suggestions with minimum loop logic.

thanks,

raj

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
991

loop at iekpo.

move-corresponding iekpo to ifinal.

read table iekko with key ebeln = iekpo-ebeln.

if sy-subrc = 0.

move-corresponding iekko to ifinal.

endif.

append ifinal.

clear : ifinal,iekko.

endloop.

regards

shiba dutta

hi,

1st internal table contains 5 field from ekko - po header table

2nd internal table contains corresponding value from ekpo - po line item table.

now i want to merge this table into 3rd table.

please give me best suggestions with minimum loop logic.

thanks,

raj

8 REPLIES 8
Read only

Former Member
0 Likes
991

Hi

Try this logic.

Loop at itab_ekko.

loop ar itab_ekpo where ebeln = itab_ekko-ebeln.

clear itab3.

<b><populate the fields of itab3 from itab_ekpo></b>

append itab3.

Endloop.

Endloop.

Regards

Raj

Read only

Former Member
0 Likes
991

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 Else</b>

If both the structure are same, we can do that by:

APPEND lines of itab1 to itab2.

if structures are different.

loop at itab1.

clear: itab2.

move-corresponding itab1 to itab2.

append itab2.

endloop.

Regards,

Priyanka.

Read only

Former Member
0 Likes
992

loop at iekpo.

move-corresponding iekpo to ifinal.

read table iekko with key ebeln = iekpo-ebeln.

if sy-subrc = 0.

move-corresponding iekko to ifinal.

endif.

append ifinal.

clear : ifinal,iekko.

endloop.

regards

shiba dutta

Read only

Former Member
0 Likes
991

Hi,

Take the new third internal table like itab3.

now using move-corresponding itab2 to itab3.

or you can also move field by field........

itab3-ebeln = itab1-ebeln.

itab3-ebelp-itab2-ebelp.

***do reward if usefull

vijay

Read only

Former Member
0 Likes
991

Hi Raj

Refer this Code.

We should create one structure; it should have all header and line item fields.

Internal table for Header: It_header.

Internal table for Line item: it_lineitem.

Internal table for Merge: it_merge.

LOOP AT IT_EKPO.

MOVE-CORRESPONDING IT_EKPO TO IT_MERGE.

APPEND IT_MERGE.

ENDLOOP.

LOOP AT IT_MERGE .

READ TABLE IT_EKKO WITH KEY EBELN = IT_MERGE-EBELN BINARY SEARCH.

IF SY-SUBRC = 0.

MOVE-CORRESPONDING IT_EKKO TO IT_MERGE.

MODIFY IT_MERGE.

ENDIF.

ENDLOOP.

I hope it will work.

Reward all helpfull answers.

Regards.

Jay

Read only

Former Member
0 Likes
991

hi,

plz refer the code below. in this way you can solve your query.

TYPES: begin of itype,

lifnr TYPE rbkp-lifnr,

belnr TYPE rbkp-belnr,

xblnr TYPE rbkp-xblnr,

END OF itype.

TYPES:BEGIN OF itype1,

name1 TYPE lfa1-name1,

END OF itype1.

TYPES: BEGIN OF itype2,

ebeln TYPE ekbe-ebeln,

belnr type ekbe-belnr,

END OF itype2.

DATA: itab TYPE TABLE OF itype, "internal table

wtab TYPE itype. "work area

DATA: itab1 TYPE TABLE OF itype1, "internal table

wtab1 TYPE itype1. "work area

DATA: itab2 TYPE TABLE OF itype2, "internal table

wtab2 TYPE itype2. "work area

select ebeln belnr from ekbe into table itab2 where ebeln in s_ebeln.

SELECT lifnr belnr xblnr FROM rbkp INTO TABLE itab FOR ALL ENTRIES IN

itab2 WHERE

belnr = itab2-belnr.

.

SELECT name1 FROM lfa1 INTO TABLE itab1 FOR ALL ENTRIES IN itab WHERE

lifnr = itab-lifnr.

Loop at itab2 into wtab2.

iheader-ebeln = wtab2-ebeln.

read table itab into wtab

with key belnr = wtab2-belnr.

iheader-lifnr = wtab-lifnr.

iheader-belnr = wtab-belnr.

iheader-xblnr = wtab-xblnr.

read table itab1 into wtab1

with key lifnr = iheader-lifnr.

iheader-name1 = wtab1-name1.

end loop.

here data of three internal table itab, itab1, itab2 is going in one internal tbale iheader.

regards,

Ruchika

Reward if useful.......

Read only

Former Member
0 Likes
991

Hi,

The following logic is a bit complicated but will give you best performance.


Sort INTTAB_EKPO by EBELN.

Loop at INTTAB_EKKO.
read table INTTAB_EKPO with key ebeln = inttab_ekko-ebeln transporting no-fields binary search.
if sy-subrc eq 0.
loop at INTTAB_EKPO from index sy-tabix.
if INTTAB_EKPO-ebeln ne INTTAB_EKKO-ebeln.
exit.
endif.

* Transfer to third internal table

endloop.
endif.
endloop.

This will give best performance when high data volume is involved. There will be less looping as we will be only looping at the desired header records in the item table. The most important thing is that the item table must be sorted by EBELN.

Reward if useful.

Thanks...

Preetham S

Read only

Former Member
0 Likes
991

thanks

raj