1. 程式人生 > >abap 中的內表操作

abap 中的內表操作

  • 宣告內表

(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.