Catalog / COBOL Cheatsheet
COBOL Cheatsheet
A quick reference guide to COBOL syntax, data types, control structures, and other essential elements.
COBOL Fundamentals
Program Structure
COBOL programs are divided into four divisions:
|
Example:
|
Data Types
|
Alphanumeric data, |
|
Numeric data, |
|
Alphabetic data, |
|
Signed numeric data, |
|
Implied decimal point. |
Data Definition
Data is defined in the Example:
|
Control Structures
IF Statement
Conditional execution based on a condition. Syntax:
Example:
|
EVALUATE Statement
Multi-way branch based on the value of a variable. Syntax:
Example:
|
PERFORM Statement
|
Executes a paragraph once. |
|
Executes a paragraph |
|
Executes a paragraph until the condition is true. |
|
Executes a paragraph, varying a counter from an initial value by an increment until a condition is met. |
File Handling
File Section
Describes the structure and organization of data files. Example:
|
File Operations
|
Opens a file for reading. |
|
Opens a file for writing. |
|
Reads a record from a file. |
|
Writes a record to a file. |
|
Closes a file. |
Example: Reading a File
|
String Handling & Tables
String Manipulation
|
Concatenates strings into a single string. |
|
Splits a string into multiple strings based on delimiters. |
|
Replaces characters or substrings within a string. |
Tables (Arrays)
Tables are defined using the Example:
|
Accessing table elements:
|
Example of Table Processing:
|
Search Statement
The Example:
|