AS/400 RPG with Data Integration
Introduction
The AS/400 system (now IBM i) uses RPG (Report Program Generator) as a primary language for business applications. RPG allows integration with DB2 databases and other data sources.
Basic RPGLE Program Structure
**Free DCL-S message CHAR(50); message = 'Hello, AS/400 RPG!'; DSPLY message; *INLR = *ON;
Database Integration (Reading from DB2)
To integrate RPG with a DB2 database, we use SQLRPGLE for embedded SQL.
**Free DCL-S CustName CHAR(50); EXEC SQL DECLARE CUST_CURSOR CURSOR FOR SELECT NAME FROM CUSTOMERS WHERE ID = 1001; EXEC SQL OPEN CUST_CURSOR; EXEC SQL FETCH CUST_CURSOR INTO :CustName; EXEC SQL CLOSE CUST_CURSOR; DSPLY CustName; *INLR = *ON;
Interactive Prompts with Display Files
To create an interactive program, we use DDS (Data Description Specifications) to design a display file.
Display File (Prompt Screen) - CUSTDSPF.DSPF
A R CUSTOMER A CUSTID 5 0B 5 2 A CUSTNAME 20 B 7 2 A ENTERKEY 1 0B 9 2 A K ENTERKEY
RPG Program with Display File - CUSTRPG.RPGLE
**Free DCLF CUSTDSPF; DCL-S CustomerName CHAR(20); EXFMT CUSTOMER; // Display the prompt screen IF ENTERKEY = '1'; EXEC SQL SELECT NAME INTO :CustomerName FROM CUSTOMERS WHERE ID = :CUSTID; CUSTNAME = CustomerName; EXFMT CUSTOMER; ENDIF; *INLR = *ON;
Conclusion
This guide demonstrates how to integrate RPG with DB2 and display files for interactive prompts.