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

Modifying internal table in loop.

Former Member
0 Likes
973

Hi Guis,

I have data in five internal table each internal tale contains one field. I have to move all these fields into one final internal table.

How to do this please any body suggest.

Thanks,

santhosh

8 REPLIES 8
Read only

Former Member
0 Likes
899

Hi,'

try this way..

Loop at itab1.

w_index = sy-tabix.

read itab2 with key commanfield1 = irab1-commaon field.

if sy-subrc = 0.

move corresponding itab2 to itab1.

endif.

read itab3with key commanfield1 = irab1-commaon field.

if sy-subrc = 0.

move corresponding itab3 to itab1.

endif

read itab4 with key commanfield1 = irab1-commaon field.

if sy-subrc = 0.

move corresponding itab4 to itab1.

endif

read itab5 with key commanfield1 = irab1-commaon field.

if sy-subrc = 0.

move corresponding itab5 to itab1.

endif.

Modify itab1 index w_index.

Endloop.

Prabhudas

Read only

Former Member
0 Likes
899

Hi,

Before creating 5 internal tables, make sure that each table has some relation with some other table.

If you have only 1 field in the table how will you relate with other tables.

Internal tables will perform better when it works same like Data base table. i.e. Relational schema.

Regards,

Prathap

Read only

Former Member
0 Likes
899

Hi,

If all the 5 internal tables are of same type then you can use the following statements for appending all the internal tables to the final internal table.

append lines of itab1 to ifinal.

append lines of itab2 to ifinal.

append lines of itab3 to ifinal.

append lines of itab4 to ifinal.

append lines of itab5 to ifinal.

Regards,

Swetha

Read only

Former Member
0 Likes
899

Hi ,

As per your question, you can use Move statement for moving all the fileds to the Final Interanl Table.

Hope this will work.

Here is the sample code:

MOVE itab1 TO itab2.

or the equivalent statement

itab2 = itab1.

Likewise you can move it to the Final Table.

regards,

Dhanalakshmi L

Read only

Former Member
0 Likes
899

Hi,

You say there is just one field in each of your 5 internal tables. Looks like there is no relation between them. This might cause a performance issue. So I would suggest you to relook into the portion of code where you are populating data into 5 different internal tables. May be, you could do so alternatively that might improve the performance. As for your requirement, you can use MOVE statement.

move itab1-field1 to itab_final-field1.

move itab2-field1 to itab_final-field2.

move itab3-field1 to itab_final-field3.

move itab4-field1 to itab_final-field4.

move itab5-field1 to itab_final-field5.

or

itab_final-field1 = itab1-field1.

And then append the data to the internal table.

Read only

0 Likes
899

HI,

Before getting table in 5 different internal table get some field which relate to other table.

then loop through the table and Read the link field in the other table

check the return value if its 0 then move the value to that table.

example

loop at itab1.

read table itab2 with key f1 = itab2-f1.

if sy-subrc eq 0.

itab1-f1 = itab2-f1.

endif.

modify itab1.

endloop.

like that you have to move all those field into the single internal table

Regards,

John Victor

Read only

Former Member
0 Likes
899

Hi ,

This code mite help you ......

      • there is a 2,500 character limit for individual posts. Please only post the relevant portions of code ***

Thanks

Ramakrishna.

Edited by: Rob Burbank on Aug 5, 2009 10:54 AM

Read only

Former Member
0 Likes
899

Hi ,

This code mite help you ......

Internal table 1:

types: begin of tt_vbak,

vbeln type vbeln_va, "SALES ORDER NO

audat type audat, "DOCUMENT DATE

end of tt_vbak.

Internal table 2:

types: begin of tt_vbap,

vbeln type vbeln_va, "SALES ORDER NO

posnr type posnr_va, "SALES DOCU ITEM

end of tt_vbap.

Internal table 3:

types: begin of tt_vbuk,

vbeln type vbeln_va,

gbstk type gbstk, "OVERALL PROCESSING STATUS OF DOCU

end of tt_vbuk.

Clubing all the internal table 1,2,3 into Final Table .

types: begin of tt_final,

audat type audat , "SOLD TO PARTY

vbeln type vbeln_va, "SALES ORDER NO

posnr type posnr_va, "SALES DOCU ITEM

gbstk type gbstk, "DISTRIBUTION CHANNE

end of tt_final.

&----


*& INTERNAL TABLE DECLARATION FOR TT_VBAK,TT_VBAP,TT_FINAL TABLE

*&

&----


data:itab_vbak type standard table of tt_vbak ,

itab_vbap type standard table of tt_vbap ,

itab_vbuk type standard table of tt_vbuk ,

itab_final type standard table of tt_final.

&----


*& WORK AREA DECLARATION FOR TT_VBAK,TT_VBAP,TT_FINAL TABLE

*&

&----


data: wa_vbak type tt_vbak,

wa_vbap type tt_vbap,

wa_final type tt_final.

orm select_vbak .

We Are Selecting Fields From Internal Table 1.

select vbeln

audat

from vbak into table itab_vbak

where vkorg = p_vkorg and vtweg = p_vtweg

We Are Selecting Fields From Internal Table 2.

if not itab_vbak[] is initial.

select vbeln

posnr

from vbap into table itab_vbap

for all entries in itab_vbak

where vbeln = itab_vbak-vbeln .

endif.

We Are Selecting Fields From Internal Table3.

if not itab_vbak[] is initial.

select vbeln gbstk from vbuk into table itab_vbuk

for all entries in itab_vbak

where vbeln = itab_vbak-vbeln and gbstk ne 'C'.

endif.

if not itab_vbuk[] is initial.

select vbeln

posnr

from vbap into table itab_vbap

for all entries in itab_vbuk

where vbeln = itab_vbuk-vbeln .

endif.

Inserting All Internaltable Fields into Final Table.

if not itab_vbap[] is initial.

loop at itab_vbap into wa_vbap.

wa_final-vbeln = wa_vbap-vbeln.

wa_final-posnr = wa_vbap-posnr.

read table itab_vbak into wa_vbak with key vbeln =

wa_vbap-vbeln.

if sy-subrc = 0.

wa_final-audat = wa_vbak-audat.

append wa_final to itab_final.

clear wa_vbak.

clear wa_vbap.

clear wa_final.

endif.

endloop.

endif.

Thanks

Ramakrishna.