‎2006 Jun 17 9:57 AM
hi,
what is the difference between 'onchange of' and 'atend of' control breaks. explain in detail with example.
Thank u in advance.
SRI.
‎2006 Jun 17 10:50 AM
ON CHANGE OF f.
Executes the processing block enclosed by the "ON CHANGE OF f" and "ENDON" statements whenever the contents of the field f change (control break processing).
Normally, you use the statement to manipulate database fields during GET events or SELECT/ENDSELECT processing.
ON CHANGE OF is unsuitable for recognizing control levels in loops of this type because it always creates a global auxiliary field which is used to check for changes. This global auxiliary field is only changed in the relevant ON CHANGE OF statement. It is not reset when the processing enters loops or subroutines, so unwanted effects can occur if the loop or subroutine is executed again. Also, since it is set to its initial value when created (like any other field), any ON CHANGE OF processing will be executed after the first test, unless the contents of the field concerned happen to be identical to the initial value.
DATA T100_WA TYPE T100.
SELECT * FROM T100
INTO T100_WA
WHERE SPRSL = SY-LANGU AND
MSGNR < '010'
ORDER BY PRIMARY KEY.
ON CHANGE OF T100_WA-ARBGB.
ULINE.
WRITE: / '**', T100_WA-ARBGB, '**'.
ENDON.
WRITE: / T100_WA-MSGNR, T100_WA-TEXT.
ENDSELECT.
Displays all messages with their numbers in the logon language, provided the number is less than '010'.
Each time the message class changes, it is output.
AT END OF f.
f is a sub-field of an internal table or extract dataset (EXTRACT) which is being processed with LOOP, i.e. the variants 1 and 2 only make sense within a LOOP.
Both "AT NEW f." and "AT END OF f. " introduce processing blocks which are concluded by " ENDAT.".
These processing blocks are processed whenever the contents of a field f or a sub-field defined before f change as a result of processing with LOOP. "AT NEW f." begins a new group of (table) lines with the same contents as the field f while "AT END OF f." concludes such a group.
Within the AT ... ENDAT processing of internal tables, all argument fields following f are filled with "*".
Examples
1. AT for sub-fields of an internal table
DATA: BEGIN OF COMPANIES OCCURS 20,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES.
...
LOOP AT COMPANIES.
AT NEW NAME.
NEW-PAGE.
WRITE / COMPANIES-NAME.
ENDAT.
WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.
AT END OF NAME.
SUM.
WRITE: / COMPANIES-NAME, COMPANIES-SALES.
ENDAT.
ENDLOOP.
The AT statements refer to the field COMPANIES-NAME.
Reward Points if it helps
Regards
Gunjan
‎2006 Jun 17 10:50 AM
ON CHANGE OF f.
Executes the processing block enclosed by the "ON CHANGE OF f" and "ENDON" statements whenever the contents of the field f change (control break processing).
Normally, you use the statement to manipulate database fields during GET events or SELECT/ENDSELECT processing.
ON CHANGE OF is unsuitable for recognizing control levels in loops of this type because it always creates a global auxiliary field which is used to check for changes. This global auxiliary field is only changed in the relevant ON CHANGE OF statement. It is not reset when the processing enters loops or subroutines, so unwanted effects can occur if the loop or subroutine is executed again. Also, since it is set to its initial value when created (like any other field), any ON CHANGE OF processing will be executed after the first test, unless the contents of the field concerned happen to be identical to the initial value.
DATA T100_WA TYPE T100.
SELECT * FROM T100
INTO T100_WA
WHERE SPRSL = SY-LANGU AND
MSGNR < '010'
ORDER BY PRIMARY KEY.
ON CHANGE OF T100_WA-ARBGB.
ULINE.
WRITE: / '**', T100_WA-ARBGB, '**'.
ENDON.
WRITE: / T100_WA-MSGNR, T100_WA-TEXT.
ENDSELECT.
Displays all messages with their numbers in the logon language, provided the number is less than '010'.
Each time the message class changes, it is output.
AT END OF f.
f is a sub-field of an internal table or extract dataset (EXTRACT) which is being processed with LOOP, i.e. the variants 1 and 2 only make sense within a LOOP.
Both "AT NEW f." and "AT END OF f. " introduce processing blocks which are concluded by " ENDAT.".
These processing blocks are processed whenever the contents of a field f or a sub-field defined before f change as a result of processing with LOOP. "AT NEW f." begins a new group of (table) lines with the same contents as the field f while "AT END OF f." concludes such a group.
Within the AT ... ENDAT processing of internal tables, all argument fields following f are filled with "*".
Examples
1. AT for sub-fields of an internal table
DATA: BEGIN OF COMPANIES OCCURS 20,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES.
...
LOOP AT COMPANIES.
AT NEW NAME.
NEW-PAGE.
WRITE / COMPANIES-NAME.
ENDAT.
WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.
AT END OF NAME.
SUM.
WRITE: / COMPANIES-NAME, COMPANIES-SALES.
ENDAT.
ENDLOOP.
The AT statements refer to the field COMPANIES-NAME.
Reward Points if it helps
Regards
Gunjan