Get Example source ABAP code based on a different SAP table
• FOR METHODS FOR • METHODS METHODS FOR • CHANGING METHODS FOR • IMPORTING METHODS FOR • FINAL METHODS FOR
METHODS>, FOR>, RAP Handler Methods
ABAP_SYNTAX 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>.>
What does it do? 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:
Nearly all parameters are typed with BDEF derived types> that have RAP components>. The parameters' names can be chosen freely.
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.> For the explicit declaration of the changing parameters, 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.
Latest notes:
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(<(><)>). ... APPEND VALUE #( %key = <(><)>-%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 = <(><)>-%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. NON_V5_HINTS
Obsolete language elements in the context of handler methods:
Addition FOR BEHAVIOR >> for the variants READ>, MODIFY> and LOCK>.
METHODS, FOR DETERMINATION, VALIDATION>> ABAP_HINT_END
ABAP_EXAMPLE_VX5 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 MODIFY 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. ...> ABAP_EXAMPLE_END
ABAP_EXAMPLES_ABEXA
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. ABAP_EXAMPLE_END