Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Free-Format RPG IV: How to Bring Your RPG Programs Into the 21st Century
Free-Format RPG IV: How to Bring Your RPG Programs Into the 21st Century
Free-Format RPG IV: How to Bring Your RPG Programs Into the 21st Century
Ebook252 pages3 hours

Free-Format RPG IV: How to Bring Your RPG Programs Into the 21st Century

Rating: 4 out of 5 stars

4/5

()

Read preview

About this ebook

What could be more important than upgrading your RPG skills? Traditional fixed-format style RPG IV programmers everywhere are embracing the increased productivity, better readability, and easier program maintenance that comes with the free-format style of programming in RPG IV. This book, a "how-to" guide and the first of its kind, will provide you with concise and thorough information on this powerful new way of coding RPG IV. Though free-format information is available in IBM manuals, it is not separated from everything else, thereby requiring hours of tedious research to track down the information you need. With this book, your search is over. Free-Format RPG IV is the "one-stop" resource that will save you time and frustration. In it, you'll find everything you need to know to write RPG IV in the free-format style. Author Jim Martin not only teaches rules and syntax, but also explains how this new style of coding has the potential to improve overall programmer productivityfrom initial development through maintenance. He methodically covers the "how to" involved in free-format RPG IV, including many style issues, such as named indicators and built-in functions. He also addresses input and output, program flow, data manipulation, and math operations. There is even a chapter on prototyping and APIs. Free-Format RPG IV is the definitive guide on the topic and just what you need to get started with this exciting, powerful style of programming. With Free-Format RPG IV you will: - Learn not only the "how-to," but also the "why" of free-format RPG IV - Acquire essential, free-format style tips to help you write good, maintainable code - Find complete-program solutions for specific problems, including associated display and printer files - Discover how upgrading your RPG skills to free-format can take your programming career to the next level.
LanguageEnglish
PublisherMC Press
Release dateMar 1, 2012
ISBN9781583476246
Free-Format RPG IV: How to Bring Your RPG Programs Into the 21st Century

Read more from Jim Martin

Related to Free-Format RPG IV

Related ebooks

Programming For You

View More

Related articles

Reviews for Free-Format RPG IV

Rating: 4 out of 5 stars
4/5

1 rating1 review

What did you think?

Tap to rate

Review must be at least 10 words

  • Rating: 4 out of 5 stars
    4/5
    It'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,

Enjoying the preview?
Page 1 of 1