ABAP 使用方法作为参数
ABAP Using Method As a Parameter
我想直接使用方法的return值。
例如在C++中,我们可以使用:
//Some codes
cout << obj1.get_foo() << endl;
int a = obj2->get_value() + 100 + obj2->get_value();
或
//...
obj1->set_color("BLUE");
cout << "Color is:" << obj1->get_color();
printf("Color is: %s", obj1->get_color()); // C Version
当我在 ABAP 中这样做时:
OBJ1->SET_COLOR( 'BLUE' ). "That's OK.
WRITE:/ 'Color is:', OBJ1->GET_COLOR( ). "Error!
而且我期望这样的输出:
Color is: BLUE
编辑:我在标题中使用了参数词不是作为 ABAP 关键字,而是作为函数参数。
你能做的是。
* before 740
OBJ1->SET_COLOR( 'BLUE' ).
DATA COLOR TYPE NAME.
COLOR = OBJ1->GET_COLOR( ).
WRITE:/ 'Color is:', COLOR.
或
* since 740
OBJ1->SET_COLOR( 'BLUE' ).
DATA(COLOR) = OBJ1->GET_COLOR( ).
WRITE:/ 'Color is:', COLOR.
此致,
塔皮奥
另一个解决方案:
DATA : STRING TYPE STRING.
CONCATENATE 'Color is:' OBJ1->GET_COLOR( ) INTO STRING SEPARATED BY ' '.
WRITE :/ STRING .
如果您有一个多语言应用程序,使用此方法,您可以同时获得 'Color is:' 的正确语言。
我想直接使用方法的return值。 例如在C++中,我们可以使用:
//Some codes
cout << obj1.get_foo() << endl;
int a = obj2->get_value() + 100 + obj2->get_value();
或
//...
obj1->set_color("BLUE");
cout << "Color is:" << obj1->get_color();
printf("Color is: %s", obj1->get_color()); // C Version
当我在 ABAP 中这样做时:
OBJ1->SET_COLOR( 'BLUE' ). "That's OK.
WRITE:/ 'Color is:', OBJ1->GET_COLOR( ). "Error!
而且我期望这样的输出:
Color is: BLUE
编辑:我在标题中使用了参数词不是作为 ABAP 关键字,而是作为函数参数。
你能做的是。
* before 740
OBJ1->SET_COLOR( 'BLUE' ).
DATA COLOR TYPE NAME.
COLOR = OBJ1->GET_COLOR( ).
WRITE:/ 'Color is:', COLOR.
或
* since 740
OBJ1->SET_COLOR( 'BLUE' ).
DATA(COLOR) = OBJ1->GET_COLOR( ).
WRITE:/ 'Color is:', COLOR.
此致, 塔皮奥
另一个解决方案:
DATA : STRING TYPE STRING.
CONCATENATE 'Color is:' OBJ1->GET_COLOR( ) INTO STRING SEPARATED BY ' '.
WRITE :/ STRING .
如果您有一个多语言应用程序,使用此方法,您可以同时获得 'Color is:' 的正确语言。