问题描述
抱歉这个基本的 ABAP 问题.在ABAP中调用方法有哪些不同的方式?他们的官方"名称是什么?我听说过执行、方法调用和内部/内联方法调用.
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 使用 PERFORM
关键字和方法调用 CALL METHOD
语法,我猜.但什么是内部"或内联方法调用"?
Perform uses the PERFORM
keyword and method call the CALL METHOD
syntax, I guess. But what is an "internal" or "inline method call"?
推荐答案
这些是内联方法调用的可能性.
These are the possibilities of an inline method call.
如果您正在调用只有 IMPORTING
参数和可选的一个 RETURN
参数的所谓函数式方法,您可以像这样调用它.
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.
如果有多个 IMPORTING
参数,您必须指定参数名称.
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
).
如果方法中有 EXPORTING
或 CHANGING
参数,则仍然可以进行内联调用,但必须明确指定参数类别.
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
).
这篇关于ABAP中调用方法的不同方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!