CW2.003 - file backup using Process Template 
Author Message
 CW2.003 - file backup using Process Template

Gentlemen,

I've set up a Process template that copies data from a local (client)
machine running my Clarion 2.003 application out to a 'master'
database on an NT server.

The idea is that the 'master' database on the server will act as a
running backup of the data on the client machines. Data is Appended
from the client database table to the 'master' table on the server.

Below is listed the code that I have on the embed for the Process
template. I'm attempting to not to append records from the client
table that already exist in the 'master' table from previous updates.

Things work fine when there is no data in the 'master' table - i.e.
the first time through, but not so fine when there is data in the
'master' table.

However, existing records are getting duplicated in the 'master' table
when the update runs. What's more, this routine 'locks up' the
computer when records exist in the master table in that the progress
window stays on-screen indicating that 2% of the update is completed.
I have to go to the task manager and terminate the program at this
point in order to regain control of the machine.

Any help with this would be greatly appreciated. I think I'm at the
point now where I've looked at this code for so long that I just can't
'see' the problem:

!Populate and save backup record:
OPEN(BU_LUMBER,WRITEONLY)
OPEN(LUMBER,READONLY)
SET(LUM:LOTNUMKEY)
SET(LUM1:LOTNUMBERKEY)
LOOP UNTIL ERRORCODE() = 37
    NEXT(LUMBER) !GET A LUMBER RECORD
        IF ERRORCODE() <> 37 THEN !A VALID RECORD WAS READ
            NEXT(BU_LUMBER) !GET A BU_LUMBER RECORD
            IF (ERRORCODE() <> 37) THEN !GOT A VALID RECORD
                IF (LUM1:LOTNUMBER = LUM:LOTNUMBER) AND (LUM1:TIME =
LUM:TIME) THEN
                    CYCLE !GO BACK TO TOP OF LOOP
                ELSE
                    BU_LUMBER:Record :=: LUMBER:Record
                    APPEND(BU_LUMBER)
                END
            ELSE !AT EOF FOR BU_LUMBER
                BU_LUMBER:RECORD :=: LUMBER:RECORD
                APPEND(BU_LUMBER) !So add a new record
            END
        ELSE !AT EOF FOR LUMBER, TIME TO SCAT
            ERRORCODE() = 37 !NO MORE LUMBER RECORDS, SO FORCE LOOP
EXIT
        END !IF ERRORCODE <> 37
END
BUILD(BU_LUMBER) !Rebuild keys
CLOSE(LUMBER)
CLOSE(BU_LUMBER)

Thanks!

Dean Lind



Wed, 15 Nov 2000 03:00:00 GMT  
 CW2.003 - file backup using Process Template

Dean,

    Just a few comments about your code.

    First, I'm not sure why you would want to open BU_LUMBER in WRITEONLY
mode. Secondly, if LUM:LOTNUMKEY and LUM1:LOTNUMBERKEY are for the same
file, I don't think you can have two SET's in a row.

    Regarding the problem you are having, I'd need to understand what the
keys are for your destination file (BU_LUMBER). Which fields are part of
it and if they are unique will make a difference. Assuming
LUM1:LOTNUMBERKEY is the key for BU_LUMBER and that it is unique, you
could use something like this within the source loop...

  BU_LUMBER:record :=: LUMBER:Record
  if get(BU_LUMBER,LUM1:LOTNUMBERKEY) = 37
    BU_LUMBER:Record :=: LUMBER:Record
    APPEND(BU_LUMBER)
  end

    Also, I would suggest using LOGOUT/COMMIT (with STREAM/FLUSH) instead
of APPEND.

    Anyway, hope that helps.

    Regards,

    kurtt

Quote:

> Gentlemen,

> I've set up a Process template that copies data from a local (client)
> machine running my Clarion 2.003 application out to a 'master'
> database on an NT server.

> The idea is that the 'master' database on the server will act as a
> running backup of the data on the client machines. Data is Appended
> from the client database table to the 'master' table on the server.

> Below is listed the code that I have on the embed for the Process
> template. I'm attempting to not to append records from the client
> table that already exist in the 'master' table from previous updates.

> Things work fine when there is no data in the 'master' table - i.e.
> the first time through, but not so fine when there is data in the
> 'master' table.

> However, existing records are getting duplicated in the 'master' table
> when the update runs. What's more, this routine 'locks up' the
> computer when records exist in the master table in that the progress
> window stays on-screen indicating that 2% of the update is completed.
> I have to go to the task manager and terminate the program at this
> point in order to regain control of the machine.

