0

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.

5
  • Your question is not clear: you want to use the method RESULT, not pass the method itself, right? Commented Jul 9, 2015 at 12:19
  • What is the signature of GET_COLOR? What SAP_BASIS release are you using? Commented Jul 9, 2015 at 12:59
  • Get_color returns COLOR attribute. Its type is NAME. Sap 740, R/3 Commented Jul 9, 2015 at 13:03
  • What is the exact error you get? Commented Jul 9, 2015 at 15:00
  • @Enes We're using SAP ECC 6.0 and SAP GUI 7.3 and we can't make that kind of operation. We must create a variable to store that value there before use it in another operation. Can you provide more details of your SAP version? Commented Jul 9, 2015 at 15:01

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, i understood how to do it. So, my way isn't possible in ABAP.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.