Traditional fixed-format RPG 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--both learning tool and handy reference guide--provides the information you need to learn this powerful way of coding.
Although free-format information is available in IBM manuals, it is mixed in with everything else, 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. You'll find everything you need to know to write RPG IV in the free-format style. Jim Martin not only teaches rules and syntax but also explains how this modern style of coding can improve overall programmer productivity--from 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--plus prototyping and APIs.
Free-format RPG now encompasses nearly all functional aspects of the language, and this Third Edition of Free-Format RPG IV brings you up-to-date on all the latest features. You'll find a chapter devoted to the new free-format H (Control), F (File definition), D (Definition), and P (Subprocedure) specifications. And throughout the book, the programming examples have been updated so you can see the new specifications in action.
Free format is the future of the RPG language, and knowing this method is quickly becoming a "must" for all RPG programmers. This book gives you the guidance you need to upgrade your programming skills and bring your RPG programs into the 21st century.
Upon completion of this book, you will be able to:
Understand how to code free-format RPG IV
Learn the new free-format H, F, D, and P specs
Master critical style issues
Learn free-format best practices
Jim Martin — Jim Martin holds a BS degree in mathematics and an MS in computer science. For 26 years, he was employed by IBM, where he wrote RPG applications for customers and worked in the programming laboratory as a programmer on portions of CPF and the OS/400 operating system. After leaving IBM, Jim took post-graduate work in computer science and performed RPG training. He is an IBM-certified RPG IV developer and author of the bestselling first and second editions of Free-Format RPG IV, which, since the book's initial publication in 2005, have taught thousands of RPG IV programmers how to be successful with the free-format coding style.
Preface to the Third Edition A Note About Source Entry
Chapter 1: Pre–Free-Format RPG IV RPG IV Extended Factor Built-in Functions Subprocedures Other Changes Some “Baggage” That Came Along The Future
Chapter 2: The Case for Free-Format RPG Easier to Read and Maintain Good Field Naming Indenting Use of Comments No Goto Operations Conclusions A “Modern” Programming Style Free-Format RPG IV and C Free-Format RPG IV and Java Conclusions Being “Current” The Programmer's Perspective Management's Perspective Conclusions Check It Out
Chapter 3: Free-Format H, F, D, and P Specifications The H (Control) Specification The F (File) Specifications The D (Definition) Specifications The P (Procedure) Specification Conclusions
Chapter 4: Introducing Free-Format RPG IV Coding Free-Format Calculations Naming Variables Programming Style A Note About Case Free-Format Operation Codes Evaluate If Controlled Looping Mathematics Character Strings Programming Style Issues Mixing Formats Keyed Access Named Indicators Naming File Indicators Summing Up
Chapter 5: Input/Output Using Free Format Database Input %Eof %Found %Error %Equal Data Area Input Database Output Write Update Delete Except Workstation I/O Write/Read Write Read ICF I/O Dsply Printer Output Overflow Indicator Write Except
Chapter 6: Program Flow Using Free Format The If Group If Else Elseif Endif The Do Operations Do While Do Until Dow and Dou Differences For Loop Interrupt Leave Iter The Select Group Select Operations Absent in Free Format
Chapter 7: Embedded SQL Operations Using Free Format Database and Embedded SQL Fixed-Format Method Free-Format Method
Chapter 8: Data-Manipulation Operations Using Free Format Assignment Statements Eval Operation: Numeric Eval Operation: Character Evaluate Right (EvalR) Operation Eval Operation: IS,OC Evaluate vs Move Built-in Functions Converting Decimal to Character Converting Character to Packed Decimal Substringing Replace Scan and Replace Concatenation and Trim Converting Character to Integer Extracting Size, Length, and Decimal Positions Number of Elements Looking for Something? String Translation Combining Built-in Functions Date and Time Operations Converting Numbers to Date and Time Converting Date and Time to Character or Decimal Date and Time Arithmetic
Chapter 9: Math Operations in Free Format Expressions in Assignment Statements and Elsewhere Four-Function Math Short-Form Math Exponentiation Precedence Mathematical Expressions Elsewhere Eval Differences in Fixed and Free Format Naming Variables Semicolon Free-Format Math in RPG IV Numeric Data Types Changing Data Type
Chapter 10: Call and Return in Free Format Call Prototyped (CallP) Operation Dynamic Call Bound Call Parameter-Passing Options Value Const Options(*NoPass) Options(*Omit) Options(*Varsize) Options(*String) Options(*RightAdj) Options(*Trim) The Return Operation Subprocedures Accessing APIs API Examples
Chapter 11: Solutions for Problem Situations Solution for the Fixed-Format MoveA Operation History The Free-Format Solution The %Subarr Built-in Function Solution for the Fixed-Format Move Operation Breaking It Down When Both Fields Are Character Data Type Differences Solution for the Fixed-Format MoveL Operation Breaking It Down When Both Fields Are Character Solution for the Case Operation Solution for the Do Operation The Do Syntax The Free-Format Solution Error-Handling Techniques The Monitor Solution ILE Exception Handler
Chapter 12: Sample Programs An Investment and Loan Utility Program A Customer Inquiry Program A Customer Data Entry Program A Sales Report Program