The DB2 UNLOAD utility pulls rows out of a table space (or an image copy) into sequential files you can archive, ship, or reload. This tutorial covers prerequisites, control statements, SHRLEVEL choices, verification, and common failures.
UNLOAD reads table data and writes sequential output. Operations teams use it for environment refreshes, vendor feeds, conversions, and “give me a file that LOAD can put back.” Unlike a casual SELECT in SPUFI, UNLOAD runs as an online utility with explicit concurrency controls, partition limits, and SYSPRINT accounting.
You specify a TABLESPACE (and optional database), optional PART ranges, and one or more FROM TABLE clauses. Output goes to a DD such as SYSREC or a name you supply with UNLDDN.
Beginners practicing on test data can start with REFERENCE. Production 24×7 tables often need CHANGE plus clear documentation of consistency expectations.
1234UNLOAD TABLESPACE TRAINING.EMPTS FROM TABLE TRAINING.EMPLOYEE SHRLEVEL REFERENCE UNLDDN SYSREC
Add PART when you only need some partitions:
12345UNLOAD TABLESPACE TRAINING.EMPTS PART 1:4 FROM TABLE TRAINING.EMPLOYEE SHRLEVEL CHANGE UNLDDN SYSREC
12345678910111213141516171819//UNLDEMP JOB (ACCT),'DB2 UNLOAD',CLASS=A,MSGCLASS=X, // NOTIFY=&SYSUID //JOBLIB DD DISP=SHR,DSN=DSN.V13R1M0.SDSNEXIT // DD DISP=SHR,DSN=DSN.V13R1M0.SDSNLOAD //UNLOAD EXEC PGM=DSNUTILB,REGION=0M, // PARM='DB2T,UNLDEMP' //SYSPRINT DD SYSOUT=* //UTPRINT DD SYSOUT=* //SYSUDUMP DD SYSOUT=* //SYSREC DD DSN=TRAINING.EMPLOYEE.UNLOAD, // DISP=(NEW,CATLG,DELETE), // UNIT=SYSDA,SPACE=(CYL,(50,20),RLSE), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=0) //SYSIN DD * UNLOAD TABLESPACE TRAINING.EMPTS FROM TABLE TRAINING.EMPLOYEE SHRLEVEL REFERENCE UNLDDN SYSREC /*
Match LRECL/RECFM to the unload format your statement produces. Site templates often set these for you—do not invent DCB values that truncate rows.
Confirm the utility ID, the objects processed, and the number of rows unloaded. Save the SYSPRINT with the output file; auditors and reload jobs both need that pair.
SELECT COUNT(*) FROM TRAINING.EMPLOYEE when SHRLEVEL and filters allow a fair comparison123456SELECT COUNT(*) AS LIVE_ROWS FROM TRAINING.EMPLOYEE; -- After a test LOAD of the unload file into TRAINING.EMPLOYEE_SHADOW: SELECT COUNT(*) AS SHADOW_ROWS FROM TRAINING.EMPLOYEE_SHADOW;
B37/D37 style abends or utility failures when SYSREC fills. Increase SPACE primary and secondary quantities; use RLSE when appropriate.
Catalog typos yield object-not-found style utility messages. Query SYSTABLESPACE / SYSTABLES before the window.
Some utilities cannot run with UNLOAD on the same target depending on SHRLEVEL. Display active utilities and drain conflicting work first.
LOAD field positions do not match what UNLOAD wrote. Keep unload/load control statements together and test on a shadow table before production cutover.
Writers continued during the extract. If you need a frozen picture, use REFERENCE/NONE, unload from a QUIESCE + COPY, or unload from an image copy taken at a known point.
Base UNLOAD has restrictions around LOB and XML table spaces as sources—check IBM documentation for your release before planning extracts of those objects.
UNLOAD is pouring the toys out of the toy box into a big bag so you can carry them to another room. SHRLEVEL REFERENCE means friends can look at the toys while you pour, but nobody adds or removes toys until you finish. SHRLEVEL CHANGE means friends can still add and remove toys while you pour, so the bag might not match a photo taken at the start. When the bag is full, you check that the number of toys makes sense before you travel.
1. What does the DB2 UNLOAD utility primarily do?
2. What does SHRLEVEL REFERENCE allow during UNLOAD?
3. Can UNLOAD read from an image copy?
4. Why might UNLOAD output not match a later SELECT count?
5. Is UNLOAD the same as REORG UNLOAD ONLY?