> Any help with this would be greatly appreciated. I think I'm at the
> point now where I've looked at this code for so long that I just can't
> 'see' the problem:

> !Populate and save backup record:
> OPEN(BU_LUMBER,WRITEONLY)
> OPEN(LUMBER,READONLY)
> SET(LUM:LOTNUMKEY)
> SET(LUM1:LOTNUMBERKEY)
> LOOP UNTIL ERRORCODE() = 37
>     NEXT(LUMBER) !GET A LUMBER RECORD
>         IF ERRORCODE() <> 37 THEN !A VALID RECORD WAS READ
>             NEXT(BU_LUMBER) !GET A BU_LUMBER RECORD
>             IF (ERRORCODE() <> 37) THEN !GOT A VALID RECORD
>                 IF (LUM1:LOTNUMBER = LUM:LOTNUMBER) AND (LUM1:TIME =
> LUM:TIME) THEN
>                     CYCLE !GO BACK TO TOP OF LOOP
>                 ELSE
>                     BU_LUMBER:Record :=: LUMBER:Record
>                     APPEND(BU_LUMBER)
>                 END
>             ELSE !AT EOF FOR BU_LUMBER
>                 BU_LUMBER:RECORD :=: LUMBER:RECORD
>                 APPEND(BU_LUMBER) !So add a new record
>             END
>         ELSE !AT EOF FOR LUMBER, TIME TO SCAT
>             ERRORCODE() = 37 !NO MORE LUMBER RECORDS, SO FORCE LOOP
> EXIT
>         END !IF ERRORCODE <> 37
> END
> BUILD(BU_LUMBER) !Rebuild keys
> CLOSE(LUMBER)
> CLOSE(BU_LUMBER)

> Thanks!

> Dean Lind



Wed, 15 Nov 2000 03:00:00 GMT  
 CW2.003 - file backup using Process Template

Hi Dean,

Quote:

>Things work fine when there is no data in the 'master' table - i.e.
>the first time through, but not so fine when there is data in the
>'master' table.

>However, existing records are getting duplicated in the 'master' table
>when the update runs. What's more, this routine 'locks up' the
>computer when records exist in the master table in that the progress
>window stays on-screen indicating that 2% of the update is completed.
>I have to go to the task manager and terminate the program at this
>point in order to regain control of the machine.

IMHO I'd consider your code unsafe as it continues the loop as long as
it does NOT return error 37 (file not open).  It should break the loop
on ANY error or you'll end up with an endless loop sooner or later;)
I would do this in a way so that when the client database is exported,
each record is marked as exported when it has been exported
successfully to the master database, so it will never attempt to
export the same record twice.  I'd put the mark field in a key, so you
can limit the process to only those records that are not exported.
Then it would be a simple matter of running the process on the client
database and duplicate the record in the master database, reset the
export flag in the client and put the record back.  Something like
this in the "Activity for each record":

MAS:Field1 = CLI:Field1
! Other field assignments
Add(MAS:Record)
If ErrorCode()
  CLI:Exported = False
Else
  CLI:Exported = True
End
Put(Client)

In case you loop through it in source, I'd use:

Set(LUM:LOTNUMKEY)
Loop
  Next(LUMBER)
  If ErrorCode()
    Break
  End
  BU_LUMBER:Record :=: LUMBER:Record
  Append(BU_LUMBER)
End
Build(BU_Lumber)

When dealing with TPS files (or basically any kind of files I think)
the best method is to use:

Clear(MYF:Record)
MYF:Field1 = SomeValue  ! Assign keyvalues if needed
Set(MyFile) ! For record order - or
Set(MYF:Key) ! For sorted order - of
Set(MYF:Key,MYF:Key) ! for sorted order starting at key field value
Loop
  Next(MyFile)
  If ErrorCode()
    Break
  End
  ! Check for key field match
  If MYF:KeyField1 <> KeyField1Value
    Break
  End
  ! Now we have the correct records...
End

Basically you would want to break out of the loop on ALL errors.
Checking for error 37 will NOT trap EOF, which returns errorcode 33,
so you could basically always expect your code to loop endlessly
because the Next eventually hits EOF.  Let's look a little bit closer
at your code:

LOOP UNTIL ERRORCODE() = 37
  NEXT(LUMBER)                         !GET A LUMBER RECORD
  IF ERRORCODE() <> 37 THEN            !A VALID RECORD WAS READ
    NEXT(BU_LUMBER)                    !GET A BU_LUMBER RECORD
    IF (ERRORCODE() <> 37) THEN        !GOT A VALID RECORD
      IF (LUM1:LOTNUMBER = LUM:LOTNUMBER) AND |
         (LUM1:TIME = LUM:TIME) THEN
        CYCLE                          !GO BACK TO TOP OF LOOP
      ELSE
        BU_LUMBER:Record :=: LUMBER:Record
        APPEND(BU_LUMBER)
      END
    ELSE                               !AT EOF FOR BU_LUMBER
      BU_LUMBER:RECORD :=: LUMBER:RECORD
      APPEND(BU_LUMBER)                !So add a new record
    END
  ELSE                                 !AT EOF FOR LUMBER, TIME TO SCAT
    ERRORCODE() = 37
  END                                  !IF ERRORCODE <> 37
END

The Next on BU_Lumber (which I take is the master database) is not
needed at all.  This is how I'd do this, providing that I had a mark
field in the Lumber database that told me if the record was exported
or not:

Loop
  Next(Lumber)
  If ErrorCode()
    Break
  End
  If LUM:Exported
    Cycle
  End
  BU_Lumber:Record :=: Lumber:Record
  Append(BU_Lumber)
  If ErrorCode()
    LUM:Exported = False
  Else
    LUM:Exported = True
  End
  Put(Lumber)
End

Same code, but instead of 20 lines of code that I can guarantee that
WILL fail (as you have already confirmed), you have 17 lines of code
that SHOULD NOT fail... well, I won't guarantee that<bg>  Take a look
and compare which code section you'd rather like to maintain in a year
or two:)

Sorry for the rather lengthy reply and please, I'm not trying to
dictate your code, I just felt you were painting yourself into a
corner here (happened to me once - literally<bg>)

Best regards,

Arnor Baldvinsson        
[Team Topspeed - Internet Connect]
Allerup Edb
Denmark

http://www.icetips.com
UIN nr.: 2428601



Wed, 15 Nov 2000 03:00:00 GMT  
 CW2.003 - file backup using Process Template

Arnor,

    You're right - I forgot I was thinking 33 (record not available). Of
course, we don't know what key is what, but I'm sure he'll get it.

    Regards,

    kurtt

Quote:

> Hi Dean,


> IMHO I'd consider your code unsafe as it continues the loop as long as
> it does NOT return error 37 (file not open).  It should break the loop
> on ANY error or you'll end up with an endless loop sooner or later;)
> I would do this in a way so that when the client database is exported,
> each record is marked as exported when it has been exported
> successfully to the master database, so it will never attempt to
> export the same record twice.  I'd put the mark field in a key, so you
> can limit the process to only those records that are not exported.
> Then it would be a simple matter of running the process on the client
> database and duplicate the record in the master database, reset the
> ..............Sorry for the rather lengthy reply and please, I'm not
> trying to
> dictate your code, I just felt you were painting yourself into a
> corner here (happened to me once - literally<bg>)

> Best regards,

> Arnor Baldvinsson
> [Team Topspeed - Internet Connect]
> Allerup Edb
> Denmark

> http://www.icetips.com
> UIN nr.: 2428601



Thu, 16 Nov 2000 03:00:00 GMT  
 CW2.003 - file backup using Process Template

Quote:

>Gentlemen,

 I know that is *mostly* males on this newsgroup, but heh?, like
accepting help from females would be a severe blow to your ego?
----------------------
Jon Waterhouse
Andy Rowe Consultants,
St. John's NF


Fri, 17 Nov 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Process template and file copy (CW2.003)

2. PRINTER{PROPPRINT:Device} w/ Process template in CW2.003

3. Need backup CW2.003 32 bits to anydrive

4. CW2.003 Report Writer - Using variable for file path/name

5. EVENT:timer ......CW2.003 et.al ..... WINDOWS Template

6. QuickFind templates to work with CW2.003

7. Template Trouble Since Upgrade to CW2.003

8. CW2.003 - file errors on Clarion file - HELP!

9. CW2.003 Copy file changes file date

10. CW2.003 32 bit on 3.11 Using WIN32S

11. Date calculations using Report Writer or CW2.003

12. Help in using CW2.003 to Create a new directory

 

 
Powered by phpBB® Forum Software