Skip to Content

Accessing with deep structures using Field Symbols

Please look at the code below and give me some suggestions:

I have a deep structure which contains some fields and a table which contains three fields and a table

let's say the name of my structure is my_struct and the structure of my struct is as follows

field_A type c

field_B type c

table_A

--> table

--> field_1

--> feld_2

--> field_3

Below is the code !!!!!

field-symbols: <my_fs> type any.

field-symbols: <fs1> type any

data: my_ref type ref to data.

create data my_ref type my_struct.

assign my_ref->* to <my_fs>.

now field-symbol my_fs is pointing to my_struct. I have been able to access fields field_A and field_B using

assign component field_A of structure <my_fs> to <fs1>.

<fs1> = 'A'

unassign <fs1>

assign component field_B of structure <my_fs> to <fs1>.

<fs1> = 'B'

unassign <fs1>

but my issue is that I have not been able to acces table_A and it's fields

Can anyone suggest how I can access the table and it's fields and also how to populate those fields? Please keep in mind that the table does not contain any records so the following statement will not work

Loop at <table_name> assigning <wa_name>

My objective is to access this table and start adding some records.

Thanks in advance for your help.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2008 at 04:49 AM

    Hi SAP Developer,

    Declare a FIELD-SYMBOL for that internal table processing using 'ANY TABLE' addition instead of 'ANY'.

    For example,

    DATA : W_STR      TYPE UPS_YS_CONTENT,
           MY_REF TYPE REF TO DATA,
           WA_CONTENT  TYPE BAPIASCONT.
    
    FIELD-SYMBOLS: <MY_FS> TYPE ANY.
    FIELD-SYMBOLS: <FS1> TYPE ANY TABLE.
    
    START-OF-SELECTION.
      APPEND SY-REPID  TO W_STR-CONTENT.
      APPEND SY-ABCDE  TO W_STR-CONTENT.
      W_STR-LANGU = SY-LANGU.
      W_STR-NEW   = SY-UNAME.
    
      CREATE DATA MY_REF TYPE UPS_YS_CONTENT.
      ASSIGN MY_REF->* TO <MY_FS>.
      <MY_FS> = W_STR.
      ASSIGN COMPONENT 'CONTENT' OF STRUCTURE <MY_FS> TO <FS1>.
      SKIP 1.
      LOOP AT <FS1> INTO WA_CONTENT.
        WRITE : /10 WA_CONTENT-LINE.
      ENDLOOP.
    

    Try this.

    Regards,

    R.Nagarajan.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2008 at 04:50 AM

    Hi,

    As per my understanding of what you wish to do is:

    You need to access the deep structure... Here a table is inside of a table... You want to access this table and add records to it...

    If I am correct then you can do it in the following way...

    DATA: <lfs> TYPE ANY TABLE.

    here you can assign table_a to <lfs> using normal assignment statement...

    Hope this helps.

    Regards,

    Kunjal

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 17, 2009 at 04:42 AM

    Hi,

    I have tried the following code but it is throwing a syntax error.

    Please advise.

    FIELD-SYMBOLS : <DYN_TABLE> TYPE STANDARD TABLE,

    <DYN_WA> TYPE ANY,

    <FIELD> TYPE ANY,

    <FIELD2> TYPE ANY TABLE,

    <TAB> TYPE ANY,

    <TAB_WA> TYPE ANY,

    <FIELD3> TYPE ANY.

    ASSIGN COMPONENT 'XYZSTYLEZYX' OF STRUCTURE <DYN_WA> TO <FIELD2>.

    CREATE DATA TAB_WA LIKE LINE OF <FIELD2>.

    ASSIGN TAB_WA->* TO <TAB_WA>.

    ASSIGN COMPONENT 'FIELDNAME' OF STRUCTURE <TAB_WA> TO <FIELD3>.

    <FIELD3> = 'AREA'.

    APPEND <TAB_WA> TO <FIELD2>.

    It throws an error saying that explicit or implicit index operations are not possible with tables of type 'ANY' or 'HASHED'.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.