Learn Rpg-iv-as400 - 10 Code Examples & CST Typing Practice Test
RPG IV (also known as RPGLE) is a high-level programming language for IBM i (AS/400) systems, designed for business applications, supporting structured programming, modern free-form syntax, and integration with DB2 databases.
Learn RPG-IV-AS400 with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
Simple Hello World in RPG IV
FQPRINT O F 132 PRINTER
DCL-S Msg CHAR(50);
Msg = 'Hello, AS400 World!';
DSPLY Msg;
*INLR = *ON;
Display a simple greeting message on the screen.
Basic Arithmetic Calculation
DCL-S Price PACKED(7:2) INZ(100);
DCL-S TaxRate PACKED(5:2) INZ(0.13);
DCL-S TaxAmount PACKED(7:2);
DCL-S Total PACKED(7:2);
TaxAmount = Price * TaxRate;
Total = Price + TaxAmount;
DSPLY ('Total Price: ' + %CHAR(Total));
*INLR = *ON;
Compute total price including tax.
Read Data from a File
FEMPFILE IF A E K DISK
DCL-S EmpName CHAR(30);
READ EMPFILE;
DOW NOT %EOF(EMPFILE);
EmpName = EMPNAME;
DSPLY EmpName;
READ EMPFILE;
ENDDO;
*INLR = *ON;
Read records from a physical file and display them.
Update a Field in a File
FEMPFILE UF E K DISK
DCL-S NewSalary PACKED(7:2) INZ(5000);
CHAIN '1001' EMPFILE;
IF %FOUND(EMPFILE);
SALARY = NewSalary;
UPDATE EMPFILE;
ENDIF;
*INLR = *ON;
Change the salary of an employee in the file.
Conditional Processing
DCL-S Status CHAR(1);
Status = 'A';
IF Status = 'A';
DSPLY 'Employee is Active';
ELSE;
DSPLY 'Employee is Inactive';
ENDIF;
*INLR = *ON;
Check employee status and display a message.
Loop Through Records
FEMPFILE IF A E K DISK
DOW '1';
READ EMPFILE;
IF %EOF(EMPFILE); LEAVE; ENDIF;
DSPLY EMPNAME;
ENDDO;
*INLR = *ON;
Process all employees in a file using a loop.
Perform Subprocedure
DCL-PROC CalcBonus;
DCL-PI CalcBonus PACKED(7:2) END-PI;
DCL-PI Amount PACKED(7:2) END-PI;
RETURN Amount * 0.10;
END-PROC;
DCL-S Bonus PACKED(7:2);
Bonus = CalcBonus(5000);
DSPLY ('Bonus: ' + %CHAR(Bonus));
*INLR = *ON;
Call a subprocedure to calculate bonus.
Use Array in RPG IV
DCL-S DeptCodes CHAR(5) DIM(5) INZ;
DeptCodes(1) = 'HR';
DeptCodes(2) = 'IT';
DeptCodes(3) = 'FIN';
FOR i = 1 TO 3;
DSPLY DeptCodes(i);
ENDFOR;
*INLR = *ON;
Store and display multiple department codes using an array.
Conditional Loop With Leave
FEMPFILE IF A E K DISK
DOW '1';
READ EMPFILE;
IF %EOF(EMPFILE); LEAVE; ENDIF;
IF SALARY > 10000; LEAVE; ENDIF;
DSPLY EMPNAME;
ENDDO;
*INLR = *ON;
Process records until a condition is met, then exit the loop.
Calculate and Display Totals
FEMPFILE IF A E K DISK
DCL-S TotalSalary PACKED(9:2) INZ(0);
READ EMPFILE;
DOW NOT %EOF(EMPFILE);
TotalSalary += SALARY;
READ EMPFILE;
ENDDO;
DSPLY ('Total Salary: ' + %CHAR(TotalSalary));
*INLR = *ON;
Sum salaries of all employees and display the total.
Frequently Asked Questions about Rpg-iv-as400
What is Rpg-iv-as400?
RPG IV (also known as RPGLE) is a high-level programming language for IBM i (AS/400) systems, designed for business applications, supporting structured programming, modern free-form syntax, and integration with DB2 databases.
What are the primary use cases for Rpg-iv-as400?
Developing core business applications on IBM i. Transaction processing and batch jobs. Integration with DB2 databases. Generating reports and financial calculations. Maintaining legacy ERP and order processing systems
What are the strengths of Rpg-iv-as400?
Optimized for IBM i platform performance. Seamless database access with DB2. Reliable and mature for enterprise-critical applications. Supports modular and maintainable code practices. Large existing ecosystem of legacy business applications
What are the limitations of Rpg-iv-as400?
Primarily limited to IBM i / AS/400 systems. Less popular outside legacy enterprise environments. Modern GUI/web development requires additional tools. Complex for developers unfamiliar with IBM i. Debugging and deployment require IBM i expertise
How can I practice Rpg-iv-as400 typing speed?
CodeSpeedTest offers 10+ real Rpg-iv-as400 code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.