Application Development and Automation 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: 
Read only

whats wrong with this code?

Former Member
0 Likes
481

Hi Experts,

I am getting the error as " the method get_data has no returning parameter.

Can someone please help me with this.

CLASS main DEFINITION.

PUBLIC SECTION.

METHODS add_data IMPORTING i_data TYPE i.

METHODS get_data EXPORTING e_data TYPE char20.

PRIVATE SECTION.

DATA attribute TYPE char01.

ENDCLASS.

----


  • CLASS main IMPLEMENTATION

----


CLASS main IMPLEMENTATION.

METHOD add_data.

ADD i_data TO attribute.

ENDMETHOD.

METHOD get_data.

CONCATENATE 'Attribute value' attribute

INTO e_data SEPARATED BY space.

ENDMETHOD.

ENDCLASS.

DATA: object_reference TYPE REF TO main.

end-of-selection.

CREATE OBJECT object_reference.

DATA:

var TYPE char20.

CALL METHOD object_reference->add_data( i_data = 3 ).

var = object_reference->get_data( ). --> errored here

WRITE var.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
441

Hi Dan, if you want to use a RETURNING parameter when you call you method, you need to define the parameter as a RETURNING parameter in your class definition.


    METHODS get_data RETURNING VALUE(e_data) TYPE char20.

You had defined it as an EXPORTING parameter, which means that when you call the method you would have need to use this syntax instead.


   object_reference->get_data( IMPORTING e_data = var ).

Regards,

Rich Heilman

3 REPLIES 3
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
442

Hi Dan, if you want to use a RETURNING parameter when you call you method, you need to define the parameter as a RETURNING parameter in your class definition.


    METHODS get_data RETURNING VALUE(e_data) TYPE char20.

You had defined it as an EXPORTING parameter, which means that when you call the method you would have need to use this syntax instead.


   object_reference->get_data( IMPORTING e_data = var ).

Regards,

Rich Heilman

Read only

0 Likes
441

Hi Rich,

I still want to use exporting param as :

METHODS get_data exporting e_data TYPE char20.

-


-


-


and called the method as u suggested it is throwing an error saying " statement object_reference->get_data( is not defined ".

Can you please suggest?

Thanks

Dany

Read only

0 Likes
441

H Dan, if you would like to use the EXPORTING parameter, then you must write you method call like this.


object_reference->get_data( importing e_data = var ).

If you are on an earlier release, then you must use the CALL METHOD as well.


CALL METHOD object_reference->get_data( importing e_data = var ).

Regars,

Rich Heilman