Rpg Programmers Guide

  • View
    24

  • Download
    3

Embed Size (px)

DESCRIPTION

Manual bsico de programacin en RPG de plataforma AS400 de IBM.

Transcript

  • Note!

    Before using this information and the product it supports, be sure to read the general information underNotices 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 Modifica-tion 5, and to all subsequent releases and modifications until otherwise indicated in new editions. Make sure you areusing the proper edition for the level of the product.

    Order publications through your IBM representative or the IBM branch serving your locality. Publications are notstocked 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 canaddress your comments to:

    IBM Canada Ltd. Laboratory Information Development 2G/345/1150/TOR1150 Eglinton Avenue EastNorth York, Ontario, Canada M3C 1H7

    You can also send your comments by facsimile (attention: RCF Coordinator), or you can send your comments elec-tronically to IBM. See "Comunicating Your Comments to IBM" for a description of the methods. This page imme-diately 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 wayit 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 issubject to restrictions set forth in GSA ADP Schedule Contract with IBM Corp.IBM is a registered trademark of International Business Machines Corporation, Armonk, N.Y.

  • ContentsNotices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiProgramming Interface Information . . . . . . . . . . . . . . . . . . . . . . . . . . xiTrademarks and Service Marks . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi

    About This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiiiWho Should Use This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiiiHow to Interpret Syntax Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . xiv

    Chapter 1. An Introduction to the RPG/400 . . . . . . . . . . . . . . . . . . . . 1The OS/400 System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1The AS/400 Control Language . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    Commonly Used Control Language Commands . . . . . . . . . . . . . . . . 2System/38 Environment on the AS/400 System . . . . . . . . . . . . . . . . . . . 3AS/400 Utilities and Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    The Source Entry Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3The Screen Design Aid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4The Structured Query Language . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Designing Your RPG/400 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    Designing the Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Designing the Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Designing the Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    Structured Programming in the RPG/400 Programming Language . . . . . . . . 6Sequential Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Conditional Branching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    If Else Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6SELEC Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Other Conditional Branching Structures . . . . . . . . . . . . . . . . . . . . . 9

    Repeating an Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9Do Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9Do While Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Do Until Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    Summary of Structured Programming Operation Codes . . . . . . . . . . . . 14Designing Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

    Single Program Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Modular Program Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16Examples of Application Design . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    Chapter 2. Entering RPG/400 Specifications . . . . . . . . . . . . . . . . . . 21The RPG/400 Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

    The Control Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21File Description Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Extension Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Line Counter Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Input Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Calculation Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Output Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

    Entering Your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

    Chapter 3. Compiling an RPG/400 Program . . . . . . . . . . . . . . . . . . 25

    Copyright IBM Corp. 1994 iii

  • Create RPG400 Program (CRTRPGPGM) Command . . . . . . . . . . . . . . . 26Using the CRTRPGPGM Command . . . . . . . . . . . . . . . . . . . . . . . 27

    Elements of the CRTRPGPGM Command Lines . . . . . . . . . . . . . . 28Entering Elements from the CRTRPGPGM Command Display . . . . . . 28Entering Only Certain Parameters . . . . . . . . . . . . . . . . . . . . . . . 28Entering Only the Parameter Values . . . . . . . . . . . . . . . . . . . . . 29

    CRTRPGPGM Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Compiling under the System/38 Environment . . . . . . . . . . . . . . . . . . . . 45

    Chapter 4. Error Messages, Testing, and Debugging . . . . . . . . . . . . . 47Using, Displaying, and Printing Messages . . . . . . . . . . . . . . . . . . . . . 47

    Using Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Systems Application Architecture Flagging Messages . . . . . . . . . . . . . 49Displaying and Printing Messages . . . . . . . . . . . . . . . . . . . . . . . . 49

    How to Run an RPG/400 Program . . . . . . . . . . . . . . . . . . . . . . . . . . 49Save-While-Active Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

    Using a Test Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51Using Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

    Example of Using Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . 54Considerations for Using Breakpoints . . . . . . . . . . . . . . . . . . . . . . 57

    Using a Trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58Example of Using a Trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59Considerations for Using a Trace . . . . . . . . . . . . . . . . . . . . . . . . . 60

    Using the DEBUG Operation Codes . . . . . . . . . . . . . . . . . . . . . . . . . 60Using the RPG/400 Formatted Dump . . . . . . . . . . . . . . . . . . . . . . . . 60Exception/Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

    Chapter 5. General File Considerations . . . . . . . . . . . . . . . . . . . . . 75Device Independence/Device Dependence . . . . . . . . . . . . . . . . . . . . . 75Spooling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

    Output Spool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77Externally Described and Program-Described Files . . . . . . . . . . . . . . . . 78Level Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80File Locking by an RPG/400 Program . . . . . . . . . . . . . . . . . . . . . . . . 81Record Locking by an RPG/400 Program . . . . . . . . . . . . . . . . . . . . . . 81Unblocking Input Records and Blocking Output Records . . . . . . . . . . . . . 82Sharing an Open Data Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83Using the Control Language Command RCLRSC . . . . . . . . . . . . . . . . . 84Specifications for Externally Described Files . . . . . . . . . . . . . . . . . . . . 84

    File Description Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . 85Renaming Record-Format Names . . . . . . . . . . . . . . . . . . . . . . . . 85Ignoring Record Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86Floating-Point Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86Overriding or Adding RPG/400 Functions to an External Description . . . . 87Output Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

    Program-Described Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90Printer Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

    Page Overflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91Overflow Indicators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92Fetch