COBOL Tutorial

Progress0 of 0 lessons

COBOL LABEL RECORDS - Syntax Quick Reference

The LABEL RECORDS clause specifies whether a file contains labels and, if so, their format. This clause appears in the File Description (FD) entry within the FILE SECTION and is essential for proper file identification and management, especially in mainframe environments with tape files and disk datasets.

Basic Syntax

cobol
1
LABEL RECORDS ARE {STANDARD | OMITTED | data-name-1 [, data-name-2]...}

The LABEL RECORDS clause can be specified in three ways:

  • STANDARD: Indicates system-managed labels conforming to system specifications
  • OMITTED: Specifies that the file has no labels
  • data-name: Specifies user-defined label names (rarely used)

LABEL RECORDS Options Explained

1. LABEL RECORDS ARE STANDARD

STANDARD indicates that the file has labels conforming to system specifications. This is commonly used for:

  • Disk files that need proper file identification
  • Tape files requiring volume serial numbers and file headers
  • Files that need system-managed label processing
  • Production data files in mainframe environments
cobol
1
2
3
4
5
FD CUSTOMER-MASTER LABEL RECORDS ARE STANDARD RECORD CONTAINS 200 CHARACTERS BLOCK CONTAINS 50 RECORDS DATA RECORDS ARE CUSTOMER-RECORD.

2. LABEL RECORDS ARE OMITTED

OMITTED specifies that the file does not have labels. This is typically used for:

  • Printer output files
  • Temporary work files
  • Files where label management is handled externally
  • Report files that don't require label processing
cobol
1
2
3
4
FD REPORT-FILE LABEL RECORDS ARE OMITTED RECORD CONTAINS 132 CHARACTERS DATA RECORD IS REPORT-LINE.

3. User-Defined Labels

You can specify user-defined label names, though this is rarely used in modern COBOL:

cobol
1
2
3
FD SPECIAL-FILE LABEL RECORDS ARE CUSTOM-LABEL-1, CUSTOM-LABEL-2 RECORD CONTAINS 100 CHARACTERS.

Complete File Description Examples

Example 1: Tape File with Standard Labels

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT TRANSACTION-TAPE ASSIGN TO "TRANS.TAPE" ORGANIZATION IS SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS WS-TRANS-STATUS. DATA DIVISION. FILE SECTION. FD TRANSACTION-TAPE LABEL RECORDS ARE STANDARD BLOCK CONTAINS 100 RECORDS RECORD CONTAINS 80 CHARACTERS DATA RECORDS ARE TRANSACTION-RECORD. 01 TRANSACTION-RECORD. 05 TRANS-ID PIC X(10). 05 TRANS-DATE PIC 9(8). 05 TRANS-AMOUNT PIC S9(10)V99. 05 TRANS-TYPE PIC X(5). 05 TRANS-ACCOUNT PIC X(15). 05 TRANS-DESCRIPTION PIC X(30).

Example 2: Printer File with Omitted Labels

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT REPORT-FILE ASSIGN TO "REPORT.OUTPUT" ORGANIZATION IS SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS WS-REPORT-STATUS. DATA DIVISION. FILE SECTION. FD REPORT-FILE LABEL RECORDS ARE OMITTED RECORD CONTAINS 132 CHARACTERS DATA RECORD IS REPORT-LINE. 01 REPORT-LINE PIC X(132).

Example 3: Disk File with Standard Labels

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CUSTOMER-MASTER ASSIGN TO "CUSTMAST.DAT" ORGANIZATION IS SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS WS-MASTER-STATUS. DATA DIVISION. FILE SECTION. FD CUSTOMER-MASTER LABEL RECORDS ARE STANDARD BLOCK CONTAINS 50 RECORDS RECORD CONTAINS 200 CHARACTERS DATA RECORDS ARE CUSTOMER-RECORD. 01 CUSTOMER-RECORD. 05 CUST-ID PIC X(10). 05 CUST-NAME PIC X(40). 05 CUST-ADDRESS PIC X(60). 05 CUST-PHONE PIC X(15). 05 CUST-CREDIT-INFO. 10 CUST-CREDIT-LIMIT PIC 9(8)V99. 10 CUST-BALANCE PIC S9(8)V99. 10 CUST-LAST-PAYMENT PIC 9(8). 05 CUST-STATUS PIC X(10). 05 FILLER PIC X(47).

Example 4: Temporary Work File with Omitted Labels

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT WORK-FILE ASSIGN TO "WORK.FILE" ORGANIZATION IS SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS WS-WORK-STATUS. DATA DIVISION. FILE SECTION. FD WORK-FILE LABEL RECORDS ARE OMITTED RECORD CONTAINS 120 CHARACTERS DATA RECORDS ARE WORK-RECORD. 01 WORK-RECORD. 05 WORK-KEY PIC X(15). 05 WORK-DATA PIC X(100). 05 WORK-FLAGS PIC X(5).

When to Use Each Option

LABEL RECORDS options and their use cases
OptionUse CaseExample Files
STANDARDFiles requiring system-managed file identification and volume managementTape files, disk datasets, production data files, master files
OMITTEDFiles that don't require label processing or where labels are managed externallyPrinter files, report files, temporary work files, console output
User-definedCustom label processing requirements (rarely used)Specialized file formats with custom label handling

