Tuesday 13 September 2016

Global Class : Events

Ex :-


Steps

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

  • Go to transaction code SE24.
  • Enter the class name start's with ZCL_<class name > and click on Create.



  • Pop-up will appear.
  • Enter the short description and click on SAVE.
  • Save it in either Package or Local Package.

  • Create a Event triggering method.
  • To pass parameters , Click on method name and click on Parameters.
  • Pass the parameters.



  • Click on Save and click on BACK button.
  • Double Click on Method name.

  • Enter the source code.





  • " RAISE EVENT " command is used to trigger the Event.
  • Copy the Event name.
  • Click on Save and click on Back button.

2.Create an event .

  • Click on Events Tab.

  • Enter the Event name ,  Type and Visibility of the Event.
  • Click on Methods Tab.

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

  • Enter the event handler method name , Type and Visibility.
  • Select the event handler name and click on " Detail View ".

  • Pop-up will appear.
  • Click on " Event Handler for ".
  • Enter the Class name and Event name.
  • Click on Change.



  • Looks like,
  • To implement the event handler method , double click on event handler method and enter the source code.




  • Save and click on Back button.
  • Create a method to display data.
  • To Pass the parameters, click on method name and click on Parameters.

  • Pass the parameters.


  • Click on Save and click on BACK button.
  • To implement the method , double click on method name.

  • Source code.
  • Save 
  • Click on BACK.
  • Save -> Check -> Activate.



  • Copy the Class name.

Main Program

  • Go to Transaction code SE38.

  • Enter the program name which start's with Y or Z < program name > and click on Create.
  • Pop-up will appear.
  • Enter the Title.
  • Select the Attribute Type as Executable Program.
  • Click on Save.


  • Source Code.


DATA : OBJ TYPE REF TO ZCL_EVENT_CLASS.

DATA : IT_VBRP TYPE TABLE OF VBRP.

PARAMETERS : P_VBELN TYPE VBRP-VBELN.

START-OF-SELECTION.

CREATE OBJECT OBJ.

"4. Register the event handler method in the program.


SET HANDLER OBJ->EVENT_HANDLER FOR OBJ.

CALL METHOD OBJ->FECT_DATA
  EXPORTING
    IM_VBELN = P_VBELN
  CHANGING
    CH_ITAB  = IT_VBRP
    .

CALL METHOD OBJ->DISPLAY
  EXPORTING
    CH_ITAB = IT_VBRP
    .

  • Save -> Check -> Activated.
  • Execute ( F8 ).


Input -1 .

  • Click on Execute without entering input value.

Output


Input - 2

  • Enter the input.

Output

  • Click on Execute.


No comments:

Post a Comment