‎2009 Jul 06 9:02 AM
Hi,
I want to update one internal table based on column index.Is there any way to find out column index of an internal table?
‎2009 Jul 06 10:12 AM
Hi,
You can use the following:
parameters: pa_idx type i. "which column should be updated
data: begin of itab occurs 0,
column1 type ..
column2 type.
columnN type...
end of itab.
field-symbols: <column> type any.
loop at itab.
do.
assign component sy-index of structure itab to <column>.
if sy-subrc = 0 .
if sy-index = pa_idx. "column index to update
<column> = "give required value here to update the content of that column
endif.
else.
exit.
endif.
enddo.
endloop.
Regards
Marcin
or shorter form without DO ... ENDDO
assign component pa_idx of structure itab to <column>.
if sy-subrc = 0 .
<column> = "give required value here to update the content of that column
endif.
Edited by: Marcin Pciak on Jul 6, 2009 11:15 AM
‎2009 Jul 06 9:56 AM
HI,
I am 100% sure that we do not have any index to update column in itab.
Thanks
Venkat.O
‎2009 Jul 06 10:12 AM
Hi,
You can use the following:
parameters: pa_idx type i. "which column should be updated
data: begin of itab occurs 0,
column1 type ..
column2 type.
columnN type...
end of itab.
field-symbols: <column> type any.
loop at itab.
do.
assign component sy-index of structure itab to <column>.
if sy-subrc = 0 .
if sy-index = pa_idx. "column index to update
<column> = "give required value here to update the content of that column
endif.
else.
exit.
endif.
enddo.
endloop.
Regards
Marcin
or shorter form without DO ... ENDDO
assign component pa_idx of structure itab to <column>.
if sy-subrc = 0 .
<column> = "give required value here to update the content of that column
endif.
Edited by: Marcin Pciak on Jul 6, 2009 11:15 AM
‎2009 Jul 06 11:33 AM
Here is the sample code with which you can find out the fields and other properties of your statically defined internal table
TYPE-POOLS : abap.
DATA: BEGIN OF tabl occurs 0,
mandt TYPE mara-mandt,
matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
laeda TYPE mara-laeda,
aenam TYPE mara-aenam,
vpsta TYPE mara-vpsta,
pstat TYPE mara-pstat,
lvorm TYPE mara-lvorm,
mtart TYPE mara-mtart,
mbrsh TYPE mara-mbrsh,
END OF tabl.
DATA : it_details TYPE abap_compdescr_tab,
wa_comp TYPE abap_compdescr.
DATA : ref_descr TYPE REF TO cl_abap_structdescr.
ref_descr ?= cl_abap_typedescr=>describe_by_data( tabl ).
it_details[] = ref_descr->components[].
loop at it_details into wa_comp.
write:/ wa_comp.
endloop.