Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Calling and leaving program units →  Calling Processing Blocks →  Calling Procedures →  Method Calls →  Static Method Calls 

meth( ... ) - Parameter Passing

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


... [EXPORTING  p1 = a1 p2 = a2 ...] 
    [IMPORTING  p1 = a1 p2 = a2 ...]
    [CHANGING   p1 = a1 p2 = a2 ...]
    [RECEIVING  r  = a  ]
    [EXCEPTIONS [exc1 = n1 exc2 = n2 ...]
                [OTHERS = n_others] ].

Extras

1. ... EXPORTING p1 = a1 p2 = a2 ...

2. ... IMPORTING p1 = a1 p2 = a2 ...

3. ... CHANGING p1 = a1 p2 = a2 ...

4. ... RECEIVING r = a

5. ... EXCEPTIONS exc1 = n1 exc2 = n2 ... [OTHERS = n_others]

Effect

With the exception of the addition EXCEPTIONS, these additions assign actual parameters a1 a2... to the formal parameters p1 p2 ... or r of the parameter interface of the called method. Any data objects (and some expressions) can be specified as actual parameters if they have a data type that matches the typing of the corresponding formal parameter in accordance with the rules of the typing check.

With the exception of the return code r for functional methods and arithmetic expressions for input parameters, every formal parameter assumes all attributes of the assigned actual parameters when called. Non-class-based exceptions can be handled using the addition EXCEPTIONS. The order of the additions is fixed.


Notes

Addition 1

... EXPORTING p1 = a1 p2 = a2 ...

Effect

This addition assigns actual parameters to the input parameters of the called method. EXPORTING can be used to assign actual parameters to the optional input parameters. It must be used to assign actual parameters to the non-optional input parameters. If pass by reference is used, a reference to an actual parameter is passed when the call is made. If pass by value is used, the content of an actual parameter is assigned to the corresponding formal parameter.

a1, a2, ... are general expression positions, which means that, alongside data objects, functions and expressions can also be passed as actual parameters. Special rules apply in this case.


Notes

  • Substring access is not possible after an actual parameter of type string or xstring specified after EXPORTING.
  • The addition EXPORTING can be omitted in the short form of the static method call.

Example

Calls of a method with passing of actual parameters to input parameters. The first call is the syntax short form of the second call. Both work in the same way.

cl_demo_output=>display_data( name  = 'Some text' 
                             value = 'blah, blah ...' ). 

cl_demo_output=>display_data( EXPORTING name  = 'Some text' 
                                      value = 'blah, blah ...' ). 

Addition 2

... IMPORTING p1 = a1 p2 = a2 ...

Effect

This addition assigns actual parameters to the output parameters of the called method. IMPORTING can be used to assign actual parameters to all output parameters, but this is not mandatory. If pass by reference is used, a reference is passed to an actual parameter when the call is made. If pass by value is used, the content of an output parameter is assigned to the actual parameter in question only if the method is completed without errors.

The actual parameters are result positions, which means that variables and writable expressions can be specified. Special rules apply in this case.

  • Existing variables or writable expressions can be specified as actual parameters for functional method calls. Inline declarations, however, cannot be specified.
  • Inline declarations DATA(var) can also be specified for standalone method calls. If an inline declaration is specified and a formal parameter is fully typed, this type is used for the declaration. If the formal parameter is typed generically, the following data types are used:
  • string for csequence and clike
  • xstring for xsequence
  • decfloat34 for numeric and decfloat
  • p with the length 8 and no decimal places if p is generic
  • The standard key for a standard table type with a generic primary table key

Other generic data types cannot be made non-generic for inline declarations in any meaningful way and produce a syntax error.


Notes

  • If a formal parameter is typed with the generic type c or x, for example, string or xstring cannot be used as the type for an inline declaration, since this means the typing cannot be checked.
  • Functional method calls are located on the right side of assignments or are part of expressions where no inline declarations are possible.

Example

The method GET_DOCU of the class CL_ABAP_DOCU_ITF has two input parameters and two output parameters, plus a return value that indicates whether the method was executed successfully. Functionally, the method is called as an operand of a comparison expression in a logical expression. The values in the output are reused in further method calls only if the method completed successfully.

DATA: itf  TYPE tline_tab, 
      head TYPE thead. 

IF cl_abap_docu_itf=>get_docu( 
     EXPORTING langu = sy-langu 
               object = 'ABENABAP' 
     IMPORTING itf  = itf 
               head = head ) = 0. 
  cl_abap_docu_itf=>get_docu_includes( 
     EXPORTING head = head 
     CHANGING  itf  = itf ). 
