IBM i: ILE COBOL Language Reference

Download IBM i: ILE COBOL Language Reference

Post on 02-Jan-2017

241 views

Category:

Documents

27 download

Embed Size (px)

TRANSCRIPT

  • IBM iVersion 7.2

    ProgrammingIBM Rational Development Studio for iILE COBOL Language Reference

    SC09-2539-08

    IBM

  • IBM iVersion 7.2

    ProgrammingIBM Rational Development Studio for iILE COBOL Language Reference

    SC09-2539-08

    IBM

  • NoteBefore using this information and the product it supports, read the information in Notices on page A-1.

    This edition applies to IBM Rational Development Studio for i (product number 5770-WDS) and to all subsequentreleases and modifications until otherwise indicated in new editions. This version does not run on all reducedinstruction set computer (RISC) models nor does it run on CISC models.

    This document may contain references to Licensed Internal Code. Licensed Internal Code is Machine Code and islicensed to you under the terms of the IBM License Agreement for Machine Code.

    Copyright IBM Corporation 1993, 2013.US Government Users Restricted Rights Use, duplication or disclosure restricted by GSA ADP Schedule Contractwith IBM Corp.

  • Contents

    ILE COBOL Language Reference

    About ILE COBOL LanguageReference . . . . . . . . . . . . . 1-1Who Should Use this Reference . . . . . . . 1-1Prerequisite and Related Information . . . . . 1-2How to Send Your Comments . . . . . . . . 1-2What's New . . . . . . . . . . . . . . 1-3

    What's New this Release? . . . . . . . . 1-3Changes to this Guide Since 7.1 . . . . . . 1-4What's New in 7.1? . . . . . . . . . . 1-4What's New in V6R1?. . . . . . . . . . 1-5What's New in V5R4?. . . . . . . . . . 1-6What's New in V5R3?. . . . . . . . . . 1-6What's New in V5R2?. . . . . . . . . . 1-7What's New in V5R1?. . . . . . . . . . 1-8What's New in V4R4?. . . . . . . . . . 1-9What's New in V4R2? . . . . . . . . . 1-10What's New in V3R7? . . . . . . . . . 1-11What's New in V3R6/V3R2? . . . . . . . 1-13What's New in V3R1? . . . . . . . . . 1-13

    ILE COBOL Syntax Notation . . . . . . . . 1-15How to Read the Syntax Diagrams . . . . . 1-16IBM Extensions . . . . . . . . . . . 1-17Documentary Syntax . . . . . . . . . 1-18Obsolete Language Elements . . . . . . . 1-18

    DBCS Notation . . . . . . . . . . . . 1-18Industry Standards . . . . . . . . . . . 1-18An Acknowledgment . . . . . . . . . . 1-19Concepts . . . . . . . . . . . . . . 1-19Supporting Information. . . . . . . . . . 1-20

    COBOL Language Structure . . . . . 2-1Characters . . . . . . . . . . . . . . 2-1

    Character-Strings . . . . . . . . . . . 2-2COBOL Words with DBCS Character . . . 2-3COBOL Words . . . . . . . . . . . 2-4

    User-Defined Words . . . . . . . . 2-4System-Names . . . . . . . . . . 2-6Function-Names . . . . . . . . . 2-6Context-Sensitive Words . . . . . . . 2-6Reserved Words . . . . . . . . . 2-6

    Literals . . . . . . . . . . . . . 2-10Boolean Literals . . . . . . . . . 2-10DBCS Literals . . . . . . . . . . 2-10National Literals . . . . . . . . . 2-12Nonnumeric Literals . . . . . . . . 2-13Null-terminated nonnumeric literals . . 2-15Numeric Literals . . . . . . . . . 2-16

    PICTURE Character-Strings . . . . . . 2-17Comment-Entry Text. . . . . . . . . 2-17

    Separators . . . . . . . . . . . . . 2-17Rules for Separators . . . . . . . . . 2-18

    Sections and Paragraphs . . . . . . . . . 2-19Entries . . . . . . . . . . . . . . 2-20

    Clauses . . . . . . . . . . . . . . 2-20Sentences . . . . . . . . . . . . . 2-20Statements . . . . . . . . . . . . . 2-20Phrases . . . . . . . . . . . . . . 2-20

    Reference Format . . . . . . . . . . . . 2-20Sequence Number Area (Columns 1 through 6) 2-21Indicator Area (Column 7) . . . . . . . . 2-21Area A (Columns 8 through 11) . . . . . . 2-21

    Division Header . . . . . . . . . . 2-21Section Header . . . . . . . . . . 2-22Paragraph Header or Paragraph Name . . 2-22Level Indicator (FD and SD) orLevel-Number (01 and 77) . . . . . . . 2-22DECLARATIVES and END DECLARATIVES 2-22END PROGRAM Header . . . . . . . 2-22

    Area B (Columns 12 through 72). . . . . . 2-22Entries, Sentences, Statements, Clauses . . 2-22Continuation Lines . . . . . . . . . 2-23

    Area A or Area B . . . . . . . . . . . 2-23Comment Lines . . . . . . . . . . 2-23Debugging Lines . . . . . . . . . . 2-24Blank Lines . . . . . . . . . . . . 2-24Pseudo-Text . . . . . . . . . . . 2-24Compiler-Directing Statements . . . . . 2-24

    Comment Area (Columns 73 through 80) . . . 2-24Data Reference and Name Scoping . . . . . . 2-24

    Methods of Data Reference . . . . . . . 2-25Identifier . . . . . . . . . . . . 2-25

    LINAGE-COUNTER . . . . . . . . 2-26condition-name . . . . . . . . . 2-26

    Qualification . . . . . . . . . . . 2-27References to Data Division Names . . . 2-27References to Procedure Division Names 2-27References to COPY Libraries . . . . . 2-28Qualification Rules . . . . . . . . 2-28

    Subscripting . . . . . . . . . . . 2-29Subscripting Using Integers orData-Names . . . . . . . . . . 2-30Subscripting Using Index-Names(Indexing) . . . . . . . . . . . 2-30Relative Subscripting . . . . . . . 2-31

    Reference Modification . . . . . . . . 2-31Evaluation of Operands. . . . . . . 2-33Reference Modification Example . . . . 2-33Range Errors . . . . . . . . . . 2-33Restrictions on Reference Modification 2-33

    Function-Identifier . . . . . . . . . 2-34References to Alphanumeric Items . . . 2-34References to Integers . . . . . . . 2-34References to DBCS Items . . . . . . 2-34References to National Items . . . . . 2-35References to Date-Time Items . . . . 2-35References to Boolean Items . . . . . 2-35

    User-Defined Data Types . . . . . . . 2-36TYPEDEF Clause . . . . . . . . . 2-36TYPE Clause . . . . . . . . . . 2-36

    Copyright IBM Corp. 1993, 2013 iii

    ||||##

  • Scope of Names . . . . . . . . . . . 2-37Types of Names . . . . . . . . . . 2-37Nested Programs . . . . . . . . . . 2-38Global and Local Names . . . . . . . 2-38External and Internal Objects . . . . . . 2-40Data Attribute Specification . . . . . . 2-40Resolution of Names. . . . . . . . . 2-41Conventions for Program-Names . . . . 2-41

    Rules Regulating the Scope of ProgramNames . . . . . . . . . . . . 2-42

    Transfer of Control . . . . . . . . . . . 2-42Next Executable Statement. . . . . . . . 2-43

    COBOL Program Structure . . . . . . 3-1General Structure . . . . . . . . . . . . 3-1

    END PROGRAM Header . . . . . . . . 3-2

    Identification Division . . . . . . . . 4-1PROGRAM-ID Paragraph . . . . . . . . . 4-2

    program-name . . . . . . . . . . . . 4-2literal . . . . . . . . . . . . . . . 4-2RECURSIVE Clause . . . . . . . . . . 4-3COMMON Clause . . . . . . . . . . . 4-3INITIAL Clause. . . . . . . . . . . . 4-3

    Optional Paragraphs . . . . . . . . . . . 4-4comment-entry . . . . . . . . . . . . . 4-4

    Environment Division . . . . . . . . 5-1Configuration Section . . . . . . . . . . . 5-1

    Coding Example . . . . . . . . . . . 5-2SOURCE-COMPUTER Paragraph . . . . . . 5-2

    computer-name . . . . . . . . . . . 5-2WITH DEBUGGING MODE Clause . . . . 5-2

    OBJECT-COMPUTER Paragraph . . . . . . 5-3SPECIAL-NAMES Paragraph . . . . . . . 5-4

    Coding Example . . . . . . . . . . 5-7ALPHABET Clause . . . . . . . . . . 5-7

    Coding Examples . . . . . . . . . . 5-10CLASS Clause . . . . . . . . . . . . 5-10CONSOLE Clause . . . . . . . . . . 5-11CRT STATUS Clause . . . . . . . . . . 5-12

    CRT STATUS Clause Considerations . . . 5-12CRT Status Key 1 . . . . . . . . . 5-12CRT Status Key 2 . . . . . . . . . 5-12CRT Status Key 3 . . . . . . . . . 5-13

    CURRENCY SIGN Clause . . . . . . . . 5-13CURSOR Clause . . . . . . . . . . . 5-15

    CURSOR Clause Considerations . . . . . 5-15DECIMAL-POINT IS COMMA Clause . . . . 5-15FORMAT Clause . . . . . . . . . . . 5-16

    SIZE Phrase . . . . . . . . . . . 5-17LOCALE Phrase . . . . . . . . . . 5-18

    LINKAGE TYPE Clause . . . . . . . . 5-18LINKAGE TYPE Clause Considerations . . 5-19

    LOCALE Clause . . . . . . . . . . . 5-20PROGRAM STATUS Clause . . . . . . . 5-20

    Input-Output Section . . . . . . . . . . 5-21File Categories. . . . . . . . . . . . 5-21

    Database Files . . . . . . . . . . . 5-22Distributed Files . . . . . . . . . 5-22

    Device Files. . . . . . . . . . . . 5-22DDM Files . . . . . . . . . . . . 5-22Save Files . . . . . . . . . . . . 5-22

    Paragraphs . . . . . . . . . . . . . 5-22FILE-CONTROL Paragraph . . . . . . . 5-23

    FILE-CONTROL Paragraph - Format 1 -Sequential Files . . . . . . . . . . 5-23FILE-CONTROL Paragraph - Format 2 -Relative Files . . . . . . . . . . . 5-24FILE-CONTROL Paragraph - Format 3 -Indexed Files . . . . . . . . . . . 5-25FILE-CONTROL Paragraph - Format 4 - Sortor Merge Files . . . . . . . . . . . 5-26FILE-CONTROL Paragraph - Format 5 -Transaction Files . . . . . . . . . . 5-26

    SELECT Clause . . . . . . . . . . . 5-27ASSIGN Clause . . . . . . . . . . . 5-27

    Device . . . . . . . . . . . . . 5-28File Name . . . . . . . . . . . . 5-29Attribute. . . . . . . . . . . . . 5-29

    RESERVE Clause . . . . . . . . . . . 5-30ORGANIZATION Clause . . . . . . . . 5-30

    ORGANIZATION IS SEQUENTIAL (Format1) . . . . . . . . . . . . . . . 5-30ORGANIZATION IS RELATIVE (Format 2) 5-31ORGANIZATION IS INDEXED (Format 3) 5-31ORGANIZATION IS TRANSACTION(Format 4) . . . . . . . . . . . . 5-31

    PADDING CHARACTER Clause . . . . . 5-31RECORD DELIMITER Clause. . . . . . . 5-32ACCESS MODE Clause. . . . . . . . . 5-32

    ACCESS MODE Clause - Format 1 -Sequential Files . . . . . . . . . . 5-32ACCESS MODE Clause - Format 2 - RelativeFiles . . . . . . . . . . . . . . 5-33ACCESS MODE Clause - Format 3 - IndexedFiles . . . . . . . . . . . . . . 5-33ACCESS MODE Clause - Format 4 -Transaction Files . . . . . . . . . . 5-33Data Organization and Access Modes . . . 5-34Data Organization . . . . . . . . . 5-34

    Sequential Organization . . . . . . 5-34Relative Organization . . . . . .

Recommended

View more >