Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Syntax to call one method with the returning of another method?

RyanK
Explorer
0 Kudos
394

I'd like to call one method with the results of another method and I keep getting the error 'The field XYZ(' is unknown but there is a field with a similar name' Error.

Consider the simple example below:

CLASS ZLCL_HELPER DEFINITION.

PUBLIC SECTION.

CLASS-METHODS emit IMPORTING text TYPE string.

CLASS-METHODS get_text RETURNING text TYPE string.

ENDCLASS.

I'd like to call emit with value of get_text without declaring a string type object in the caller such as:

START-OF-SELECTION.

DATA: text TYPE string.

text = zlcl_helper=>get_text( ).

zlcl_helper=>emit( text ).

I'd rather do something like:

START-OF-SELECTION.

zlcl_helper=>emit( zlcl_helper=>get_text( ) ).

Is there a way to do this?

Thanks,

-Ryan

1 ACCEPTED SOLUTION

Former Member
0 Kudos
254

Hi Ryan,

you got it almost right....try using following syntax...

zlcl_helper=>emit( text = zlcl_helper=>get_text( ) ).

~Piyush

4 REPLIES 4

Former Member
0 Kudos
255

Hi Ryan,

you got it almost right....try using following syntax...

zlcl_helper=>emit( text = zlcl_helper=>get_text( ) ).

~Piyush

RyanK
Explorer
0 Kudos
254

I still have the field "GET_TEXT(" is unknown problem. Here is the code that I tried. Am I missing something else?

CLASS zlcl_helper DEFINITION.

PUBLIC SECTION.

CLASS-METHODS emit IMPORTING text TYPE string.

CLASS-METHODS get_text RETURNING VALUE(text) TYPE string.

ENDCLASS.

CLASS zlcl_helper IMPLEMENTATION.

METHOD get_text.

text = 'xyz'.

ENDMETHOD.

METHOD emit.

WRITE text.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

zlcl_helper=>emit( text = zlcl_helper=>get_text( ) ).

matt
Active Contributor
0 Kudos
254

You can't nest method calls. You have to split it into two.

some_text = zlcl_helper=>get_text( ). 
zlcl_helper=>emit( text = some_text( ).

Former Member
0 Kudos
254

Hi Ryan,

The syntax requires a space after the opening bracket '(' and before the closing one ')'....thats it..

rest the code is fine....works for me..

~Piyush