Please tell me why this scan...endscan is exiting too early.

Please tell me why this scan...endscan is exiting too early.

Post by Richard Hollingswor » Sat, 09 Aug 1997 04:00:00



Thanx for reading this...

Here's part of the code...

p_Month = MONTH(EOW)
use EM excl
do case
        case p_Month = 1
        scan for hire_date < {02/01/97}
                ** 1st, set grant and ent.
                replace grant with 80.0, entitlement with 80.0  
                ** Next, re-calc for pos. balance.
                replace carryover with balance, ;  
                        balance with grant ;
                        for balance >= 0.0
                ** Now, re-calc for neg. balance.
                replace balance with (grant + balance), ;  
                        carryover with 0.0 ;
                        for balance < 0.0                    
        endscan

        case p_Month = 2
        ...SNIP...

endcase

The other 11 months are similar to case p_Month = 1.

I thought scan...endscan was supposed to loop thru EVERY record that
matches the for condition AND execute all the statements within.  In
this case however, the trace window shows that the scan EXITS after it
processes the first record.  The other records that meet this criteria
do not get processed and replaced as per the code.

Please tell me why this is happening, and how to fix it.  I need the
replacements to run against ALL records that match the scans' "for
condition".

Thanx much for your help.  RH

 
 
 

Please tell me why this scan...endscan is exiting too early.

Post by Andy Nei » Sat, 09 Aug 1997 04:00:00




.

Quote:>            replace carryover with balance, ;  
>                    balance with grant ;
>                    for balance >= 0.0

The problem is the FOR clause, which applies to multiple records (an
implicit ALL scope).  This leaves the record pointer at EOF after the
replace is done.  The SCAN loop sees it's at EOF, decides there are no more
records to process, and bails out.  You may need to store the record
number, then put the pointer back after the REPLACE is finished in order to
get the effect you want.

Andy

 
 
 

Please tell me why this scan...endscan is exiting too early.

Post by Bill Bardo » Sat, 09 Aug 1997 04:00:00



>         scan for hire_date < {02/01/97}
>                 ** 1st, set grant and ent.
>                 replace grant with 80.0, entitlement with 80.0
>                 ** Next, re-calc for pos. balance.
>                 replace carryover with balance, ;
>                         balance with grant ;
>                         for balance >= 0.0
>                 ** Now, re-calc for neg. balance.
>                 replace balance with (grant + balance), ;
>                         carryover with 0.0 ;
>                         for balance < 0.0
>         endscan

> I thought scan...endscan was supposed to loop thru EVERY record that
> matches the for condition AND execute all the statements within.

In this case your REPLACE FORs are short-circuiting the SCAN.  For an
example, open a test table and do a REPLACE FOR with whatever fields and
criteria you want.  Where does the record pointer wind up after the
replace?  Yep, at EOF.

ENDSCAN is just a glorified CONTINUE (yes, often more efficient, faster,
cleaner, whatever.)  If a command within the SCAN loop moves the pointer
to EOF, when you hit ENDSCAN you're done.

You need to save the record position before your REPLACE FORs, and
re-position the pointer before the ENDSCAN.  Try:

scan for hire_date < {02/01/97}
        * SAVE POSITION
        hrec = recno()

        replace balance with (grant + balance), ;
                carryover with 0.0 ;
                for balance < 0.0
        etc.....

        * RESTORE POSITION
        go hrec
endscan

--
Bill Bardon
Elkhorn, Nebraska

 
 
 

Please tell me why this scan...endscan is exiting too early.

Post by Mark Hal » Sun, 10 Aug 1997 04:00:00


Hello,

If you haven't already been told or figured it out by now, the reason is
the FOR clause on your REPLACE statements.

The FOR clause cases the REPLACE to process the entire table, picking only
the records that match, and it leaves the record pointer at the end of the
file.  So when your ENDSCAN hits, there are no more records to process.

Try

SCAN
   lcRecord = RECNO
   REPLACE ....  FOR ....

   GO lcRecord
ENDSCAN

Regards
Mark

 
 
 

Please tell me why this scan...endscan is exiting too early.

Post by ATMSte » Mon, 11 Aug 1997 04:00:00




