字段符号可以看作仅是已经被解除引用的指针(类似于C语言中带有解引用操作符 * 的指针),但更像是C++中的引用类型(int i ;&ii= i;),即某个变量的别名,它与真真的指针还是有很大的区别的,在ABAP中引用变量则就是C语言中的指针。 添加链接描述
DATA : gv_1 TYPE c VALUE 'A',
gv_2 TYPE c VALUE 'B',
gv_3 TYPE c VALUE 'C',
gv_4 TYPE c VALUE 'D',
gv_5 TYPE c VALUE 'E'.
DATA : gv_name TYPE c LENGTH 10,
gv_idx TYPE n.
FIELD-SYMBOLS : <fs>.
DO 5 TIMES .
CLEAR : gv_name.
gv_name = 'GV_'.
gv_idx = sy-index.
CONCATENATE gv_name gv_idx INTO gv_name.
ASSIGN (gv_name) TO <fs>.
WRITE : <fs>.
ENDDO.
DATA : BEGIN OF gs_str,
col1 TYPE char5 VALUE 'CHINA',
col2 TYPE char10 VALUE 'BEIJING',
col3 TYPE char15 VALUE 'TWIN BUILDING',
END OF gs_str.
FIELD-SYMBOLS : <fs1> LIKE gs_str,
<fs2> TYPE any.
ASSIGN gs_str TO <fs1>.
DO 3 TIMES.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs1> TO <fs2>.
WRITE <fs2>.
ENDDO.
Field Symbol语句与内表
TYPES : BEGIN OF t_line,
col1 TYPE c ,
col2 TYPE c,
END OF t_line.
DATA : gs_wa TYPE t_line ,
gt_itab TYPE HASHED TABLE OF t_line WITH UNIQUE KEY col1,
gv_key(4) TYPE c VALUE 'col1'.
FIELD-SYMBOLS <fs> TYPE ANY TABLE.
ASSIGN gt_itab TO <fs>.
READ TABLE <fs> WITH TABLE KEY (gv_key) = 'X' INTO gs_wa.
WRITE : gs_wa-col1.
DATA : BEGIN OF gs_line,
carrid TYPE sflight-carrid,
connid TYPE sflight-carrid,
carrname TYPE scarr-carrname ,
END OF gs_line.
DATA gt_line LIKE TABLE OF gs_line.
FIELD-SYMBOLS <fs> LIKE gs_line.
SELECT carrid connid INTO CORRESPONDING FIELDS OF TABLE gt_line FROM sflight.
LOOP AT gt_line ASSIGNING <fs>.
SELECT SINGLE carrname INTO <fs>-carrname FROM scarr WHERE carrid = <fs>-carrid.
ENDLOOP.
-
TYPE REF TO 用来定义一个数据对象,这个数据对象是用来指向另外的数据的; *TYPE用来定义一个数据对象,它本身就是一个存储数据的对象,不是用来指向别的数据对象的. -
DATA: r1 TYPE REF TO c1. *属于ABAP面向对象编程,c1是一个类,r1定义了这个类的对象 -
数据引用
PARAMETERS : p_tname(30) DEFAULT 'SFLIGHT'.
DATA : dref TYPE REF TO data.
FIELD-SYMBOLS : <fs1> TYPE any,<fs2> TYPE any.
CREATE DATA dref TYPE (p_tname).
ASSIGN dref->* to <fs1>.
SELECT * FROM (p_tname) INTO <fs1> UP TO 3 ROWS.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs1> TO <fs2>.
IF sy-subrc NE 0.
SKIP.
EXIT.
ENDIF.
WRITE : <fs2>.
ENDDO.
ENDSELECT.
|