Saturday, February 2, 2013

ABAP-Object-Oriented-Event-Handling-and-Triggering

SAP Object Oriented ABAP Event Handling & Triggering, this post gives and idea about ABAP Event Handling and Triggering, dear ABAPers refer this post for Event Handling in OOABAP. It also consists of all interview based stuff ablut Event Handling. Clidk on read more to read this post.


ABAP-Object-Oriented-Event-Handling-and-Triggering 


SAP Object Oriented ABAP Event Handling & Triggering, this post gives and idea about ABAP Event Handling and Triggering, dear ABAPers refer this post for Event Handling in OOABAP. It also consists of all interview based stuff ablut Event Handling.


Event Handling:

Triggering and handling an event means that certain methods act as triggers and trigger events, to which other methods - the handlers - react. This means that the handler methods are executed when the event occurs.


Characteristics and uses:


  • Looses linkage than for a method call

  • Different communication model
¨      Trigger does not know the user

  • Important for GUI implementation

  • Conformity to other object models

¨      COM
¨      Activex Controls
¨      OpenDoc


Triggering Events To trigger an event, a class must

·         Declare the event in its declaration part
·         Trigger the event in one of its methods


Declaring Events

You declare events in the declaration part of a class or in an interface. To declare instance events, use the following statement:


EVENTS evt EXPORTING... VALUE(e1 e2 ...) TYPE type [OPTIONAL]..


To declare static events, use the following statement:

CLASS-EVENTS evt...


Both statements have the same syntax.


When you declare an event, you can use the EXPORTING addition to specify parameters that are passed to the event handler. The parameters are always passed by value.


Default Parameter of events:

Instance events always contain the implicit parameter SENDER, which has the type of a reference to the type or the interface in which the event is declared.


Triggering Events

An instance event in a class can be triggered by any instance method in the class. Static events can be triggered by any method. However, static methods can only trigger static events. To trigger an event in a method, use the following statement:


RAISE EVENT evt EXPORTING e1 = fe2 = f2 ...


Handling Events

Events are handled using special methods. To handle an event, a method must

·         be defined as an event handler method for that event

·         be registered at runtime for the event.


Declaring Event Handler Methods

Any class can contain event handler methods for events from other classes. You can, of course, also define event handler methods in the same class as the event itself. To declare an event handler method, use the following statement:


METHODS meth FOR EVENT evt OF cif IMPORTING e1 e2 ...


for an instance method. For a static method, use CLASS-METHODS instead of METHODS.


Registering Event Handler Methods for instance events:

To allow an event handler method to react to an event, you must determine at runtime the trigger to which it is to react. You can do this with the following statement:


SET HANDLER h1 h2 ... [FOR]...


It links a list of handler methods with corresponding trigger methods. There are four different types of event.


It can be


·         An instance event declared in a class

·         An instance event declared in an interface

·         A static event declared in a class

·         A static event declared in an interface


To trigger the event for all instances use the following syntax


SET HANDLER h1 h2 ... FOR ALL INSTANCES.


Registering event handler methods for static events:


Set handler h1 h2 .

            Here we don’t use ‘FOR’ clause because static events are independent of instances.


Deregistering Event handler methods:

            Set handler h for obj_ref activation ‘ ‘.

We can deregister an event handler method by specifying activation clause. Space indicates deregistration and ‘X’ indicates registration.


Timing of Event Handling

After the RAISE EVENTstatement, all registered handler methods are executed before the next statement is processed (synchronous event handling).

 If a handler method itself triggers events, its handler methods are executed before the original handler method continues. To avoid the possibility of endless recursion, events may currently only be nested 64 deep.


Note Points:


  • Events can be declared in interfaces

  • Garbage Collector will not delete registered objects even though registered objects do not have external references, because registration has the same effect as object referencing.

  • Exceptions cannot be propagated by event handling methods.

  • Event handling is sequential i.e., the sequence in which they are registered.

  • Events can be delcared as PUBLIC, PROTECTED, PRIVATE components of any class or interface.

  • An event handler method must have either the same or more restricted visibility than the event it refers to.

  • Events can be static or instance

  • Events can be triggered by any method in the class using the RAISE EVENT statement.

  • The parameter interface for events is limited to EXPORTING parameters.

  • Events don’t have implementation part.

  • Methods are only executed when the event associated with these methods are triggered.

  • An event can have multiple event handler method associate with it.



