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"?
The redundant ABAP words CALL METHOD provide no additional information to the reader. Using the short form, self-contained method calls have the same appearance as functional method calls on operand positions. For dynamic method calls, the long form with CALL METHOD is required by the syntax.
In the dynamic method call, the parameters are not passed in parentheses. The syntax of the dynamic method call is like that of a function module call. The CALL_METHOD statement should now only be used for the dynamic method call. It is unnecessary, and therefore obsolete, for the static method call.
Method Calls A method is a routine that applies to a particular class of objects. Once an object is declared, you can refer to it by its identifier when calling methods.
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
).
Good luck in your quest - you will find this task to be much harder than anticipated. For example, ABAP contains a macro processing facility that will make it really hard to find out that an actual method call is taking place. A malicious example that will compile nonetheless:
DATA: l_foo TYPE c LENGTH 32.
DEFINE foo.
l_&4 = cl_&1_&3&5&2&9if_&1_&3&5_&8~&7_&3&5_c&6( ).
END-OF-DEFINITION.
foo system = u foo uid 32 create static >.
You will find that macros are used extensively in some parts of the system. Good luck finding method calls in that kind of stuff without using the built-in parser and macro processor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With