Field symbol:用来访问分配给他的变量,任何对于field symbol的操作等同于对其分配变量的操作,field symbol可看作是dereferenced指针,只能对其指向的内容进行操作,即其只有值属性。可以通过给field symbol指定type那么就保证了只有兼容的变量可以分配给他。用语句<fs> IS ASSIGNED用来判断field symbol是否被分配,通过unassign <fs>是<fs>points nothing。可以通过casting把一个不同类型的变量分配给一个<fs>。通过field symbol来访问这个变量时,这个变量就被认为是field symbol所具有的类型了。举例如下:
REPORT ZTESTFSCAST.
TYPES: BEGIN OF st_date,
year(4) TYPE c,
month(2) TYPE c,
day(2) TYPE c,
END OF st_date.
*FIELD-SYMBOLS <fs> TYPE st_date.
FIELD-SYMBOLS <fs> TYPE ANY.
FIELD-SYMBOLS <fd> TYPE ANY.
*ASSIGN sy-datum TO <fs> CASTING.
ASSIGN sy-datum TO <fs> CASTING TYPE st_date.
*WRITE: <fs>-year,
* <fs>-month,
* <fs>-day.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs> TO <fd>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
WRITE:/ <fd>.
ENDDO.
不过在使用CASTING TYPE时,就不能静态指定其包含的component了如例。CASTING TYPE的应用实例如下:
REPORT ZTESTFSCASTTYPE.
PARAMETERS: p_tabam TYPE dd02l-tabname OBLIGATORY.
DATA: line(65535) TYPE c.
FIELD-SYMBOLS: <fs_line> TYPE ANY,
<fd> TYPE ANY.
ASSIGN line TO <fs_line> CASTING TYPE (p_tabam).
SELECT * FROM (p_tabam) INTO <fs_line>.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs_line> TO <fd>.
IF sy-subrc <> 0 OR sy-index > 5.
WRITE: '|'.
EXIT.
ENDIF.
WRITE: '|'.
WRITE: <fd>.
ENDDO.
ULINE.
ENDSELECT.