>do case
>    case p_Month = 1
>    scan for hire_date < {02/01/97}
>            ** 1st, set grant and ent.
>            replace grant with 80.0, entitlement with 80.0  
>            ** Next, re-calc for pos. balance.
>            replace carryover with balance, ;  
>                    balance with grant ;
>                    for balance >= 0.0
>            ** Now, re-calc for neg. balance.
>            replace balance with (grant + balance), ;  
>                    carryover with 0.0 ;
>                    for balance < 0.0                    
>    endscan

I may be missing the point, but I don't think you need to save the recno
and go back to it.  What about
Scan for....
                  replace grant with 80.0, entitlement with 80.0        
                  if balance>=0.0
                replace carryover with balance, ;  
                balance with grant
                 endi
                 if balance<0.0
                replace balance with (grant + balance), ;  
                carryover with 0.0            
                 endi
endscan

Steve Andrews

 
 
 

Please tell me why this scan...endscan is exiting too early.

Post by Peter Fran » Wed, 13 Aug 1997 04:00:00



> ...
> do case
>         case p_Month = 1
>         scan for hire_date < {02/01/97}
>                 ** 1st, set grant and ent.
>                 replace grant with 80.0, entitlement with 80.0
>                 ** Next, re-calc for pos. balance.
>                 replace carryover with balance, ;
>                         balance with grant ;
>                         for balance >= 0.0
>                 ** Now, re-calc for neg. balance.
>                 replace balance with (grant + balance), ;
>                         carryover with 0.0 ;
>                         for balance < 0.0
>         endscan

>         case p_Month = 2
>         ...SNIP...

> endcase

Do the last two REPLACE commands depend on the month? If no, I would
suggest to move them after DO CASE structure and leave them as they are
(means REPLACE *ALL* ...). If yes, use IF command to avoid the FOR
clause and replace just *ONE* record:

IF balance < 0
    REPLACE ;
        balance with (grant + balance), ;
        carryover with 0.0
ELSE
    REPLACE ;
        carryover with balance, ;
        balance with grant ;
ENDIF

Btw. now you are replacing ALL records meeting the FOR condition in
REPLACE command, not only those meeting both FORs in REPLACE and SCAN
commands, so the REPLACEs are actually redundant..

Peter

--
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

    University of Zilina, Moyzesova 20, 01001 Zilina, Slovakia
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

 
 
 

1. Help please with this SCAN....ENDSCAN problem

Hi folks.  Thanx for reading this.

I have what I think is a very simple problem, but I can't seen to make it work
right.

I using VFP 3.0 Pro.

I have a temp table called Lab1 that has one record for each ssn/charge_number
combination.

I also have a master table called YtdLabor that also has one record per
ssn/charge_number combo.

What I want to do is get the current value for several fields from the Lab1
table into the corresponding field(s) in the master table based on an
ssn/charge_number match between the two tables.  Then, update some accumulator
fields in the master table using these temp values.

I've tried using SET RELATION between the two tables and can't seem to make
that work.  It keeps barfing something about "variable ssncn dosen't exit"

Now, I'm trying to use SCAN...ENDSCAN and make that work, but no luck yet.

Here's what I currently have.....

USE LAB1 EXCL IN 0
index on ssn+charge_no tag ssncn
USE YTDLABOR EXCL IN 0
sele ytdlabor

SCAN
        last_rec = recno()
        REPLACE YTDLABOR.CUR_RHR WITH LAB1.CUR_RHR, ;
        YTDLABOR.CUR_OTS WITH LAB1.CUR_OTS, ;
        YTDLABOR.CUR_OTH WITH LAB1.CUR_OTH, ;
        YTDLABOR.CUR_OTD WITH LAB1.CUR_OTD, ;
        YTDLABOR.CUR_OTE WITH LAB1.CUR_OTE ;
        FOR YTDLABOR.SSN = LAB1.SSN AND YTDLABOR.CHARGE_NO = LAB1.CHARGE_NO
        goto last_rec
ENDSCAN
CLOSE DATA

But, this only replaces 1 record in YtdLabor, it never advances thru the Lab1
table.

Can someone tell me the best way to do this procedure?

Thanx

Richard H.

2. Request help: Can't connect to sql server unless connected to the internet.

3. Why am I doing a Table Scan?

4. Removing Rows in table

5. Question on Scan ..Endscan PDX7.0

6. Sql 7 Stored procedures and Default Values

7. need help with SCAN...ENDSCAN

8. ORA-00600 with empty arguments

9. SCAN..ENDSCAN

10. SCAN...ENDSCAN

11. SCAN...ENDSCAN (strike 2)

12. SCAN...ENDSCAN