欢迎来到萧静默的博客

书山有路勤为径,学海无涯苦作舟。

动态、指针field-symbols初探

DATA: BEGIN OF STRUC,
        COMP1 TYPE C LENGTH 1 VALUE '1',
        COMP2 TYPE C LENGTH 20 VALUE '22222',
        COMP3 TYPE STRING VALUE 'bruce king',
      END OF STRUC,
      COMP_VALUE TYPE C LENGTH 10 VALUE 'value',
      COMP_NAME  TYPE C LENGTH 15.

FIELD-SYMBOLS: <FS> .
"指派结构的一个字段给<fs>
ASSIGN STRUC-COMP1 TO <FS>.  WRITE:/ '第一个',<FS>. " 输出:1
"指派结构字段的基地址加上两倍此字段长度的地址给字段符号
ASSIGN STRUC-COMP1 INCREMENT 2 TO <FS>. WRITE:/ '第二个',<FS>. " 输出: 1
"指派结构的第二个组件字段给字段符号
ASSIGN COMPONENT 2 OF STRUCTURE STRUC TO <FS>.  WRITE:/ '第三个',<FS>. " 输出:22222

ASSIGN COMPONENT 3 OF STRUCTURE STRUC TO <FS>. WRITE:/ '第四个',<FS>.
"动态指定字段名,一般不用
COMP_NAME = 'comp_value'.
ASSIGN (COMP_NAME) TO <FS>. WRITE:/ '第五个',<FS>. "输出:value
ASSIGN COMP_NAME TO <FS>. WRITE:/ '第六个',<FS>. "输出:comp_value

 

 

posted @ 2020-02-28 13:54  萧静默  阅读(257)  评论(0编辑  收藏  举报