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: 

FIELD-SYMBOL: Reading a column dynamically

Former Member
0 Kudos

Hello everybody!

I'm trying to get dynamically a column value from a field-symbol structure.

Building a a field-symbol and assing values to its columns it is ok.

Reading it dynamically is showing to be the fun stuff.

Let me show you some example-code of what i'm trying to do

(1) starting point:


* building field-symbol structure and value assign
...
ASSIGN COMPONENT 'MY_COLUMN'   OF STRUCTURE <DYN_WA_MY_TABLE> TO <L_FIELD>. 
<L_FIELD> = 'this is my value'.
...
* end building field-symbol


*Reading field symbol column by name (the good stuff)

data: my_column_name(10) type C, my_column_value(100) type C.

my_column_name = 'MY_COLUMN'. "the name of the column I want to read

my_column_value = <DYN_WA_MY_TABLE>-[my_column_name].


* my_column_value must have 'this is my value'.

Hope this helps. But this was the best way I've found to show you my issue.

Thank you very much for your attention.

Code Formatted by: Alvaro Tejada Galindo on Jan 28, 2008 6:17 PM

1 ACCEPTED SOLUTION

former_member194669
Active Contributor
0 Kudos

May be this way


report  zars no standard page heading
        line-size 170
        line-count 65(4).

data : begin of itab occurs 0,
    my_column1 type c value '1',
    my_column2 type c value '2',
    my_column3 type c value '3',
    my_column4 type c value '4',
    my_column5 type c value '5'.
data : end of itab.
data : i_components  like rstrucinfo occurs 0 with header line.
field-symbols:     <fs> type any.

call function 'GET_COMPONENT_LIST'
  exporting
    program    = 'ZARS'
    fieldname  = 'ITAB'
  tables
    components = i_components.
read table i_components with key compname = 'MY_COLUMN1'.
if sy-subrc eq 0.
  assign component sy-tabix of structure itab to
                                           <fs>.
  write : <fs>.

endif.
read table i_components with key compname = 'MY_COLUMN2'.
if sy-subrc eq 0.
  assign component sy-tabix of structure itab to
                                           <fs>.
  write : <fs>.

endif.

3 REPLIES 3

former_member194669
Active Contributor
0 Kudos

May be this way


report  zars no standard page heading
        line-size 170
        line-count 65(4).

data : begin of itab occurs 0,
    my_column1 type c value '1',
    my_column2 type c value '2',
    my_column3 type c value '3',
    my_column4 type c value '4',
    my_column5 type c value '5'.
data : end of itab.
data : i_components  like rstrucinfo occurs 0 with header line.
field-symbols:     <fs> type any.

call function 'GET_COMPONENT_LIST'
  exporting
    program    = 'ZARS'
    fieldname  = 'ITAB'
  tables
    components = i_components.
read table i_components with key compname = 'MY_COLUMN1'.
if sy-subrc eq 0.
  assign component sy-tabix of structure itab to
                                           <fs>.
  write : <fs>.

endif.
read table i_components with key compname = 'MY_COLUMN2'.
if sy-subrc eq 0.
  assign component sy-tabix of structure itab to
                                           <fs>.
  write : <fs>.

endif.

0 Kudos

Hi. The code just works fine.

But now I'm trying to put it on a Function.. I'm getting a sy-subrc = 4 when I read table i_components.

The same code, but changing the exporting program to sy-repid.

call function 'GET_COMPONENT_LIST'

exporting

program = sy-repid

fieldname = 'ITAB'

tables

components = i_components.

0 Kudos

Just knowledge sharing:

It works if the data is declared global to the Group Function.

SOLVED.