10-25-2006 3:25 PM
Hello,
i want to count the amount of entries in connection with a condition. in open-sql its fairly easy.
select count( <field_1> ) into cnt from table where <field_1> = xyz.
how can i rebuild it for an internal table?
thx 4 help
markus
10-25-2006 3:27 PM
hi,
Use <b>describe table</b> statement ... check help for syntax..
REgards,
Santosh
10-25-2006 3:29 PM
Hi Matkus,
<b>Example</b>
DATA: N1 TYPE I,
N2 TYPE I,
ITAB1 TYPE TABLE OF I INITIAL SIZE 10,
ITAB2 TYPE I OCCURS 5.
<b>DESCRIBE TABLE ITAB1 OCCURS N1.
DESCRIBE TABLE ITAB2 OCCURS N2.</b>
Result: OCC contains the value 10 and N2 the value 5.
Reward points if this helps.
Manish
Message was edited by: Manish Kumar
10-25-2006 3:30 PM
Hi Markus,
Use the describe command to get the number of lines.
data: ITAB2 like ITAB1.
data: WS_LINES TYPE I.
LOOP AT ITAB1.
IF ITAB1-FIELD = 'XYZ'.
ITAB2-FIELD = ITAB1-FIELD.
APPEND ITAB2.
ENDLOOP.
Describe table itab2 lines ws_lines.
Regards.
Message was edited by: Biju Varughese
10-25-2006 3:34 PM
Hi,
Do u mean to say total no of records in the internal table ?? If so then use the following:
data: l_count type i.
Describe table i_kna1 lines l_count. (make sure before using this command the internal table already populated other wise count will be zeor only.
Now l_count will be the total no of records in the internal table i_kna1.
Cheers.
10-25-2006 3:42 PM
Hi,
i know that i get with the describe statement the amount of ALL entries of the internal table, but i need the amount of entries whitch matchs the condition and according to my informations abap supports not the following statement.
describe itab lines itab_count where itab-field_1 = 10.
10-25-2006 4:56 PM
There is not a single statement which can give you the result but there are many others way to do it.
One of the them is as below.
DESCRIBE TABLE itab1 LINES lcnt1.
itab1[] = itab[].
DELETE itab1 where {condition or NOT}
DESCRIBE TABLE itab1 LINES lcnt.
lcnt is the number if you use a NOT condition otherwise you can do is lcnt1 - lcnt is the total count.
10-25-2006 3:38 PM
Hi
Please use the loop conditions
<b>loop at itab where field = 'xyz'.
cnt = cnt + 1.
endloop.
Write: cnt.</b>
10-25-2006 3:50 PM
Hi
Yes you are correct there is not one single statement which will give you the required output.
BUt you could check the logic i gave earlier.
i.e
loop at (internal table) where (field) = 10.
cnt = cnt + 1.
endloop.
here cnt will contain the number of entries in the internal table with the field eq 10.
Hope this helps.
10-25-2006 5:29 PM
Hi,
loop at itab.
case itab-fld1.
when 'A'.
cnt = cnt + 1.
endcase.
endloop.
write cnt.
Regards
amole