ABAP区别CLEAR、REFRESH、FREE

CLEAR、REFRESHFREE

内表:如果使用有表头行的内表,CLEAR 仅清除表格工作区域。

要重置整个内表而不清除表格工作区域,使用REFRESH语句或 CLEAR 语句CLEAR <itab>[].;REFRESH加不加中括号都是只清内表,另外REFRESH是专为清内表的,不能清基本类型变量,但CLEAR可以清基本类型变量。

CLEAR、REFRESH语句都不会释放掉内表所占用的空间。

如果想初始化内表的同时还要释放所占用的空间,请使用:FREE <itab>.

TYPESBEGIN OF ty_school,

   schoolno(8TYPE c,

   schoolname(20TYPE c,

  END OF ty_school.

DATA gt_school TYPE TABLE OF ty_school WITH HEADER LINE.

gt_school-schoolno '20190001'.

gt_school-schoolname '学生1'.

APPEND gt_school.

CLEAR gt_school.

gt_school-schoolno '20190002'.

gt_school-schoolname '学生2'.

APPEND gt_school.

CLEAR gt_school.

gt_school-schoolno '20190003'.

gt_school-schoolname '学生3'.

INSERT gt_school INDEX 3.

CLEAR gt_school.

WRITE '输出全表为:'.

LOOP AT gt_school.

  WRITE / gt_school.

ENDLOOP.

gt_school-schoolno '20190003'.

gt_school-schoolname '修改学生3'.

MODIFY gt_school INDEX 3.

CLEAR gt_school.

WRITE / '输出全表为:'.

LOOP AT gt_school.


  WRITE / gt_school.

ENDLOOP.

CLEAR gt_school.

READ TABLE gt_school WITH KEY schoolno '20190003'.

WRITE: /  '读取到的行为:',gt_school.

CLEAR gt_school.



DELETE TABLE gt_school WITH TABLE KEY schoolno '20190003' schoolname '修改学生3'.

WRITE / '删除后的结果为:'.

LOOP AT gt_school.

  WRITE / gt_school.

ENDLOOP.

gt_school-schoolno '20190003'.

gt_school-schoolname '修改学生3'.

REFRESH gt_school.

APPEND gt_school.

CLEAR gt_school[].

Free gt_school.

APPEND gt_school.

CLEAR gt_school.

CLEAR gt_school.
 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyjwww.html