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

Get the Variable Name dynamically

prabhu_s2
Active Contributor
1,849

Hi

I want to get the variable name dyncamically. Here is a small example:

Data: T_HeadNr type string.

Data: Var_Name type string.

I want to move the name of the field T_HeadNr i.e. "T_HeadNr" to Var_Name and not the content of T_HeadNr.

any inputs is highly appriciated,.

thkx

Prabhu

10 REPLIES 10
Read only

Former Member
0 Likes
1,344

Why would you want to do that.

Read only

0 Likes
1,344

its a kinda requirement which i would want put in my code....any inputs>

I dont wanna to hardcode

Message was edited by:

Prabhu S

Read only

0 Likes
1,344

If you define the fields within a stucture you can use the code

data: i_components type standard table of rstrucinfo.

data w_repid type syrepid.

w_repid = sy-repid.

call function 'GET_COMPONENT_LIST'

exporting

program = w_repid

fieldname = 'ST_RECORDS'

tables

components = i_components.

Read only

0 Likes
1,344

i dont want this 'ST_RECORDS' to be hardocded. this is my requirement. i need to pass the name dynamically to this f/n module !!!

Read only

0 Likes
1,344

tell me if this helps

data: begin of myitab occurs 0,
  number type i,
  name(30),
 end of myitab.


data: INT_TABNAME(40).
INT_TABNAME = 'MYITAB'.

* Insert internal table fieldname into itab
DATA : IRSTRUCINFO LIKE RSTRUCINFO OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'GET_COMPONENT_LIST'
  EXPORTING
    PROGRAM    = sy-repid
    FIELDNAME  = INT_TABNAME
  TABLES
    COMPONENTS = IRSTRUCINFO.

loop at IRSTRUCINFO.
  write:/ IRSTRUCINFO-COMPNAME.
endloop.

write:/ 'end'.

Read only

0 Likes
1,344

thkx kris for ur reply. but again i dont want any hardcoding such as INT_TABNAME = 'MYITAB'. is it possible to get the name of 'MYITAB' into INT_TABNAME??????

Read only

0 Likes
1,342

MYITAB is the name of an internal table containing the fields

when you ask the program to fetch the fieldnames, you need to tell it from where to fetch it

Read only

0 Likes
1,342

there are some classes that gives u the type references of the internal table. in this case is there any similar case where we can get the name of the variable itself?

Read only

0 Likes
1,342

For classes, do you not need to specify the internal table name.

You will have to hardcode something.

Read only

Former Member
0 Likes
1,342

You will have to hardcode something. The program cannot assume what structure/field you require.

What is reason you do not want to hardcode the structure.

Message was edited by:

Martin Shinks