Monday, February 7, 2011

Event Handler Technique in Object oriented ABAP

Event is a mechanism by which method of one class can raise method of another class, without the hazard of instantiating that class. It provides to raise the method (event handler method) of one class with help of another method in the same or different class (triggering method).

The below steps is required to have the event handler in the class:-

  • Create an event in a class.

  • Create a triggering method in the same class which will raise the event.

  • Create an event handler method for the event in same/other class.

  • Register the event handler method in the program.

Now, the above settings are complete for event handler in class. Create an object from the class containing the event and call the triggering method to raise the event.

By taking the above steps, the following sample examples will demonstrate the event handler technique in Class.

1. Events with Handler Method in the same class.

This example tells that how to raise method, if the triggering method and event handler method presents in the same class.

Sample code and Output.

Next->

Output.



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.




No comments:

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive

goodsites