COBOL ANSI-74 Programming Reference Manual, Volume 1: Basic ...

8 downloads 82 Views 3MB Size Report
Column 7: Indicator Area ............................................................. 1–8. Columns 8–11: ..... 3–7. Task-Attribute Identifiers (Extension to ANSI. X3.23-1974 COBOL).
unisys

Application Development Solutions COBOL ANSI-74 Programming Reference Manual Volume 1: Basic Implementation ClearPath MCP 14.0 April 2012

8600 0296–207

NO WARRANTIES OF ANY NATURE ARE EXTENDED BY THIS DOCUMENT. Any product or related information described herein is only furnished pursuant and subject to the terms and conditions of a duly executed agreement to purchase or lease equipment or to license software. The only warranties made by Unisys, if any, with respect to the products described in this document are set forth in such agreement. Unisys cannot accept any financial or other responsibility that may be the result of your use of the information in this document or software material, including direct, special, or consequential damages. You should be very careful to ensure that the use of this information and/or software material complies with the laws, rules, and regulations of the jurisdictions with respect to which it is used. The information contained herein is subject to change without notice. Revisions may be issued to advise of such changes and/or additions. Notice to U.S. Government End Users: This is commercial computer software or hardware documentation developed at private expense. Use, reproduction, or disclosure by the Government is subject to the terms of Unisys standard commercial license for the products, and where applicable, the restricted/limited rights provisions of the contract data rights clauses.

Unisys and ClearPath are registered trademarks of Unisys Corporation in the United States and other countries. All other brands and products referenced in this document are acknowledged to be the trademarks or registered trademarks of their respective holders.

Contents Section 1.

Program Structure Documentation Updates ................................................................................. 1–3 What's New? ...................................................................................................... 1–3 Source Program Components ....................................................................... 1–4 Program Divisions ......................................................................... 1–4 Sections ........................................................................................... 1–4 Paragraphs ...................................................................................... 1–5 Sentences ....................................................................................... 1–6 Statements ..................................................................................... 1–7 Clauses, Phrases, and Options .................................................. 1–7 Words ............................................................................................... 1–7 Line Layout .......................................................................................................... 1–7 Columns 1–6: Sequence Area .................................................... 1–8 Column 7: Indicator Area ............................................................. 1–8 Columns 8–11: Area A .................................................................. 1–9 Columns 12–72: Area B .............................................................. 1–10 Columns 73–80: Identification Area ........................................ 1–11 Special-Purpose Lines ..................................................................................... 1–11 Comment Lines ............................................................................. 1–11 Continuation Lines ...................................................................... 1–12 Debugging Lines .......................................................................... 1–13 Compiler Control Options ......................................................... 1–14 Blank Lines .................................................................................... 1–14

Section 2.

Language Elements Character Set ...................................................................................................... 2–1 Separators ........................................................................................................... 2–2 Character Strings ...............................................................................................2–3 Word Types ....................................................................................................... 2–4 Reserved Words .......................................................................... 2–4 Context-Sensitive Keywords ................................................... 2–11 Application-Specific Keywords ............................................... 2–12 System-Name .............................................................................. 2–12 User-Defined Words .................................................................. 2–12 Literals ................................................................................................................ 2–14 Nonnumeric .................................................................................. 2–15 Numeric ......................................................................................... 2–15 Floating Point ................................................................................ 2–16 Undigit (Extension to ANSI X3.23-1974 COBOL) ................. 2–17 Kanji (Extension to ANSI X3.23-1974 COBOL) ...................... 2–19

8600 0296–207

iii

Contents

Section 3.

File and Task Concepts Physical Aspects of a File ............................................................................... 3–1 Logical Aspects of a File.................................................................................. 3–1 Assigning a File to a Device............................................................................3–2 Remote Files ...................................................................................3–2 Port Files ..........................................................................................3–2 File Attributes .................................................................................................... 3–3 File-Attribute Identifiers.............................................................. 3–3 File-Attribute Categories ............................................................ 3–4 File Organization and Access Methods .......................................................3–5 Sequential Organization ...............................................................3–5 Relative Organization .................................................................. 3–6 Indexed Organization .................................................................. 3–6 Current-Record Pointer .................................................................................. 3–6 Task Attributes ..................................................................................................3–7 Task-Attribute Identifiers (Extension to ANSI X3.23-1974 COBOL)..................................................................3–7 Task-Attribute Types ................................................................... 3–8 Interrogating Task Attributes .................................................... 3–9

Section 4.

IDENTIFICATION DIVISION PROGRAM-ID Paragraph ................................................................................ 4–2 DATE-COMPILED Paragraph .......................................................................... 4–3

Section 5.

ENVIRONMENT DIVISION CONFIGURATION SECTION ............................................................................5–2 SOURCE-COMPUTER ...................................................................5–2 OBJECT-COMPUTER ....................................................................5–3 SPECIAL-NAMES ...........................................................................5–5 INPUT-OUTPUT SECTION ..............................................................................5–14 FILE-CONTROL Paragraph .........................................................5–14 Sort-Merge................................................................................... 5–25 I-O-CONTROL .............................................................................. 5–26 I/O Status .......................................................................................................... 5–29

Section 6.

Data Concepts Records ................................................................................................................ 6–1 Levels ...................................................................................................................6–2 Understanding Elementary and Group Items ........................6–2 Organizing Data with Level-Numbers ..................................... 6–3 Constructing a Record ................................................................ 6–4 Data ...................................................................................................................... 6–6 Qualifying Data to Ensure Uniqueness ....................................6–7 Aligning Data ................................................................................ 6–10 Tables ................................................................................................................. 6–11 Defining Tables ............................................................................ 6–11

iv

8600 0296–207

Contents

Accessing Tables ........................................................................ 6–12 Editing ................................................................................................................. 6–17 Section 7.

DATA DIVISION Sections of the DATA DIVISION .................................................................... 7–1 FILE SECTION..................................................................................................... 7–4 File-Description (FD) Entry ............................................................................. 7–4 BLOCK CONTAINS Clause ..........................................................7–9 RECORD CONTAINS Clause ..................................................... 7–10 LABEL RECORDS Clause ........................................................... 7–12 VALUE OF Clause ........................................................................ 7–13 DATA RECORDS Clause ............................................................ 7–18 LINAGE Clause ............................................................................. 7–18 CODE-SET Clause ........................................................................ 7–21 Record Description .........................................................................................7–22 Data-Description Entry for Record Structure ......................................... 7–23 Data-Name or FILLER Clause .................................................. 7–28 BLANK WHEN ZERO Clause .................................................... 7–29 GLOBAL Clause (Extension to ANSI X3.23-1974 COBOL) .................................................................................... 7–29 JUSTIFIED Clause ........................................................................ 7–31 LOCAL Clause (Extension to ANSI X3.23-1974 COBOL) ..................................................................................... 7–31 LOWER-BOUNDS Clause (Extension to ANSI X3.23-1974 COBOL)............................................................... 7–32 OCCURS Clause .......................................................................... 7–33 OWN Clause (Extension to ANSI X3.23-1974 COBOL) .................................................................................... 7–37 PICTURE Clause .......................................................................... 7–38 RECEIVED Clause (Extension to ANSI X3.23-1974 COBOL) .................................................................................... 7–53 REDEFINES Clause ..................................................................... 7–55 SIGN Clause ................................................................................. 7–56 SYNCHRONIZED Clause ........................................................... 7–58 TYPE Clause (Extension to ANSI X3.23-1974 COBOL) .................................................................................... 7–60 USAGE Clause ............................................................................. 7–62 VALUE Clause .............................................................................. 7–69 Data-Description Entry for Renaming Entries..........................................7–72 Data-Description Entry for Condition-Names ......................................... 7–74 WORKING-STORAGE SECTION .................................................................. 7–77 Noncontiguous WORKING-STORAGE Items ...................... 7–77 WORKING-STORAGE Records ............................................... 7–77 LOCAL-STORAGE SECTION (Extension to ANSI X3.23-1974 COBOL) ........................................................................................................ 7–78

Section 8.

PROCEDURE DIVISION Concepts PROCEDURE DIVISION Header ...................................................................... 8–1 PROCEDURE DIVISION Body..........................................................................8–2

