ABAP中内表的几个常用的清空内表语句,及它们之间的区别

时间:2021-09-09 16:27:39

CLEAR、REFRESH、FREE功能对比:


clear itab,仅清空HEADER LINE,对内表数据存储空间不影响,保留内存区。 

clear itab[],清空内表数据存储空间里的内容。

refresh itab,不清空HEADER LINE,清除内表数据存储空间,但保存内存区。 

free itab,不清空HEADER LINE,清空内表数据存储空间。



例子:

REPORT ZZZZZZZZZ.

types:begin of head, mantr(10) type c, id(10) type c, end of head. data gt_head type table of head with header line.

gt_head-mantr = 'wo'. gt_head-id = '00001'. append gt_head.

gt_head-mantr = 'you'. gt_head-id = '00002'. append gt_head.

free gt_head. write:gt_head.

loop at gt_head. write: / gt_head. endloop.

gt_head-mantr = 'he'. gt_head-id = '00003'. append gt_head. write:gt_head.