An IBMi RPG sub-procedure is a modular piece of code within an RPG (Report Program Generator) program on the IBM i Power System (the replacement for he IBM iSeries and even older AS400).
Here are some key points about sub-procedures:
Here's a simple example of a sub-procedure in RPG:
// Prototype for the sub-procedure
DCL-PR CalculateSum INT(10);
TERM1 INT(5) VALUE;
TERM2 INT(5) VALUE;
END-PR;
// Definition of the sub-procedure
DCL-PROC CalculateSum;
DCL-PI *N INT(10);
TERM1 INT(5) VALUE;
TERM2 INT(5) VALUE;
END-PI;
DCL-S Result INT(10);
DCL-PR CalculateSum INT(10);
TERM1 INT(5) VALUE;
TERM2 INT(5) VALUE;
END-PR;
// Definition of the sub-procedure
DCL-PROC CalculateSum;
DCL-PI *N INT(10);
TERM1 INT(5) VALUE;
TERM2 INT(5) VALUE;
END-PI;
DCL-S Result INT(10);
Result = TERM1 + TERM2;
RETURN Result;
END-PROC;
In this example, `CalculateSum` is a sub-procedure that takes two integer parameters and returns their sum.