8600 0296–207

v

Contents

Categories of Statements and Sentences ................................................ 8–5 Conditional Statements and Sentences ................................. 8–5 Compiler-Directing Imperative Statements and Sentences ................................................................................. 8–5 Program-Directing Imperative Statements and Sentences ................................................................................. 8–6 Arithmetic Expressions .................................................................................. 8–6 Arithmetic Operators .................................................................. 8–6 Formation and Evaluation Rules ................................................8–7 Numeric Functions ....................................................................... 8–8 Conditional Expressions ................................................................................8–14 Simple Conditions .......................................................................8–14 Complex Conditions ...................................................................................... 8–22 Common Phrases in Statements ............................................................... 8–27 ROUNDED Phrase ...................................................................... 8–27 SIZE ERROR Phrase ................................................................... 8–28 CORRESPONDING Phrase ........................................................ 8–28 Common Rules for Arithmetic Statements ............................................. 8–29 Calculating Multiple Results with One Arithmetic Statement ................................................................................ 8–29 Handling Incompatible Data..................................................... 8–30 I/O Exception Conditions ............................................................................... 8–31 Functional Groupings of Verbs ................................................................... 8–33 Section 9.

PROCEDURE DIVISION Statements ACCEPT ................................................................................................................ 9–1 ADD ...................................................................................................................... 9–3 ALLOW (Extension to ANSI X3.23-1974 COBOL) ..................................... 9–6 ALTER .................................................................................................................. 9–8 ATTACH (Extension to ANSI X3.23-1974 COBOL).................................... 9–9 AWAIT-OPEN (Extension to ANSI X3.23-1974 COBOL) ......................... 9–11 CALL .................................................................................................................... 9–15 CAUSE (Extension to ANSI X3.23-1974 COBOL) ..................................... 9–21 CHANGE (Extension to ANSI X3.23-1974 COBOL) ................................. 9–22 CLOSE ................................................................................................................ 9–25 Format 1: Sequential I/O ........................................................... 9–26 Format 2: Relative and Indexed I/O ....................................... 9–34 Format 3: Port Files (Extension to ANSI X3.23-1974 COBOL) .................................................................................... 9–36 Handling of Error Conditions ................................................... 9–39 I/O Status Value .......................................................................... 9–40 COMPUTE ..........................................................................................................9–41 CONTINUE (Extension to ANSI X3.23-1974 COBOL) ............................. 9–43 COPY.................................................................................................................. 9–43 DELETE .............................................................................................................. 9–48 DETACH (Extension to ANSI X3.23-1974 COBOL) ................................. 9–49 DISALLOW ....................................................................................................... 9–50 DISPLAY ............................................................................................................. 9–51 DIVIDE................................................................................................................ 9–52 EXECUTE (Extension to ANSI X3.23-1974 COBOL) ................................ 9–55

vi

8600 0296–207

Contents

EXIT .................................................................................................................... 9–56 GO TO ................................................................................................................ 9–58 IF ........................................................................................................................ 9–59 INSPECT ............................................................................................................ 9–60 Inspection ..................................................................................... 9–66 Examples of the INSPECT Statement ................................... 9–69 LOCK (Extension to ANSI X3.23-1974 COBOL) ....................................... 9–72 MERGE .............................................................................................................. 9–73 MOVE................................................................................................................. 9–77 MULTIPLY ......................................................................................................... 9–82 OPEN.................................................................................................................. 9–85 Format 1: Sequential, Relative, and Indexed I/O................. 9–85 Open Modes ................................................................................ 9–88 Format 2: Opening Port Files (Extension to ANSI X3.23-1974 COBOL)............................................................... 9–90 Handling of Error Conditions ................................................... 9–94 I/O Status Value .......................................................................... 9–95 PERFORM ......................................................................................................... 9–96 PROCESS (Extension to ANSI X3.23-1974 COBOL) ............................. 9–105 READ................................................................................................................ 9–106 Format 1: Sequential Access ................................................. 9–107 Format 2: Random Access of Relative or Indexed Files ......................................................................................... 9–109 Format 3: Dynamic Access of Relative or Indexed I/O Files ................................................................................... 9–110 Format 4: Random Access of Indexed Files ...................... 9–111 RELEASE .......................................................................................................... 9–114 RESET (Extension to ANSI X3.23-1974 COBOL) .................................... 9–115 RESPOND (Extension to ANSI X3.23-1974 COBOL).............................. 9–116 RETURN .......................................................................................................... 9–120 REWRITE ..........................................................................................................9–122 Sequential I/O ............................................................................ 9–123 Relative I/O................................................................................. 9–123 Indexed I/O................................................................................. 9–123 RUN (Extension to ANSI X3.23-1974 COBOL) ....................................... 9–124 SEARCH .......................................................................................................... 9–125 SEEK (Extension to ANSI X3.23-1974 COBOL) ....................................... 9–131 SET ................................................................................................................... 9–132 SORT ................................................................................................................ 9–137 START .............................................................................................................. 9–148 Relative I/O Comparison......................................................... 9–149 Indexed I/O Comparison......................................................... 9–149 Reference Key Use .................................................................. 9–150 STOP ................................................................................................................. 9–151 STRING ............................................................................................................ 9–152 SUBTRACT ..................................................................................................... 9–155 UNLOCK (Extension to ANSI X3.23-1974 COBOL) ............................... 9–158 UNSTRING ...................................................................................................... 9–159 USE .................................................................................................................... 9–171 WAIT (Extension to ANSI X3.23-1974 COBOL) ......................................9–177 WRITE .............................................................................................................. 9–180

8600 0296–207

vii

Contents

Format 1: Sequential I/O and Vertical Positioning of Lines......................................................................................... 9–181 Format 2: Sequential, Relative, and Indexed I/O .............. 9–184 Sequential I/O ............................................................................ 9–185 Relative I/O................................................................................. 9–186 Indexed I/O................................................................................. 9–186 Port Files (Extension to ANSI X3.23-1974 COBOL) .......... 9–187 Formats 3 and 4: Kanji Delimiters ........................................ 9–187 Section 10.

Segmentation Actual COBOL74 Segmentation .................................................................. 10–1 Standard COBOL74 Segmentation ............................................................. 10–1

Section 11.

Debugging Compile-Time Switch ...................................................................................... 11–1 Object-Time Switch ......................................................................................... 11–1 ENVIRONMENT DIVISION in the Debug Module .................................... 11–2 PROCEDURE DIVISION in the Debug Module.......................................... 11–2 DEBUG-ITEM Special Register ..................................................................... 11–7 Debugging Lines .............................................................................................11–10 Debug Module Program Sample ................................................................ 11–11

Section 12.

Report Writer FILE SECTION REPORT Clause ..................................................................... 12–1 REPORT SECTION Report-Description Entry ........................................... 12–3 CODE Clause (Extension to ANSI X3.23-1974 COBOL) ..................................................................................... 12–4 CONTROL Clause ........................................................................ 12–5 PAGE Clause ................................................................................. 12–7 Special Registers ............................................................................................ 12–11 PAGE-COUNTER ......................................................................... 12–11 LINE-COUNTER ........................................................................... 12–11 REPORT SECTION Report-Group Descriptions ..................................... 12–13 Format 1: Report-Group Descriptions .................................. 12–14 Processing Report Groups .....................................................12–20 Format: 2 Report-Group Descriptions ................................. 12–22 Format 3: Report-Group Description ...................................12–23 Incrementing Sum Counters ..................................................12–29 PROCEDURE DIVISION Statements ......................................................... 12–31 INITIATE Statement .................................................................. 12–31 GENERATE Statement..............................................................12–32 GENERATE Statement Actions ..............................................12–32 Producing Report Groups .......................................................12–33 TERMINATE Statement ...........................................................12–33 USE BEFORE REPORTING Statement ................................. 12–34 Report Writer Program Example ..............................................................12–35

viii

8600 0296–207

Contents

Section 13.