Dear ABAPers if you know any notes and interview questions related this Event Handling article please leave a comment on comment box.

"You found the information helpful and want to say thanks? Your donation is enough to inspire us to do more. Thanks a bunch!"

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Categories

ABAP (1) ABAP Interview Questions (112) ABAP Open SQL Statements (1) ABAP Syntax Rules (6) ABAP WORKBENCH (2) ABAP-Interview-Questions (52) ALE IDOC (6) ALE IDOC Interview Questions (6) ale-idoc (6) ALE-IDOC-Interview-Questions (19) ALV Interview Questions (5) ALV-Interview-Questions (22) BADI (2) BAPI (1) BAPI Interview Questions (1) BAPI-Interview-Questions (14) BDC (6) BDC Interview Questions (6) BDC-Interview-Questions (9) big data (2) big data interview questions (1) Classical Reports Interview Question (3) Classical-Reports-Interview-Questions (22) Conditional Statements (1) Cross Applications (3) Cross-Applications (14) Data Dictionary (22) Data Type Questins (1) Data types (1) Data-Dictionary (48) Data-Type-Questins (6) Dialog programming (5) Dialog Programming Interview Questions (4) Dialog-Programming (30) DOMAIN Interview Questions (1) Domain-Interview-Questions (8) Function Module (2) hadoop (2) hadoop interview questions (2) hdfs (1) IDoc Tutorials (6) Interactive Report Interview Questions (4) Interactive-Reports-Interview-Questions (22) Internal Tables (1) interview questions (1) Lock Object Interview Questions (1) Lock-Objects-Interview-Questions (10) Logical Database (1) Modularization Interview Questions (4) Modularization-Interview-Questions (25) Module Pool Programming (5) Module-Pool-Programming (39) modules in sap (1) Object Oriented ABAP (19) Object Oriented ABAP Interview Questions (15) object-oriented-abap (2) Object-Oriented-ABAP-Interview-Questions (34) OOABAP (9) Reports (14) Reports Interview Questions (9) Reports-Interview-Questions (19) RFC (1) RFC Interview Questions (1) RFC-Interview-Questions (14) RICEF (1) RICEF Objects (1) SAP (4) SAP ABAP (4) SAP ABAP Interview Questions (42) SAP ABAP Introduction (46) SAP ABAP Message Types (2) SAP BADI Interview Questions (2) SAP Basics (71) SAP Books (2) SAP Certification (1) SAP CONSULTANTS (5) SAP CRM (1) SAP ENHANCEMENTS (3) SAP EXITS (2) SAP EXITS ( SAP ENHANCEMENTS ) Interview Questions (1) SAP Free Books (1) SAP HR (2) SAP Lock Object (1) sap modules (2) SAP Open SQL Statements (1) SAP R/3 Architecture (4) SAP Search help (1) SAP Smartforms (1) SAP Smartforms Interview Questions (2) SAP Tables (5) SAP Tcodes (10) SAP Views (1) SAP Webdynpro ABAP (12) SAP Work Processors (2) SAP Workflow (3) SAP-BADI-Interview-Questions (11) SAP-Enhancements (39) SAP-Exits (39) SAP-Exits-Enhancements-Interview Questions (3) SAP-HANA (1) SAP-HANA-Interview-Questions (1) SAP-Smartforms-Interview-Questions (2) SAP-Workflow (3) Scripts (3) Scripts Interview Questions (2) Scripts-Interview-Questions (32) Search Help Interview Questions (1) Search-Help-Interview-Questions (9) Smartforms (1) Table Maintenance Generator (1) Table-Maintenance-Generator (4) Tables in SAP (2) Tables Interview Questions (3) Tables-Interview-Questions (3) Type Group Interview Questions (1) Type-Group-Interview-Questions (7) Variable Declaration (1) Views Interview Questions (1) Views-Interview-Questions (5) Webdynpro (12) what is big data (1)

Protected Blog

 
This blog is not affiliated to SAP AG |SAP is trademark of SAP AG |The information collected from various sources use information with your own risk.