RPG (Report Program Generator) is a high-level programming language with a long history, primarily used for business applications on IBM midrange systems. RPG/400 specifically refers to the version of the language designed for the IBM AS/400 (now known as IBM i) system, introduced in the late 1980s.
Unlike "free-form" languages like Python or Java, classic RPG/400 is positional, meaning the column in which you type a character determines what that character does.
Column-Based Logic: Traditional RPG/400 uses fixed-format coding. For example, an operation code (like ADD) must start in a specific column (usually column 28).
The "Program Cycle": A unique feature where the language automatically handles reading records, updating counters, and printing totals without the programmer writing explicit loops.
Indicators: These are two-digit switches (01–99) used to control conditioning logic (e.g., if a record is found, turn on indicator 10).
Data-Centric: It is exceptionally efficient at handling DB2 databases, which are integrated directly into the OS/400 operating system.
In RPG/400, you don't just type code anywhere. You use different "Specification Sheets" to define different parts of the program:
Spec Type - Name -Purpose
H-Spec -Header - Defines program-wide settings and title.
F-Spec - File - Defines the files (databases, displays, printers) the program will use.
E-Spec - Extension - Used for defining arrays and tables.
I-Spec - Input - Defines the data structures and fields within the files.
C-Spec - Calculation - Where the actual logic (addition, moves, comparisons) happens.
O-Spec - Output - Defines the layout of reports or files being written.
RPG has evolved significantly since the RPG/400 era:
RPG II / RPG III: Used on older System/34 and System/38 machines.
RPG/400: The version standardized for the original AS/400.
RPGLE (RPG IV): Introduced in 1994. This allowed for mixed-case, longer field names, and "Bound" programs (Integrated Language Environment - ILE).
Free-Form RPG: The modern version used today, which looks much more like C# or Java and has mostly abandoned the strict column-based requirements.
A R SCREEN1
A 1 30'MULTIPLY TOOL'
A 5 5'ENTER NUM 1:'
A NUM1 5S 0I 5 20
A 6 5'ENTER NUM 2:'
A NUM2 5S 0I 6 20
A 10 5'RESULT IS:'
A RESULT 10S 0O 10 20
A 23 5'CF03 TO EXIT'
A R RPTREC
A 1 10'CALCULATION REPORT'
A NUM1 10 5 5
A 5 16'*'
A NUM2 10 5 18
A 5 29'='
A RESULT 15 5 31
H* Header Spec - Program Name: MULTIPLY
FWORKDSPFCF E WORKSTN
FWORKPRTF O E PRINTER
*
C* 1. Display the screen and wait for user input
C TAG1 TAG
C EXFMTIDSCREEN1
*
C* 2. Check if user pressed F3 (Indicator 03) to exit
C *IN03 GOTO END
*
C* 3. Multiplication Logic (Factor 1 * Factor 2 = Result)
C NUM1 MULT NUM2 RESULT
*
C* 4. Output to Printer
C WRITE RPTREC
*
C* 5. Loop back to show result on screen
C GOTO TAG1
*
C END TAG
C SETON LR
ILE RPG
H DFTACTGRP(*NO) ACTGRP(*NEW)
* File Specifications
FMYSCREEN CF E WORKSTN
FMYPRINTER O E PRINTER
* Data Specifications (Variable Definitions)
D Input1 S 5P 0
D Input2 S 5P 0
D FinalResult S 10P 0
* Main Logic
C MainLoop TAG
* 1. Display Screen (EXFMT)
C EXFMT SCREEN1
* 2. Exit if F3 is pressed (Indicator 03)
C IF *IN03 = *ON
C SETON LR
C RETURN
C ENDIF
* 3. Calculation using EVAL (Extended Factor 2)
C EVAL FinalResult = Input1 * Input2
* 4. Write to Printer
C WRITE PRT_REC
* 5. Loop back
C GOTO MainLoop