The Library section is your program's data dictionary. Before any JOB reads a record or any REPORT prints a column, the compiler needs to know file names, record sizes, field positions, data types, and working storage variables. FILE and DEFINE statements supply that information. Beginners who skip careful Library coding discover problems late: compile errors for undefined fields, garbled report columns from wrong lengths, or S0C7 abends from treating text as packed decimal. This page explains how to describe files and fields so Activity logic and reports can trust every name they reference.
Broadcom places FILE and DEFINE in the Library section because data description is separate from processing logic. The compiler reads Library first to build symbol tables, then validates JOB and REPORT statements against those symbols. When you type EMPNAME in an IF statement, the compiler checks length, type, and file association defined here. Operations staff can read Library alone to learn which files a program touches and how records are structured without parsing every IF block.
A FILE statement names a file and describes its records. The name must match the DD name used in execute JCL unless site conventions map them differently. After the FILE header, each line defines one field: name, starting position, length, type, and optional decimal positions for numeric types. Positions are usually one-based within the record, matching mainframe copybook conventions beginners learn from COBOL or PL/I layouts.
12345FILE PERSNL FB(150 1800) EMPNO 1 5 N EMPNAME 6 8 A DEPT 14 3 A GROSS 40 7 P 2
PERSNL is the logical file name. FB(150 1800) describes fixed-block organization with record length 150 and block size 1800—values must match the actual dataset DCB. EMPNO starts at byte 1 for length 5 with type N (numeric display/zoned depending on context). EMPNAME is 8 bytes of alphanumeric A. GROSS is 7 bytes packed decimal P with 2 decimal places, so report masks can show 9999999.99 style output.
| Type code | Meaning | Beginner notes |
|---|---|---|
| A | Alphanumeric characters | Use for names, codes, flags stored as text |
| N | Numeric display data | Often zoned decimal in file; good for edited numeric text fields |
| P | Packed decimal | Compact numeric storage; specify decimal digits when fractions exist |
| B | Binary | Binary integers; mind alignment and length for arithmetic |
| D | Date fields | Requires date format awareness in comparisons and masks |
Choosing the wrong type is a common source of runtime abends. If GROSS is actually zoned decimal in the file but you code P, arithmetic may corrupt data or raise data exceptions. When in doubt, compare against a known good copybook, file sample, or data dictionary from the data owner—not guesswork from report appearance alone.
DEFINE creates working storage fields not mapped to a file position. Counters, switch flags, accumulated totals before writing extract files, and temporary hold areas belong here. DEFINE fields follow similar type rules but live in program memory rather than on incoming records.
123DEFINE COUNT N 5 DEFINE WS-TOTAL P 9 2 DEFINE ERR-FLAG A 1
COUNT holds a numeric counter. WS-TOTAL is packed with two decimals for money aggregation. ERR-FLAG is a one-byte alphanumeric switch. JOB logic can MOVE values into these fields, add to WS-TOTAL, or SET ERR-FLAG when validation fails. Because they are not in FILE layouts, they never appear in FILE INPUT buffer unless you explicitly MOVE them to output records.
When two files contain similarly named fields, qualify references with the file name to remove ambiguity. Broadcom documents qualified field syntax so DEPT in one file does not collide with DEPT in another. Even when names differ, qualification improves readability in multi-file programs where auditors trace which file supplied a value on a report line.
Production shops rarely hand-type fifty-field FILE statements in every program. Macros, COPY members, or %include patterns expand standard layouts into Library. When a macro library is missing at compile time, you may see cascades of undefined field errors that clear once STEPLIB or SYSLIB includes the macro source. Treat macro expansion as part of Library maintenance: one corrected layout fixes every program that includes it.
Broadcom recommends coding definitions to avoid unnecessary conversions. If a field is packed in the file, define it packed rather than defining alphanumeric and converting on every arithmetic operation. If you only need a substring, consider whether a smaller defined field or masked reference meets the need without copying entire records into working storage. These choices affect CPU on million-row jobs more than they affect tiny classroom examples.
Library names files logically; JCL DD statements connect those names to physical data sets at execute time. A perfect Library with missing PERSNL DD still fails at runtime. Conversely, correct JCL cannot fix wrong start positions—records will read, but fields will show garbage. Developers and operations share responsibility: Library accuracy and DD allocation must align.
The Library section is like the legend on a treasure map. It says where each clue sits on the page—employee number starts here, name starts there, pay amount is in this box. The JOB section is the walk you take to follow the map. If the legend is wrong, you dig in the wrong place even if you follow directions perfectly. FILE and DEFINE keep the legend accurate.
1. The FILE statement in the Library section describes:
2. DEFINE is used for:
3. Field type A in a FILE definition means:
4. Why should field names be unique across Library definitions?
5. Correct FILE definitions help performance because: