testa.roberta.free.frtesta.roberta.free.fr/My Books/Mainframe/COBOL 400... · 2009-03-02 ·...

of 547 /547
Note! Before using this information and the product it supports, be sure to read the general information under “Notices” on page xv. First Edition (June 1994) This edition applies to the IBM* ILE* COBOL/400* licensed program (Program 5763-CB1), Version 3 Release 0 Modifi- cation 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 elec- tronically to IBM. See "communicating Your Comments" 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. IBM is a registered trademark of International Business Machines Corporation, Armonk, N.Y.

Embed Size (px)

Transcript of testa.roberta.free.frtesta.roberta.free.fr/My Books/Mainframe/COBOL 400... · 2009-03-02 ·...

  • Note!

    Before using this information and the product it supports, be sure to read the general information under“Notices” on page xv.

    First Edition (June 1994)

    This edition applies to the IBM* ILE* COBOL/400* licensed program (Program 5763-CB1), Version 3 Release 0 Modifi-cation 5, and to all subsequent releases and modifications until otherwise indicated in new editions. Make sure youare 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 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/TOR

    1150 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 "communicating Your Comments" for a description of the methods. This page immediatelyprecedes 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.

  • Contents

    Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvProgramming Interface Information . . . . . . . . . . . . . . . . . . . . . . . . . xvTrademarks and Service Marks . . . . . . . . . . . . . . . . . . . . . . . . . . . xv

    About This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviiWho Should Use this Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviiCOBOL/400 Syntax Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii

    How to Read the Syntax Diagrams . . . . . . . . . . . . . . . . . . . . . . . . xixIBM Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiDocumentary Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiiObsolete Language Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii

    Industry Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii

    Chapter 1. COBOL Language Structure . . . . . . . . . . . . . . . . . . . . . . 1Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Character-Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

    COBOL Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3User-Defined Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3System-Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Optional Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Special Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Figurative Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Special Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9Boolean Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9Nonnumeric Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9Numeric Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

    PICTURE Character-Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

    Separators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Rules for Separators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

    Sections and Paragraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Clauses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Sentences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

    Reference Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Sequence Number Area (Columns 1 through 6) . . . . . . . . . . . . . . . . . . 16Indicator Area (Column 7) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16Area A (Columns 8 through 11) . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

    Division Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Section Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Paragraph Header or Paragraph Name . . . . . . . . . . . . . . . . . . . . . 18Level Indicator (FD and SD) or Level-Number (01 and 77) . . . . . . . . . . 18DECLARATIVES and END DECLARATIVES . . . . . . . . . . . . . . . . . . 18

    Area B (Columns 12 through 72) . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Entries, Sentences, Statements, Clauses . . . . . . . . . . . . . . . . . . . . 19

    Copyright IBM Corp. 1994 iii

  • Continuation Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Area A or Area B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

    Level-Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Comment Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Debugging Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Blank Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Pseudo-Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

    Methods of Data Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Qualification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

    References to Data Division Names . . . . . . . . . . . . . . . . . . . . . . 21References to Procedure Division Names . . . . . . . . . . . . . . . . . . 22References to COPY Libraries . . . . . . . . . . . . . . . . . . . . . . . . . 22

    Qualification Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Reference Modification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

    Evaluation of Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Range Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Restrictions on Reference Modification . . . . . . . . . . . . . . . . . . . . 25

    Subscripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Data Attribute Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Transfer of Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

    Chapter 2. COBOL Program Structure . . . . . . . . . . . . . . . . . . . . . . 29Identification Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

    Coding Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30PROGRAM-ID Paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Optional Paragraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31Environment Division—Configuration Section . . . . . . . . . . . . . . . . . . . . 32

    Coding Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33SOURCE-COMPUTER Paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . 34OBJECT-COMPUTER Paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . 35SPECIAL-NAMES Paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

    Coding Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41ALPHABET Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41CLASS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44CURRENCY SIGN Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45DECIMAL-POINT Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45CONSOLE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46CURSOR Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

    CURSOR Clause Considerations . . . . . . . . . . . . . . . . . . . . . . . . . 47CRT STATUS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

    CRT STATUS Clause Considerations . . . . . . . . . . . . . . . . . . . . . . 47

    Chapter 3. Environment Division—Input-Output Section . . . . . . . . . . 51File Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

    Database Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51Device Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51DDM Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51Save Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52Paragraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

    FILE-CONTROL Paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53SELECT Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57ASSIGN Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58RESERVE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60ORGANIZATION Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

    iv COBOL/400 Reference

  • ACCESS MODE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62Data Organization and Access Modes . . . . . . . . . . . . . . . . . . . . . . 63

    Data Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63Access Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65Relationship Between Data Organizations and Access Modes . . . . . . 65

    RECORD KEY Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66RELATIVE KEY Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68FILE STATUS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69I-O-CONTROL Paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70RERUN Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74SAME AREA Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74SAME RECORD AREA Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75SAME SORT AREA Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75SAME SORT-MERGE AREA Clause . . . . . . . . . . . . . . . . . . . . . . . . 76MULTIPLE FILE TAPE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76COMMITMENT CONTROL Clause . . . . . . . . . . . . . . . . . . . . . . . . . 77

    Chapter 4. Data Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Data Division Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

    File Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80Working-Storage Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81Linkage Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

    ADDRESS OF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82ADDRESS OF Special Register . . . . . . . . . . . . . . . . . . . . . . . . 82

    Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83File Data (External Data) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83Program Data (Internal Data) . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

    Data Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84Levels of Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

    Levels of Data in a Record Description Entry . . . . . . . . . . . . . . . . 84Special Level-Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86Indentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

    Classes and Categories of Data . . . . . . . . . . . . . . . . . . . . . . . . . 87Alignment Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88Standard Data Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89Character-String and Item Size . . . . . . . . . . . . . . . . . . . . . . . . 89

    Signed Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89Operational Signs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89Editing Signs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

    Chapter 5. Data Division—File and Sort Description Entries . . . . . . . . 91File Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97BLOCK CONTAINS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97RECORD CONTAINS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98LABEL RECORDS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100VALUE OF Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100DATA RECORDS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101LINAGE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

    LINAGE-COUNTER Special Register . . . . . . . . . . . . . . . . . . . . 104CODE-SET Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

    Chapter 6. Data Division—Data Description Entry . . . . . . . . . . . . . 107Level-Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110BLANK WHEN ZERO Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

    Contents v

  • JUSTIFIED Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112LIKE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

    Rules and Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115

    OCCURS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115Table Handling Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

    Table Handling Considerations . . . . . . . . . . . . . . . . . . . . . . . . 116Table Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

    Table References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118Fixed-Length Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

    ASCENDING/DESCENDING KEY Phrase . . . . . . . . . . . . . . . . . 119INDEXED BY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

    Variable-Length Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121OCCURS DEPENDING ON Clause . . . . . . . . . . . . . . . . . . . . . 122

    Subscripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123Subscripting Using Integers or Data-Names . . . . . . . . . . . . . . . . 124Subscripting Using Index-Names (Indexing) . . . . . . . . . . . . . . . . 124Restrictions on Subscripting . . . . . . . . . . . . . . . . . . . . . . . . . 126

    PICTURE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126Symbols Used in the PICTURE Clause . . . . . . . . . . . . . . . . . . . . 126Character-String Representation . . . . . . . . . . . . . . . . . . . . . . . . 130Data Categories and PICTURE Rules . . . . . . . . . . . . . . . . . . . . . 130PICTURE Clause Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

    Simple Insertion Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134Special Insertion Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135Fixed Insertion Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135Floating Insertion Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . 136Zero Suppression and Replacement Editing . . . . . . . . . . . . . . . . 137

    REDEFINES Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138REDEFINES Clause Considerations . . . . . . . . . . . . . . . . . . . . 139REDEFINES Clause Examples . . . . . . . . . . . . . . . . . . . . . . . 141Undefined Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141

    RENAMES Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141SIGN Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143SYNCHRONIZED Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144USAGE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

    Computational Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149DISPLAY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151INDEX Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152POINTER Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153

    Pointer Alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154VALUE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

    Chapter 7. Procedure Division . . . . . . . . . . . . . . . . . . . . . . . . . 159The Procedure Division Header . . . . . . . . . . . . . . . . . . . . . . . . . . 160

    The USING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160Declaratives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

    Sample Procedure Division Statements . . . . . . . . . . . . . . . . . . . 164Arithmetic Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

    Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165Conditional Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166

    Simple Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166Class Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

    vi COBOL/400 Reference

  • Condition-Name Condition . . . . . . . . . . . . . . . . . . . . . . . . . . 168Relation Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169Comparison of Numeric and Nonnumeric Operands . . . . . . . . . . . 173Sign Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175Switch-Status Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176

    Complex Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176Negated Simple Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . 177Combined Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177Abbreviated Combined Relation Conditions . . . . . . . . . . . . . . . . 180

    Statement Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181Imperative Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183Delimited Scope Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 184

    Explicit Scope Terminators . . . . . . . . . . . . . . . . . . . . . . . . . . 185Implicit Scope Terminators . . . . . . . . . . . . . . . . . . . . . . . . . . 185

    Compiler-Directing Statements . . . . . . . . . . . . . . . . . . . . . . . . . 185Statement Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186

    Common Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186CORRESPONDING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . 186GIVING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187ROUNDED Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187SIZE ERROR Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188

    Arithmetic Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189Arithmetic Statement Operands . . . . . . . . . . . . . . . . . . . . . . . 189

    Data Manipulation Statements . . . . . . . . . . . . . . . . . . . . . . . . . . 191Input-Output Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191

    Common Processing Facilities . . . . . . . . . . . . . . . . . . . . . . . . 191DB-FORMAT-NAME Special Register . . . . . . . . . . . . . . . . . . . . 195

    Procedure Branching Statements . . . . . . . . . . . . . . . . . . . . . . . . 195

    Chapter 8. Procedure Division Statements . . . . . . . . . . . . . . . . . . 197ACCEPT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197

    Data Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197System Information Transfer . . . . . . . . . . . . . . . . . . . . . . . . . 199DATE, DAY, and TIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200Local Data Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201Format 5 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 202Attribute Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203Attribute Data Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204Workstation I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204AT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211FROM CRT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212MODE IS BLOCK Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 212ON EXCEPTION Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . 212END-ACCEPT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212WITH Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213AUTO (AUTO-SKIP) Phrase . . . . . . . . . . . . . . . . . . . . . . . . . 213BELL (BEEP) Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213BLINK Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213FULL (LENGTH-CHECK) Phrase . . . . . . . . . . . . . . . . . . . . . . 213HIGHLIGHT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213REQUIRED (EMPTY-CHECK) Phrase . . . . . . . . . . . . . . . . . . . 213REVERSE-VIDEO Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . 214

    Contents vii

  • SECURE (NO-ECHO) Phrase . . . . . . . . . . . . . . . . . . . . . . . . 214UNDERLINE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214RIGHT-JUSTIFY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 214SPACE-FILL Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214TRAILING-SIGN Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 214UPDATE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214ZERO-FILL Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215Phrases Syntax Checked Only . . . . . . . . . . . . . . . . . . . . . . . . 215Format 7 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 215

    Extended ACCEPT and Extended DISPLAY Considerations . . . . . . . . 215Number of Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216Screen Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216Release Availability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217Subscripting and Reference Modification . . . . . . . . . . . . . . . . . . 217Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217DBCS Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217Combinations of Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . 217Display File QDLBACCDSP . . . . . . . . . . . . . . . . . . . . . . . . . 218Remote Workstations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218Differences from COBOL/2 Processing . . . . . . . . . . . . . . . . . . . 218

    ACQUIRE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219ADD Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221

    ROUNDED Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223SIZE ERROR Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223CORRESPONDING Phrase (Format 3) . . . . . . . . . . . . . . . . . . . 223END-ADD Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223

    ALTER Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224Segmentation Information . . . . . . . . . . . . . . . . . . . . . . . . . . . 225

    CALL Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226BY REFERENCE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 228BY CONTENT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229ON EXCEPTION Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 230NOT ON EXCEPTION Phrase . . . . . . . . . . . . . . . . . . . . . . . . 230ON OVERFLOW Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 230END-CALL Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230Program Termination Statements . . . . . . . . . . . . . . . . . . . . . . 231

    CALL Statement Considerations . . . . . . . . . . . . . . . . . . . . . . . . 232Call by Identifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232Length of Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232

    OS/400 Graphics Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232CANCEL Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234CLOSE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236

    CLOSE Statement Considerations . . . . . . . . . . . . . . . . . . . . . . 237COMMIT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241COMPUTE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242

    ROUNDED Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242SIZE ERROR Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243END-COMPUTE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 243

    CONTINUE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244DELETE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245

    DELETE Statement Considerations . . . . . . . . . . . . . . . . . . . . . 245DUPLICATES Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247

    viii COBOL/400 Reference

  • DISPLAY Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249Local Data Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252Format 3 – Extended DISPLAY Statement . . . . . . . . . . . . . . . . . 253AT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255UPON CRT/CRT-UNDER Phrase . . . . . . . . . . . . . . . . . . . . . . 256MODE IS BLOCK Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 256WITH Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256BELL (BEEP) Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256The BLANK Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256BLINK Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257HIGHLIGHT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257REVERSE-VIDEO Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . 257SIZE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257UNDERLINE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258Phrases that are Syntax Checked Only . . . . . . . . . . . . . . . . . . . 258Format 3 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 258

    DIVIDE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259ROUNDED Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262REMAINDER Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262SIZE ERROR Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262END-DIVIDE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263

    DROP Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264ENTER Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265EVALUATE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266

    END-EVALUATE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 269Determining Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269Comparing Selection Subjects and Objects . . . . . . . . . . . . . . . . 270Executing the EVALUATE Statement . . . . . . . . . . . . . . . . . . . . 271

    EXIT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272EXIT PROGRAM Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273GOBACK Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274GO TO Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275

    Unconditional GO TO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275Conditional GO TO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275Altered GO TO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276

    IF Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277END-IF Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278Transferring Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278Nested IF Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278

    INITIALIZE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279REPLACING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279INITIALIZE Statement Rules . . . . . . . . . . . . . . . . . . . . . . . . . 280

    INSPECT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281Comparison Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283INSPECT Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285TALLYING Phrase (Formats 1 and 3) . . . . . . . . . . . . . . . . . . . . 286REPLACING Phrase (Formats 2 and 3) . . . . . . . . . . . . . . . . . . 286BEFORE and AFTER Phrases (All Formats) . . . . . . . . . . . . . . . . 287CONVERTING Phrase (Format 4) . . . . . . . . . . . . . . . . . . . . . . 287INSPECT Statement Examples . . . . . . . . . . . . . . . . . . . . . . . 288

    MERGE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290ASCENDING/DESCENDING KEY Phrase . . . . . . . . . . . . . . . . . 291COLLATING SEQUENCE Phrase . . . . . . . . . . . . . . . . . . . . . . 292USING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292

    Contents ix

  • GIVING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292OUTPUT PROCEDURE Phrase . . . . . . . . . . . . . . . . . . . . . . . 294

    MOVE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295Elementary Moves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297Group Moves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299WHEN-COMPILED Special Register . . . . . . . . . . . . . . . . . . . . 300

    MULTIPLY Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301ROUNDED Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302SIZE ERROR Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302END-MULTIPLY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302

    OPEN Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303Sequential Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303Indexed and Relative Files . . . . . . . . . . . . . . . . . . . . . . . . . . 304Transaction Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305

    OPEN Statement Considerations . . . . . . . . . . . . . . . . . . . . . . . . 305OPEN Statement Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310

    PERFORM Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312Basic PERFORM Statement . . . . . . . . . . . . . . . . . . . . . . . . . 312PERFORM with TIMES Phrase . . . . . . . . . . . . . . . . . . . . . . . 315PERFORM with UNTIL Phrase . . . . . . . . . . . . . . . . . . . . . . . . 315PERFORM with VARYING Phrase . . . . . . . . . . . . . . . . . . . . . 316Varying Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317Varying One Identifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317Varying Two Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319Varying Three Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . 321Varying More Than Three Identifiers . . . . . . . . . . . . . . . . . . . . 324Varying Phrase Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324

    READ Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325Sequential Access Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 327Random Access Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328Dynamic Access Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328Multiple Record Processing . . . . . . . . . . . . . . . . . . . . . . . . . . 328Multivolume Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329READ Statement Considerations . . . . . . . . . . . . . . . . . . . . . . 330READ Statement Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337

    Transaction Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338RELEASE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347RETURN Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348

    AT END Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349END-RETURN Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349

    REWRITE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350Reusing a Logical Record . . . . . . . . . . . . . . . . . . . . . . . . . . . 351REWRITE Statement Considerations . . . . . . . . . . . . . . . . . . . . 352DUPLICATES Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353Sequential Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356Indexed Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356Relative Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356

    Transaction Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357ROLLBACK Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359SEARCH Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361

    AT END/WHEN Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . 362END-SEARCH Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362Serial Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362VARYING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363

    x COBOL/400 Reference

  • WHEN Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363Binary Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365WHEN Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365Search Statement Considerations . . . . . . . . . . . . . . . . . . . . . . 366SEARCH Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367

    SET Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369Format 1: TO Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369Format 2: UP BY/DOWN BY Phrase . . . . . . . . . . . . . . . . . . . . 371Format 3: ON/OFF Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . 371Format 4: TO TRUE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . 372Format 5: Pointer Data Item . . . . . . . . . . . . . . . . . . . . . . . . . 372

    SORT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374ASCENDING/DESCENDING KEY Phrase . . . . . . . . . . . . . . . . . 375DUPLICATES Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375COLLATING SEQUENCE Phrase . . . . . . . . . . . . . . . . . . . . . . 376USING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376INPUT PROCEDURE Phrase . . . . . . . . . . . . . . . . . . . . . . . . 376GIVING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377OUTPUT PROCEDURE Phrase . . . . . . . . . . . . . . . . . . . . . . . 378

    START Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379KEY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380INVALID KEY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380END-START Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380Indexed Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380Relative Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381START Statement Considerations . . . . . . . . . . . . . . . . . . . . . . 381

    STOP Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387STRING Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389

    DELIMITED BY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390INTO Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390POINTER Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390ON OVERFLOW Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . 390END-STRING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391Data Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391STRING Statement Example . . . . . . . . . . . . . . . . . . . . . . . . . 392

    SUBTRACT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395ROUNDED Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396SIZE ERROR Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396CORRESPONDING Phrase (Format 3) . . . . . . . . . . . . . . . . . . . 397END-SUBTRACT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 397

    UNSTRING Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398DELIMITED BY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398INTO Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399POINTER Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400TALLYING IN Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400ON OVERFLOW Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . 400END-UNSTRING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 401Data Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401UNSTRING Statement Example . . . . . . . . . . . . . . . . . . . . . . . 403

    WRITE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407Sequential Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407

    ADVANCING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408END-OF-PAGE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409END-WRITE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410

    Contents xi

  • Multivolume Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410Indexed and Relative Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411

    INVALID KEY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412END-WRITE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412

    Relative Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413WRITE Statement Considerations . . . . . . . . . . . . . . . . . . . . . . 414

    Chapter 9. Compiler-Directing Statements . . . . . . . . . . . . . . . . . . 427*CONTROL (*CBL) Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 427

    *CONTROL (*CBL) and the COPY Statement . . . . . . . . . . . . . . . 428COPY Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429

    SUPPRESS Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430REPLACING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431Replacement and Comparison Rules . . . . . . . . . . . . . . . . . . . . 432Format 2 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 434

    General Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436Data Structures Generated . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436

    Format (Record) Level Structures . . . . . . . . . . . . . . . . . . . . . . 436Data Field Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437Indicator Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439INDICATOR Attribute of the Format 2 COPY Statement . . . . . . . . . 439Generation of I-O Formats . . . . . . . . . . . . . . . . . . . . . . . . . . 440Redefinition of Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441Additional Notes on Field and Format Names . . . . . . . . . . . . . . . 441Floating Point Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442Date, Time, and Timestamp Fields . . . . . . . . . . . . . . . . . . . . . 442Variable-length Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442Considerations Regarding Use of REPLACING in Format 2 COPY

    Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443EJECT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445SKIP1/2/3 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446TITLE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447USE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448

    USE Statement Programming Notes . . . . . . . . . . . . . . . . . . . . 449USE FOR DEBUGGING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450

    Appendix A. COBOL/400 Compiler Limits . . . . . . . . . . . . . . . . . . . 451

    Appendix B. Summary of IBM Extensions . . . . . . . . . . . . . . . . . . 453Character-String Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . 453Identification Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453Environment Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453Data Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454Procedure Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455COPY Statement–All Divisions . . . . . . . . . . . . . . . . . . . . . . . . . . . 457Transaction Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457Compiler-Directing Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 458

    Appendix C. Intermediate Result Fields . . . . . . . . . . . . . . . . . . . . 459Compiler Calculation of Intermediate Results . . . . . . . . . . . . . . . . . . . 460

    Appendix D. EBCDIC and ASCII Collating Sequences . . . . . . . . . . . 463EBCDIC Collating Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463ASCII Collating Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466

    xii COBOL/400 Reference

  • Appendix E. COBOL/400 Reserved Word List . . . . . . . . . . . . . . . . 471

    Appendix F. File Structure Support Summary and Status Key Values . 475File Status Key Values and Meanings . . . . . . . . . . . . . . . . . . . . . . . 480Attribute Data Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485

    OPEN-FEEDBACK and I-O-FEEDBACK Data Areas . . . . . . . . . . . . . 488OPEN-FEEDBACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488I-O-FEEDBACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488

    Appendix G. PROCESS Statement, PICTURE Symbols, ASSIGN Clause 491PROCESS Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491Symbols Used in the PICTURE Clause . . . . . . . . . . . . . . . . . . . . . . 495Assignment-Names in the ASSIGN Clause . . . . . . . . . . . . . . . . . . . . 496

    Appendix H. SAA COBOL Compiler Options . . . . . . . . . . . . . . . . . 497

    Appendix I. ACCEPT/DISPLAY and COBOL/2 Considerations . . . . . . 499

    Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501

    Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503

    Contents xiii

  • xiv COBOL/400 Reference

  • Notices

    References in this publication to IBM products, programs, or services do not implythat IBM intends to make these available in all countries in which IBM operates.Any reference to an IBM product, program, or service is not intended to state orimply that only IBM's product, program, or service may be used. Any functionallyequivalent product, program, or service that does not infringe any of IBM's intellec-tual property rights may be used instead of the IBM product, program, or service.Evaluation and verification of operation in conjunction with other products, exceptthose expressly designated by IBM, is the user's responsibility.

    IBM may have patents or pending patent applications covering subject matter inthis document. The furnishing of this document does not give you any license tothese patents. You can send license inquiries, in writing, to the IBM Director of

    | Licensing, IBM Corporation, 208 Harbor Drive, Stamford, Connecticut, USA| 06904-250.

    Important changes or additions to the text are indicated by a vertical line (|) to theleft of the change or addition.

    This publication contains examples of data and reports used in daily business oper-ations. To illustrate them as completely as possible, the examples include thenames of individuals, companies, brands, and products. All of these names arefictitious and any similarity to the names and addresses used by an actual businessenterprise is entirely coincidental.

    Programming Interface InformationThis manual is intended to help you write COBOL/400* programs. It contains infor-mation necessary for you to use the COBOL/400 compiler. This manual docu-ments no programming interfaces for use in writing programs that request orreceive the services of the COBOL/400 compiler.

    Trademarks and Service MarksThe following terms, denoted by an asterisk (*) in this publication, are trademarks ofthe IBM Corporation in the United States and/or other countries:

    Application System/400 AS/400

    CICS/400 COBOL/2

    COBOL/400 IBM

    | ILE Operating System/400

    OS/2 OS/400

    Systems Application Architecture SAA

    400

    Copyright IBM Corp. 1994 xv

  • xvi COBOL/400 Reference

  • About This Manual

    About This Manual

    This manual describes the COBOL/400 language structure, program organization,procedure division statements, and compiler-directing statements.

    This manual might refer to products that are announced but are not yet available.

    The COBOL/400 language delivers most elements of the IBM Systems ApplicationArchitecture* (SAA*) Common Programming Interface (CPI) COBOL, and is theimplementing product on the AS/400* system.

    Who Should Use this ManualThis manual is a guide for the COBOL/400 programming language on the AS/400system. It is intended for people who have a basic understanding of data proc-essing concepts and of the COBOL programming language.

    Before you use this manual, you should be familiar with certain AS/400 systeminformation:

    For a comprehensive breakdown of information that pertains to COBOL/400concepts, use the Publications Guide, GC41-9678, to locate reference material.

    You should be familiar with your display station (also known as a work station),and its controls. There are also some elements of its display and certain keyson the keyboard that are standard regardless of which software system is cur-rently running at the display station, or which hardware system the displaystation is hooked up to. Some of these keys are:

    – Cursor movement keys – Command keys

    – Field exit keys– Insert and delete keys– The Error Reset key.

    This information is contained in New User’s Guide, SC41-8211.

    You should know how to operate your display station when it is hooked up tothe IBM AS/400 system and running AS/400 software. This means knowingabout the OS/400* operating system and the Control Language (CL) to do suchthings as:

    – Sign on and sign off the display station– Interact with displays

    – Use Help– Enter control commands

    – Call utilities– Respond to messages.

    To find out more about this operating system and its control language, refer to:

    – Programming: Control Language Reference, SC41-0030– Programming: Control Language Programmer’s Guide, SC41-8077

    Copyright IBM Corp. 1994 xvii

  • About This Manual

    The Data Management Guide, SC41-9658, provides information on using datamanagement support, which allows an application to work with files.

    The manual includes information on:

    – Fundamental structure and concepts of data management support on thesystem

    – Data management support for display stations, printers, tapes, anddiskettes, as well as spooling support

    – Overrides and file redirection (temporarily making changes to files when anapplication is run)

    – Copying files by using system commands to copy data from one place toanother

    – Tailoring a system using double-byte data.

    You should know how to call and use certain utilities available on the AS/400system:

    – The Screen Design Aid (SDA) utility used to design and code displays.This information is contained in Application Development Tools: ScreenDesign Aid User’s Guide and Reference, SC09-1340.

    – The Source Entry Utility (SEU), which is a full-screen editor you can use toenter and update your source and procedure members. This information iscontained in Application Development Tools: Source Entry Utility User’sGuide and Reference, SC09-1338.

    You should know how to interpret displayed and printed messages. This infor-mation is contained in the COBOL/400 User’s Guide, SC09-1812.

    COBOL/400 Syntax NotationCOBOL/400 basic formats are presented in a uniform system of syntax notation.This notation, designed to assist you in writing COBOL source statements, isexplained in the following paragraphs:

    COBOL keywords and optional words appear in uppercase letters; for example:

    PARM1

    They must be spelled exactly as shown. If any keyword is missing, the com-piler considers it as an error.

    Variables representing user-supplied names or values appear in all lowercaseletters; for example:

    parmx

    For easier text reference, some words are followed by a hyphen and a digit ora letter, as in:

    identifier–1

    This suffix does not change the syntactical definition of the word.

    Arithmetic and logical operators (+, -, *, /, **, >, =, and

  • About This Manual

    You must write the required clauses and the optional clauses (when used) inthe order shown in the diagram unless the associated rules explicitly state oth-erwise.

    How to Read the Syntax DiagramsThroughout this book, syntax is described using the structure defined below.

    Read the syntax diagrams from left to right, from top to bottom, following thepath of the line:

    The 55─── symbol indicates the beginning of a statement.

    The ───5 symbol indicates that the statement syntax is continued on the nextline.

    The 5──── symbol indicates that a statement is continued from the previousline.

    The ───5% symbol indicates the end of a statement.

    Diagrams of syntactical units other than statements, such as clauses, phrasesand paragraphs, also start with the 55─── symbol and end with the ───5%symbol.

    Note: Statements within a diagram of an entire paragraph will not start with55─── and end with ───5% unless their beginning or ending coincides with thatof the paragraph.

    Required items appear on the horizontal line (the main path):

    55────STATEMENT───────required item─────────────────────5%

    Optional items appear below the main path:

    55───STATEMENT─────┬───────────────┬────────────────────5% └─optional item─┘

    When you can choose from two or more items, they appear vertically, in astack.

    If you must choose one of the items, one item of the stack appears on the mainpath:

    55───STATEMENT───┬──required choice1──┬─────────────────5% └──required choice2──┘

    If choosing one of the items is optional, the entire stack appears below themain path:

    55───STATEMENT───┬────────────────────┬─────────────────5% ├──optional choice1──┤ └──optional choice2──┘

    About This Manual xix

  • About This Manual

    An arrow returning to the left above an item indicates that that item may berepeated:

    ┌────────────────┐ 6 │55───STATEMENT─────repeatable item──┴───────────────────5%

    A repeat arrow above a stack of required or optional choices indicates that youcan make more than one choice from the stacked items, or repeat a singlechoice:

    ┌───────────┐ ┌───────────┐ 6 │ 6 │55───STATEMENT───┬───────────┼────┬──choice3──┼─────────5% ├──choice1──┤ └──choice4──┘ └──choice2──┘

    The following example shows how the syntax is used:

    Format

    .3/ ┌──────────┐ .1/ .2/ 6 │ 55───STATEMENT──┬──identifier─1──┬──────┬──────────┼──────────────────────────5 └──literal─1─────┘ └──item─1──┘

    5────┬────┬─identifier─m──┬───────────┬──┬────────────────────────────────────5 ± └─TO─┘ └──ROUNDED──┘ │ ┌────────────────────────┐ .5/

    │ 6 .4/ │ └─identifier─n─┬───────────┼─────────5 ² └──ROUNDED──┘

    ± 5────────────────────────────────────────────────────┬──┬─────────────────┬──5% .6/ │ └──END─STATEMENT──┘² 5────┬────────────────────────────────────────────┬──┘ .7/

    └──┬────┬──SIZE ERROR──imperative statement──┘ └─ON─┘

    where item─1 is:

    55───┬──identifier─2─────────────┬───────────────────────────────────────────5% ├──literal─2────────────────┤ └──arithmetic─expression─1──┘

    .1/ The STATEMENT keyword must be specified and coded as shown.

    .2/ This operand is required. Either identifier-1 or literal-1 must be coded.

    xx COBOL/400 Reference

  • About This Manual

    .3/ The operand item-1 is optional. It may be coded or not, as required by theapplication. If coded, it may be repeated, with each entry separated by one or moreblanks. Entry selections allowed for this operand are described at the bottom of thediagram.

    .4/ The operand identifier-n is optional. If specified it may be repeated with one ormore blanks separating each entry. Each entry may be assigned the keywordROUNDED.

    .5/ In cases where multiple lines must be continued past the right margin, lineorder from top to bottom is preserved.

    .6/ The ON keyword is optional to the keyword SIZE ERROR, which is optionalitself. If SIZE ERROR is coded, then the operand imperative-statement is required.

    .7/ The END-STATEMENT keyword may be coded to end the statement. It is nota required delimiter.

    IBM ExtensionsAn IBM extension generally modifies a rule or restriction that immediately precedesit. The standard is presented first, because some programmers use theCOBOL/400 language without IBM extensions. The extension is then presented forthose who do use them.

    IBM extensions within figures or tables are shown in boxes unless they are explic-itly identified as extensions.

    Clauses and statements illustrated within syntax diagrams that are COBOL/400 lan-guage extensions to ANSI X3.23-1985 COBOL are enclosed in double lines, asfollows:

    ╔══════════════════════════╗5────RECORD─┬─────┬──┬────┬──┬──╫─EXTERNALLY-DESCRIBED-KEY─╫──┬─────────5

    └─KEY─┘ └─IS─┘ │ ╚══════════════════════════╝ │ └────data-name-2─────────────────┘

    IBM Extension

    COBOL/400 language extensions to ANSI X3.23-1985 COBOL that are part of thetext description are enclosed in IBM Extension bars, like this paragraph.

    End of IBM Extension

    About This Manual xxi

  • About This Manual

    Documentary SyntaxCOBOL clauses and statements illustrated within syntax diagrams that are syntaxchecked, but are treated as documentation by the COBOL/400 compiler, areenclosed by asterisks, as follows:

    \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\5────┬──────────────────────────────────────────┬──────────────────────5

    \ └──RESERVE────integer────┬────────────┬────┘ \ \ ├────AREA────┤ \ \ └────AREAS───┘ \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

    Obsolete Language ElementsObsolete language elements are COBOL/400 language elements in the AmericanNational Standard Programming Language COBOL, X3.23-1985, that will bedeleted from the next revision of this Standard. Throughout this book obsolete lan-guage elements are identified in the main description of the language element.They are also listed in the index under 'obsolete elements'.

    Industry StandardsThe COBOL/400 compiler is designed according to the specifications of the fol-lowing industry standards as understood and interpreted by IBM as of September1987.

    1. American National Standard Programming Language COBOL, X3.23-1985

    Following is an explanation of the notation used in the list:

    A 3-character code that identifies the module.In this example, the Segmentation module is

    referenced. │ │ │ 6 ┌───┐

    2 SEG ð,2 └─┘ └───┘ & & │ │ │ │ │ │The level of this module supported by The range of levels of supportthe COBOL/4ðð compiler. In this defined by the ANSI X3.23-1985 COBOLexample, support is provided for the standard. A level of ð means a minimumhigher of the two levels of the standard. COBOL does not need to supportSegmentation module. this module to conform to the standard.

    The COBOL/400 language conforms to the following modules:

    Nucleus (1 NUC 1,2)

    Provides internal processing of data within the four basic divisions of aprogram and the capability for defining and accessing tables.

    xxii COBOL/400 Reference

  • About This Manual

    Sequential I-O (1 SEQ 1,2)

    Provides access to records of a file in established sequence. Thesequence is established as a result of writing the records to the file.

    Relative I-O (1 REL 0,2)

    Provides access to records in either a random or sequential manner; eachrecord is uniquely identified by an integer specifying the record's logicalposition in a file.

    Indexed I-O (1 INX 0,2)

    Provides access to records in either a random or sequential manner; eachrecord in an indexed file is uniquely identified by the value of a key withinthat record.

    Inter-Program Communication (1 IPC 1,2)

    Allows a COBOL/400 program to communicate with other programs throughtransfers of control and access to common data items.

    Sort-Merge (1 SRT 0,1)

    Orders one or more files of records, or combines two or more identicallyordered files of records, according to a set of user-specified keys.

    Source-Text Manipulation (1 STM 0,2)

    Allows the insertion of source program text as part of the compilation of thesource program. COBOL/400 libraries contain texts which are available tothe compiler at compile time and which can be treated by the compiler aspart of the source program.

    Debug (2 DEB 0,2)

    Specifies the conditions under which procedures are to be monitored duringexecution.

    Segmentation (2 SEG 0,2).

    Provides programmer-controlled storage optimization of the Procedure Divi-sion by allowing that division to be subdivided both physically and logically.

    The following modules are not included:

    Report Writer (0 RPW 0,1) Communication (0 COM 0,2).

    Portions of this manual are copied (with permission) from the ANSI Standard.Copies of the ANSI Standard may be purchased from:

    American National Standards Institute1430 BroadwayNew York, New York 10018

    2. ISO 1989-1985 Standard of the International Organization for Standardization(ISO)

    3. Federal Standard COBOL of March 1986 (FIPS PUB 21-2), Intermediate Level

    4. The 7-bit coded character sets defined in American National StandardX3.4-1977, Code for Information Interchange

    About This Manual xxiii

  • About This Manual

    5. International Reference Version of the ISO 7-bit code defined in InternationalStandard 646, 7-Bit Coded Character Set for Information Processing Inter-change.

    The COBOL language is developed by the Conference on Data Systems Lan-guages (CODASYL).

    xxiv COBOL/400 Reference

  • Characters

    Chapter 1. COBOL Language Structure

    CharactersIn COBOL, the indivisible unit of data is the character. In the COBOL/400 lan-guage, the letters of the alphabet, digits, and special characters that form theCOBOL character set are represented by a subset of the EBCDIC (extendedbinary-coded decimal interchange code) character set.

    Figure 1 on page 2 shows the complete set of COBOL characters, their meanings,and their uses.

    In COBOL, an alphabetic character is a letter or a space character.

    In the COBOL/400 language, each lowercase letter is generally equivalent to thecorresponding uppercase letter. Important exceptions are letters in nonnumericliterals that do not use hexadecimal notation, and the uppercase D that mustappear in column 7 of a debugging line.

    The COBOL/400 language is restricted to the defined character set, but the con-tents of nonnumeric literals, comment lines, comment entries, and the values heldin data items, can include any of the characters from the EBCDIC character set.

    IBM Extension

    Characters from the Double-Byte Character Set (DBCS) are valid characters incertain COBOL character-strings. (See the DBCS information under “Character-Strings” on page 2 for more information.)

    End of IBM Extension

    Individual characters are joined to form character-strings and separators.

    A character-string is a character or sequence of contiguous characters that form aCOBOL word, a literal, a PICTURE character-string, or a comment. A character-string is delimited by separators.

    A separator is a contiguous string of one or more punctuation characters. A sepa-rator can be placed next to another separator, or next to a character-string. Sepa-rators are described in detail under “Separators” on page 11.

    IBM Extension

    You can use the apostrophe in place of the quotation mark if you override thedefault compiler option.

    End of IBM Extension

    Copyright IBM Corp. 1994 1

  • Character-Strings

    Character Meaning Use

    A─Z Alphabet (uppercase) Alphabetic characters

    a─z Alphabet (lowercase) Alphabetic characters

    ð─9 Arabic numerals Numeric characters

    Space Punctuation character

    . Decimal point or Editing character Period Punctuation character

    < Less than Relation character

    ( Left parenthesis Punctuation character

    + Plus sign Arithmetic operator Editing character

    $ Dollar sign Editing character

    \ Asterisk Arithmetic operator Editing character Comment character

    ) Right parenthesis Punctuation character

    ; Semicolon Punctuation character

    : Colon Punctuation character

    ─ Minus sign or Arithmetic operator Hyphen Editing character Continuation character

    / Stroke or Arithmetic operator Slash Editing character

    Line control character

    , Comma Punctuation character Editing character

    > Greater than Relation character

    = Equal sign Relation character Punctuation character

    " Quotation marks Punctuation characters

    ╔══════════════════════════════════════════════════════════════╗ ║ ' Apostrophe Punctuation character ║ ╚══════════════════════════════════════════════════════════════╝

    Figure 1. COBOL Characters—Their Meanings and Uses

    Character-StringsYou can use Single-Byte Character Set (SBCS) character-strings to form:

    COBOL words Literals PICTURE character-strings Comments.

    2 COBOL/400 Reference

  • Character-Strings

    IBM Extension

    You can use Double-Byte Character Set (DBCS) character-strings to form:

    Literals Comments.

    DBCS character-strings are constructed using characters from the Double-ByteCharacter Set of a system. DBCS character-strings can be embedded into nonnu-meric strings.

    End of IBM Extension

    COBOL WordsCOBOL words must be character-strings from the set of letters, digits, and thehyphen. The three types of COBOL words are:

    User-defined words System-names Reserved words.

    The maximum length of a COBOL word is 30 characters.

    User-Defined WordsA reserved word cannot be a user-defined word. The types of user-defined wordsare listed below, with the rules that must be followed in forming them.

    The function of each user-defined word is described in the clause or statement inwhich it appears.

    Types of User-Defined Words General Rules

    Alphabet-nameClass-nameCondition-nameData-nameRecord-nameFile-nameIndex-nameMnemonic-namePointer-nameRoutine-name

    Each word must contain at leastone alphabetic character.

    Library-nameProgram-nameText-name

    Each word must contain at leastone alphabetic character. The first10 characters must be unique.

    Paragraph-nameSection-name

    The word need not contain analphabetic character.

    Level-numbers: 01-49,66,77,88 Each word must be a 1-digit or2-digit integer.

    Segment-Numbers: 00-99 Must be a 1 or 2 digit integer; itdoes not have to be unique.

    Chapter 1. COBOL Language Structure 3

  • Character-Strings

    Valid characters in a user-defined word are:

    A through Z a through z 0 through 9

    - (hyphen).

    The hyphen may not appear as the first or last character in a user-defined word.

    User-defined words form sets equivalent to the types in the above table, except thatlevel-numbers are not a set, and condition-names, data-names, and record-namesare grouped into a single set. No user-defined word can belong to more than oneof these sets. Within each set, each user-defined word must be unique, except asspecified in “Methods of Data Reference” on page 21.

    System-NamesA system-name is a character string that is defined by IBM to have a specificmeaning to the system. There are three types of system-names:

    Computer-names Language-names Implementor-names.

    There are two types of implementor-names:

    Environment-name Assignment-name.

    The meaning of each system-name is described with the format in which it appears.

    Reserved WordsA reserved word is a character-string with a predefined meaning in a COBOLsource program. A reserved word must not be used as a user-defined word or asa system-name. Reserved words can be used only as specified in the formats fora COBOL source program.

    COBOL/400 reserved words are listed in Appendix E, “COBOL/400 Reserved WordList” on page 471.

    There are five types of reserved words:

    Keywords Optional words Special characters Figurative constants Special registers.

    KeywordsKeywords are reserved words that are required within a given clause, entry, orstatement. Within each format, such words are in uppercase and appear on themain path.

    4 COBOL/400 Reference

  • Character-Strings

    Optional WordsOptional words are reserved words that may be included in the format of a clause,entry, or statement in order to improve readability. They have no effect on theexecution of the program. When an optional word is omitted, such as in the KEYIS phrase, the meaning of the COBOL statement is unchanged. Optional wordsare shown in formats as uppercase, but appear below the main path.

    Special CharactersThere are two types of special character reserved words:

    Arithmetic operators : + - / * **

    See “Arithmetic Expressions” on page 164.

    Relational operators : < > = =

    See “Conditional Expressions” on page 166.

    Figurative ConstantsFigurative constants are reserved words that name and refer to specific constantvalues. Figurative constants are not allowed as function arguments. The reservedwords for figurative constants and their meanings are:

    ZERO/ZEROS/ZEROESRepresents the numeric value zero (0), one or more occurrences of the nonnu-meric character zero (0), or the Boolean value B"0", depending on context.

    SPACE/SPACESRepresents one or more blanks or spaces; treated as a nonnumeric literal.

    HIGH-VALUE/HIGH-VALUESRepresents one or more occurrences of the character that has the highestordinal position in the collating sequence used. For the EBCDIC and ASCIIcollating sequences, the character is X'07'; for other collating sequences, theactual character used depends on the collating sequence. HIGH-VALUE istreated as a nonnumeric literal.

    LOW-VALUE/LOW-VALUESRepresents one or more occurrences of the character that has the lowestordinal position in the collating sequence used. For the EBCDIC and ASCIIcollating sequences, the character is X'00'; for other collating sequences, theactual character used depends on the collating sequence. LOW-VALUE istreated as a nonnumeric literal.

    QUOTE/QUOTESRepresents one or more occurrences of the quotation mark character and mustbe nonnumeric. QUOTE, or QUOTES cannot be used in place of a quotationmark or an apostrophe to enclose a nonnumeric literal.

    IBM Extension

    When APOST is specified as a compiler option, the figurative constant QUOTEhas the EBCDIC value of an apostrophe.

    End of IBM Extension

    Chapter 1. COBOL Language Structure 5

  • Character-Strings

    ALL literalRepresents one or more occurrences of the string of characters comprising theliteral. The literal must be a nonnumeric literal or a figurative constant otherthan the ALL literal.

    IBM Extension

    ALL Boolean literalThe ALL literal can be Boolean.

    End of IBM Extension

    When a figurative constant other than ALL literal is used, the word ALL isredundant and is used for readability only. The figurative constant ALL literalmust not be used with the INSPECT, STOP, or STRING statements.

    Note: The figurative constant ALL literal, when associated with a numeric ornumeric-edited item and when the length of the literal is greater than one, is anobsolete element and is to be deleted from the next revision of the ANSIStandard.

    IBM Extension

    NULL/NULLSRepresents a value used to indicate that a data item defined with the USAGEIS POINTER clause, ADDRESS OF phrase, or ADDRESS OF special registerdoes not contain a valid address. NULL can be used only where explicitlyallowed in the syntax format.

    In the COBOL/400 language, a value of NULL is undefined.

    End of IBM Extension

    The singular and plural forms of a figurative constant are equivalent, and may beused interchangeably. For example, if DATA-NAME-1 is a 5-character data item,each of the following statements will fill DATA-NAME-1 with five spaces:

    MOVE SPACE TO DATA-NAME-1MOVE SPACES TO DATA-NAME-1MOVE ALL SPACES TO DATA-NAME-1

    A figurative constant may be used wherever 'literal' appears in a format, exceptwhere explicitly prohibited. When a numeric literal appears in a format, the figura-tive constant ZERO may be used.

    IBM Extension

    The figurative constant ZERO can be used as a Boolean literal.

    End of IBM Extension

    6 COBOL/400 Reference

  • Character-Strings

    The length of a figurative constant depends on the context of the program. Thefollowing rules apply:

    When a figurative constant is associated with a data item (for example, when itis moved to or compared with another item), the length of the figurative con-stant character-string is equal to the size of the associated data item.

    When a figurative constant, other than the ALL literal, is not associated withanother data item (for example, in a STOP, STRING, or UNSTRING state-ment), the length of the character-string is one (1) character.

    Special RegistersSpecial registers are reserved words that name storage areas generated by thecompiler. Their primary use is to store information produced through one of thespecific COBOL features. Each such storage area has a fixed name, and need notbe further defined within the program. Each special register is discussed in thesection indicated.

    IBM Extension

    End of IBM Extension

    IBM Extension

    LENGTH OF Special Register: The LENGTH OF special register contains thenumber of bytes used by a data item referenced by an identifier.

    The LENGTH OF phrase creates an implicit special register whose contents equalthe current length, in bytes, of the data item referenced by the identifier.

    The LENGTH OF special register has the implicit definition:

    USAGE IS BINARY, PICTURE 9(9)

    You can use it anywhere in the Procedure Division where you can use a numericdata item having the same definition as the implied definition of the LENGTH OFspecial register.

    It can appear in the starting position or length expression of a reference modifier,but you cannot apply it to an operand that is reference modified.

    Special Register Page

    ADDRESS OF 82

    Special Register Page

    DB-FORMAT-NAME 195

    Special Register Page

    DEBUG-ITEM Refer to theCOBOL/400 User’sGuide.

    Chapter 1. COBOL Language Structure 7

  • Character-Strings

    It cannot be either of the following:

    A receiving data item A subscript.

    You can use LENGTH OF in the BY CONTENT phrase of the CALL statement.

    For a table element, the LENGTH OF special register contains the length, in bytes,of one occurrence. To refer to a table element in this case, you do not need to usea subscript.

    For a variable-length element, the LENGTH OF special register contains the lengthbased on the current contents of the occurs depending on (ODO) variable.

    | Note: The ODO variable is not checked to ensure that it is within range when the| LENGTH OF a variable length item is taken.

    The register returns a value for any identifier whose length can be determined,even if the area referenced by the identifier is currently not available to theprogram. For example, an identifier that is part of a 01-level record in a File Defi-nition is not available until the corresponding file is open; however, the LENGTHOF such an identifier can be determined before the file is open.

    If, for a variable-length item, the contents of the ODO variable are not available, theLENGTH OF special register is undefined. For example, if an ODO variable isdefined in the 01-level record of a file that is not open, no LENGTH OF valueexists, and an error results.

    A separate LENGTH OF special register exists for each identifier referenced withthe LENGTH OF phrase.

    For example:

    MOVE LENGTH OF A TO BDISPLAY LENGTH OF A, AADD LENGTH OF A TO BCALL "PROGX" USING BY REFERENCE A BY CONTENT LENGTH OF A

    End of IBM Extension

    IBM Extension

    End of IBM Extension

    Special Register Page

    LINAGE-COUNTER 104

    Special Register Page

    WHEN-COMPILED 300

    8 COBOL/400 Reference

  • Character-Strings

    LiteralsA literal is a character-string whose value is specified either by the characters ofwhich it is composed, or by the use of a figurative constant. (See “FigurativeConstants” on page 5.) There are three types of literals: Boolean , nonnumeric ,and numeric .

    IBM Extension

    Boolean LiteralsA Boolean literal is a character-string delimited on the left by the separator B" andon the right by the quotation mark separator. The character-string consists only ofthe character 0 or 1. The value of a Boolean literal is the character itself, excludingthe delimiting separators. All Boolean literals are of the category Boolean.

    End of IBM Extension

    Nonnumeric LiteralsA nonnumeric literal is a character-string enclosed in quotation marks ("), and cancontain any allowable character from the EBCDIC character set. The maximumlength of a nonnumeric literal is 160 characters.

    A nonnumeric literal must be enclosed in quotation marks (") (or apostrophes if theAPOST option is in effect). These quotation marks (or apostrophes) are excludedfrom the literal when the program is compiled. An embedded quotation mark mustbe represented by a pair of quotation marks ("").

    Any punctuation characters included within a nonnumeric literal are part of thevalue of the literal.

    Every nonnumeric literal is in the alphanumeric data category. (Data categoriesare described in “Classes and Categories of Data” on page 87.)

    IBM Extension

    You can use hexadecimal notation to form a hexadecimal nonnumeric literal .

    X" The opening delimiter for hexadecimal notation of a nonnumeric literal. (If thecompiler option *APOST or the PROCESS statement option APOST is speci-fied, the opening delimiter is X'.)

    " The closing delimiter for hexadecimal notation of a nonnumeric literal. (If thecompiler option *APOST or the PROCESS statement option APOST is speci-fied, the closing delimiter is '.)

    Hexadecimal digits can be characters that range from 0 to 9, and A to F, inclusive.Two hexadecimal digits represent a single character, so an even number ofhexadecimal digits must be specified in each case.

    The maximum length of a hexadecimal nonnumeric literal is 320 hexadecimal digits.

    The continuation rules are the same as those for any nonnumeric literal.

    Chapter 1. COBOL Language Structure 9

  • Character-Strings

    55───X"────hexadecimal-digits────"───────────────────────────────5%

    Figure 2. Format

    The GRAPHIC option of the PROCESS statement does not affect the processing ofhexadecimal nonnumeric literals.

    The compiler converts the hexadecimal literal into an ordinary nonnumeric literal.Hexadecimal nonnumeric literals can be used anywhere nonnumeric literals canappear.

    The padding character for hexadecimal nonnumeric literals is a trailing blank(X"40"). Empty hexadecimal nonnumeric literals are converted to X"40".

    End of IBM Extension

    IBM Extension

    SBCS and DBCS characters can be combined within a character-string to form amixed literal . SAA COBOL statements process mixed literals without sensitivity tothe machine representation. Those statements that operate on a byte-to-byte basis(for example, STRING and UNSTRING) may produce literals that are not valid mix-tures of SBCS and DBCS. It is the user's responsibility to be certain that the state-ments are used correctly.

    Mixed literals must not be continued.

    End of IBM Extension

    Numeric LiteralsA numeric literal is a character-string whose characters are selected from thedigits 0 through 9, a sign character (+ or -), and the decimal point. If the literalcontains no decimal point, it is an integer. (In this manual, the word integerappearing in a format represents a numeric literal of nonzero value that contains nosign and no decimal point; any other restrictions are included with the description ofthe format.) The following rules apply:

    One through 18 digits are allowed.

    Only one sign character is allowed. If included, it must be the leftmost char-acter of the literal. If the literal is unsigned, it is positive in value.

    Only one decimal point is allowed. If a decimal point is included, it is treated asan assumed decimal point (that is, as not taking up a character position in theliteral). The decimal point may appear anywhere within the literal except as therightmost character.

    If enclosed in quotation marks, the compiler treats the literal as a nonnumericliteral.

    The value of a numeric literal is the algebraic quantity expressed by the charactersin the literal. The size of a numeric literal in standard data format characters isequal to the number of digits specified by the user.

    10 COBOL/400 Reference

  • Separators

    Every numeric literal is in the numeric data category. (Data categories aredescribed under “Classes and Categories of Data” on page 87.)

    PICTURE Character-StringsA PICTURE character-string consists of certain symbols that are composed of thecurrency symbol and certain combinations of characters in the COBOL characterset.

    Any punctuation character that appears as part of the specification of a PICTUREcharacter-string is not considered as a punctuation character, but rather as asymbol used in the specification of that PICTURE character-string. (A chart ofPICTURE clause symbols appears in Table 10 on page 127.)

    CommentsA comment is a character-string that can contain any combination of charactersfrom the EBCDIC character set. It has no effect on the execution of the program.There are two forms of comments:

    Comment entry(Identification Division)

    This form is described under “Optional Paragraphs” on page 31.

    Comment line(Any division)

    This form is described under “Comment Lines” on page 20.

    SeparatorsA separator can be a single punctuation character or a string of punctuation charac-ters.

    Table 1 shows the COBOL separator characters supported in the COBOL/400 lan-guage.

    Chapter 1. COBOL Language Structure 11

  • Separators

    Table 1. Separators

    Separator Meaning

    ␣ Space

    ,␣ Comma

    .␣ Period

    ;␣ Semicolon

    ( Left parenthesis

    ) Right parenthesis

    " Quotation mark

    == Pseudo-text delimiter

    : Colon

    IBM Extension

    '

    End of IBM Extension

    IBM Extension

    Apostrophe

    End of IBM Extension

    IBM Extension

    B"

    End of IBM Extension

    IBM Extension

    Opening delimiter for Boolean literal

    End of IBM Extension

    IBM Extension

    X"

    End of IBM Extension

    IBM Extension

    Opening delimiter for hexadecimal nonnumeric literal

    End of IBM Extension

    Rules for SeparatorsIn the following description, brackets enclose each separator. Anywhere a space isused as a separator, or as part of a separator, more than one space may be used.

    A space [ ␣]A space can immediately precede or follow any separator except:

    As specified in standard format rules (see “Reference Format” on page 15).

    Within quotation marks. (or apostrophes if the APOST option is in effect).Spaces between quotation marks are considered part of the nonnumericliteral; they are not considered separators.

    Period [. ␣]Comma [, ␣]Semicolon [; ␣]

    The separator period must be used only to indicate the end of a sentence, oras shown in formats. The separator comma and separator semicolon may beused anywhere the separator space is used.

    12 COBOL/400 R