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: 

populating final internal table

Former Member
0 Kudos

hi,

i have 5 internal tables.in that 1 & send have one common field,2 & 3 have one common field,similarly 3& 4,3 & 5.

i need to populate final internal table with these five internal tables.

if i tried to populate it ,final internal table is appending for each internal table.

it is appending records more than one time.

t i am unable to do it.if any one knows please help,it's urgent.

i am giving my code which i wrote.

SORT it_t5utv BY txcmp.

sort it_eeo_locat by txcmp.

LOOP AT it_t5utv .

it_output-txcmp = it_t5utv-txcmp.

it_output-wksit = it_t5utv-wksit.

it_output-ltext = it_t5utv-ltext.

it_output-adres = it_t5utv-adres.

it_output-stras = it_t5utv-stras.

it_output-ort01 = it_t5utv-ort01.

it_output-state = it_t5utv-state.

it_output-zipcd = it_t5utv-zipcd.

read table it_eeo_locat with key txcmp = it_t5utv-txcmp binary search.

it_output-wstate = it_eeo_locat-wstate.

it_output-unitcd = it_eeo_locat-unitcd.

APPEND it_output.

ENDLOOP.

sort it_eeo_locat by unitcd.

SORT it_eeo_unit BY unitcd.

SORT it_country BY countycd.

SORT it_naics BY naicscd.

LOOP AT it_eeo_locat.

read table it_eeo_unit with key unitcd = it_eeo_locat-unitcd binary

search.

it_output-eeoccd = it_eeo_unit-eeoccd.

it_output-naicscd = it_eeo_unit-naicscd

.

it_output-unitname = it_eeo_unit-unitname.

it_output-street = it_eeo_unit-street.

it_output-street_ext = it_eeo_unit-street_ext.

it_output-city = it_eeo_unit-city.

it_output-eeoccd = it_eeo_unit-eeoccd.

it_output-state = it_eeo_unit-state.

it_output-zip = it_eeo_unit-zip.

it_output-zip_rem = it_eeo_unit-zip_rem.

it_output-county = it_eeo_unit-county.

it_output-hq_ind = it_eeo_unit-hq_ind.

it_output-hire_ind = it_eeo_unit-hire_ind.

APPEND it_output.

ENDLOOP.

loop at it_eeo_unit .

read table it_country with key countycd = it_eeo_unit-county binary

search.

it_output-countynm = it_country-countynm.

read table it_naics with key naicscd = it_eeo_unit-naicscd binary

search.

it_output-naicsnm = it_naics-naicsnm.

APPEND it_output.

ENDLOOP.

1 ACCEPTED SOLUTION

amit_khare
Active Contributor
0 Kudos

Hi,

Try out this, it might help you.

Loop at it1 into wa1.

read table it2 into wa2 where <condition>.

read table it3 into wa3 where <condition>.

read table it4 into wa4 where <condition>.

read table it5 into wa5 where <condition>.

wa_final -f1 = wa1-f1.

wa_final-f2 = wa2-f2.

wa_final-f3 = wa2-f3.

wa_final-f4 = wa2-f4.

wa_final-f5 = wa2-f5.

append wa_final to it_final.

endloop.

Regards,

Amit

Reward all helpful replies.

4 REPLIES 4

former_member191977
Contributor
0 Kudos

Hi Sudha,

First thing is you are appending the records to your final output internal table so many times. Instead of 1 record each time.

You should be designing it in such a way that you should have a key internal table and further information in the respective internal tables. Loop at the key IT (Internal table) and do a read on further table get the data and do a append to your final internal table. this is one way.

or else the only way left is you have to loop the other internal tables in your main loop which is not suggestable with regards to performance.

Award points if it helps.

amit_khare
Active Contributor
0 Kudos

Hi,

Try out this, it might help you.

Loop at it1 into wa1.

read table it2 into wa2 where <condition>.

read table it3 into wa3 where <condition>.

read table it4 into wa4 where <condition>.

read table it5 into wa5 where <condition>.

wa_final -f1 = wa1-f1.

wa_final-f2 = wa2-f2.

wa_final-f3 = wa2-f3.

wa_final-f4 = wa2-f4.

wa_final-f5 = wa2-f5.

append wa_final to it_final.

endloop.

Regards,

Amit

Reward all helpful replies.

Former Member
0 Kudos

sort all the tables.

loop at itab1.

move-corresponding itab1 to itabfinal.

read table itab2 with key f1 = itab1-f1.

if sy-subrc = 0.

move-corresponding itab2 to itabfinal.

read table itab3 with key f2 = itab2-f2.

if sy-subrc = 0.

move-corresponding itab3 to itabfinal.

read table itab4 with key f3 = itab3-f3.

if sy-subrc = 0.

move-corresponding itab4 to itabfinal.

read table itab5 with key f4 = itab3-f4.

if sy-subrc = 0.

move-corresponding itab5 to itabfinal.

endif.

endif.

endif.

endif.

append itabfinal.

clear : itab1,itab2,itab3,itab4,itab5.

endloop.

regards

shiba dutta

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Loop at the main table.

loop at itab1.

move-corresponding itab1 to itab_final.

loop at itab2 where f1 = itab-f1."You can use read if you are sure that you will get single record

move-corresponding itab2 to itab_final.

apend itab_final.

endloop.

endloop.