ABAP中的导入和导出参数概念与继承的概念是否相同或类似?

huangapple go评论60阅读模式
英文:

Is the concept of IMPORTING and EXPORTING parameters in ABAP the same or similar to the concept of inheritance

问题

I want to understand the concept of Importing, Exporting and Changing parameters in ABAP, because I have never met them before. To my understanding you can pass down values of parameters from one method to another using Importing, Exporting and Changing keywords.

The concept of inheritance for classes and methods is clear to me. But it seems to me that there are some parallels between those two concepts?

Suppose I call method B from method A and I use Exporting to pass to method B a parameter value from method A. Is that „inheritance“? Is it correct to say that the method B inherited a parameter value from the method A?

英文:

I want to understand the concept of Importing, Exporting and Changing parameters in ABAP, because I have never met them before. To my understanding you can pass down values of parameters from one method to another using Importing, Exporting and Changing keywords.

The concept of inheritance for classes and methods is clear to me. But it seems to me that there are some parallels between those two concepts?

Suppose I call method B from method A and I use Exporting to pass to method B a parameter value from method A. Is that „inheritance“? Is it correct to say that the method B inherited a parameter value from the method A?

答案1

得分: 2

继承的概念与方法参数无关。

继承允许您从现有类中派生新类,新类(子类)继承现有类(超类)的所有组件。

方法参数定义了方法的“接口”,即该方法应该如何从外部世界使用,即它期望作为输入接受什么数据并返回什么结果。 方法是包含在类内部的函数/过程的名称,方法名称与其参数一起称为“方法签名”。

您可以从任何类的任何方法中调用任何类的任何方法,从其他类型的程序、函数模块等,只要形式上允许(即可见性规则允许此调用,对于实例方法调用,需要一个对象实例,对于使用类名的静态方法调用等)。

在ABAP中,可以为方法定义多个输入多个输出参数,有几种可能性:

  • 方法定义中的IMPORTING定义了输入参数,必须为每个非可选输入参数指定适当的实际参数通过方法调用时

    当调用方法时,实际的IMPORTING参数将使用EXPORTING关键字提供。

  • 方法定义中的EXPORTING定义了输出参数,可以为每个输出参数通过方法调用指定适当的实际参数。

    当调用方法时,EXPORTING参数将使用IMPORTING关键字分配给实际参数。

  • CHANGING 定义了输入/输出参数,必须为每个非可选的输入/输出参数指定适当的实际参数通过方法调用时。实际参数的内容传递给调用中的输入/输出参数,类的内容在调用后传递给实际参数。

    当调用方法时,CHANGING参数将使用CHANGING关键字分配给实际参数。

  • 在方法定义中,RETURNING VALUE(r) 定义了除了任何其他形式参数之外,确切地一个返回值 r。

    当调用方法时,RETURNING参数将使用RECEIVING关键字分配给实际参数,或者这个(功能性)方法可以在操作数位置使用。

英文:

The concept of inheritance has nothing to do with method parameters.

Inheritance in short allows you to derive new classes from existing classes where the new class (subclass) inherits all components of the existing class (superclass)

Methods parameters define 'the interface' of the method, how the method should be used from the outside world, i.e. what data it expects as an input and what it returns as a result. Method is a name for a function/procedure which is contained inside the class, and method name together with its parameters known as method signature.

You can call any method of any class from any metod of any class, from other types of programs, function modules, etc as long as it is formally allowed (i.e. visibility rules allow this call, an object instance is available for an instance method call, static method call using the name of the class, etc).

In ABAP it is possible to define multiple input and multiple output parameters for a method and there are several possibilities for this:

  • IMPORTING in method definition defines input parameters, an appropriate actual parameter must be specified for every non-optional input parameter by method call

> when the method is called, the actual IMPORTING parameters are supplied with an
EXPORTING keyword

  • EXPORTING in method definition defines output parameters, an appropriate actual parameter can be specified for every output parameter by method call
    > when method is called, the EXPORTING parameters are assigned to the actual parameters using IMPORTING keyword

  • CHANGING defines input/output parameters, an appropriate actual parameter must be specified for every non-optional input/output parameter by method call. The content of the actual parameter is passed to the input/output parameter in the call and ater the class the content of the input/output parameter is passed to the actual parameter
    > when method is called, the CHANGING parameters are assigned to the actual parameters using CHANGING keyword

  • RETURNING VALUE(r) in method definition defines alongside any other formal parameters, precisely one return value r
    > when method is called, the RETURNING parameter is assigned to the actual parameters using RECEIVING keyword or this (functional) method can be used in an operand position

huangapple
  • 本文由 发表于 2023年5月10日 20:55:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76218686.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定