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

Append statments for multiple loop

Former Member
0 Likes
2,012

Hi all,

I have three loops under a main loop

Loop at maintable .

loop at table1.

endloop.

loop at table2.

endloop.

loop at table3.

endloop.

endloop.

my question is that i have mutiple records in the table 1,2,3

i dont know where to use my append maintable as if i use in the main loop only one record of the table

is updated

anyone there to help me

please

13 REPLIES 13
Read only

Former Member
0 Likes
1,817

Hi Sridhar,

Declare one work area for maintable and use it at the end of all three loops, as given below.


Loop at maintable .
loop at table1.
" WA_MAINTABLE-field
endloop.
loop at table2.
" WA_MAINTABLE-field
endloop.
loop at table3.
" WA_MAINTABLE-field
endloop.
" APPEND WA_MAINTABLE to MAINTABLE.
endloop.

Instead you can even use READ statement if possible, based on your requirement.

Best Regards,

Ram.

Read only

0 Likes
1,817

i have used read table only but , it is getting only record , i have used workarea ,

and the table1,2,3 has muliple records , where is it is overwriten and the final value is updated to the fiinal tale

Read only

0 Likes
1,817

Hi Sridhar,

1. Is it necessary for you to LOOP in table 1, 2 and 3, inside your MAINTABLE. Are you using any condition in your inner loops?

2. If yes, and if you want all those records to be updated then you need to use APPEND inside your inner loop.

KIndly let us know your requirement.

Best Regards,

Ram.

Read only

0 Likes
1,817

yes i need to use loop inside the maintable , and one more thing , can i use multiple append in my loops , casue i am afraid it might lead to duplicate records or some error

Read only

0 Likes
1,817

Hi Sridhar,

In case you are worrying about duplicate records, you can always use, Delete adjacent duplicates statement on your main table to remove it.

I think i am not very clear on what you are trying to acheive.

First, You want records from your MAINTABLE to be filled from itab1, itab2 and itab3. Hope this is correct.

To acheive this,

First


loop at itab1.
" Append entries to your maintable.
endloop.

Now, based on these entries, if you want to fill records from itab2 and itab3. If yes, then


loop at itab2.
" read maintable with key. If found, modify, else, append to maintable
endloop.
loop at itab3.
" read maintable with key. if found, modify, else append to maintable.
endloop.

Hope this is what you want. If otherwise, please let us know.

Best Regards,

Ram.

Read only

Former Member
0 Likes
1,817

Hi,

Can you please explain your question more clearly?

Regards,

Aruna

Read only

Former Member
0 Likes
1,817

Hi

try to using read statement instead

READ TABLE <table> INTO <wa?WITH KEY <key>

Read only

Former Member
0 Likes
1,817

Hi Loganadhan,

Please note if you are appending rows to an internal table which you are looping will result in ENDLESS LOOP.

First you collect the records from each internal table into a temporary itab then pass them to main loop.

or

loop each itab separately and append them to main table.

loop at itab1

append itab from itab1.

endloop

loop at itab2

append itab from itab2

endloop

loop at itab3

append itab from itab3

endloop

Regards

Ramchander Rao.K

Read only

0 Likes
1,817

sorry ram chandran,

i am not clear with ur concept casue append itab from itab1 it is showing me syntax error

Read only

0 Likes
1,817

Hi,

May be their line types are incompatible( not equal).

check the components of your internal tables( are they having same names and types)

loop at itab1.

move-correspondign itab1 to itab.

append itab.

endloop.

loop at itab2.

move-corresponding itab2 to itab.

append itab.

endloop.

loop at itab3.

move-corresponding itab3 to itab.

append itab.

endloop.

Best Regards

Ramchander Rao.K

Read only

Former Member
0 Likes
1,817

loop at itab1.

move-corresponding itab1 to maintable.

append maintable.

endloop.

loop at itab2.

move-corresponding itab2 to maintable.

append maintable.

endloop

loop at itab3.

move-corresponding itab3 to maintable.

append maintable.

endloop

Read only

Former Member
0 Likes
1,817

Hi,

What's your requirement?

So many loops in a main loop will effect the performance.

Regards,

Chris Gu

Read only

Former Member
0 Likes
1,817

changed the loop with item level and read the header table using read statement and appended , the final table

i was not having any eror by doing this