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

COUNT(*) problem

Former Member
0 Likes
506

Hello,

I have the following select statement:

SELECT COUNT( * ) FROM marc

JOIN mard ON marcmatnr = mardmatnr

JOIN mara ON marcmatnr = maramatnr

JOIN eina ON maramatnr = einamatnr

JOIN lfa1 ON einalifnr = lfa1lifnr

JOIN wtaddi ON marcmatnr = wtaddimatnr

INTO COUNT_PROMO_ZERO

WHERE marc~werks = p_plant

AND mard~labst = 0

AND eina~loekz <> 'X'

AND lfa1~sperq NOT IN ('01','02','03')

AND lfa1~sperm <> 'X'

AND mara~lvorm <>'X'

AND mara~mstae NOT IN ('01','02','03')

AND marc~matnr = p_matnr.

COUNT_PROMO_ZERO is a type i variable.

My problem is that if I run this statement for a material(matnr) with field mard~labst > 0, the count_promo_zero is 1. Why?

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
475

In your join between MARC and MARD you forget fields WERKS. Your request make a mix of MARC and MARD with different WERKS.

So i think there is a record with a WERKS <> p_plant and labst <> 0

ADD: marcwerks = mardwerks in the JOIN MARD.

(Check all your JOIN, to get the whole set of key)

Regards

3 REPLIES 3
Read only

RaymondGiuseppi
Active Contributor
0 Likes
476

In your join between MARC and MARD you forget fields WERKS. Your request make a mix of MARC and MARD with different WERKS.

So i think there is a record with a WERKS <> p_plant and labst <> 0

ADD: marcwerks = mardwerks in the JOIN MARD.

(Check all your JOIN, to get the whole set of key)

Regards

Read only

Former Member
0 Likes
475

Hi George,

As per raymond, check your keys declaration and where clause. Do u have the parameter for matnr?

Regards,

Kumar.

Read only

Former Member
0 Likes
475

sorry i cant get your actual query count(*) returns the how many lines are read by the select query ..for your case i think it only fetch one record so it is giing 1 to you.

regards

shiba dutta