CLEAR、REFRESH、FREE
内表:如果使用有表头行的内表,CLEAR 仅清除表格工作区域。例如 clear gs-school 清除工作区。
要重置整个内表而不清除表格工作区域,使用REFRESH语句或 CLEAR 语句CLEAR <itab>[].;REFRESH加不加中括号都是只清内表,另外REFRESH是专为清内表的,不能清基本类型变量,但CLEAR可以清基本类型变量。例如 clear gs-school[] 等价于 refresh gs-school 等价于 refresh gs-school[]。
CLEAR、REFRESH语句都不会释放掉内表所占用的空间。
如果想初始化内表的同时还要释放所占用的空间,请使用:FREE <itab>. 比如 free gs-school 可以释放内表空间。
TYPES: BEGIN OF ty_school,
schoolno() TYPE c,
schoolname() TYPE c,
END OF ty_school.
DATA gt_school TYPE TABLE OF ty_school WITH HEADER LINE. gt_school-schoolno = ''.
gt_school-schoolname = '学生1'.
APPEND gt_school.
CLEAR gt_school. gt_school-schoolno = ''.
gt_school-schoolname = '学生2'.
APPEND gt_school.
CLEAR gt_school. gt_school-schoolno = ''.
gt_school-schoolname = '学生3'.
INSERT gt_school INDEX .
CLEAR gt_school. WRITE '输出全表为:'.
LOOP AT gt_school.
WRITE / gt_school.
ENDLOOP. gt_school-schoolno = ''.
gt_school-schoolname = '修改学生3'.
MODIFY gt_school INDEX .
CLEAR gt_school.
WRITE / '输出全表为:'.
LOOP AT gt_school.
WRITE / gt_school.
ENDLOOP.
CLEAR gt_school. READ TABLE gt_school WITH KEY schoolno = ''.
WRITE: / '读取到的行为:',gt_school.
CLEAR gt_school. DELETE TABLE gt_school WITH TABLE KEY schoolno = '' schoolname = '修改学生3'.
WRITE / '删除后的结果为:'.
LOOP AT gt_school.
WRITE / gt_school.
ENDLOOP.
gt_school-schoolno = ''.
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.