Ansicht
Dokumentation

ABAPMETHODS_FOR_RAP_BEHV - METHODS FOR RAP BEHV

ABAPMETHODS_FOR_RAP_BEHV - METHODS FOR RAP BEHV

SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up   ROGBILLS - Synchronize billing plans  
This documentation is copyright by SAP AG.
SAP E-Book

METHODS, FOR

Handler method definitions:

METHODS meth $[FINAL$]
   FOR ${ DETERMINE ON ${ SAVE $| MODIFY $} ... $[IMPORTING$] ... FOR ... $}
     $| ${ GLOBAL AUTHORIZATION  ...  $[IMPORTING$] ... FOR ... $}
     $| ${ GLOBAL FEATURES ... $[IMPORTING$] ... FOR ... $}
     $| ${ $[INSTANCE$] AUTHORIZATION ... $[IMPORTING$] ... FOR ... $}
     $| ${ $[INSTANCE$] FEATURES ... $[IMPORTING$] ... FOR ... $}
     $| ${ LOCK ... $[IMPORTING$] ... FOR ... $}
     $| ${ MODIFY ... $[IMPORTING$] ... FOR ... $}
     $| ${ NUMBERING ... $[IMPORTING$] ... FOR ... $}
     $| ${ PRECHECK ... $[IMPORTING$] ... FOR ...  $}
     $| ${ READ ... $[IMPORTING$] ... FOR ... $}
     $| ${ VALIDATE ON SAVE ... $[IMPORTING$] ... FOR ... $}
   $[CHANGING ${ $[ failed TYPE data$] $[reported TYPE data$] $[mapped TYPE data$] $}$].


Handler method implementations:

METHOD meth.
   ...
ENDMETHOD.


Effect

Handler methods must be defined and implemented in a handler class of an ABAP behavior pool. The method name (meth) can be freely chosen except for the predefined draft actions (whose implementation is only relevant if they are specified with with additional implementation in the BDEF) and the method names in the context of augment operations. The METHODS statements of handler methods in behavior pools contain RAP-specific ABAP words like FOR MODIFY, FOR CREATE or FOR READ as well as optional or mandatory ABAP words like REQUEST and RESULT that are followed by parameters typed with BDEF derived types.

The following list provides an overview on parameters of handler methods:

  • Each handler method must have at least one importing parameter. The addition IMPORTING is optional since it is used implicitly.
  • All handler methods have changing parameters. The changing parameters for retrieving mapping information (mapped) or information on failures (failed) and error messages (reported) have predefined names and are used implicitly. The addition CHANGING and the explicit specification of those changing parameters is optional. The availability of the mapped, failed and reported parameters depends on the handler method used. When used explicitly, for example, for the method ... FOR MODIFY ... FOR CREATE ..., the syntax can be as follows:
METHODS create FOR MODIFY
    IMPORTING entities FOR CREATE bdef
    CHANGING failed TYPE DATA mapped TYPE DATA reported TYPE DATA.
In the above code example, the generic type DATA is used. At runtime, the typed parameters, e. g. failed, implicitly has the BDEF derived type TYPE RESPONSE FOR.
  • In many cases, parameters can be passed by reference (see REFERENCE), however, they cannot be passed by value (VALUE). Hence, the importing parameters cannot be changed in the methods.

At least one of the three methods with the predefined names MODIFY, READ and LOCK must be implemented in each handler class. Apart from that, helper methods can be implemented.

Notes

  • Obsolete language elements in the context of handler methods:
  • Addition FOR BEHAVIOR for the variants READ, MODIFY and LOCK.

  • It is recommended that the CHANGING parameters failed, reported and mapped are filled with returned information, for example, if an instance cannot be read. The components of each of the CHANGING parameters can vary depending on how it is typed with a BDEF derived type. Here is an example on how a CHANGING parameter can be filled within the method implementation:
LOOP AT import_params ASSIGNING FIELD-SYMBOL(<fs>).
...
  APPEND VALUE #( %key = <fs>-%key
                  %fail = if_abap_behv=>cause-not_found
                  ... ) TO failed-bdef.
  APPEND VALUE #( %msg  = new_message_with_text(
                     severity = if_abap_behv_message=>severity-error
                     text = 'Issue occurred.'
                     %key = <fs>-%key
                  ... ) TO reported-bdef.
ENDLOOP.
  • In some cases, the F2 help of the ADT shows further CHANGING parameters for RAP handler methods apart from failed, reported and mapped. RESULT is a RAP-specific ABAP word that must be explicitly specified. Hence, the CHANGING parameter result cannot be specified using the ABAP word CHANGING:
METHODS read FOR READ IMPORTING keys FOR READ bdef RESULT result.
Similarly, the IMPORTING parameter requested_field must be specified in combination with the ABAP word REQUEST in the handler method definition.
  • The handler method FOR MODIFY can handle multiple entities and operations within one processing step. However, it might be useful to split the handler method implementation into separate methods in the interest of readability and keeping the complexity on a lower level. In doing so, multiple RAP handler classes within one ABP or multiple ABPs can be defined. The following handler method definition demonstrates a handler method FOR MODIFY that includes multiple operations:
METHODS modify_meth FOR MODIFY IMPORTING
   create_imp_param FOR CREATE bdef
   update_imp_param FOR UPDATE bdef
   delete_imp_param FOR DELETE bdef
   action_imp_param FOR ACTION bdef~action
   cba_imp_param FOR CREATE bdef\_assoc.
  • Exceptions cannot be raised in handler methods, hence, the addition RAISING cannot be used.

Example

The following code snippet shows several handler method definitions. The method create includes an explicit specification of the CHANGING keyword and the parameters for the information retrieval.

METHODS create FOR MODIFY
    IMPORTING entities FOR CREATE demo_bdef
    CHANGING failed TYPE DATA mapped TYPE DATA reported TYPE DATA.


METHODS cba_child FOR MODIFY
    IMPORTING entities_cba FOR CREATE demo_bdef\_assoc.


METHODS update FOR MODIFY
    IMPORTING entities FOR UPDATE demo_bdef.


METHODS delete FOR MODIF
    IMPORTING keys FOR DELETE demo_bdef.


METHODS read FOR READ
    IMPORTING keys FOR READ demo_bdef RESULT result.


METHODS rba_child FOR READ
    IMPORTING keys_rba FOR READ demo_bdef\_child
    FULL result_requested RESULT result LINK association_links.

  • The example Example for RAP Handler Methods demonstrates RAP handler methods within a RAP handler class using a simple unmanaged RAP BO that is draft-enabled.
  • The example ABAP EML - MODIFY AUGMENTING ENTITY demonstrates the three handler methods augment_create, augment_update and augment_cba_assoc (assoc refers to the name of the association) with a RAP projection business object.





PERFORM Short Reference   BAL Application Log Documentation  
This documentation is copyright by SAP AG.

Length: 13412 Date: 20240329 Time: 114005     sap01-206 ( 157 ms )