MainframeMaster

COBOL Tutorial

COBOL UNIT - Quick Reference

Progress0 of 0 lessons

Overview

UNIT is a system/JCL concept indicating a device class or number. COBOL files are typically assigned via DDNAMEs, with UNIT specified in JCL for physical allocation.

Common Patterns

  • Device class - UNIT=SYSDA, UNIT=TAPE
  • COBOL mapping - SELECT ASSIGN TO ddname; JCL DD binds device
  • Portability - Keep device specifics outside COBOL source

Syntax and Usage

COBOL File Assignment

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
* COBOL file assigned to a DDNAME ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INFILE ASSIGN TO "INFILE". DATA DIVISION. FILE SECTION. FD INFILE. 01 IN-REC PIC X(80). PROCEDURE DIVISION. OPEN INPUT INFILE READ INFILE AT END DISPLAY "EOF" END-READ CLOSE INFILE STOP RUN.

The JCL DD named INFILE will control device allocation (UNIT, SPACE, etc.).

JCL UNIT Parameter

jcl
1
2
3
4
//* JCL example //STEP1 EXEC PGM=COBPROG //INFILE DD DSN=MY.DATASET,DISP=SHR,UNIT=SYSDA //OUTFILE DD DSN=*.TEMP,DISP=(,CATLG),SPACE=(CYL,(5,5)),UNIT=SYSDA

UNIT selects the device class; SMS may override explicit UNIT based on policies.

Best Practices

  • Abstraction - Keep device specifics in JCL or deployment configs
  • Standards - Follow site allocation rules and SMS classes
  • Testing - Validate on the target system with real allocations

UNIT Quick Reference

AspectDescriptionExample
Device classUNIT= parameterUNIT=SYSDA
DD mappingCOBOL ASSIGN TO DDASSIGN TO "INFILE"
PortabilityKeep in JCLDD with UNIT set

Test Your Knowledge

1. What does UNIT typically refer to in mainframe contexts?

  • A COBOL arithmetic verb
  • A device class or device number used by the operating system/JCL
  • A COBOL intrinsic function
  • A screen control command

2. How does COBOL usually connect to a device/unit?

  • Directly specifying UNIT in the ENVIRONMENT DIVISION
  • Through file assignment (SELECT ASSIGN TO DDNAME) with JCL controlling UNIT
  • Using PERFORM UNIT
  • By setting UNIT in the IDENTIFICATION DIVISION

3. Which JCL parameter commonly controls device allocation?

  • UNIT=
  • CLASS=
  • REGION=
  • PARM=

4. What is a best practice for portability regarding UNIT?

  • Hard-code physical devices in the COBOL source
  • Use DDNAMEs in COBOL and configure UNIT in JCL or environment
  • Always use tape devices
  • Avoid JCL entirely

5. What happens if UNIT is omitted in JCL?

  • The COBOL runtime fails immediately
  • The system selects defaults based on installation standards
  • The program switches to screen mode
  • The dataset is always temporary

Frequently Asked Questions