‎2007 Sep 26 8:18 AM
Hello everyone,
I want to be able to SELECT COUNT(*) from an internal table where a certain
condition exists i.e. COL1 = 'A' like you would do with a normal database table.
Does anyone have any tricks up their sleeves to do this???
Andy
‎2007 Sep 26 8:21 AM
Hi
If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself. Some of the Aggregate functions allowed in SAP are MAX, MIN, AVG, SUM, COUNT, COUNT( * )
Consider the following extract.
Maxno = 0.
Select * from zflight where airln = LF and cntry = IN.
Check zflight-fligh > maxno.
Maxno = zflight-fligh.
Endselect.
The above mentioned code can be much more optimized by using the following code.
Select max( fligh ) from zflight into maxno where airln = LF and cntry = IN.
If you want to count number of records then
LV_COUNT = 0.
LOOP AT IT_OUTPUT INTO WA_OUTPUT.
LV_COUNT = LV_COUNT + 1.
WA_OUTPUT-COUNT = LV_COUNT.
APPEND WA_OUTPUT TO IT_OUTPUT_1.
ENDLOOP.
REFRESH IT_OUTPUT.
IT_OUTPUT = IT_OUTPUT_1.
reward if usefull
‎2007 Sep 26 8:21 AM
Hi
If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself. Some of the Aggregate functions allowed in SAP are MAX, MIN, AVG, SUM, COUNT, COUNT( * )
Consider the following extract.
Maxno = 0.
Select * from zflight where airln = LF and cntry = IN.
Check zflight-fligh > maxno.
Maxno = zflight-fligh.
Endselect.
The above mentioned code can be much more optimized by using the following code.
Select max( fligh ) from zflight into maxno where airln = LF and cntry = IN.
If you want to count number of records then
LV_COUNT = 0.
LOOP AT IT_OUTPUT INTO WA_OUTPUT.
LV_COUNT = LV_COUNT + 1.
WA_OUTPUT-COUNT = LV_COUNT.
APPEND WA_OUTPUT TO IT_OUTPUT_1.
ENDLOOP.
REFRESH IT_OUTPUT.
IT_OUTPUT = IT_OUTPUT_1.
reward if usefull
‎2007 Sep 26 8:22 AM
We cannot directly have the count.
Check these options -
You cannot find the count in one direct statement. You will have to use the count() in your select, or if that is not possible, then:
Easy option:
loop at itab where field1 = condition1.
counter = counter + 1.
endloop.
A lesser easy way, and not always feasible:
itab_copy[] = itab[].
delete itab_copy where field1 NE condition1.
describe table itab_copy lines lv_lines.
~ As found in forum
Regards,
Amit
Reward all helpful replies.
‎2007 Sep 26 8:23 AM
hi
good
go through this link
http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/dba09d35c111d1829f0000e829fbfe/content.htm
thanks
mrutyun^
‎2007 Sep 26 8:28 AM
Hi,
Use
loop at itab where field1 = condition1 (e.g col1 = 'A').
counter = counter + 1.
endloop.
If it is helpful pls rewards points.
Regards
Srimanta