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

onchange

Former Member
0 Likes
522

what is the difference between 'on change of' and 'at new' commands exactly at what situation they are used.its urgent please

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
503

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

2 REPLIES 2
Read only

Clemenss
Active Contributor
0 Likes
503

search forum first

Read only

Former Member
0 Likes
504

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