Different ways to call methods in ABAP

Ulrich Scholz picture Ulrich Scholz · Feb 5, 2015 · Viewed 39.3k times · Source

Sorry for this basic ABAP question. What are the different ways to call methods in ABAP? And what are their "official" names? I've heard of perform, method call, and internal/inline method call.

Perform uses the PERFORM keyword and method call the CALL METHOD syntax, I guess. But what is an "internal" or "inline method call"?

Answer

Jagger picture Jagger · Feb 6, 2015

These are the possibilities of an inline method call.

If you are calling so called functional method which has only IMPORTING parameters and optionally one RETURN parameter you can call it like this.

CLASS lcl_test DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      func_meth
        IMPORTING
          i_param TYPE i
        RETURNING
          VALUE(r_res) TYPE char1.
ENDCLASS.

l_res = lcl_test=>func_meth( 1 ).

* you could also call it like this
l_res = lcl_test=>func_meth( i_param = 1 ).

* also this variant is possible
l_res = lcl_test=>func_meth( EXPORTING i_param = 1 ).

* the traditional CALL METHOD syntax would be like this
CALL METHOD lcl_test=>func_meth
  EXPORTING
    i_param = 1
  RECEIVING
    r_res = l_res.

If there is more than one IMPORTING parameter you have to specify names of the parameters.

CLASS lcl_test DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      func_meth
        IMPORTING
          i_param1 TYPE i
          i_param2 TYPE i
        RETURNING
          VALUE(r_res) TYPE char1.
ENDCLASS.

l_res = lcl_test=>func_meth(
   i_param1 = 1
   i_param2 = 2
).

If there are EXPORTING or CHANGING parameters in the method then an inline call is still possible but the parameter categories have to be explicitly specified.

CLASS lcl_test DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      func_meth
        IMPORTING
          i_param TYPE i
        EXPORTING
          e_param TYPE c
        CHANGING
          c_param TYPE n.
ENDCLASS.

lcl_test=>func_meth(
  EXPORTING
    i_param = 1
  IMPORTING
    e_param = l_param
  CHANGING
    c_param = l_paramc
).