How to 'group by' using variables in 4gl

前端 未结 2 698
感动是毒
感动是毒 2021-01-28 13:30

Is there a way to group records by a field within a table within a 4gl query?

My code.

  define variable v-invoice     as inte    no-undo.
define variabl         


        
2条回答
  •  余生分开走
    2021-01-28 14:04

    Actually this is what the ACCUMULATE STATEMENT and the ACCUM function are meant for. I find the exact syntax for those somewhat hard to remember (and sometimes difficult to understand even after reading the online help), so I often resort to accumulating the variables myself like in Jensd's answer. The code for your example should look something like this (syntax-checked but not tested):

    FOR EACH order BREAK BY order.invoice:
    
        accumulate Order.sell-price (sub-total by order.invoice).
        accumulate Order.cost-price (sub-total by order.invoice).
    
        IF LAST-OF(order.invoice) THEN
    
            DISPLAY Order.invoice 
              accum sub-total by order.invoice Order.sell-price
              accum sub-total by order.invoice Order.cost-price.
    END.
    

提交回复
热议问题