RPG/400 User's Guide
Total Page:16
File Type:pdf, Size:1020Kb
Application System/400 ÉÂÔ RPG/400 User’s Guide SC09-1816-00 Note! Before using this information and the product it supports, be sure to read the general information under “Notices” on page xi. First Edition (June 1994) This edition applies to the licensed program IBM* ILE* RPG/400* (Program 5763-RG1), Version 3 Release 0 Modification 5, and to all subsequent releases and modifications until otherwise indicated in new editions. Make sure you are using the proper edition for the level of the product. Order publications through your IBM representative or the IBM branch serving your locality. Publications are not stocked at the address given below. A form for readers' comments is provided at the back of this publication. If the form has been removed, you can address your comments to: IBM Canada Ltd. Laboratory Information Development 2G/345/1150/TOR 1150 Eglinton Avenue East North York, Ontario, Canada M3C 1H7 You can also send your comments by facsimile (attention: RCF Coordinator), or you can send your comments electronically to IBM. See "Communicating Your Comments to IBM" for a description of the methods. This page immediately precedes the Readers' Comment Form at the back of this publication. When you send information to IBM, you grant IBM a non-exclusive right to use or distribute the information in any way it believes appropriate without incurring any obligation to you. Copyright International Business Machines Corporation 1994. All rights reserved. Note to U.S. Government Users — Documentation related to restricted rights — Use, duplication or disclosure is subject to restrictions set forth in GSA ADP Schedule Contract with IBM Corp. Contents Notices . xi Programming Interface Information .......................... xi Trademarks and Service Marks ............................ xi About This Manual .................................. xiii Who Should Use This Manual ............................ xiii How to Interpret Syntax Diagrams .......................... xiv Chapter 1. An Introduction to RPG/400 and the AS/400 System ....... 1 The OS/400 System ................................. 1 The AS/400 Control Language ........................... 1 Commonly Used Control Language Commands ................ 2 System/38 Environment on the AS/400 System ................... 3 AS/400 Utilities and Languages ............................ 3 The Source Entry Utility ............................... 3 The Screen Design Aid ................................ 4 The Structured Query Language .......................... 4 Restrictions . 4 Designing Your RPG/400 Program ........................... 5 Designing the Output ............................... 5 Designing the Processing ............................. 6 Designing the Input ................................ 6 Structured Programming in the RPG/400 Programming Language ........ 6 Sequential Operation . 6 Conditional Branching . 6 If Else Structure .................................. 6 SELEC Structure . 8 Other Conditional Branching Structures ..................... 9 Repeating an Operation ............................... 9 Do Operation . 9 Do While Operation ............................... 11 Do Until Operation ................................ 13 Summary of Structured Programming Operation Codes ............ 14 Designing Applications . 15 Single Program Design ............................... 15 Modular Program Design .............................. 16 Examples of Application Design .......................... 17 Chapter 2. Entering RPG/400 Specifications .................. 21 The RPG/400 Specifications ............................. 21 The Control Specification .............................. 21 File Description Specifications ........................... 22 Extension Specifications . 22 Line Counter Specifications ............................ 22 Input Specifications . 22 Calculation Specifications . 22 Output Specifications . 23 Entering Your Program ................................ 23 Chapter 3. Compiling an RPG/400 Program .................. 25 Copyright IBM Corp. 1994 iii Create RPG400 Program (CRTRPGPGM) Command ............... 26 Using the CRTRPGPGM Command ....................... 27 Elements of the CRTRPGPGM Command Lines .............. 28 Entering Elements from the CRTRPGPGM Command Display ...... 28 Entering Only Certain Parameters ....................... 28 Entering Only the Parameter Values ..................... 29 CRTRPGPGM Command . 29 Compiling under the System/38 Environment .................... 45 Chapter 4. Error Messages, Testing, and Debugging ............. 47 Using, Displaying, and Printing Messages ..................... 47 Using Messages . 47 Systems Application Architecture Flagging Messages ............. 49 Displaying and Printing Messages ........................ 49 How to Run an RPG/400 Program .......................... 49 Save-While-Active Support . 50 Using a Test Library .................................. 51 Using Breakpoints . 54 Example of Using Breakpoints ........................... 54 Considerations for Using Breakpoints ...................... 57 Using a Trace ...................................... 58 Example of Using a Trace ............................. 59 Considerations for Using a Trace ......................... 60 Using the DEBUG Operation Codes ......................... 60 Using the RPG/400 Formatted Dump ........................ 60 Exception/Error Handling . 70 Chapter 5. General File Considerations ..................... 75 Device Independence/Device Dependence ..................... 75 Spooling . 77 Output Spool . 77 Externally Described and Program-Described Files ................ 78 Level Checking . 80 File Locking by an RPG/400 Program ........................ 81 Record Locking by an RPG/400 Program ...................... 81 Unblocking Input Records and Blocking Output Records ............. 82 Sharing an Open Data Path .............................. 83 Using the Control Language Command RCLRSC ................. 84 Specifications for Externally Described Files .................... 84 File Description Specifications ........................... 85 Renaming Record-Format Names ........................ 85 Ignoring Record Formats .............................. 86 Floating-Point Fields . 86 Overriding or Adding RPG/400 Functions to an External Description .... 87 Output Specifications . 88 Program-Described Files . 90 Printer Files . 90 Page Overflow . 91 Overflow Indicators . 92 Fetch-Overflow Logic . 94 PRTCTL (Printer Control) Option ......................... 96 Sequential File . 99 Special File . 101 iv RPG/400 User's Guide Chapter 6. Commitment Control . 107 Using Commitment Control ............................. 107 Starting and Ending Commitment Control ................... 107 Specifying Files for Commitment Control ................... 108 Commitment Control Operations ........................ 108 Commitment Control Locks ........................... 109 Commitment Control in the Program Cycle .................. 109 Example of Using Commitment Control .................... 110 Chapter 7. Using DISK Files ........................... 113 Externally Described Disk Files ........................... 113 Record Format Specifications .......................... 113 Access Path . 114 Valid Keys for a Record or File ......................... 117 Valid Search Arguments ........................... 117 Referring to a Partial Key ........................... 118 Processing Methods for Externally Described DISK Files .......... 118 Program-Described Disk Files ........................... 119 Indexed File . 119 Valid Search Arguments ........................... 119 Sequential Files . 122 Record Address File ............................... 122 Limits Records . 122 Relative Record Numbers ........................... 123 Externally Described File as Program Described ............... 123 Methods for Processing Disk Files ......................... 123 Relative-Record-Number Processing . 123 Consecutive Processing . 124 Sequential-by-Key Processing . 124 Sequential-within-Limits Processing . 132 Keyed Processing Examples .......................... 132 Valid File Operations ................................. 140 Chapter 8. Using WORKSTN Files ....................... 143 Intersystem Communications Function ...................... 143 Externally Described WORKSTN Files ...................... 143 Processing an Externally Described WORKSTN File ............. 144 Function Key Indicators on Display Device Files ............... 146 Command Keys on Display Device Files .................... 147 Processing WORKSTN Files ............................ 147 EXFMT Operation . 147 READ Operation . 147 WRITE Operation . 147 WORKSTN file . 148 Subfiles . 150 Use of Subfiles ................................. 152 Program-Described WORKSTN File ........................ 154 Program-Described WORKSTN File with a Format Name .......... 154 Output Specifications . 154 Input Specifications . 155 Calculation Specifications . 155 Additional Considerations . 156 Program-Described WORKSTN File without a Format Name ........ 156 Input File . 156 Contents v Output File . 156 Combined File . 156 Multiple-Device Files . 157 WORKSTN File Examples ............................. 158 Sample Program 1–Inquiry ............................ 159 Sample Program 2–Data Entry with Master Update ............. 166 Sample Program 3–Maintenance ........................ 174 Sample Program 4–WORKSTN Subfile Processing ............. 187 Sample Program 5–Inquiry by Zip Code and Search on Name ....... 196 Sample Program 6–Program-Described