ANSI Inter-Program Communication (IPC) LINKAGE SECTION in the IPC Module........................................................ 13–1 Noncontiguous Linkage Storage ............................................. 13–2 Linkage Records .......................................................................... 13–3 PROCEDURE DIVISION in the IPC Module ................................................ 13–3 PROCEDURE DIVISION Header ................................................ 13–3 CALL Statement...........................................................................13–4 CANCEL Statement ..................................................................... 13–5 EXIT PROGRAM Statement ...................................................... 13–6 STOP RUN Statement ................................................................ 13–6

Section 14.

COMMUNICATION SECTION DCILIBRARY Library ........................................................................................ 14–1 DCIENTRYPOINT .......................................................................... 14–1 Program Sample: CD Array .......................................................14–5 DATA DIVISION in the Communication Module...................................... 14–7 PROCEDURE DIVISION in the Communication Module ..................... 14–20 ACCEPT MESSAGE COUNT Statement .............................. 14–20 DISABLE Statement ................................................................. 14–20 ENABLE Statement ...................................................................14–22 RECEIVE Statement ................................................................. 14–23 SEND Statement ....................................................................... 14–25

Section 15.

Libraries Creating a Library ............................................................................................ 15–1 PROCEDURE DIVISION Header in Library Program ............ 15–2 Rules for Parameters ................................................................. 15–3 Exiting a Library................................................................................................15–4 Securing a Library ............................................................................................ 15–5 Referring to a Library ..................................................................................... 15–6 CALL Statement for Libraries ................................................... 15–6 Effect of Library State on a CALL Statement..................... 15–10 CANCEL Statement for Libraries ............................................15–11 Effect of Library Initial State on a CANCEL Statement ............................................................................... 15–12 Library Attributes .......................................................................................... 15–12 Types of Library Attributes ..................................................... 15–12 CHANGE ATTRIBUTE Statement for Libraries ................... 15–14 Library Compiler Control Options ............................................................. 15–15 LIBRARYLOCK ............................................................................ 15–15 SHARING...................................................................................... 15–15 TEMPORARY .............................................................................. 15–16 Program Samples of Referring to a Library............................................ 15–17

Section 16.

Internationalization Accessing the Internationalization Features ............................................ 16–1

8600 0296–207

ix

Contents

Using the Ccsversion, Language, and Convention Default Settings ...................................................................... 16–2 Understanding the Hierarchy for Default Settings ............. 16–3 Components of the MLS Environment ......................................................16–4 Coded Character Sets and Ccsversions ................................16–4 Providing Support for Natural Languages ........................... 16–10 Providing Support for Business and Cultural Conventions ............................................................................16–11 Summary of Language Syntax by Division ............................................. 16–16 ENVIRONMENT DIVISION ....................................................... 16–16 DATA DIVISION .......................................................................... 16–16 PROCEDURE DIVISION............................................................. 16–17 Summary of CENTRALSUPPORT Library Procedures ........................ 16–20 Identifying Available Coded Character Sets and Ccsversions .......................................................................... 16–20 Mapping Data from One Coded Character Set to Another ................................................................................... 16–21 Processing Data According to Ccsversion ......................... 16–21 Comparing and Sorting Text ..................................................16–22 Positioning Characters .............................................................16–22 Determining Available Natural Languages ..........................16–22 Accessing CENTRALSUPPORT Library Messages ...........16–22 Identifying Available Convention Definitions .................... 16–23 Obtaining Convention Information....................................... 16–23 Formatting Dates According to Convention ..................... 16–24 Formatting Times According to Convention ......................16–25 Formatting Monetary Data According to Convention .............................................................................16–25 Determining Default Page Size ............................................. 16–26 Library Calls .................................................................................16–27 Parameter Categories ..............................................................16–27 Procedure Descriptions ............................................................................... 16–31 CCSTOCCS_TRANS_TEXT ....................................................... 16–31 CCSVSN_NAMES_NUMS ........................................................ 16–35 CENTRALSTATUS ..................................................................... 16–39 CNV_CURRENCYEDITTMP_DOUBLE_COB ........................ 16–43 CNV_DISPLAYMODEL_COB................................................... 16–46 CNV_FORMATDATETMP_COB ............................................. 16–49 CNV_FORMATDATE_COB .......................................................16–52 CNV_CURRENCYEDIT_DOUBLE_COB ................................. 16–55 CNV_FORMATTIMETMP_COB .............................................. 16–57 CNV_FORMATTIME_COB ........................................................ 16–61 CNV_FORMSIZE ........................................................................ 16–64 CNV_NAMES .............................................................................. 16–67 CNV_SYMBOLS .......................................................................... 16–71 CNV_SYSTEMDATETIMETMP_COB ...................................... 16–81 CNV_SYSTEMDATETIME_COB ............................................. 16–85 CNV_TEMPLATE_COB ............................................................. 16–88 CNV_VALIDATENAME .............................................................. 16–91 GET_CS_MSG ............................................................................. 16–93 MCP_BOUND_LANGUAGES .................................................. 16–99 VALIDATE_NAME_RETURN_NUM ...................................... 16–102 x

8600 0296–207

Contents

VALIDATE_NUM_RETURN_NAME ......................................16–105 VSNCOMPARE_TEXT ..............................................................16–108 VSNESCAPEMENT ................................................................... 16–113 VSNGETORDERINGFOR_ONE_TEXT ................................... 16–117 VSNINSPECT_TEXT.................................................................. 16–123 VSNTRANS_TEXT .................................................................... 16–129 Errors ..............................................................................................................16–133 Declarations ..............................................................................16–133 Explanation of Error Values ................................................. 16–134 Section 17.

Control of the Compilation Process Starting a Compilation .................................................................................... 17–1 Using Cross-Reference Files ........................................................................ 17–2 Performing a Separate Compilation ........................................................... 17–5 Providing the Changed Records .............................................. 17–6 Observing Compilation Restrictions ...................................... 17–6 Compiler Control Option Concepts ............................................................ 17–8 Types of Compiler Control Records (CCRs) ......................... 17–8 Types of Compiler Control Options ....................................... 17–8 Compiler Control Option Formats ............................................................. 17–10 Option Action Indicators ............................................................................. 17–12 COBOL74 Source and Object Files ........................................................... 17–13 Input Files .................................................................................... 17–14 Output Files ................................................................................ 17–16 Compiler Control Options ........................................................................... 17–19 BINARYCOMP ............................................................................ 17–19 BINDINFO .................................................................................... 17–19 CLEAR ...........................................................................................17–20 CODE ............................................................................................17–20 COMPILERDEBUG .....................................................................17–20 DEBUG ..........................................................................................17–20 DELETE ......................................................................................... 17–21 DOUBLE ....................................................................................... 17–21 ERRORLIMIT ............................................................................... 17–21 ERRORLIST .................................................................................. 17–22 FEDLEVEL..................................................................................... 17–22 FREE ..............................................................................................17–23 GLOBAL .......................................................................................17–23 GLOBALTEMP ............................................................................17–24 GROUPMOVEWARN ................................................................17–25 INFO ..............................................................................................17–26 LABELSINTABLE ........................................................................17–26 LEVEL ............................................................................................ 17–27 LIB$ OR LIBDOLLAR ................................................................. 17–27 LIBRARYLOCK ............................................................................17–28 LINEINFO......................................................................................17–28 LIST ...............................................................................................17–28 LIST$ or LISTDOLLAR...............................................................17–29 LISTDELETED ............................................................................. 17–30 LISTOMITTED ............................................................................ 17–30

8600 0296–207

xi

Contents

