四 內錶及其宣告

2022-09-22 06:30:09 字數 2235 閱讀 6290

1.概述:內錶是程式執行過程中建立的儲存空間,是記憶體中建立的臨時表,程式結束後,會被釋放。可對內表執行插入、修改和刪除操作。

2.分類:

表名說明

效率語法

標準表在增加或插入資料行時不對資料行的位址進行重新排序,包含index,可通過index和key查詢,只能包含non unique key,key可為

效率取決於表的行,隨行數線性增加

type table of、type standard table of

排序表在增加或插入資料行時對資料行的位址進行重新排序,包含index,可通過index和key查詢,可包含unique和non unique key,key必需;具有自動排序功能,所以sort關鍵字對其沒有任何意義,還會導致編譯錯誤

效率取決於表的行數,隨行數對數級增長

type sorted table of

雜湊表只能通過關鍵字訪問,在檢索資料裡與資料行數無關,不包含index,只能通過key查詢,只能包含unique key,key必需

效率與行數無關,資料量大的情況下使用關鍵字查詢時最快的

type hashed table of

示例:types:begin of ty_stu,

id type n,

name type string,

age type i,

end of ty_stu.

表名示例

注意標準表

data gt_stu1 type standard table of ty_stu.

只能使用non-unique,可以省略

排序表data gt_stu2 type sorted table of ty_stu with unique key id.

是否可以儲存重複的,取決於定義時指定的key型別是unique還是non-unique

雜湊表data gt_stu3 type hashed table of ty_stu with unique key id.

只能使用unique,不能省略

3.內錶操作:

操作型別

說明語法

追加資料(雜湊表不支援)

① loop at itab1

endloop.

insert

① insert wa into table itab.

② insert lines of itab1 into itab2.

delete

①刪除單行:table key(non-unique型別的表,當查詢多條時,只會刪除第一條)②刪除多行:where③刪除臨近重複行:adjacent duplicate

delete itab.

read

標準表:順序查詢;排序表:二分查詢;雜湊表:根據雜湊演算法查詢

read table itab into wa.

change

modify table itab from wa

collect

內錶分類彙總

①coolect into itab.

②coolect itab.

modify

①修改單條記錄:table key(non-unique型別的表,當查詢多條時,只會修改第一條)②修改多條記錄:where

①根據索引:modify itab from wa index idx.

②根據關鍵字段:modify table itab from wa.

at內錶的第一行觸發

at first.

endat.

內錶的最後一行觸發

at last.

endat.

按內表列f,列的左邊發生改變時觸發(可用於按年、月、日統計)

at new f.

endat.

按內表列f,列的右邊發生改變時觸發

at end of f.

endat.

sort

排序sort itab.

describe

獲取內錶行數

describe table itab lines data(lv_line).

lines

data(lv_data) = lines(itab).

4.清空內錶

clear itab:僅清空header line,對內表資料儲存空間不影響

refresh itab:清空內錶資料儲存空間,對header line不影響

dree itab:清空內錶資料儲存空間,對header line不影響

三 結構及其宣告

說明 type 定義型別 data 建立物件 參照結構體生成結構體,只能用like不能用type 但參照sap標準的結構體生成結構,可以用type 語法types begin of structure1,k1 type 資料型別 k2 type 資料型別 end of structure1.data...

switch語句case內宣告物件

今天本來想使用switch語句來實現不同情況下執行相對應的 在每個case內都需要宣告不同的類的物件,結果出現switch work state ptr cutter type 錯誤 error c2360 cutter1 的初始化操作由 case 標籤跳過 分析原因 在case 可能沒有被執行到時...

內錶 XML互轉 JSON 內錶互轉

轉進內錶 strans try.call transformation id source xml lv text out options clear all 4.7 沒有這個options value handling accept data loss 這個引數也沒有 result data p ...