0

我试图找出不。来自城市 = 利物浦的客户的表中的预订;但这似乎给了我错误的结果。可能出了什么问题?

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.
4

3 回答 3

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.
于 2014-07-07T05:48:29.500 回答
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中有聚合功能!)

于 2014-07-06T18:19:54.300 回答
-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-<???>
于 2014-07-28T20:19:08.637 回答