Application Development 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: 

Accessing with deep structures using Field Symbols

former_member445996
Participant
0 Kudos

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.

5 REPLIES 5

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

Hi,

If you have this error, it is because you have declared <FIELD2> as ANY TABLE. In this case, ABAP don't know if it is a STANDARD / SORTED or HASHED table...

And in your last line you use command APPEND <TAB_WA> TO <FIELD2>. which can not be used with HASHED tables : it uses indexes...

So you can correct your correct with one of these 2 solutions :

1st - Declare <FIELD2> as STANDARD TABLE (or SORTED TABLE if you prefer)

2nd - Modify your last line with the following one :

INSERT <TAB_WA> INTO TABLE <FIELD2>.

Best regards,

Samuel

0 Kudos

Thanks a lot Samuel...

Your solution has solved my problem.