COBOL/400 is a specific implementation of the COBOL programming language designed for the IBM AS/400 (now known as IBM i) platform. While COBOL itself is a legacy language used globally for business, COBOL/400 includes specific extensions to interact with the unique architecture of IBM's midrange systems.
COBOL/400 (officially known as ILE COBOL in modern versions) is defined by its integration with the IBM i operating system.
Business-Oriented: Like all COBOL, it excels at processing large volumes of data and generating reports.
External File Descriptions: One of its most unique features is that it does not require you to define file structures inside the program. It can "copy" the definitions directly from the database (DB2 for i) using the COPY DDS statement.
Integrated Language Environment (ILE): Modern COBOL/400 allows you to bind modules written in different languages (like RPG or C) into a single executable program.
Every COBOL/400 program is structured into four mandatory divisions:
Identification Division: Contains the program name and author details.
Environment Division: Specifies the computer hardware and links the program to external files.
Data Division: Defines the variables, constants, and record layouts.
Procedure Division: Contains the logic—the actual instructions that the computer executes.
On the AS/400, the database is integrated into the OS. COBOL/400 uses DDS (Data Description Specifications) to handle files.
Physical Files (PF): The actual data storage.
Logical Files (LF): Different "views" or indexes of that data.
COBOL/400 uses indicators (two-digit switches from 01-99) to communicate with display files (screens) and printers. For example, an indicator can be used to make a field on a screen turn red or become protected.
Unlike modern web languages, COBOL/400 uses "Workstation Files" to interact with green-screen terminals (5250 emulators). You define the UI in a separate DDS file and the COBOL program simply "WRITES" to that screen format.
Modern Context: ILE COBOL
Today, COBOL/400 has evolved into ILE COBOL. This allows for:
Free-format code (removing the strict "column-based" coding rules of the 70s).
Stored Procedures: Using COBOL as the logic layer for SQL-based web applications.
XML/JSON parsing: New statements to handle modern data formats.
IDENTIFICATION DIVISION.
PROGRAM-ID. MULTIPLY.
AUTHOR. GEMINI-AI.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
* SELECTING THE PRINTER FILE
SELECT PRINT-OUT ASSIGN TO PRINTER-QPRINT.
DATA DIVISION.
FILE SECTION.
FD PRINT-OUT.
01 PRINT-REC.
05 FILLER PIC X(10) VALUE SPACES.
05 P-RESULT-MSG PIC X(30).
WORKING-STORAGE SECTION.
* INPUT VARIABLES
01 INPUT-DATA.
05 NUM-1 PIC 9(5)V99.
05 NUM-2 PIC 9(5)V99.
* CALCULATION VARIABLE
01 CALC-RESULT PIC 9(10)V99.
* FORMATTED OUTPUT FOR DISPLAY/PRINT
01 DISPLAY-RESULT PIC Z,ZZZ,ZZ9.99.
PROCEDURE DIVISION.
MAIN-LOGIC.
* 1. ACCEPT INPUT FROM USER
DISPLAY "ENTER FIRST NUMBER (7 DIGITS): ".
ACCEPT NUM-1.
DISPLAY "ENTER SECOND NUMBER (7 DIGITS): ".
ACCEPT NUM-2.
* 2. PERFORM MULTIPLICATION
MULTIPLY NUM-1 BY NUM-2 GIVING CALC-RESULT.
* 3. FORMAT THE RESULT
MOVE CALC-RESULT TO DISPLAY-RESULT.
* 4. OUTPUT TO SCREEN
DISPLAY "THE MULTIPLICATION RESULT IS: " DISPLAY-RESULT.
* 5. OUTPUT TO PRINTER
OPEN OUTPUT PRINT-OUT.
STRING "FINAL RESULT: " DISPLAY-RESULT
DELIMITED BY SIZE INTO P-RESULT-MSG.
WRITE PRINT-REC.
CLOSE PRINT-OUT.
STOP RUN.