Enes F.
Enes F.

Reputation: 535

ABAP Using Method As a Parameter

I want to use the return value of methods directly. For example in C++, we can use:

//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:

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.

Upvotes: 0

Views: 385

Answers (2)

inetphantom
inetphantom

Reputation: 2617

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.

Upvotes: 0

Tapio Reisinger
Tapio Reisinger

Reputation: 196

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

Upvotes: 1

Related Questions