‎2007 Aug 16 12:14 PM
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
‎2007 Aug 16 12:16 PM
‎2007 Aug 16 12:19 PM
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
‎2007 Aug 16 12:22 PM
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.
‎2007 Aug 16 12:25 PM
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 !!!
‎2007 Aug 16 12:33 PM
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'.
‎2007 Aug 16 12:35 PM
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??????
‎2007 Aug 16 12:41 PM
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
‎2007 Aug 16 12:50 PM
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?
‎2007 Aug 16 12:56 PM
For classes, do you not need to specify the internal table name.
You will have to hardcode something.
‎2007 Aug 16 12:48 PM
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