二维码

[基础语法] Field Symbols高级使用教程

Twilight发表于 2016-10-11 14:42luckychn 最后回复于 2019-12-17 11:27 [复制链接] 5140 2

1、通过field-symbols直接复制内表数据
  1. DATA: lt_1 TYPE STANDARD TABLE OF t100.
  2. DATA: lt_2 TYPE STANDARD TABLE OF t100.
  3. FIELD-SYMBOLS: <lt_1> TYPE ANY TABLE.
  4. FIELD-SYMBOLS: <lt_2> TYPE ANY TABLE.

  5. ASSIGN lt_1 TO <lt_1>.

  6. SELECT * FROM t100
  7.   INTO TABLE <lt_1>
  8.   UP TO 10 ROWS.

  9. ASSIGN lt_2 TO <lt_2>.
  10. <lt_2> = <lt_1>.

  11. DATA: lv_lines TYPE i.
  12. lv_lines = lines( lt_2 ).
  13. WRITE: lv_lines.
复制代码

2、通过field-symbols一条条复制内表数据
  1. DATA: lt_1 TYPE STANDARD TABLE OF t100.
  2. DATA: lt_2 TYPE STANDARD TABLE OF t100.
  3. FIELD-SYMBOLS: <ls_1> TYPE t100.
  4. FIELD-SYMBOLS: <ls_2> TYPE t100.

  5. SELECT * FROM t100
  6.   INTO TABLE lt_1
  7.   UP TO 10 ROWS.

  8. LOOP AT lt_1 ASSIGNING <ls_1>.
  9.   APPEND INITIAL LINE TO lt_2 ASSIGNING <ls_2>.
  10.   <ls_2> = <ls_1>.
  11. ENDLOOP.

  12. DATA: lv_lines TYPE i.
  13. lv_lines = lines( lt_2 ).
  14. WRITE: lv_lines.
复制代码

3、Field Symbol 以结构中字段名称访问数据
  1. DATA: lt_1 TYPE STANDARD TABLE OF t100.
  2. FIELD-SYMBOLS: <ls_1> LIKE LINE OF lt_1.

  3. SELECT * FROM t100
  4.   INTO TABLE lt_1
  5.   UP TO 10 ROWS.

  6. * dynamic access
  7. DATA: lv_field TYPE char30.
  8. FIELD-SYMBOLS: <lv_field> TYPE any.
  9. lv_field = 'TEXT'.
  10. LOOP AT lt_1 ASSIGNING <ls_1>.
  11.   ASSIGN COMPONENT lv_field OF STRUCTURE <ls_1> TO <lv_field>.
  12.   CHECK <lv_field> IS ASSIGNED.
  13.   WRITE: / <lv_field>.
  14. ENDLOOP.
复制代码

4、Field Symbol 以结构中字段顺序号访问数据
  1. SELECT * FROM t100
  2.   INTO TABLE lt_1
  3.   UP TO 10 ROWS.

  4. * dynamic access
  5. DATA: lv_comp_number TYPE i.
  6. FIELD-SYMBOLS: <lv_field> TYPE any.
  7. lv_comp_number = 4.
  8. LOOP AT lt_1 ASSIGNING <ls_1>.
  9.   ASSIGN COMPONENT lv_comp_number OF STRUCTURE <ls_1> TO <lv_field>.
  10.   CHECK <lv_field> IS ASSIGNED.
  11.   WRITE: / <lv_field>.
  12. ENDLOOP.
复制代码
回复

使用道具 举报

zlzt
感谢分享
回复

使用道具 举报

luckychn
很实用,很全面的Field Symbol知识
回复 支持 反对

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表