Complete AS/400 RPG Application: Input, Output, and Storage
Introduction
The AS/400 system (now IBM i) uses RPG (Report Program Generator) to build robust business applications. This guide covers a complete RPG application, including user input, data processing, and database storage.
Database Table (DB2)
First, create a DB2 table to store customer data.
CREATE TABLE CUSTOMERS ( ID INT PRIMARY KEY, NAME VARCHAR(50), BALANCE DECIMAL(10,2) );
Display File (User Input) - CUSTDSPF.DSPF
A DDS (Data Description Specifications) file for user input.
A R CUSTOMER A CUSTID 5 0B 5 2 A CUSTNAME 20 B 7 2 A CUSTBAL 10 2B 9 2 A ENTERKEY 1 0B 11 2 A K ENTERKEY
RPGLE Program (Processing and Storage) - CUSTRPG.RPGLE
This program interacts with the user, retrieves input, and updates the database.
**Free DCLF CUSTDSPF; DCL-S CustomerName CHAR(20); DCL-S CustomerBalance PACKED(10:2); EXFMT CUSTOMER; // Display input screen IF ENTERKEY = '1'; EXEC SQL INSERT INTO CUSTOMERS (ID, NAME, BALANCE) VALUES (:CUSTID, :CUSTNAME, :CUSTBAL); DSPLY 'Record Saved Successfully'; ENDIF; *INLR = *ON;
Retrieving and Displaying Stored Data
**Free DCL-S CustName CHAR(20); DCL-S CustBalance PACKED(10:2); EXEC SQL SELECT NAME, BALANCE INTO :CustName, :CustBalance FROM CUSTOMERS WHERE ID = :CUSTID; DSPLY 'Customer Name: ' + CustName; DSPLY 'Customer Balance: ' + %CHAR(CustBalance); *INLR = *ON;
Conclusion
This complete RPG application allows users to input customer details, store them in DB2, and retrieve them later.