How to 'group by' using variables in 4gl

前端 未结 2 713
感动是毒
感动是毒 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:12

    Yes, of course you can, very basic:

    DEFINE VARIABLE v-sell-price AS INTEGER NO-UNDO.
    DEFINE VARIABLE v-cost-price AS INTEGER NO-UNDO.
    
    FOR EACH order BREAK BY order.invoice:
    
        /* Sum the prices */
        ASSIGN 
            v-sell-price = v-sell-price + Order.sell-price.
            v-cost-price = v-cost-price + Order.cost-price. 
    
        /* On the last order matching this order display and reset sums */
        IF LAST-OF(order.invoice) THEN DO:
    
            DISPLAY Order.invoice v-sell-price v-cost-price.
            ASSIGN 
                v-sell-price = 0
                v-cost-price = 0.
        END.
    END.
    

提交回复
热议问题