Show SUM

velo85

New Member
Code:
DEF STREAM velorob.
OUTPUT STREAM velorob TO "d:\velo\veloroba.txt".
DEFINE VARIABLE centrala AS INTEGER NO-UNDO.
centrala = 0.

    FOR EACH komdet WHERE komdet.vrs = "centrala"
    AND komdet.opis = "0522",

    EACH komit WHERE komit.sifkom = komdet.sifkom,
    EACH rromat WHERE rromat.sifkom = komdet.sifkom
    AND rromat.sifrob = "6306 "
    AND rromat.kto = "mg1"
    AND rromat.datdok > 01/01/2018
    AND rromat.datdok < 01/31/2018,
    EACH roba WHERE roba.sifra = rromat.sifrob.
    centrala = centrala + rromat.izkol.
EXPORT STREAM velorob DELIMITER "," centrala.
END.
OUTPUT STREAM velorob CLOSE.

With this a get all changes to centrala var. I want only last output. Is there any solution.
 
Last edited by a moderator:

TomBascom

Curmudgeon
You might want to consider using LAST() or LAST-OF() combined with BREAK BY in your FOR EACH.

Or move your EXPORT outside the loop -- the last record will still be available there.
 

velo85

New Member
Thanks, EXPORT outside the loop did job done.
Can you put Last ( ) or Last-OF () in my script, i dont know how to do it.

Thx again.
 

Cecil

19+ years progress programming and still learning.
THIS MIGHT *NOT* WORK. You will need to test it!

Code:
DEF STREAM velorob.
OUTPUT STREAM velorob TO "d:\velo\veloroba.txt".
DEFINE VARIABLE centrala AS INTEGER NO-UNDO.
centrala = 0.

    FOR EACH komdet NO-LOCK
        WHERE komdet.vrs = "centrala"
        AND   komdet.opis = "0522",
    EACH komit NO-LOCK
        WHERE komit.sifkom = komdet.sifkom,
    EACH rromat NO-LOCK
        WHERE rromat.sifkom = komdet.sifkom
        AND rromat.sifrob = "6306 "
        AND rromat.kto = "mg1"
        AND rromat.datdok > 01/01/2018
        AND rromat.datdok < 01/31/2018,
    EACH roba NO-LOCK
        WHERE roba.sifra = rromat.sifrob:

ACCUMULATE rromat.izkol (TOTAL).
 
END.

EXPORT STREAM velorob DELIMITER "," (ACCUM TOTAL rromat.izkol).


OUTPUT STREAM velorob CLOSE.
 

velo85

New Member
Code:
customer_table                            order_table                                                            item_table   
customer_id        customer_name        item_id       item_amount      customer_id      ord_date      item_id          item_name
-----------------------------------|-------------------------------------------------------------|-----------------------------------|
0001            name1              |       1000                5           0001        02/02/18  |   1000                  item1     |
0002            name2              |       1000                8           0005        02/02/18  |   1100                  item2     |
0003            name3              |       1100                3           0001        02/02/18  |   1200                  item3     |
0004            name4              |       1200                10          0004        02/02/18  |   1300                  item4     |
0005            name5              |       1200                5           0001        02/02/18  |   1400                  item5     |
                                   |       1000                11          0001        02/03/18  |                                   |
-----------------------------------------------------------------------------------------------------------------------------------------------------------
I have 3 tabels like and i need to do report

For each "customer_id" i need total amount of "item_amount" by "item_id" .

Report like this:
Code:
customer_id     customer_name        item_id          item_name          item_amount_total

    0001               name1           1000              item1                         16

And so on for each item_id.
I hope you understand me.
Sorry for my english.
 
Last edited:
Top