Repository navigation
Procedure Overloading
danlong005 edited this page Aug 30, 2026
·
2 revisions
OVERLOAD declares a generic procedure name that dispatches to one of several
typed implementations based on argument types at call time.
// Typed implementations
DCL-PR absInt INT(10);
n INT(10) VALUE;
END-PR;
DCL-PR absFloat FLOAT(8);
n FLOAT(8) VALUE;
END-PR;
// Generic overloaded name
DCL-PR abs OVERLOAD(absInt : absFloat);
END-PR;The compiler selects the implementation whose parameter types best match the argument types at the call site:
DCL-S i INT(10);
DCL-S f FLOAT(8);
i = abs(-7); // calls absInt
f = abs(-3.5); // calls absFloat**FREE
CTL-OPT MAIN(main);
DCL-PR formatInt VARCHAR(30);
n INT(10) VALUE;
END-PR;
DCL-PR formatFloat VARCHAR(30);
n FLOAT(8) VALUE;
END-PR;
DCL-PR format OVERLOAD(formatInt : formatFloat);
END-PR;
DCL-PROC main;
DCL-PI main; END-PI;
DSPLY format(42); // calls formatInt → "INT:42"
DSPLY format(3.14); // calls formatFloat → "FLT:3"
END-PROC;
DCL-PROC formatInt EXPORT;
DCL-PI formatInt VARCHAR(30);
n INT(10) VALUE;
END-PI;
RETURN 'INT:' + %CHAR(n);
END-PROC;
DCL-PROC formatFloat EXPORT;
DCL-PI formatFloat VARCHAR(30);
n FLOAT(8) VALUE;
END-PI;
RETURN 'FLT:' + %CHAR(%INT(n));
END-PROC;- Installation
- Quick Start
- CLI Reference
- Language Basics
- Data Types
- Variables and Constants
- Data Structures
- Arrays
- Varying-Dimension Arrays
- Control Flow
- Procedures
- Procedure Overloading
- Built-In Functions
- Error Handling
- Operation Extenders
- Enumerations
- Program Status Data Structure
- Data Areas
- SND-MSG
- Embedded SQL
- Record-Level Access
- Display Files (WORKSTN)
- Program-Described Files (I-Specs and O-Specs)
- DATA-INTO and DATA-GEN
- XML-INTO
- Fixed-Format Source
- Database Connections
- Multi-Module Programs
- Environment Variables
- Testing
- Complete Example: Employee Report
- IBM i Conformance Results
- IBM i Execution Results