I am trying to find out the no. of bookings from a table where customer from City = Liverpool; but it seems to give me wrong results. What could have gone wrong?
Tables : scustom,
sbook.
Data : ABCtable type scustom,
BKcnt(4) type N.
Clear BKcnt.
Select * from scustom into ABCtable where city = 'Liverpool'.
Select * from sbook.
BKcnt = BKcnt + 1.
Endselect.
Write: / ABCtable-id,
15 ABCtable-name,
50 BKcnt.
ENDSELECT.
For "What could have gone wrong", see the diagnosis of @knut : You get the same number for each customer, since you always select the complete sbook table.
For questions like this, it is better to leave the aggregation, grouping etc. to the database. Try this version:
report zz_count_sbook.
parameters: p_city type scustom-city lower case default 'Liverpool'.
data: id type scustom-id,
name type scustom-name,
count type i.
select customid name count(*) into (id,name,count)
from scustom as c
join sbook as b
on b~customid = c~id
where city eq p_city
group by customid name.
write: / id,
15 name,
50 count.
endselect.