在ABAP中调用方法的不同方法 [英] Different ways to call methods in ABAP

查看:692
本文介绍了在ABAP中调用方法的不同方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉,这个基本的ABAP问题。在ABAP中调用方法有哪些不同的方法?他们的正式名字是什么?我听说过执行,方法调用和内部/内联方法调用。



Perform使用 PERFORM 关键字我猜方法调用 CALL METHOD 语法。但是什么是内部或内联方法调用?

解决方案

这些是内联方法调用的可能性。 / p>

如果要调用所谓的函数方法,该方法仅具有 IMPORTING 参数和一个可选的 RETURN 参数,您可以这样称呼它。

  CLASS lcl_test定义。 
公共部分。
类方法:
func_meth
导入
i_param类型i
返回
值(r_res)类型char1。
ENDCLASS。

l_res = lcl_test => func_meth(1)。

*您也可以这样称呼它
l_res = lcl_test => func_meth(i_param = 1)。

*也可以使用此变体
l_res = lcl_test => func_meth(EXPORTING i_param = 1)。

*传统的CALL METHOD语法如下:
CALL METHOD lcl_test => func_meth
导出
i_param = 1
接收
r_res = l_res。

如果有多个 IMPORTING 参数您必须指定参数的名称。

  CLASS lcl_test定义。 
公共部分。
类方法:
func_meth
导入
i_param1类型i
i_param2类型i
返回
VALUE(r_res)类型char1。
ENDCLASS。

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

如果有出口 CHANGING 参数,然后仍然可以进行内联调用,但必须明确指定参数类别。

  CLASS lcl_test定义。 
公共部分。
类方法:
func_meth
导入
i_param类型i
导出
e_param类型c
更改
c_param类型n。
ENDCLASS。

lcl_test => func_meth(
汇出
i_param = 1
汇入
e_param = l_param
变更
c_param = l_paramc
)。


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"?

解决方案

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
).

这篇关于在ABAP中调用方法的不同方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