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

Read Table by column index

Former Member
0 Likes
4,986

Hi All,

Is it possible to read a table by its column index ??

Suppose if I have to read the 6th column(without knowing the name) in a particular row of an internal table, is that possible ?

Please suggest.

Thanks in advance,

Archana.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,115

Hi Archana,

try this

suppose u want to read 5th row 6th column

Field-symbols : <FS> type any.

  loop at itab.
   if sy-tabix eq 5.
   do.
   assign component 'FIELD6' of structure itab to <FS>.
   if sy-subrc eq 0.
   exit.
  endif.
 enddo.
   endif.
  endloop.

<FS> will contain the value of 6th column

Message was edited by:

Chandrasekhar Jagarlamudi

8 REPLIES 8
Read only

Former Member
0 Likes
2,115

I guess you want to read table rows you can use statement

read table <itab name> index 6

Read only

Former Member
0 Likes
2,115

Hi, read return 1 record...because use keys.. column have not sense.

regs

Read only

0 Likes
2,115

Hi,

I want to read columns of the tables, b'cos the keys will not be known till runtime.

Since the column name is not known I cannot use 'KEYS' but the column index is known to me. So, I am exploring the possibility to read the table's column for a particular row, if we have the column number.

Does anybody have any suggestions for this ?

Read only

0 Likes
2,115

Hi,

Yes u can do that using Field symbols.

DO you know the field symbols concept. This is only possible with Field symbols, as i did the same in one of my requirement.

Read table itab with key <fs1> = ____.

Revert back if any issues,

Reward with points if helpful.

Regards,

Naveen

Read only

Former Member
0 Likes
2,116

Hi Archana,

try this

suppose u want to read 5th row 6th column

Field-symbols : <FS> type any.

  loop at itab.
   if sy-tabix eq 5.
   do.
   assign component 'FIELD6' of structure itab to <FS>.
   if sy-subrc eq 0.
   exit.
  endif.
 enddo.
   endif.
  endloop.

<FS> will contain the value of 6th column

Message was edited by:

Chandrasekhar Jagarlamudi

Read only

0 Likes
2,115

Hi Chandrashekhar,

Is 'field6' the name of the column, because that will not be known.

I know how to read the 6th field using the field name but I want to know if it can be read only using the column index.

Read only

0 Likes
2,115

hi Archana,

try this

loop at itab.

if sy-tabix eq 5.

do.

if sy-index eq 6.

assign component sy-index of structure itab to <FS>.

if sy-subrc eq 0.

exit.

endif.

endif.

enddo.

endif.

endloop.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,115

Use a field symbol and assign it to the nth column of a record of the table;

DATA: itab TYPE TABLE OF whatyouwant.
FIELD-SYMBOLS <fs>. 
* assign using column number
ASSIGN COMPONENT column_nr  OF STRUCTURE itab TO <fs>. 

Regards