‎2007 Mar 18 1:48 PM
HELLO FRIENDS,
I have a scenario where, i need to check the entries i a ztable for a field, i have to count how many entries in the field have value X, and how many entries have value Y,
Total number of X entries has to be multiplied by value *, and total number of entries of Y got to be multiplied by 4, and
total has tobe added.
If any one can give me little detailed code, along with declarations, it will be really greatfull to me.
thanks.
‎2007 Mar 18 2:12 PM
Hi,
Please try this.
TABLES: ZTABLE.
DATA: COUNT_X TYPE I,
COUNT_Y TYPE I,
TOTALS TYPE I.
RANGES: R_FIED1 FOR ZTABLE-FIELD1.
R_FIELD1-SIGN = 'I'.
R_FIELD1-OPTION = 'NP'.
R_FIELD1-LOW = '008%'.
APPEND R_FIELD1.
SELECT COUNT( DISTINCT FIELD1 )
INTO COUNT_X
FROM ZTABLE
WHERE FIELD1 LIKE '008%'.
WRITE: / COUNT_X.
SELECT COUNT( DISTINCT FIELD1 )
INTO COUNT_Y
FROM ZTABLE
WHERE FIELD1 IN R_FIELD1.
WRITE: / COUNT_Y.
OR
SELECT FIELD1 COUNT( * )
INTO COUNT_X
FROM ZTABLE
WHERE FIELD1 LIKE '008%'.
WRITE: / COUNT_X.
SELECT FIELD1 COUNT( * )
INTO COUNT_Y
FROM ZTABLE
WHERE FIELD1 IN R_FIELD1.
WRITE: / COUNT_Y.
SKIP.
COUNT_X = COUNT_X * <...>. <--- any number
COUNT_Y = COUNT_Y * 4.
TOTALS = COUNT_X + COUNT_Y.
WRITE: / COUNT_X, COUNT_Y, TOTALS.
Regards,
Ferry Lianto
‎2007 Mar 18 1:51 PM
sorry friends , i forgot toput the condition,
the fields with entries X are those char strings which tart with 008 in the start of the string out of 10 charecters. the field is a 10 charecter string.
thanks again.
‎2007 Mar 18 1:52 PM
the field with entries Y are those who donot have 008 at their starting of the 10 char string.
thanks
‎2007 Mar 18 1:58 PM
Hi,
Please try something like this.
TABLES: ZTABLE.
DATA: COUNT_X TYPE I.
SELECT COUNT( FIELD1 )
INTO COUNT_X
FROM ZTABLE
WHERE FIELD1 LIKE '008%'.
WRITE: / COUNT_X.
Regards,
Ferry Lianto
‎2007 Mar 18 2:07 PM
hi ferry thanks for your reply,
but when i execute it says.
count( field1) is only valid in the extended form count( distinct field1).
can u plz look in to it.
thank you.
‎2007 Mar 18 2:01 PM
Hi...
check this code ...
data :
w_count type i.
w_count1 type i.
w_sum type i.
select count( field1 )
from ztable
into w_count
where field1 like '008%'.
select count( field1 )
from ztable
into w_count1
where field1 not like '008%'.
w_sum = w_count + w_count1.
write : w_count , w_count1 , w_sum.
regards,
sai ramesh
‎2007 Mar 18 2:12 PM
Hi,
Please try this.
TABLES: ZTABLE.
DATA: COUNT_X TYPE I,
COUNT_Y TYPE I,
TOTALS TYPE I.
RANGES: R_FIED1 FOR ZTABLE-FIELD1.
R_FIELD1-SIGN = 'I'.
R_FIELD1-OPTION = 'NP'.
R_FIELD1-LOW = '008%'.
APPEND R_FIELD1.
SELECT COUNT( DISTINCT FIELD1 )
INTO COUNT_X
FROM ZTABLE
WHERE FIELD1 LIKE '008%'.
WRITE: / COUNT_X.
SELECT COUNT( DISTINCT FIELD1 )
INTO COUNT_Y
FROM ZTABLE
WHERE FIELD1 IN R_FIELD1.
WRITE: / COUNT_Y.
OR
SELECT FIELD1 COUNT( * )
INTO COUNT_X
FROM ZTABLE
WHERE FIELD1 LIKE '008%'.
WRITE: / COUNT_X.
SELECT FIELD1 COUNT( * )
INTO COUNT_Y
FROM ZTABLE
WHERE FIELD1 IN R_FIELD1.
WRITE: / COUNT_Y.
SKIP.
COUNT_X = COUNT_X * <...>. <--- any number
COUNT_Y = COUNT_Y * 4.
TOTALS = COUNT_X + COUNT_Y.
WRITE: / COUNT_X, COUNT_Y, TOTALS.
Regards,
Ferry Lianto
‎2007 Mar 18 2:35 PM
thanks ferry,
the first one was only giving distinct values, there are duplicate values too, we nee to count them too. and the second option was giving error saying there should be a goup by cluse.
thanks.
can u once again plz look into it.
‎2007 Mar 18 2:46 PM
friends what i feel is ,
if we create an internal table and only copy those field1 values into that itab where
the field1 contains '008%' and we can use sy-dbcnt.
but i dont know how to code this logic,
can any one plz give me code for this logic thanks.
‎2007 Mar 18 3:37 PM
thanks ferry and ramesh,
i used both of ur code to write the code.
now its working.
thank you so much.
i have a last question, if i use this logic of bringing all fields from database and then checking the sy-dbcnt a good way.
please suggest me what to do.
thanks once again.