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

looping through internal tables

Former Member
0 Likes
752

Hi Guys,

Need to know something. I have this following code:

LOOP at tab1

-

-

LOOP at tab2

Append ftab.

endloop

LOOP at tab3

Append ftab.

endloop

LOOP at tab4

Append ftab.

endloop

LOOP at tab5

Append ftab.

endloop

Append ftab

Endloop

Now the problem is that my final table ftab is giving repeated values.

Can somebody help?

I really need help on this asap.

Thanks in advance.

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
636

Can you please post the entire loop with all the code. From what you have shown us so far, you are not moving anything into fTab.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
636

Hi,

As you are looping on each table based on the condition which is derived from tab1 and appending at each loop for the same key data, also finally after these entire process you append at the last which might have the entries same as that of the last loop for tab5. try to clear the header if required at each sucessive loop statements.

Regards,

Jagath

Read only

Former Member
0 Likes
636

Hi Minal,

if your probles is the presence of repeted values, try to make a DELETE ADJACENTS .

More, what do you do in the inner loop?

Does ftab have always value of tab1?

Put all the code, problably I coul'd help you better.

Bye

Read only

Former Member
0 Likes
636

Hi Minal,

You can do 2 things:

(1) decide whether to append ftab before 'append' statement: Use "read table ftab into wa_ftab with key keyfield = value" for this. If you get a returncode 0, the record is already in ftab.

(2) always append and delete double entries afterwards (like suggested by Enzo). You will have to sort the table first. "sort ftab by key. delete adjacent duplicates from ftab comparing key."

I think, I'd prefer the second option...

Hope this helps, regards, Kathrin!

Read only

Former Member
0 Likes
636

Hi Minal,

If it is so that ftab table is taking some fields form each of the tables u are looping at then what u need to take care of in addition to the above advice(s) is clear the internal tables u are looping at, at the end of every loop ... if not what it will do is carry forward the values even if not populate in the record of the next itab iteration.

Hope this makes sense.

Regards,

Aditya