使用Break By for Multiple Fields

时间:2015-09-26 01:24:16

标签: break progress-4gl openedge progress-db

我想问一下如何在for each语句中使用多个break。

样品:

Car Code   Color Code
0001       002
0001       002
0001       001
0005       003
0005       002
0007       001
0008       001
0008       005
0008       001

我的代码是:

def var ctr as int.

对于每辆汽车,通过颜色代码按车号码解锁。

   ctr = ctr + 1.


/*I tried*/
   if last-of(carcode) and last-of(colorcode) then do:
      disp carcode colorcode ctr.
      ctr = 0.
   end. 


/*and tried*/
   last-of(colorcode) then do:
      if last-of(carcode) 
         disp carcode colorcode ctr.
         ctr = 0.
      end.
   end. 
end.

我的预期输出是:

car code   Color Code    QTY
0001       001           1
0001       002           2
0005       002           1
0005       003           1
0007       001           1
0008       001           2
0008       005           1

3 个答案:

答案 0 :(得分:1)

试试这个:

GHCi> printListTuples [(123, "foo"), (456, "bar")]
"foo 1,2,3\nbar 4,5,6\n"

LAST-OF(颜色代码)可能为真,而LAST-OF(carcode)可能为假,因此将AND更改为OR。

如果LAST-OF(carcode)为真,则LAST-OF(colorcode)也将为真。

答案 1 :(得分:0)

当我检查代码时,我忽略了使用last-of并使用了临时表和缓冲区。

def buffer btt-car for tt-car.

find first tt-car where tt-car.carcode = car.carcode exclusive.
if not avail tt-car then do:
  create tt-car.
  assign tt-car.car-code = car.carcode
  tt-car.color-code = car.colorcode
  tt-car.qty = tt-car.qty + car.qty.
end.
if avail tt-car then do:
  find first btt-car where btt-car.colorcode = car.colorcode exclusive.
  if not avail btt-car then do:
    create btt-car.
    assign btt-car.car-code = car.carcode
    btt-car.color-code = car.colorcode
    btt-car.qty = btt-car.qty + car.qty.
  end.
  if avail btt-car then assign btt-car.qty = btt-car.qty + car.qty.
end.

但如果你们有使用最后一个休息时间的解决方案,请分享..

感谢

答案 2 :(得分:0)

这样的事情应该有效:

for each car 
    no-lock
    break by car.carcode
          by car.colorcode
:

    accumulate car.colorcode (count by car.colorcode).

    if last-of(car.colorcode)
    then
        display car.carcode 
                car.colorcode
                (accum count by car.colorcode car.colorcode).

end.

当然,如果需要,您可以使用变量而不是ACCUMULATE。