Free-Format RPG IV: How to Bring Your RPG Programs Into the 21st Century
By Jim Martin
4/5
()
About this ebook
Read more from Jim Martin
The Just Church: Becoming a Risk-Taking, Justice-Seeking, Disciple-Making Congregation Rating: 0 out of 5 stars0 ratingsFunctions in Free-Format RPG IV Rating: 0 out of 5 stars0 ratingsHow to Master the Art of Selling Health Club Memberships Rating: 0 out of 5 stars0 ratingsOut of Chaos, Shapes Rating: 0 out of 5 stars0 ratingsThe Old Minbro Rating: 0 out of 5 stars0 ratings
Related to Free-Format RPG IV
Related ebooks
Programming in RPG IV Rating: 5 out of 5 stars5/5Subfiles in Free-Format RPG: Rules, Examples, Techniques, and Other Cool Stuff Rating: 5 out of 5 stars5/5The iSeries and AS/400 Programmer's Guide to Cool Things Rating: 3 out of 5 stars3/5The Programmer's Guide to iSeries Navigator Rating: 0 out of 5 stars0 ratingsIBM i5/iSeries Primer: Concepts and Techniques for Programmers, Administrators, and System Operators Rating: 0 out of 5 stars0 ratingsIBM System i APIs at Work Rating: 5 out of 5 stars5/5Mastering IBM i: The Complete Resource for Today's IBM i System Rating: 3 out of 5 stars3/5An Introduction to IBM Rational Application Developer: A Guided Tour Rating: 5 out of 5 stars5/5COBOL Basic Training Using VSAM, IMS and DB2 Rating: 5 out of 5 stars5/5Cobol Rating: 0 out of 5 stars0 ratingsComplete CL Rating: 0 out of 5 stars0 ratingsThe IBM i Programmer's Guide to PHP Rating: 0 out of 5 stars0 ratingsCOBOL Language Fundamentals Quick Start Rating: 0 out of 5 stars0 ratingsCOBOL Language Fundamentals with VSAM Quick Start Rating: 0 out of 5 stars0 ratingsCOBOL Language Fundamentals with DB2 Quick Start Rating: 0 out of 5 stars0 ratingsIMS-DB Basic Training For Application Developers Rating: 0 out of 5 stars0 ratingsJava for RPG Programmers: 3rd edition Rating: 4 out of 5 stars4/5PLI Basic Training Using VSAM, IMS and DB2 Rating: 1 out of 5 stars1/5SQL for eServer i5 and iSeries Rating: 5 out of 5 stars5/5RPG TnT: 101 Dynamite Tips 'n Techniques with RPG IV Rating: 5 out of 5 stars5/521st Century RPG: /Free, ILE, and MVC Rating: 5 out of 5 stars5/5IBM RPG A Complete Guide Rating: 0 out of 5 stars0 ratingsUnderstanding AS/400 System Operations Rating: 5 out of 5 stars5/5A Guide to Db2 Performance for Application Developers: Code for Performance from the Beginning Rating: 0 out of 5 stars0 ratingsSQL Built-In Functions and Stored Procedures: The i5/iSeries Programmer's Guide Rating: 0 out of 5 stars0 ratingsIBM i Security Administration and Compliance Rating: 0 out of 5 stars0 ratingsDB2 11 for z/OS: Basic Training for Application Developers Rating: 5 out of 5 stars5/5The Remote System Explorer: Modern Developer Tools for the System i Rating: 0 out of 5 stars0 ratingsDB2 Interview Questions, Answers, and Explanations: DB2 Database Certification Review Rating: 0 out of 5 stars0 ratingsDatabase Design and SQL for DB2 Rating: 5 out of 5 stars5/5
Programming For You
Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Java for Beginners: A Crash Course to Learn Java Programming in 1 Week Rating: 5 out of 5 stars5/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Python Machine Learning By Example Rating: 4 out of 5 stars4/5101 Amazing Nintendo NES Facts: Includes facts about the Famicom Rating: 4 out of 5 stars4/5Pokemon Go: Guide + 20 Tips and Tricks You Must Read Hints, Tricks, Tips, Secrets, Android, iOS Rating: 5 out of 5 stars5/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Modern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 Standards Rating: 0 out of 5 stars0 ratingsPython Projects for Beginners: A Ten-Week Bootcamp Approach to Python Programming Rating: 0 out of 5 stars0 ratings
Reviews for Free-Format RPG IV
1 rating1 review
- Rating: 4 out of 5 stars4/5It's a good and quick read. Brings you up to speed on free-format RPG programming.
Book preview
Free-Format RPG IV - Jim Martin
Free-Format RPG IV
Jim Martin
First Printing — April 2005
Second Printing — September 2005
Third Printing — August 2006
Fourth Printing — May 2009
© 2005–2009 Jim Martin. All rights reserved.
Every attempt has been made to provide correct information. However, the publisher and the author do not guarantee the accuracy of the book and do not assume responsibility for information included in or omitted from it.
The following terms are trademarks or registered trademarks of International Business Machines Corporation in the United States, other countries, or both: AS/400, OS/400, iSeries, i5, i5/OS, and IBM. All other products names are trademarked or copyrighted by their respective manufacturers.
Printed in Canada. All rights reserved. This publication is protected by copyright, and permission mut be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise.
MC Press offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include custom covers and content particular to your business, training goals, marketing focus, and branding interest.
For information regarding permissions or special orders, please contact:
MC Press
Corporate Offices
125 N. Woodland Trail
Lewisville, TX 75077 USA
For information regarding sales and/or customer service, please contact:
MC Press
P.O. Box 4300
Big Sandy, TX 75755-4300 USA
ISBN: 978-158347-055-8
To my lovely wife Jody, for her encouragement and support in all that I pursue.
Acknowledgments
I wish to express my appreciation to several people who have encouraged me over many years. Thanks to Dave Michelson, my mentor and friend; to Phil Bolian, who inspired me to pursue excellence; to professor Herb Morris of Bradley University, who taught me well and fueled the fire of interest in computer science; to Kathy Thorpe, who gave me opportunities to learn and grow; to Bill Merchantz, who coached me as a new manager; and to Victoria, Merrikay, and Katie at MC Press, who have taken my vision and turned it into a reality.
My thanks also go to my friend Joe Pluta, who kindly provided technical assistance in the programming-language comparison section of this book.
Table of Contents
Title Page
Copyright Page
Dedication
Acknowledgments
1 - Pre–Free-Format RPG IV
2 - Introducing Free-Format RPG IV
3 - Input/Output Using Free Format
4 - Program Flow Using Free Format
5 - Data-Manipulation Operations Using Free Format
6 - Math Operations in Free Format
7 - Call and Return in Free Format
8 - Solutions for Problem Situations
9 - The Case for Free-Format RPG
10 - Sample Programs
A - Free-Format Operations
B - Additional Elements Used by the Sample Programs
C - Free-Format Alternatives for Fixed-Format Operations
1
Pre–Free-Format RPG IV
The RPG programming language has certainly come a long way since its introduction as a simple report program generator in the 1960s. From the earliest versions of RPG to the latest release of free-format RPG IV on IBM’s eServer iSeries (now i5) platform, the changes have been dramatic.
The centerpiece of today’s RPG is its support for a free-format style of calculation coding. Free format puts RPG on the map of modern programming languages and gives programmers important new functionality for constructing programs that are easier to create, understand, and maintain. If you’re writing RPG programs today, you owe it to yourself to make the most of this great new function.
In this book, you’ll learn the ins and outs of free-format RPG, from I/O and program flow to data manipulation, math operations, and call and return. But before we dive into the delights of free-format RPG, let’s take a brief look at its precursor: fixed-format RPG IV.
RPG IV
Even before free format, RPG IV was a powerful, functionally rich programming language. RPG IV — or ILE RPG, as it’s officially known — debuted in late 1994 with Version 3 Release 1 (V3R1) of the OS/400 operating system. IBM had introduced the Integrated Language Environment (ILE) in a prior release, but everyone eagerly awaited RPG’s entrée into ILE. Three major additions to RPG in V3R1 brought the language a significant level of sophistication that was previously absent: the extended Factor 2, built-in functions, and subprocedures.
Extended Factor 2
The introduction of the extended Factor 2 format, along with operations to exploit it, represented a huge departure from RPG’s past. With this enhancement to calculation specifications, RPG programmers could begin to use operations such as Eval (Evaluate expression) and If (If) with long expressions.
The ability to use math symbols (+,–, *, /) within expressions was a major step in modernizing the language. Other symbols, used in comparison expressions, included equal (=), less than (<), greater than (>), less than or equal (<=), greater than or equal (>=), and not equal (<>). The exponentiation symbol (**) became the newest math operator, and support for parentheses let programmers indicate higher precedence in math or comparison expressions. Other programming languages had used these symbols for a while, and IBM chose to bring them into its new version of RPG.
One of the symbols, the plus sign (+), found an additional use in RPG IV: concatenation. Using this new operator, RPG programmers could put character data together into strings much more easily than with previous methods.
Built-in Functions
iSeries programmers were already familiar with built-in functions through their use of such functions in CL, OS/400’s control language. The %Sst (substring) and %Bin (binary) functions, for example, are commonly used CL built-in functions.
The whole idea of an RPG IV built-in function was based on the C language’s concept of a function. A built-in function performs one task, with or without parameters, and usually returns data of a predetermined data type to the point in the program where the function was specified. For example, RPG IV’s %Eof built-in function checks for end-of-file after a Read operation, eliminating the need to code a resulting indicator on the Read. The %Found built-in function lets you check for a record-found condition after a Chain operation without using a resulting indicator.
The number of built-in functions available in RPG has grown from the dozen or so provided in RPG IV’s initial release to 76 as of V5R3. Many of these built-ins
duplicate the function of older operation codes, such as Scan (built-in function %Scan) and Subst (built-in function %Subst). In some cases, the built-in function provides more capabilities than the operation code it replaces. For example, the %Subst built-in function can substring a target as well as a source string, whereas the Subst (Substring) operation code can substring only a source string.
Subprocedures
As if these new capabilities weren’t enough, IBM added another powerful feature to RPG IV. Support for subprocedures gives RPG IV programmers the option to break complex programs into smaller parts and to create homegrown
built-in functions if desired. For the first time in RPG, IBM introduced the concept of a local variable for use in subprocedures. Also for the first time, a routine — in this case, a subprocedure — could use recursion.
Other Changes
In RPG IV, IBM also eliminated many of the old constraints of RPG/400 (RPG IV’s predecessor). Eight-character file and record names were lengthened to 10. Field name lengths were increased, too — at first to 10 and then to 4,096! The maximum size of character fields grew from 256 bytes to 32,767. Packed-numeric field size was raised to 30 and then 31 digits; it now stands at 63.
Even fans of binary and hexadecimal programming got something new in RPG IV. Previously, you could convert two-byte binary numbers to four-digit decimal numbers and convert four-byte binary numbers to nine digits. The new RPG IV language provided an integer data type, both signed and unsigned, up to 20 digits. To handle ultra-small and ultra-large numbers, the floating point data type made its debut, in both standard and double precision.
Other data types added to the language include the pointer data type, which contains the address of data or a procedure; the object data type, used to handle references to a Java object; and the date, time, and timestamp data types.
Adding these new data types and enlarging the older ones must have come from some greater motivating factor. Why did IBM provide all these things? In my opinion, the reasons lay in maintaining the iSeries as a modern and viable solution for the midrange server marketplace. Older RPG can easily be called a dinosaur
in this modern age. The gap in programming capabilities between older RPG and modern languages such as C, C++, Java, and others was huge. With today’s RPG IV, there is no gap. RPG IV has come from behind
to be a major player in the modern world of application development.
Some Baggage
That Came Along
Like any responsible vendor, IBM doesn’t like to offend any of its customers. If you wrote an RPG program in 1969 that used the RPG cycle and 99 indicators, IBM won’t tell you today that your approach is obsolete. Instead, IBM continues to provide a compatibility path from the here and now
back to almost any previous time in RPG’s history. The machines may change every six to eight years, but programs and the inherent investment made in developing them are preserved. One byproduct of this commitment to long-time customers and their legacy code is that RPG IV, in its current form, carries the weight of 40 years of baggage.
The RPG cycle, and its emulation of the gray accounting machines of the 1960s, lives on.
When IBM introduced RPG IV, many of us hoped we might see a break with the past. Companies that cared little about change could stay with RPG/400, and those interested in new ideas could embrace the new incarnation of RPG. Maybe, I thought, the new RPG would at least drop the cycle. Perhaps we’d only be able to use newer instructions such as Eval,