09-22-2008 11:40 AM
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.
09-22-2008 11:45 AM
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
09-22-2008 11:45 AM
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
09-22-2008 11:45 AM
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'.
09-22-2008 11:47 AM
Hi Karim,
It can be using the pointers concept, nothing but Field symbols
Regards,
Salini
09-22-2008 11:48 AM
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