Default Behavior

If the LABEL RECORDS clause is omitted entirely, the default behavior depends on the COBOL implementation:

  • Some compilers assume STANDARD when the clause is omitted
  • Other compilers assume OMITTED when the clause is omitted
  • Modern implementations may treat it as syntax-only

Best Practice: Always explicitly specify LABEL RECORDS to avoid ambiguity and ensure code portability across different COBOL implementations.

Modern Considerations

In modern COBOL implementations, the LABEL RECORDS clause is often treated as syntax-only and may not affect program execution. File labeling is typically managed by:

  • The operating system (for disk files)
  • The file system (for modern storage systems)
  • External utilities (for tape management)

However, the clause is still required syntax for proper file descriptions and should be included for:

  • Code compatibility with different COBOL compilers
  • Documentation purposes (indicating file type and usage)
  • Compliance with COBOL standards

Common Patterns

Pattern 1: Sequential Input File

cobol
1
2
3
4
FD INPUT-FILE LABEL RECORDS ARE STANDARD RECORD CONTAINS 100 CHARACTERS DATA RECORD IS INPUT-RECORD.

Pattern 2: Sequential Output File

cobol
1
2
3
4
FD OUTPUT-FILE LABEL RECORDS ARE STANDARD RECORD CONTAINS 150 CHARACTERS DATA RECORD IS OUTPUT-RECORD.

Pattern 3: Report File

cobol
1
2
3
4
FD REPORT-FILE LABEL RECORDS ARE OMITTED RECORD CONTAINS 132 CHARACTERS DATA RECORD IS REPORT-LINE.

Best Practices

1. Always Specify LABEL RECORDS

Explicitly specify LABEL RECORDS in every FD entry to avoid ambiguity and ensure code portability.

2. Use STANDARD for Data Files

Use LABEL RECORDS ARE STANDARD for all production data files, tape files, and disk datasets that require proper file identification.

3. Use OMITTED for Output Files

Use LABEL RECORDS ARE OMITTED for printer files, report files, and temporary work files that don't require label processing.

4. Document Your Choices

Add comments explaining why you chose STANDARD or OMITTED for each file, especially if the choice is non-obvious.

Explain It Like I'm 5 Years Old

Imagine files are like boxes with name tags:

When you have a box, you might put a name tag on it so you know what's inside. LABEL RECORDS STANDARD is like having a special name tag that the computer system writes and manages for you - it tells everyone what's in the box and where it came from.

LABEL RECORDS OMITTED is like a box without a name tag - maybe it's a temporary box you're using right now, or maybe the name tag is written somewhere else. The computer doesn't need to manage a name tag for this box.

Just like you choose whether to put a name tag on your box, COBOL programs choose whether files need system-managed labels or not!

Exercises

Exercise 1: Tape File Definition

Write a complete FD entry for a tape file named BACKUP-TAPE that contains 500-character records, uses standard labels, and blocks 200 records.

cobol
1
2
3
4
5
FD BACKUP-TAPE LABEL RECORDS ARE STANDARD BLOCK CONTAINS 200 RECORDS RECORD CONTAINS 500 CHARACTERS DATA RECORD IS BACKUP-RECORD.

Exercise 2: Report File Definition

Write a complete FD entry for a report file that prints 80-character lines and doesn't need labels.

cobol
1
2
3
4
FD REPORT-FILE LABEL RECORDS ARE OMITTED RECORD CONTAINS 80 CHARACTERS DATA RECORD IS REPORT-LINE.

Exercise 3: Complete File Definition

Create a complete file definition (FILE-CONTROL and FD) for a customer master file with standard labels, 200-character records, and 50-record blocks.

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CUSTOMER-MASTER ASSIGN TO "CUSTMAST.DAT" ORGANIZATION IS SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS WS-MASTER-STATUS. DATA DIVISION. FILE SECTION. FD CUSTOMER-MASTER LABEL RECORDS ARE STANDARD BLOCK CONTAINS 50 RECORDS RECORD CONTAINS 200 CHARACTERS DATA RECORDS ARE CUSTOMER-RECORD.

Test Your Knowledge

1. What does LABEL RECORDS STANDARD indicate?

  • The file has no labels
  • The file has system-managed labels
  • The file uses custom labels
  • The file labels are optional

2. Which LABEL RECORDS option is typically used for printer files?

  • STANDARD
  • OMITTED
  • USER-DEFINED
  • AUTOMATIC

3. Where does the LABEL RECORDS clause appear?

  • In the FILE-CONTROL paragraph
  • In the File Description (FD) entry
  • In the WORKING-STORAGE SECTION
  • In the PROCEDURE DIVISION

4. What is the default behavior if LABEL RECORDS is omitted?

  • Always STANDARD
  • Always OMITTED
  • Depends on the COBOL implementation
  • Always causes a compilation error

5. Which file type most commonly uses LABEL RECORDS STANDARD?

  • Printer files
  • Tape files
  • Console output
  • Temporary work files

Related Pages