EasyManua.ls Logo

HP TACL - Copying Records between Files; Figure 4-5 Copying Records from One File to Another File

HP TACL
235 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Copying Records Between Files
Accessing Files
4–10 107365 Tandem Computers Incorporated
Copying Records
Between Files
Use the routine in Figure 4-5, copy, to read records from one file and write them to
another file. The source file is specified as the first argument; the destination file is
specified as the second argument; both files must exist. In this example:
read_err is the error variable for the read operation
read_var contains the data obtained from the read operation
prompt_var is the prompt variable to start the read operation
write_err is the error variable for the write operation
write_var contains the record to be written
To invoke this routine, load the file that contains copy and then type:
copy
file1
file2
Copy appends data to the end of FILE2. Copy could be changed to modify records
before copying them; for example, you could search for a string and, if it is present,
modify the string before writing the record to the destination file.
Figure 4-5. Copying Records From One File to Another File (Page 1 of 2)
?SECTION copy ROUTINE
#FRAME
#PUSH rslt rslt2 source dest
#PUSH write_err write_var read_err read_var prompt_var
#PUSH Ready open_err
== Check for existence of the first argument. If empty,
== display a message and exit.
#SET rslt [#ARGUMENT /VALUE source/ FILENAME OTHERWISE]
[#CASE [rslt]
|1|
== Check for the second file.
#SET rslt2 [#ARGUMENT /VALUE dest/ FILENAME OTHERWISE]
[#CASE [rslt2]
|1|
== Open the source and destination files and
== associate variables with them.
#SET open_err [#REQUESTER READ [source] read_err
read_var prompt_var]
[#IF open_err = 0 |THEN|
#OUTPUT [source] opened successfully
|ELSE|
#OUTPUT [source] not open; error [read_err]
#RETURN
]
#SET open_err [#REQUESTER WRITE [dest] write_err
write_var]

Table of Contents

Related product manuals