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: 

Access column of an internal table dynamically.

Former Member
0 Kudos

Hi All,

How can I access the column of a table dynamically?

Ex: Data : columnname type string.

columnname = 'name'.

itab-columnname = 'test'.

Kind regards.

Karim.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Karim,

That is possible through field symbols. Try the following way

field-symbols <fs> type any.

Data : columnname type string,

columnname = 'name',

s_itab like line of itab.

assign component columnname of structure s_itab to <fs>.

Now <fs> Contains the value of the dynamic field 'name'.

Cheers,

Kothand

4 REPLIES 4

Former Member
0 Kudos

Hi Karim,

That is possible through field symbols. Try the following way

field-symbols <fs> type any.

Data : columnname type string,

columnname = 'name',

s_itab like line of itab.

assign component columnname of structure s_itab to <fs>.

Now <fs> Contains the value of the dynamic field 'name'.

Cheers,

Kothand

former_member188685
Active Contributor
0 Kudos

you can do some thing like this..

field-symbols: <fs> type any.
Data : columnname type string,
          var(15).
columnname = 'NAME'.
concatenate 'ITAB-' columnname into var.
assign (var) to <fs>.
<fs> = 'test'.

Former Member
0 Kudos

Hi Karim,

It can be using the pointers concept, nothing but Field symbols

Regards,

Salini

Former Member
0 Kudos

You need field symbols

I insert an example of a form using them.

In the example the fields are assigned dynamically

&----


*& Form pasar_de_tc_a_infty

&----


  • text

----


FORM pasar_de_tc_a_infty.

FIELD-SYMBOLS: <l_fs_campo_lgaxx>,

<l_fs_campo_betxx>.

DATA: l_nombre_lgaxx(9) VALUE 'P9709-LGA',

l_nombre_betxx(9) VALUE 'P9709-BET',

l_num(2) TYPE n,

l_campo_lgaxx(11),

l_campo_betxx(11).

DO 10 TIMES.

CLEAR: l_campo_lgaxx, l_campo_betxx, l_num.

l_num = sy-index.

l_campo_lgaxx = l_nombre_lgaxx.

l_campo_lgaxx+9 = l_num.

l_campo_betxx = l_nombre_betxx.

l_campo_betxx+9 = l_num.

ASSIGN (l_campo_lgaxx) TO <l_fs_campo_lgaxx>.

ASSIGN (l_campo_betxx) TO <l_fs_campo_betxx>.

CLEAR: <l_fs_campo_lgaxx>, <l_fs_campo_betxx>.

ENDDO.

LOOP AT g_t_ccnom.

CLEAR: l_campo_lgaxx, l_campo_betxx, l_num.

l_num = sy-tabix.

l_campo_lgaxx = l_nombre_lgaxx.

l_campo_lgaxx+9 = l_num.

l_campo_betxx = l_nombre_betxx.

l_campo_betxx+9 = l_num.

ASSIGN (l_campo_lgaxx) TO <l_fs_campo_lgaxx>.

ASSIGN (l_campo_betxx) TO <l_fs_campo_betxx>.

<l_fs_campo_lgaxx> = g_t_ccnom-lgaxx.

<l_fs_campo_betxx> = g_t_ccnom-betxx.

ENDLOOP.

ENDFORM. " pasar_de_tc_a_infty