O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Who Knew You Could Do That with RPG IV? Modern RPG for the Modern Programmer

Book Description

Application development is a key part of IBM® i businesses. The IBM i operating system is a modern, robust platform to create and develop applications. The RPG language has been around for a long time, but is still being transformed into a modern business language.

This IBM Redbooks® publication is focused on helping the IBM i development community understand the modern RPG language. The world of application development has been rapidly changing over the past years. The good news is that IBM i has been changing right along with it, and has made significant changes to the RPG language. This book is intended to help developers understand what modern RPG looks like and how to move from older versions of RPG to a newer, modern version. Additionally, it covers the basics of Integrated Language Environment® (ILE), interfacing with many other languages, and the best tools for doing development on IBM i.

Using modern tools, methodologies, and languages are key to continuing to stay relevant in today's world. Being able to find the right talent for your company is key to your continued success. Using the guidelines and principles in this book can help set you up to find that talent today and into the future.

This publication is the result of work that was done by IBM, industry experts, business partners, and some of the original authors of the first edition of this book. This information is important not only for developers, but also business decision makers (CIO for example) to understand that the IBM i is not an 'old' system. IBM i has modern languages and tools. It is a matter of what you choose to do with the IBM i that defines its age.

Table of Contents

  1. Front cover
  2. Notices
    1. Trademarks
  3. Preface
    1. Authors
    2. Now you can become a published author, too!
    3. Comments welcome
    4. Stay connected to IBM Redbooks
  4. Chapter 1. Introduction to RPG IV
    1. 1.1 Why update this book on RPG IV now?
    2. 1.2 Evolution of the RPG IV language
      1. 1.2.1 Examples in this book are based on IBM i 7.2
    3. 1.3 The future for RPG IV
      1. 1.3.1 A future for RPG programmers
    4. 1.4 A roadmap
      1. 1.4.1 Step 1: RPG IV and RDi
      2. 1.4.2 Step 2: Modularization by using ILE
      3. 1.4.3 Step 3: Using database features
      4. 1.4.4 Step 4: Modernizing the user interface
    5. 1.5 RPG IV sources on the web
  5. Chapter 2. Programming RPG IV with style
    1. 2.1 Just another programming language
    2. 2.2 RPG is free-form
      1. 2.2.1 The modern free-form RPG
      2. 2.2.2 The basics of /Free coding
      3. 2.2.3 Unsupported op-codes
      4. 2.2.4 Op-codes that tend to produce unclear and error-prone source code
      5. 2.2.5 Liberating data and file definitions
      6. 2.2.6 Data declarations
      7. 2.2.7 More on data definitions
      8. 2.2.8 Defining prototypes and subprocedures
      9. 2.2.9 Miscellaneous topics
      10. 2.2.10 Moving to free-form
    3. 2.3 Modern RPG programs and subprocedures
    4. 2.4 Naming
      1. 2.4.1 The names
      2. 2.4.2 Case
      3. 2.4.3 Special characters
      4. 2.4.4 Underscore
      5. 2.4.5 Named constants
      6. 2.4.6 Naming conventions
    5. 2.5 Comments
      1. 2.5.1 Summary comments
      2. 2.5.2 Detailed commenting
      3. 2.5.3 Other commenting
      4. 2.5.4 Positions 1 - 5
    6. 2.6 Structuring code
      1. 2.6.1 Declarative code
      2. 2.6.2 Executable code
      3. 2.6.3 Multipath comparison
      4. 2.6.4 Embedded SQL
    7. 2.7 Using templates and qualified data structures
    8. 2.8 Qualifying wherever possible
    9. 2.9 Strings
    10. 2.10 Subroutines
    11. 2.11 Older functions
      1. 2.11.1 RPG built-in indicators
      2. 2.11.2 Compile-time arrays
      3. 2.11.3 Multiple occurrence data structures
      4. 2.11.4 Do not use GOTO, CABxx, or COMP
      5. 2.11.5 Do not use obsolete IFxx, DOUxx, DOWxx, or WHxx opcodes
      6. 2.11.6 Use SELECT, WHEN, OTHER, ENDSL for multipath comparison
    12. 2.12 Embedded SQL
    13. 2.13 Global definitions
    14. 2.14 Parameters and prototyping and procedure interfaces
      1. 2.14.1 Parameters
      2. 2.14.2 Return value
      3. 2.14.3 Copy members
    15. 2.15 The Integrated Language Environment
      1. 2.15.1 ILE programs
      2. 2.15.2 Service programs
      3. 2.15.3 Binding directories
      4. 2.15.4 Activation groups
  6. Chapter 3. Subprocedures
    1. 3.1 Subprocedure terminology
      1. 3.1.1 ILE modules
      2. 3.1.2 Main procedure
      3. 3.1.3 Built-in functions
      4. 3.1.4 Subroutines
    2. 3.2 Advantages of using subprocedures
    3. 3.3 The anatomy of a subprocedure
      1. 3.3.1 Subprocedure definition
      2. 3.3.2 Procedure-interface definitions
      3. 3.3.3 Order of coding the source elements
      4. 3.3.4 Calling your subprocedures
    4. 3.4 Moving from subroutines to subprocedures
      1. 3.4.1 Why use subprocedures
      2. 3.4.2 Subroutine example DATESUBR
      3. 3.4.3 Transforming a subroutine to a subprocedure
      4. 3.4.4 DATEMAIN1 subprocedure example
    5. 3.5 Using subprocedures efficiently
      1. 3.5.1 Using /COPY members for prototypes
      2. 3.5.2 Prototype for the main procedure
      3. 3.5.3 Subprocedures using subprocedures
      4. 3.5.4 Using an ILE service program
    6. 3.6 More on subprocedures
      1. 3.6.1 The power of prototyping
      2. 3.6.2 Parameter passing styles
      3. 3.6.3 Using procedure pointer calls
  7. Chapter 4. An ILE guide for the RPG programmer
    1. 4.1 Introduction to ILE
      1. 4.1.1 Modules
      2. 4.1.2 Service programs
      3. 4.1.3 Binding: Creating programs and service programs
      4. 4.1.4 Binding directories
      5. 4.1.5 Service program exports
      6. 4.1.6 Binder language source
      7. 4.1.7 Activation groups
      8. 4.1.8 CL commands used with ILE and RPG
    2. 4.2 ILE tips for the RPG programmer
      1. 4.2.1 Creating programs from modules (binding by copy)
      2. 4.2.2 Binding service programs to programs
      3. 4.2.3 Service programs, binder language, and signatures
      4. 4.2.4 Using binding directories
      5. 4.2.5 Activation groups
      6. 4.2.6 Call stack and error handling
    3. 4.3 Additional CL commands and useful ILE APIs
      1. 4.3.1 Additional CL commands
      2. 4.3.2 Some useful APIs to get information about ILE objects
    4. 4.4 More information about ILE and shared open data paths
  8. Chapter 5. Application programming interfaces
    1. 5.1 Finding APIs
    2. 5.2 C functions
      1. 5.2.1 Prototype mapping example
      2. 5.2.2 A more complex prototype mapping example
    3. 5.3 POSIX interfaces
      1. 5.3.1 Accessing the IFS
    4. 5.4 IBM i system interfaces
      1. 5.4.1 Standard techniques
      2. 5.4.2 List objects (QUSLOBJ) API
    5. 5.5 Creating a reusable API
      1. 5.5.1 Making a web service
    6. 5.6 Things to remember
  9. Chapter 6. Database access with RPG IV
    1. 6.1 Externalizing input and output
      1. 6.1.1 What is meant by externalizing
      2. 6.1.2 Putting theory into practice: An example of externalizing I/O
      3. 6.1.3 Externalizing example: Overview
      4. 6.1.4 Externalizing example: Separating database logic from display logic
      5. 6.1.5 Externalizing example: Implementing changes
      6. 6.1.6 Externalizing example: Other possibilities
      7. 6.1.7 Summary
    2. 6.2 Embedded SQL
      1. 6.2.1 Rules for embedding SQL statements
      2. 6.2.2 SQL preprocessor
      3. 6.2.3 Error and exception handling
      4. 6.2.4 Using a cursor
      5. 6.2.5 An embedded SQL program example
      6. 6.2.6 Source code for the SQLEMBED program
    3. 6.3 Stored procedures
      1. 6.3.1 Creating an external procedure
      2. 6.3.2 Creating an SQL procedure
      3. 6.3.3 Starting a stored procedure and returning the completion status
      4. 6.3.4 A stored procedure example
    4. 6.4 DB2 call level interface
      1. 6.4.1 Differences between DB2 CLI and embedded SQL
      2. 6.4.2 Writing a DB2 CLI application
      3. 6.4.3 Initialization and termination
      4. 6.4.4 Transaction processing
      5. 6.4.5 Diagnostic tests
      6. 6.4.6 Data types and data conversion
      7. 6.4.7 Functions
      8. 6.4.8 Introduction to a CLI example
    5. 6.5 Trigger programs
      1. 6.5.1 Adding a trigger program to a file
      2. 6.5.2 Creating a trigger program
    6. 6.6 Commitment control
      1. 6.6.1 File journaling
      2. 6.6.2 Using commitment control with RPG native file operations
      3. 6.6.3 Using commitment control with embedded SQL
      4. 6.6.4 Using commitment control with the CLI interface
    7. 6.7 A note about globalization
    8. 6.8 More information about database access with RPG IV
  10. Chapter 7. Exception and error handling
    1. 7.1 Introduction to exception and error handling
    2. 7.2 What is an exception/error
    3. 7.3 Trapping at the program level
      1. 7.3.1 Program exception/errors
      2. 7.3.2 The fatal program
      3. 7.3.3 File exception/errors
      4. 7.3.4 Can it get any easier
    4. 7.4 Trapping at the operation level
      1. 7.4.1 Error extender
      2. 7.4.2 Status codes
      3. 7.4.3 Monitor groups
      4. 7.4.4 Information data structures
      5. 7.4.5 ILE condition handlers
    5. 7.5 Subprocedures and exception/errors
      1. 7.5.1 Percolation
      2. 7.5.2 Trapping percolated errors
      3. 7.5.3 Identifying a percolated message
    6. 7.6 ILE CEE APIs
      1. 7.6.1 Condition management APIs
      2. 7.6.2 Activation group and control flow APIs
      3. 7.6.3 Further information
    7. 7.7 Priority of handlers
    8. 7.8 The embedded SQL problem
    9. 7.9 Using percolation: Try, throw, and catch
      1. 7.9.1 A traditional approach
      2. 7.9.2 Throw
      3. 7.9.3 Catch
      4. 7.9.4 Using throw and catch
      5. 7.9.5 The problem with throw and catch
    10. 7.10 Conclusion
  11. Chapter 8. Interfacing
    1. 8.1 Interfacing with Java
      1. 8.1.1 Java calling RPG IV
      2. 8.1.2 RPG IV calling Java
      3. 8.1.3 Things to remember
    2. 8.2 Python
      1. 8.2.1 Calling a stored procedure
      2. 8.2.2 Toolkit for IBM i
      3. 8.2.3 Test script
      4. 8.2.4 Output
    3. 8.3 PHP
  12. Chapter 9. IBM Rational Developer for IBM i
    1. 9.1 Why you should use Rational Developer for IBM i
      1. 9.1.1 Integrated compile-time error feedback
      2. 9.1.2 Outlining your program
      3. 9.1.3 Editing multiple members at the same time
      4. 9.1.4 Modern editor capabilities
      5. 9.1.5 Moving from SEU/PDM to RDi
    2. 9.2 Built on Eclipse
      1. 9.2.1 iSphere tools
    3. 9.3 What is new in Rational Developer for IBM i
      1. 9.3.1 Code coverage monitor
      2. 9.3.2 Integrated emulator
      3. 9.3.3 IBM i Access Client Solutions and Run SQL scripts
      4. 9.3.4 RPG formatter
      5. 9.3.5 More flexible outline view
      6. 9.3.6 Native Mac OS X support
      7. 9.3.7 Commenting and uncommenting in RPG, CL, and DDS
      8. 9.3.8 Hyperlink navigation within source member
      9. 9.3.9 Importing and exporting RDi configurations and push-to-client support
      10. 9.3.10 Smaller usability enhancements
    4. 9.4 Using the RDi debugger
      1. 9.4.1 Starting a debug session using service entry point
      2. 9.4.2 Starting a debug session by using a debug configuration
      3. 9.4.3 Debug server and preferences
      4. 9.4.4 RDi debug activities
  13. Chapter 10. Modern RPG comparison as viewed by a young developer
    1. 10.1 Fixed format versus free-format
    2. 10.2 File-Specs
    3. 10.3 Tables
    4. 10.4 Parameters
    5. 10.5 Key lists
    6. 10.6 Array and error lookups
    7. 10.7 Calling programs from a program
    8. 10.8 Read commands
    9. 10.9 Evaluates, checks, and scans
    10. 10.10 Select statements
    11. 10.11 Substring and concatenate
    12. 10.12 Go-To commands
    13. 10.13 Embedded SQL in free-format 101
    14. 10.14 Built-in functions that you need to know
  14. Appendix A. Additional material
    1. Locating the web material
    2. Using the web material
  15. Related publications
    1. IBM Redbooks
    2. Other publications
    3. Online resources
    4. Help from IBM
  16. Back cover