Program Structure:
IDENTIFICATION DIVISION.
PROGRAM-ID. ProgramName.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 VariableName PIC X(10).
PROCEDURE DIVISION.
Display 'Hello, World!'.
STOP RUN.
Data Types:
- Alphanumeric:
PIC X(n)
(e.g.,PIC X(10)
for a 10-character string). - Numeric:
PIC 9(n)
(e.g.,PIC 9(3)
for a 3-digit number).
Data Division:
- File Definition:
FILE SECTION.
FD File-Name.
01 Record-Name.
05 Field1 PIC X(10).
05 Field2 PIC 9(3).
Working with Data:
- MOVE Statement:
MOVE 'Value' TO VariableName.
- ADD Statement:
ADD 10 TO NumVariable.
- SUBTRACT Statement:
SUBTRACT 5 FROM NumVariable.
Conditional Statements:
- IF Statement:
IF Condition
Perform Some-Operation
END-IF.
- EVALUATE Statement:
EVALUATE Variable
WHEN 1
Perform Operation-1
WHEN 2
Perform Operation-2
WHEN OTHER
Perform Default-Operation
END-EVALUATE.
Loops:
- PERFORM UNTIL:
PERFORM UNTIL Condition
Perform Some-Operation
END-PERFORM.
- PERFORM VARYING:
PERFORM VARYING Counter FROM 1 BY 1 UNTIL Counter > 10
Perform Some-Operation
END-PERFORM.
Procedures:
- Paragraphs:
Some-Operation.
Display 'Performing Some Operation'.
...
File Handling:
- OPEN, READ, CLOSE File:
OPEN INPUT File-Name.
READ File-Name INTO Record-Name.
CLOSE File-Name.
Display Output:
- DISPLAY Statement:
DISPLAY 'Hello, World!'.
Stop Execution:
- STOP RUN Statement:
STOP RUN.
This is a basic COBOL cheat sheet covering fundamental syntax and constructs. COBOL is known for its verbose syntax, and this cheat sheet provides a starting point for understanding its structure and commonly used statements.