简体   繁体   English

ABAP使用方法作为参数

[英]ABAP Using Method As a Parameter

I want to use the return value of methods directly. 我想直接使用方法的返回值。 For example in C++, we can use: 例如在C ++中,我们可以使用:

//Some codes
cout << obj1.get_foo() << endl;
int a = obj2->get_value() + 100 + obj2->get_value();

or 要么

//...
obj1->set_color("BLUE");
cout << "Color is:" << obj1->get_color();
printf("Color is: %s", obj1->get_color()); // C Version

When I do this in ABAP like: 当我在ABAP中这样做时:

OBJ1->SET_COLOR( 'BLUE' ). "That's OK.

WRITE:/ 'Color is:', OBJ1->GET_COLOR( ). "Error!

And I expected this output: 我期望这个输出:

Color is: BLUE

Edit: I used Parameter word in Title not as ABAP Keyword , but as function arguments. 编辑:我在Title中使用的参数字不是ABAP关键字 ,而是函数参数。

What you can do is. 你能做的是。

* before 740
OBJ1->SET_COLOR( 'BLUE' ).
DATA COLOR TYPE NAME.
COLOR = OBJ1->GET_COLOR( ).
WRITE:/ 'Color is:', COLOR.

or 要么

* since 740
OBJ1->SET_COLOR( 'BLUE' ).
DATA(COLOR) = OBJ1->GET_COLOR( ).
WRITE:/ 'Color is:', COLOR.

Best regards, Tapio 最好的问候,Tapio

An other solution: 另一个解决方案:

DATA : STRING TYPE STRING.


CONCATENATE 'Color is:' OBJ1->GET_COLOR( ) INTO STRING SEPARATED BY ' '.

WRITE :/ STRING .

if you have a multilingual application, with this method, you can get the right language for 'Color is:' at the same time. 如果您有多语言应用程序,则使用此方法,您可以同时获取“颜色为:”的正确语言。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM