如何使用opensge中的累积函数计算每个国家/地区的每个州的总余额

时间:2015-03-28 15:15:48

标签: progress-4gl openedge

我试过了这段代码。

DEFINE VARIABLE totalbalance AS DECIMAL     NO-UNDO.

DEFINE FRAME f1

    WITH CENTERED THREE-D SIZE 100 BY 50.
FOR EACH customer NO-LOCK BREAK BY country WITH FRAME f1:

    ACCUMULATE balance(TOTAL BY country).
    IF FIRST-OF(customer.country) THEN
        DISPLAY customer.country.
    DISPLAY customer.state customer.balance.
    IF LAST-OF(customer.country) THEN
    DO:   
         DISPLAY SKIP FILL("-", 25) AT 50 FORMAT "x(25)".
         DISPLAY ACCUM TOTAL customer.balance AT 51.
         DISPLAY SKIP FILL("-", 25) AT 50 FORMAT "x(25)".
    END.
END.

它仅提供每个国家/地区的总余额,但我还想显示每个州的总余额。

1 个答案:

答案 0 :(得分:3)

你没有按州和#34;所以它不会由国家做任何事情。

这样的事情(未经过严格测试):

define frame f1
  with
   centered
.

for each customer no-lock break by country by state with frame f1:

    accumulate balance( total by country ).
    accumulate balance( sub-total by state ).

    if first-of( customer.country ) then
        display customer.country.

    if first-of( customer.state ) then
        display customer.state.

    display customer.balance.

    if last-of( customer.country ) then
      do:
        display skip fill( "-", 25 ) at 50 format "x(25)".
        display accum total customer.balance at 51.
        display skip fill( "-", 25 ) at 50 format "x(25)".
      end.

    if last-of( customer.state ) then
      do:
        display skip fill( "-", 25 ) at 80 format "x(25)".
        display accum sub-total customer.balance at 81.
        display skip fill( "-", 25 ) at 80 format "x(25)".
      end.

end.

(这可能并没有真正起作用......但是多个BY条款是你缺少的主要内容。)

就个人而言,我发现ACCUM语法令人不愉快,不值得打扰。我通常只是创建和管理简单变量。我发现那种编码更加清晰。所以,除非这是一个" gotchya"关于技能测试的问题我强烈建议你避免以这种方式编码。如果它是" gotchya"问题转移到一个更合适的未来雇主 - 你不想为认为这是个好主意的人工作。

我会更喜欢这样做:

define variable countryBalance as decimal no-undo.
define variable stateBalance   as decimal no-undo.

for each customer no-lock break by country by state with frame f1:

    if first-of( customer.country ) then
      do:
        display customer.country.
        countryBalance = 0.
      end.

    if first-of( customer.state ) then
      do:
        display customer.state.
        statebalance = 0.
      end.

    assign
      countryBalance = countryBalance + customer.balance
      stateBalance   = stateBalance  + customer.balance
    .

    display customer.balance.

    if last-of( customer.country ) then
      do:
        display countryBalance.
      end.

    if last-of( customer.state ) then
      do:
        display stateBalance.
      end.

end.

我认为这更容易阅读,理解和维护。