100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

COBOL Quick Reference

A condensed cheat sheet covering program structure, PICTURE clauses, common verbs, and file I/O syntax for day-to-day COBOL development.

PracticeBeginner8 min readJul 10, 2026
Analogies

Divisions and Program Structure

Every COBOL program follows the same four-division skeleton in fixed order: IDENTIFICATION DIVISION (names the program), ENVIRONMENT DIVISION (declares file assignments to physical resources via SELECT/ASSIGN), DATA DIVISION (declares every variable and record layout), and PROCEDURE DIVISION (contains the executable logic). Missing or misordering a division is a compile-time error, since the compiler expects this exact structure regardless of program size.

🏏

Cricket analogy: It's like the fixed sequence of a Test match day — toss, then play, then breaks at fixed intervals — you can't swap the order any more than you can reorder COBOL's four divisions.

cobol
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SAMPLE01.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT CUST-FILE ASSIGN TO CUSTFILE
               ORGANIZATION IS INDEXED
               ACCESS MODE IS DYNAMIC
               RECORD KEY IS CUST-ID.

       DATA DIVISION.
       FILE SECTION.
       FD  CUST-FILE.
       01  CUST-RECORD.
           05  CUST-ID       PIC 9(6).
           05  CUST-NAME     PIC X(30).

       WORKING-STORAGE SECTION.
       01  WS-EOF-FLAG       PIC X VALUE 'N'.

       PROCEDURE DIVISION.
       MAIN-PARA.
           DISPLAY 'PROGRAM STARTED'
           STOP RUN.

Data Types and PICTURE Clauses

The PICTURE (PIC) clause defines a field's data type and size using symbols: 9 for a numeric digit, X for alphanumeric character, A for alphabetic, V for an implied (non-stored) decimal point, and S for a sign. So PIC S9(7)V99 COMP-3 describes a signed 7-digit-plus-2-decimal packed number occupying 5 bytes, while PIC X(30) is a plain 30-character alphanumeric field occupying 30 bytes as DISPLAY (character) storage.

🏏

Cricket analogy: It's like a scorecard template with fixed-width columns — 3 digits for runs, 2 for overs — where the format itself constrains exactly what can be recorded, just as a PIC clause constrains a field's shape.

Quick PIC symbol reference: 9 = numeric digit, X = alphanumeric, A = alphabetic only, V = implied decimal point (not stored), S = sign (not stored unless SIGN IS SEPARATE), and 99 in DISPLAY usage takes 1 byte per digit, while the same digits in COMP-3 take roughly half that, since COMP-3 packs two digits per byte.

Common Verbs and Statements

The most frequently used PROCEDURE DIVISION verbs are MOVE (copy data between fields), COMPUTE (evaluate an arithmetic expression), IF/EVALUATE (conditional branching, with EVALUATE acting as COBOL's structured switch statement), PERFORM (call a paragraph, with variants like PERFORM ... VARYING for loops), and STRING/UNSTRING (concatenate or split alphanumeric fields, the closest COBOL equivalent to string manipulation functions in other languages).

🏏

Cricket analogy: EVALUATE is like an umpire's decision tree for a run-out appeal — check the bails, check the throw, check the batsman's position — branching cleanly to exactly one outcome, just like EVALUATE's WHEN clauses.

EVALUATE TRUE with a series of WHEN condition clauses is generally preferred over long nested IF-ELSE chains for readability and maintainability, but remember EVALUATE does not fall through between WHEN clauses like a C-style switch without breaks — each WHEN is implicitly exclusive, which is the opposite of C/Java switch-case default behavior.

File I/O Cheatsheet

The five core file verbs are OPEN (INPUT/OUTPUT/I-O/EXTEND mode), READ (retrieve the next or a keyed record, checking AT END or INVALID KEY), WRITE (add a new record, checking INVALID KEY for indexed files), REWRITE (update an existing record in an I-O opened file), and CLOSE. For indexed VSAM files opened I-O, a program typically READs a record, checks a condition, then REWRITEs it in place — the update pattern behind most COBOL master-file maintenance programs.

🏏

Cricket analogy: It's like the fixed sequence of a review: open the review (OPEN), check the replay (READ), the third umpire confirms or overturns (REWRITE the decision), then the review closes (CLOSE) — a defined lifecycle just like COBOL file verbs.

  • Every COBOL program has four divisions in fixed order: IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURE.
  • PIC clauses define field type and size: 9 numeric, X alphanumeric, V implied decimal, S sign.
  • COMP-3 packs two digits per byte, roughly halving storage versus DISPLAY numeric fields.
  • EVALUATE is COBOL's structured alternative to long IF-ELSE chains, with exclusive WHEN branches.
  • PERFORM VARYING provides structured, counted looping similar to a for-loop in other languages.
  • OPEN, READ, WRITE, REWRITE, and CLOSE are the five core file-handling verbs.
  • The READ-then-REWRITE pattern on an I-O opened indexed file is the standard master-file update idiom.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#COBOLStudyNotes#COBOLQuickReference#COBOL#Quick#Reference#Divisions#StudyNotes#SkillVeris#ExamPrep