‎2006 Aug 02 12:09 AM
Hello Gurus,
I always have the confusion while I am using the control loops statment with respective to fields I want to use control loops on.
data: begin of sample_tab occurs 0,
field1 like mara-matnr,
field2 like vbrp-vbeln,
field3 like maktx-maktl,
end of sample_tab.
Let's think that FIELD1 is the desired field that I want to apply the control loops statment logic on always. Please also let me know that what care that I have to take before the use of Control loop statement. Please explain following scenarios.
AT end of - field1 is first field in sample_tab?
- field2 is second field in sample_tab?
- field1 is first field in sample_tab and not
a key field of any db table.
- field1 is second field in sample_tab and not
a key field of any db table.
AT frist - field1 is first field in sample_tab?
- field2 is second field in sample_tab?
- field1 is first field in sample_tab and not
a key field of any db table?
- field1 is second field in sample_tab and not
a key field of any db table?
AT last - field1 is first field in sample_tab?
- field2 is second field in sample_tab?
- field1 is first field in sample_tab and not
a key field of any db table?
- field1 is second field in sample_tab and not
a key field of any db table?
on change of - field1 is first field in sample_tab?
- field2 is second field in sample_tab?
- field1 is first field in sample_tab and not
a key field of any db table?
- field1 is second field in sample_tab and not
a key field of any db table?
Thanks in advance.
SDN
‎2006 Aug 02 12:33 AM
hi
before using the control loop statements you should sort the internal table by control break.
In your case you should sort your itab as <b>SORT SAMPLE_TAB BY FIELD1.</b>
Cheers,
Abdul Hakim
‎2006 Aug 02 12:19 AM
Hi,
Go through the link for control levels,
http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb381a358411d1829f0000e829fbfe/content.htm
Regards,
Azaz Ali.
‎2006 Aug 02 12:33 AM
hi
before using the control loop statements you should sort the internal table by control break.
In your case you should sort your itab as <b>SORT SAMPLE_TAB BY FIELD1.</b>
Cheers,
Abdul Hakim
‎2006 Aug 02 2:39 AM
Hi,
In order to properly use those statements, you should first sort your itab by field1. For example:
sort sample_tab by field1.
loop at sample_tab.
at end of field1.
write: / 'END'.
endat.
at first.
write: / 'This is the first record'.
endat.
at last.
write: / 'This is the last record'.
endat.
endloop.
Hope this helps...
P.S. Please award points for useful answers.
‎2006 Aug 02 3:55 AM
AT end of field1
- field1 is first field in sample_tab?
<b> will be processed whenever field1 changes </b>
AT end of field2
- field2 is second field in sample_tab?
<b> will be processed whenever field1 or field2 changes </b>
- field1 is first field in sample_tab and not
a key field of any db table.
<b> will be processed whenever field1 changes </b>
<b> being a key field is not relevant </b>
- field1 is second field in sample_tab and not
a key field of any db table.
<b> will be processed whenever field1 OR the first field changes </b>
<b> being a key field is not relevant </b>
AT frist - field1 is first field in sample_tab?
- field2 is second field in sample_tab?
- field1 is first field in sample_tab and not
a key field of any db table?
- field1 is second field in sample_tab and not
a key field of any db table?
<b> regardless of field values this code will be exected on the very FIRST pass of the loop</b>
AT last - field1 is first field in sample_tab?
- field2 is second field in sample_tab?
- field1 is first field in sample_tab and not
a key field of any db table?
- field1 is second field in sample_tab and not
a key field of any db table?
<b> regardless of field values this code will be exected on the very LAST pass of the loop</b>
on change of - field1 is first field in sample_tab?
- field2 is second field in sample_tab?
- field1 is first field in sample_tab and not
a key field of any db table?
- field1 is second field in sample_tab and not
a key field of any db table?
<b> do not use 'on change' this it is intended for 'selects' not loops. Instead use 'at new ..'. </b>
at new field1.
<b>This will be executed whenever the field1 value differs from the previous pass (or on the first pass).</b>
at new field2.
<b>This will be executed whenever the field1 OR field2 values differ from the previous pass (or on the first pass).</b>