Copybook
A block of field declarations kept in one library and pulled into programs with COPY.
Also written COPY, copy member, copylib
Why it matters. Many programs read the same account record. The layout is written once, in a copybook, so every program agrees.
See it
The compiler pastes the copybook here, at compile time.
Syntax
COPY text-name [{OF|IN} library-name] [REPLACING ==old== BY ==new==].- text-name
- The copybook member to bring in.
- OF / IN
- Which library to take it from, when it isn't the default SYSLIB.
- REPLACING
- Change some text in the copybook as it comes in, such as a prefix.
- SYSLIB DD
- The JCL statement that names the library to search.
Try it COPY
- 1
You're in the WORKING-STORAGE SECTION of the program ZBCOPY. Bring in the account record layout. It is kept in the member ACCTREC.
COBOL COPY ACCTREC. - 2
Submit the job COMPCOPY from your DEV JCL library. It compiles ZBCOPY.
SUBMIT 'ZB0001.DEV.JCL(COMPCOPY)' - 3
Read the output of the job.
OUTPUT COMPCOPY
Remember
- COPY name pulls a member in when the program is compiled.
- Change the copybook once, compile again, and every program has the new layout.
- The compile step needs a SYSLIB DD for the copybook library.
The usual mistake
A compile step with no //SYSLIB DD
The compiler cannot find ACCTREC. It copies nothing, so every field from it is missing. The statements that use those fields fail, and the step ends with a severe error, usually RC=0012.
//SYSLIB DD DSN=ZB0001.COPYLIB,DISP=SHR
On real z/OS
MF/OS reads the SYSLIB in the compile job. A missing copybook is found when the program is run (RC 12) as well as by the checker, where a real compiler stops at compile time. The run step in MF/OS is given every member on the machine.
Where can I practise Copybook?
Right here, at ZedBank. You take a junior job at a simulated bank and use Copybook in real work, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- COBOLThe programming language most business logic on the mainframe is written in. Verbose by design, and still running the world's payments.
- DATA DIVISIONThe part of a COBOL program that declares every record layout and variable it will use.
- MemberOne named item inside a partitioned dataset, such as a single program, job or copybook within a library.
- Partitioned datasetA dataset that works like a library or folder, holding many separately named members inside one dataset.
- CompileTurning COBOL source code into machine instructions, checking the syntax and producing a listing of any errors.
- Level numberThe two-digit number in front of a COBOL data item that shows how fields nest inside a record.