如何从一个人的输出中获得结果?(循环中循环)



我想找出答案。来自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.

对于"可能出了什么问题",请参阅@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.

您的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中有一个聚合函数!)

始终使用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-<???>

相关内容

  • 没有找到相关文章

最新更新