Sidebar to data/basic break-on totals:

I eliminate the chance of redundant or missed adding by rolling up totals
instead of details. What I mean is that within the LOOP READNEXT...REPEAT
detail processing, I accumulate those values to the closest subtotal, like
in this case, CITY. When I 'break-on' CITY, i roll the city totals to STATE
and clear the city totals when I reset the CITY value for the next break.
The last level, STATE, rolls up into a GRANDTOTAL variable during the
'break-on' STATE.

For grins, I also tend to have a common structure for the CITY.TOTAL,
STATE.TOTAL array and GRAND.TOTAL array as I can send these to a single
printline routine so that the formatting is consistent. Usually, I'm
accumulating more than one value (qty, price, cost etc) and having all the
formulas in one place is helpful. Also, I can fabricate a variable printline
like
LINE=TEXT"L#10":" ":VAL1/100"R2,#10":" ":VAL2/100"R2,#10"
PRINT LINE
and then accumulate the LINEs in a RECAP<-1> variable for printing a summary
report at the end. Thus, after printing the regular GRAND.TOTAL line at the
end, I can announce a recap section and
LOOP UNTIL RECAP="" DO ; PRINT RECAP<1> ; DEL RECAP<1> ; REPEAT

or your preferred method of printing an array.

This is great for creating a detailed A/R then summary A/R aging report
without processing twice.

my 1 cent.