LISTP ............................................................................................ 17–30 LIST1 .............................................................................................. 17–31 MAKEHOST ................................................................................. 17–31 MAP .............................................................................................. 17–31 MERGE .........................................................................................17–32 NEW ..............................................................................................17–32 NEWID ..........................................................................................17–33 NORMALMCPWARNING .........................................................17–33 NOXREFLIST .............................................................................. 17–34 OMIT .............................................................................................17–35 OPTIMIZE or OPT.......................................................................17–35 OWN ............................................................................................ 17–36 OWNTEMP ..................................................................................17–37 PAGE .............................................................................................17–37 SEPCOMP ................................................................................... 17–38 SEQCHECK ................................................................................. 17–38 SEQUENCE or SEQ ................................................................... 17–39 Sequence Base ............................................................... 17–40 Sequence Increment ..................................................... 17–40 SHARING...................................................................................... 17–41 SPEC..............................................................................................17–42 STATISTICS .................................................................................17–42 STERNFATAL ............................................................................. 17–43 STERNMULTDEST .................................................................... 17–43 STRICTPICTURE ........................................................................ 17–43 SUMMARY ................................................................................. 17–43 Symbolic ID ................................................................................ 17–44 TADS ............................................................................................ 17–44 TARGET ....................................................................................... 17–45 TEMPORARY ............................................................................. 17–46 USER ............................................................................................ 17–46 VOID ............................................................................................. 17–47 WARNFATAL ............................................................................. 17–47 WARNSUPR ............................................................................... 17–48 XDECS.......................................................................................... 17–48 XREF ............................................................................................. 17–48 XREFFILES................................................................................... 17–49 XREFS .......................................................................................... 17–49 Appendix A. General Format Notation Appendix B. Reserved Words and Keywords Reserved Words ...............................................................................................B–1 Context-Sensitive Keywords ........................................................................ B–8 Application-Specific Keywords .................................................................... B–9 Appendix C. EBCDIC and ASCII Character Sets

xii

8600 0296–207

Contents

Appendix D. Examples Index

8600 0296–207

..................................................................................................... 1

xiii

Contents

xiv

8600 0296–207

Figures 1–1.

Line Format ........................................................................................................................ 1–7

7–1.

PICTURE Character Precedence Chart..................................................................... 7–53

9–1. 9–2. 9–3.

VARYING Phrase of a PERFORM Statement with One Condition .................. 9–102 VARYING Phrase of a PERFORM Statement with Two Conditions ............... 9–103 SEARCH Statement Containing Two WHEN Phrases .........................................9–127

12–1. 12–2. 12–3.

Page Format Control.................................................................................................... 12–10 Input Data File to Sample Report Writer Program ............................................. 12–39 Sample Report Writer Report .................................................................................. 12–40

14–1. 14–2.

Communication Status Condition in the 01-level ................................................. 14–11 Communication Status Key Condition in the 02-level ........................................ 14–16

17–1.

Compiler Data Flow ..................................................................................................... 17–13

8600 0296–207

xv

Figures

xvi

8600 0296–207

Tables 1–1. 1–2. 1–3.

Purpose of COBOL74 Divisions.................................................................................... 1–4 Purpose of Sections ........................................................................................................ 1–5 Placement of Source Program Component within Areas ..................................... 1–8

2–1. 2–2. 2–3. 2–4. 2–5. 2–6. 2–7.

Character Set ..................................................................................................................... 2–1 Valid Separators ................................................................................................................ 2–2 Figurative Constants ........................................................................................................2–5 Special-Register Definitions ..........................................................................................2–9 Special-Character Words ............................................................................................. 2–11 User-Defined Words ..................................................................................................... 2–13 Range of Values Permitted for Floating-Point Literals ......................................... 2–17

6–1. 6–2. 6–3. 6–4. 6–5.

Usage and Maximum Size of a Record Description ............................................... 6–1 Assigning Level-Numbers ............................................................................................. 6–4 Level-Numbers Associated with Data-Description Entries ................................. 6–4 Classes and Categories of Data Items .......................................................................6–7 Alignment Rules for Move Operation by Data Categories ................................. 6–10

7–1. 7–2. 7–3. 7–4. 7–5. 7–6. 7–7. 7–8. 7–9. 7–10. 7–11. 7–12.

COBOL74 and ALGOL Parameter Matching ........................................................... 7–32 Defining Items with the PICTURE Clause ............................................................... 7–39 Describing Elementary Items Using Symbols ........................................................ 7–41 Simple Insertion Editing Examples ........................................................................... 7–45 Special Insertion Editing Example ............................................................................. 7–46 Data Item Values and Results of Editing Sign Control Symbols ....................... 7–47 Floating Insertion Editing Examples ......................................................................... 7–48 Zero-Suppression and Replacement Editing Examples ...................................... 7–49 Data Categories and Editing Methods Allowed .................................................... 7–50 Editing Application of the PICTURE Clause ............................................................. 7–51 VALUE Clause Rules by Data Category ................................................................... 7–70 VALUE Clause Rules by Section ................................................................................. 7–71

8–1. 8–2. 8–3. 8–4. 8–5. 8–6. 8–7.

Binary Arithmetic Operators .........................................................................................8–7 Unary Arithmetic Operators ..........................................................................................8–7 Combination of Symbols in Arithmetic Expressions ............................................. 8–8 Meanings of Relational Operators ............................................................................. 8–17 Logical Operators and Their Meaning ...................................................................... 8–22 Combinations of Conditions, Logical Operators, and Parentheses ................. 8–24 Abbreviated Combined Relation Conditions .......................................................... 8–26

9–1. 9–2. 9–3.

Designating Subfiles for the AWAIT-OPEN Statement ........................................ 9–13 I/O Status Values for the AWAIT-OPEN Statement .............................................. 9–13 Parameter Mapping for Tasking Calls ....................................................................... 9–17

8600 0296–207

xvii

Tables

9–4. 9–5. 9–6. 9–7. 9–8. 9–9. 9–10. 9–11. 9–12. 9–13. 9–14. 9–15. 9–16.

WFL and COBOL74 Parameters .................................................................................9–18 Parameters for Bound and Host Programs .............................................................9–19 Close-File Dispositions for Sequential I/0 ............................................................... 9–32 Designating Subfiles to Close .................................................................................... 9–37 I/O Status Values for CLOSE Statement Completion .......................................... 9–40 Comparison of Sending and Receiving Items in MOVE Statements ............... 9–80 I/O Statements Allowed for Open Files with Sequential Organization........... 9–89 I/O Statements Allowed for Open Relative or Indexed Files ............................ 9–89 Designating Subfiles to Open .................................................................................... 9–93 I/O Status Values for OPEN Statement ................................................................... 9–95 Designating Subfiles to Respond ............................................................................. 9–117 Values for RESPOND Statement Completion ....................................................... 9–118 Validity of Operands for the SET Statement ........................................................ 9–133

12–1. 12–2.

Page Regions Established by the PAGE Clause ................................................... 12–10 Permissible Combinations in Format 3 Report-Group Description Entries ........................................................................................................................12–28

14–1.

Transmission Indicator Schedule ............................................................................ 14–28

15–1. 15–2.

15–4. 15–5. 15–6. 15–7. 15–8. 15–9.

Parameter Matching for Data Items Requiring Special Rules ............................ 15–3 Effect of SHARING Option and Library Initial State on CALL Statement .................................................................................................................. 15–10 SHARING Option and Library Initial State Effect on CANCEL Statement .................................................................................................................. 15–12 Effects of Setting the LIBACCESS Attribute ......................................................... 15–13 Meanings of SHARING Option Values .................................................................... 15–15 SHARING and TEMPORARY Compiler Control Option Combinations ............ 15–16 Alphanumeric Value Returned by the CURRENT_DATE Procedure ................ 15–21 Meaning of Character in Position 17 ........................................................................ 15–21 Meaning of Characters in Positions 18–21 ............................................................. 15–22

16–1.

Specific Descriptions for Internationalization Error Values .............................16–135

17–1. 17–2. 17–3. 17–4. 17–5. 17–6. 17–7.

Effects of the XDECS and XREFS Compiler Control Options.............................. 17–3 Effects of the NOXREFLIST Option ........................................................................... 17–3 Effects of the XREF and XREFFILES Options .......................................................... 17–4 Attribute Values for the Compiler Input File ......................................................... 17–14 Compiler Input Files ..................................................................................................... 17–15 Attribute Assignments for Compiler Output Files .............................................. 17–17 Effects of the SHARING Option ............................................................................... 17–41

A–1.

General Format Notation Components ..................................................................... A–2

C–1. C–2.

EBCDIC-to-ASCII Translation Chart .............................................................................. C–1 ASCII-to-EBCDIC Translation Chart ............................................................................ C–11

15–3.

xviii

8600 0296–207

Examples 1–1. 1–2. 1–3. 1–4. 1–5. 1–6.

