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: 

How to Refer an Internal Table's field by index

Former Member
0 Kudos

I have a internal table with 10 columns,

how can i refer the column with it's index.

something like field(1) or field(2) etc.

Thanks in Advance

Arun Kumar

6 REPLIES 6

Former Member
0 Kudos

Hi,

You can use field symbols.

ASSIGN COMPONENT idx OF STRUCTURE struc TO <fs>.

Svetlin

athavanraja
Active Contributor
0 Kudos

you can use field symbol and use index of structure.

if you tell us what exactly you are trying to do may be we could help better.

Regards

Raja

0 Kudos

Dear Durairaj Athavan Raja

You might be knowing, In HR, in the table PA0008, basic may stored in any of the field from BET01 to BET20.

This is based on the wage type , which is once again stored in LGA01 to LGA20.

if i want to get the basic of a particular employee,

i'll execute a query for pa0008,

select * from pa0008 into corresponding fields of taable itpa008 where pernr = '1234'.

if i am able to get the field value thro index of a field,

my cod will be

loop at itpa0008.

if itpa0008-LGA(index) = '1001'.

actbasic = itpa0008-BET(index).

endif.

endloop.

now variable actbasic will have the basic of that particular employee.

orelse, i have to check from LGA01 to LGA20 manually using if statement.

How can i achive this.

thanks in advance

Arun

0 Kudos

hi try this,

field-symbols: <f1> LIKE LINE OF itpa008,<f2>.

data:

i type i,

j type i.

assign itpa008 to <f1>.

i = <write offset of field LGA>.

j = <write offset of field BET>.

DO 20 TIMES.

ASSIGN COMPONENT i OF STRUCTURE <F1> TO <F3>.

if <f3> = '1001'.

ASSIGN COMPONENT j OF STRUCTURE <F1> TO <F3>.

actbasic = <f3>.

endif.

i = i + 1.

j = j + 1.

ENDDO.

regards,

Hemendra

Message was edited by: Hemendra Singh Manral

Former Member
0 Kudos

you can access rows of internal by index (in read statement), but i dont know if you can do the same for column.

however, if dont like to use the column name (like itab-matnr) to refer to a column you can use length offset to access the columns..

REPORT ZTEST_TABLE.

data: begin of itab occurs 0,

matnr like mara-matnr, "field length 18

matkl like mara-matkl, "field length 9.

end of itab.

start-of-selection.

*

select matnr matkl from mara

into corresponding fields of table itab up to 10 rows.

loop at itab.

write:/ 'matnr', itab(18).

write:/ 'matkl', itab+18(9).

endloop.

Former Member
0 Kudos

Please assign reward points to the useful anwsers.

Svetlin