ENDIF. 

Addition 3

... CHANGING p1 = a1 p2 = a2 ...

Effect

This addition assigns actual parameters to the input/output parameters of the called method. CHANGING can be used to assign actual parameters to the optional input/output parameters. It must be used to assign actual parameters to the non-optional input/output parameters. If pass by reference is used, a reference to an actual parameter is passed when the call is made. If pass by value is used, the content of an actual parameter is assigned to the corresponding formal parameter. In pass by value, the modified content of an input/output parameter is assigned to the actual parameter in question only if the method is completed without errors.

The actual parameters are result positions, which means that variables and writable expressions can be specified. Special rules apply in this case.


Example

Calls a method with an input/output parameter.

DATA(text) = `...`. 
cl_demo_input=>request( CHANGING field = text ). 

Addition 4

... RECEIVING r = a

Effect

This addition assigns an actual parameter to the return value of the called method. This addition is only possible for standalone method calls and not for functional method calls. An actual parameter can be assigned to the return value of a functional method using RECEIVING. The data type of the actual parameter does not have to comply with the general rules of the typing check and it is sufficient if the return value can be converted to the actual parameter in accordance with the conversion rules.

If the method ends without errors, the content of the formal parameter is assigned to the actual parameter. The content is converted if necessary. If an exception is raised here, it cannot be handled and a runtime error always occurs.

The actual parameter is a result position, which means that variables and writable expressions can be specified. Special rules apply in this case.

An existing variable or expression or an inline declaration DATA(var) can be specified as an actual parameter. An inline declaration is made as soon as the data type of the return value is known in full.


Note

The addition RECEIVING is not usually used for static method calls. A functional method with a return code is not usually called as a standalone method call and is usually called as a functional method call in operand positions instead.


Example

Calls of a functional method with return value. The first call is the usual functional method call. The second call demonstrates the unusual use of the addition RECEIVING. The result is the same in both cases.

DATA html type string. 

html = cl_demo_output=>get( 'blah, blah ...' ). 

cl_demo_output=>get( EXPORTING data   = 'blah, blah ...' 
                     RECEIVING output = html ). 

Addition 5

... EXCEPTIONS exc1 = n1 exc2 = n2 ... [OTHERS =n_others]

Effect

This addition is only possible for standalone method calls and not for functional method calls.

EXCEPTIONS can be used to assign return codes to non-class-based exceptions exc1 exc2 ... declared in the parameter interface. Each exception exc1 exc2 ... that the caller wants to handle must be assigned to a directly specified number n1 n2 ... All numbers between 0 and 65535 can be specified. The behavior outside of this range is undefined.

OTHERS can be specified as the last entry after EXCEPTIONS to assign a common return code to all exceptions not specified explicitly in exc1 exc2.... This is done by assigning a number n_others. The same return code can be assigned to different exceptions (including OTHERS). The behavior when an exception is raised is as follows:

  • If the statement RAISE or MESSAGE RAISING is used to raise an exception exc1 exc2 ... (to which a return code is assigned), the statement is ended immediately, any procedure parameters passed by value are not filled, and the number n1 n2 ... assigned to the exception is available to be evaluated in sy-subrc .
  • If the call of an exception raised by RAISE does not assign a return code, the program terminates with a runtime error.
  • If the call of an exception raised by MESSAGE RAISING does not assign a return code, the message is sent and the system resumes in accordance with the message type.

If no exception is raised, a call sets sy-subrc to 0.

The addition EXCEPTIONS cannot be specified in the call if RAISING is used to declare class-based exceptions in the parameter interface of the called procedure. The specified exceptions must be present in the parameter interface of the method.


Notes

  • If the value 0 is assigned to an exception, this indicates that the caller wants to ignore this exception. If the exception is raised in the method, no runtime error occurs, but the exception cannot be handled.
  • Information about the behavior of class-based exceptions in methods can be found in Class-Based Exceptions in Procedures.

Example

Handles non-class-based exceptions in a method call.

cl_gui_frontend_services=>directory_exist( 
  EXPORTING 
    directory            =  '...' 
  RECEIVING 
    result               =     DATA(flag) 
  EXCEPTIONS 
    cntl_error           = 1 
    error_no_gui         = 2 
    wrong_parameter      = 3 
    not_supported_by_gui = 4 
    OTHERS               = 5 ). 
IF sy-subrc <> 0. 
  CASE sy-subrc. 
    WHEN 1. 
      ... 
    ... 
  ENDCASE. 
ENDIF.