ABAP中COLLECT的用法

2021-09-06 01:58:34 字數 1172 閱讀 6092

要填充內錶 ,既可逐行 新增資料, 也可複製另 乙個**的 內容。

_ 要計算數 字字段之和 或要確保內 表中沒有出 現重複條目 ,請使用 collect 語句,它根 據標準關鍵 字處理行。

_ 要在內表 現有行之前 插入新行, 請使用 insert 語句。

_ 要將內錶 行插入另一 個內錶中, 請使用 insert 語句的變式 。

_ 要將內錶 條目內容復 製到另乙個 內錶中,並 且覆蓋該目 標**,請 使用 move 語句。

collect的特性讓我看到了企業寫報表的曙光。有的時候我們需要對某個區域或者某個客戶年度營業額進行彙總,於是collect就大派用場了,甚至可以不用跟qad一樣判斷是否有存在這個記錄而進行彙總,sap就已經幫你處理好這一切!

report  z_collect.

data: begin 

of itab occurs 4,

column1(3) type c,

column2(2) type n,

column3    type i,

column4(5) type c,

end 

of itab.

itab-column1 = 'abc'. itab-column2 = '12'. itab-column3 = 3. itab-column4 = 'xyz'.

collect itab.

write / sy-tabix.

itab-column1 = 'def'. itab-column2 = '34'. itab-column3 = 5. itab-column4 = 'xyz'.

collect itab.

write / sy-tabix.

itab-column1 = 'abc'. itab-column2 = '12'. itab-column3 = 15. itab-column4 = 'xyz'.

collect itab.

write / sy-tabix.

loop 

at itab.

write: / itab-column1, itab-column2, itab-column3, itab-column4.

endloop.

結果:abc 12 18 xyz

def 34 5 xyz

看懂了這個結果了嗎??

ABAP中Collect的用法

簡單來說 collect在非數值字段相同的情況下,起到了數值字段彙總作用。語法 collect w table into i table 舉個簡單的栗子 如下 report ztest no standard page heading.types begin of ty test,id 3 type...

abap 中內表處理collect的用法

1說明及 collect是用於內錶去掉重複的行,然後還有數字求和.loop at lt mseg.itab bukrs lt mseg bukrs.itab werks lt mseg werks.itab lifnr lt mseg lifnr.itab matnr lt mseg matnr.i...

Stream中collect方法在業務中的使用

背景 在實際業務中,可能需要把資料庫查詢出來資料的某乙個字段 例如 id等唯一值 新增到集合中 data class person 先查詢資料庫記錄集合 listpersonlist db.querybycond 需要將person中的id全部儲存到新的list,也就是要實現如下功能 把id新增到l...