abap 中的内表操作

来源:互联网 发布:mac添加不了qq邮箱 编辑:程序博客网 时间:2024/06/04 17:59
  • 声明内表

(1)
data: begin of itab occurs 0,
     a type  c,
end of itab.

 

data: begin of itab occurs 0.

    include structure mara.

    include type ty_self.
     data a type  c.
data:end of itab.

 

(2)
DATA itab TYPE TABLE OF t-tab WITH HEADER LINE.

(3)
DATA  itab like  table of  stuc WITH HEADER LINE.
DATA  itab TYPE  table of  rowtype WITH HEADER LINE.
(4)
DATA itab LIKE itab OCCURS 0 WITH HEADER LINE.

DATA itab type tabtype   WITH HEADER LINE.

  • 类型定义

针对于内表与结构,类型也有表类型和行类型之分。

types:   begin of ty_itab ,
     a type  c,
end of ty_itab.

 

types:ty_itab1 type table of ty_itab.

types:ty_itab2 type line of ty_itab1.

 

types:   begin of ty_itab .

    include structure mara.

    include type ty_itab.
   types:  data a type  c,
   end of itab.

 

 

types:aa type ty_itab.

 

types:bb type ty_itab occurs 0.

 

types: cc like itab occurs 0.

 

types: cc like itab .

 

 

  • 内表清空

refresh itab    "清除内表数据
clear  itab      "清除没有headerline的内表数据,或者有headerline的内表工作区数据。
free itab      " 清除内表内容,并收回内存

  • 内表数据删除

(1) delete itab where name = 'northsnow'.
(2) delete itab index i.  (利用 sy-tabix)
(3)
loop at itab.
    delete itab.   相当于delete itab index i.  ,只不过是省略了 index i
endloop.          
或者
loop at itab.
    delete itab index sy-tabix.
endloop.     
(4)
delete itab from n1 to n2    (利用 sy-tabix)

 

(5) delete itab from wa   根据关键字删除

 

(6)  DELETE ADJACENT DUPLICATES FROM itab
         COMPARING fieldlist.  删除重复的数据

where 条件和 from to 条件可以同时使用,处理两个条件的交集

 

  • 内表记录数

(1)  data a type i.

       a = lines( itab ).

 

(2)  data a type i.

      describe table itab lines a.

原创粉丝点击