‎2007 Jul 15 1:49 PM
what is the difference between 'on change of' and 'at new' commands exactly at what situation they are used.its urgent please
‎2007 Jul 15 2:21 PM
Hi,
<b>ON CHANGE OF:</b>
I see this error in programs quite often. The problem is that using ON CHANGE OF does seem to work in loop processing, so many people get in the habit of using it. However, it only works the first time the code is used, and on the second pass you may get unexpected results. Look at the code sample below.
DATA: ITAB LIKE MARA OCCURS 10 WITH HEADER LINE.
ITAB-MATNR = '5'. APPEND ITAB.
ITAB-MATNR = '6'. APPEND ITAB.
PERFORM PRINT_ITAB.
REFRESH ITAB.
ITAB-MATNR = '6'. APPEND ITAB.
ITAB-MATNR = '7'. APPEND ITAB.
PERFORM PRINT_ITAB.
FORM PRINT_ITAB.
ON CHANGE OF MATNR.
WRITE: ITAB-MATNR.
ENDON.
ENDFORM
Those of you who guessed that the output would be "5 6 6 7" are wrong! The actual output is simply "5 6 7." What happens during the ON CHANGE OF is that SAP holds the contents of the last ON CHANGE OF variable in memory, and this does not get refreshed or cleared during loop processing. For this reason you should avoid using ON CHANGE OF when processing loops.
Another area to look out for in control statements for loop processing is the use of AT. Do not use this statement when using the loop additions FROM, TO, and WHERE. New programmers out there should remember that AT NEW compares the structure for anything that has changed starting at the left hand side of the structure all the way to the field that you are specifying.
<b>AT NEW:</b>
you can use the AT statement within a loop to program statement blocks that the system processes only at a control break, that is, when the control level changes.
AT NEW <f> .
WRITE:/ ........
ENDAT.A control break occurs when the value of the field <f> or a superior field in the current record has a different value from the previous record (AT NEW) or the subsequent record (AT END). Field <f> must be part of the HEADER field group.
for more information follow this link.
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb381a358411d1829f0000e829fbfe/content.htm
regards,
Ashok Reddy
‎2007 Jul 15 2:10 PM
‎2007 Jul 15 2:21 PM
Hi,
<b>ON CHANGE OF:</b>
I see this error in programs quite often. The problem is that using ON CHANGE OF does seem to work in loop processing, so many people get in the habit of using it. However, it only works the first time the code is used, and on the second pass you may get unexpected results. Look at the code sample below.
DATA: ITAB LIKE MARA OCCURS 10 WITH HEADER LINE.
ITAB-MATNR = '5'. APPEND ITAB.
ITAB-MATNR = '6'. APPEND ITAB.
PERFORM PRINT_ITAB.
REFRESH ITAB.
ITAB-MATNR = '6'. APPEND ITAB.
ITAB-MATNR = '7'. APPEND ITAB.
PERFORM PRINT_ITAB.
FORM PRINT_ITAB.
ON CHANGE OF MATNR.
WRITE: ITAB-MATNR.
ENDON.
ENDFORM
Those of you who guessed that the output would be "5 6 6 7" are wrong! The actual output is simply "5 6 7." What happens during the ON CHANGE OF is that SAP holds the contents of the last ON CHANGE OF variable in memory, and this does not get refreshed or cleared during loop processing. For this reason you should avoid using ON CHANGE OF when processing loops.
Another area to look out for in control statements for loop processing is the use of AT. Do not use this statement when using the loop additions FROM, TO, and WHERE. New programmers out there should remember that AT NEW compares the structure for anything that has changed starting at the left hand side of the structure all the way to the field that you are specifying.
<b>AT NEW:</b>
you can use the AT statement within a loop to program statement blocks that the system processes only at a control break, that is, when the control level changes.
AT NEW <f> .
WRITE:/ ........
ENDAT.A control break occurs when the value of the field <f> or a superior field in the current record has a different value from the previous record (AT NEW) or the subsequent record (AT END). Field <f> must be part of the HEADER field group.
for more information follow this link.
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb381a358411d1829f0000e829fbfe/content.htm
regards,
Ashok Reddy