Coding Paragraphs ........................................................................................................... 1–6 Coding Area A Entries ................................................................................................... 1–10 Coding Area B Entries for Readability........................................................................ 1–11 Coding Comment Lines ................................................................................................. 1–11 Coding Continuation Lines ........................................................................................... 1–13 Coding Debugging Lines............................................................................................... 1–14

3–1.

Setting the BDBASE Option ........................................................................................ 3–10

4–1.

Coding the IDENTIFICATION DIVISION ...................................................................... 4–2

5–1. 5–2. 5–3. 5–4.

CCSVERSION Not Specified ......................................................................................... 5–9 CCSVERSION Is Defined at RUN Time ....................................................................... 5–9 CCSVERSION Specified by ....................................................................... 5–10 Coding the ENVIRONMENT DIVISION ...................................................................... 5–34

6–1. 6–2. 6–3. 6–4.

Coding Elementary and Group Items ......................................................................... 6–3 Level-Number Construction for a Record ................................................................ 6–5 Defining a One-Dimensional Table ............................................................................ 6–11 Defining a Three-Dimensional Table ......................................................................... 6–12

7–1. 7–2. 7–3. 7–4. 7–5. 7–6. 7–7. 7–8. 7–9. 7–10.

Coding the LABEL RECORDS Clause ........................................................................ 7–13 Coding the VALUE OF Clause ...................................................................................... 7–17 Coding the DATA RECORDS Clause .......................................................................... 7–18 Effect of the BLANK WHEN ZERO Clause .............................................................. 7–29 Coding the GLOBAL Clause ........................................................................................ 7–30 Using the GLOBAL Compiler Option ........................................................................ 7–30 Coding the OWN Clause.............................................................................................. 7–37 Coding the TYPE Clause ............................................................................................... 7–61 Coding Condition-Names ............................................................................................ 7–75 Coding the WORKING-STORAGE SECTION............................................................ 7–78

8–1. 8–2. 8–3. 8–4. 8–5. 8–6. 8–7. 8–8.

Use of Declaratives ........................................................................................................ 8–4 Coding the DIV Function ................................................................................................ 8–9 Results of FORMATTED-SIZE Function ....................................................................8–10 Coding the MOD Function ........................................................................................... 8–12 Coding the OFFSET Function ....................................................................................... 8–13 Coding the REM Function............................................................................................. 8–13 Coding Multiple Function Calls in an Expression ...................................................8–14 Parentheses Restrictions in Simple Conditions ..................................................... 8–15

9–1.

Coding an AWAIT-OPEN WITH WAIT Statement .................................................. 9–13

8600 0296–207

xix

Examples

xx

9–2. 9–3. 9–4. 9–5. 9–6. 9–7. 9–8. 9–9. 9–10. 9–11. 9–12. 9–13. 9–14. 9–15. 9–16. 9–17. 9–18. 9–19. 9–20. 9–21. 9–22. 9–23. 9–24. 9–25. 9–26. 9–27. 9–28. 9–29. 9–30. 9–31. 9–32. 9–33. 9–34. 9–35. 9–36. 9–37.

Coding an AWAIT-OPEN WITH NO WAIT Statement ...........................................9–14 Coding an AWAIT-OPEN AVAILABLE Statement ...................................................9–14 Coding an AWAIT-OPEN...PARTICIPATE Statement .............................................9–14 Coding an AWAIT-OPEN...CONNECT-TIME-LIMIT Statement ............................9–14 Coding a CLOSE WITH WAIT Statement ................................................................ 9–38 Coding a CLOSE WITH NO WAIT Statement ......................................................... 9–38 Coding a CLOSE...ASSOCIATED-DATA Statement ............................................... 9–38 Coding a CLOSE...ASSOCIATED-DATA-LENGTH Statement .............................. 9–38 Closing Multiple Port Files .......................................................................................... 9–39 INSPECT TALLYING Statement with LEADING Option ........................................ 9–69 INSPECT TALLYING Statement with BEFORE INITIAL Option ........................... 9–69 INSPECT TALLYING Statement with LEADING BEFORE Option ....................... 9–69 INSPECT TALLYING Statement with FOR ALL REPLACING Option ................. 9–70 INSPECT REPLACING ALL Statement with BEFORE INITIAL Option ............... 9–70 INSPECT TALLYING REPLACING Statement .......................................................... 9–70 INSPECT...REPLACING Statement with Literals ..................................................... 9–71 INSPECT...REPLACING CHARACTERS Statement .................................................. 9–71 Coding an OPEN Statement........................................................................................ 9–88 Coding an OPEN WAIT Statement ............................................................................ 9–93 Coding an OPEN OFFER Statement .......................................................................... 9–93 Coding an OPEN NO WAIT Statement .................................................................... 9–94 Coding a RESPOND Statement for an Orderly Close Operation ..................... 9–118 Coding a RESPOND Statement That Requests a Dialogue ............................... 9–118 Coding a RESPOND Statement That Rejects an Open Request ...................... 9–118 Coding a RESPOND Statement That Uses Associated Data ............................ 9–119 Coding a RESPOND Statement with Multiple Files ............................................. 9–119 INPUT PROCEDURE IS and OUTPUT PROCEDURE IS Options........................ 9–145 Coding a Simple UNSTRING Statement ................................................................ 9–165 UNSTRING Statement Using the DELIMITED BY Option .................................. 9–165 UNSTRING Statement Using the DELIMITED BY ALL Option ......................... 9–166 UNSTRING Statement Using the WITH POINTER Option................................. 9–166 UNSTRING Statement Using Many Options ........................................................ 9–167 UNSTRING Statement Using the FOR Option...................................................... 9–167 Coding an UNSTRING Statement Using FOR, WITH POINTER Options........ 9–168 Sample Program Using Format 1 and 2 Examples .............................................. 9–168 Display from UNSTRING Program .......................................................................... 9–170

11–1. 11–2. 11–3.

Implicit Description of DEBUG-ITEM Special Register ......................................... 11–7 Debug Module Sample Program ............................................................................... 11–12 Debugging Output from Debug Module Sample Program ...............................11–13

12–1.

Sample Report Writer Program............................................................................... 12–36

14–1. 14–2.

Example Program for DCI Library Entry Point.........................................................14–5 Maintaining Associations of Physical Terminals with Queues......................... 14–18

15–1. 15–2. 15–3. 15–4. 15–5.

Calling a Library ............................................................................................................. 15–17 Calling a Library by Function ...................................................................................... 15–18 Substituting a Family Specification .......................................................................... 15–18 Requesting a Time Zone Name ................................................................................ 15–19 Calling the CURRENT_DATE Procedure ..................................................................15–20

8600 0296–207

Examples

16–1. 16–2. 16–3. 16–4. 16–5. 16–6. 16–7. 16–8. 16–9. 16–10. 16–11. 16–12. 16–13. 16–14. 16–15. 16–16. 16–17. 16–18. 16–19. 16–20. 16–21. 16–22. 16–23. 16–24. 16–25. 16–26. 16–27. 16–28. 16–29. 16–30.

