Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Count entries of an internal table

Former Member
0 Kudos

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

9 REPLIES 9

Former Member
0 Kudos

hi,

Use <b>describe table</b> statement ... check help for syntax..

REgards,

Santosh

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

0 Kudos

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.

0 Kudos

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.

Former Member
0 Kudos

Hi

Please use the loop conditions

<b>loop at itab where field = 'xyz'.

cnt = cnt + 1.

endloop.

Write: cnt.</b>

Former Member
0 Kudos

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.

Former Member
0 Kudos

Hi,

loop at itab.

case itab-fld1.

when 'A'.

cnt = cnt + 1.

endcase.

endloop.

write cnt.

Regards

amole