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

Former Member
0 Likes
1,566

Hi

I have 5 internal tables. I want to move all the records into single internal table. All 5 internal tables (1 header table and 4 item table) are in different structure. If any one have sample code for this please post the logic for the same.

Regards

Ravi

1 ACCEPTED SOLUTION
Read only

former_member210123
Active Participant
0 Likes
1,504

Hi Without knowing the fields of the 5 internal tables there is no way we can a logic for your problem.

Normally it is done like this.

Loop at the header table.

read from the item1 with key field1 = headerfield1.

read from the item2 with key field1 = headerfield2.

read from the item3 with key field1 = headerfield3.

read from the item4 with key field1 = headerfield4.

store the values in a work area of the final structure.

append all the values into the final structure.

endloop.

Hi Without knowing the fields of the 5 internal tables there is no way we can a logic for your problem.

Normally it is done like this.

Loop at the header table.

read from the item1 with key field1 = headerfield1.

read from the item2 with key field1 = headerfield2.

read from the item3 with key field1 = headerfield3.

read from the item4 with key field1 = headerfield4.

store the values in a work area of the final structure.

append all the values into the final structure.

endloop.

8 REPLIES 8
Read only

former_member210123
Active Participant
0 Likes
1,505

Hi Without knowing the fields of the 5 internal tables there is no way we can a logic for your problem.

Normally it is done like this.

Loop at the header table.

read from the item1 with key field1 = headerfield1.

read from the item2 with key field1 = headerfield2.

read from the item3 with key field1 = headerfield3.

read from the item4 with key field1 = headerfield4.

store the values in a work area of the final structure.

append all the values into the final structure.

endloop.

Read only

Former Member
0 Likes
1,504

Hi,

if all internal tables of same structure you can easily move all values to one internal table,if it has different structure it is little difficult ,you have to move only by field to field....

Regards,

V.Balaji

Reward if usefull

Read only

Former Member
0 Likes
1,504

Hi

loop at one item table make it as final type

read table2 based on loop

read table3based on loop

so on

finally use modify transrporting to get all the fields into one table

regards

Shiva

Read only

Former Member
0 Likes
1,504

Hi,

U cannot merge internal Tables of different structures .

Only way to create a structure with all the header and Item fields .

using the LOOP statement move the contents and append it into a the Final Internal Table .

Regards,

Balakumar.G

Reward Points if helpful.

Read only

Former Member
0 Likes
1,504

HI,

Try this formate.

LOOP AT mattab.
        SELECT SINGLE * FROM mara WHERE matnr = mattab-matnr.
        IF sy-subrc = 0.
*** mara
          it_final-matnr = mara-matnr.
          it_final-mtart = mara-mtart.
          it_final-meins = mara-meins.
          it_final-matkl = mara-matkl.
          it_final-brgew = mara-brgew.
          it_final-ntgew = mara-ntgew.
          it_final-gewei = mara-gewei.
          it_final-zeinr = mara-zeinr.
          it_final-ekwsl = mara-ekwsl.
          it_final-iprkz = mara-iprkz.
***This is for Qulity
          it_qulity-matnr = mara-matnr.
          it_qulity-qmpur = mara-qmpur.
***This is for Accounting
          it_act-matnr = mara-matnr.
***This is for Sales
          it_sales-matnr = mara-matnr.
          it_sales-tragr = mara-tragr.
          it_sales-taxkm = mara-taklv.
        ENDIF.

append it_final.
clear it_final.

endloop.

REgards,

S.Nehru

Read only

0 Likes
1,504

Hi

There is no link(Key fields) between all the 5 internal tables.

i want to print like this.

Header

Batch Header

Item1

item2

item3

batch header

item1

item2

item3.

This is a IFILE Requirment for INDIAN BANKS to print cheques..

Regards

Ravi

Read only

Former Member
0 Likes
1,504

Build a final internal table with all required fields based on Header and 5 item internal table.

then move corresponding data as below...........

loop at head.

move-corresponding head to final.

read item1 with key item1-field = head-field.

if sy-subrc eq 0.

move-corresponding item1 to final.

endif.

read item2 with key item2-field = head-field.

if sy-subrc eq 0.

move-corresponding item2 to final.

endif.

read item3 with key item3-field = head-field.

if sy-subrc eq 0.

move-corresponding item3 to final.

endif.

read item4 with key item4-field = head-field.

if sy-subrc eq 0.

move-corresponding item4 to final.

endif.

reward if useful............

append final.

endloop.

Read only

Former Member
0 Likes
1,504

hi,

report ztest.

tables:pa0002,pa0008,pa0021,pa0041.

data: begin of itab occurs 0,

pernr like pa0002-pernr,

vorna like pa0002-vorna,

nachn like pa0002-nachn,

end of itab.

data: begin of itab1 occurs 0,

pernr like pa0008-pernr,

begda like pa0008-begda,

stvor like pa0008-stvor,

ansal like pa0008-ansal,

end of itab1.

data :begin of itab2 occurs 0,

pernr like pa0021-pernr,

favor like pa0021-favor,

fanam like pa0021-fanam,

end of itab2.

data:begin of itab3 occurs 0,

pernr like pa0041-pernr,

dar01 like pa0041-dar01,

dat01 like pa0041-dat01,

end of itab3.

data:begin of final occurs 0,

pernr like pa0002-pernr,

vorna like pa0002-vorna,

nachn like pa0002-nachn,

begda like pa0008-begda,

stvor like pa0008-stvor,

ansal like pa0008-ansal,

favor like pa0021-favor,

fanam like pa0021-fanam,

dar01 like pa0041-dar01,

dat01 like pa0041-dat01,

end of final.

select-options:s_pernr for pa0002-pernr.

select pernr

vorna

nachn

from pa0002

into table itab

where pernr in s_pernr.

select pernr

begda

stvor

ansal

from pa0008

into table itab1

for all entries in itab

where pernr = itab-pernr.

select pernr

favor

fanam

from pa0021

into table itab2

for all entries in itab1

where pernr = itab1-pernr.

select pernr

dar01

dat01

from pa0041

into table itab3

for all entries in itab2

where pernr = itab2-pernr.

loop at itab.

final-pernr = itab-pernr.

final-vorna = itab-vorna.

final-nachn = itab-nachn.

read table itab1 with key pernr = itab-pernr.

final-begda = itab1-begda.

final-stvor = itab1-stvor.

final-ansal = itab1-ansal.

read table itab2 with key pernr = itab1-pernr.

final-favor = itab2-favor.

final-fanam = itab2-fanam.

read table itab3 with key pernr = itab2-pernr.

final-dar01 = itab3-dar01 .

final-dat01 = itab3-dat01.

append final.

clear final.

endloop.

loop at final.

write:final-pernr ,

final-vorna ,

final-nachn ,

final-begda ,

final-stvor ,

final-ansal ,

final-favor ,

final-fanam ,

final-dar01 ,

final-dat01 .

endloop.

regards,

venkat.