This code example is also flawed in that a break-on state should
automatically break-on city first regardless if the city has changed. As it
is, it assumes that there could never be this situation:

CITY            STATE
Middletown    NJ
Springfield      NJ
Springfield      PA
Springfield      TX

Perhaps Cities and States won't have this real problem. But Salesman,
Customers and Products certainly could.

my 1 cent
----- 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