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(*) from

glittle_tjc
Explorer
0 Likes
19,950

Hello experts

I use the following statements to obtain the number of entries in a db table matching my criteria:

data: lv_extractrows TYPE i.

SELECT COUNT(*) FROM (P_TABNAME) BYPASSING BUFFER

WHERE (cond_syntax).

lv_extractrows = sy-dbcnt.

What is strange is that this works fine for large numbers of entries but when it runs with a cond_syntax that should return 2 entries it returns 0 entries...(sy-dbcnt = 0).

If I check in SE11 'number of entries' for cond_syntax it returns 2.

Can anyone say why the code works fine for 12k entries but not for 2?

Thanks

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
10,657

Hello Graham,

What is the value in cond_syntax at run-time for which it is giving an error ?

Can you share this detail with us?

BR,

Suhas

13 REPLIES 13
Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
10,657

Hi,

Try it this way:


data: lv_extractrows TYPE i.

SELECT COUNT(*)
FROM (P_TABNAME)
INTO (lv_extractrows)
WHERE (cond_syntax).

Hope this solves your problem.

Thanks & Regards,

Tarun Gambhir

Read only

0 Likes
10,657

Hi Tarun

Thanks for the code - I already tried this way originally but it doesn't work either.

I changed it to the way above after looking at the code in SE11.

The problem is the select doesn't return the value 2 (it returns sy-dbcnt = 0)

Graham

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
10,658

Hello Graham,

What is the value in cond_syntax at run-time for which it is giving an error ?

Can you share this detail with us?

BR,

Suhas

Read only

0 Likes
10,657

Hi Suhas

The vales are filled depending on the call of the routine.

In this case P_TABNAME is BSEG and for the testing the values in cond_syntax are:

BELNR EQ 0100000000 AND BUKRS EQ 0001 AND BUZEI GE 001 AND GJAHR EQ 1995

If I try with BUKRS EQ 0001 AND GJAHR EQ 1995 I get 0 entries back when I expect 2

If I try with BUKRS EQ 1000 AND GJAHR EQ 1995 I get 12k entries back when I expect 12K - so correct.

thanks

Graham

Read only

Former Member
0 Likes
10,657

The SELECT statement has to return the dbcount.

You just Make sure that WHERE condition is passed on properly.

You can also check the DB Table for which you want to see the count(SE11) and see if the your condition is working here for at least one value.

Read only

Former Member
0 Likes
10,657

Hi Graham,

In below statement

BUKRS EQ 0001 AND GJAHR EQ 1995

when you fill condition for BUKRS make sure that it is '0001' and not '1'

Regards,

Manoj Kumar P

Read only

0 Likes
10,657

Hi Yogesh

Yes, this is what I don't understand.

Using the same code with the same style cond_syntax, one case returns the correct value and the other not.

In SE11 it returns the correct values all the time.

This makes me think I've missed out something somewhere but I have no idea what.

Thanks

Graham

Read only

0 Likes
10,657

It's probably because BUKRS = 0001 is selecting effectively as BUKRS = 1, so try with BUKRS = '0001'.

Thomas

Read only

0 Likes
10,657

Hi Manoj

It is 0001, the line in the post is a direct cut and paste from debugging.

Maybe I should try it as '0001'.

Thanks

Graham

Read only

0 Likes
10,657

Hi Thomas, Mahesh

Excellent!

I just put in some ' ' in debugging and it works.

Thanks

Graham

Read only

Former Member
0 Likes
10,657

This may be beacause of any errors in the condition in the cond_syntax. some thing may be missed in that..can pls specify the code. ie,values of P_TABNAME and cond_syntax.

Read only

former_member222860
Active Contributor
0 Likes
10,657

Hi,

Pass the values of BUKRS and BELNR with single( ' ) quotes like '0001'.

Read only

0 Likes
10,657

Hi Mahesh

I'll try it now.

Thanks

Graham