I would like to explain about Working with Events in Global Class” .
Go to Class Builder “SE24”.
Provide class name.
Press create button.
Save it.
Go to event tab.
Then provide event method.
Provide parameters also for this method.
Save it.
Then go to methods option.
We wouldn’t be able to write any code in the events directly.
For this we can create another method in the method tab.
Then provide link between method and also the event method.
Then we can click on this detail view button.
Then enable the event handler for check box.
Provide the class name and also the event name.
Save & activate. Following screen appears:
Now select the method.
And also copy the parameters of the event method.
By pressing this copy event parameter we can get the parameters.
Save and go back to the earlier screen..
Then double click on the method name.
Then provide the following logic for triggering the event.
METHOD METHOD_EVENT .
*check the condition
IF S_LIFNR_LOW <> 2000.
MESSAGE I000(0) WITH 'enter the values between 1000 and 2000'.
RAISE EVENT ZEVENT_METHOD.
ENDIF.
*provide select statement
SELECT *
FROM LFA1
INTO TABLE IT_LFA1
WHERE LIFNR BETWEEN S_LIFNR_LOW AND S_LIFNR_HIGH.
*transfer the values to another internal table
IT_LFA11 = IT_LFA1.
ENDMETHOD.
After that provide the logic in se38.
REPORT ZCL_EVENT_OPERATION .
*provide data objects
DATA: LFA1 TYPE LFA1,
OBJ TYPE REF TO ZCL_EVENT_OPERATION,
IT_LFA1 TYPE Z_LFA1,
IT_LFA11 TYPE Z_LFA1,
WA_LFA1 TYPE LFA1.
*provide select statement
SELECT-OPTIONS: S_LIFNR FOR LFA1-LIFNR.
*provide create object
START-OF-SELECTION.
CREATE OBJECT OBJ.
*call the method
CALL METHOD OBJ->METHOD_EVENT
EXPORTING
S_LIFNR_LOW = S_LIFNR-LOW
S_LIFNR_HIGH = S_LIFNR-HIGH
IT_LFA1 = IT_LFA1.
*provide attribute value
IT_LFA11 = OBJ->IT_LFA11.
*display the data
LOOP AT IT_LFA11 INTO WA_LFA1.
WRITE:/ WA_LFA1-LIFNR,
WA_LFA1-LAND1,
WA_LFA1-NAME1,
WA_LFA1-ORT01.
ENDLOOP.
Save it, check it, activate it and execute it.
Then the output is like this.
If lifnr value is <1000>2000.
Then press execute it.
The output is like this.
Then press enter.
The output is like this.