Skip to content

Language Basics

Daniel Long edited this page Sep 29, 2026 · 3 revisions

Language Basics

All programs begin with **FREE to indicate free-format RPG IV:

**FREE

// Declarations go here
DCL-S name VARCHAR(40);

// Executable statements
name = 'World';
DSPLY ('Hello, ' + %TRIM(name) + '!');

*INLR = *ON;
RETURN;

DSPLY follows IBM i's rules. An expression must be in parentheses — DSPLY ('Total: ' + x);, not DSPLY 'Total: ' + x; — and the message may be at most 52 characters, judged at compile time from the declared lengths of what it shows ('Hello, ' + a VARCHAR(40) + '!' is 48). To show something longer, assign it to a VARCHAR(52) work field and display that; the assignment keeps the first 52 characters.

Comments

// Single-line comment

Statement Terminator

Statements end with a semicolon (;), one statement to a line: after the semicolon only a comment may follow (IBM: RNF5508). A statement may run over several lines.

total = 0;          // fine: a comment after the semicolon
count = 0;  i = 1;  // rejected: two statements on one line

Clone this wiki locally