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

Problem with generic interface parameter

Former Member
0 Likes
1,251

Hi,

In my custom class, I have a method which has a generic exporting parameter ( type ref to data). This method is supposed to return an internal table in the form of this generic parameter. Inside the method, I am taking the reference of the actual internal table and assigning to the exporting parameter.

However , when I try to call this method from my program, this parameter is returning nothing. It shows 'FREED STACK:{A:2*\TYPE=%_T00004S00000039O0000002888}'. what could be the problem here? Any suggestions will be helpful.

The code in the method:

types : BEGIN OF ty_employee,

         no type i,

         name type char30,

         age type i,

         END OF ty_employee.

data : it_employee type STANDARD TABLE OF ty_employee.

data : wa_employee type ty_employee.

wa_employee-no = 1.

wa_employee-name = 'Tom'.

wa_employee-age = 29.

append  wa_employee to it_employee.

wa_employee-no = 2.

wa_employee-name = 'Henk'.

wa_employee-age = 23.

append  wa_employee to it_employee.

get REFERENCE OF it_employee into ex_data.

Ex_data is the exporting parameter(type ref to data).

This is how I am calling this method.

data : im_data type REF TO data.

FIELD-SYMBOLS : <fs_table> type any table.

call METHOD ZCL_test=>TEST

IMPORTING ex_data = im_data.

assign im_data->* to <fs_table> .

write ' ' .

Here the data reference variable im_data gets 'FREED STACK:{A:2*\TYPE=%_T00004S00000039O0000002888}'.

Thanks

Ajith C


1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
865

Hello Ajith,

Like Kiran had mentoned above, Freed stack refers to a completed program stack or a completed program unit popped from a program stack .

The Error you are getting is due to the following reason.

get REFERENCE OF it_employee into ex_data.

You are getting the reference of a local  varaible into an Exporting parameter ex_data.

EX_DATA now points to IT_EMPLOYEE. EX_DATA has not allocated any memory, rather points to an alllocated memory of a local variable, IT_EMPLOYEE. Once the method is completed, all Local variables are freed and hence you get the Freed Stack reference message.

To correct this, you need EX_DATA to allocate its own memory. The below code snippet within the method , should solve your issue.

FIELD-SYMBOLS : <fs_data> like it_employee .

create data ex_data LIKE it_employee.

ASSIGN ex_data->* to <fs_data>.

<fs_data> = it_employee.

I hope this helps.

Thanks,

Venkat.

Message was edited by: Venkat Gowrishankar

3 REPLIES 3
Read only

Kiran_Valluru
Active Contributor
0 Likes
865

Hi,

Freed stack means - the resources of the program are freed after completion of the program stack.

In your scenario, you take an exporting parameter of type ANY TABLE and do the assignment inside the method and export the internal table data.

Regards,

Kiran

Read only

Former Member
0 Likes
866

Hello Ajith,

Like Kiran had mentoned above, Freed stack refers to a completed program stack or a completed program unit popped from a program stack .

The Error you are getting is due to the following reason.

get REFERENCE OF it_employee into ex_data.

You are getting the reference of a local  varaible into an Exporting parameter ex_data.

EX_DATA now points to IT_EMPLOYEE. EX_DATA has not allocated any memory, rather points to an alllocated memory of a local variable, IT_EMPLOYEE. Once the method is completed, all Local variables are freed and hence you get the Freed Stack reference message.

To correct this, you need EX_DATA to allocate its own memory. The below code snippet within the method , should solve your issue.

FIELD-SYMBOLS : <fs_data> like it_employee .

create data ex_data LIKE it_employee.

ASSIGN ex_data->* to <fs_data>.

<fs_data> = it_employee.

I hope this helps.

Thanks,

Venkat.

Message was edited by: Venkat Gowrishankar

Read only

0 Likes
865

Hi Vankat,

Thanks. I figured where the problem was.