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

using variable in accessing itab field

Former Member
0 Likes
755

Hi all!

is it possible to access a field of an internal table using a variable.

for example, please see my code below.

DATA: BEGIN OF itab,

field1 LIKE mara-matnr,

field2 LIKE mara-matkl,

END OF itab.

data: v_fldname(5).

**- itab is being populated here -**

v_fldname = 'field1'.

**- i want to access the first field of itab, field1-**

***- but instead of doing this code

write itab-field1.

***- i want to do this...

write itab-(v_fldname).

but im getting an error message saying that <<The data object "IT_VAD" does not have a component called "">>

please send me the correct way to deal with this.

Thanks for your usual support.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
720

Yes it is possible to achive what you want, not with variables but with Field symbols.

- Guru

Reward points for helpful answers

5 REPLIES 5
Read only

Former Member
0 Likes
721

Yes it is possible to achive what you want, not with variables but with Field symbols.

- Guru

Reward points for helpful answers

Read only

Former Member
0 Likes
720

im sorry, here's the correct error message:

The data object "itab" does not have a component called ""

Read only

Former Member
0 Likes
720

Hi guru,

can you show me a sample code.

Thanks you very much.

Read only

0 Likes
720

I dont have a SAP sytem now but This is a sample.

Field-symbols f_field.

  • Assin a value to the field symbol

Assign f_field value "Field name"

  • Now the value "Field name" is stored in F_Field. You can use the value as below

v_somefield = <f_field>. " V_somefield will now have a value of "Field name"

- Guru

Reward points for helpful answers

Read only

Former Member
0 Likes
720

try this it may help

FM name 'GET_COMPONENT_LIST'

DATA : components LIKE rstrucinfo OCCURS 0 WITH HEADER LINE.

*----


Get component list

CALL FUNCTION 'GET_COMPONENT_LIST'

EXPORTING

program = sy-repid

fieldname = 'ITAB'

TABLES

components = components.

regards

shiba dutta