‎2005 Oct 25 1:28 PM
Hi,
I hope someone knows a solution for the following problem:
I want to access a table. I know the tablename and create a structure to access the values, but the table and therfore also the fieldnames of the structure can differ everytime.
Thats why i want to access the structure dynamical. I get the fielsnames of the structure with the Function:
'RFC_GET_STRUCTURE_DEFINITION'
But when i program the following code:
...
LOOP AT lt_fields INTO ls_fields.
lv_fieldname = ls_fields-fieldname.
Append <b>ls_Table-lv_fieldname</b> TO serializedTable.
ENDLOOP.
...
the compile is saying: no such fieldname exists.
How can i make him clear, to use the content of the variable during runtime?????
Thanks for ure help or hint!
‎2005 Oct 25 1:32 PM
I think you'd need to use a field-symbol. Have a look at report SAPRDEMO_TABLES_IN_EXCEL; it uses the same function module.
‎2005 Oct 25 1:33 PM
Hi Jim,
Which table is "ls_Table" ?
You can try using field symbols for assigning fields dynamically.
Ravi.
‎2005 Oct 25 1:38 PM
without the definition of
<b>lt_fields
ls_fields
lv_fieldname
ls_Table
serializedTable</b>
addressing your question would be tough for us.
Regards
Raja
‎2005 Oct 25 1:41 PM
@both:
i already tryed to solve it with Field Symbols, but failed.
How could I?
A FS is just a pointer maybe for something with unknown type. But i know the type of the table - means the name - which can differ from situation to situation. Therefore i just can access it dynamical.
if someone of u knows how i can solve it with FS, i would appreciate your help - i dont know how to solve it with FS.
‎2005 Oct 25 1:48 PM
no prob - if it help u:
lt_fields TYPE itab_RFC_FIELDS
ls_fields TYPE RFC_FIELDS,
lv_fieldname TYPE CHAR100
ls_Table TYPE ANY TABLE
serializedTable TYPE itab_XMLFile
‎2005 Oct 25 1:53 PM
Hi,
it seems to me that you can work with field-symbols:
assign (tab-name) to <f>.
append <f> to itab.
regards Andreas
‎2005 Oct 25 1:55 PM
is this what you are looking for
DATA: tablename TYPE x030l-tabname .
DATA: irfc_fields TYPE STANDARD TABLE OF rfc_fields .
DATA: wa_rfc_fields LIKE LINE OF irfc_fields .
DATA: serializedtable TYPE STANDARD TABLE OF string .
CLEAR tablename .
MOVE: 'MARA' TO tablename .
CALL FUNCTION 'RFC_GET_STRUCTURE_DEFINITION'
EXPORTING
tabname = tablename
* UCLEN = UCLEN
* IMPORTING
* TABLENGTH = TABLENGTH
TABLES
fields = irfc_fields
EXCEPTIONS
table_not_active = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT irfc_fields INTO wa_rfc_fields .
APPEND wa_rfc_fields-fieldname TO serializedtable .
ENDLOOP .
Regards
Raja
‎2005 Oct 25 2:10 PM
@Andreas: The compile is not accepting: assign(tab-<i>name</i>)to <f>
if <i>name</i> is a variable that contains the real fieldname
@Raja: almost what im looking for, but
APPEND wa_rfc_fields-fieldname TO serializedtable
isnt correct. It should be:
APPEND <i>StructureName</i>-wa_rfc_fields-fieldname TO serializedtable
‎2005 Oct 25 2:40 PM
Thanks everybody for ure help.
I guess i found the solution:
lc_fieldname = ls_fields-fieldname.
CONCATENATE 'ls_Table-' lc_fieldname INTO lc_fieldname.
ASSIGN (lc_fieldname) TO <FS_FIELDNAME>.
Append <FS_fieldname> TO serializedTable.