Coding the Format 3 ACCEPT Statement .............................................................. 16–18 Coding the MOVE Statement for Internationalization ........................................ 16–19 Sample Data Declarations for Type Value Data Items ...................................... 16–30 Calling the CCSTOCCS_TRANS_TEXT Procedure ................................................ 16–33 Calling the CCSVSN_NAMES_NUMS Procedure ................................................. 16–35 Calling the CENTRALSTATUS Procedure .............................................................. 16–39 Calling the CNV_CURRENCYEDITTMP_DOUBLE_COB Procedure .................. 16–44 Calling the CNV_DISPLAYMODEL_COB Procedure ............................................ 16–46 Calling the CNV_FORMATDATETMP_COB Procedure....................................... 16–49 Calling the CNV_FORMATDATE_COB Procedure ................................................16–52 Calling the CNV_CURRENCYEDIT_DOUBLE_COB Procedure .......................... 16–55 Calling the CNV_FORMATTIMETMP_COB Procedure........................................ 16–58 Calling the CNV_FORMATTIME_COB procedure ................................................. 16–61 Calling the CNV_FORMSIZE Procedure.................................................................. 16–64 Calling the CNV_NAMES Procedure ....................................................................... 16–67 Calling the CNV_SYMBOLS Procedure ................................................................... 16–71 Calling the CNV_SYSTEMDATETIMETMP_COB Procedure ............................... 16–81 Calling the CNV_SYSTEMDATETIME_COB Procedure ....................................... 16–85 Calling the CNV_TEMPLATE_COB Procedure ...................................................... 16–88 Calling the CNV_VALIDATENAME Procedure ...................................................... 16–92 Calling the GET_CS_MSG Procedure ...................................................................... 16–95 Calling the MCP_BOUND_LANGUAGES Procedure ...........................................16–100 Calling the VALIDATE_NAME_RETURN_NUM Procedure ................................ 16–102 Calling the VALIDATE_NUM_RETURN_NAME Procedure ................................16–105 Calling the VSNCOMPARE_TEXT Procedure ....................................................... 16–110 Calling the VSNESCAPEMENT Procedure ............................................................ 16–114 Calling the VSNGETORDERINGFOR_ONE_TEXT Procedure ............................ 16–117 Calling the VSNINSPECT_TEXT Procedure ........................................................... 16–123 Calling the VSNTRANS_TEXT Procedure .............................................................. 16–129 Declaring Message Values ......................................................................................16–133

17–1. 17–2. 17–3.

Separate Compilation with the Host Title Given as a String ............................... 17–5 Separate Compilation with the Host Title File-Equated ....................................... 17–6 Understanding the GROUPMOVEWARN Option .................................................17–26

D–1. D–2. D–3. D–4. D–5. D–6. D–7. D–8. D–9.

Coding READ and WRITE Statements ....................................................................... D–1 Coding Indexed Files with Alternate Keys ............................................................... D–2 Coding OCCURS DEPENDING ON Phrase in WRITE FROM Statement ............ D–6 Coding the SORT Program with the USING and GIVING Options ..................... D–8 Coding MERGE Program with the USING and GIVING Options ........................ D–10 Coding Remote Files with Variable-Record Lengths ........................................... D–13 Coding PERFORM Program with the VARYING UNTIL Option ......................... D–14 Coding Remote Files .................................................................................................... D–15 Coding Tape Label Access with USE Routines ..................................................... D–17

8600 0296–207

xxi

Examples

xxii

8600 0296–207

Section 1 Program Structure Purpose This two-volume set provides a complete description of the implementation of COBOL74. To use this manual, you should be familiar with the general concepts of COBOL programming, a programming language based on the English language and, as such, composed of paragraphs, sentences, clauses, and words. The language is designed so that your source program is self-explanatory to someone who does not understand COBOL74. This volume provides the syntax and rules specific to COBOL74. Volume 2 contains the syntax for using COBOL74 to write application programs that interface with the following products: •

Advanced Data Dictionary System (ADDS)



Enterprise Database Server for ClearPath MCP



Transaction Server



Enterprise Database Server Transaction Processing System (TPS)



Screen Design Facility (SDF)

Audience The primary audience for this manual includes programmers and system analysts who are experienced in developing, maintaining, and reading COBOL programs. The secondary audience consists of technical support personnel and information systems management. A possible tertiary audience includes programmers who are learning COBOL, but the manual is not designed for this audience. To use this manual, you should be familiar with the general concepts of COBOL programming; a programming language based on the English language and, as such is composed of paragraphs, sentences, clauses, and words. The language is designed so that your source program is self-explanatory to someone who does not understand COBOL74.

8600 0296–207

1–1

Documentation Updates

Conventions Throughout this manual, Volume 2 refers to the COBOL ANSI-74 Programming Reference Manual, Volume 2: Product Interfaces, unless a different manual title is specified. This implementation of COBOL74 is based on, and is fully compatible with, the American National Standard programming language COBOL, X3.23-1974. Throughout this manual, extensions to the American National Standard for Programming Language COBOL, ANSI X3.23-1974 are identified as such with the phrase Extension to ANSI X3.23-1974 COBOL. The elements of the language are described in the order in which they are coded in a program. The IDENTIFICATION DIVISION is described first; the PROCEDURE DIVISION is described last. For a statement or a clause, individual elements are described in the order in which they are listed in the format. COBOL modules including the Report Writer, Debugging, Communication, Segmentation, and Inter-Program Communication modules are described in separate sections. The GENERALSUPPORT system library must be installed before you can use the features of the COBOL74 compiler described in this manual.

Acknowledgment Any organization wishing to reproduce this COBOL manual in whole or in part as the basis for an instruction manual or for any other purpose is free to do so. However, all such organizations are requested to reproduce this section as part of the introduction to the manual. Those using a short passage, as in a book, need not quote this entire preface. COBOL is an industry language and is not the property of any company or group of companies or of any organization or group of organizations. No warranty, expressed or implied, is made by any contributor or by the COBOL Committee as to the accuracy and functioning of the programming system and language. Moreover, no responsibility is assumed by any contractor or by the committee in connection therewith. Procedures have been established for the maintenance of COBOL. Inquiries concerning the procedures for proposing changes should be directed to the Executive Committee of the Conference on Data Systems Language.

1–2

8600 0296–207

Documentation Updates

The authors and copyright holders of the copyrighted material used herein have specifically authorized the use of this material, in whole or in part, in the COBOL specifications. These authors or copyright holders are the following: •

FLOW-MATIC (Trademark of Sperry Rand Corporation), Programming for the Univac R I and II, Data Automation Systems, copyrighted 1958, 1959 by Sperry Rand Corporation



IBM Commercial Translator, Form No. F28-8013, copyrighted 1959 by International Business Machines Corporation



FACT, DSI 27A5260-2760, copyrighted 1960 by Minneapolis–Honeywell

Such authorization extends to the reproduction and use of COBOL specifications in programming manuals or similar publications.

Documentation Updates This document contains all the information that was available at the time of publication. Changes identified after release of this document are included in problem list entry (PLE) 18839253. To obtain a copy of the PLE, contact your Unisys representative or access the current PLE from the Unisys Product Support Web site: http://www.support.unisys.com/all/ple/18839253

Note: If you are not logged into the Product Support site, you will be asked to do so.

What's New? New or Revised Information

Location

Added information about default value of the BINDINFO and LINEINFO compiler control option in subsequent releases.

Section 17:

Added information about deimplementing the MAKEHOST and SEPCOMP option in subsequent releases.

Section 17:

8600 0296–207

Control of the Compilation Process

Control of the Compilation Process

1–3

Source Program Components

Source Program Components A source program is code written in COBOL74 that the compiler accepts as input. When you compile the source program, the compiler verifies that your code follows the rules presented in this manual and translates the source program into an object program. The object program directs the computer to operate on the data. If the compiler indicates that your source program needs corrections, you can make the appropriate changes and then recompile it. The object program always reflects the source program you create.

Program Divisions A COBOL74 source program is divided into four parts called divisions. The divisions must appear in the following order: 1.

IDENTIFICATION DIVISION

2.

ENVIRONMENT DIVISION

3.

DATA DIVISION

4. PROCEDURE DIVISION A division header consists of the name of a division, the word DIVISION, and a period. Table 1–1 describes the purpose of each division. Table 1–1. Purpose of COBOL74 Divisions Division Name

Purpose of Division

IDENTIFICATION

Identifies and provides documentation about the source program.

ENVIRONMENT

Specifies the computer system and associates files with I/O devices.

DATA

Describes the structure of the data, the constants to be used, the intermediate storage areas, and any external data.

PROCEDURE

Instructs the computer to perform the steps necessary to solve the problem addressed by the source program. This division uses the data described in the DATA DIVISION.

Sections The ENVIRONMENT, DATA, and PROCEDURE DIVISIONs can be subdivided into sections. A section further identifies the purpose of a division. A section begins with a name that identifies the section. COBOL74 specifies the names of sections in the ENVIRONMENT and DATA DIVISIONs. You specify names of sections in the PROCEDURE DIVISION.

1–4

8600 0296–207

Source Program Components

A section header consists of the name of the section, the word SECTION and a period. A section continues with one or more successive paragraphs that follow the period. A section ends immediately before the next section, at the end of the division, or at the keywords END DECLARATIVES in the DECLARATIVES SECTION of the PROCEDURE DIVISION. Table 1–2 describes the sections associated with each division Table 1–2. Purpose of Sections Division Name

