ON CHANGE OF triggers when there is any change of the first occurrence of mentioned fields’ value.
It means it actually works like AT NEW statement. If there is any change of the value of the mentioned
field then ON CHANGE OF will trigger. At the time of triggering all of other fields contain their respective
data. Hence it doesn’t go for *** value at the time of triggering. ON CHANGE OF can be used outside
the loop also.
REPORT zctrlbrk_on_change NO STANDARD PAGE HEADING.
TYPES: BEGIN OF ty_tab,
werks TYPE mard-werks,
matnr TYPE mard-matnr,
lgort TYPE mard-lgort,
END OF ty_tab.
DATA: wtab TYPE ty_tab,
itab TYPE TABLE OF ty_tab.
START-OF-SELECTION.
SELECT matnr werks lgort
UP TO 25 ROWS FROM mard
INTO CORRESPONDING FIELDS OF TABLE itab.
IF sy-subrc = 0.
SORT itab BY werks.
WRITE: / 'Material', 20 'Plant', 27 'Storage Location'.
ULINE.
LOOP AT itab INTO wtab.
WRITE: / wtab-matnr, 20 wtab-werks, 27 wtab-lgort.
ON CHANGE OF wtab-werks.
WRITE: '=== On Change Of triggers at plant - ', wtab-werks.
ENDON.
ENDLOOP.
ENDIF.
TYPES: BEGIN OF ty_tab,
werks TYPE mard-werks,
matnr TYPE mard-matnr,
lgort TYPE mard-lgort,
END OF ty_tab.
DATA: wtab TYPE ty_tab,
itab TYPE TABLE OF ty_tab.
START-OF-SELECTION.
SELECT matnr werks lgort
UP TO 25 ROWS FROM mard
INTO CORRESPONDING FIELDS OF TABLE itab.
IF sy-subrc = 0.
SORT itab BY werks.
WRITE: / 'Material', 20 'Plant', 27 'Storage Location'.
ULINE.
LOOP AT itab INTO wtab.
WRITE: / wtab-matnr, 20 wtab-werks, 27 wtab-lgort.
ON CHANGE OF wtab-werks.
WRITE: '=== On Change Of triggers at plant - ', wtab-werks.
ENDON.
ENDLOOP.
ENDIF.
Now at debugging level we can see as follows. At first loop iteration system will definitely triggers the
ON CHANGE OF statement because the plant data is new. All other fields contain their respective data
at the time of triggering.
After that the system triggers AT LAST statement at the last loop iteration when SY-TABIX = 25.
Previously the values of work area are also ***.
output is
No comments:
Post a Comment