Application Development and Automation 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: 
Read only

select count( * ) command at internal tables

Former Member
0 Likes
8,656

Hi,

it is not possible to use a select quiry at internal tables.

I would like determine the number of person with a where

condition at an internal table. How does it work ?

I cant say :

select count( * ) from xxx into xxxxxxx

where xx= xx.

What else can I do ?

Regards

ertas

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
3,275

Rather than loop through the table you could try this.

Your table is itab1. Define a temporary table, itab2, of the same type. NOTE: neither table with header lines. cond is the condition you want the records to meet.

itab2 = itab1.
DELETE itab2 WHERE NOT cond.
no_of_recs_meeting_cond = lines( itab2 ).

Not terribly memory efficient, but it could be a little quicker than looping.

matt

6 REPLIES 6
Read only

Former Member
0 Likes
3,275

hi check this..

PARAMETERS: p_carrid TYPE sbook-carrid,

p_connid TYPE sbook-connid.

TYPES: BEGIN OF sbook_type,

fldate TYPE sbook-fldate,

smoker TYPE sbook-smoker,

smk_cnt TYPE i,

END OF sbook_type.

DATA sbook_tab TYPE TABLE OF sbook_type.

SELECT fldate smoker COUNT( * ) AS smk_cnt

FROM sbook

INTO CORRESPONDING FIELDS OF TABLE sbook_tab

WHERE connid = p_connid

GROUP BY carrid fldate smoker

HAVING carrid = p_carrid

ORDER BY fldate smoker

regards,

venkat

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
3,275

If the data is in an internal table you would have to count it manually.

data: lv_count type i.

clear lv_count.
loop at itab where some_field = 'ABC'.
  lv_count = lv_count + 1.
endloop.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
3,275

Hi,

Use a normal select.

The system variable sy-dbcnt has the number of records from last select statement.

Regards,

Fernando

Read only

valter_oliveira
Active Contributor
0 Likes
3,275

Hello.

Make queries to internal tables it's not possible.

In your specific case, to know the number of rows with a specific WHERE condition, you can do it this way:

- LOOP at itab WHERE condition ...

- after the loop check variable sy-tabix: it return how many lines where found.

Best regards.

Valter Oliveira.

Read only

matt
Active Contributor
0 Likes
3,276

Rather than loop through the table you could try this.

Your table is itab1. Define a temporary table, itab2, of the same type. NOTE: neither table with header lines. cond is the condition you want the records to meet.

itab2 = itab1.
DELETE itab2 WHERE NOT cond.
no_of_recs_meeting_cond = lines( itab2 ).

Not terribly memory efficient, but it could be a little quicker than looping.

matt

Read only

0 Likes
3,275

I think LINES() is available as of release 6.10,

a®