02-18-2006 9:09 PM
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.
02-18-2006 9:43 PM
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
02-18-2006 9:43 PM
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
02-18-2006 11:31 PM
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
02-18-2006 11:39 PM
Rich,
Thanks for the clarification.. BTW is there any performance gain by assigning the itab to a <fs>?
Regards,
Suresh Datti
02-18-2006 11:44 PM
02-20-2006 12:32 AM
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.
02-20-2006 4:42 AM
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
02-20-2006 5:43 AM
02-20-2006 2:22 PM