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: 

Using the Inline declared table outside the processing block

anmolamb
Participant
0 Kudos

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

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

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.

6 REPLIES 6

srikanthnalluri
Active Participant
0 Kudos

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>

0 Kudos

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.

0 Kudos

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.

-- Tomas --

Sandra_Rossi
Active Contributor

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.

0 Kudos

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.

matt
Active Contributor

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?