03-22-2019 12:44 PM
Hello Experts,
I am trying to pass the data fetched using inline declaration to next method.
For that tried below code
method get_data.
select 1,2,3,, from abc into table @data(it).
data(gv_data) = ref #( it ).
endmethod.
method process_data.
assign gv_data->* to field-symbol(<fs_data>).
endmethod.
However the reference of the gv_data is lost and I am not able to use it anymore.
Do you know the better approach to do this.
We should not write all the code in one processing block to use the inline function isn't.
Thanks a lot for your help in advance.
Regards,
Anmol
03-22-2019 3:21 PM
Inline declarations are good for readability, but it's only local.
As you don't want it local, don't use an inline declaration. Note that with Eclipse ADT, it takes you 2 clicks to turn your inline expression into an equivalent attribute declaration.
03-22-2019 1:16 PM
gv_data is local to the get_data method, if you export it to process_data it should work.
class lcl1 definition.
methods: get_data,
process_data importing !iv_data type data.
endclass.
class lcl1 implementation.
method get_data.
select 1,2,3,, from abc into table @data(it).
data(gv_data) = ref #( it ).
process_data( iv_data = gv_data ).
endmethod.
method process_data.
assign iv_data->* to field-symbol(<fs_data>).
endmethod.
endclass.
start-of-selection.
data(lo_obj) = new lcl1( ).
lo_obj->get_data( ).
<br>
03-22-2019 2:19 PM
GV_data would be global anyways.
I want to call get_data and process_data separately if possible.
I dont know why but the data reference of the gv_data is lost when I try to call it in process data.
03-22-2019 2:36 PM
Anmol Bhat inline declared variables are valid only in the current context. In your case it is thus visible only inside a method. It is explained in ABAP documentation.
03-22-2019 3:21 PM
Inline declarations are good for readability, but it's only local.
As you don't want it local, don't use an inline declaration. Note that with Eclipse ADT, it takes you 2 clicks to turn your inline expression into an equivalent attribute declaration.
03-25-2019 9:36 AM
Hi Sandra,
Thanks a lot, it would have been good option to by someway to use this inline declaration outside by using reference or something.
When it is local, it hardly helps then as we write code in modules.
Anyways, Thanks a lot.
03-25-2019 1:43 PM
Too few lines of code per modular unit is as bad as too many. There should be a balance.
And fs as a prefix for field-symbols adds no values. Isn't the angle brackets sufficient a clue? What else can go in an angled bracket?