Section Name

Purpose of Section

IDENTIFICATION

None

Not applicable

ENVIRONMENT

CONFIGURATION

Specifies computer equipment

INPUT-OUTPUT

Associates files with specific devices

FILE

Describes the record structure of files

DATA-BASE

Describes one or more databases that can be used by the COBOL program

WORKINGSTORAGE

Describes intermediate data items

LOCAL-STORAGE

Describes data to be either passed or received as parameters to an external procedure

LINKAGE

Describes data items to be referenced by the calling program and the called program

COMMUNICATION

Describes the data items in the source program that serve as the interface between the data communications interface (DCI) library and the program

REPORT

Describes the contents and format of generated reports for the Report Writer

User defined

Groups paragraphs into sections that you define

DATA

PROCEDURE

Note: DATA-BASE and LOCAL-STORAGE are extensions to ANSI X3.23-1974 COBOL.

Paragraphs In the IDENTIFICATION and ENVIRONMENT DIVISIONs, a paragraph begins with a header that identifies the paragraph. A paragraph header consists of a reserved word followed by a period. The paragraph continues with one or more successive entries. In the PROCEDURE DIVISION, a paragraph begins with a user-defined word called a paragraph-name. It is followed by a period and optionally one or more entries.

8600 0296–207

1–5

Source Program Components

A paragraph ends immediately before the next paragraph header or section name, at the end of the division, or at the keywords END DECLARATIVES in the DECLARATIVES SECTION of the PROCEDURE DIVISION. Example 1–1 shows examples of paragraphs in the IDENTIFICATION, ENVIRONMENT, and PROCEDURE DIVISIONs. 010000 IDENTIFICATION DIVISION. 010050*The PROGRAM-ID paragraph header is a reserved word. 010100 PROGRAM-ID. GUEST-CREDIT-AUTHORIZATION. 100000 ENVIRONMENT DIVISION. 100050 CONFIGURATION SECTION. 100150*The SOURCE-COMPUTER paragraph header is a reserved word. 100200 SOURCE-COMPUTER. MICROA. 100250 INPUT-OUTPUT SECTION. 100300*The FILE-CONTROL paragraph header is a reserved word. 100350 FILE-CONTROL. : 200000 PROCEDURE DIVISION. 200050* You define paragraph-names in the PROCEDURE DIVISION. 200100 MAIN-PARAGRAPH. : Example 1–1. Coding Paragraphs

Sentences A sentence consists of one or more statements. You must end a sentence with a period. A sentence can be one of the following three types: •

A compiler-directing sentence that directs the compiler to take a specific action during the compilation process.



A conditional sentence that tests a truth value and specifies an action depending on the result of the test.



An imperative sentence that specifies an unconditional action to be taken.

Example The following is an example of a conditional sentence: IF BALANCE LESS THAN ZERO PERFORM PROCESS-DEBIT ELSE NEXT SENTENCE. For More Information For more information about types of sentences, refer to Section 8, “PROCEDURE DIVISION Concepts.”

1–6

8600 0296–207

Line Layout

Statements A statement is a syntactically valid combination of words and symbols beginning with a COBOL74 verb. A statement ends whenever the compiler detects a new verb or a period.

Clauses, Phrases, and Options A clause is a set of consecutive COBOL74 words that represents a valid portion of a statement or entry. A phrase is a set of consecutive COBOL74 words that represents a valid portion of a statement, entry, or clause. In this manual, optional phrase and clauses are often referred to as options.

Words A word is a string of characters that form a valid COBOL74 word for creating valid phrases, clauses, statement, sentences, paragraphs, sections, and divisions. For More Information For a complete description of the rules for forming words, refer to Section 2, “Language Elements.”

Line Layout The compiler expects the components of your source program to appear in specific areas along a line of code. Each line has 80 positions, which are grouped into five areas that make up the line format (also called the reference format), as shown in Figure 1–1.

Figure 1–1. Line Format Table 1–3 shows the columns associated with each area, the name of the area, and the program components that can begin in that area.

8600 0296–207

1–7

Line Layout

Table 1–3. Placement of Source Program Component within Areas Columns

Name

Acceptable Entries

1–6

Sequence area

Sequence number

7

Indicator area

Asterisk (*), slash (/), D, hyphen (–), or dollar sign ($)

8–11

Area A

• • • • • • • • • •

12–72

Area B

73–80

Identification area

Division header Section header Paragraph header File description (FD) entry Sort merge description (SD) entry Level numbers DECLARATIVES keyword END DECLARATIVES keyword Sentences Level numbers other than 01 or 77

Comment entries

For More Information For information on using the FREE compiler option to remove the margin restrictions, refer to “FREE” in Section 17, “Control of the Compilation Process.”

Columns 1–6: Sequence Area The sequence area contains a 6-digit sequence number that is incremented with each successive line. These numbers are generated automatically.

Column 7: Indicator Area The indicator area is blank or contains one of five characters that indicate a special purpose for the line. Leave column 7 blank, unless there is a programmatic need to use one of the following listed characters in that location. •

An asterisk (*) indicates the line is a comment line.



A slash (/) indicates the line is a comment line and causes the printer to eject a page and print the comment at the top of the source listing.



The letter D indicates the line is a debugging line.



A hyphen (–) indicates the line is a continuation line.



A dollar sign ($) indicates the line is a compiler control record.



A space ( ) indicates the line is a normal COBOL74 source image.

When the FREE compiler control option is

1–8

8600 0296–207

Line Layout



Set, any character in column 7 other than an asterisk, slash, hyphen, dollar sign, or space is treated as part of the source image.



Reset, any character in column 7 other than an asterisk, slash, hyphen, or dollar sign is treated as a space.

For More Information •

For information about the types of lines, see “Special-Purpose Lines” later in this section.



For information on the compiler control option, refer to “FREE” in Section 17, “Control of the Compilation Process.”

Columns 8–11: Area A Division, section, and paragraph headers, level indicators, the level numbers 01 and 77, and the keywords for declaratives must begin in area A. You can begin your entry anywhere within area A. It is acceptable for your entry to extend into area B. The rules for forming division and section headers are as follows: •

Enter the division or section name in area A.



Follow the name by at least one space.



Enter DIVISION or SECTION, whichever is appropriate.



End the entry with a period.

The rules for forming paragraph headers are as follows: •

Enter the name of the paragraph.



Follow the name with a period.

The rules for forming the indicators of a file description (FD) or sort-merge description (SD) entry or a level-number 01 or 77 entry are as follows: •

Enter FD, SD, 01, or 77, whichever is appropriate.



Follow the entry with the appropriate associated name and descriptive information.

The rules for forming declarative keywords are as follows: •

Enter DECLARATIVES. on a line by itself at the beginning of the DECLARATIVES SECTION of the PROCEDURE division.



Enter END DECLARATIVES. on a line by itself at the end of the DECLARATIVES SECTION.

Example Example 1–2 shows coding of area A entries. 000100 IDENTIFICATION DIVISION. 000200 ENVIRONMENT DIVISION.

8600 0296–207

1–9

Line Layout

000300 000400 000500 000600 001000 001100 001200 001400 001800 001900 003000 003100 003300 003400

CONFIGURATION SECTION. SOURCE-COMPUTER. MICROA. INPUT-OUTPUT SECTION. FILE-CONTROL. : DATA DIVISION. FILE SECTION. FD GUEST-FILE : 01 NAME-RECORD. : WORKING-STORAGE SECTION. 77 EOF-FLAG. : PROCEDURE DIVISION. DECLARATIVES. : END DECLARATIVES. MAIN SECTION. : Example 1–2. Coding Area A Entries

For More Information •

For information about level numbers, refer to Section 7, “DATA DIVISION.”



For information about declaratives, refer to Section 8,“PROCEDURE DIVISION Concepts.”

