The problem is, so many attempts to rewrite COBOL legacy systems or replace them with off-the-shelf solutions have ended in failure that custodians of legacy systems are now wary of these approaches to modernization. Migrating the COBOL codebase to take advantage of less-expensive hardware and software is now seen as a more viable, safer, and cheaper alternative to replacement. But keeping, and even growing, the COBOL codebase requires COBOL
programmers—and the COBOL workforce is aging and nearing retirement. In an effort to avert the workforce crisis, legacy system stakeholders have implemented initiatives to increase the number of new COBOL programmers
entering the marketplace. COBOL implementers such as IBM and Micro Focus have introduced initiatives to
encourage colleges and universities around the world to teach COBOL as part of their curriculum, training companies and in-house training groups are once more starting to provide instruction in COBOL, and employers have begun to offer a number of entry-level COBOL positions.
Over the last few years, the demand for programmers has far exceeded the supply. However, as the number of students graduating from computer science courses recovers from the year 2000 downturn, the job market is likely to become more and more competitive. In such a competitive environment, and at a time when the demand for COBOL
programmers is increasing, you may find it profitable to have a résumé that includes a knowledge of COBOL.
Who This Book Is For
This book is aimed at programmers familiar with other languages who are curious about COBOL or are working with COBOL legacy systems or who wish to take advantage of COBOL job opportunities. To get the most from this book, you must have some knowledge of programming. It is not an introductory programming text.
xxvii
■ PrefaCe
How You Should Read This Book
If you are using this book to learn to program in COBOL, rather than just dipping into it to find out how a particular construct or verb works, then you should read the book in the chapter order provided. Many chapters foreshadow or preview material that is dealt with more completely in succeeding chapters. If you read the chapters out of order, you may find the discussion confusing. However, if you wish, you may skip the first chapter, because it deals with such matters as the history of COBOL, the importance for COBOL, and the characteristics of COBOL and COBOL
applications. Even if you do skip Chapter 1, you may find it rewarding to read it later. It should provide a ready source of ammunition with which to respond to any expressions of amazement that you are learning COBOL.
xxviii
Document Outline
Contents at a Glance
Contents
About the Author
About the Technical Reviewer
Acknowledgments
Preface
Chapter 1: Introduction to COBOL What Is COBOL? COBOL’s Target Application Domain
COBOL’s Fitness for Its Application Domain
History of COBOL Beginnings
COBOL Standards COBOL ANS 68
COBOL ANS 74 (External Subprograms)
COBOL ANS 85 (Structured Programming Constructs)
COBOL ANS 2002 (OO Constructs)
The Argument for COBOL (Why COBOL?) Dominance of COBOL in Enterprise Computing
Danger, Difficulty, and Expense of Replacing Legacy COBOL Applications Replacement with a COTS Package
Complete Rewrite
Automatic Language Conversion
Wrapping the Legacy System
Code Renovation
Migration to Commodity Hardware and Software
Shortage of COBOL Programmers: Crisis and Opportunity
COBOL: The Hidden Asset
Advantages of Bespoke Software
Characteristics of COBOL Applications COBOL Applications Can Be Very Large
COBOL Applications Are Very Long-Lived
COBOL Applications Often Run in Critical Areas of Business
COBOL Applications Often Deal with Enormous Volumes of Data
Characteristics of COBOL COBOL Is Self-Documenting
COBOL Is Stable
COBOL Is Simple
COBOL Is Nonproprietary
COBOL Is Maintainable
Summary
References
Chapter 2: COBOL Foundation COBOL Idiosyncrasies
COBOL Syntax Metalanguage Some Notes on Syntax Diagrams
Example Metalanguage Divisions
Sections
Paragraphs
Sentences
Statements
Structure of COBOL Programs
The Four Divisions IDENTIFICATION DIVISION
ENVIRONMENT DIVISION
DATA DIVISION
File Section
Working-Storage Section
Data Hierarchy
PROCEDURE DIVISION
Shortest COBOL Program
COBOL Coding Rules Name Construction Comments about Naming
Comments about Program Formatting
Comments about Programming Style
Example Programs The COBOL Greeting Program
The DoCalc Program
The Condition Names Program
Chapter Exercise
Where to Get a COBOL Compiler Micro Focus Visual COBOL
OpenCOBOL
Raincode COBOL
Compileonline COBOL
Fujitsu NetCOBOL
Summary
References
Chapter 3: Data Declaration in COBOL Categories of Program Data COBOL Literals Alphanumeric Literals
Numeric Literals
Data Items (Variables) Data Type Enforcement
Figurative Constants
Elementary Data Items
Declaring Elementary Data Items PICTURE Clause Symbols
PICTURE Clause Notes
Example Declarations
Assignment in COBOL The MOVE Verb
MOVE Syntax
MOVE Rules
MOVE Combinations
MOVE Examples Alphanumeric MOVEs
Numeric MOVEs Example Set 1
Example Set 2
Structured Data Group Data Items
Level Numbers
Data Hierarchy
Level-Number Relationships Govern Hierarchy
Summary
Chapter 4: Procedure Division Basics Input and Output with ACCEPT and DISPLAY The DISPLAY Verb Notes
DISPLAY Examples
The ACCEPT Verb Rules
Required Format for System Variables
Example Program: ACCEPT and DISPLAY
Arithmetic in COBOL Common Arithmetic Template Arithmetic Template Notes
Examples of COBOL Arithmetic Statements
The ROUNDED Phrase
The ON SIZE ERROR
Nonconforming Arithmetic Verbs The COMPUTE Verb COMPUTE Examples
The ADD Verb Notes
ADD Examples
The SUBTRACT Verb Notes
SUBTRACT Examples
The MULTIPLY Verb MULTIPLY Examples
The DIVIDE Verb DIVIDE Examples
Let’s Write a Program
Summary
Chapter 5: Control Structures: Selection Selection
IF Statement
Condition Types Relation Conditions
Class Conditions Notes on Class Conditions
User-Defined Class Names
How the Program Works
Sign Conditions
Complex Conditions Truth Tables
The Effect of Bracketing
Implied Subjects
Nested IFs
Delimiting Scope: END-IF vs. Period
Condition Names Defining Condition Names Rules
Single Condition Name, Single Value
Multiple Condition Names Overlapping and Multiple-Value Condition Names
Values Can Be Alphabetic or Numeric
List Values Can Be Whole Words
Using Condition Names Correctly
Example Program
Setting a Cond
ition Name to True SET Verb Metalanguage
SET Verb Examples
Design Pattern: Reading a Sequential File
Group Item Condition Names
Condition Name Tricks
EVALUATE Decision Tables
EVALUATE Metalanguage
Notes
EVALUATE Examples Payment Totals Example
Amusement Park Example
Acme Book Club Example
Summary
References
Chapter 6: Control Structures: Iteration Paragraphs Revisited
The PERFORM Verb Open Subroutines
Closed Subroutines
COBOL Subroutines
Why Use Open Subroutines?
PERFORM NamedBlock
How PERFORM Works
PERFORM..THRU Dangers
Using PERFORM..THRU Correctly
PERFORM..TIMES Inline Execution
Out-of-Line Execution
PERFORM..UNTIL Notes on PERFORM..UNTIL
How PERFORM..UNTIL Works
PERFORM..VARYING Notes on PERFORM..VARYING
How PERFORM..VARYING Works
Summary
References
Chapter 7: Introduction to Sequential Files What Is a File ? Terminology
Files, Records, and Fields
How Files Are Processed
Implications of Buffers
File and Record Declarations
Creating a Record
Declaring the Record Buffer in Your Program
The SELECT and ASSIGN Clause
SELECT and ASSIGN Syntax
Processing Sequential Files The OPEN Statement Notes on the OPEN Statement
The CLOSE Statement Notes
The READ Statement Notes
How READ Works
The WRITE Statement Write a Record, Read a File
How WRITE works
Reading and Writing to the Employee File
Summary
Chapter 8: Advanced Sequential Files Files with Multiple Record Types Problem Specification
Implications of Files with Multiple Record Types
Multiple Record Descriptions, One Record Buffer
The Type Code Example Program
Specification Amendment
Some Comments about the Program
Printer Sequential Files SELECT and ASSIGN Notes
What Is in a Report
Problem of Multiple Print Records
Solution to the Multiple Print Record Problem
WRITE Syntax Revisited Notes on WRITE
Example Program
Report Writer Version
Variable-Length Records FD Entries for Variable-Length Records
Notes on Varying-Length Records
Example Program
Summary Output Template Entrants File
Some Statements You Need for Your Program Executable Statements
Some Data Descriptions
Chapter 9: Edited Pictures Edited Pictures
Formatting Output Immediate Editing
Example Program
Types of Editing
Editing Symbols
Insertion Editing Simple-Insertion Editing How the Symbols Work
Simple-Insertion Examples
Special-Insertion Editing Special-Insertion Examples
Fixed-Insertion Editing Plus and Minus Symbols
CR and DB
The Currency Symbol
Fixed-Insertion Examples
Floating Insertion Floating-Insertion Examples
Suppression-and-Replacement Editing Suppression-and-Replacement Examples
Example Print Lines Immediate Editing
Example Program
PICTURE String Restrictions
The PICTURE Clause Scaling Symbol Rules
Summary
Chapter 10: Processing Sequential Files File Organization vs. Method of Access
Sequential Organization Ordered and Unordered Files
Control-Break Processing Specifications that Require Control Breaks Specification Requiring a Single Control Break
Specification Requiring Two Control Breaks
Specification Requiring Three Control Breaks
Detecting the Control Break
Writing a Control-Break Program
Control-Break Program Template
Three-Level Control Break Three-Level Control-Break Program
Program Notes
Test Data and Results
An Atypical Control Break Specification
Atypical Control-Break Program
Program Notes
Test Data and Results
Updating Sequential Files Applying Transactions to an Ordered Sequential File Inserting Records in an Ordered Sequential File
Updating Records in an Ordered Sequential File
Deleting Records from an Ordered Sequential File
The File-Update Problem: Simplified Updating a Stock File: Problem Specification
Buffer Implications of Multiple Record Types
File Update Program
Program Notes
Test Data and Results
The Full File Update Problem Full File Update Program
Program Notes
Test Data and Results
Summary TestData
Notes
Chapter 11: Creating Tabular Data Tables vs. Arrays Table/Array Definition
Table/Array Differences
Declaring Tables OCCURS Clause Rules
Subscript Rules
Why Use Tabular Data? First Specification
Second Specification
Using a Table for the State Sales Totals
Third Specification: Group Items as Table Elements
Tabular Data Program
Multidimensional Tables Multidimensional Program
Correct Depiction of COBOL Tables
Three-Dimensional Tables Problem Specification
Depicting a Three-dimensional Table
Prefilled Tables REDEFINES Clause
Creating Prefilled Tables of Values
Creating a Prefilled Two-dimensional Table Prefilled Table Program
Revised Specification
Final Prefilled Table Program
ANS 85 Table Changes
Summary Specification Extension
References
Chapter 12: Advanced Data Declaration The Redefines Clause Specification: Aromamora Base Oil Sales Report The Sales File
Report Template
Notes
Oil Costs Table
Program
Test Data and Results
The REDEFINES Clause REDEFINES Syntax
REDEFINES Notes
REDEFINES Examples REDEFINES Example 1
REDEFINES Example 2
REDEFINES Example 3
REDEFINES Example 4
The RENAMES Clause RENAMES Syntax
RENAMES Notes
RENAMES Examples
Listing Notes
The USAGE Clause Representation of Numeric Data Disadvantage of USAGE DISPLAY
Advantage of USAGE IS DISPLAY
USAGE Clause Syntax
Notes
COMP Explanation
PACKED-DECIMAL Explanation
The SYNCHRONIZED Clause
Nonstandard USAGE Extensions
Decimal Arithmetic
Summary The Problems Program 1
Program 2
Program 3
Program 4
Program 1 Problem Cause
Problem Solution
Program 2 Problem Cause
Problem Solution
Program 3 Problem Cause
Problem Solution
Program 4 Problem Cause
Problem Solution
References
Chapter 13: Searching Tabular Data SEARCHING Tabular Data
Searching Using SEARCH and SEARCH ALL INDEXED BY Clause
Using SET to Manipulate the Table Index
The SEARCH Verb SEARCH Examples Letter Position Exam
ple
American States Example
Searching Multidimensional Tables
Searching the First Dimension of a Two-Dimensional Table
The SEARCH ALL Verb KEY IS Clause
How a Binary Search Works
SEARCH ALL
Michael Coughlan Page 78