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

loop table into SAPscript

Former Member
0 Likes
625

Hi all,

I would like to loop certain lines of an itab into a sapscript.

For example if the itab looks like below, then all materials with item 10 is outputted under 1 header, whilst all materials under item 20 is outputted under another header.

item matnr

10 abc

10 bcd

10 cde

20 zzz

20 xxx

20 yyy

In my sapscript I have:

/E components

'Hi there',,&vbplp-vbeln&

&st_matnr&

The output should look like the following:

Hi there 1001

abc

bcd

cde

Hi there 1002

zzz

xxx

yyy

I am using a loop, write_form function but it is not working.

loop itab.

call function write_form.

..

endform.

endloop.

Does anyone know how this can be achieved?

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
504

Hi,

I think you need to create a nested loop. Put your item loop within a header loop and call the write_form function once in the header loop and once in the item loop.

PERFORM open_form.

LOOP AT itab_header.

PERFORM write_form.

LOOP AT itab_item WHERE vbeln = itab_header-vbeln

PERFORM write_form.

ENDLOOP.

ENDLOOP.

PERFORM close_form.

Regards,

Martin

2 REPLIES 2
Read only

Former Member
0 Likes
505

Hi,

I think you need to create a nested loop. Put your item loop within a header loop and call the write_form function once in the header loop and once in the item loop.

PERFORM open_form.

LOOP AT itab_header.

PERFORM write_form.

LOOP AT itab_item WHERE vbeln = itab_header-vbeln

PERFORM write_form.

ENDLOOP.

ENDLOOP.

PERFORM close_form.

Regards,

Martin

Read only

Former Member
0 Likes
504

A nested loop solved it, thanks