Skip to content

Multi Module Programs

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

Multi-Module Programs

For larger applications, split code across modules:

mathlib.rpgle (module — no main):

**FREE
CTL-OPT NOMAIN;

DCL-PROC Add EXPORT;
  DCL-PI *N INT(10);
    a INT(10) VALUE;
    b INT(10) VALUE;
  END-PI;
  RETURN a + b;
END-PROC;

main.rpgle (main program):

**FREE

DCL-PR Add INT(10) EXTPROC('ADD');
  a INT(10) VALUE;
  b INT(10) VALUE;
END-PR;

DCL-S result INT(10);
result = Add(3 : 5);
DSPLY %CHAR(result);

RETURN;

Build:

rpgc -c mathlib.rpgle              # produces mathlib.o
rpgc main.rpgle mathlib.o -o myapp # compiles main and links with module

The EXTPROC name is case-sensitive, and procedure names are exported upper-cased. DCL-PROC Add EXPORT exports the symbol ADD, so the caller must say EXTPROC('ADD') — EXTPROC('Add') compiles both sides cleanly and then fails at link time with an undefined symbol.

Clone this wiki locally