Columns 12–72: Area B The bulk of your code, including sentences, statements, clauses, and many levelnumber entries, begin in area B. Your entry can begin anywhere within area B. In the DATA DIVISION, all level numbers other than 01 and 77 can begin anywhere in area A or B. The first sentence or entry in a paragraph begins either on the same line as the paragraph name or in area B of the next nonblank line that is not a comment line. Additional sentences begin after the previous sentence in area B of the same line or in area B of the next nonblank line that is not a comment line. For readability, begin all level numbers other than 01 or 77 in area B and indent each successively higher level number two to four positions. In addition, define level numbers with an increment value greater than one so that it is possible to insert new levels between two levels, if the need arises.

1–10

8600 0296–207

Special-Purpose Lines

Example Example 1–3 shows the use of indentation to make your coding more readable. Subordinate entries are indented four spaces. For example, MONTH, DAY, and YEAR are all elements of DATER. 010000* Indentation improves the readability of your program. 010050* 010100 01 INPUT-RECORD. 100350 03 DATER 100400 05 MONTH PIC 99. 100450 05 DAY PIC 99. 100500 05 YEAR PIC 99. 100550 03 FILLER PIC X(33). 100600 66 IN-DATE RENAMES MONTH THRU YEAR. Example 1–3. Coding Area B Entries for Readability

Columns 73–80: Identification Area This area is an optional area. You can use it for documentation purposes.

Special-Purpose Lines Special purpose lines are lines that have a special character in the indicator area (column 7) or are blank. These include comment lines, continuation lines, debugging lines, compiler control options, and blank lines.

Comment Lines A comment line is any line with either an asterisk (*) or a slash (/) in the indicator area (column 7) of the line. A comment line can appear anywhere in a source program and can use any combination of characters from the character set of the computer, not just the characters in the COBOL74 character set. You can use successive comment lines. If you use the slash character to indicate a comment, the printer ejects a page before printing the comment on the output listing of the compiler. Example Example 1–4 shows the use of comment lines. 100100 IDENTIFICATION DIVISION. 100200* The purpose of this program is to... 100300* Notice that comments can use lowercase letters. 100400 PROGRAM-ID. GUEST-CREDIT-AUTHORIZATION. 100500/ This comment is printed at the top of a new page. 100600 ENVIRONMENT DIVISION. Example 1–4. Coding Comment Lines

8600 0296–207

1–11

Special-Purpose Lines

Continuation Lines A continuation line is a line that is continued from a previous line. You indicate a continuation line with a hyphen (–) in the indicator area (column 7). The hyphen means that the first nonblank character in area B (columns 12–72) of the continuation line follows the last nonblank character of the preceding line, with no spaces inserted. You can use successive continuation lines. Area A (columns 8–11) of a continuation line must be blank. The compiler determines the length of the continuation line as follows: •

For nonnumeric literals, the first nonblank character in Area B to the end of Area B



For other strings, the first nonblank character in Area B to the last nonblank character in Area B

If no hyphen is present in the indicator area of a line, the compiler assumes that the last character in the preceding line is followed by a space. The rules for using a continuation line with a nonnumeric literal (which must begin with a quotation mark) or an undigit literal (which must begin with a commercial at sign) are as follows: •

Use all 72 positions on the line to be continued. All spaces at the end of the line are considered to be part of the literal.



Do not close the literal in column 72 with a quotation mark for the nonnumeric literal or a commercial at sign (@) for the undigit literal because doing so will delimit the literal and prevent it from being continued.



Enter as the first nonblank character in area B a quotation mark for the nonnumeric literal or a commercial at sign for the undigit literal. The literal continues with the character immediately after the quotation mark or a commercial at sign.



Limit the length of a nonnumeric literal to 160 characters. If the length is greater than 160 characters, but less than 262 characters, a syntax error is generated. If the length exceeds 261 characters, the compilation process might terminate abnormally without providing a syntax error.

Example Example 1–5 shows coding of continuation lines. 100150*Line 100200 continues the clause begun on the preceding line. 100100 SELECT GUEST-FILE ASSIGN TO DISK OR 100200GANIZATION IS SEQUENTIAL. . . 100700* Line 100900 continues a nonnumeric literal. 100800 77 HEADER-LINE PIC X(60) VALUE IS " JANUARY FEBRUARY 100900" MARCH APRIL MAY JUNE ". 101000 101500*Line 102000 continues an undigit literal. 101000 77 HEX-LITERAL PIC X(30) VALUE IS @AAAAAAAAAABBBBBBBBBBCCC

1–12

8600 0296–207

Special-Purpose Lines

102000@CCCCCC@. 102300 102500* The first quote continues the nonnumeric literal; the second 102550* quote ends the literal. 102600 01 WARNING MESSAGE PIC X(24) VALUE IS "WRONG ENTRY FOR THIS KEY 102700"". Example 1–5. Coding Continuation Lines

Debugging Lines A debugging line is any line with a D in the indicator area (column 7) of the line. A debugging line with spaces in columns 8 through 72 is considered to be the same as a blank line. You can enter a debugging line anywhere after the OBJECT-COMPUTER paragraph. The debugging module is activated when you specify the WITH DEBUGGING MODE clause in the SOURCE-COMPUTER paragraph. If you do not activate the debugging module, the compiler treats a debugging line like a comment line. Therefore, you should make sure that your program is syntactically correct when the debugging lines are considered to be comment lines. You can use successive debugging lines and can continue debugging lines; however, each continuation line must contain a D in the indicator area, and character strings cannot be continued across multiple lines. Example Example 1–6 shows the use of debugging lines. 010000 IDENTIFICATION DIVISION. 100000 ENVIRONMENT DIVISION. 100100 SOURCE-COMPUTER. MICROA WITH DEBUGGING MODE . . 100600 WORKING STORAGE SECTION. 100700D77 PERFORMANCE-COUNT PIC 9(4). 100800D77 BAD-RECORDS PIC 9(4). 100900D77 RATIO PIC 9(4).99. . . 101000 PROCEDURE DIVISION. 102000 OPEN-IT. 102100 OPEN INPUT GUEST-FILE. 103000D MOVE ZEROS TO PERFORMANCE-COUNT, BAD-RECORDS, RATIO. 104000 READ-IT. 104100 READ GUEST-FILE AT END GO TO FINISH-IT. 105000D ADD 1 TO PERFORMANCE-COUNT. 106000D IF IN-KEY NOT NUMERIC ADD 1 TO BAD-RECORDS. .

8600 0296–207

1–13

Special-Purpose Lines

. 107000 GO TO READ-IT. 108000 FINISH-IT. 108100 CLOSE GUEST-FILE. 109000D DIVIDE PERFORMANCE-COUNT BY BAD-RECORDS GIVING RATIO. . . Example 1–6. Coding Debugging Lines For More Information •

For information about the WITH DEBUGGING MODE clause, refer to Section 4, “IDENTIFICATION DIVISION”.



For information about the debug module, refer to Section 11, “Debugging.”

Compiler Control Options A compiler control option is any line with a dollar sign ($) in the indicator area (column 7) of the line. This line specifies compiler control options to use during the compilation process. For More Information For a discussion of the available compiler control options and their uses, refer to Section 17, “Control of the Compilation Process”.

Blank Lines A blank line is a line that has no entries in the indicator area, area A, or area B. You can use a blank line anywhere in the source program except immediately preceding a continuation line.

1–14

8600 0296–207

Section 2 Language Elements This section describes the following elements used to form the components of a source program: •

Character set



Separators



Character strings

Character Set The most basic and indivisible unit of the COBOL74 language is the character. The set of characters you use to write COBOL74 programs includes the letters of the alphabet, digits, and special characters. The character set consists of 52 characters, including the 51 characters specified in the ANSI-74 standard plus the commercial at sign (@), which is an extension to ANSI X3.23-1974 COBOL. You link these individual characters together to form character strings and separators and you link character strings and separators to form a source program. Table 2–1 shows the COBOL74 character set. Table 2–1. Character Set Character

Meaning

Character

Meaning

0 through 9

Digit

A through Z

Letter

Space or blank

+

Plus sign



Minus sign or hyphen

*

Asterisk

/

Virgule, or slash

=

Equal sign

$

Dollar sign

,

Comma or decimal point

;

Semicolon

.

Period or decimal point

"

Quotation mark

(

Left parenthesis

)

Right parenthesis

>

Greater than sign