Who Knew You Could Do That with RPG IV? Modern RPG for the Modern Programmer
Total Page:16
File Type:pdf, Size:1020Kb
Front cover Who Knew You Could Do That with RPG IV? Modern RPG for the Modern Programmer Rich Diedrich Jim Diephuis Susan Gantner Jeff Minette Jon Paris Kody Robinson Tim Rowe Paul Tuohy Redbooks International Technical Support Organization Who Knew You Could Do That with RPG IV? Modern RPG for the Modern Programmer December 2016 SG24-5402-01 Note: Before using this information and the product it supports, read the information in “Notices” on page ix. Second Edition (December 2016) This edition applies to Version 7, Release 2, Modification 0, Technology Refresh 1 of IBM i (5770-SS1) and IBM Rational Development Studio for i (5770-WDS). © Copyright International Business Machines Corporation 2000, 2016. All rights reserved. Note to U.S. Government Users Restricted Rights -- Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Notices . ix Trademarks . .x Preface . xi Authors. xi Now you can become a published author, too! . xiv Comments welcome. xiv Stay connected to IBM Redbooks . .xv Chapter 1. Introduction to RPG IV . 1 1.1 Why update this book on RPG IV now? . 3 1.2 Evolution of the RPG IV language . 3 1.2.1 Examples in this book are based on IBM i 7.2 . 7 1.3 The future for RPG IV . 7 1.3.1 A future for RPG programmers . 7 1.4 A roadmap. 8 1.4.1 Step 1: RPG IV and RDi . 8 1.4.2 Step 2: Modularization by using ILE . 9 1.4.3 Step 3: Using database features. 9 1.4.4 Step 4: Modernizing the user interface . 9 1.5 RPG IV sources on the web . 10 Chapter 2. Programming RPG IV with style . 11 2.1 Just another programming language . 12 2.2 RPG is free-form . 12 2.2.1 The modern free-form RPG . 12 2.2.2 The basics of /Free coding . 13 2.2.3 Unsupported op-codes . 14 2.2.4 Op-codes that tend to produce unclear and error-prone source code . 15 2.2.5 Liberating data and file definitions . 15 2.2.6 Data declarations . 18 2.2.7 More on data definitions . 21 2.2.8 Defining prototypes and subprocedures . 23 2.2.9 Miscellaneous topics. 26 2.2.10 Moving to free-form. 27 2.3 Modern RPG programs and subprocedures . 28 2.4 Naming . 28 2.4.1 The names . 29 2.4.2 Case . 29 2.4.3 Special characters . 29 2.4.4 Underscore . 29 2.4.5 Named constants . 30 2.4.6 Naming conventions . 30 2.5 Comments. 31 2.5.1 Summary comments . 31 2.5.2 Detailed commenting . 31 2.5.3 Other commenting . 31 2.5.4 Positions 1 - 5 . 32 2.6 Structuring code . 32 © Copyright IBM Corp. 2000, 2016. All rights reserved. iii 2.6.1 Declarative code . 32 2.6.2 Executable code . 33 2.6.3 Multipath comparison . 34 2.6.4 Embedded SQL . 35 2.7 Using templates and qualified data structures . 35 2.8 Qualifying wherever possible . 36 2.9 Strings . 36 2.10 Subroutines . 36 2.11 Older functions . 36 2.11.1 RPG built-in indicators . 36 2.11.2 Compile-time arrays . 37 2.11.3 Multiple occurrence data structures . 38 2.11.4 Do not use GOTO, CABxx, or COMP . 38 2.11.5 Do not use obsolete IFxx, DOUxx, DOWxx, or WHxx opcodes . 38 2.11.6 Use SELECT, WHEN, OTHER, ENDSL for multipath comparison. 38 2.12 Embedded SQL. 38 2.13 Global definitions. 39 2.14 Parameters and prototyping and procedure interfaces . 39 2.14.1 Parameters . 39 2.14.2 Return value . 39 2.14.3 Copy members . 40 2.15 The Integrated Language Environment. 42 2.15.1 ILE programs . ..