[英]how to get the num of records from a table?
SELECT COUNT(*) AS NumberOfRecords FROM tableX;
我如何將其轉換為 sap ABAP
對於數據庫表,您可以像這樣執行SELECT COUNT
:
SELECT COUNT( * )
INTO numberOfRecords
FROM tableX.
要獲取內部表的行數,您需要DESCRIBE
語句:
DESCRIBE TABLE tableX LINES numberOfRecords.
對於內部表,您也可以使用此內置函數:
numberOfRecords = lines( tableX)
我有一個類似的問題,一位同事讓我關注。 我需要一個鍵的數據庫表中的條目計數,並且沒有在此處輸入代碼想要在循環中執行選擇計數(*)。 因此,我們創建了一個帶有唯一鍵的排序表,在循環之前使用條件在該表中執行 select... endselect 到該表中,並在循環中簡單地讀取這個新的排序表:
types:
begin of ts_tab
f1 type 1
f2 type 2
f3 type i
end of ts_tab
tt_tab type sorted table of ts_tab
with unigue key f1 f2
select f1 f2 into coorresponding fields of ls_tab
read table lt_tab assigning <ls_tab>
with table key f1 = f1 etc.
if sy-subrc = 0.
add 1 to <ls_tab>-f3
else.
ls_tab-f3 = 1.
insert ls_tab into lt_tab.
endif.
endselect
loop etc.
read lt_tab into ls_tab with key f1 = f1 f2 = f2.
if sy-subrc eq 0.
my_count = ls_tabl-f3.
endif
endloop
您可以使用 ABAP 語句:
DESCRIBE TABLE itab[] lines lv_no.
1) 如果您只想要數據庫表中的記錄數,請使用以下語法。
SELECT COUNT( * ) INTO RecordCount FROM tableX.
2)但是,如果您需要處理記錄以及計數,請使用以下內容。
SELECT * INTO TABLE itab FROM tableX.
DESCRIBE TABLE itab[] lines RecordCount.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.