In the procedures that follow, you specify a comparison operator. The following comparison operators are supported by the Database Services Utility: Comparison Operators
= Equal to ¬= Not equal to <> Not equal to > Greater than >= Greater than or equal to < Less than <= Less than or equal to
Suppose that you are loading data to a table named DEPARTMENT in columns DEPTNO, DEPTNAME, MGRNO, and ADMRDEPT, but you do not have a manager for every department. You still want to insert the DEPTNO, DEPTNAME, and ADMRDEPT into the database. For those departments that do not have a manager, you want to insert a null value. Use the TCI subcommand's null-current-clause. Figure 20 illustrates one way to code the MGRNO TCI to load null values.
Figure 20. TCI Subcommand with a Null Clause
DATALOAD TABLE (DEPARTMENT) DEPTNO 1-3 DEPTNAME 5-40 MGRNO 42-47 NULL IF POS (42-47)=' ' <----6 blanks. ADMRDEPT 49-51 INFILE (NEWDEPT) |
A translation of this clause is: make the corresponding table field null if input-record positions 42 through 47 are blank.
To specify a null condition in the TCI subcommand, do the following:
NULL IF POS (startpos-endpos) operator constant
where startpos is the first character position in the input record that contains the comparison string, endpos is the last position of the string, constant is the value against which the string at position startpos-endpos is to be compared, and operator is a comparison operator. (See Comparison Operators for a list of comparison operators.) Do not put spaces within the brackets.
Note: | The positions checked for the null value need not be in the same positions
occupied by the data field for the column. You can assign the null
value to a column depending on any convention you choose. For example,
to set the MGRNO column to NULL whenever a blank exists in position 11 of the
DEPTNAME column, code the MGRNO TCI as follows:
MGRNO 42-47 NULL IF POS (11) = ' ' |
However, if the positions of the data fields and the positions specified by the startpos and endpos in the subcommand's null-current-clause overlap, your data may be overlaid. For more information on the null-current-clause, see page ***.
Alternative Method |
---|
Another way to insert null values into the database for new rows is by omitting a TCI subcommand for that column: DATALOAD TABLE (DEPARTMENT) DEPTNO 1-3 DEPTNAME 5-40 ADMRDEPT 49-51 INFILE (NEWDEPT) In the above example, there is no TCI subcommand for the MGRNO column of the DEPARTMENT table. For each new row inserted, the MGRNO field is null. The columns that the utility loads null values into must permit nulls. |
The database manager supports the following date and time formats: International Standards Organization (ISO) form, IBM Standard for Europe form (EUR), IBM Standard for the U.S. form (USA), Japanese Industrial Standard Christian Era form (JIS), and an installation-defined form (LOCAL).
Suppose that someone created the following table with the SQL CREATE TABLE statement and you want to load data into the table.
CREATE TABLE PAYABLE (COMPANY CHAR(20), PAYMENT_DUE DATE, AMOUNT DEC(9,2));
Some of the companies in the PAYABLE table are in arrears with their payments. For these organizations, you want the payment due date to be today's date. Use the TCI subcommand's null-current-clause. Figure 21 shows one way to code the TCI subcommand PAYMENT_DUE to load the current date. (This example does not use the sample tables; therefore, do not attempt to process it.)
Figure 21. TCI Subcommand with a Current-Date Clause
DATALOAD TABLE (PAYABLE) COMPANY 1-20 PAYMENT_DUE 22-31 CURRENT DATE IF POS(22-30) = 'IMMEDIATE' AMOUNT 35-45 INFILE(*) VESUVIUS, INC. 2000-05-01 5000.00 ATLANTIS CO. 28.05.1999 3820.00 TITANIC LTD. IMMEDIATE 7250.00 SKY INC. 05/22/1999 300.00 ENDDATA |
A translation of the current date clause is: load the corresponding table field with the current date if input-record positions 22 through 30 contain the string IMMEDIATE.
To specify a current date in the TCI subcommand, proceed as follows:
CURRENT DATE IF POS (startpos-endpos) operator constant
where startpos is the first character position in the input record that contains the comparison string, endpos is the last position of that string, constant is the value against which the string startpos-endpos is to be compared, and operator is a comparison operator. See Comparison Operators for a list of comparison operators.
To load current times and timestamps, replace CURRENT DATE with CURRENT TIME or CURRENT TIMESTAMP in Step 1 of this procedure. For example, in Figure 21, you could replace CURRENT DATE with CURRENT TIME if the PAYMENT_DUE column were TIME data type.
Note: | The current date, current time, and current timestamp value is acquired by Database Services Utility at the start of the DATALOAD command processing, and will not change throughout the DATALOAD command processing. |
You can load the same data records into more than one table, or load different data records in the same input file into their respective tables. When you are loading data into more than one table, the Database Services Utility automatically performs an UPDATE STATISTICS (unless a SET UPDATE STATISTICS OFF command has been issued) after the DATALOAD command processing is completed successfully.
If you had to load data into two tables, you would probably prepare two DATALOAD commands that could be run either separately or consecutively in the same (input) control file. This is shown in Figure 22.
Figure 22. Separate DATALOAD Commands Run Successively
DATALOAD TABLE (ACTIVITY) ACTNO 1-3 ACTKWD 5-10 ACTDESC 12-31 INFILE (*) 190 MARKET MARKETING 200 CUSTOM CUSTOMER SUPPORT 25 RSRCH RESEARCH 55 TRAIN TRAINING ENDDATA DATALOAD TABLE (DEPARTMENT) DEPTNO 1-3 DEPTNAME 5-23 MGRNO 25-30 ADMRDEPT 32-34 INFILE (*) F01 PERSONNEL 000110 A00 G01 MARKETING AND SALES 000120 A00 ENDDATA |
If, for some reason, the input data records for two tables were mixed in one data group, you could run the single data group against multiple DATALOAD commands. This is possible with the use of the DATALOAD statement's input-record-id clause. Figure 23 shows two DATALOAD commands that share one INFILE(*) subcommand. Both DATALOAD commands have input-record-id clauses that specify the records that belong to each table.
Figure 23. DATALOAD Commands Sharing a Data File
DATALOAD TABLE (ACTIVITY) IF POS (54)='1' ACTNO 1-3 -------*------- ACTKWD 5-10 | ACTDESC 12-31 *--------------------* DATALOAD TABLE (DEPARTMENT) IF POS (54)='2' | DEPTNO 1-3 -------*------- *-------*-------* DEPTNAME 5-23 *----------*INPUT-RECORD-ID| MGRNO 25-30 | Clauses | ADMRDEPT 32-34 *---------------* INFILE (*) 190 MARKET MARKETING 1 F01 PERSONNEL 000110 A00 2 200 CUSTOM CUSTOMER SUPPORT 1 G01 MARKETING AND SALES 000120 A00 2 25 RSRCH RESEARCH 1 55 TRAIN TRAINING 1 ENDDATA ^ | *-------------* | |Column 54, *----* |Control Field| *-------------* |
Translations of the input-record-id clauses are:
To load separate tables with mixed input data from a single file, proceed as follows:
IF POS (startpos-endpos) operator constant
where startpos is the first character position in the control field, endpos is the last position in that field, constant is the value against which the string startpos-endpos is to be compared, and operator is a comparison operator. See Comparison Operators for a list of comparison operators.
column-name startpos-endpos data-type
where column-name is the name of the table column; startpos is the starting position of the input record; endpos is the last position in the input record; and data-type is the data format of the column values. If the data type is character (CHAR), you can omit it.
Note: | Ensure that the control field occupies the same position or positions in each of the data records of the input file. |
When the Database Services Utility loads records from a mixed input file into multiple tables, each data record is inserted into a particular table only. You can also write DATALOAD commands so that a single input data record can be a source of rows in more than one table. For example, suppose that you want to expand your activities for each project. Each activity number added to the ACTIVITY table has a corresponding activity number added to the PROJ_ACT table. To use a single input data record to make entries in these two tables, you could code utility commands as shown in Figure 24.
Figure 24. Individual Records Supplying the Same Activity Number to Two Tables
DATALOAD TABLE(ACTIVITY) ACTNO 1-3 ACTKWD 5-10 ACTDESC 12-27 DATALOAD TABLE(PROJ_ACT) PROJNO 29-34 ACTNO 36-38 ACSTAFF 40-43 ACSTDATE 45-54 ACENDATE 56-65 INFILE (*) 190 MARKET MARKETING AD3100 190 0.50 1999-01-02 1999-04-30 200 CUSTOM CUSTOMER SUPPORT OP2000 200 1.50 1998-03-01 1999-12-31 55 TRAIN TRAINING IF2000 55 1.00 1999-02-01 1999-09-05 ENDDATA |
In Figure 24, each DATALOAD command has its own set of TCI subcommands that point to unique positions on the same input record.
In Figure 24, the activity number is repeated twice (once for the ACTIVITY table and once for the PROJ_ACT table) in each input data record. Eliminate the need for duplicate fields by using TCI subcommands for each of the tables that point to the same physical location in the input record, as shown in Figure 25.
Figure 25. TCIs in Individual DATALOADs That Point to the Same Location
DATALOAD TABLE(ACTIVITY) *------------------------* ACTNO 1-3 <--------| | ACTKWD 5-10 | These two subcommands | ACTDESC 12-27 | point to the same | DATALOAD TABLE(PROJ_ACT) | physical location in | PROJNO 29-34 | the input data records.| ACTNO 1-3 <--------| | ACSTAFF 40-43 *------------------------* ACSTDATE 45-54 ACENDATE 56-65 INFILE (*) 190 MARKET MARKETING AD3100 0.50 1989-01-02 1989-04-30 200 CUSTOM CUSTOMER SUPPORT OP2000 1.50 1989-03-01 1995-12-31 55 TRAIN TRAINING IF2000 1.00 1989-02-01 1989-09-05 ENDDATA |
To use similar TCI subcommands in multiple DATALOAD TABLE commands, proceed as follows:
Usually, one input data record provides information for one table row. This is illustrated in Figure 26.
Figure 26. Normal Relationship: One Record for One Row
DATALOAD TABLE(ACTIVITY) ACTNO 1-3 ACTKWD 5-10 ACTDESC 12-27 INFILE (*) 190 MARKET MARKETING 200 CUSTOM CUSTOMER SUPPORT 25 RSRCH RESEARCH 55 TRAIN TRAINING ENDDATA |
Using multiple DATALOAD commands, however, you can load more than one table row with each input data record. Figure 27 presents a way of using multiple DATALOAD statements to load combined records into the same table.
Figure 27. Combined Records: Each for Two Rows
DATALOAD TABLE(ACTIVITY) ACTNO 1-3 ACTKWD 5-10 ACTDESC 12-27 DATALOAD TABLE(ACTIVITY) ACTNO 29-31 ACTKWD 33-38 ACTDESC 40-55 INFILE(*) 190 MARKET MARKETING 200 CUSTOM CUSTOMER SUPPORT 25 RSRCH RESEARCH 55 TRAIN TRAINING ENDDATA |
In the above example, two rows are inserted into the ACTIVITY table for each data record that is read.
To load combined records into the same table, proceed as follows:
You can load data that is continued onto the next physical record. Figure 28 illustrates the command sequence necessary to load data from 80-byte input data records into the columns ACTNO and ACTDESC in the table named SQLDBA.ACTIONS where:
Figure 28. Specifying Continued Input Records
*-------------------------* |Activity description that| DATALOAD TABLE(SQLDBA.ACTIONS) |is 77 positions long and | ACTNO 1-10 |cannot fit on one record.| ACTDESC 11-110 *---------------------*---* INFILE(* CONTINUED(YES)) | C1234567890THIS ACTIVITY DESCRIPTION FILLS IN THE ENTIRE LOGICAL RECORD LENGTH|<------* AND MORE | C1234567891THIS DESCRIPTION DOES NOT USE THE WHOLE RECORD|<---------------------------* | | ^ . | | *---------------------*---* | . |Activity description that| | |is 46 positions long. | | . *------------------------* |The next record is blank | | | Position 1 of the input| |to fill in the rest of | *---------------------* data record contains a | |the 100 positions. | | continuation character.| *-------------------------* *------------------------* ENDDATA |
The CONTINUED parameter of the INFILE subcommand indicates that continued records are in the input data. If position 1 of an input data record contains a character, the input data is continued onto the next physical input data record. The above example uses a C as a continuation character, but you can use any character. The first position of each input file data record is not included in the actual input data, so character positions begin numbering from the second position. Therefore, the physical position 2 of an input data record is referred to as position 1 in the TCI subcommand.
If position 1 of the input data record is blank, the input data is contained on a single logical input record, or it is the terminating row of a continued record. All actual input data records must be at least as long as the highest end-position value specified in a TCI subcommand. In this situation, the ACTDESC field must be 100 characters in length. Therefore, a second physical input line containing all blanks is necessary to extend the ACTDESC field of the second logical input record (beginning with ACTNO=1234567891) to the maximum length value of 100.
If the highest TCI endpos value exceeds the input record length, you need to use continued input records. To construct a Database Services Utility command to load continued physical input records into a table, proceed as follows:
For DB2 Server for VSE
INFILE (* CONTINUED(YES))
The CONTINUED parameter must be on the same record as INFILE.
C ...data...
where C can be the character C or any other character, and ...data... is the actual input-record data to a maximum of 79 characters.
If you have to enter more than two records for a physical input record, put a continuation character at the beginning of each record except the last one. The blank in position 1 terminates that input record.
ENDDATA
For DB2 Server for VM
INFILE (*
CONTINUED(YES))
C ...data...
where C can be the character C or any other character, and ...data... is the actual input-record data to a maximum of 79 characters.
If you have to enter more than two lines for a physical input record, put a continuation character at the beginning of each line except the last one. The blank in position 1 terminates that input record.
ENDDATA
If the SET AUTOCOMMIT ON command has been issued, the DATALOAD command can specify that the utility issue SQL COMMIT statements periodically during processing. The interval is specified in terms of a specific number of input records processed by DATALOAD. A record is considered to be processed by DATALOAD when it is read and appropriate action is taken. The action is one of the following:
You indicate the number of records by specifying the COMMITCOUNT(ccount) parameter on the INFILE subcommand. Each time that COMMIT processing is to begin, a message (ARI0800I) is written to the message file containing the number of input records processed up to this point. The message is written as a result of COMMITCOUNT processing. You also receive a message (ARI0811I) to inform you that the changes were committed successfully.
You can use COMMITCOUNT to minimize lock interface with other users of a dbspace or a table. If you set the value of ccount low enough, escalation is avoided.
The COMMITCOUNT parameter also helps reduce log space requirements during execution with multiple user mode.
To cause the Database Services Utility to commit work during processing, proceed as follows:
COMMITCOUNT(ccount)where ccount is a number from 1 to 2,147,483,647.
Specifying a COMMITCOUNT value commits that number of input records to the database as soon as the Database Services Utility has processed them.
During DATALOAD processing of files containing more than 15,000 data records, a message (ARI8995I) is written to either the VSE operator console or your VM terminal after every 15,000 records to let you know that the job is running normally and that n input records have been processed. These messages appear unless:
A bad data record is one that:
If the COMMITCOUNT parameter is specified with AUTOCOMMIT ON, and ERRORMODE CONTINUE processing is in effect, DATALOAD processing skips bad data records. Processing continues under the following circumstances:
Insert blocking is not in effect under the following conditions:
A bad data record is not skipped, and DATALOAD processing is terminated under the following conditions:
The Database Services Utility is designed to run despite minor errors. If, however, an error is serious enough to halt the utility, you must rerun your particular Database Services Utility command and reprocess all your files; you cannot simply restart the Database Services Utility from the point of failure.
The COMMITCOUNT parameter, introduced in the preceding section, saves processed data at intervals that you specify. This saves you processing time because, although you must rerun jobs from the beginning, you do not have to reprocess data that has already been committed to the database. The part of the DATALOAD TABLE command that lets you bypass records is the RESTARTCOUNT parameter.
In general, you want to skip any records that have been successfully processed and also any bad input records. To run a job that has errors, proceed as follows:
Note: | If you were running the Database Services Utility without SET AUTOCOMMIT protection, or with too high a COMMITCOUNT value, you could rerun the job with SET AUTOCOMMIT ON and an appropriately low COMMITCOUNT value to save the successfully processed records. If you choose this course of action, return to step 1. |
RESTARTCOUNT(rcount)
where rcount specifies the number of input records to be skipped. In general, start processing from the last COMMIT action.
If a DATALOAD job is canceled or halted repeatedly by errors, or if bad records are causing the errors, consider using the following:
ARI0800I ...Begin COMMIT. Input Record Count = 100
If you were running a DATALOAD job with the COMMITCOUNT set to 100, but the job was unsuccessful at record 151, you could run DATALOAD again with a new COMMITCOUNT value and restart after the number of records that were committed:
DATALOAD TABLE(SMITH.DEPARTMENT) IF POS (50) = 'X' INFILE(SOMEDEPT) COMMITCOUNT(50) RESTARTCOUNT(100)
Now you have committed all the records up to the bad record. To skip the bad record, change the RESTARTCOUNT value, and restore the COMMITCOUNT parameter to its original value:
DATALOAD TABLE(SMITH.DEPARTMENT) IF POS (50) = 'X' INFILE(SOMEDEPT) COMMITCOUNT(100) RESTARTCOUNT(151)
Alternative Method |
---|
You can specify that the Database Services Utility ignore certain error conditions and continue processing records:
Although this procedure skips bad records, it does not pinpoint them. After a job is finished, compare the loaded table with source input documents to locate missing table rows. For more information on Database Services Utility's error handling, see Chapter 9, Error Handling and Debugging. |
The database manager generates table statistics while loading the data and calculates index statistics while creating an index. This method of creating statistics avoids doing a dbspace scan and a separate scan of the index pages, which are done when you issue an UPDATE STATISTICS statement.
The database manager generates table statistics while the Database Services Utility DATALOAD, RELOAD TABLE, and RELOAD DBSPACE commands are loading data only if the SET UPDATE STATISTICS command is set to ON. Other rules that must be met if statistics are to be collected for DATALOAD processing are:
The database manager determines that rows are already in the table when the ROWCOUNT column of the SYSCATALOG table is a positive number for the table you are loading. Generally, a positive number in the ROWCOUNT column indicates that the table contains rows, but if you delete all the data from the table without updating the statistics, ROWCOUNT still contains a positive number. You must update the statistics to set the ROWCOUNT to zero before loading data into that table.
If, for any of the above reasons, table statistics were not generated while data was being loaded, the Database Services Utility executes an SQL UPDATE STATISTICS statement for each table loaded after DATALOAD or RELOAD command processing successfully ends. Statistics are neither updated automatically nor is an UPDATE STATISTICS statement executed under either one of the following conditions: