SELECT COUNT(*) AS NumberOfRecords FROM tableX;
how do I convert this to sap ABAP
how to get the num of records from a table?
30k views Asked by your friend At
5
There are 5 answers
0
On
I had a similar issue, and a colleague gave me to following. I needed the counts of entries in a db table for a key, and didn'enter code heret want to do a select count(*) in a loop. So, we created a sorted table with the unique key, did a select... endselect into that table with the condition BEFORE the loop, and in the loop simply read this new sorted table:
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
3
On
1) If you just want the count of the records in database table, use the following syntax.
SELECT COUNT( * ) INTO RecordCount FROM tableX.
2) But, if you need the records for processing, as well as the count then use following.
SELECT * INTO TABLE itab FROM tableX.
DESCRIBE TABLE itab[] lines RecordCount.
For database tables you can do
SELECT COUNT
like this:To get the line count of an internal table you need the
DESCRIBE
statement: