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

Accessing a structure dynamical

Former Member
0 Likes
1,114

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!

9 REPLIES 9
Read only

Former Member
0 Likes
1,066

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.

Read only

Former Member
0 Likes
1,066

Hi Jim,

Which table is "ls_Table" ?

You can try using field symbols for assigning fields dynamically.

Ravi.

Read only

0 Likes
1,066

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

Read only

Former Member
0 Likes
1,066

@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.

Read only

Former Member
0 Likes
1,066

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

Read only

0 Likes
1,066

Hi,

it seems to me that you can work with field-symbols:

assign (tab-name) to <f>.

append <f> to itab.

regards Andreas

Read only

0 Likes
1,066

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

Read only

Former Member
0 Likes
1,066

@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

Read only

Former Member
0 Likes
1,066

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.