Previous Topic: CREATE

Next Topic: LOAD

UNLOAD

The UNLOAD option is the first step to create a test subset of a production CA-DATACOM/DB database. A series of commands are coded to direct database operations. Selection criteria is specified to determine which database records are written out to a flat file for subsequent reloading to a test database using the LOAD option of CA-Datamacs/II.

The intermediate output file can also be used to refresh the test database throughout the testing phase, or it could be saved for future regression testing.

Field generators are not allowed during the unload process, but may be used during the subsequent load operation.

Sufficient logical capabilities are provided to allow unloading one table in conjunction with other tables in the same run, thus supporting advanced table relationships, such as many-to-many.

A READ command is available which will retrieve table records based on user-supplied key values. The key values can be made available by the user in the following ways:

Another READ option allows a further qualification of the record just read by doing a comparison of data values in one or more fields. This is called WHEN processing. In this instance, the READ command will be executed repeatedly until the WHEN condition is true. Then it will fall through to the next executable statement. The field(s) chosen can be a key or non-key field.

The results of the READ command are indicated through the AT-END and NOT-FOUND keywords, which allow the logic flow to be altered with a COBOL-like GO TO keyword.

SCANning a database table sequentially is supported and, if desired, a CA-Datamacs/II WHEN statement can select records with specific values. Also, only unique data values can be retrieved. For example, if a test table had to be built containing policyholder insurance information and one policy of each plan type was needed, we could use the UNIQUE option to select one policy for each plan type available in the table.

To eliminate the requirement of knowing the low-level CA-DATACOM/DB error return codes and increase readability of the function logic, generic names like NOT-FOUND and AT-END are used to control logic flow. Should the need arise, there is an ON-DB-ERROR option to test the low level error return codes.

The sequential output file is blocked with a variable length record (QSAM for MVS, with a DD name of DCOMOUT). To allow records from more than one table to be written to the same output file and not lose the table identity, control information is prefixed to each output record. This technique will allow CA-Datamacs/II to automatically reload the data to its correct test table.

To make the subsequent reload as automatic as possible, there is an option on the WRITE statement to APPEND READ EQ INDEX-ONLY to be executed prior to adding the record. If successful, the record would then be added. The key value must be physically located within the output data record. Concatenated keys are supported.

The following example illustrates using CA-Datamacs/II to UNLOAD one record from a single CA-DATACOM/DB database table.

        *DM  TBLSZE IS 10.
         IDENTIFICATION DIVISION.
         PROGRAM-ID. Datamacs.
         AUTHOR.  CA-DATACOM/DB INTERFACE.
         REMARKS. UNLOAD DESIGN
         ENVIRONMENT DIVISION.
         INPUT-OUTPUT SECTION.
         FILE-CONTROL.
        *DM  GENERATE        ALL RECORDS.
        *DM  PRINT           ALL RECORDS.
        *DM  DATACOM UNLOAD DATABASE NAME IS x------------------------x.
        *DM  START.
        *DM   READ  EQ  EMPLOYEE USING KEY '5286'
        *DM     NOT-FOUND GO TO FINISH.
        *DM   WRITE EMPLOYEE.
        *DM   GO TO FINISH.
        *
         DATA DIVISION.
         WORKING-STORAGE SECTION.
        *
        *DM  COPY TABLE NAME IS EMPLOYEE
        *DM      ELEMENT element-name1,element-name2,
        *DM              element-name3
        *DM      KEY-NAME IS EMP-KEY
        *DM      SUPPRESS.
        *DM  END-COPY.
        *
         PROCEDURE DIVISION.

Programming Notes:

In this example, the retrieval command READ was used with a single key of a record specified as a literal. The EQ option finds the exact key.

The NOT-FOUND was coded so that if the key does not exist the job will end.

FINISH is an internal CA-Datamacs/II label used to perform end-of-job processing, which includes insuring all tables and files are closed and printing the end-of-job statistics.

If the key is found, then the WRITE command will output the table row as a variable length record to the DCOMOUT output file, which then may be used as an input (DMIFILE) file to a CA-Datamacs/II LOAD job.

After the WRITE statement, the GO TO FINISH will pass control to the end of job processing and print the end-of-job statistics.

Coding a GO TO START statement after the WRITE statement would cause an infinite loop by retrieving the same record repeatedly.

Other READ commands for the same or a different table can be coded in one run.

Specifying the key occurrence name on the READ (or EQUI-JOIN) statement is done with great flexibility. If the key occurrence name is not specified either in the COPY TABLE or READ statement, CA-Datamacs/II will automatically default to the master key occurrence name, defined within Datadictionary. Any key occurrence name can be used by coding it on the appropriate statement or in any combination between the two statements. For example, if one key occurrence name was specified on the COPY TABLE statement, a different key occurrence name may be specified on the READ command. Different READ statements for the same table may use different key occurrence names. The intended purpose of this flexibility is to specify the key occurrence once on the COPY TABLE command, so that it would not have to be specified on the READ statement.

CHECKPOINT and BACKOUT are not needed for a read-only function.