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—which is both a learning tool and handy reference guide—provides concise and thorough information to help you learn this powerful way of coding RPG IV.
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. In it, you will 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 modern style of coding has the potential to 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. There is even a chapter on prototyping and APIs.
In the second edition, this programming classic has been updated to V7.1 of the IBM i operating system on IBM Power. A new chapter shows the new way to code embedded SQL in free format. Throughout the book, updates have been made and paragraphs added that describe new techniques available for source program entry (LPEX editor in IBM RDp) and other items that have occurred in the years since the first edition.
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 tools you need to upgrade your programming skills and bring your RPG programs into the 21st century.
Upon completion of Free-Format RPG IV, you will be able to:
Transition easily from fixed format to the free-format style of coding RPG IV
Know how to handle embedded SQL coding in free format
Possess a handy, easy-to-read reference guide for free-format coding
Understand that the free-format style is the future direction of the RPG language
Use this book as a learning tool to upgrade your programming skills and career opportunities
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.
CONTENTS Preface to the Second Edition A Note About Source Entry
Chapter 1: Pre–Free-Format RPG IV RPG IV Extended Factor 2 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: Introducing Free-Format RPG IV The Free-Format Code Block Coding Free-Format Operations 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 4: 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 5: 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 6: Embedded SQL Operations Using Free Format Database and Embedded SQL Fixed-Format Method Free-Format Method
Chapter 7: 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 8: 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 9: 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 10: 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 11: Sample Programs An Investment and Loan Utility Program A Customer Inquiry Program A Customer Data Entry Program A Sales Report Program
Appendix A: Free-Format Operations Appendix B: Example Screens, DDS, and Programs Appendix C: Free-Format Alternatives for Fixed-Format Operations Index