The DB2 LOAD utility is how shops move large files into tables quickly and repeatably. This hands-on tutorial covers prerequisites, a practical JCL and control-statement pattern, how to verify success, and the pending states and discard problems that show up on day one.
LOAD operates on a table space. It reads input records, converts them into Db2 rows, writes pages, and maintains indexes defined on the target tables. You choose whether to replace existing data or resume by appending. Optional phases enforce referential constraints, build indexes in parallel, collect inline statistics, and write discarded records for cleanup.
Compared with INSERT, LOAD is built for volume: sorted input, bulk index build, and utility restart logic. Compared with UNLOAD, LOAD is the inbound direction—file to table—while UNLOAD extracts table to file.
Always practice on a test table space. A mistaken REPLACE on a shared multi-table space can empty tables you did not intend to touch.
Align columns in the file with the field list in the LOAD statement. Pad character fields, watch EBCDIC encoding, and confirm numeric and date layouts. A single off-by-one in positions produces conversion errors and discards.
A minimal append load into a training table looks like this. Adjust names, positions, and DDs to match your data.
12345678LOAD DATA INDDN SYSREC RESUME YES LOG YES INTO TABLE TRAINING.EMPLOYEE (EMPNO POSITION(1) CHAR(6), FIRSTNME POSITION(7) CHAR(12), LASTNAME POSITION(19) CHAR(15), DEPTNO POSITION(34) CHAR(3))
For a full refresh of a dedicated single-table table space, beginners often use REPLACE:
12345678LOAD DATA INDDN SYSREC REPLACE LOG YES INTO TABLE TRAINING.EMPLOYEE (EMPNO POSITION(1) CHAR(6), FIRSTNME POSITION(7) CHAR(12), LASTNAME POSITION(19) CHAR(15), DEPTNO POSITION(34) CHAR(3))
Important REPLACE meanings:
Online utilities typically run under DSNUTILB with a SYSIN control statement. Your shop may generate JCL from DB2I Utilities, Automation Tool, or a standard PROC. A teaching skeleton:
12345678910111213141516171819202122232425262728//LOADEMP JOB (ACCT),'DB2 LOAD',CLASS=A,MSGCLASS=X, // NOTIFY=&SYSUID //JOBLIB DD DISP=SHR,DSN=DSN.V13R1M0.SDSNEXIT // DD DISP=SHR,DSN=DSN.V13R1M0.SDSNLOAD //LOAD EXEC PGM=DSNUTILB,REGION=0M, // PARM='DB2T,LOADEMP' //SYSPRINT DD SYSOUT=* //UTPRINT DD SYSOUT=* //SYSUDUMP DD SYSOUT=* //SYSREC DD DISP=SHR,DSN=TRAINING.EMPLOYEE.INPUT //SYSDISC DD DSN=TRAINING.EMPLOYEE.DISC, // DISP=(NEW,CATLG,DELETE), // UNIT=SYSDA,SPACE=(CYL,(5,5),RLSE) //SYSERR DD UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(NEW,DELETE) //SYSMAP DD UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(NEW,DELETE) //SORTOUT DD UNIT=SYSDA,SPACE=(CYL,(10,10)),DISP=(NEW,DELETE) //* add SORTWKnn per site standards when indexes need sort //SYSIN DD * LOAD DATA INDDN SYSREC RESUME YES LOG YES ENFORCE CONSTRAINTS INTO TABLE TRAINING.EMPLOYEE (EMPNO POSITION(1) CHAR(6), FIRSTNME POSITION(7) CHAR(12), LASTNAME POSITION(19) CHAR(15), DEPTNO POSITION(34) CHAR(3)) /*
The PARM supplies the SSID and a utility ID. Utility IDs must be unique while a utility is active; reuse after successful termination or after you terminate a failed utility per site procedure.
LOG YES (default in many examples) logs changes for recovery.LOG NO can speed large loads but often leaves COPY-pending so you must take an image copy before the object is considered recoverable under normal rules. Some options such as NOCOPYPEND exist for specific scenarios—use them only when your recovery procedures explicitly allow it.
Watch SYSPRINT for phase messages (RELOAD, BUILD, ENFORCE, DISCARD, REPORT). Non-zero return codes demand a full read of the messages, not only the final RC.
SELECT COUNT(*) FROM TRAINING.EMPLOYEE versus expected input size minus discards-DISPLAY DATABASE(...) or catalog queries for COPY/CHECK pending if you used LOG NO or constraint deferral options1234567SELECT COUNT(*) AS ROW_CNT FROM TRAINING.EMPLOYEE; SELECT EMPNO, LASTNAME, DEPTNO FROM TRAINING.EMPLOYEE WHERE EMPNO IN ('000010','000020','000050') ORDER BY EMPNO;
If discards occurred, browse SYSDISC, fix the data or the field map, and LOAD again with RESUME YES for the repaired subset—or correct the full file and REPLACE when that is the approved refresh pattern.
Wrong POSITION lengths, invalid packed decimals, or bad date strings send rows to discard or fail the utility. Dump a few input records in hex and compare to the field list.
Input contains keys already present (RESUME) or duplicates within the file. Clean the file, use REPLACE when a full refresh is intended, or adjust keys.
Child rows reference missing parents. Load parents first, or stage data and run CHECK DATA when your process defers enforcement. With ENFORCE CONSTRAINTS, violators go to discard.
Applications may be restricted until you COPY the table space. Schedule image copy immediately after the load window.
A previous LOAD failed and left a utility record. Display utilities, then TERM or restart according to IBM and site rules—never guess on production.
REPLACE emptied more than you expected because multiple tables share the table space. Prefer one table per table space for refreshable tables, or use careful partition-level options.
Imagine a toy box (the table). INSERT is dropping toys in one at a time. LOAD is pouring a big bag of toys into the box. You can either dump out the old toys first (REPLACE) or pour the new toys on top of the old ones (RESUME). If some toys are broken (bad data), LOAD can put them in a reject pile (SYSDISC) so you can fix them later. When you pour very fast without writing everything in the diary (LOG NO), a grown-up may ask you to take a photo of the box (image copy) so you can rebuild it if something goes wrong.
1. What is the difference between LOAD REPLACE and LOAD RESUME YES?
2. Which DD usually holds the input records for LOAD?
3. Why might a table space be COPY-pending after LOAD LOG NO?
4. What happens to records that violate constraints when ENFORCE CONSTRAINTS is in effect?
5. Who needs authority for LOAD on a table space with multiple tables?