Copying Files Between Databases
To copy all CUSTOMER records from one database to another:
SET --- NEXT DATABASE = DB1
OPEN TAR CUSTOMER SHARE? Y FAIL 0
*
BEG READ TAR CUSTOMER Hold? N
*
* The DB1 Customer file is currently accessible
* through the CUSTOMER file name - we just read
* a record from the DB1 Customer file. Now we
* Want to write this record to the DB2 Customer
* file - have to open it first
*
SET --- NEXT DATABASE = DB2
OPEN TAR CUSTOMER SHARE? Y FAIL 0
WRITE TAR CUSTOMER FAIL 0
F CANCEL unexpected error (duplicate key?) WRITEing CUSTOMER
*
* Now we have to switch databases again before we
* do the END READ
*
OPEN TAR CUSTOMER SHARE? Y FAIL 0
END READ TAR CUSTOMER
No CLOSE statement is needed - APPX simply switches the internal data structures between databases with each OPEN statement. This turns out to be much faster than the SPEED II method which required physically closing the file and reopening it for each database switch. Of course you have more files open with the APPX method.
When APPX needs to open a file, it does so in two phases... a logical open and a physical open. The logical open takes place when APPX opens the file automatically OR when you open the file with an OPEN statement - this phase sets up internal memory structures to keep track of the file - the structure files are also verified during the logical open (this is expensive).
The physical open only takes place when you actually do the first I/O to the file (a read, write, etc.).
A file name (use "CUSTOMER" as an example) actually acts as a file multiplexor - you can get to multiple CUSTOMER files using the same file name. You do this by setting --- NEXT DATABASE and executing an OPEN statement to open a CUSTOMER file in a different database.
Comments:
Read what other users have said about this page or add your own comments.