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

How to fetch fields dynamically

Former Member
0 Likes
792

Hi experts

I am using a report with following code , in which itemmaster is a workarea.

SELECT SINGLE * FROM zmartitemmaster CLIENT SPECIFIED INTO itemmaster

WHERE mandt = sy-mandt

AND prodid = prodid.

this work area has fields like itemdes1, itemdes2 and so on . Now problem is that i want to fetch its fields dynamically

so i collected dynamic fiels name inot a variable named <b>var</b> (ex concattenate 'itemdes' '1' to var)

then i am trying t fetch as

MOVE itemmaster-var to X.

but its giving a syntax error as itemmaster does not have a component called VAR.

can any body give any possible solution for getting dynamic fields contents.

Regards

Abhay

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
712

Hi

thanks for reply but i want to fetch its fields dynamically ,

and i am storing fields name in <b>var</b> .

so i dont understand how to do it

can you plz explain it with piece of code .

Regards

Abhay

6 REPLIES 6
Read only

Former Member
0 Likes
712

declare var of type itemmaster

Read only

Former Member
0 Likes
713

Hi

thanks for reply but i want to fetch its fields dynamically ,

and i am storing fields name in <b>var</b> .

so i dont understand how to do it

can you plz explain it with piece of code .

Regards

Abhay

Read only

0 Likes
712

Hi,

You can use field symbols for it.

e.g. FIELD-SYMBOLS : <fs1>.

Using the function GET_COMPONENT_LIST you can get the fieldnames for the internal table being used in the program into another internal table.

Now, loop at the itab.

CONCATENATE 'zitemmaster-' itab-fieldname into str.

ASSIGN (str) to <fs1>.

ENDLOOP.

This will populate the value of zitemmaster-itemdes1, itemdes2 etc. one by one in the field symbol which we can use.

Hope it helps.

Regards,

Himanshu

Read only

0 Likes
712

Use field symbols to get the info

field-symbols: <fs> type any.

assign component Var of structure itemmaster to <fs>

Regards,

abhishek

Read only

Former Member
0 Likes
712

Hi Himanshu and abhishek

Thanks a lot , problem solved

Regards

abhay

Read only

Former Member
0 Likes
712

Thanks a lot problem solved

Regards

Abhay