Application Development and Automation 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: 
Read only

Column Index

Former Member
0 Likes
2,040

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?

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
1,005

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

3 REPLIES 3
Read only

venkat_o
Active Contributor
0 Likes
1,005

HI,

I am 100% sure that we do not have any index to update column in itab.

Thanks

Venkat.O

Read only

MarcinPciak
Active Contributor
0 Likes
1,006

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

Read only

Former Member
0 Likes
1,005

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.