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

Nested loop in smartforms

Former Member
0 Likes
756

Hi gurus,

I have a issue with nested looping. Based on the quantity in the order item I want to print the number of labels at item level.

i.e Order Item qty

111 10 2 ( I need 2 labels )

111 20 3 ( I need 3 labels )

112 10 5 ( I need 5 labels )

So under the order items loop, I created another loop and and added a program line and tried to manage the 2nd loop by a count. But I failed, I just couldn't get the loop working properly.

How can I control the second loop just by a count and exit it once it reaches a particular value.

Thanks and regards

Dhanushka.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
706

In the second loop, put the condition on item and order number.

I mean in the whrere clause of the second loop, use the condition item = 1stloop-item

5 REPLIES 5
Read only

Former Member
0 Likes
707

In the second loop, put the condition on item and order number.

I mean in the whrere clause of the second loop, use the condition item = 1stloop-item

Read only

0 Likes
706

Hi,

You can use counter also


loop at itab.
counter = 10.
loop at itab where sy-tabix <= counter.

endloop.
endloop.

Hope this will work for you

Read only

0 Likes
706

Hi,

There is no itab for second loop. I just want to have a DO WHILE till it reaches a Value. Basically once it reaches the value it should exit from the second loop in the smartform and go to the next item in the first loop. Can i do this without having another itab for the second loop.

Thanks & Regards

Dhanushka.

Read only

0 Likes
706

Hi

I hope this example is helfull for you:

DATA: BEGIN OF ITAB,

NUMBER TYPE ...

ITEM TYPE ...

QTY TYPE ...

END OF ITAB.

DATA TIMES TYPE I.

LOOP AT ITAB.

MOVE ITAB-QTY TO TIMES.

DO TIMES TIMES.

......

ENDDO.

ENDLOOP.

You can use a WHILE cycle:

DATA COUNTER TYPE I.

LOOP AT ITAB.

MOVE ITAB-QTY TO TIMES.

COUNTER = 0.

WHILE COUNTER > TIMES.

......

COUNTER = COUNTER + 1.

ENDWHILE.

ENDLOOP.

Max

Message was edited by: max bianchi

Read only

Former Member
0 Likes
706

Hi,

loop at item table.

at new posnr.

do qty times.

call print lable program

enddo.

endat.

endloop.

Hope this help you.

Thanks,

Nethaji.