‎2011 Sep 14 1:42 AM
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
‎2011 Sep 16 8:31 AM
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
‎2011 Sep 16 8:31 AM
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
‎2011 Sep 16 2:55 PM