This also semi-documents what levels roll up to which other levels
----- Original Message -----
From: "Allen E. Elwood (CA)" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, June 21, 2004 12:22 PM
Subject: RE: [U2] [UV] WHILE READNEXT id DO {{not a holy war,just a code
example)


> Just a quick look, it appears the code is adding to the city and state
> totals before checking if the city or state values have changed.  This
means
> if the city or state has changed that it'll be adding some of the next
city
> and state totals to the previous city and state totals.  Unless I'm
> mistaken, this will not match a uniquery stmt doing the same.  If you see
my
> example posted earlier you'll see it checks for change of key values, then
> print totals, then clear totals, then add to totals, which is necessary
for
> correct results.
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of Dennis Bartlett
> Sent: Monday, June 21, 2004 2:07 AM
> To: [EMAIL PROTECTED]
> Subject: RE: [U2] [UV] WHILE READNEXT id DO {{not a holy war,just a code
> example)
>
>
> SORT CUSTOMER
>          BY STATE
>          BY CITY
> {showing}   NAME
> BREAK-ON    CITY
> BREAK-ON    STATE
> TOTAL       YTD-SALES
>
>
> ORDERS File layout
> ------------------
> <0>    Order Number
> <1>    State
> <2>    City
> <3>    Cust.Name (for purpose of example)
> <4>    Sales by month position (ie 12 multivals)
>
>
> PROGRAM YTD.SALES.RPT
> * author  :  d.bartlett
> * written :  21 June 04
> * example of GOTO-less code in a break-on environment
> * ---------------------------------------------------
> * Assumes there won't be a city in a different state
> * with the same name / code
> * ---------------------------------------------------
>    OPEN 'ORDERS' TO CUSTOMER ELSE STOP 201,'CUSTOMER'
>    TODAY = OCONV(DATE(),'D2/') ; * assumes dd/mm/yy
>    PERIOD = TODAY[4,2]         ; * assumes simple periods
>    CUST.YTD.SALES = 0
>    LPT.WIDTH = 80
>    STATE.SALES = 0
>    CITY.SALES = 0
>    CUST.SALES = 0
>    TOT.SALES = 0
>    LAST.STATE = ''
>    LAST.CITY = ''
>
> * --------------------------------------------------
> *  select data - assumes I can still use select-by
> *  - if not, we do a two stage pass
> *    (1) process file,
> *        using locate to sequence state*city
> *        build array1 = state*city } state*city*
> *        build array2 = orderno
> *
> *    (2) process sorted array1 with REMOVE
> *        MORE = 1
> *        LOOP
> *           REMOVE KEY FROM ARRAY1 SETTING MORE
> *           REMOVE ORDERNO FROM ARRAY2 SETTING JUNK
> *           * --> process
> *        WHILE MORE
> *        REPEAT
> *
> *  Limitations are size, speed
> * --------------------------------------------------
>    CMD = 'SELECT CUSTOMER'
>    CMD := ' BY STATE'
>    CMD := ' BY CITY'
>    CRT 'Selecting data - please wait'
>    EXECUTE CMD CAPTURING X RETURNING Y
>
>    IF (Y < 1) THEN
>       MSG = 'No records were found matching'
>       MSG := ' your selection'
>       CRT MSG :; INPUT REPLY
>    END ELSE
>       CRT Y : ' records selected'
>       GOSUB PROCESS.ORDERS
>    END
>    CRT @(-1)
>    STOP
> * =================================================
> PROCESS.ORDERS:
>    LOOP
>       READNEXT ORDERNO ELSE DONE = 1
>    UNTIL (DONE = 1)
>       READ ORDREC FROM ORDERS, ORDERNO THEN
>          GOSUB PARSE.ORDER
>          GOSUB ACCUM.YTD
>
> *        initialise temp variables
>          IF (LAST.STATE = '') THEN
>             LAST.STATE = STATE
>             LAST.CITY = CITY
>          END
>
> *        test if city has changed?
>          IF (CITY NE LAST.CITY) THEN GOSUB CITY.TOTALS
>
> *        test if state has changed?
>          IF (STATE NE LAST.STATE) THEN GOSUB STATE.TOTALS
>
> *        print a detail line
>          CRT NAME                       'L#40' :
>          CRT OCONV(YTD.SALES,  'MD2')   'R#15'
>       END
>    REPEAT
>
> *  final CITY totals
>    GOSUB CITY.TOTALS
>    GOSUB STATE.TOTALS
>    GOSUB FINAL.TOTAL
>    RETURN
> * ---------------------------------------------------
> PARSE.ORDER:
> *  <0>    Order Number
> *  <1>    State
> *  <2>    City
> *  <3>    Cust.ID
> *  <4>    Cust.Name (for purpose of example)
> *  <5>    Sales by month position (ie 12 multivals)
>    STATE = ORDREC<1>
>    CITY  = ORDREC<2>
>    NAME  = ORDREC<3>
>    SALES = ORDREC<4>
>    RETURN
> * ---------------------------------------------------
> ACCUM.YTD:
>    CUST.SALES = 0
>    FOR P = 1 TO PERIOD
>       CUST.SALES += OR.SALES<1,P>
>    NEXT P
>    STATE.SALES += CUST.SALES
>    CITY.SALES += CUST.SALES
>    TOT.SALES += CUST.SALES
>    RETURN
> * ---------------------------------------------------
> CITY.TOTALS:
>    CRT SPACE(40)                      :
>    CRT STR('-',15)
>
>    CRT SPACE(40)                      :
>    CRT OCONV(CITY.SALES, 'MD2') 'R#15'
>
>    LAST.CITY = CITY
>    CITY.SALES = 0
>    RETURN
> * ---------------------------------------------------
> STATE.TOTALS:
>    CRT
>
>    CRT SPACE(40)                      :
>    CRT STR('=',15)
>
>    CRT SPACE(40)                      :
>    CRT OCONV(STATE.SALES, 'MD2') 'R#15'
>
>    STATE.SALES = 0
>    LAST.STATE = STATE
>    RETURN
> * ---------------------------------------------------
> FINAL.TOTAL:
>    CRT
>
>    CRT STR('=',LPT.WIDTH)
>    CRT SPACE(40)                      :
>
>    CRT OCONV(TOT.SALES,        'MD2')   'R#15'
>    CRT STR('=',LPT.WIDTH)
>    RETURN
> * ---------------------------------------------------
> END
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Mark Johnson
> Sent: 18 June 2004 04:14
> To: [EMAIL PROTECTED]
> Subject: Re: [U2] [UV] WHILE READNEXT id DO
>
>
> I respond with the GOTO perspective
> -------
> u2-users mailing list
> [EMAIL PROTECTED]
> To unsubscribe please visit http://listserver.u2ug.org/
> -------
> u2-users mailing list
> [EMAIL PROTECTED]
> To unsubscribe please visit http://listserver.u2ug.org/
-------
u2-users mailing list
[EMAIL PROTECTED]
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to