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: 

Field-symbols and internal table

Former Member
0 Kudos

Hello,

How do I declare a field-symbol as an intenal table?

I have a internal table declared, but i need to declare a field symbols as my internal table´s type. How do I do it?

What I wrote was this:

DATA: BEGIN OF IT_INTE OCCURS 0,

FIELD(3) TYPE C,

....

END OF IT_INTE.

FIELD-SYMBOLS: isn´t defined as an internal table, how do I fix it.

Thanks!!!

Gabriel.

1 ACCEPTED SOLUTION

suresh_datti
Active Contributor
0 Kudos

Hi Gabriel,

I think you can only declare a structure a field symbol, not the entire table. ie, instead of declaring a work area--use a field symbol. The work area concept and header line format both require data to be moved from the internal table to the work area or header area. A field symbol is just a pointer that will point to the proper line of the itab. With field symbols, no data needs to be moved. The field symbol just stores the proper memory address to point at the right line. The field symbol can have structure and be made up of fields similar to a work area or header line. Because no data needs to be copied, processing is much faster.

Try this..


types: BEGIN OF it_INTE_line,
FIELD(3) TYPE C,
....
END OF it_INTE_line.
data: it_inte type table of it_INTE_line.
FIELD-SYMBOLS: <MY_IT_INTE> type IT_INTE_line.


LOOP at IT_INTE assigning <MY_IT_INTE>.
...
ENDLOOP.

Regards,

Suresh Datti

8 REPLIES 8

suresh_datti
Active Contributor
0 Kudos

Hi Gabriel,

I think you can only declare a structure a field symbol, not the entire table. ie, instead of declaring a work area--use a field symbol. The work area concept and header line format both require data to be moved from the internal table to the work area or header area. A field symbol is just a pointer that will point to the proper line of the itab. With field symbols, no data needs to be moved. The field symbol just stores the proper memory address to point at the right line. The field symbol can have structure and be made up of fields similar to a work area or header line. Because no data needs to be copied, processing is much faster.

Try this..


types: BEGIN OF it_INTE_line,
FIELD(3) TYPE C,
....
END OF it_INTE_line.
data: it_inte type table of it_INTE_line.
FIELD-SYMBOLS: <MY_IT_INTE> type IT_INTE_line.


LOOP at IT_INTE assigning <MY_IT_INTE>.
...
ENDLOOP.

Regards,

Suresh Datti

0 Kudos

It is very much possible to have a field symbol point to a internal table. Here is some sample code.



report  zrich_0001.

data: begin of itab1 occurs 0,
      fld1(10) type c,
      fld3(10) type c,
      fld5(10) type c,
      end of itab1.
data: wa1 like line of itab1.
field-symbols: <fs_table> type table.
field-symbols: <fs_wa>.
field-SYMBOLS: <fs_field>.

* Setup the data
itab1-fld1 = '0000000001'.
itab1-fld3 = '0000000002'.
itab1-fld5 = '0000000003'.
append itab1.

itab1-fld1 = '0000000004'.
itab1-fld3 = '0000000005'.
itab1-fld5 = '0000000006'.
append itab1.


assign itab1[] to <fs_table>.
assign wa1     to <fs_wa>.

loop at <fs_table> into <fs_wa>.

* Write out each field of the line
  do.
       assign COMPONENT sy-index of structure <fs_wa> to <fs_field>.
    if sy-subrc <> 0.
      exit.
      endif.
      write:/ <fs_field>.
  enddo.
  skip 2.

endloop.


Regards,

Rich Heilman

0 Kudos

Rich,

Thanks for the clarification.. BTW is there any performance gain by assigning the itab to a <fs>?

Regards,

Suresh Datti

0 Kudos

You know, I never really did a study on it. I really only do this kind of thing when working with dynamic internal tables. Maybe a study is in order?

Regards,

Rich Heilman

former_member186741
Active Contributor
0 Kudos

you could try:

types: begin of ty_inte, field(3) type c, end

DATA: IT_INTE type table of ty_inte.

FIELD-SYMBOLS: <MY_IT_INTE> type table,

<it_inte_line> type any.

...

ASSIGN IT_INTE TO <MY_IT_INTE> .

....

LOOP at <MY_IT_INTE> assigning <it_inte_line>

...

ENDLOOP.

hymavathi_oruganti
Active Contributor
0 Kudos

FIELD-SYMBOLS: <FS> TYPE ANY.

LOOP AT ITAB ASSIGNING <FS>.

<FS>-NAME = 'ABC'. "<b>now <FS> is pointing to add of itab</b>

ENDLOOP.

in the above type , there is no need for us to use <b>MODIFY</b> statement to change the contents of itab,

if we change the contents by using <fs> like above.so performance wise assigning <FS> is much better.

Message was edited by: Hymavathi Oruganti

Former Member
0 Kudos

hi,

following are the examples:

1. Adrreses components of flight bookings table sbook using field-symbol.

data sbook_wa like sbook.

fiels-symbols <sb> structure sbook default sbook_wa.

write:/ <sb>-bookid, <sb>-fldate.

2.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Gabriel, Please remember to close this post when solved completely. Thanks.

Regards,

Rich Heilman