我试图找出答案。来自City = Liverpool的客户表中的预订;但它似乎给了我错误的结果。什么可能出错?
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.
答案 0 :(得分:1)
对于"可能出现什么问题",请参阅@knut的诊断:每个客户都得到相同的编号,因为您总是选择完整的sbook表。
对于这样的问题,最好将聚合,分组等留给数据库。试试这个版本:
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.
答案 1 :(得分:0)
您的Select * from sbook.
不包含任何其他条件。因此,您可以在每个循环中计算sbook中的所有条目,而不仅仅是与scustom
中的条目相关联的条目。
我不知道表格,所以我无法给你正确的选择。
你数不高,你不需要自己计算:
Tables : scustom,
sbook.
Data : ABCtable type scustom,
BKcnt(4) type N.
Clear BKcnt.
Select * from scustom into ABCtable where city = 'Liverpool'.
Select count(*) into BKcnt from sbook
where <???> = ABCtable-<???>. "I don't know your keys, replace <???> with the correct fields.
Write: / ABCtable-id,
15 ABCtable-name,
50 BKcnt.
ENDSELECT.
(我希望我的select count
是正确的。请使用语法检查器进行检查。至少在ABAP中有聚合函数!)
答案 2 :(得分:-1)
始终使用FOR ALL ENTRIES
加入两个表以获得更好的效果。
SELECT * FROM scustom INTO TABLE ABCtable WHERE city = 'Liverpool'
SELECT count(*) INTO BKcnt FROM sbook FOR ALL ENTRIES IN ABCtable
WHERE <???> = ABCtable-<???>