Cobol400 Reference
Cobol400 Reference
Before using this information and the product it supports, be sure to read the general information under
Notices on page xv.
First Edition (June 1994)
This edition applies to the IBM* ILE* COBOL/400* licensed program (Program 5763-CB1), Version 3 Release 0 Modifi-
cation 5, and to all subsequent releases and modifications until otherwise indicated in new editions. Make sure you
are using the proper edition for the level of the product.
Order publications through your IBM representative or the IBM branch serving your locality. Publications are not
stocked at the address given below.
A form for readers' comments is provided at the back of this publication. If the form has been removed, you can
address your comments to:
IBM Canada Ltd. Laboratory
Information Development
2G/345/1150/TOR
1150 Eglinton Avenue East
North York, Ontario, Canada M3C 1H7
You can also send your comments by facsimile (attention: RCF Coordinator), or you can send your comments elec-
tronically to IBM. See "communicating Your Comments" for a description of the methods. This page immediately
precedes the Readers' Comment Form at the back of this publication.
When you send information to IBM, you grant IBM a non-exclusive right to use or distribute the information in any way
it believes appropriate without incurring any obligation to you.
Copyright International Business Machines Corporation 1994. All rights reserved.
Note to U.S. Government Users Documentation related to restricted rights Use, duplication or disclosure is
subject to restrictions set forth in GSA ADP Schedule Contract with IBM Corp.
IBM is a registered trademark of International Business Machines Corporation, Armonk, N.Y.
Contents
Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Programming Interface Information . . . . . . . . . . . . . . . . . . . . . . . . . xv
Trademarks and Service Marks . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
About This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Who Should Use this Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
COBOL/400 Syntax Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii
How to Read the Syntax Diagrams . . . . . . . . . . . . . . . . . . . . . . . . xix
IBM Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
Documentary Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
Obsolete Language Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
Industry Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
Chapter 1. COBOL Language Structure . . . . . . . . . . . . . . . . . . . . . . 1
Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Character-Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
COBOL Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
User-Defined Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
System-Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Optional Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Special Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Figurative Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Special Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Boolean Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Nonnumeric Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Numeric Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
PICTURE Character-Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Separators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Rules for Separators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Sections and Paragraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Clauses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Sentences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Reference Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Sequence Number Area (Columns 1 through 6) . . . . . . . . . . . . . . . . . . 16
Indicator Area (Column 7) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Area A (Columns 8 through 11) . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Division Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Section Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Paragraph Header or Paragraph Name . . . . . . . . . . . . . . . . . . . . . 18
Level Indicator (FD and SD) or Level-Number (01 and 77) . . . . . . . . . . 18
DECLARATIVES and END DECLARATIVES . . . . . . . . . . . . . . . . . . 18
Area B (Columns 12 through 72) . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Entries, Sentences, Statements, Clauses . . . . . . . . . . . . . . . . . . . . 19
Copyright IBM Corp. 1994 iii
Continuation Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Area A or Area B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Level-Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Comment Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Debugging Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Blank Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Pseudo-Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Methods of Data Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Qualification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
References to Data Division Names . . . . . . . . . . . . . . . . . . . . . . 21
References to Procedure Division Names . . . . . . . . . . . . . . . . . . 22
References to COPY Libraries . . . . . . . . . . . . . . . . . . . . . . . . . 22
Qualification Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Reference Modification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Evaluation of Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Range Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Restrictions on Reference Modification . . . . . . . . . . . . . . . . . . . . 25
Subscripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Data Attribute Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Transfer of Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Chapter 2. COBOL Program Structure . . . . . . . . . . . . . . . . . . . . . . 29
Identification Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Coding Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
PROGRAM-ID Paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Optional Paragraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Environment DivisionConfiguration Section . . . . . . . . . . . . . . . . . . . . 32
Coding Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
SOURCE-COMPUTER Paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . 34
OBJECT-COMPUTER Paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . 35
SPECIAL-NAMES Paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Coding Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
ALPHABET Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
CLASS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
CURRENCY SIGN Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
DECIMAL-POINT Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
CONSOLE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
CURSOR Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
CURSOR Clause Considerations . . . . . . . . . . . . . . . . . . . . . . . . . 47
CRT STATUS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
CRT STATUS Clause Considerations . . . . . . . . . . . . . . . . . . . . . . 47
Chapter 3. Environment DivisionInput-Output Section . . . . . . . . . . 51
File Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Database Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Device Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
DDM Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Save Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Paragraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
FILE-CONTROL Paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
SELECT Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
ASSIGN Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
RESERVE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
ORGANIZATION Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
iv COBOL/400 Reference
ACCESS MODE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Data Organization and Access Modes . . . . . . . . . . . . . . . . . . . . . . 63
Data Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Access Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Relationship Between Data Organizations and Access Modes . . . . . . 65
RECORD KEY Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
RELATIVE KEY Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
FILE STATUS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
I-O-CONTROL Paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
RERUN Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
SAME AREA Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
SAME RECORD AREA Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
SAME SORT AREA Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
SAME SORT-MERGE AREA Clause . . . . . . . . . . . . . . . . . . . . . . . . 76
MULTIPLE FILE TAPE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
COMMITMENT CONTROL Clause . . . . . . . . . . . . . . . . . . . . . . . . . 77
Chapter 4. Data Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Data Division Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
File Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Working-Storage Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Linkage Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
ADDRESS OF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
ADDRESS OF Special Register . . . . . . . . . . . . . . . . . . . . . . . . 82
Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
File Data (External Data) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Program Data (Internal Data) . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Data Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Levels of Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Levels of Data in a Record Description Entry . . . . . . . . . . . . . . . . 84
Special Level-Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Indentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Classes and Categories of Data . . . . . . . . . . . . . . . . . . . . . . . . . 87
Alignment Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Standard Data Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Character-String and Item Size . . . . . . . . . . . . . . . . . . . . . . . . 89
Signed Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Operational Signs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Editing Signs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Chapter 5. Data DivisionFile and Sort Description Entries . . . . . . . . 91
File Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
BLOCK CONTAINS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
RECORD CONTAINS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
LABEL RECORDS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
VALUE OF Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
DATA RECORDS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
LINAGE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
LINAGE-COUNTER Special Register . . . . . . . . . . . . . . . . . . . . 104
CODE-SET Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Chapter 6. Data DivisionData Description Entry . . . . . . . . . . . . . 107
Level-Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
BLANK WHEN ZERO Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Contents v
JUSTIFIED Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
LIKE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Rules and Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
OCCURS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Table Handling Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Table Handling Considerations . . . . . . . . . . . . . . . . . . . . . . . . 116
Table Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Table References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Fixed-Length Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
ASCENDING/DESCENDING KEY Phrase . . . . . . . . . . . . . . . . . 119
INDEXED BY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Variable-Length Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
OCCURS DEPENDING ON Clause . . . . . . . . . . . . . . . . . . . . . 122
Subscripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Subscripting Using Integers or Data-Names . . . . . . . . . . . . . . . . 124
Subscripting Using Index-Names (Indexing) . . . . . . . . . . . . . . . . 124
Restrictions on Subscripting . . . . . . . . . . . . . . . . . . . . . . . . . 126
PICTURE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Symbols Used in the PICTURE Clause . . . . . . . . . . . . . . . . . . . . 126
Character-String Representation . . . . . . . . . . . . . . . . . . . . . . . . 130
Data Categories and PICTURE Rules . . . . . . . . . . . . . . . . . . . . . 130
PICTURE Clause Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Simple Insertion Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Special Insertion Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Fixed Insertion Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Floating Insertion Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Zero Suppression and Replacement Editing . . . . . . . . . . . . . . . . 137
REDEFINES Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
REDEFINES Clause Considerations . . . . . . . . . . . . . . . . . . . . 139
REDEFINES Clause Examples . . . . . . . . . . . . . . . . . . . . . . . 141
Undefined Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
RENAMES Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
SIGN Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
SYNCHRONIZED Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
USAGE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Computational Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
DISPLAY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
INDEX Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
POINTER Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Pointer Alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
VALUE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Chapter 7. Procedure Division . . . . . . . . . . . . . . . . . . . . . . . . . 159
The Procedure Division Header . . . . . . . . . . . . . . . . . . . . . . . . . . 160
The USING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Declaratives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Sample Procedure Division Statements . . . . . . . . . . . . . . . . . . . 164
Arithmetic Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Conditional Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Simple Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Class Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
vi COBOL/400 Reference
Condition-Name Condition . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Relation Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Comparison of Numeric and Nonnumeric Operands . . . . . . . . . . . 173
Sign Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Switch-Status Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Complex Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Negated Simple Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Combined Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Abbreviated Combined Relation Conditions . . . . . . . . . . . . . . . . 180
Statement Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Imperative Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Delimited Scope Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Explicit Scope Terminators . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Implicit Scope Terminators . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Compiler-Directing Statements . . . . . . . . . . . . . . . . . . . . . . . . . 185
Statement Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Common Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
CORRESPONDING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . 186
GIVING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
ROUNDED Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
SIZE ERROR Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Arithmetic Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Arithmetic Statement Operands . . . . . . . . . . . . . . . . . . . . . . . 189
Data Manipulation Statements . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Input-Output Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Common Processing Facilities . . . . . . . . . . . . . . . . . . . . . . . . 191
DB-FORMAT-NAME Special Register . . . . . . . . . . . . . . . . . . . . 195
Procedure Branching Statements . . . . . . . . . . . . . . . . . . . . . . . . 195
Chapter 8. Procedure Division Statements . . . . . . . . . . . . . . . . . . 197
ACCEPT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Data Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
System Information Transfer . . . . . . . . . . . . . . . . . . . . . . . . . 199
DATE, DAY, and TIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Local Data Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Format 5 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Attribute Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Attribute Data Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Workstation I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
AT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
FROM CRT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
MODE IS BLOCK Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
ON EXCEPTION Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
END-ACCEPT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
WITH Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
AUTO (AUTO-SKIP) Phrase . . . . . . . . . . . . . . . . . . . . . . . . . 213
BELL (BEEP) Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
BLINK Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
FULL (LENGTH-CHECK) Phrase . . . . . . . . . . . . . . . . . . . . . . 213
HIGHLIGHT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
REQUIRED (EMPTY-CHECK) Phrase . . . . . . . . . . . . . . . . . . . 213
REVERSE-VIDEO Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Contents vii
SECURE (NO-ECHO) Phrase . . . . . . . . . . . . . . . . . . . . . . . . 214
UNDERLINE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
RIGHT-JUSTIFY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
SPACE-FILL Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
TRAILING-SIGN Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
UPDATE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
ZERO-FILL Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Phrases Syntax Checked Only . . . . . . . . . . . . . . . . . . . . . . . . 215
Format 7 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Extended ACCEPT and Extended DISPLAY Considerations . . . . . . . . 215
Number of Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Screen Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Release Availability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Subscripting and Reference Modification . . . . . . . . . . . . . . . . . . 217
Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
DBCS Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Combinations of Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Display File QDLBACCDSP . . . . . . . . . . . . . . . . . . . . . . . . . 218
Remote Workstations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Differences from COBOL/2 Processing . . . . . . . . . . . . . . . . . . . 218
ACQUIRE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
ADD Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
ROUNDED Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
SIZE ERROR Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
CORRESPONDING Phrase (Format 3) . . . . . . . . . . . . . . . . . . . 223
END-ADD Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
ALTER Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Segmentation Information . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
CALL Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
BY REFERENCE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
BY CONTENT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
ON EXCEPTION Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
NOT ON EXCEPTION Phrase . . . . . . . . . . . . . . . . . . . . . . . . 230
ON OVERFLOW Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
END-CALL Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Program Termination Statements . . . . . . . . . . . . . . . . . . . . . . 231
CALL Statement Considerations . . . . . . . . . . . . . . . . . . . . . . . . 232
Call by Identifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Length of Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
OS/400 Graphics Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
CANCEL Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
CLOSE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
CLOSE Statement Considerations . . . . . . . . . . . . . . . . . . . . . . 237
COMMIT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
COMPUTE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
ROUNDED Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
SIZE ERROR Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
END-COMPUTE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
CONTINUE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
DELETE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
DELETE Statement Considerations . . . . . . . . . . . . . . . . . . . . . 245
DUPLICATES Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
viii COBOL/400 Reference
DISPLAY Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Local Data Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Format 3 Extended DISPLAY Statement . . . . . . . . . . . . . . . . . 253
AT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
UPON CRT/CRT-UNDER Phrase . . . . . . . . . . . . . . . . . . . . . . 256
MODE IS BLOCK Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
WITH Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
BELL (BEEP) Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
The BLANK Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
BLINK Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
HIGHLIGHT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
REVERSE-VIDEO Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . 257
SIZE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
UNDERLINE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Phrases that are Syntax Checked Only . . . . . . . . . . . . . . . . . . . 258
Format 3 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
DIVIDE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
ROUNDED Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
REMAINDER Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
SIZE ERROR Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
END-DIVIDE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
DROP Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
ENTER Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
EVALUATE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
END-EVALUATE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
Determining Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
Comparing Selection Subjects and Objects . . . . . . . . . . . . . . . . 270
Executing the EVALUATE Statement . . . . . . . . . . . . . . . . . . . . 271
EXIT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
EXIT PROGRAM Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
GOBACK Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
GO TO Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Unconditional GO TO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Conditional GO TO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Altered GO TO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
IF Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
END-IF Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Transferring Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Nested IF Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
INITIALIZE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
REPLACING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
INITIALIZE Statement Rules . . . . . . . . . . . . . . . . . . . . . . . . . 280
INSPECT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Comparison Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
INSPECT Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
TALLYING Phrase (Formats 1 and 3) . . . . . . . . . . . . . . . . . . . . 286
REPLACING Phrase (Formats 2 and 3) . . . . . . . . . . . . . . . . . . 286
BEFORE and AFTER Phrases (All Formats) . . . . . . . . . . . . . . . . 287
CONVERTING Phrase (Format 4) . . . . . . . . . . . . . . . . . . . . . . 287
INSPECT Statement Examples . . . . . . . . . . . . . . . . . . . . . . . 288
MERGE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
ASCENDING/DESCENDING KEY Phrase . . . . . . . . . . . . . . . . . 291
COLLATING SEQUENCE Phrase . . . . . . . . . . . . . . . . . . . . . . 292
USING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Contents ix
GIVING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
OUTPUT PROCEDURE Phrase . . . . . . . . . . . . . . . . . . . . . . . 294
MOVE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
Elementary Moves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
Group Moves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
WHEN-COMPILED Special Register . . . . . . . . . . . . . . . . . . . . 300
MULTIPLY Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
ROUNDED Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
SIZE ERROR Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
END-MULTIPLY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
OPEN Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Sequential Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Indexed and Relative Files . . . . . . . . . . . . . . . . . . . . . . . . . . 304
Transaction Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
OPEN Statement Considerations . . . . . . . . . . . . . . . . . . . . . . . . 305
OPEN Statement Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
PERFORM Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Basic PERFORM Statement . . . . . . . . . . . . . . . . . . . . . . . . . 312
PERFORM with TIMES Phrase . . . . . . . . . . . . . . . . . . . . . . . 315
PERFORM with UNTIL Phrase . . . . . . . . . . . . . . . . . . . . . . . . 315
PERFORM with VARYING Phrase . . . . . . . . . . . . . . . . . . . . . 316
Varying Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Varying One Identifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Varying Two Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
Varying Three Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
Varying More Than Three Identifiers . . . . . . . . . . . . . . . . . . . . 324
Varying Phrase Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
READ Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
Sequential Access Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
Random Access Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Dynamic Access Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Multiple Record Processing . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Multivolume Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
READ Statement Considerations . . . . . . . . . . . . . . . . . . . . . . 330
READ Statement Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
Transaction Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
RELEASE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
RETURN Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
AT END Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
END-RETURN Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
REWRITE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
Reusing a Logical Record . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
REWRITE Statement Considerations . . . . . . . . . . . . . . . . . . . . 352
DUPLICATES Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
Sequential Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
Indexed Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
Relative Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
Transaction Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
ROLLBACK Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
SEARCH Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
AT END/WHEN Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
END-SEARCH Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
Serial Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
VARYING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
x COBOL/400 Reference
WHEN Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
Binary Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
WHEN Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Search Statement Considerations . . . . . . . . . . . . . . . . . . . . . . 366
SEARCH Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
SET Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Format 1: TO Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Format 2: UP BY/DOWN BY Phrase . . . . . . . . . . . . . . . . . . . . 371
Format 3: ON/OFF Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Format 4: TO TRUE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . 372
Format 5: Pointer Data Item . . . . . . . . . . . . . . . . . . . . . . . . . 372
SORT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
ASCENDING/DESCENDING KEY Phrase . . . . . . . . . . . . . . . . . 375
DUPLICATES Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
COLLATING SEQUENCE Phrase . . . . . . . . . . . . . . . . . . . . . . 376
USING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
INPUT PROCEDURE Phrase . . . . . . . . . . . . . . . . . . . . . . . . 376
GIVING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
OUTPUT PROCEDURE Phrase . . . . . . . . . . . . . . . . . . . . . . . 378
START Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
KEY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
INVALID KEY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
END-START Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Indexed Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Relative Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
START Statement Considerations . . . . . . . . . . . . . . . . . . . . . . 381
STOP Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
STRING Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
DELIMITED BY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
INTO Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
POINTER Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
ON OVERFLOW Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
END-STRING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Data Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
STRING Statement Example . . . . . . . . . . . . . . . . . . . . . . . . . 392
SUBTRACT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
ROUNDED Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
SIZE ERROR Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
CORRESPONDING Phrase (Format 3) . . . . . . . . . . . . . . . . . . . 397
END-SUBTRACT Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
UNSTRING Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
DELIMITED BY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
INTO Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
POINTER Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
TALLYING IN Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
ON OVERFLOW Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
END-UNSTRING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Data Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
UNSTRING Statement Example . . . . . . . . . . . . . . . . . . . . . . . 403
WRITE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Sequential Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
ADVANCING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
END-OF-PAGE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
END-WRITE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
Contents xi
Multivolume Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
Indexed and Relative Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
INVALID KEY Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
END-WRITE Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
Relative Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
WRITE Statement Considerations . . . . . . . . . . . . . . . . . . . . . . 414
Chapter 9. Compiler-Directing Statements . . . . . . . . . . . . . . . . . . 427
*CONTROL (*CBL) Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
*CONTROL (*CBL) and the COPY Statement . . . . . . . . . . . . . . . 428
COPY Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
SUPPRESS Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
REPLACING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
Replacement and Comparison Rules . . . . . . . . . . . . . . . . . . . . 432
Format 2 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
General Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
Data Structures Generated . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
Format (Record) Level Structures . . . . . . . . . . . . . . . . . . . . . . 436
Data Field Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
Indicator Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
INDICATOR Attribute of the Format 2 COPY Statement . . . . . . . . . 439
Generation of I-O Formats . . . . . . . . . . . . . . . . . . . . . . . . . . 440
Redefinition of Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
Additional Notes on Field and Format Names . . . . . . . . . . . . . . . 441
Floating Point Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
Date, Time, and Timestamp Fields . . . . . . . . . . . . . . . . . . . . . 442
Variable-length Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
Considerations Regarding Use of REPLACING in Format 2 COPY
Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
EJECT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
SKIP1/2/3 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
TITLE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
USE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448
USE Statement Programming Notes . . . . . . . . . . . . . . . . . . . . 449
USE FOR DEBUGGING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
Appendix A. COBOL/400 Compiler Limits . . . . . . . . . . . . . . . . . . . 451
Appendix B. Summary of IBM Extensions . . . . . . . . . . . . . . . . . . 453
Character-String Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . 453
Identification Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
Environment Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
Data Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
Procedure Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
COPY StatementAll Divisions . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
Transaction Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
Compiler-Directing Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
Appendix C. Intermediate Result Fields . . . . . . . . . . . . . . . . . . . . 459
Compiler Calculation of Intermediate Results . . . . . . . . . . . . . . . . . . . 460
Appendix D. EBCDIC and ASCII Collating Sequences . . . . . . . . . . . 463
EBCDIC Collating Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
ASCII Collating Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
xii COBOL/400 Reference
Appendix E. COBOL/400 Reserved Word List . . . . . . . . . . . . . . . . 471
Appendix F. File Structure Support Summary and Status Key Values . 475
File Status Key Values and Meanings . . . . . . . . . . . . . . . . . . . . . . . 480
Attribute Data Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
OPEN-FEEDBACK and I-O-FEEDBACK Data Areas . . . . . . . . . . . . . 488
OPEN-FEEDBACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
I-O-FEEDBACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
Appendix G. PROCESS Statement, PICTURE Symbols, ASSIGN Clause 491
PROCESS Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
Symbols Used in the PICTURE Clause . . . . . . . . . . . . . . . . . . . . . . 495
Assignment-Names in the ASSIGN Clause . . . . . . . . . . . . . . . . . . . . 496
Appendix H. SAA COBOL Compiler Options . . . . . . . . . . . . . . . . . 497
Appendix I. ACCEPT/DISPLAY and COBOL/2 Considerations . . . . . . 499
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
Contents xiii
xiv COBOL/400 Reference
Notices
References in this publication to IBM products, programs, or services do not imply
that IBM intends to make these available in all countries in which IBM operates.
Any reference to an IBM product, program, or service is not intended to state or
imply that only IBM's product, program, or service may be used. Any functionally
equivalent product, program, or service that does not infringe any of IBM's intellec-
tual property rights may be used instead of the IBM product, program, or service.
Evaluation and verification of operation in conjunction with other products, except
those expressly designated by IBM, is the user's responsibility.
IBM may have patents or pending patent applications covering subject matter in
this document. The furnishing of this document does not give you any license to
these patents. You can send license inquiries, in writing, to the IBM Director of
| Licensing, IBM Corporation, 208 Harbor Drive, Stamford, Connecticut, USA
| 06904-250.
Important changes or additions to the text are indicated by a vertical line (|) to the
left of the change or addition.
This publication contains examples of data and reports used in daily business oper-
ations. To illustrate them as completely as possible, the examples include the
names of individuals, companies, brands, and products. All of these names are
fictitious and any similarity to the names and addresses used by an actual business
enterprise is entirely coincidental.
Programming Interface Information
This manual is intended to help you write COBOL/400* programs. It contains infor-
mation necessary for you to use the COBOL/400 compiler. This manual docu-
ments no programming interfaces for use in writing programs that request or
receive the services of the COBOL/400 compiler.
Trademarks and Service Marks
The following terms, denoted by an asterisk (*) in this publication, are trademarks of
the IBM Corporation in the United States and/or other countries:
Application System/400 AS/400
CICS/400 COBOL/2
COBOL/400 IBM
| ILE Operating System/400
OS/2 OS/400
Systems Application Architecture SAA
400
Copyright IBM Corp. 1994 xv
xvi COBOL/400 Reference
About This Manual
About This Manual
This manual describes the COBOL/400 language structure, program organization,
procedure division statements, and compiler-directing statements.
This manual might refer to products that are announced but are not yet available.
The COBOL/400 language delivers most elements of the IBM Systems Application
Architecture
*
(SAA
*
) Common Programming Interface (CPI) COBOL, and is the
implementing product on the AS/400
*
system.
Who Should Use this Manual
This manual is a guide for the COBOL/400 programming language on the AS/400
system. It is intended for people who have a basic understanding of data proc-
essing concepts and of the COBOL programming language.
Before you use this manual, you should be familiar with certain AS/400 system
information:
For a comprehensive breakdown of information that pertains to COBOL/400
concepts, use the Publications Guide, GC41-9678, to locate reference material.
You should be familiar with your display station (also known as a work station),
and its controls. There are also some elements of its display and certain keys
on the keyboard that are standard regardless of which software system is cur-
rently running at the display station, or which hardware system the display
station is hooked up to. Some of these keys are:
Cursor movement keys
Command keys
Field exit keys
Insert and delete keys
The Error Reset key.
This information is contained in New Users Guide, SC41-8211.
You should know how to operate your display station when it is hooked up to
the IBM AS/400 system and running AS/400 software. This means knowing
about the OS/400
*
operating system and the Control Language (CL) to do such
things as:
Sign on and sign off the display station
Interact with displays
Use Help
Enter control commands
Call utilities
Respond to messages.
To find out more about this operating system and its control language, refer to:
Programming: Control Language Reference, SC41-0030
Programming: Control Language Programmers Guide, SC41-8077
Copyright IBM Corp. 1994 xvii
About This Manual
The Data Management Guide, SC41-9658, provides information on using data
management support, which allows an application to work with files.
The manual includes information on:
Fundamental structure and concepts of data management support on the
system
Data management support for display stations, printers, tapes, and
diskettes, as well as spooling support
Overrides and file redirection (temporarily making changes to files when an
application is run)
Copying files by using system commands to copy data from one place to
another
Tailoring a system using double-byte data.
You should know how to call and use certain utilities available on the AS/400
system:
The Screen Design Aid (SDA) utility used to design and code displays.
This information is contained in Application Development Tools: Screen
Design Aid Users Guide and Reference, SC09-1340.
The Source Entry Utility (SEU), which is a full-screen editor you can use to
enter and update your source and procedure members. This information is
contained in Application Development Tools: Source Entry Utility Users
Guide and Reference, SC09-1338.
You should know how to interpret displayed and printed messages. This infor-
mation is contained in the COBOL/400 Users Guide, SC09-1812.
COBOL/400 Syntax Notation
COBOL/400 basic formats are presented in a uniform system of syntax notation.
This notation, designed to assist you in writing COBOL source statements, is
explained in the following paragraphs:
COBOL keywords and optional words appear in uppercase letters; for example:
PARM1
They must be spelled exactly as shown. If any keyword is missing, the com-
piler considers it as an error.
Variables representing user-supplied names or values appear in all lowercase
letters; for example:
parmx
For easier text reference, some words are followed by a hyphen and a digit or
a letter, as in:
identifier1
This suffix does not change the syntactical definition of the word.
Arithmetic and logical operators (+, -, *, /, **, >, <, =, >=, and <=) that appear in
syntax formats are required. These operators are special character reserved
words. For a complete listing of reserved COBOL/400 words, see Appendix E,
COBOL/400 Reserved Word List on page 471.
All punctuation and other special characters appearing in the diagram are
required by the syntax of the format when they are shown; if you leave them
out, an error occurs in the program.
xviii COBOL/400 Reference
About This Manual
You must write the required clauses and the optional clauses (when used) in
the order shown in the diagram unless the associated rules explicitly state oth-
erwise.
How to Read the Syntax Diagrams
Throughout this book, syntax is described using the structure defined below.
Read the syntax diagrams from left to right, from top to bottom, following the
path of the line:
The symbol indicates the beginning of a statement.
The symbol indicates that the statement syntax is continued on the next
line.
The symbol indicates that a statement is continued from the previous
line.
The symbol indicates the end of a statement.
Diagrams of syntactical units other than statements, such as clauses, phrases
and paragraphs, also start with the symbol and end with the
symbol.
Note: Statements within a diagram of an entire paragraph will not start with
and end with unless their beginning or ending coincides with that
of the paragraph.
Required items appear on the horizontal line (the main path):
STATEMENTrequired item
Optional items appear below the main path:
STATEMENT
optional item
When you can choose from two or more items, they appear vertically, in a
stack.
If you must choose one of the items, one item of the stack appears on the main
path:
STATEMENTrequired choice1
required choice2
If choosing one of the items is optional, the entire stack appears below the
main path:
STATEMENT
optional choice1
optional choice2
About This Manual xix
About This Manual
An arrow returning to the left above an item indicates that that item may be
repeated:
STATEMENTrepeatable item
A repeat arrow above a stack of required or optional choices indicates that you
can make more than one choice from the stacked items, or repeat a single
choice:
STATEMENTchoice3
choice1 choice4
choice2
The following example shows how the syntax is used:
Format
3
1 2
STATEMENTidentifier1
literal1 item1
identifierm 1
TO ROUNDED 5
4
identifiern :
ROUNDED
1
6 ENDSTATEMENT
: 7
SIZE ERRORimperative statement
ON
where item1 is:
identifier2
literal2
arithmeticexpression1
1 The STATEMENT keyword must be specified and coded as shown.
2 This operand is required. Either identifier-1 or literal-1 must be coded.
xx COBOL/400 Reference
About This Manual
3 The operand item-1 is optional. It may be coded or not, as required by the
application. If coded, it may be repeated, with each entry separated by one or more
blanks. Entry selections allowed for this operand are described at the bottom of the
diagram.
4 The operand identifier-n is optional. If specified it may be repeated with one or
more blanks separating each entry. Each entry may be assigned the keyword
ROUNDED.
5 In cases where multiple lines must be continued past the right margin, line
order from top to bottom is preserved.
6 The ON keyword is optional to the keyword SIZE ERROR, which is optional
itself. If SIZE ERROR is coded, then the operand imperative-statement is required.
7 The END-STATEMENT keyword may be coded to end the statement. It is not
a required delimiter.
IBM Extensions
An IBM extension generally modifies a rule or restriction that immediately precedes
it. The standard is presented first, because some programmers use the
COBOL/400 language without IBM extensions. The extension is then presented for
those who do use them.
IBM extensions within figures or tables are shown in boxes unless they are explic-
itly identified as extensions.
Clauses and statements illustrated within syntax diagrams that are COBOL/400 lan-
guage extensions to ANSI X3.23-1985 COBOL are enclosed in double lines, as
follows:
RECORDEXTERNALLY-DESCRIBED-KEY
KEY IS
data-name-2
IBM Extension
COBOL/400 language extensions to ANSI X3.23-1985 COBOL that are part of the
text description are enclosed in IBM Extension bars, like this paragraph.
End of IBM Extension
About This Manual xxi
About This Manual
Documentary Syntax
COBOL clauses and statements illustrated within syntax diagrams that are syntax
checked, but are treated as documentation by the COBOL/400 compiler, are
enclosed by asterisks, as follows:
RESERVEinteger
AREA
AREAS
Obsolete Language Elements
Obsolete language elements are COBOL/400 language elements in the American
National Standard Programming Language COBOL, X3.23-1985, that will be
deleted from the next revision of this Standard. Throughout this book obsolete lan-
guage elements are identified in the main description of the language element.
They are also listed in the index under 'obsolete elements'.
Industry Standards
The COBOL/400 compiler is designed according to the specifications of the fol-
lowing industry standards as understood and interpreted by IBM as of September
1987.
1. American National Standard Programming Language COBOL, X3.23-1985
Following is an explanation of the notation used in the list:
A 3-character code that identifies the module.
In this example, the Segmentation module is
referenced.
2 SEG ,2
The level of this module supported by The range of levels of support
the COBOL/4 compiler. In this defined by the ANSI X3.23-1985 COBOL
example, support is provided for the standard. A level of means a minimum
higher of the two levels of the standard. COBOL does not need to support
Segmentation module. this module to conform to the standard.
The COBOL/400 language conforms to the following modules:
Nucleus (1 NUC 1,2)
Provides internal processing of data within the four basic divisions of a
program and the capability for defining and accessing tables.
xxii COBOL/400 Reference
About This Manual
Sequential I-O (1 SEQ 1,2)
Provides access to records of a file in established sequence. The
sequence is established as a result of writing the records to the file.
Relative I-O (1 REL 0,2)
Provides access to records in either a random or sequential manner; each
record is uniquely identified by an integer specifying the record's logical
position in a file.
Indexed I-O (1 INX 0,2)
Provides access to records in either a random or sequential manner; each
record in an indexed file is uniquely identified by the value of a key within
that record.
Inter-Program Communication (1 IPC 1,2)
Allows a COBOL/400 program to communicate with other programs through
transfers of control and access to common data items.
Sort-Merge (1 SRT 0,1)
Orders one or more files of records, or combines two or more identically
ordered files of records, according to a set of user-specified keys.
Source-Text Manipulation (1 STM 0,2)
Allows the insertion of source program text as part of the compilation of the
source program. COBOL/400 libraries contain texts which are available to
the compiler at compile time and which can be treated by the compiler as
part of the source program.
Debug (2 DEB 0,2)
Specifies the conditions under which procedures are to be monitored during
execution.
Segmentation (2 SEG 0,2).
Provides programmer-controlled storage optimization of the Procedure Divi-
sion by allowing that division to be subdivided both physically and logically.
The following modules are not included:
Report Writer (0 RPW 0,1)
Communication (0 COM 0,2).
Portions of this manual are copied (with permission) from the ANSI Standard.
Copies of the ANSI Standard may be purchased from:
American National Standards Institute
1430 Broadway
New York, New York 10018
2. ISO 1989-1985 Standard of the International Organization for Standardization
(ISO)
3. Federal Standard COBOL of March 1986 (FIPS PUB 21-2), Intermediate Level
4. The 7-bit coded character sets defined in American National Standard
X3.4-1977, Code for Information Interchange
About This Manual xxiii
About This Manual
5. International Reference Version of the ISO 7-bit code defined in International
Standard 646, 7-Bit Coded Character Set for Information Processing Inter-
change.
The COBOL language is developed by the Conference on Data Systems Lan-
guages (CODASYL).
xxiv COBOL/400 Reference
Characters
Chapter 1. COBOL Language Structure
Characters
In COBOL, the indivisible unit of data is the character. In the COBOL/400 lan-
guage, the letters of the alphabet, digits, and special characters that form the
COBOL character set are represented by a subset of the EBCDIC (extended
binary-coded decimal interchange code) character set.
Figure 1 on page 2 shows the complete set of COBOL characters, their meanings,
and their uses.
In COBOL, an alphabetic character is a letter or a space character.
In the COBOL/400 language, each lowercase letter is generally equivalent to the
corresponding uppercase letter. Important exceptions are letters in nonnumeric
literals that do not use hexadecimal notation, and the uppercase D that must
appear in column 7 of a debugging line.
The COBOL/400 language is restricted to the defined character set, but the con-
tents of nonnumeric literals, comment lines, comment entries, and the values held
in data items, can include any of the characters from the EBCDIC character set.
IBM Extension
Characters from the Double-Byte Character Set (DBCS) are valid characters in
certain COBOL character-strings. (See the DBCS information under Character-
Strings on page 2 for more information.)
End of IBM Extension
Individual characters are joined to form character-strings and separators.
A character-string is a character or sequence of contiguous characters that form a
COBOL word, a literal, a PICTURE character-string, or a comment. A character-
string is delimited by separators.
A separator is a contiguous string of one or more punctuation characters. A sepa-
rator can be placed next to another separator, or next to a character-string. Sepa-
rators are described in detail under Separators on page 11.
IBM Extension
You can use the apostrophe in place of the quotation mark if you override the
default compiler option.
End of IBM Extension
Copyright IBM Corp. 1994 1
Character-Strings
Character Meaning Use
AZ Alphabet (uppercase) Alphabetic characters
az Alphabet (lowercase) Alphabetic characters
9 Arabic numerals Numeric characters
Space Punctuation character
. Decimal point or Editing character
Period Punctuation character
< Less than Relation character
( Left parenthesis Punctuation character
+ Plus sign Arithmetic operator
Editing character
$ Dollar sign Editing character
Asterisk Arithmetic operator
Editing character
Comment character
) Right parenthesis Punctuation character
; Semicolon Punctuation character
: Colon Punctuation character
Minus sign or Arithmetic operator
Hyphen Editing character
Continuation character
/ Stroke or Arithmetic operator
Slash Editing character
Line control character
, Comma Punctuation character
Editing character
> Greater than Relation character
= Equal sign Relation character
Punctuation character
" Quotation marks Punctuation characters
' Apostrophe Punctuation character
Figure 1. COBOL CharactersTheir Meanings and Uses
Character-Strings
You can use Single-Byte Character Set (SBCS) character-strings to form:
COBOL words
Literals
PICTURE character-strings
Comments.
2 COBOL/400 Reference
Character-Strings
IBM Extension
You can use Double-Byte Character Set (DBCS) character-strings to form:
Literals
Comments.
DBCS character-strings are constructed using characters from the Double-Byte
Character Set of a system. DBCS character-strings can be embedded into nonnu-
meric strings.
End of IBM Extension
COBOL Words
COBOL words must be character-strings from the set of letters, digits, and the
hyphen. The three types of COBOL words are:
User-defined words
System-names
Reserved words.
The maximum length of a COBOL word is 30 characters.
User-Defined Words
A reserved word cannot be a user-defined word. The types of user-defined words
are listed below, with the rules that must be followed in forming them.
The function of each user-defined word is described in the clause or statement in
which it appears.
Types of User-Defined Words General Rules
Alphabet-name
Class-name
Condition-name
Data-name
Record-name
File-name
Index-name
Mnemonic-name
Pointer-name
Routine-name
Each word must contain at least
one alphabetic character.
Library-name
Program-name
Text-name
Each word must contain at least
one alphabetic character. The first
10 characters must be unique.
Paragraph-name
Section-name
The word need not contain an
alphabetic character.
Level-numbers: 01-49,66,77,88 Each word must be a 1-digit or
2-digit integer.
Segment-Numbers: 00-99 Must be a 1 or 2 digit integer; it
does not have to be unique.
Chapter 1. COBOL Language Structure 3
Character-Strings
Valid characters in a user-defined word are:
A through Z
a through z
0 through 9
- (hyphen).
The hyphen may not appear as the first or last character in a user-defined word.
User-defined words form sets equivalent to the types in the above table, except that
level-numbers are not a set, and condition-names, data-names, and record-names
are grouped into a single set. No user-defined word can belong to more than one
of these sets. Within each set, each user-defined word must be unique, except as
specified in Methods of Data Reference on page 21.
System-Names
A system-name is a character string that is defined by IBM to have a specific
meaning to the system. There are three types of system-names:
Computer-names
Language-names
Implementor-names.
There are two types of implementor-names:
Environment-name
Assignment-name.
The meaning of each system-name is described with the format in which it appears.
Reserved Words
A reserved word is a character-string with a predefined meaning in a COBOL
source program. A reserved word must not be used as a user-defined word or as
a system-name. Reserved words can be used only as specified in the formats for
a COBOL source program.
COBOL/400 reserved words are listed in Appendix E, COBOL/400 Reserved Word
List on page 471.
There are five types of reserved words:
Keywords
Optional words
Special characters
Figurative constants
Special registers.
Keywords
Keywords are reserved words that are required within a given clause, entry, or
statement. Within each format, such words are in uppercase and appear on the
main path.
4 COBOL/400 Reference
Character-Strings
Optional Words
Optional words are reserved words that may be included in the format of a clause,
entry, or statement in order to improve readability. They have no effect on the
execution of the program. When an optional word is omitted, such as in the KEY
IS phrase, the meaning of the COBOL statement is unchanged. Optional words
are shown in formats as uppercase, but appear below the main path.
Special Characters
There are two types of special character reserved words:
Arithmetic operators: + - / * **
See Arithmetic Expressions on page 164.
Relational operators: < > = <= >=
See Conditional Expressions on page 166.
Figurative Constants
Figurative constants are reserved words that name and refer to specific constant
values. Figurative constants are not allowed as function arguments. The reserved
words for figurative constants and their meanings are:
ZERO/ZEROS/ZEROES
Represents the numeric value zero (0), one or more occurrences of the nonnu-
meric character zero (0), or the Boolean value B"0", depending on context.
SPACE/SPACES
Represents one or more blanks or spaces; treated as a nonnumeric literal.
HIGH-VALUE/HIGH-VALUES
Represents one or more occurrences of the character that has the highest
ordinal position in the collating sequence used. For the EBCDIC and ASCII
collating sequences, the character is X'07'; for other collating sequences, the
actual character used depends on the collating sequence. HIGH-VALUE is
treated as a nonnumeric literal.
LOW-VALUE/LOW-VALUES
Represents one or more occurrences of the character that has the lowest
ordinal position in the collating sequence used. For the EBCDIC and ASCII
collating sequences, the character is X'00'; for other collating sequences, the
actual character used depends on the collating sequence. LOW-VALUE is
treated as a nonnumeric literal.
QUOTE/QUOTES
Represents one or more occurrences of the quotation mark character and must
be nonnumeric. QUOTE, or QUOTES cannot be used in place of a quotation
mark or an apostrophe to enclose a nonnumeric literal.
IBM Extension
When APOST is specified as a compiler option, the figurative constant QUOTE
has the EBCDIC value of an apostrophe.
End of IBM Extension
Chapter 1. COBOL Language Structure 5
Character-Strings
ALL literal
Represents one or more occurrences of the string of characters comprising the
literal. The literal must be a nonnumeric literal or a figurative constant other
than the ALL literal.
IBM Extension
ALL Boolean literal
The ALL literal can be Boolean.
End of IBM Extension
When a figurative constant other than ALL literal is used, the word ALL is
redundant and is used for readability only. The figurative constant ALL literal
must not be used with the INSPECT, STOP, or STRING statements.
Note: The figurative constant ALL literal, when associated with a numeric or
numeric-edited item and when the length of the literal is greater than one, is an
obsolete element and is to be deleted from the next revision of the ANSI
Standard.
IBM Extension
NULL/NULLS
Represents a value used to indicate that a data item defined with the USAGE
IS POINTER clause, ADDRESS OF phrase, or ADDRESS OF special register
does not contain a valid address. NULL can be used only where explicitly
allowed in the syntax format.
In the COBOL/400 language, a value of NULL is undefined.
End of IBM Extension
The singular and plural forms of a figurative constant are equivalent, and may be
used interchangeably. For example, if DATA-NAME-1 is a 5-character data item,
each of the following statements will fill DATA-NAME-1 with five spaces:
MOVE SPACE TO DATA-NAME-1
MOVE SPACES TO DATA-NAME-1
MOVE ALL SPACES TO DATA-NAME-1
A figurative constant may be used wherever 'literal' appears in a format, except
where explicitly prohibited. When a numeric literal appears in a format, the figura-
tive constant ZERO may be used.
IBM Extension
The figurative constant ZERO can be used as a Boolean literal.
End of IBM Extension
6 COBOL/400 Reference
Character-Strings
The length of a figurative constant depends on the context of the program. The
following rules apply:
When a figurative constant is associated with a data item (for example, when it
is moved to or compared with another item), the length of the figurative con-
stant character-string is equal to the size of the associated data item.
When a figurative constant, other than the ALL literal, is not associated with
another data item (for example, in a STOP, STRING, or UNSTRING state-
ment), the length of the character-string is one (1) character.
Special Registers
Special registers are reserved words that name storage areas generated by the
compiler. Their primary use is to store information produced through one of the
specific COBOL features. Each such storage area has a fixed name, and need not
be further defined within the program. Each special register is discussed in the
section indicated.
IBM Extension
End of IBM Extension
IBM Extension
LENGTH OF Special Register: The LENGTH OF special register contains the
number of bytes used by a data item referenced by an identifier.
The LENGTH OF phrase creates an implicit special register whose contents equal
the current length, in bytes, of the data item referenced by the identifier.
The LENGTH OF special register has the implicit definition:
USAGE IS BINARY, PICTURE 9(9)
You can use it anywhere in the Procedure Division where you can use a numeric
data item having the same definition as the implied definition of the LENGTH OF
special register.
It can appear in the starting position or length expression of a reference modifier,
but you cannot apply it to an operand that is reference modified.
Special Register Page
ADDRESS OF 82
Special Register Page
DB-FORMAT-NAME 195
Special Register Page
DEBUG-ITEM Refer to the
COBOL/400 Users
Guide.
Chapter 1. COBOL Language Structure 7
Character-Strings
It cannot be either of the following:
A receiving data item
A subscript.
You can use LENGTH OF in the BY CONTENT phrase of the CALL statement.
For a table element, the LENGTH OF special register contains the length, in bytes,
of one occurrence. To refer to a table element in this case, you do not need to use
a subscript.
For a variable-length element, the LENGTH OF special register contains the length
based on the current contents of the occurs depending on (ODO) variable.
| Note: The ODO variable is not checked to ensure that it is within range when the
| LENGTH OF a variable length item is taken.
The register returns a value for any identifier whose length can be determined,
even if the area referenced by the identifier is currently not available to the
program. For example, an identifier that is part of a 01-level record in a File Defi-
nition is not available until the corresponding file is open; however, the LENGTH
OF such an identifier can be determined before the file is open.
If, for a variable-length item, the contents of the ODO variable are not available, the
LENGTH OF special register is undefined. For example, if an ODO variable is
defined in the 01-level record of a file that is not open, no LENGTH OF value
exists, and an error results.
A separate LENGTH OF special register exists for each identifier referenced with
the LENGTH OF phrase.
For example:
MOVE LENGTH OF A TO B
DISPLAY LENGTH OF A, A
ADD LENGTH OF A TO B
CALL "PROGX" USING BY REFERENCE A BY CONTENT LENGTH OF A
End of IBM Extension
IBM Extension
End of IBM Extension
Special Register Page
LINAGE-COUNTER 104
Special Register Page
WHEN-COMPILED 300
8 COBOL/400 Reference
Character-Strings
Literals
A literal is a character-string whose value is specified either by the characters of
which it is composed, or by the use of a figurative constant. (See Figurative
Constants on page 5.) There are three types of literals: Boolean, nonnumeric,
and numeric.
IBM Extension
Boolean Literals
A Boolean literal is a character-string delimited on the left by the separator B" and
on the right by the quotation mark separator. The character-string consists only of
the character 0 or 1. The value of a Boolean literal is the character itself, excluding
the delimiting separators. All Boolean literals are of the category Boolean.
End of IBM Extension
Nonnumeric Literals
A nonnumeric literal is a character-string enclosed in quotation marks ("), and can
contain any allowable character from the EBCDIC character set. The maximum
length of a nonnumeric literal is 160 characters.
A nonnumeric literal must be enclosed in quotation marks (") (or apostrophes if the
APOST option is in effect). These quotation marks (or apostrophes) are excluded
from the literal when the program is compiled. An embedded quotation mark must
be represented by a pair of quotation marks ("").
Any punctuation characters included within a nonnumeric literal are part of the
value of the literal.
Every nonnumeric literal is in the alphanumeric data category. (Data categories
are described in Classes and Categories of Data on page 87.)
IBM Extension
You can use hexadecimal notation to form a hexadecimal nonnumeric literal.
X" The opening delimiter for hexadecimal notation of a nonnumeric literal. (If the
compiler option *APOST or the PROCESS statement option APOST is speci-
fied, the opening delimiter is X'.)
" The closing delimiter for hexadecimal notation of a nonnumeric literal. (If the
compiler option *APOST or the PROCESS statement option APOST is speci-
fied, the closing delimiter is '.)
Hexadecimal digits can be characters that range from 0 to 9, and A to F, inclusive.
Two hexadecimal digits represent a single character, so an even number of
hexadecimal digits must be specified in each case.
The maximum length of a hexadecimal nonnumeric literal is 320 hexadecimal digits.
The continuation rules are the same as those for any nonnumeric literal.
Chapter 1. COBOL Language Structure 9
Character-Strings
X"hexadecimal-digits"
Figure 2. Format
The GRAPHIC option of the PROCESS statement does not affect the processing of
hexadecimal nonnumeric literals.
The compiler converts the hexadecimal literal into an ordinary nonnumeric literal.
Hexadecimal nonnumeric literals can be used anywhere nonnumeric literals can
appear.
The padding character for hexadecimal nonnumeric literals is a trailing blank
(X"40"). Empty hexadecimal nonnumeric literals are converted to X"40".
End of IBM Extension
IBM Extension
SBCS and DBCS characters can be combined within a character-string to form a
mixed literal. SAA COBOL statements process mixed literals without sensitivity to
the machine representation. Those statements that operate on a byte-to-byte basis
(for example, STRING and UNSTRING) may produce literals that are not valid mix-
tures of SBCS and DBCS. It is the user's responsibility to be certain that the state-
ments are used correctly.
Mixed literals must not be continued.
End of IBM Extension
Numeric Literals
A numeric literal is a character-string whose characters are selected from the
digits 0 through 9, a sign character (+ or -), and the decimal point. If the literal
contains no decimal point, it is an integer. (In this manual, the word integer
appearing in a format represents a numeric literal of nonzero value that contains no
sign and no decimal point; any other restrictions are included with the description of
the format.) The following rules apply:
One through 18 digits are allowed.
Only one sign character is allowed. If included, it must be the leftmost char-
acter of the literal. If the literal is unsigned, it is positive in value.
Only one decimal point is allowed. If a decimal point is included, it is treated as
an assumed decimal point (that is, as not taking up a character position in the
literal). The decimal point may appear anywhere within the literal except as the
rightmost character.
If enclosed in quotation marks, the compiler treats the literal as a nonnumeric
literal.
The value of a numeric literal is the algebraic quantity expressed by the characters
in the literal. The size of a numeric literal in standard data format characters is
equal to the number of digits specified by the user.
10 COBOL/400 Reference
Separators
Every numeric literal is in the numeric data category. (Data categories are
described under Classes and Categories of Data on page 87.)
PICTURE Character-Strings
A PICTURE character-string consists of certain symbols that are composed of the
currency symbol and certain combinations of characters in the COBOL character
set.
Any punctuation character that appears as part of the specification of a PICTURE
character-string is not considered as a punctuation character, but rather as a
symbol used in the specification of that PICTURE character-string. (A chart of
PICTURE clause symbols appears in Table 10 on page 127.)
Comments
A comment is a character-string that can contain any combination of characters
from the EBCDIC character set. It has no effect on the execution of the program.
There are two forms of comments:
Comment entry
(Identification Division)
This form is described under Optional Paragraphs on page 31.
Comment line
(Any division)
This form is described under Comment Lines on page 20.
Separators
A separator can be a single punctuation character or a string of punctuation charac-
ters.
Table 1 shows the COBOL separator characters supported in the COBOL/400 lan-
guage.
Chapter 1. COBOL Language Structure 11
Separators
Table 1. Separators
Separator Meaning
Space
, Comma
. Period
; Semicolon
( Left parenthesis
) Right parenthesis
" Quotation mark
== Pseudo-text delimiter
: Colon
IBM Extension
'
End of IBM Extension
IBM Extension
Apostrophe
End of IBM Extension
IBM Extension
B"
End of IBM Extension
IBM Extension
Opening delimiter for
Boolean literal
End of IBM Extension
IBM Extension
X"
End of IBM Extension
IBM Extension
Opening delimiter for
hexadecimal nonnumeric
literal
End of IBM Extension
Rules for Separators
In the following description, brackets enclose each separator. Anywhere a space is
used as a separator, or as part of a separator, more than one space may be used.
A space []
A space can immediately precede or follow any separator except:
As specified in standard format rules (see Reference Format on page 15).
Within quotation marks. (or apostrophes if the APOST option is in effect).
Spaces between quotation marks are considered part of the nonnumeric
literal; they are not considered separators.
Period [.]
Comma [,]
Semicolon [;]
The separator period must be used only to indicate the end of a sentence, or
as shown in formats. The separator comma and separator semicolon may be
used anywhere the separator space is used.
12 COBOL/400 Reference
Separators
In the Identification Division, separator commas and separator semico-
lons can be used in the comment-entries. Each paragraph must end with a
separator period.
In the Environment Division, separator commas or separator semicolons
may separate clauses and operands within clauses. The
SOURCE-COMPUTER, OBJECT-COMPUTER, SPECIAL-NAMES, and
I-O-CONTROL paragraphs must each end with a separator period. In the
FILE-CONTROL paragraph, each File-Control entry must end with a sepa-
rator period.
In the Data Division, separator commas or separator semicolons may sep-
arate clauses and operands within clauses. File (FD), Sort/Merge file (SD),
and data description entries must each end with a separator period.
In the Procedure Division, separator commas or separator semicolons
may separate statements within a sentence, and operands within a state-
ment. Each sentence and each procedure must end with a separator
period.
Parentheses [ ( ] . . . [ ) ]
Must appear as balanced pairs of left and right parentheses. They delimit sub-
scripts, reference modification, arithmetic expressions, and conditions.
Quotation marks ["] . . . ["]
An opening quotation mark must be immediately preceded by a space or a left
parenthesis. A closing quotation mark must be immediately followed by a sep-
arator (space, comma, semicolon, period, or right parenthesis). Quotation
marks must appear as balanced pairs. They delimit nonnumeric literals, except
when the literal is continued (see Continuation Lines on page 19).
IBM Extension
Under the *APOST compiler option, or the APOST PROCESS option, an apos-
trophe can be used in place of a quotation mark.
End of IBM Extension
Pseudo-text delimiters [==] ... [==]
An opening pseudo-text delimiter must be immediately preceded by a space. A
closing pseudo-text delimiter must be immediately followed by a separator
(space, comma, semicolon, or period). Pseudo-text delimiters must appear as
balanced pairs. They delimit pseudo-text. (See COPY Statement on
page 429.)
Colon [ : ]
The colon is a separator, and is required when shown in general formats.
IBM Extension
B" is a separator when used to describe a Boolean literal. The B must immediately
precede the quotation mark.
End of IBM Extension
Chapter 1. COBOL Language Structure 13
Sections and Paragraphs
IBM Extension
X" is a separator when used to describe a hexadecimal nonnumeric literal. The X
must immediately precede the quotation mark.
End of IBM Extension
Note: Any punctuation character included in a PICTURE character-string, a
comment character-string, or a nonnumeric literal is not considered as a punctu-
ation character, but rather as part of the character-string or literal.
Sections and Paragraphs
Sections and paragraphs define a program. They are subdivided into clauses and
statements. For more information on sections, paragraphs, and statements, see
Procedures on page 162.
Unless the associated rules explicitly state otherwise, each required clause or state-
ment must be written in the sequence shown in its format. If optional clauses or
statements are used, they must be written in the sequence shown in their formats.
These rules are true even for clauses and statements treated as comments.
The grammatical hierarchy follows this form:
Identification Division
Paragraphs
Entries
Clauses
Environment Division
Sections
Paragraphs
Entries
Clauses
Phrases
Data Division
Sections
Entries
Clauses
Phrases
Procedure Division
Sections
Paragraphs
Sentences
Statements
Phrases
14 COBOL/400 Reference
Reference Format
Entries
An entry is a series of clauses ending with a separator period. Entries are con-
structed in the Identification, Environment, and Data Divisions.
Clauses
A clause is an ordered set of consecutive COBOL character-strings that specifies
an attribute of an entry. Clauses are constructed in the Identification, Environment,
and Data Divisions.
Sentences
A sentence is a sequence of one or more statements, ending with a separator
period. Sentences are constructed in the Procedure Division.
Statements
A statement is a valid combination of a COBOL verb and its operands. It specifies
an action to be taken by the object program. Statements are constructed in the
Procedure Division. For descriptions of the different types of statements, see:
Imperative Statements on page 181
Conditional Statements on page 183
Delimited Scope Statements on page 184
Chapter 9, Compiler-Directing Statements on page 427.
Phrases
Each clause or statement in the program can be subdivided into smaller units
called phrases.
Reference Format
COBOL programs must be written in the COBOL reference format. Figure 3
shows the reference format for a COBOL source line.
1 2 | 3 | 4 | 5 | 6 7 8 | 9 | 1 | 11 12 | ... | 72 73 | ... | 8
Sequence Number Area Area AArea BComment Area
Indicator Area
Figure 3. Reference Format for COBOL Source Line
The following areas are described below in terms of an 80-character line:
Sequence Number Area
Columns 1 through 6
Indicator Area
Column 7
Area A
Columns 8 through 11
Chapter 1. COBOL Language Structure 15
Area B
Columns 12 through 72
Comment Area
Columns 73 through 80 are available for your own use; for example, to identify
your program.
Sequence Number Area (Columns 1 through 6)
A sequence number identifies each statement to be compiled by the COBOL com-
piler. The use of sequence numbers is optional. If used, a sequence number must
be in columns 1 through 6, and may consist of any character in the character set of
the computer.
If sequence numbers are present in the source program, they may be in any order,
and they need not be unique.
IBM Extension
The user can use sequence checking at compile time by specifying SEQUENCE.
If the NUMBER option is specified, the sequence numbers from columns 1 through
6 are used; otherwise the source sequence numbers provided in the source file are
used.
End of IBM Extension
Indicator Area (Column 7)
Use the indicator area to specify:
The continuation of words or nonnumeric literals from the previous line onto the
current line
The treatment of text as documentation
Debugging lines.
See Continuation Lines on page 19, Comment Lines on page 20, and Debug-
ging Lines on page 20.
Area A (Columns 8 through 11)
The following items must begin in Area A:
Division header
Section header
Paragraph header or paragraph name
Level indicator or level-number (01 and 77)
DECLARATIVES and END DECLARATIVES.
16 COBOL/400 Reference
C
SEQUENCE O A B
N
PAGE SERIALT
1 34 678 12 16 2 24 28
11 IDENTIFICATION DIVISION.
3 ENVIRONMENT DIVISION.
4 CONFIGURATION SECTION.
6 INPUTOUTPUT SECTION.
7 FILECONTROL.
9 DATA DIVISION.
1 FILE SECTION.
11 FD
12 WORKINGSTORAGE SECTION.
13 1 DESCRIPTION
14 1
15
16 PROCEDURE DIVISION.
17 DECLARATIVES.
18
19 END DECLARATIVES.
2 SECTIONNAME SECTION.
21 PARAGRAPHNAME
22 COMMENTS.
23D DEBUGSTATEMENTS.
24 MOVE "TEST" TO A.
AUTHOR.
commententry
INSTALLATION.
commententry
DATE-WRITTEN.
commententry
DATE-COMPILED.
commententry
SECURITY.
commententry
Figure 6. Format
The Identification Division must begin with the words IDENTIFICATION DIVISION
followed by a separator period.
The first paragraph of the Identification Division must be the PROGRAM-ID para-
graph. The other paragraphs are optional, but, when written, must appear in the
order shown in the format.
Copyright IBM Corp. 1994 29
PROGRAM-ID Paragraph
IBM Extension
The abbreviation ID DIVISION may be substituted for the standard division header,
and the optional paragraphs may be in any order.
End of IBM Extension
Note: The SEU Syntax Checker requires that the first sentence of the following
paragraph headers begin on the same line as the paragraph header:
PROGRAM-ID
AUTHOR
INSTALLATION
DATE-WRITTEN
DATE-COMPILED
SECURITY
Coding Example
IDENTIFICATION DIVISION.
PROGRAM-ID. IDSAMPLE.
AUTHOR. PROGRAMMER NAME.
INSTALLATION. COBOL DEVELOPMENT CENTER.
DATE-WRITTEN. 8/27/88.
DATE-COMPILED. 9/1/88 12:57:53.
SECURITY. NON-CONFIDENTIAL.
PROGRAM-ID Paragraph
PROGRAM-ID.program-name.
Figure 7. Format
The PROGRAM-ID paragraph specifies the name by which the object program is
known to the system. It is required and must be the first paragraph in the Identifi-
cation Division.
program-name
A user-defined word that identifies your object program to the system. The
system uses the first 10 characters of program-name as the identifying name of
the program; these first 10 characters, therefore, should be unique among
program-names. The first character of program-name is forced to be alpha-
betic; if it is numeric, it is converted as follows:
to J
1 through 9 to A through I
If a hyphen is in positions 2 through 10, it is converted to zero (0).
The name by which the program is known to the system can be overridden by the
PGM parameter of the CRTCBLPGM command. See the COBOL/400 Users
Guide for more information on the PGM parameter.
30 COBOL/400 Reference
Optional Paragraphs
Optional Paragraphs
These optional paragraphs in the Identification Division may be omitted:
AUTHOR
Name of the author of the program.
AUTHOR.
comment-entry
Figure 8. Format
INSTALLATION
Name of the company or location.
INSTALLATION.
comment-entry
Figure 9. Format
DATE-WRITTEN
Date the program was written.
DATE-WRITTEN.
comment-entry
Figure 10. Format
DATE-COMPILED
Date the program was compiled.
DATE-COMPILED.
comment-entry
Figure 11. Format
SECURITY
Level of confidentiality of the program.
Chapter 2. COBOL Program Structure 31
Environment Division-Configuration Section
SECURITY.
comment-entry
Figure 12. Format
Note: These optional paragraphs are obsolete elements and are to be deleted
from the next revision of the ANSI Standard.
The comment-entry in any of the optional paragraphs may be any combination of
characters from the character set of the computer. The comment-entry is written in
Area B on one or more lines.
The paragraph name DATE-COMPILED and any comment-entry associated with it
are replaced during compilation with a paragraph of the form:
DATE-COMPILED. current date.
Comment-entries serve only as documentation; they do not affect the meaning of
the program. A hyphen in the indicator area (column 7) is not permitted in
comment-entries.
IBM Extension
Comment-entry may contain the *CBL, *CONTROL, EJECT, SKIP1, SKIP2,
SKIP3, or TITLE statements anywhere on the line. These statements will be acted
on if they are alone on a line within the comment-entry, and they will not terminate
the comment-entry.
End of IBM Extension
IBM Extension
Comments may combine DBCS and SBCS character-strings. Multiple lines are
allowed in a comment-entry containing DBCS strings.
Note: DBCS strings are described under Character-Strings on page 2.
End of IBM Extension
Environment DivisionConfiguration Section
The Environment Division has two sections:
The Configuration Section
The Input-Output Section. (See Chapter 3, Environment
DivisionInput-Output Section on page 51.)
The Environment Division is optional in a COBOL source program.
32 COBOL/400 Reference
Environment Division-Configuration Section
ENVIRONMENT DIVISION. 1
CONFIGURATION SECTION. :
SOURCE-COMPUTER.
source-computer-entry
1
:
OBJECT-COMPUTER. SPECIAL-NAMES.
object-computer-entry special-names-entry
1
INPUT-OUTPUT SECTION. FILE-CONTROL. file-control-entry :
1
: .
I-O-CONTROL.
input-output-control-entry
Figure 13. Format
The Configuration Section is optional. When specified, it can describe the com-
puter on which the source program is compiled and the computer on which the
object program is executed.
In addition, the Configuration Section can:
Relate IBM-defined environment-names to user-defined mnemonic names
Specify the collating sequence
Specify a substitution for the currency sign
Interchange the functions of the comma and the period in PICTURE clauses
and numeric literals
Relate alphabet-names to character sets or collating sequences
Relate class names to sets of characters.
Each paragraph must contain one, and only one, separator period immediately after
the last entry in the paragraph.
Note: The SEU Syntax Checker requires that the first clause of the following para-
graphs be entered on the same line as the paragraph name:
SOURCE-COMPUTER
OBJECT-COMPUTER
SPECIAL-NAMES
Coding Example
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-AS4.
OBJECT-COMPUTER. IBM-AS4.
SPECIAL-NAMES. C1 IS TOP-OF-PAGE.
Chapter 2. COBOL Program Structure 33
SOURCE-COMPUTER Paragraph
SOURCE-COMPUTER Paragraph
The SOURCE-COMPUTER paragraph describes the computer on which the source
program is to be compiled.
SOURCECOMPUTER.
computername.
DEBUGGING MODE
WITH
Figure 14. Format
computer-name
A system-name. The suggested computer-name is:
IBM-AS4.
WITH DEBUGGING MODE
Activates a compile-time switch for debugging lines written in the source
program.
A debugging line is a statement that is compiled only when the compile-
time switch is activated. Debugging lines allow you, for example, to check
the value of a data-name at certain points in a procedure.
The WITH DEBUGGING MODE clause causes any USE FOR DEBUG-
GING procedure to be compiled. Without this clause, these procedures are
treated as comments and ignored.
Note that the USE FOR DEBUGGING declarative causes all subsequent
statements to be ignored up to a valid USE AFTER EXCEPTION/ERROR
statement, or END DECLARATIVES delimiter. Entire programs can be
ignored because of this.
To specify a debugging line in your program, code a 'D' in column 7 (indi-
cator area). You may include successive debugging lines, but each must
have a 'D' in column 7 and you may not break character strings across
lines.
All your debugging lines must be written so that the program is syntactically
correct, whether the debugging lines are compiled or treated as comments.
The presence or absence of the DEBUGGING MODE clause is logically
determined after all COPY statements are processed.
You may code debugging lines in the Environment (after the
OBJECT-COMPUTER paragraph), Data, or Procedure Divisions.
If a debugging line contains only spaces in Area A and in Area B, it is
treated the same as a blank line.
Except for the WITH DEBUGGING MODE clause, the SOURCE-COMPUTER para-
graph is syntax-checked, but has no effect on the execution of the program.
34 COBOL/400 Reference
OBJECT-COMPUTER Paragraph
OBJECT-COMPUTER Paragraph
The OBJECT-COMPUTER paragraph specifies the system for which the object
program is designated.
OBJECT-COMPUTER. 1
computer name :
1 1
: :
MEMORYintegerWORDS
SIZE CHARACTERS
MODULES
1 1
: :
SEQUENCEalphabet-name
PROGRAM COLLATING IS
1
: .
SEGMENT-LIMITsegment-number
IS
Figure 15. Format
computer-name
A system-name. The suggested computer-name is:
IBM-AS4.
MEMORY SIZE
The amount of main storage needed to run the object program. The MEMORY
SIZE clause is syntax-checked, but it has no effect on the execution of the
program.
Note: MEMORY SIZE is an obsolete element, and is to be deleted from the
next revision of the ANSI Standard.
integer
Expressed in words, characters, or modules.
PROGRAM COLLATING SEQUENCE IS
The collating sequence used in this program is the collating sequence associ-
ated with the specified alphabet-name.
alphabet-name
The collating sequence.
Chapter 2. COBOL Program Structure 35
OBJECT-COMPUTER Paragraph
PROGRAM COLLATING SEQUENCE determines the truth value of the fol-
lowing nonnumeric comparisons:
Those explicitly specified in relation conditions
Those explicitly specified in condition-name conditions.
The PROGRAM COLLATING SEQUENCE clause also applies to any nonnu-
meric merge or sort keys, unless the COLLATING SEQUENCE phrase is speci-
fied in the MERGE or SORT statement. When the PROGRAM COLLATING
SEQUENCE clause is omitted, the EBCDIC collating sequence is used.
See Appendix D, EBCDIC and ASCII Collating Sequences on page 463 for
more information about these sequences.
SEGMENT-LIMIT IS
Determines which segments will be considered as permanent segments of the
object program.
segment-number
Must be an integer varying in value from 1 through 49.
When the SEGMENT-LIMIT is specified:
Only those segments having segment-numbers from 0 up to, but not
including, the segment-number designated as the segment-limit, are consid-
ered as permanent segments of the object program.
Those segments having segment-numbers from the segment-limit through
49 are considered as overlayable fixed segments.
For example, if SEGMENT-LIMIT IS 25 is specified, sections with segment-
numbers 0 through 24 are permanent segments of the object program, and
sections with segment-numbers 25 through 49 are overlayable fixed segments.
When the SEGMENT-LIMIT clause is omitted, all segments having segment-
numbers from 0 through 49 are considered as permanent segments of the
object program.
36 COBOL/400 Reference
SPECIAL-NAMES Paragraph
SPECIAL-NAMES Paragraph
The SPECIAL-NAMES paragraph:
Relates IBM-specified environment-names to user-defined mnemonic-names.
Relates alphabet-names to character sets or collating sequences.
Relates class names to sets of characters.
Specifies a substitute character for the currency sign.
Specifies that the functions of the comma and decimal point are to be inter-
changed in PICTURE clauses and numeric literals.
IBM Extension
Specifies that ACCEPT or DISPLAY statements are treated as extended
ACCEPT or DISPLAY statements.
Specifies additional functions associated with ACCEPT statements.
End of IBM Extension
Chapter 2. COBOL Program Structure 37
SPECIAL-NAMES Paragraph
SPECIAL-NAMES.
environment-name-1mnemonic-name-1
IS
environment-name-2mnemonic-name-2
IS status-cond
status-cond
ALPHABET alphabet-name-1STANDARD-1
IS STANDARD-2
NATIVE
EBCDIC
literal-1
THROUGHliteral-2
THRU
ALSO literal-3
CLASS class-name-1literal-4
IS THROUGHliteral-5
THRU
CURRENCYliteral-6 DECIMAL-POINTCOMMA
SIGN IS IS
.
|
|
CONSOLECRT
IS
CURSORdata-name-1
IS
CRT STATUSdata-name-2
IS
where status-cond is:
ONcond-1
STATUS IS OFFcond-2
STATUS IS
OFFcond-2
STATUS IS ONcond-1
STATUS IS
Figure 16. Format
Note: The optional separator period at the end of the format must be used if any
of the optional clauses are selected.
environment-name-1
System devices or standard system actions taken by the compiler.
Table 3 shows the actions that are associated with mnemonic-names for
environment-name-1.
38 COBOL/400 Reference
SPECIAL-NAMES Paragraph
Table 3. Choices of Environment-Name-1 and Action Taken
Environment-name-1 Statement where
mnemonic-name asso-
ciated with
environment-name is
used
Usage
CSP WRITE Suppress spacing when printing a line. Use only when
PRINTER is the device.
C01 WRITE Skip to the next page. Use only when PRINTER is the
device.
ATTRIBUTE-DATA ACCEPT Retrieve attribute data about a program device
acquired by a transaction file, but only when the file is
open.
I-O-FEEDBACK ACCEPT Give information about the last I-O operation on a file,
but only when the file is open.
OPEN-FEEDBACK ACCEPT Give information about a file, but only when the file is
open.
CONSOLE,
SYSTEM-CONSOLE
ACCEPT, DISPLAY Communicate with the system operators message
queue (QSYSOPR).
LOCAL-DATA ACCEPT, DISPLAY Retrieve data from, or move data to the local data
area created by the system for every job.
PIP-DATA ACCEPT Retrieve data from the Program Initialization Parame-
ters (PIP) data area for programs running as part of a
prestart job.
REQUESTOR ACCEPT, DISPLAY Communicate with the user work station (interactive
jobs) or the batch input stream or job log (batch jobs).
SYSIN ACCEPT The equivalent of REQUESTOR (for the ACCEPT
statement only).
SYSOUT DISPLAY The equivalent of REQUESTOR (for the DISPLAY
statement only).
1 For more information regarding prestart jobs, see the Programming: Work
Management Guide, SC41-8078.
environment-name-2
Environment-name-2 can be defined as UPSI-0 through UPSI-7 or as
SYSTEM-SHUTDOWN.
User Program Status Indicator (UPSI): Environment-name-2 can define eight
one-byte program switches, UPSI-0 through UPSI-7.
Each UPSI is a User Program Status Indicator switch. UPSI-0 through UPSI-7 are
COBOL names that identify program switches defined outside the COBOL program
at object time. Their contents are considered to be alphanumeric. A value of zero
is off; a value of one is on.
Chapter 2. COBOL Program Structure 39
SPECIAL-NAMES Paragraph
Each switch represents one byte from the 8-character SWS parameter of the
control language CHGJOB, SBMJOB, JOB, and JOBD commands as follows:
UPSI-0 First byte (leftmost)
UPSI-1 Second byte
UPSI-2 Third byte
. .
. .
. .
UPSI-7 Eighth byte (rightmost)
SYSTEM-SHUTDOWN: SYSTEM-SHUTDOWN is an internal switch that is set to
ON status when the system operator causes the system to be in a shutdown-
pending state or when the job is being canceled in a controlled manner. The asso-
ciated ON or OFF condition-names can be referenced anywhere a condition-name
is valid. Their status cannot be altered by the program.
mnemonic-name-1
mnemonic-name-2
Mnemonic-name-1 and mnemonic-name-2 follow the rules of formation for user-
defined names. Mnemonic-name-1 can be used in ACCEPT, DISPLAY, and
WRITE statements. Mnemonic-name-2 can be referenced only in the SET
statement. Mnemonic-name-2 can qualify cond-1 or cond-2 names.
ON STATUS IS, OFF STATUS IS
UPSI switches process special conditions within a program, such as year-
beginning or year-ending processing. For example, at the beginning of the
Procedure Division, an UPSI switch can be tested; if it is ON, the special
branch is taken. (See Switch-Status Condition on page 176.)
cond-1, cond-2
Condition-names follow the rules for user-defined names. At least one
character must be alphabetic. The value associated with the condition-
name is considered to be alphanumeric. A condition-name may be
associated with the on status and/or off status of each UPSI switch
specified.
In the Procedure Division, the UPSI switch status is tested through the
associated condition-name. Each condition-name is the equivalent of a
level-88 item; the associated mnemonic-name, if specified, is consid-
ered the conditional variable and can be used for qualification.
40 COBOL/400 Reference
ALPHABET Clause
Coding Example
This coding example assigns mnemonic-names to some commonly used
environment-names in the SPECIAL-NAMES paragraph.
SPECIAL-NAMES. SYSTEM-CONSOLE IS SYSTM
REQUESTOR IS WORK-STATION
C1 IS NEXT-PAGE
LOCAL-DATA IS LOCAL-DATA-AREA
ATTRIBUTE-DATA IS ATTRB-DATA
SYSTEM-SHUTDOWN IS SHUTDOWN-SWITCH
ON STATUS IS SHUTDOWN-PENDING
UPSI- IS UPSI-SWITCH-
ON STATUS IS U-ON
OFF STATUS IS U-OFF
UPSI-1 IS UPSI-SWITCH-1
ON STATUS IS U1-ON
OFF STATUS IS U1-OFF
IBM-ASCII IS STANDARD-1
CURRENCY-SIGN IS "Y".
ALPHABET Clause
Format
ALPHABETalphabet-name-1 CODE SET
IS
CODE SET:
STANDARD-1
STANDARD-2
NATIVE
EBCDIC
literal-1
| | THROUGH literal-2
| THRU
ALSOliteral-3
ALPHABET alphabet-name-1 IS
Provides a means of relating an alphabet-name to a specified character code
set or collating sequence.
It specifies a collating sequence when used in either:
The PROGRAM COLLATING SEQUENCE clause of the
OBJECT-COMPUTER paragraph
The COLLATING SEQUENCE phrase of the SORT or MERGE statement.
It specifies a character code set when specified in the FD entry CODE-SET
clause.
The EBCDIC collating sequence is used when the alphabet-name clause is
omitted.
STANDARD-1
Specifies the ASCII character set.
Chapter 2. COBOL Program Structure 41
ALPHABET Clause
STANDARD-2
Specifies the International Reference Version of the ISO 7-bit code defined
in International Standard 646, 7-bit Coded Character Set for Information
Processing Interchange.
NATIVE
Specifies the native character code set. This is the equivalent to EBCDIC
for the OS/400 operating system.
EBCDIC
Specifies the EBCDIC character set.
literal-1, literal-2, literal-3
Specifies that the collating sequence is to be determined by the program,
according to the following rules:
The order in which literals appear specifies the ordinal number, in
ascending sequence, of the character(s) in this collating sequence.
Each numeric literal specified must be an unsigned integer and must
have a value from 1 through 256 (the maximum number of characters
in the EBCDIC character set). The value of each literal specifies the
relative position of a character within the EBCDIC character set. For
example:
literal 112 represents the EBCDIC character ?
literal 234 represents the EBCDIC character Z
literal 241 represents the EBCDIC numeric character 0.
Appendix D, EBCDIC and ASCII Collating Sequences on page 463,
lists the ordinal number for each character in the EBCDIC and ASCII
collating sequences.
Each character in a nonnumeric literal represents that actual character
in the EBCDIC character set. (If the nonnumeric literal contains more
than one character, each character, starting with the leftmost, is
assigned a successively ascending position within this collating
sequence.)
Any EBCDIC characters not explicitly specified assume positions in this
collating sequence higher than any of the explicitly specified characters.
The relative order of the unspecified characters remains unchanged
from the EBCDIC collating sequence.
Within one alphabet-name clause, a given character must not be speci-
fied more than once.
Each nonnumeric literal associated with a THROUGH or ALSO phrase
must be 1 character in length.
When the THROUGH phrase is specified, the contiguous EBCDIC
characters beginning with the character specified by literal-1 and ending
with the character specified by literal-2 are assigned successively
ascending positions in this collating sequence. This sequence may be
either ascending or descending within the original EBCDIC sequence.
For example, if the characters Z through S are specified, then for this
collating sequence the ascending values are: ZYXWVUTS.
42 COBOL/400 Reference
ALPHABET Clause
When the ALSO phrase is specified, the EBCDIC characters specified
as literal-1, literal-3, and so on, are assigned to the same position in
this collating sequence. For example, if you specify:
"D" ALSO "N" ALSO "%"
the characters D, N, and % are all considered to be in the same posi-
tion in the collating sequence.
If specified as literals in the SPECIAL-NAMES paragraph, the figurative
constants HIGH-VALUE and LOW-VALUE are associated with hex FF
and hex 00 respectively.
After all clauses in the SPECIAL-NAMES paragraph are processed, the
character having the highest ordinal position in this collating sequence
is associated with the figurative constant HIGH-VALUE. If more than
one character has the highest position, because of specification of the
ALSO phrase, the last character specified (or defaulted to when some
characters in the native collating sequence are not explicitly specified)
is considered to be the HIGH-VALUE character for procedural state-
ments such as DISPLAY, or as the sending field in a MOVE statement.
(If all characters within the native collating sequence were explicitly
specified, and the ALSO phrase example from above were specified as
the high-order characters of this collating sequence, the HIGH-VALUE
character would be %.)
After all clauses in the SPECIAL-NAMES paragraph are processed, the
character having the lowest ordinal position in this collating sequence
is associated with the figurative constant LOW-VALUE. If more than
one character has the lowest position, because of specification of the
ALSO phrase, the first character specified is the LOW-VALUE char-
acter. (If the ALSO phrase example given above were specified as the
low-order characters of the collating sequence, the LOW-VALUE char-
acter would be D.)
When literal-1, literal-2, or literal-3 is specified, the alphabet-name must
not be referred to in a CODE-SET clause (see CODE-SET Clause on
page 104).
Alphabet-Name Clause Examples: The following examples illustrate some uses
for the alphabet-name clause.
If PROGRAM COLLATING SEQUENCE IS USER-SEQUENCE; if the alphabet-
name clause is specified as USER-SEQUENCE IS D, E, F; and if two Data
Division items are defined as follows:
1 ITEM-1 PIC X(3) VALUE "ABC".
1 ITEM-2 PIC X(3) VALUE "DEF".
then the following comparison is true:
IF ITEM-1 > ITEM-2
Characters D, E, and F are in ordinal positions 1, 2, and 3 of this collating
sequence. Characters A, B, and C are in ordinal positions 197, 198, and 199 of
this collating sequence.
Chapter 2. COBOL Program Structure 43
CLASS Clause
If the alphabet-name clause is USER-SEQUENCE IS 1 THRU 247, 251 THRU 256,
7, ALSO 8, ALSO 9; if all 256 EBCDIC characters have been specified; and if
the two Data Division items are specified as follows:
1 ITEM-1 PIC X(3) VALUE HIGH-VALUE.
1 ITEM-2 PIC X(3) VALUE "787".
then both of the following comparisons are true:
IF ITEM-1 = ITEM-2 . . .
IF ITEM-2 = HIGH-VALUE . . .
They compare as true because the values 7, 8, and 9 all occupy the same
position (HIGH-VALUE) in this USER-SEQUENCE collating sequence.
If the alphabet-name clause is specified as USER-SEQUENCE IS E, D, F and
a table in the Data Division is defined as follows:
5 TABLE A OCCURS 6 ASCENDING KEY IS
KEY-A INDEXED BY INX-A.
1 FIELD-A ...
1 KEY-A ...
and if the contents in ascending sequence of each occurrence of KEY-A are A, B,
C, D, E, G, then the results of the execution of a SEARCH ALL statement for this
table will be invalid because the contents of KEY-A are not in ascending order.
The proper ascending order would be E, D, A, B, C, G.
CLASS Clause
CLASSclass-name-1literal-4
IS THROUGHliteral-5
THRU
Figure 17. Format
CLASS class-name-1 IS
Provides a means for relating a name to the specified set of characters listed in
that clause. Class-name can be referenced only in a class condition. The
characters specified by the values of the literals in this clause define the exclu-
sive set of characters of which this class-name consists.
literal-4, literal-5
If numeric, must be unsigned integers and must have a value from 1 through
256 (the maximum number of characters in the EBCDIC character set).
The value of each literal specifies the relative position, or ordinal number, of a
character within the EBCDIC character set. Appendix D, EBCDIC and ASCII
Collating Sequences on page 463 lists the ordinal number for each character
in the EBCDIC collating sequence.
If nonnumeric, the literal is the actual character within the EBCDIC character
set. If the value of the nonnumeric literal contains multiple characters, each
44 COBOL/400 Reference
DECIMAL-POINT Clause
character in the literal is included in the set of characters identified by class-
name.
If the nonnumeric literal is associated with a THROUGH phrase, it must be one
character in length.
THROUGH, THRU
THROUGH and THRU are equivalent. If THROUGH is specified, class-
name includes those characters beginning with the value of literal-4 and
ending with the value of literal-5. In addition, the characters specified by a
THROUGH phrase may specify characters in either ascending or
descending order.
CURRENCY SIGN Clause
CURRENCYliteral-6
SIGN IS
Figure 18. Format
CURRENCY SIGN IS
Currency symbol in the PICTURE clause.
literal-6
Must be a one-character, nonnumeric literal, and must not be any of the fol-
lowing:
Digits zero (0) through nine (9)
Uppercase alphabetic characters A B C D P R S V X Z
Lowercase alphabetic characters a through z
The space
Special characters * + - / , . ; ( ) = ".
A figurative constant.
When the CURRENCY SIGN clause is omitted, only the dollar sign ($) may be
used as the PICTURE symbol for the currency sign.
DECIMAL-POINT Clause
DECIMAL-POINTCOMMA
IS
Figure 19. Format
Exchanges the functions of the period and the comma in PICTURE character
strings and in numeric literals.
Chapter 2. COBOL Program Structure 45
IBM Extension
CONSOLE Clause
CONSOLECRT
IS
Figure 20. Format
If CONSOLE IS CRT is present, any ACCEPT or DISPLAY statement that has no
phrases specific to a particular format (such as LOCAL-DATA or PIP-DATA), is
treated as an extended ACCEPT or DISPLAY statement.
If CONSOLE IS CRT is not present, any ACCEPT or DISPLAY statement that has
no phrases specific to a particular format is treated as a standard ANSI X3.23-1985
COBOL ACCEPT or DISPLAY statement.
See the Workstation I/O on page 204 and the Format 3 Extended DISPLAY
Statement on page 253 for descriptions of the conditions which determine whether
ACCEPT or DISPLAY statements are extended or standard.
CURSOR Clause
CURSORdata-name-1
IS
Figure 21. Format
CURSOR IS data-name-1
Specifies the data item that will contain the cursor address used by the
ACCEPT statement.
data-name-1
Must be a 4- or 6-byte alphanumeric field or a 4- or 6-byte unsigned zoned
integer field. If data-name-1 is 4 characters in length, the first two characters
are interpreted as line number, and the second two as column number. If
data-name-1 is 6 characters in length, the first three characters are interpreted
as line number, and the second three as column number.
The clause has no effect if data-name-1 contains an invalid position value
(such as zeros, a nonnumeric value, or a value that is beyond the range of the
screen).
46 COBOL/400 Reference
Data-name-1 must be declared in the WORKING-STORAGE SECTION of the
program.
CURSOR Clause Considerations
At the start of an extended ACCEPT operation, if data-name-1 contains a value that
is a valid character position on the screen, that position is used as the initial posi-
tion for the cursor. A valid position is a coordinate that lies on the screen (that is,
within the range from line 1, column 1, to line 24, column 80). After the ACCEPT
operation, if the position in data-name-1 was valid, data-name-1 is updated to show
the position of the cursor at the end of the operation.
If the CURSOR IS identifier contains an invalid value (such as spaces, low-values,
high-values or a value outside of the screen range), the cursor is positioned at the
start of the first input field that is active on the screen.
CURSOR IS has no effect on the positioning of fields on the screen.
CRT STATUS Clause
CRT STATUSdata-name-2
IS
Figure 22. Format
CRT STATUS IS data-name-2
Specifies a data item into which a status value is moved after an extended
ACCEPT statement.
data-name-2
Must be described in the WORKING-STORAGE SECTION and must be a
6-byte alphanumeric field or a 6-byte unsigned zoned integer.
CRT STATUS Clause Considerations
If the CRT STATUS clause is specified in the SPECIAL-NAMES paragraph, every
extended ACCEPT statement places a value into data-name-2 to indicate the
outcome of the ACCEPT operation. Data-name-2 consists of status keys which are
set to indicate possible conditions resulting from the completion of the operation.
CRT Status Key 1: The first two bytes of data-name-2 form CRT Status Key 1
and should be described as PIC 99. It indicates the condition that caused the ter-
mination of the ACCEPT operation. The possible values are:
0 Indicates a terminating key such as an enter key, or an auto skip from the final
field
1 Indicates a function key
9 Indicates an error
Chapter 2. COBOL Program Structure 47
A termination that returns a value of 0 is a normal completion (normal termination).
If the ACCEPT statement contains an ON EXCEPTION phrase, any value in CRT
Status Key 1, except 0, will cause the execution of the imperative statement in the
ON EXCEPTION phrase.
CRT Status Key 2: The next two bytes of data-name-2 form CRT Status Key 2,
and contain a code giving further details of the condition that terminated the
ACCEPT operation. Its format and possible values depend on the value in CRT
Status Key 1, as shown in the following table.
CRT Status Key 3: The last two bytes of data-name-2 form CRT Status Key 3. If
CRT Status Key 1 is 0, CRT Status Key 3 contains the code for the keyboard key
that terminated the ACCEPT operation. Otherwise, if CRT Status Key 1 is 9, an
error is signaled by the operating system, and CRT Status Key 3 will be set to 99.
Table 4. Valid Combinations of CRT STATUS Keys 1 and 2
KEY 1 KEY 2 Meaning
Format Value
0 PIC 99 0 The operator pressed a
terminating key
0 PIC 99 1 Auto skip from the last
field
1 PIC 99 1-24 The function key number
9 PIC 99 0 Error condition (no items
fall within the screen)
Note: When auto skip from the last field takes place, the value of 1 for CRT STATUS
KEY 2 is returned to supported controllers, and the value of 0 is returned to those controllers
not supported. This relationship is shown in Table 5.
Table 5. Auto Skip Value Returned by Controller Type
Type of Controller Auto Skip Value of 1 Returned
AS/400 controllers:
Local workstation controllers
Remote 5251 model 12
Remote 5294
Remote 5394
Remote 3174
Remote 3274
Yes
Not applicable
No
Yes, if installed with new workstation
controller code
No, with *NOUNDSPCHR option
No, with *NOUNDSPCHR option
PC attachments:
DOS and OS/2
*
operating
environments
No
System to system passthru:
AS/400 system to AS/400 system
System/36 to AS/400 system
System/38 to AS/400 system
Yes
No
No
48 COBOL/400 Reference
The codes for the keys are:
00 Enter key
90 Roll up key
91 Roll down key
92 Print key
93 Help key
94 Clear key
95 Home key
End of IBM Extension
Chapter 2. COBOL Program Structure 49
50 COBOL/400 Reference
Environment DivisionInput-Output Section
Chapter 3. Environment DivisionInput-Output Section
The Input-Output Section defines each file, identifies its external storage medium,
assigns the file to one or more input/output devices, and also specifies information
needed for efficient transmission of data between the external medium and the
COBOL program.
File Categories
The AS/400 system has four categories of files: database files, device files, DDM
files, and save files.
This manual uses the term file to mean any of these files.
Database Files
Database files allow information to be permanently stored on the system. Multiple
programs can access this information in different ways.
A database file is subdivided into groups of records called members.
There are two types of database files: physical files and logical files.
Physical Files: A physical file is a file that actually contains data records. This
makes physical files similar to disk files on other systems. A physical file can
contain only fixed-length records, all of which have the same format.
Logical Files: A logical file is a database file through which data from one or
more physical files can be accessed. The format and organization of this data is
different from that of the data in the physical file(s). Each logical file can define a
different access path (index) for the data in the physical file(s). Each logical file
can exclude and reorder the fields defined in the physical file(s).
Device Files
A device file reads from or writes to a device or remote system. A device file con-
trols the transfer of data between the physical device or remote system and the
program.
DDM Files
Distributed Data Management (DDM) allows you to access data that reside on
remote systems that support DDM. DDM files are supported by the COBOL com-
piler. You can retrieve, add, update, or delete data records in a file that resides on
another system.
When you compile a source program that is on a remote system, the COBOL/400
compiler expects a source type of CBL. If the source type is not CBL, the compiler
issues a message indicating that it encountered an unexpected source member
type. To resolve this discrepancy, you should recompile the program in the envi-
ronment indicated by the source member type, or change the source member type,
or use the correct compiler indicated by the source member type.
For more information about accessing remote files, refer to the DDM Guide.
Copyright IBM Corp. 1994 51
Environment DivisionInput-Output Section
Save Files
A save file is a file that is used to prepare data in a format that is correct for
backup and recovery purposes or for transportation to another system. A save file
can be used to contain the output that is produced from the Save Library (SAVLIB)
or Save Object (SAVOBJ) CL commands. See the Data Management Guide for
information about save files.
Paragraphs
The Input-Output section of the Environment Division contains two paragraphs:
FILE-CONTROL paragraph
I-O-CONTROL paragraph.
1
INPUT-OUTPUT SECTION. FILE-CONTROL. file-control-entry :
1
:
IOCONTROL.
input-output-control-entry.
Figure 23. Format
FILE-CONTROL paragraph
Names and associates the files with the external media.
The key word FILE-CONTROL may appear only once, at the beginning of the
FILE-CONTROL paragraph. It must begin in Area A, and be followed by a sep-
arator period.
file-control-entry
Must begin in Area B with a SELECT clause. It must end with a separator
period. See FILE-CONTROL Paragraph on page 53.
I-O-CONTROL paragraph
Specifies information needed for efficient transmission of data between external
media and the COBOL program.
input-output-control-entry
The series of entries must end with a separator period. See
I-O-CONTROL Paragraph on page 70.
The exact contents of the Input-Output Section depend on the file organization and
access methods used. See ORGANIZATION Clause on page 61 and ACCESS
MODE Clause on page 62.
52 COBOL/400 Reference
FILE-CONTROL Paragraph
FILE-CONTROL Paragraph
The FILE-CONTROL paragraph associates each file in the COBOL program with
an external medium, and specifies file organization, access mode, and other infor-
mation.
COBOL allows for four distinct kinds of file input and output:
Sequential
Indexed
Relative
IBM Extension
Transaction
End of IBM Extension
The FILE-CONTROL paragraph begins with the word "FILE-CONTROL", followed
by a separator period. It must contain one and only one entry for each file
described in an FD or SD entry in the Data Division. Within each entry, the
SELECT clause must appear first. The other clauses may appear in any order.
Each data-name must appear in a Data Division data description entry. Each data-
name can be qualified but cannot be subscripted or indexed.
Chapter 3. Environment DivisionInput-Output Section 53
FILE-CONTROL Paragraph
FILE-CONTROL.SELECTfile-name
OPTIONAL
ASSIGNassignment-name-1
TO literal-1
RESERVEinteger
AREA
AREAS
SEQUENTIAL
ORGANIZATION
IS
ACCESSSEQUENTIAL
MODE IS
.
STATUSdata-name-1
FILE IS
data-name-5
Figure 24. Format 1 - Sequential
54 COBOL/400 Reference
FILE-CONTROL Paragraph
FILE-CONTROL.SELECTfile-name
ASSIGNassignment-name-1
TO literal-1
RESERVEinteger
AREA
AREAS
INDEXED
ORGANIZATION
IS
ACCESSSEQUENTIAL
MODE IS RANDOM
DYNAMIC
RECORDEXTERNALLY-DESCRIBED-KEY
KEY IS
data-name-2
DUPLICATES
WITH
.
STATUSdata-name-1
FILE IS
data-name-5
Figure 25. Format 2 - Indexed
Chapter 3. Environment DivisionInput-Output Section 55
FILE-CONTROL Paragraph
FILE-CONTROL.SELECTfile-name
ASSIGNassignment-name-1
TO literal-1
RESERVEinteger
AREA
AREAS
RELATIVE
ORGANIZATION
IS
1
ACCESS :
MODE IS
1
: SEQUENTIAL
RELATIVEdata-name-4
KEY IS
RANDOMRELATIVEdata-name-4
DYNAMIC KEY IS
.
STATUSdata-name-1
FILE IS
data-name-5
Figure 26. Format 3 - Relative
SELECTfile-nameASSIGNassignment-name-1
TO literal-1
Figure 27. Format 4 - Sort or Merge
56 COBOL/400 Reference
SELECT Clause
SELECTfile-nameASSIGNassignment-name-1
TO literal-1
TRANSACTION
ORGANIZATION
IS
ACCESSSEQUENTIAL
MODE IS DYNAMICRELATIVEdata-name-3
KEY IS
STATUSdata-name-1
FILE IS data-name-5
.
CONTROL-AREAdata-name-6
IS
Figure 28. Format 5 - Transaction
See the chapter on Transaction Files in the COBOL/400 Users Guide for more
information on working with transaction files.
SELECT Clause
The SELECT clause chooses a file.
SELECT OPTIONAL (Format 1)
May be specified only for sequential files opened in the input, I-O, or extend
mode. You must specify SELECT OPTIONAL for such input files that are not
necessarily present each time the object program is executed.
file-name
Must be identified by an FD or SD entry in the Data Division. A file-name must
conform to the rules for a COBOL user-defined name, must contain at least
one alphabetic character, and must be unique within this program.
When file-name specifies a sort or a merge file, only the ASSIGN clause may follow
the SELECT clause.
Chapter 3. Environment DivisionInput-Output Section 57
ASSIGN Clause
ASSIGN Clause
ASSIGNassignment-name-1
TO literal-1
Figure 29. Format
The ASSIGN clause associates a file with an external medium.
For sort or merge files (associated with an SD entry), no external medium is used.
The related ASSIGN clause is only validity checked. It is not actually used for I-O.
assignment-name-1
literal-1
The assignment-name or literal makes the association between the file and the
external medium.
Any assignment-name or literal after the first is syntax checked, but has no
effect on the execution of the program
Assignment-name-1 or literal-1 consists of 3 parts:
Device
File name
Attribute.
It has the following general structure:
device -file-name
-attribute
Figure 30. Format
Device: This part specifies the type of device that the file will use. The compiler
can then check whether the file is described and used in a consistent manner. See
the COBOL/400 Users Guide for further information.
Notes:
1. The compiler does not check whether the device associated with the external
file is of the type specified in the device portion of assignment-name-1 or
literal-1.
2. The compiler provides no diagnostics unless the I-O verbs were used in an
inconsistent manner.
3. When the program runs, the operating system could either issue an escape
message or ignore the function if it was not applicable to the device. See the
Data Management Guide for further information on overriding files.
58 COBOL/400 Reference
ASSIGN Clause
IBM Extension
The device that the file will use can be changed at run time with the OVRxxxF CL
command. To ensure consistent results, the device type associated with the file
should correspond to that given in the assignment-name.
End of IBM Extension
Device can be any of the following:
PRINTER should be specified for program described printer files only.
FORMATFILE should be specified for externally described printer files only.
For more information on how to use externally described printer files see the
section on FORMATFILE Files in the COBOL/400 Users Guide.
When DISK is the device, database extensions cannot be used. See the
COBOL/400 Users Guide for more information about DISK files.
When DATABASE is the device, externally described data and database exten-
sions can be used. However these file types are not supported for dynamic file
creation. See the OPEN Statement on page 303 for information about
Dynamic Files. See the COBOL/400 Users Guide for more information about
DATABASE files .
See the OPEN Statement on page 303 for information about Dynamic Files.
File Name: This part of assignment-name must be an unhyphenated, 1- through
10-character system name of the actual external file (physical or logical database,
or device). This external file has to be created before compiling the program only
when it is used by a COPY statement, DDS (data description specifications) or DD
format, within this program.
For database files, the member name cannot be specified in the program. If a
member other than the first member is to be specified, the Override with Database
File (OVRDBF) CL command must be used at execution time to specify the
member name.
This file name is the name of the AS/400 object that is displayed by the Display
Program References (DSPPGMREF) command. Since no external medium is used
for an SD file, the DSPPGMREF command does not list any files defined for an SD
file.
Device Associated File
PRINTER Printer file
FORMATFILE Printer file
TAPEFILE Tape file
DISKETTE Diskette file
DISK Any physical database file or single format
logical database file
DATABASE^ Any database file (or DDM file)
WORKSTATION Display file or ICF file
Chapter 3. Environment DivisionInput-Output Section 59
RESERVE Clause
The file name can be changed at execution time with the TOFILE parameter of the
OVRxxxF CL command. To ensure consistent results, the device type associated
with the TOFILE parameter should be the same as that specified for
assignment-name-1 or literal-1.
Attribute: This part of assignment-name-1 or literal-1 can be SI. SI indicates that
a separate indicator area has been specified in the DDS for a FORMATFILE or
WORKSTATION file.
See the COBOL/400 Users Guide for details on the use of the SI attribute and
further information about the ASSIGN clause.
The valid entries for each field of assignment-name-1 or literal-1 vary with the
device. The valid combinations of fields are shown in Figure 31.
Device
File
Name
Default
File Name
SI
PRINTER O QPRINT N
FORMATFILE R O
TAPEFILE O QTAPE N
DISKETTE O QDKT N
DISK R N
DATABASE R N
WORKSTATION R O
R=Required
O=Optional
N=Not Allowed
Figure 31. Valid Entries for Assignment-Name-1 and Literal-1
RESERVE Clause
RESERVEinteger
AREA
AREAS
Figure 32. Format
The RESERVE clause reserves input-output areas.
The RESERVE clause is syntax-checked, but is treated as documentation.
60 COBOL/400 Reference
ORGANIZATION Clause
ORGANIZATION Clause
The ORGANIZATION clause specifies the logical structure of the file. The file
organization is established at the time the file is created and cannot subsequently
be changed. When the ORGANIZATION clause is omitted, ORGANIZATION IS
SEQUENTIAL is assumed.
IBM Extension
For database files, the ORGANIZATION clause indicates the current program
usage of the file in the program. Therefore, the same database file can use
SEQUENTIAL, INDEXED (assuming a keyed sequence access path exists), or
RELATIVE in the ORGANIZATION clause. This is true regardless of what is speci-
fied in other programs that use this file.
Note: A keyed sequence access path is always created when a key is specified in
the DDS that was used as input to the Create Physical File (CRTPF) or the Create
Logical File (CRTLF) CL command.
End of IBM Extension
ORGANIZATION IS SEQUENTIAL (Format 1): A predecessor-successor relation-
ship of the records in the files is established by the order in which records are
placed in the file when it is created or extended (arrival sequence access path).
ORGANIZATION IS INDEXED (Format 2): The position of each logical record in
the file is determined by the key sequence access path created with the file and
maintained by the system. The access path is based on an embedded key within
the files records.
ORGANIZATION IS RELATIVE (Format 3): The position of each record in the file
is determined by its relative record number within the arrival sequence access path.
IBM Extension
ORGANIZATION IS TRANSACTION (Format 5): Signifies interaction between a
COBOL program and either a work station user or another system. For more infor-
mation on transaction files, see the COBOL/400 Users Guide.
End of IBM Extension
Chapter 3. Environment DivisionInput-Output Section 61
ACCESS MODE Clause
ACCESS MODE Clause
The ACCESS MODE clause defines the manner in which the records of the file are
made available for processing. If the ACCESS MODE clause is not specified,
sequential access is assumed.
ACCESS MODE IS SEQUENTIAL
Can be specified in all three formats.
Format 1Sequential
Records in the file are accessed in the sequence established when the file
was created or extended (arrival sequence). Format 1 supports only
sequential access.
Format 2Indexed
Records in the file are accessed in the sequence of ascending record key
values according to the collating sequence of the file.
IBM Extension
When using an externally described file, if the DDS keyword DESCEND is
used when the field is specified as a key field, the records in the file are
accessed in the sequence of descending record key values within the
index. Either the DESCEND keyword, or the ASCEND keyword (if
DESCEND is not specified) appears under the heading RETRIEVAL in a
comment table in the COBOL source program listing.
End of IBM Extension
Format 3Relative
Records in the file are accessed in the ascending sequence of relative
record numbers of existing records in the file.
ACCESS MODE IS RANDOM
Can be specified in Formats 2 and 3 only.
Format 2Indexed
The value placed in a record key data item specifies the record to be
accessed.
Format 3Relative
The value placed in a relative key data item specifies the record to be
accessed.
ACCESS MODE IS DYNAMIC
Can be specified in Formats 2 and 3 only.
Format 2Indexed
Records in the file may be accessed sequentially or randomly, depending
on the form of the specific input-output request.
Format 3Relative
Records in the file may be accessed sequentially or randomly, depending
on the form of the specific input-output request.
62 COBOL/400 Reference
ACCESS MODE Clause
Data Organization and Access Modes
Data organization is the permanent logical structure of the file. You tell the com-
puter how to retrieve records from the file by specifying the access mode. In
COBOL you can specify any of four types of data organization, and three access
modes. The COBOL/400 Users Guide shows which clauses and statements are
required, and which clauses and statements are optional for each access mode and
device. See the COBOL/400 Users Guide for information about COBOL file proc-
essing in relation to AS/400 file processing.
Note: Sequentially organized data may only be accessed sequentially; however,
data that has indexed or relative organization may be accessed with any of the
three access methods.
Data Organization
In a COBOL program, data organization can be sequential, indexed, relative, or
TRANSACTION.
Records can be fixed or variable in length. For all files other than tape, variable
length records are stored as fixed length records of the maximum size specified for
the file.
Sequential Organization: The physical order in which the records are placed in
the file determines the sequence of records. The relationships among records in
the file do not change, except that the file can be extended. There are no keys.
Both database files and device files can have sequential organization.
Each record in the file, except the first, has a unique predecessor record, and each
record, except the last, also has a unique successor record.
Indexed Organization: Each record in the file has an embedded key called a key
data item that is associated with an index. An index provides a logical path to the
data records, according to the contents of the associated embedded record key
data items. Only database files can have indexed organization.
Each record in an indexed file must have an embedded prime key data item.
When records are inserted, updated, or deleted, they are identified solely by the
values of their prime keys. Thus, the value in each prime key data item must be
unique and must not be changed when the record is updated. You tell COBOL the
name of the prime key data item on the RECORD KEY clause of the
FILE-CONTROL paragraph.
IBM Extension
A logical file that is opened for OUTPUT does not remove all records in the phys-
ical file on which it is based. Instead, the file is opened to allow only write oper-
ations, and the records are added to the file.
End of IBM Extension
Relative Organization: Think of the file as a string of record areas, each of which
contains a single record. Each record area is identified by a relative record
number; the access method stores and retrieves a record, based on its relative
record number. For example, the first record area is addressed by relative record
Chapter 3. Environment DivisionInput-Output Section 63
ACCESS MODE Clause
number 1, and the 10th is addressed by relative record number 10. The physical
sequence in which the records were placed in the file has no bearing on the record
area in which they are stored, and thus on each record's relative record number.
Relative files must be assigned to DISK or DATABASE.
Table 6 summarizes conditions affecting relative output files.
To extend a file boundary beyond the current number of records and within the file
size, use the INZPFM command to add deleted records before processing the file.
You will need to do this when more records need to be added to the file, and file
status 0Q has been received.
Any attempt to extend a relative file beyond its current size results in a boundary
violation.
To recover from a file status of 9Q, use the CHGPF command as described in the
associated run-time message text.
Relative record number processing can be used for a physical file or for a logical
file that is based on only one physical file.
IBM Extension
TRANSACTION Organization: Work station and data communication files can
have TRANSACTION organization. See the Transaction Files chapter in the
COBOL/400 Users Guide for a discussion of using this organization.
End of IBM Extension
Table 6. Initialization of Relative Output Files
File Access and
CL Specifications
Conditions at
Opening Time
Conditions at
Closing Time
File Boundary
Sequential
*INZDLT
Records not
written are
initialized
All increments
Sequential
*INZDLT
*NOMAX size
CLOSE succeeds
File status is 0Q
Up to boundary of
records written
Sequential
*NOINZDLT
Up to boundary of
records written
Random or
dynamic
Records are
initialized
File is open
All increments
Random or
dynamic
*NOMAX size
OPEN fails
File status is 9Q
File is empty
64 COBOL/400 Reference
ACCESS MODE Clause
Access Modes
Access mode is a COBOL term that defines the manner in which data in a logical
or physical file is to be processed. The three access modes are sequential,
random, and dynamic.
Sequential-Access Mode: Allows reading and writing records of a file in a serial
manner; the order of reference is implicitly determined by the position of a record in
the file.
Random-Access Mode: Allows reading and writing records in a programmer-
specified manner; the control of successive references to the file is expressed by
specifically defined keys supplied by the user.
Dynamic-Access Mode: Allows a specific input-output request to determine the
access mode. Therefore, records may be processed sequentially and/or randomly.
Relationship Between Data Organizations and Access Modes
Sequential Files: Files with sequential organization can be accessed only
sequentially. The sequence in which records are accessed is the order in which
the records were originally written.
Indexed Files: All three access modes are allowed.
In the sequential access mode, the sequence in which records are accessed is
determined by the prime record key value.
In the random access mode, you control the sequence in which records are
accessed. The desired record is accessed by placing the value of its record key in
that record key data item.
In the dynamic access mode, you may change, as necessary, from sequential
access to random access, using appropriate forms of input-output statements.
Relative Files: All three access modes are allowed.
In the sequential access mode, the sequence in which records are accessed is the
ascending order of the relative record numbers of all records that currently exist
within the file.
In the random access mode, you control the sequence in which records are
accessed. The desired record is accessed by placing its relative record number in
a RELATIVE KEY data item; the RELATIVE KEY must not be defined within the
record description entry for this file.
In the dynamic access mode, you may change, as necessary, from sequential
access to random access, using the appropriate forms of input-output statements.
IBM Extension
Transaction Files: See the Transaction Files chapter in the COBOL/400 Users
Guide for a discussion of access mode considerations for transaction files.
End of IBM Extension
Chapter 3. Environment DivisionInput-Output Section 65
RECORD KEY Clause
RECORD KEY Clause
The RECORD KEY clause (Format 2) must be specified for an indexed file. The
RECORD KEY clause specifies the data item within the record that is the record
key for an indexed file. Each record in the file must have a unique record key
value.
RECORDEXTERNALLY-DESCRIBED-KEY
KEY IS
data-name-2
DUPLICATES
WITH
Figure 33. Format
IBM Extension
The DUPLICATES phrase can only be specified for files assigned to DATABASE.
This allows the file to have keys with the same values. If the file has multiple
formats, two keys in different formats have the same values only when the key
lengths and the contents of the keys are the same.
For example, given a file with the following two formats:
Format F1 with keys A, B, C
Format F2 with keys A, B, D.
If fields C and D are the same length, have the same data type, and have the
same values, the file would contain two records with a duplicate key. The term
duplicate key applies only to a complete record key for the format. A record key for
the format consists of the key field(s) defined for a DDS format for records residing
on the database. The term does not apply to the common key for the file (only
fields A and B in the above example).
Users can indicate DUPLICATES on the RECORD KEY clause. A file status of 95
is returned after a successful open when:
The DUPLICATES phrase is specified in the COBOL program and the file was
created with UNIQUE specified in DDS.
The DUPLICATES phrase is not specified in the COBOL program and the file
was created allowing nonunique keys.
Processing files when either of these conditions exist can cause unpredictable
results.
In a file that allows duplicates and is processed randomly or dynamically, the dupli-
cate record that is updated or deleted must be the proper one. To ensure this, the
66 COBOL/400 Reference
RECORD KEY Clause
last input/output statement processed prior to the REWRITE or DELETE operation
must be a successfully processed READ statement without the NO LOCK phrase.
If the DDS file level keyword LIFO (last-in-first-out) is specified, the duplicate
records within a physical file are retrieved in a last-in-first-out order.
End of IBM Extension
data-name-2
Data-name-2 is the RECORD KEY data item. It must be described as a fixed-
length alphanumeric item within a record description entry associated with the
file. The length of the record key is restricted; the key length, in bytes, cannot
exceed 2 000. See the DDS Reference for more information. Data-name-2
may be qualified, but it must not be subscripted.
IBM Extension
The RECORD KEY data item, data-name-2, can be a numeric item when the
file is assigned to a DATABASE device type. The numeric item can have a
usage of DISPLAY, COMP (COMP-3), COMP-4, PACKED-DECIMAL, or
BINARY.
Depending on the keywords specified for the data item in DDS, the keyed
sequence access path can be by algebraic value. See the ABSVAL, DIGIT,
SIGNED, and ZONE keywords in the DDS Reference. If one of these
keywords is specified, its name appears in a comment table in the COBOL
source listing under the heading TYPE. If no keyword is specified, the table
entry is the data type specified in DDS. The table entry AN indicates that the
data type is alphanumeric (specified in DDS as A). The table entry N indicates
that the data type is numeric (specified in DDS as P, S, or B).
The keywords specified for the data item in DDS can modify record sequence.
See the ALTSEQ, DIGIT, and ZONE keywords in the DDS Reference. If none
of these keywords are specified, the records are ordered according to the
EBCDIC collating sequence.
End of IBM Extension
The keys are ordered within the collating sequence used when the file was
created.
The data description of data-name-2 and its relative location within the record
must be the same as the ones used when the file was defined in DDS.
The record description that defines data-name-2 will always be used to access
the record key field for the I-O operation.
IBM Extension
The reserved word EXTERNALLY-DESCRIBED-KEY can specify that the keys
for this file are those that are externally described in DDS. The keys are deter-
mined by the record formats that are copied by the COPY statement, DDS, DD,
DDSR, or DDR format, under the FD for this file.
Chapter 3. Environment DivisionInput-Output Section 67
RELATIVE KEY Clause
The key can start at different offsets within the buffer for each format. In this
situation, care must be used when changing from one record format to another,
using a random READ or START statement. The key must be placed in the
record format at the correct offset in the format that will be used in the random
access of the file. Unpredictable results can occur if the key for the desired
record is based on data that was part of the last record read. This is because
the movement of the data to the key field can involve overlapping fields.
The key within a format can be made up of multiple, noncontiguous (not adja-
cent) fields. Only those record formats copied in within the FD for the file
should be referenced by the FORMAT phrase. If a format is referenced that is
defined within the file, but that format has not been copied into the program,
the key is built using the key fields defined for the first record format that was
copied. This can cause unpredictable results.
If a portion of the key is declared in the logical file only as an element of a
concatenated item (rather than an independently-declared item), the result of
the CONCAT operation must not be a variable-length item.
End of IBM Extension
RELATIVE KEY Clause
The RELATIVE KEY clause (Format 3) identifies a data-name that specifies the
relative record number for a specific logical record within a relative file.
RELATIVEdata-name-4
KEY IS
Figure 34. Format
data-name-4
Must be defined as an unsigned integer data item whose description does not
contain the PICTURE symbol P. Data-name-4 must not be defined in a record
description entry associated with this relative file. That is, the RELATIVE KEY
is not part of the record.
Data-name-4 is required for ACCESS IS SEQUENTIAL only when the START
statement is to be used. It is always required for ACCESS IS RANDOM and
ACCESS IS DYNAMIC. When the START statement is issued, the system
uses the contents of the RELATIVE KEY data item to determine the record at
which sequential processing is to begin.
If a value is placed in data-name-4, and a START statement is not issued, the
value is ignored and processing begins with the first record in the file.
68 COBOL/400 Reference
FILE STATUS Clause
IBM Extension
When the file is opened, the POSITION parameter on the OVRDBF CL
command can be used to set the file position indicator. This causes processing
to begin with a record other than the first record. See the CL Reference for
further information.
End of IBM Extension
If a relative file is to be referenced by a START statement, you must specify
the RELATIVE KEY clause for that file.
The ACCESS MODE IS RANDOM clause must not be specified for file-names
specified in the USING or GIVING phrase of a SORT or MERGE statement.
Refer to the Transaction File chapter in the COBOL/400 Users Guide for trans-
action file considerations.
FILE STATUS Clause
The FILE STATUS clause monitors the execution of each input-output request for
the file.
When the FILE STATUS clause is specified, the system moves a value into the
status key data item after each input-output request that explicitly or implicitly refers
to this file. The value indicates the status of execution of the statement. (See the
Status Key description under Common Processing Facilities on page 191.)
If you specify this clause at all, specify it for all files in a given program. For more
information, see the chapter on exception and error handling in the COBOL/400
Users Guide.
When the compiler generates code to block output records or unblock input
records, file status values that are caused by OS/400 exceptions are set only when
a block is processed. See Appendix F, File Structure Support Summary and
Status Key Values for a description of the possible values. See the COBOL/400
Users Guide for more information on blocking output records and unblocking input
records.
.
STATUSdata-name-1
FILE IS
data-name-5
Figure 35. Format
data-name-1
The status key data item must be defined in the Data Division as a 2-character
alphanumeric item. Data-name-1 must not be defined in the File Section.
Chapter 3. Environment DivisionInput-Output Section 69
I-O-CONTROL Paragraph
IBM Extension
data-name-1
The status key data item may also be defined in the Data Division as a
2-character numeric item, that is an unsigned integer with explicit or implicit
USAGE IS DISPLAY. It is treated as an alphanumeric item.
data-name-5
An optional status key data item may be specified for transaction and non-
transaction file processing. See the COBOL/400 Users Guide for more infor-
mation about using transaction files.
For non-transaction files, the data item must be a 6-byte group item. The item
is treated as documentation for all non-transaction files except for those that
are dynamically created.
For transaction files, the data item must be a 4-character alphanumeric item.
End of IBM Extension
I-O-CONTROL Paragraph
The I-O-CONTROL paragraph of the INPUT-OUTPUT SECTION specifies when
checkpoints are to be taken and the storage areas to be shared by different files.
This paragraph is optional in a COBOL program.
The key word I-O-CONTROL may appear only once, at the beginning of the para-
graph. The word I-O-CONTROL must begin in Area A, and must be followed by a
separator period.
Each clause within the paragraph may be separated from the next by a separator
comma or a separator semicolon. The order in which I-O-CONTROL paragraph
clauses are written is not significant. The I-O-CONTROL paragraph ends with a
separator period.
70 COBOL/400 Reference
I-O-CONTROL Paragraph
I-O-CONTROL. 1
:
1 1
=
: :
RERUN :
ONfile-name-1
assignment-name-1
1 1
=
: :
: integer-1RECORDSfile-name-2
EVERY OF
1 1
: :
SAME-file-name-3file-name-4
| RECORD AREA FOR
(continued on next page)
Figure 36 (Part 1 of 2). Format 1-Sequential Files
Chapter 3. Environment DivisionInput-Output Section 71
I-O-CONTROL Paragraph
(continued from previous page)
1 1
: :
MULTIPLE FILEfile-name-5
TAPE CONTAINS POSITIONinteger-2
1
: .
COMMITMENT CONTROLfile-name-6
FOR
1
: .
COMMITMENT CONTROLfile-name-6
FOR
WORKINGSTORAGE SECTION.
recorddescriptionentry
dataitemdescriptionentry
LINKAGE SECTION.
recorddescriptionentry
dataitemdescriptionentry
Figure 40. Format
Copyright IBM Corp. 1994 79
Data Division Structure
File Section
The File Section describes:
All externally stored files
Each sort-merge file.
The File Section must begin with the header FILE SECTION, followed by a sepa-
rator period.
FILE SECTION.
file-description-entryrecord-description-entry
Figure 41. Format
file-description-entry
Represents the highest level of organization in the File Section. It provides
information about the physical structure and identification of a file, and gives
the record-name(s) associated with that file. For the format and the clauses
required in a file description entry, see Chapter 5, Data DivisionFile and Sort
Description Entries on page 91.
record-description-entry
A set of data description entries (described in Chapter 6, Data DivisionData
Description Entry on page 107) that describe the particular record(s) contained
within a particular file.
More than one record description entry may be specified; each is an alternative
description of the same record storage area.
Data areas described in the File Section are not available for processing unless
the file containing the data area is open.
The initial value of a data item in the File Section is undefined.
IBM Extension
The record description entry for a file can be specified using the Format 2 COPY
statement (DD, DDR, DDS, or DDSR option). This allows the field descriptions for
a record format to be exactly as defined in DDS. Also, programs are easier to write
because the record format description is maintained in only one place. See
Chapter 9, Compiler-Directing Statements on page 427 for further information on
this format of the COPY statement.
End of IBM Extension
Note: Group items (including tables) are limited to a length of 32 766 bytes.
80 COBOL/400 Reference
Data Division Structure
Working-Storage Section
The Working-Storage Section describes data records that are not part of external
data files but are developed and processed internally.
The Working-Storage Section contains record description entries and data
description entries for independent data items, called data item description
entries.
The Working-Storage Section must begin with the section header
WORKING-STORAGE SECTION, followed by a separator period.
WORKING-STORAGE SECTION.
record-description-entry
data-item-description-entry
Figure 42. Format
record-description-entry
See File Section on page 80 for description.
Data entries in the Working-Storage Section that bear a definite hierarchic
relationship to one another must be grouped into records structured by level
number.
data-item-description-entry
Independent items in the Working-Storage Section that bear no hierarchic
relationship to one another need not be grouped into records, provided that
they do not need to be further subdivided. Instead, they are classified and
defined as independent elementary items. Each is defined in a separate data-
item description entry that begins with either the level number 77 or 01. (See
Chapter 6, Data DivisionData Description Entry on page 107.)
The initial value of any data item in the Working-Storage Section, except an index
data item, is specified by associating a VALUE clause with the item. The initial
value of any index data item, or of any data item not associated with a VALUE
clause, is undefined.
Note: A maximum of 3 000 000 bytes is permitted for group items (including
tables).
Chapter 4. Data Division 81
Data Division Structure
Linkage Section
The Linkage Section describes data made available from another program.
LINKAGE SECTION.
record-description-entry
data-item-description-entry
Figure 43. Format
record-description-entry
See File Section on page 80 for description.
data-item-description-entry
See Working-Storage Section on page 81 for description.
Record description entries and data item description entries in the Linkage Section
provide names and descriptions, but storage within the program is not reserved
because the data area exists elsewhere.
Any data description clause may be used to describe items in the Linkage Section,
with one exception: the VALUE clause may not be specified for items other than
level-88 items.
Note: A maximum of 3 000 000 bytes are permitted for group items (including
tables).
IBM Extension
ADDRESS OF
ADDRESS OF refers to the calculated address of a data item. The data item can
be reference modified or subscripted.
The ADDRESS OF any Linkage Section item except for level-number 66 or 88 can
be taken. Such an address can be referenced, but not changed.
The ADDRESS OF an item is implicitly defined as USAGE IS POINTER.
| Note: Referencing the address of an elementary item when the address of the
| group item is NULL will result in a machine check.
ADDRESS OF Special Register
The ADDRESS OF special register is the starting address of the data structure
from which all calculated addresses are determined.
It exists for each record (level-number 01 or 77) in the Linkage Section, except for
those records that redefine each other. In such cases, the special register is simi-
larly redefined.
This special register is implicitly defined as USAGE IS POINTER, and you can
change it.
82 COBOL/400 Reference
Data Types
If you reference modify this data item, it is no longer the starting address of a data
structure. It is a calculated address, or ADDRESS OF.
End of IBM Extension
Data Types
Two types of data can be processed: file data and program data.
File Data (External Data)
File data is contained in files. (See File Section on page 97.) A file is a col-
lection of data records existing on some input-output device. A file can be consid-
ered as a group of physical records; it can also be considered as a group of logical
records. The Data Division describes the relationship between physical and logical
records.
A physical record is a unit of data that is treated as an entity when moved into or
out of storage. The size of a physical record is determined by the particular input-
output device on which it is stored. The size does not necessarily have a direct
relationship to the size or content of the logical information contained in the file.
A logical record is a unit of data whose subdivisions have a logical relationship. A
logical record may itself be a physical record (that is, be contained completely
within one physical unit of data); several logical records may be contained within
one physical record, or one logical record may extend across several physical
records.
File description entries specify the physical aspects of the data (such as the size
relationship between physical and logical records, the size and name(s) of the
logical record(s), labeling information, and so forth).
Record description entries describe the logical records in the file, including the
category and format of data within each field of the logical record, different values
the data might be assigned, and so forth.
After the relationship between physical and logical records has been established,
only logical records are made available to you. For this reason, a reference in this
manual to records means logical records, unless the term physical records is
used.
Program Data (Internal Data)
Program data is created by the program itself, instead of being read from a file.
The concept of logical records applies to program data as well as to file data.
Program data can thus be grouped into logical records, and be defined by a series
of record description entries. Items that need not be so grouped can be defined in
independent data description entries (called data item description entries).
Chapter 4. Data Division 83
Data Relationships
Data Relationships
The relationships among all data to be used in a program are defined in the Data
Division, through a system of level indicators and level-numbers.
A level indicator, with its descriptive entry, identifies each file in a program. Level
indicators represent the highest level of any data hierarchy with which they are
associated; FD is the file description level indicator and SD is the sort-merge file
description level indicator.
A level-number, with its descriptive entry, indicates the properties of specific data.
Level-numbers can be used to describe a data hierarchy; they can indicate that this
data has a special purpose, and while they can be associated with (and subordi-
nate to) level indicators, they can also be used independently to describe internal
data or data common to two or more programs. (See Level-Numbers on
page 110 for level-number rules.)
Levels of Data
After a record has been defined, it can be subdivided to provide more detailed data
references.
For example, in a customer file for a department store, one complete record could
contain all data pertaining to one customer. Subdivisions within that record could
be: customer name, customer address, account number, department number of
sale, unit amount of sale, dollar amount of sale, previous balance, plus other perti-
nent information.
The basic subdivisions of a record (that is, those fields not further subdivided) are
called elementary items. Thus, a record can be made up of a series of elemen-
tary items, or it may itself be an elementary item.
It may be necessary to refer to a set of elementary items; thus, elementary items
can be combined into group items. Groups themselves can be combined into a
more inclusive group that contains one or more subgroups. Thus, within one hier-
archy of data items, an elementary item can belong to more than one group item.
A system of level-numbers specifies the organization of elementary and group
items into records. Special level-numbers are also used; they identify data items
used for special purposes.
Levels of Data in a Record Description Entry
Each group and elementary item in a record requires a separate entry, and each
must be assigned a level-number.
A level-number is a 1- or 2-digit integer between 01 and 49, or one of three special
level-numbers: 66, 77, or 88. The following level-numbers are used to structure
records:
01 This level-number specifies the record itself, and is the most inclusive level-
number possible. A level-01 entry may be either a group item or an elementary
item. It must begin in Area A.
84 COBOL/400 Reference
Data Relationships
02-49
These level-numbers specify group and elementary items within a record. They
may begin in Area A or Area B. Less inclusive data items are assigned higher
(not necessarily consecutive) level-numbers in this series.
A group item includes all group and elementary items following it, until a level-
number less than or equal to the level-number of this group is encountered.
All elementary or group items immediately subordinate to one group item must be
assigned identical level-numbers higher than the level-number of this group item.
IBM Extension
The COBOL/400 compiler accepts nonstandard level-numbers that are not identical
to others at the same level. For example, the following two data description entries
are equivalent:
1 EMPLOYEE-RECORD.
5 EMPLOYEE-NAME.
1 FIRST PICTURE X(1).
1 LAST PICTURE X(1).
5 EMPLOYEE-ADDRESS.
1 STREET PICTURE X(1).
1 CITY PICTURE X(1).
1 EMPLOYEE-RECORD.
5 EMPLOYEE-NAME.
1 FIRST PICTURE X(1).
1 LAST PICTURE X(1).
4 EMPLOYEE-ADDRESS.
8 STREET PICTURE X(1).
8 CITY PICTURE X(1).
IBM does not recommend such coding practices, and this extension is provided
only for compatibility.
End of IBM Extension
Figure 44 on page 86 illustrates the concept. Note that all groups immediately
subordinate to the level-01 entry have the same level-number. Note also that ele-
mentary items from different subgroups do not necessarily have the same level
numbers, and that elementary items can be specified at any level within the hier-
archy.
Chapter 4. Data Division 85
Data Relationships
The COBOL record-description entry
written as follows: is subdivided as indicated below:
1 RECORDENTRY. This entry includes
5 GROUP1. This entry includes
1 SUBGROUP1. This entry includes
15 ELEM1 PIC... .
15 ELEM2 PIC... .
1 SUBGROUP2. This entry includes
15 ELEM3 PIC... .
15 ELEM4 PIC... .
5 GROUP2. This entry includes
15 SUBGROUP3. This entry includes
25 ELEM5 PIC... .
25 ELEM6 PIC... .
15 SUBGROUP4 PIC... . This entry includes itself.
5 ELEM7 PIC... . This entry includes itself.
The storage arrangement of the record-description entry is illustrated below:
RECORDENTRY
GROUP1GROUP2
SUBGROUP1SUBGROUP2SUBGROUP3
FOOTINGdata-name-4
WITH AT integer-6
TOPdata-name-5
LINES AT integer-7
BOTTOMdata-name-6
LINES AT integer-8
Figure 57. Format
data-name-3, integer-5
The number of lines that can be written and/or spaced on this logical page.
The area of the page that these lines represent is called the page body. The
value must be greater than zero.
WITH FOOTING AT
Integer-6 or the value in data-name-4 specifies the first line number of the
footing area within the page body. The footing line number must be greater
than zero, and not greater than the last line of the page body. The footing area
extends between those two lines.
LINES AT TOP
Integer-7 or the value in data-name-5 specifies the number of lines in the top
margin of the logical page. The value may be zero.
LINES AT BOTTOM
Integer-8 or the value in data-name-6 specifies the number of lines in the
bottom margin of the logical page. The value may be zero.
Figure 58 on page 103 illustrates the use of each phrase of the LINAGE clause.
102 COBOL/400 Reference
LINAGE Clause
)
) LINES AT TOP integer7 (top margin)
)
logical
page body page depth
WITH FOOTING integer6
footing area
LINAGE integer5
)
) LINES AT BOTTOM integer8 (bottommargin)
)
REDEFINES clause
LIKE clause
ASCENDINGdataname2
DESCENDING KEY IS
INDEXEDindexname1
BY
Figure 69. Format 1Fixed-Length Tables
integer-2
Specifies the exact number of occurrences, and must be greater than zero.
In the COBOL/400 language, integer-2 must be between 1 and 3 000 000
bytes.
ASCENDING/DESCENDING KEY Phrase
Data is arranged in ascending or descending order (depending on the key word
specified) according to the values contained in data-name-2. The data-names are
listed in their descending order of significance.
ASCENDINGdata-name-2
DESCENDING KEY IS
Figure 70. Format
The order is determined by the rules for comparison of operands (see Relation
Condition on page 169). The ASCENDING and DESCENDING KEY data items
are used in OCCURS clauses and the SEARCH ALL statement for a binary search
of the table element.
data-name-2
Must be the name of the subject entry, or the name of an entry subordinate to
the subject entry.
Chapter 6. Data DivisionData Description Entry 119
OCCURS Clause
If data-name-2 names the subject entry, that entire entry becomes the
ASCENDING/DESCENDING KEY, and is the only key that may be specified for
this table element.
If data-name-2 does not name the subject entry, then data-name-2:
Must be subordinate to the subject of the table entry itself
Must not be subordinate to, or follow, any other entry that contains an
OCCURS clause
Must not contain an OCCURS clause.
When the ASCENDING/DESCENDING KEY phrase is specified, the following rules
apply:
Keys must be listed in decreasing order of significance.
You must arrange the data in the table in ASCENDING or DESCENDING
sequence according to the collating sequence in use.
A key may have DISPLAY, BINARY, PACKED-DECIMAL, or COMPUTA-
TIONAL usage.
The following example illustrates the specification of ASCENDING KEY data items:
WORKING-STORAGE SECTION.
1 TABLE-RECORD.
5 EMPLOYEE-TABLE OCCURS 1 TIMES
ASCENDING KEY IS WAGE-RATE EMPLOYEE-NO
INDEXED BY A, B.
1 EMPLOYEE-NAME PIC X(2).
1 EMPLOYEE-NO PIC 9(6).
1 WAGE-RATE PIC 9999V99.
1 WEEK-RECORD OCCURS 52 TIMES
ASCENDING KEY IS WEEK-NO INDEXED BY C.
15 WEEK-NO PIC 99.
15 AUTHORIZED-ABSENCES PIC 9.
15 UNAUTHORIZED-ABSENCES PIC 9.
15 LATE-ARRIVALS PIC 9.
The keys for EMPLOYEE-TABLE are subordinate to that entry, while the key for
WEEK-RECORD is subordinate to that subordinate entry.
In the preceding example, records in EMPLOYEE-TABLE must be arranged in
ascending order of WAGE-RATE, and in ascending order of EMPLOYEE-NO within
WAGE-RATE. Records in WEEK-RECORD must be arranged in ascending order
of WEEK-NO. If they are not, results of any SEARCH ALL statement will be unpre-
dictable.
INDEXED BY Phrase
The INDEXED BY phrase specifies the indexes that can be used with this table.
The INDEXED BY phrase is required if indexing is used to refer to this table
element. See Subscripting Using Index-Names (Indexing) on page 124.
120 COBOL/400 Reference
OCCURS Clause
INDEXEDindex-name-1
BY
Figure 71. Format
index-name-1
Must follow the rules for formation of user-defined words. At least one char-
acter must be alphabetic.
Each index-name specifies an index to be created by the compiler for use by
the program. These index-names are not data-names, and are not identified
elsewhere in the COBOL program; instead, they can be regarded as private
special registers for the use of this object program only. As such, they are not
data, or part of any data hierarchy; as such, each must be unique.
Variable-Length Tables
Variable-length tables are specified using the OCCURS DEPENDING ON clause.
OCCURS integer1 TO integer2
TIMES
DEPENDINGdataname1
ON
ASCENDINGdataname2
DESCENDING KEY IS
INDEXEDindexname1
BY
Figure 72. Format 2Variable-Length Tables
integer-1
The minimum number of occurrences.
The value of integer-1 must be greater than or equal to zero; it must also be
less than the value of integer-2.
integer-2
The maximum number of occurrences.
The value of integer-2 must be no more than 32 767.
The length of the subject item is fixed; it is only the number of repetitions of the
subject item that is variable.
Chapter 6. Data DivisionData Description Entry 121
OCCURS DEPENDING ON Clause
OCCURS DEPENDING ON Clause
The OCCURS DEPENDING ON clause specifies variable-length tables.
data-name-1
Specifies the object of the OCCURS DEPENDING ON clause; that is, the data
item whose current value represents the current number of occurrences of the
subject item. The contents of items whose occurrence numbers exceed the
value of the object are unpredictable.
The object of the OCCURS DEPENDING ON clause must not occupy any storage
position within the range of any table (that is, any storage position from the first
character position in the table through the last character position in the table).
At the time that the group item (or any data item that contains a subordinate
OCCURS DEPENDING ON item or that follows but is not subordinate to the
OCCURS DEPENDING ON item) is referenced, the value of the object referenced
by data-name-1 must fall within the range integer-1 through integer-2.
When a group item containing a subordinate OCCURS DEPENDING ON item is
referred to, the part of the table area used in the operation is determined as
follows:
If the object is outside the group, only that part of the table area that is speci-
fied by the object at the start of the operation will be used.
If the object is included in the same group and the group data item is refer-
enced as a sending item, only that part of the table area that is specified by the
value of the object at the start of the operation will be used in the operation.
If the object is included in the same group and the group data item is refer-
enced as a receiving item, the maximum length of the group item will be used
in the operation.
The subject of an OCCURS clause is the data-name of the data item containing
the OCCURS clause. Except for the OCCURS clause itself, data description
clauses used with the subject apply to each occurrence of the item described.
Subscripting or indexing is required whenever the subject is used in a statement
other than SEARCH or USE FOR DEBUGGING, unless it is the object of a REDE-
FINES clause. In this case, the subject refers to one occurrence within a table
element.
Subscripting and indexing are not allowed when the subject is used in a SEARCH
or USE FOR DEBUGGING statement, or when it is the object of a REDEFINES
clause. In this case, the subject represents an entire table element.
Note that the previous two restrictions do not apply to the LENGTH OF special reg-
ister.
In one record description entry, any entry that contains an OCCURS DEPENDING
ON clause may be followed only by items subordinate to it.
The OCCURS DEPENDING ON clause may not be specified as subordinate to
another OCCURS clause.
All data-names used in the OCCURS clause may be qualified; they may not be
subscripted or indexed.
122 COBOL/400 Reference
Subscripting
The OCCURS clause cannot be specified in a data description entry that:
Has a level number of 01, 66, 77, or 88.
Describes an item of variable size (an item is of variable size if any subordinate
entry contains an OCCURS DEPENDING ON clause).
Describes a redefined data item. (However, a redefined item can be subordi-
nate to an item containing an OCCURS clause.) See REDEFINES Clause on
page 138.
The ASCENDING/DESCENDING KEY and INDEXED BY clauses are described
under Fixed-Length Tables on page 119.
Note: If you use the OCCURS DEPENDING ON clause, the table must contain no
more than 32 767 occurrences, the length of a table element must be no more than
32 767 bytes, and the length of the whole table must be no more than 32 767
bytes.
Subscripting
Subscripting is a method of providing table references through the use of sub-
scripts. A subscript is a positive integer whose value specifies the occurrence
number of a table element.
conditionname(integer1)
dataname1 OFdataname2 dataname3
IN 1 integer2
indexname1
1 integer3
Figure 73. Format
integer-1
May be signed. If signed, it must be positive.
data-name-3
Must be a numeric elementary item representing an integer. It may be quali-
fied.
index-name-1
Corresponds to a data description entry in the hierarchy of the table being ref-
erenced which contains an INDEXED BY phrase specifying that name.
Occurrence numbers are specified by appending one or more subscripts to the
data-name.
| Note: When referencing a table element, integer-2 and integer-3 have a maximum
| offset of 99999999.
The subscript can be represented either by an integer, a data-name which refer-
ences an integer numeric elementary item, or an index-name associated with the
table. A data-name or index-name may be followed by either the operator + or the
operator - and an integer (delimited by a space), which is used as an increment or
decrement, respectively. It is permissible to mix integers, data-names, and index-
names.
Chapter 6. Data DivisionData Description Entry 123
Subscripting
The subscripts, enclosed in parentheses, are written immediately following any
qualification for the name of the table element. The number of subscripts in such a
reference must equal the number of dimensions in the table whose element is
being referenced. That is, there must be a subscript for each OCCURS clause in
the hierarchy containing the data-name, including the data-name itself.
When more than one subscript is required, they are written in the order of succes-
sively less inclusive dimensions of the data organization. If a multi-dimensional
table is considered a series of nested tables and the outermost table in the nest is
considered to be the major table and the innermost table being the minor table, the
subscripts are written from left to right in the order major, intermediate (up to five
dimensions), and minor. For example, valid literal subscript references to
TABLE-THREE are:
ELEMENT-THREE (1, 2, 1)
ELEMENT-THREE (2 2 1)
A reference to an item must not be subscripted unless the item is a table element
or an item or condition-name associated with a table element.
The lowest permissible occurrence number represented by a subscript is 1. The
highest permissible occurrence number in any particular case is the maximum
number of occurrences of the item as specified in the OCCURS clause.
If the RANGE option is specified or implied, the system insures that the subscript
value is valid. If the RANGE option is not active, it is your responsibility to ensure
that the subscript value is valid. The RANGE option does not cause the system to
verify that index entries are valid; it is your responsibility to ensure valid index
values.
Note: See the COBOL/400 Users Guide for comprehensive information on the
CRTCBLPGM command and the PROCESS statement.
Subscripting Using Integers or Data-Names
When an integer or data-name is used to represent a subscript, it may be used to
reference items within different tables. These tables need not have elements of the
same size. The same integer or data-name may appear as the only subscript with
one item and as one of two or more subscripts with another item. TABLE-THREE
on page 117, assuming that SUB1, SUB2, and SUB3 are all items subordinate to
SUBSCRIPT-ITEM are:
ELEMENT-THREE (SUB1 SUB2 SUB3)
ELEMENT-THREE IN TABLE-THREE (SUB1 OF SUBSCRIPT-ITEM, SUB2 OF
SUBSCRIPT-ITEM, SUB3 OF SUBSCRIPT-ITEM)
Subscripting Using Index-Names (Indexing)
Indexing facilitates such operations as table searching and manipulating specific
items. To use indexing you assign one or more index-names to an item whose
data description entry contains an OCCURS clause. An index associated with an
index-name acts as a subscript, and its value corresponds to an occurrence
number for the item to which the index-name is associated.
124 COBOL/400 Reference
Subscripting
The INDEXED BY phrase specifies the indexes that can be used with this table
element. The INDEXED BY phrase is required if indexing is used to refer to this
table element.
Each index-name must follow the rules for formation of a user-defined word; at
least one character must be alphabetic. Each index-name specifies an index to be
created by the compiler for use by the program. These index-names are not data-
names and are not identified elsewhere in the COBOL program; instead, they can
be regarded as compiler generated registers for the use of this object program only.
Therefore, they are not data or part of any data hierarchy; as such, each must be
unique. An INDEX-NAME can only be referenced by a PERFORM, SET, or
SEARCH statement, as a parameter in the USING phrase in a CALL statement, or
in a relational condition comparison.
The initial value of an index at object time is undefined, and the index must be
initialized before it is used as a subscript. The initial value of an index is assigned
with the PERFORM statement with the VARYING phrase, the SEARCH statement
with the ALL phrase, or the SET statement.
The use of an integer or data-name as a subscript referencing a table element or
an item within a table element does not cause the alteration of any index associ-
ated with that table.
An index-name can be used to reference only the table to which it is associated by
the INDEXED BY phrase.
Data that is arranged in the form of a table is often searched. The SEARCH state-
ment provides facilities for producing serial and non-serial (for example, binary)
searches. It is used to search a table for a table element that satisfies a specific
condition and to adjust the value of the associated index to indicate that table
element.
In relative indexing, there is an additional phrase for making references to a table
element or to an item within a table element. When the name of a table element is
followed by a subscript of the form (index-name + or - integer), the occurrence
number required to complete the reference is the same as if index-name were set
up or down by integer via the SET statement before the reference. The integer is
considered to be an occurrence number, and is converted to an index value before
being added to or subtracted from the index-name. The use of relative indexing
does not cause the object program to alter the value of the index.
The value of an index can be made accessible to an object program by storing the
value in an index data item. Index data items are described in the program by a
data description entry containing USAGE IS INDEX clause. The index value is
moved to the index data item by the execution of a SET statement.
To be valid during execution, an index value must correspond to a table element
occurrence of not less than one, nor greater than the highest permissible occur-
rence number.
Further information on index-names is given in the description of the INDEXED BY
phrase of the OCCURS clause, on page 120.
Chapter 6. Data DivisionData Description Entry 125
PICTURE Clause
Restrictions on Subscripting
1. A data-name must not be subscripted or indexed when it is being used as a
subscript or qualifier.
2. An index may be modified only by a PERFORM, SEARCH, or SET statement.
3. When a literal is used in a subscript, it must be a positive or unsigned integer.
4. When a literal is used in relative subscripting and indexing, it must be an
unsigned integer.
PICTURE Clause
The PICTURE clause specifies the general characteristics and editing requirements
of an elementary item.
PICTUREcharacterstring
PIC IS
Figure 74. Format
The PICTURE clause must be specified for every elementary item except an index
data item or the subject of the RENAMES clause. In these cases, use of this
clause is prohibited.
The PICTURE clause may be specified only at the elementary level. PIC is an
abbreviation for PICTURE and has the same meaning.
The PICTURE character-string is made up of certain COBOL characters used as
symbols. The allowable combinations determine the category of the elementary
data item.
The PICTURE character-string may contain a maximum of 30 characters.
DECIMAL-POINT IS COMMA, when specified in the SPECIAL-NAMES paragraph,
exchanges the functions of the period and the comma in PICTURE character
strings and in numeric literals.
The PICTURE clause is not allowed in descriptions of items described with USAGE
IS INDEX or USAGE IS POINTER.
Symbols Used in the PICTURE Clause
The meaning of each PICTURE clause symbol is defined in Table 10 on page 127.
The sequence in which PICTURE clause symbols must be specified is shown in
Figure 75 on page 129. More detailed explanations of PICTURE clause symbols
follow the figures.
Any punctuation character appearing within the PICTURE character-string is not
considered a punctuation character, but rather a PICTURE character-string symbol.
The lowercase letters corresponding to the uppercase letters representing the
PICTURE symbols A, B, P, S, V, X, Z, CR, and DB are equivalent to their upper-
case representations in a PICTURE character-string.
126 COBOL/400 Reference
PICTURE Clause
Table 10 (Page 1 of 2). PICTURE Clause Symbol Meanings
Symbol Meaning
A A character position that can contain only a letter of the alphabet or a space.
B A character position into which the space character is inserted.
P An assumed decimal scaling position. It is used to specify the location of an assumed decimal point
when the point is not within the number that appears in the data item. The scaling position character
P is not counted in the size of the data item. Scaling position characters are counted in determining
the maximum number of digit positions (18) in numeric-edited items or in items that appear as arith-
metic operands.
The scaling position character P may appear only as a continuous string of Ps in the leftmost or right-
most digit positions within a PICTURE character-string. Because the scaling position character P
implies an assumed decimal point (to the left of the Ps, if the Ps are leftmost PICTURE characters; to
the right of the Ps, if the Ps are rightmost PICTURE characters), the assumed decimal point symbol,
V, is redundant as either the leftmost or rightmost character within such a PICTURE description.
In certain operations that reference a data item whose PICTURE character-string contains the symbol
P, the algebraic value of the data item is used rather than the actual character representation of the
data item. This algebraic value assumes the decimal point in the prescribed location and zero in place
of the digit position specified by the symbol P. The size of the value is the number of digit positions
represented by the PICTURE character-string. These operations are any of the following:
Any operation requiring a numeric sending operand.
A MOVE statement where the sending operand is numeric and its PICTURE character-string con-
tains the symbol P.
A MOVE statement where the sending operand is numeric-edited and its PICTURE character-
string contains the symbol P and the receiving operand is numeric or numeric-edited.
A comparison operation where both operands are numeric.
In all other operations the digit positions specified with the symbol P are ignored and are not counted
in the size of the operand.
S An indicator of the presence (but not the representation nor, necessarily, the position) of an opera-
tional sign. It must be written as the leftmost character in the PICTURE string. An operational sign
indicates whether the value of an item involved in an operation is positive or negative. The symbol S
is not counted in determining the size of the elementary item, unless an associated SIGN clause spec-
ifies the SEPARATE CHARACTER phrase. Because hardware instructions use signs, you can
improve performance by including the S in picture clauses whenever possible.
V An indicator of the location of the assumed decimal point. It may appear only once in a character
string. The V does not represent a character position and, therefore, is not counted in the size of the
elementary item. When the assumed decimal point is to the right of the rightmost symbol in the string,
the V is redundant.
X A character position that may contain any allowable character from the EBCDIC character set.
Z A leading numeric character position; when that position contains a zero, the zero is replaced by a
space character. Each Z is counted in the size of the item.
9 A character position that contains a numeral and is counted in the size of the item.
1
IBM Extension
A character position that contains a Boolean value of B"1" or B"0". Usage must be explicitly or
implicitly defined as DISPLAY.
End of IBM Extension
0 A character position into which the numeral zero is inserted. Each zero is counted in the size of the
item.
Chapter 6. Data DivisionData Description Entry 127
PICTURE Clause
Table 10 (Page 2 of 2). PICTURE Clause Symbol Meanings
Symbol Meaning
/ A character position into which the slash character is inserted. Each slash is counted in the size of
the item.
, A character position into which a comma is inserted. This character is counted in the size of the item.
If the comma insertion character is the last symbol in the PICTURE character-string, the PICTURE
clause must be the last clause of the data description entry and must be immediately followed by the
separator period.
. An editing symbol that represents the decimal point for alignment purposes. In addition, it represents
a character position into which a period is inserted. This character is counted in the size of the item.
If the period insertion character is the last symbol in the PICTURE character string, the PICTURE
clause must be the last clause of that data description entry and must be immediately followed by the
separator period.
Note: For a given program, the functions of the period and comma are exchanged if the clause
DECIMAL-POINT IS COMMA is specified in the SPECIAL-NAMES paragraph. In this exchange, the
rules for the period apply to the comma and the rules for the comma apply to the period wherever they
appear in a PICTURE clause.
+
CR
DB
Editing sign control symbols. Each represents the character position into which the editing sign control
symbol is placed. The symbols are mutually exclusive in one character string. Each character used in
the symbol is counted in determining the size of the data item.
* A check protect symbola leading numeric character position into which an asterisk is placed when
that position contains a zero. Each asterisk (*) is counted in the size of the item.
$ A character position into which a currency symbol is placed. The currency symbol in a character
string is represented either by the symbol $ or by the single character specified in the CURRENCY
SIGN clause in the SPECIAL-NAMES paragraph of the Environment Division. The currency symbol is
counted in the size of the item.
Figure 75 on page 129 shows the sequence in which PICTURE clause symbols
must be specified. See the notes at the end of the figure.
128 COBOL/400 Reference
PICTURE Clause
Figure 75. PICTURE Clause Symbol Sequence
Notes to Figure 75:
1. An X at an intersection indicates that the symbol(s) at the top of the column
may, in a given character-string, appear anywhere to the left of the symbol(s) at
the left of the row.
Chapter 6. Data DivisionData Description Entry 129
PICTURE Clause
2. The $ character, however it is represented in the appropriate character set, is
the default value for the currency symbol.
3. At least one of the symbols A, X, Z, 9, or *, or at least two of the symbols +, ,
or $ must be present in a PICTURE string.
4. Nonfloating insertion symbols + and , floating insertion symbols Z, *, +, , and
$, and the symbol P appear twice in the above PICTURE character precedence
table. The leftmost column and uppermost row for each symbol represents its
use to the left of the decimal point position. The second appearance of the
symbol in the table represents its use to the right of the decimal point position.
5. Braces ({ }) indicate items that are mutually exclusive.
Character-String Representation
The following symbols may appear more than once in one PICTURE character-
string:
A B P X Z 9 / , + $
An integer enclosed in parentheses immediately following any of these symbols
specifies the number of consecutive occurrences of that symbol. The number of
consecutive occurrences cannot exceed 3 000 000.
For example, the following two PICTURE clause specifications are equivalent:
PICTURE IS $99999.99CR
PICTURE IS $9(5).9(2)CR
The following symbols may appear only once in one PICTURE character-string:
S V . CR DB
or
IBM Extension
1 (A character position that contains a Boolean value).
End of IBM Extension
Each time any of the above symbols appears in the character-string, it represents
an occurrence of that character or set of allowable characters in the data item.
Data Categories and PICTURE Rules
The allowable combinations of PICTURE symbols determine the data category of
the item.
Alphabetic items
Numeric Items
Numeric-edited items
Alphanumeric items
Alphanumeric-edited items
130 COBOL/400 Reference
PICTURE Clause
IBM Extension
Boolean items.
End of IBM Extension
Alphabetic Items:
The PICTURE character-string can contain only the symbol A.
The contents of the item in standard data format must consist of any of the
letters of the English alphabet and the space character.
USAGE DISPLAY must be specified or implied.
Any associated VALUE clause must specify a nonnumeric literal containing only
alphabetic characters or the figurative constant SPACE.
Numeric Items:
Types of numeric items are:
Binary
Packed decimal (internal decimal)
Zoned decimal (external decimal).
The PICTURE character-string can contain only the symbols 9, P, S, and V.
The number of digit positions must range from 1 through 18, inclusive.
If unsigned, the contents of the item in standard data format must contain a
combination of the Arabic numerals 0-9. If signed, it may also contain a +, ,
or other representation of the operational sign.
The USAGE of the item can be DISPLAY, BINARY, COMPUTATIONAL, or
PACKED-DECIMAL.
IBM Extension
The USAGE of the item can be COMPUTATIONAL-3 or COMPUTATIONAL-4.
End of IBM Extension
A VALUE clause associated with an elementary numeric item must specify a
numeric literal or the figurative constant ZERO. A VALUE clause associated
with a group item consisting of elementary numeric items must specify a non-
numeric literal or a figurative constant, because the group is considered alpha-
numeric. In both cases, the literal is treated exactly as specified; no editing is
performed.
Chapter 6. Data DivisionData Description Entry 131
PICTURE Clause
Examples of numeric items:
PICTURE Valid Range of Values
9999 through 9999
S99 -99 through +99
S999V9 -999.9 through +999.9
PPP999 through .999
S999PPP -1 through -999 and
+1 through +999 or zero
Numeric-edited Items:
The PICTURE character-string can contain the following symbols:
B P V Z 9 / , . + - CR DB $
The combinations of symbols allowed are determined from the PICTURE
clause symbol order allowed (see Figure 75 on page 129), and the editing
rules (see PICTURE Clause Editing on page 133). The following additional
rules also apply:
Either the BLANK WHEN ZERO clause must be specified for the item, or
the string must contain at least one of the following symbols:
B / Z , . + - CR DB $
The number of digit positions represented in the character-string must be in
the range 1 through 18, inclusive.
The total length of the resultant character positions must be 127 or less.
The contents of those character positions representing digits in standard data
format must be one of the 10 Arabic numerals.
USAGE DISPLAY must be specified or implied.
Any associated VALUE clause must specify a nonnumeric literal or a figurative
constant. The literal is treated exactly as specified; no editing is done.
Alphanumeric Items:
The PICTURE character-string must consist of either of the following:
The symbol X
Combinations of the symbols A, X, and 9.
(A character-string containing all As or all 9s does not define an alphanu-
meric item.)
The item is treated as if the character-string contained only the symbol X.
The contents of the item in standard data format may be any allowable
characters from the EBCDIC character set.
USAGE DISPLAY must be specified or implied.
Any associated VALUE clause must specify a nonnumeric literal or a figura-
tive constant.
Alphanumeric-edited Items:
The PICTURE character-string can contain the following symbols:
A X 9 B /
132 COBOL/400 Reference
PICTURE Clause
The string must contain at least one A or X, and at least one B or 0 (zero) or /.
The contents of the item in standard data format may be any allowable char-
acter from the EBCDIC character set.
The total length of the resultant character positions must be 127 or less.
USAGE DISPLAY must be specified or implied.
Any associated VALUE clause must specify a nonnumeric literal or a figurative
constant. The literal is treated exactly as specified; no editing is done.
IBM Extension
Boolean items: The following rules apply:
1. The PICTURE character-string can contain only the symbol 1.
2. Only one character 1 can be specified.
3. The USAGE of an item can only be DISPLAY.
4. An associated VALUE clause must specify a Boolean literal (B"1" or B"0") or
zero.
5. The following clauses cannot be specified for a Boolean item:
SIGN clause
BLANK WHEN ZERO clause
ASCENDING/DESCENDING KEY clause.
6. The INDICATOR clause can be specified. (See the COBOL/400 Users Guide
for more information about indicators.)
End of IBM Extension
PICTURE Clause Editing
There are two general methods of editing in a PICTURE clause:
Insertion editing
Simple insertion
Special insertion
Fixed insertion
Floating insertion.
Suppression and replacement editing
Zero suppression and replacement with asterisks
Zero suppression and replacement with spaces.
The type of editing allowed for an item depends on its data category. The type of
editing that is valid for each category is shown below:
This type of editing is valid for alphabetic, alphanumeric edited, and numeric edited
items. The valid insertion symbols for each category are shown in Table 12.
Chapter 6. Data DivisionData Description Entry 133
PICTURE Clause
Table 11. Valid Editing for Each Data Category
Category Type of Editing
Alphabetic None
IBM Extension
Boolean
End of IBM Extension
None
Numeric None
Alphanumeric None
Alphanumeric edited Simple insertion
Numeric edited All
Simple Insertion Editing
This type of editing is valid for numeric-edited and alphanumeric-edited items.
Each insertion symbol is counted in the size of the item, and represents the posi-
tion within the item where the equivalent characters will be inserted. Examples of
simple insertion editing are shown in Table 13.
Table 12. Simple Insertion Editing Valid Insertion Symbols for Each
Data Category
Category Valid Insertion Symbols
Alphabetic None
IBM Extension
Boolean
End of IBM Extension
None
Numeric None
Alphanumeric None
Alphanumeric edited B 0 /
Numeric edited B 0 / ,
Table 13. Examples of Simple Insertion Editing
PICTURE Value of Data Edited Result
X(10)/XX ALPHANUMER01 ALPHANUMER/01
X(5)BX(7) ALPHANUMERIC ALPHA NUMERIC
99,B999,B000 1234 01, 234, 000
99,999 12345 12,345
134 COBOL/400 Reference
PICTURE Clause
Special Insertion Editing
This type of editing is valid only for numeric-edited items.
The period (.) is the special insertion symbol; it also represents the actual decimal
point for alignment purposes.
The period insertion symbol is counted in the size of the item, and represents the
position within the item where the actual decimal point is inserted.
Either the actual decimal point or the symbol V as the assumed decimal point, but
not both, must be specified in one PICTURE character-string.
Examples of special insertion editing:
PICTURE Value of Data Edited Results
999.99 1.234 1.23
999.99 12.34 12.34
999.99 123.45 123.45
999.99 1234.5 234.5
Fixed Insertion Editing
This type of editing is valid only for numeric-edited items. The following insertion
symbols are used:
$ (currency symbol)
+ CR DB (editing-sign control symbols)
In fixed insertion editing, only one currency symbol and one editing sign control
symbol can be specified in one PICTURE character-string.
Unless it is preceded by a + or symbol, the currency symbol must be the first
character in the character-string.
When either + or is used as a symbol, it must be the first or last character in the
character-string.
When CR or DB is used as a symbol, it must occupy the rightmost two character
positions in the character-string. If these two character positions contain the
symbols CR or DB, the uppercase letters are the insertion characters.
Editing sign control symbols produce results that depend on the value of the data
item, as shown below:
Editing Symbol Result: Result:
in PICTURE Data Item Data Item
Character-String Positive or Zero Negative
+ + -
- space -
CR 2 spaces CR
DB 2 spaces DB
Chapter 6. Data DivisionData Description Entry 135
PICTURE Clause
Examples of fixed insertion editing:
PICTURE Value of Data Edited Result
999.99+ +6555.556 555.55+
+9999.99 -6555.555 -6555.55
9999.99 +1234.56 1234.56
$999.99 -123.45 $123.45
-$999.99 -123.456 -$123.45
-$999.99 +123.456 $123.45
$9999.99CR +123.45 $123.45
$9999.99DB -123.45 $123.45DB
Floating Insertion Editing
This type of editing is valid only for numeric-edited items. The following symbols
are used:
$ +
Within one PICTURE character-string, these symbols are mutually exclusive as
floating insertion characters.
Floating insertion editing is specified by using a string of at least two of the allow-
able floating insertion symbols to represent leftmost character positions into which
these actual characters can be inserted.
The leftmost floating insertion symbol in the character-string represents the leftmost
limit at which this actual character can appear in the data item. The rightmost
floating insertion symbol represents the rightmost limit at which this actual character
can appear.
The second leftmost floating insertion symbol in the character-string represents the
leftmost limit at which numeric data can appear within the data item. Nonzero
numeric data may replace all characters at or to the right of this limit.
Any simple-insertion symbols (B 0 / ,) within or to the immediate right of the string
of floating insertion symbols are considered part of the floating character-string. If
the period (.) special-insertion symbol is included within the floating string, it is con-
sidered to be part of the character-string.
In a PICTURE character-string, there are two ways to represent floating insertion
editing and thus, two ways in which editing is performed:
1. Any or all leading numeric character positions to the left of the decimal point
are represented by the floating insertion symbol. When editing is performed, a
single floating insertion character is placed to the immediate left of the first
nonzero digit in the data, or of the decimal point, whichever is farther to the left.
The character positions to the left of the inserted character are filled with
spaces.
2. All the numeric character positions are represented by the floating insertion
symbol. When editing is performed, then:
If the value of the data is zero, the entire data item will contain spaces.
If the value of the data is nonzero, the result is the same as in rule 1.
136 COBOL/400 Reference
PICTURE Clause
To avoid truncation, the minimum size of the PICTURE character-string must be:
The number of character positions in the sending item, plus
The number of nonfloating insertion symbols in the receiving item, plus
One character for the floating insertion symbol.
Examples of floating insertion editing:
PICTURE Value of Data Edited Result
$$$$.99 .123 $.12
$$$9.99 .12 $.12
$,$$$,999.99 -1234.56 $1,234.56
+,+++,999.99 -123456.789 -123,456.78
$$,$$$,$$$.99CR -1234567 $1,234,567.CR
++,+++,+++.+++ .
Zero Suppression and Replacement Editing
This type of editing is valid only for numeric-edited items. In zero suppression
editing, the symbols Z and * are used. These symbols are mutually exclusive in
one PICTURE character-string.
The following symbols are mutually exclusive as floating replacement symbols in
one PICTURE character-string:
Z * + $
Specify zero suppression and replacement editing with a string of one or more of
the allowable symbols to represent leftmost character positions in which zero sup-
pression and replacement editing can be performed.
Any simple insertion symbols (B 0 / ,) within or to the immediate right of the string
of floating editing symbols are considered part of the string. If the period (.) special
insertion symbol is included within the floating editing string, it is considered to be
part of the character-string.
In a PICTURE character-string, there are two ways to represent zero suppression,
and two ways in which editing is performed:
Any or all of the leading numeric character positions to the left of the decimal
point are represented by suppression symbols. When editing is performed, any
leading zero in the data that appears in the same character position as a sup-
pression symbol is replaced by the replacement character. Suppression stops
at the leftmost character:
That does not correspond to a suppression symbol
That contains nonzero data
That is the decimal point.
All the numeric character positions in the PICTURE character-string are repres-
ented by the suppression symbols. When editing is performed, and the value
of the data is nonzero, the result is the same as in the preceding rule. If the
value of the data is zero, then:
If Z has been specified, the entire data item will contain spaces.
If * has been specified, the entire data item, except the actual decimal
point, will contain asterisks.
Chapter 6. Data DivisionData Description Entry 137
REDEFINES Clause
Note: Do not specify both the asterisk (*) as a suppression symbol and the
BLANK WHEN ZERO clause for the same entry.
Examples of zero suppression and replacement editing:
PICTURE Value of Data Edited Result
. . .
ZZZZ.ZZ .
ZZZZ.99 . .
.99 . .
ZZ99.99 . .
Z,ZZZ.ZZ+ +123.456 123.45+
,.+ -123.45 123.45-
,,.+ +12345678.9 12,345,678.9+
$Z,ZZZ,ZZZ.ZZCR +12345.67 $ 12,345.67
$B,,.BBDB -12345.67 $ 12,345.67 DB
REDEFINES Clause
The REDEFINES clause allows you to use different data description entries to
describe the same computer storage area.
levelnumberREDEFINES dataname2
dataname1
FILLER
Figure 76. Format
Note: Level-number, data-name-1, and FILLER are not part of the REDEFINES
clause itself, and are included in the format only for clarity.
When specified, the REDEFINES clause must be the first entry following
data-name-1 or FILLER. If data-name-1 or FILLER is not specified, the REDE-
FINES clause must be the first entry following the level-number.
The level-numbers of data-name-1 and data-name-2 must be identical, and must
not be level 66 or level 88.
data-name-1
Identifies an alternate description for the same area, and is the redefining item
or the REDEFINES subject.
data-name-2
Is the redefined item or the REDEFINES object.
When more that one level-01 entry is written subordinate to an FD entry, a condi-
tion known as implicit redefinition occurs. That is, the second level-01 entry implic-
itly redefines the storage allotted for the first entry. In such level-01 entries, the
REDEFINES clause must not be specified.
Redefinition begins at data-name-1 and ends when a level-number less than or
equal to that of data-name-1 is encountered. No entry having a level-number
numerically lower than those of data-name-1 and data-name-2 may occur between
these entries.
138 COBOL/400 Reference
REDEFINES Clause
For example:
5 A PICTURE X(6).
5 B REDEFINES A.
1 B-1 PICTURE X(2).
1 B-2 PICTURE 9(4).
5 C PICTURE 99V99.
In this example, A is the redefined item, and B is the redefining item. Redefinition
begins with B and includes the two subordinate items B-1 and B-2. Redefinition
ends when the level-05 item C is encountered.
The data description entry for the redefined item cannot contain an OCCURS
clause. However, the redefined item may be subordinate to an item whose data
description entry contains an OCCURS clause. In this case, the reference to the
redefined item in the REDEFINES clause may not be subscripted. Neither the ori-
ginal definition nor the redefinition can include a variable occurrence data item.
Data-name-1, the redefining item, may be smaller than data-name-2, the redefined
item. If the redefined item is specified with a level-number other than 01, however,
the number of character positions it contains must be greater than or equal to the
number of character positions in the redefining item.
One or more redefinitions of the same storage area are permitted. The entries
giving the new descriptions of the storage area must be in the same section, and
must immediately follow the description of the redefined area without intervening
entries that define new character positions. Multiple redefinitions must all use the
data-name of the original entry that defined this storage area. For example:
5 A PICTURE 9999.
5 B REDEFINES A PICTURE 9V999.
5 C REDEFINES A PICTURE 99V99.
The redefining entry (identified by data-name-1), and any subordinate entries, must
not contain any VALUE clauses.
REDEFINES Clause Considerations
Data items within an area can be redefined without changing their lengths. For
example:
5 NAME-2.
1 SALARY PICTURE XXX.
1 SO-SEC-NO PICTURE X(9).
1 MONTH PICTURE XX.
5 NAME-1 REDEFINES NAME-2.
1 WAGE PICTURE XXX.
1 EMP-NO PICTURE X(9).
1 YEAR PICTURE XX.
Chapter 6. Data DivisionData Description Entry 139
REDEFINES Clause
Data item lengths and types can also be respecified within an area. For example:
5 NAME-2.
1 SALARY PICTURE XXX.
1 SO-SEC-NO PICTURE X(9).
1 MONTH PICTURE XX.
5 NAME-1 REDEFINES NAME-2.
1 WAGE PICTURE 999V999.
1 EMP-NO PICTURE X(6).
1 YEAR PICTURE XX.
When an area is redefined, all descriptions of the area are always in effect; that is,
redefinition does not cause any data to be erased and never supersedes a previous
description. Thus, if B REDEFINES C has been specified, either of the two proce-
dural statements, MOVE X TO B and MOVE Y TO C, could be executed at any
point in the program.
In the first case, the area described as B would assume the value and format of X.
In the second case, the same physical area (described now as C) would assume
the value and format of Y. Note that, if the second statement is executed imme-
diately after the first, the value of Y replaces the value of X in the one storage area.
The usage of a redefining data item need not be the same as that of a redefined
item. This does not, however, cause any change in existing data. For example:
5 B PICTURE 99 USAGE DISPLAY VALUE 8.
5 C REDEFINES B PICTURE S99 USAGE COMPUTATIONAL-4.
5 A PICTURE S99 USAGE COMPUTATIONAL-4.
The bit configuration of the DISPLAY value 8 is
1111 1111 1.
Redefining B does not change the bit configuration of the data in the storage area.
Therefore, the following two statements produce different results:
ADD B TO A
ADD C TO A
In the first case, the value 8 is added to A (because B has USAGE DISPLAY). In
the second statement, the value -48 is added to A (because C has USAGE
COMPUTATIONAL-4) because the bit configuration (truncated to 2 decimal digits)
in the storage area has the binary value -48.
The above example demonstrates how the improper use of redefinition may give
unexpected or incorrect results.
140 COBOL/400 Reference
RENAMES Clause
REDEFINES Clause Examples
The REDEFINES clause may be specified for an item within the scope of an area
being redefined (that is, an item subordinate to a redefined item). For example:
5 REGULAR-EMPLOYEE.
1 LOCATION PICTURE A(8).
1 GRADE PICTURE X(4).
1 SEMI-MONTHLY-PAY PICTURE 9999V99.
1 WEEKLY-PAY REDEFINES SEMI-MONTHLY-PAY
PICTURE 999V999.
5 TEMPORARY-EMPLOYEE REDEFINES REGULAR-EMPLOYEE.
1 LOCATION PICTURE A(8).
1 FILLER PICTURE X(6).
1 HOURLY-PAY PICTURE 99V99.
The REDEFINES clause may also be specified for an item subordinate to a rede-
fining item. For example:
5 REGULAR-EMPLOYEE.
1 LOCATION PICTURE A(8).
1 GRADE PICTURE X(4).
1 SEMI-MONTHLY-PAY PICTURE 999V999.
5 TEMPORARY-EMPLOYEE REDEFINES REGULAR-EMPLOYEE.
1 LOCATION PICTURE A(8).
1 FILLER PICTURE X(6).
1 HOURLY-PAY PICTURE 99V99.
1 CODE-H REDEFINES HOURLY-PAY PICTURE 9999.
Undefined Results
Undefined results may occur when:
A redefining item is moved to a redefined item (that is, if B REDEFINES C and the
statement MOVE B TO C is executed).
A redefined item is moved to a redefining item (that is, if B REDEFINES C and if
the statement MOVE C TO B is executed).
RENAMES Clause
The RENAMES clause specifies alternative, possibly overlapping, groupings of ele-
mentary data items.
66 dataname1 RENAMES dataname2.
THROUGHdataname3
THRU
Figure 77. Format
The special level-number 66 must be specified for data description entries that
contain the RENAMES clause. Level-number 66 and data-name-1 are not part of
the RENAMES clause itself, and are included in the format only for clarity.
Chapter 6. Data DivisionData Description Entry 141
RENAMES Clause
One or more RENAMES entries can be written for a logical record. All RENAMES
entries associated with one logical record must immediately follow that record's last
data description entry.
data-name-1
Identifies an alternative grouping of data items.
A level-66 entry cannot rename a level-01, level-77, level-88, or another
level-66 entry.
Data-name-1 cannot be used as a qualifier; it can be qualified only by the
names of level indicator entries or level-01 entries.
data-name-2, data-name-3
Identify the original grouping of elementary data items; that is, they must name
elementary or group items within the associated level-01 entry, and must not be
the same data-name. Both data-names may be qualified.
The OCCURS clause must not be specified in the data entries for data-name-2
and data-name-3, or for any group entry to which they are subordinate. In
addition, the OCCURS DEPENDING ON clause must not be specified for any
item defined between data-name-2 and data-name-3.
When data-name-3 is specified, data-name-1 is treated as a group item that
includes all elementary items:
Starting with data-name-2 (if it is an elementary item) or the first elementary
item within data-name-2 (if it is a group item)
Ending with data-name-3 (if it is an elementary item) or the last elementary
item within data-name-3 (if it is a group item)
The key words THROUGH and THRU are equivalent.
The leftmost character in data-name-3 must not precede that in data-name-2;
the rightmost character in data-name-3 must follow that in data-name-2. This
means that data-name-3 cannot be subordinate to data-name-2.
When data-name-3 is not specified, all of the data attributes of data-name-2
become the data attributes for data-name-1. That is:
When data-name-2 is a group item, data-name-1 is treated as a group
item.
When data-name-2 is an elementary item, data-name-1 is treated as an
elementary item.
Figure 78 illustrates valid and invalid RENAMES clause specifications.
142 COBOL/400 Reference
SIGN Clause
COBOL Specifications Storage Layouts
Example 1 (Valid)
1 RECORDI.
5 DN1... . RECORDI
5 DN2... .
5 DN3... . DN1 DN2 DN3 DN4
5 DN4... .
66 DN6 RENAMES DN1 THROUGH DN3. DN6
Example 2 (Valid)
1 RECORDII. RECORDII
5 DN1. DN1
1 DN2... .
1 DN2A... . DN2 DN2A DN5
5 DN1A REDEFINES DN1.
1 DN3A... . DN1A
1 DN3... .
1 DN3B... . DN3A DN3 DN3B
5 DN5... .
66 DN6 RENAMES DN2 THROUGH DN3. DN6
Example 3 (Invalid)
1 RECORDIII. RECORDIII
5 DN2. DN2
1 DN3... .
1 DN4... . DN3 DN4 DN5
5 DN5... .
66 DN6 RENAMES DN2 THROUGH DN3. DN6 is indeterminate
Example 4 (Invalid)
1 RECORDIV. RECORDIV
5 DN1. DN1
1 DN2A... .
1 DN2B... . DN2A DN2B DN3
1 DN2C REDEFINES DN2B.
15 DN2... .
15 DN2D... . DN2 DN2D
5 DN3... .
66 DN4 RENAMES DN1 THROUGH DN2. DN4 is indeterminate
Figure 78. RENAMES ClauseValid and Invalid Specifications
SIGN Clause
The SIGN clause specifies the position and mode of representation of the opera-
tional sign for a numeric entry.
LEADING
SIGN TRAILING SEPARATE
IS CHARACTER
Figure 79. Format
The SIGN clause may be specified only for a signed numeric data description entry
(that is, one whose PICTURE character-string contains an S), or for a group item
that contains at least one such elementary entry. USAGE IS DISPLAY must be
specified, explicitly or implicitly.
Chapter 6. Data DivisionData Description Entry 143
SYNCHRONIZED Clause
If a SIGN clause is specified in either an elementary or group entry subordinate to
a group item for which a SIGN clause is specified, the SIGN clause for the subordi-
nate entry takes precedence for the subordinate entry.
If you specify the CODE-SET clause in an FD entry, any signed numeric data
description entries associated with that file description entry must be described with
the SIGN IS SEPARATE clause.
The SIGN clause is required only when an explicit description of the properties
and/or position of the operational sign is necessary.
When specified, the SIGN clause defines the position and mode of representation
of the operational sign for the numeric data description entry to which it applies, or
for each signed numeric data description entry subordinate to the group to which it
applies.
If the SEPARATE CHARACTER phrase is not specified, then:
The operational sign is presumed to be associated with the LEADING or
TRAILING digit position, whichever is specified, of the elementary numeric data
item. (In this instance, specification of SIGN IS TRAILING is the equivalent of
the standard action of the compiler.)
The character S in the PICTURE character string is not counted in determining
the size of the item (in terms of standard data format characters).
If the SEPARATE CHARACTER phrase is specified, then:
The operational sign is presumed to be the LEADING or TRAILING character
position, whichever is specified, of the elementary numeric data item. This
character position is not a digit position.
The character S in the PICTURE character string is counted in determining the
size of the data item (in terms of standard data format characters).
+ is the character used for the positive operational sign.
- is the character used for the negative operational sign.
Every numeric data description entry whose PICTURE contains the symbol S is a
signed numeric data description entry. If the SIGN clause is also specified for such
an entry, and conversion is necessary for computations or comparisons, the con-
version takes place automatically.
SYNCHRONIZED Clause
The SYNCHRONIZED clause specifies the alignment of an elementary item on a
natural boundary in storage.
SYNCHRONIZED
SYNC LEFT
RIGHT
Figure 80. Format
SYNC is an abbreviation for SYNCHRONIZED and has the same meaning.
144 COBOL/400 Reference
SYNCHRONIZED Clause
The SYNCHRONIZED clause is never required, but may improve performance on
some systems for binary items used in arithmetic.
The SYNCHRONIZED clause may appear only at the elementary level. It is not
permitted for group items.
IBM Extension
The SYNCHRONIZED clause is implicit for pointer data items.
End of IBM Extension
Depending on the USAGE that is specified for an item, the SYNCHRONIZED
clause has a particular effect. Figure 81 shows how the USAGE of an item deter-
mines the effect of the SYNCHRONIZED clause upon it.
If the USAGE is... The SYNCHRONIZED clause...
DISPLAY is syntax checked but does not affect execution
PACKED-DECIMAL is syntax checked but does not affect execution
BINARY:
PIC S9(1) thru S9(4) aligns data item at a multiple of 2 relative
to the beginning of the record
PIC S9(5) thru S9(18) aligns data item at a multiple of 4 relative
to the beginning of the record
2 2 2 2 2 2 2 2 2 2
4 4 4 4 4
8 8 8 8 8 8
Figure 82. Computer Storage Allocation
@ Indicates implicit FILLER bytes allocated because of automatic synchronization
or a record (01-level) description
# Indicates implicit FILLER bytes allocated when the following data item is explic-
itly synchronized
* The first byte of a BINARY item that has been synchronized
$ Indicates implicit FILLER bytes allocated when a non-elementary item is subject
to an OCCURS clause.
9 Indicates bytes allocated for a numeric DISPLAY character
X Indicates bytes allocated for an alphanumeric DISPLAY character
C Indicates bytes allocated for a BINARY data storage
148 COBOL/400 Reference
USAGE Clause
USAGE Clause
BINARY
USAGE COMPUTATIONAL
IS COMP
COMPUTATIONAL-3
COMP-3
COMPUTATIONAL-4
COMP-4
DISPLAY
INDEX
PACKED-DECIMAL
POINTER
Figure 83. Format
The USAGE clause can be specified for an entry at any level. However, if it is
specified at the group level, it applies to each elementary item in the group. The
usage of an elementary item must not contradict the usage of a group to which the
elementary item belongs.
The USAGE clause specifies the format in which data is represented in storage.
The format may be restricted if certain Procedure Division statements are used.
When the USAGE clause is not specified at either the group or elementary level, it
is assumed that the usage is DISPLAY.
Computational Items
A computational item is a value used in arithmetic operations. It must be numeric.
If the USAGE of a group item is described with any of these items, the elementary
items within the group have this usage. The group itself is considered nonnumeric
and cannot be used in numeric operations, except for those using the CORRE-
SPONDING phrase (see CORRESPONDING Phrase on page 186).
The maximum length of a computational item is 18 decimal digits.
The PICTURE of a computational item may contain only:
9 One or more numeric character positions
S One operational sign
V One implied decimal point
P One or more decimal scaling positions.
BINARY
Specified for binary data items. Such items have a decimal equivalent con-
sisting of the decimal digits 0 through 9, plus a sign. Negative numbers are
represented as the two's complement of the positive number with the same
absolute value.
Chapter 6. Data DivisionData Description Entry 149
USAGE Clause
The amount of storage occupied by a binary item depends on the number of
decimal digits defined in its PICTURE clause:
Digits in
PICTURE Clause Storage Occupied
1 through 4 2 bytes
5 through 9 4 bytes
10 through 18 8 bytes
The leftmost bit of the storage area is the operational sign.
For better performance, avoid using 8-byte binary items. You can specify these
items for convenience, but the compiler must make conversions in order to use
them.
PACKED-DECIMAL
Specified for internal decimal items. Such an item appears in storage in
packed decimal format. There are 2 digits for each character position, except
for the trailing character position, which is occupied by the low-order digit and
the sign. Such an item may contain any of the digits 0 through 9, plus a sign,
representing a value not exceeding 18 decimal digits.
The sign representation is shown in Figure 84 on page 152.
COMPUTATIONAL or COMP
Specified for internal decimal items. Such an item appears in storage as 2
digits per byte, with the sign contained in the 4 rightmost bits of the rightmost
byte. An internal decimal item can contain any of the digits 0 through 9 plus a
sign. If the PICTURE of an internal decimal item does not contain an S, the
sign position is occupied by a bit configuration that is interpreted as positive.
IBM Extension
COMPUTATIONAL-3 or COMP-3 (internal decimal)
This is the equivalent of PACKED-DECIMAL.
COMPUTATIONAL-4 or COMP-4 (binary)
This is the equivalent of BINARY.
End of IBM Extension
To improve compilation performance, specify odd numbers of numeric character
positions in the picture clauses for COMP-3 (packed decimal) items. Internally,
the rightmost byte of a packed decimal item contains a digit and a sign, and
any other bytes contain two digits. If you use the more efficient configuration,
the compiler does not need to supply the missing digit.
| When a packed decimal item containing an even number of digits is redefined
| or forms part of a group field, the leftmost (unused) digit position of the allo-
| cated storage might contain an unexpected value if, for example, data from a
| longer field has been moved to the item.
150 COBOL/400 Reference
USAGE Clause
DISPLAY Phrase
The data item is stored in character form, 1 character for each 8-bit byte. This
corresponds to the format used for printed output. DISPLAY can be explicit or
implicit.
USAGE IS DISPLAY is valid for the following types of items:
Alphabetic
Alphanumeric
Alphanumeric-edited
Numeric-edited
IBM Extension
Boolean
End of IBM Extension
External decimal (numeric).
Alphabetic, alphanumeric, alphanumeric-edited, and numeric-edited items are
discussed in Data Categories and PICTURE Rules on page 130.
The PICTURE character-string of a zoned item can contain only 9s, the operational
sign symbol S, the assumed decimal point V, and one or more Ps.
External Decimal Items are sometimes referred to as zoned decimal items. Each
digit of a number is represented by a single byte. The 4 high-order bits of each
byte are zone bits; the 4 high-order bits of the low-order byte represent the sign of
the item. If the number is positive, these four bits contain a hexadecimal F. If the
number is negative, these four bits contain a hexadecimal D. The 4 low-order bits
of each byte contain the value of the digit.
The maximum length of an external decimal item is 18 digits.
The PICTURE character-string of an external decimal item may contain only 9s; the
operational-sign, S; the assumed decimal point, V; and one or more Ps.
Examples of external decimal items are shown in Figure 84 on page 152.
Chapter 6. Data DivisionData Description Entry 151
USAGE Clause
NOTES:
1. The leftmost bit of a binary number represents the sign: is positive, 1 is negative.
2. Negative binary numbers are represented in twos complement form.
3. Hex 4E represents the EBCDIC character +, Hex 6 represents the EBCDIC character .
4. Specification of SIGN TRAILING (without the SEPARATE CHARACTER option) is the equivalent
of the standard action of the compiler.
C|
SEQUENCE O| A B
N|
PAGE SERIALT|
1 34 67|8 12 16 2 24 28 32 36
41 |PROCEDURE DIVISION.
2 |DECLARATIVES.
3 |SECTION-NAME SECTION.
4 |PARAGRAPH-NAMES.
5 | PROGRAMMING STATEMENTS.
6| COMMENTS.
7 |END DECLARATIVES.
8 |SECTION-NAME SECTION.
9 |PARAGRAPH-NAME.
1 | PROGRAMMING STATEMENTS.
NU
NU
Numeric Literal (NL) NU NU NU NU
External Decimal (ED) NU NU NU NU NU NU
Binary (BI) NU NU NU NU NU NU
Arithmetic Expression (AE) NU NU NU NU NU NU
IBM Extension
Boolean data item or Boolean literal
(BO)
End of IBM Extension
NU
Internal Decimal (ID) NU NU NU NU NU NU
Notes to Table 18 on page 172 and Table 19:
Includes all figurative constants except ZERO and NULL
Integer item only
Comparison of Numeric and Nonnumeric Operands
Comparing Numeric Operands: The algebraic values of numeric operands are
compared.
The length (number of digits) of the operands is not significant.
Unsigned numeric operands are considered positive.
Zero is considered to be a unique value, regardless of sign.
Comparison of numeric operands is permitted, regardless of the type of
USAGE specified for each.
Comparing Nonnumeric Operands: Comparisons of nonnumeric operands are
made with respect to the collating sequence of the character set in use.
When the PROGRAM COLLATING SEQUENCE clause is specified in the
OBJECT-COMPUTER paragraph, the collating sequence associated with the
Chapter 7. Procedure Division 173
Conditional Expressions
alphabet-name clause in the SPECIAL-NAMES paragraph is used. Otherwise, the
native EBCDIC character set is used.
The size of each operand is the total number of characters in that operand; the size
affects the result of the comparison. There are two cases to consider:
Operands of Equal Size
Characters in corresponding positions of the two operands are compared,
beginning with the leftmost character and continuing through the rightmost
character.
If all pairs of characters through the last pair test as equal, the operands
are considered as equal.
If a pair of unequal characters is encountered, the characters are tested to
determine their relative positions in the collating sequence. The operand
containing the character higher in the sequence is considered the greater
operand.
Operands of Unequal Size
If the operands are of unequal size, the comparison is made as though the
shorter operand were extended to the right with enough spaces to make
the operands equal in size.
Comparing Numeric and Nonnumeric Operands: The nonnumeric comparison
rules, discussed above, apply. In addition, when numeric and nonnumeric oper-
ands are being compared, their USAGE must be the same. In such comparisons:
The numeric operand must be described as an integer literal or data item.
Noninteger literals and data items must not be compared with nonnumeric
operands.
If either of the operands is a group item, the nonnumeric comparison rules, dis-
cussed above, apply. In addition to those rules:
If the nonnumeric operand is a literal or an elementary data item, the
numeric operand is treated as though it were moved to an alphanumeric ele-
mentary data item of the same size, and the contents of this alphanumeric data
item were then compared with the nonnumeric operand.
If the nonnumeric operand is a group item, the numeric operand is treated as
though it were moved to a group item of the same size, and the contents of this
group item were compared then with the nonnumeric operand.
(See MOVE Statement on page 295.)
IBM Extension
Comparison of Boolean Operands: Boolean operands can be used only in the
[NOT] EQUAL TO relation condition. Boolean operands cannot be compared to
non-Boolean operands. Boolean data items and literals must be one position in
length. Two Boolean operands are equal if they both have a value of Boolean 1 or
Boolean 0. The Boolean operands are unequal if one has a value of Boolean 1
and the other has a value of Boolean 0.
End of IBM Extension
174 COBOL/400 Reference
Conditional Expressions
Comparing Index-Names and Index Data Items: Comparisons involving index-
names and/or index data items conform to the following rules:
The comparison of two index-names is actually the comparison of the corre-
sponding occurrence numbers.
In the comparison of an index-name with a data item (other than an index data
item), or in the comparison of an index-name with a literal, the occurrence
number that corresponds to the value of the index-name is compared with the
data item or literal.
In the comparison of an index data item with an index-name or another index
data item, the actual values are compared without conversion. Results of any
other comparison involving an index data item are undefined.
Table 20 shows valid comparisons involving index-names and index data items.
Table 20. Comparisons Involving Index Names and Index Data Items
Operands
Compared
Index-Name Index Data
Item
Data-Name Literal
Index-Name Compare
occurrence
number
Compare
without con-
version
Compare
occurrence
number with
data-name
Compare
occurrence
number with
literal
Index Data
Item
Compare
without con-
version
Compare
without con-
version
Not permitted Not permitted
Sign Condition
The sign condition determines whether or not the algebraic value of a numeric
operand is greater than, less than, or equal to zero.
operandPOSITIVE
IS NOT NEGATIVE
ZERO
Figure 96. Format
operand
Must be defined as a numeric identifier, or it must be defined as an arithmetic
expression that contains at least one reference to an identifier.
The operand is:
POSITIVE if its value is greater than zero
NEGATIVE if its value is less than zero
ZERO if its value is equal to zero.
An unsigned operand is either POSITIVE or ZERO.
NOT
An algebraic test is executed for the truth value of the sign condition. For
example, NOT ZERO is regarded as true when the operand tested is positive
or negative in value.
Chapter 7. Procedure Division 175
Conditional Expressions
Switch-Status Condition
The switch-status condition determines the on or off status of an UPSI switch.
condition-name
Figure 97. Format
condition-name
Must be defined in the SPECIAL-NAMES paragraph as associated with the ON
or OFF value of an UPSI switch. (See SPECIAL-NAMES Paragraph on
page 37.)
The switch-status condition tests the value associated with the condition-name.
(The value associated with the condition-name is considered to be alphanumeric.)
The result of the test is true if the UPSI switch is set to the value (0 or 1) corre-
sponding to condition-name.
Complex Conditions
A complex condition is formed by combining simple conditions, combined condi-
tions, and/or complex conditions with logical operators, or negating these conditions
with logical negation.
Each logical operator must be preceded and followed by a space. The following
chart shows the logical operators and their meanings.
Unless modified by parentheses, the following precedence rules (from highest to
lowest) apply:
1. Arithmetic operations
2. Simple conditions
3. NOT
4. AND
5. OR
The truth value of a complex condition (whether parenthesized or not) is the truth
value that results from the interaction of all the stated logical operators on either of
the following:
The individual truth values of simple conditions
The intermediate truth values of conditions logically combined or logically
negated.
Table 21. Logical Operators and Their Meanings
Logical
Operator
Name
Meaning
AND Logical con-
junction
The truth value is true when both conditions are true.
OR Logical inclu-
sive OR
The truth value is true when either or both conditions
are true.
NOT Logical
negation
Reversal of truth value (the truth value is true if the
condition is false).
176 COBOL/400 Reference
Conditional Expressions
A complex condition can be either of the following:
A negated simple condition
A combined condition (which can be negated).
Negated Simple Conditions
A simple condition is negated through the use of the logical operator NOT.
NOTsimple-condition
Figure 98. Format
The negated simple condition gives the opposite truth value of the simple condition.
That is, if the truth value of the simple condition is true, then the truth value of that
same negated simple condition is false, and vice versa.
Placing a negated simple condition within parentheses does not change its truth
value. That is, the following two statements are equivalent:
NOT A IS EQUAL TO B.
NOT (A IS EQUAL TO B).
Combined Conditions
Two or more conditions can be logically connected to form a combined condition.
condition-1ANDcondition-2
OR
Figure 99. Format
The condition to be combined may be any of the following:
A simple-condition
A negated simple-condition
A combined condition
A negated combined condition (that is, the NOT logical operator followed by a
combined condition enclosed in parentheses)
Combinations of the preceding conditions, specified according to the rules in
Figure 100 on page 178.
Chapter 7. Procedure Division 177
Conditional Expressions
OR No simple-condition No simple-condition
AND ) NOT
(
( Yes OR No simple-condition
NOT NOT
AND (
(
) No simple-condition Yes OR
) AND
)
SIZE ERRORimperative-statement-1
ON
NOTSIZE ERRORimperative-statement-2
ON
END-ADD
Figure 115. Format 1
Identifiers and literals preceding the keyword TO are added together, and this initial
sum is added to and stored in identifier-2. The initial sum is also added to each
successive occurrence of identifier-2, in the left-to-right order in which identifier-2 is
specified.
ADDidentifier-1identifier-2
literal-1 TO literal-2
GIVINGidentifier-3
ROUNDED
SIZE ERRORimperative-statement-1
ON
NOTSIZE ERRORimperative-statement-2
ON
END-ADD
Figure 116. Format 2
The values of the operands preceding the word GIVING are added together, and
the sum is stored as the new value of each data item referenced by identifier-3.
Chapter 8. Procedure Division Statements 221
ADD Statement
ADDCORRESPONDINGidentifier-1 TO identifier-2
CORR ROUNDED
SIZE ERRORimperative-statement-1
ON
NOTSIZE ERRORimperative-statement-2
ON
END-ADD
Figure 117. Format 3
Elementary data items within identifier-1 are added to and stored in the corre-
sponding elementary items within identifier-2.
For all Formats:
identifier
In Format 1, must name an elementary numeric item.
In Format 2, must name an elementary numeric item, except when following the
word GIVING. Each identifier following the word GIVING must name an ele-
mentary numeric or numeric-edited item.
In Format 3, must name a group item.
literal
Must be a numeric literal.
If the composite of operands is 18 digits or less, enough places are carried so that
no significant digits are lost during execution.
In Format 1, the composite of operands is determined by using all of the oper-
ands in a given statement.
In Format 2, the composite of operands is determined by using all of the oper-
ands in a given statement excluding the data items that follow the word
GIVING.
In Format 3, the composite of operands is determined separately for each pair
of corresponding data items.
IBM Extension
The composite of all operands in an arithmetic statement can have a maximum
length of 30 digits.
End of IBM Extension
222 COBOL/400 Reference
ADD Statement
ROUNDED Phrase
For Formats 1, 2, and 3, see ROUNDED Phrase on page 187.
SIZE ERROR Phrases
For Formats 1, 2, and 3, see SIZE ERROR Phrases on page 188.
CORRESPONDING Phrase (Format 3)
See CORRESPONDING Phrase on page 186.
IBM Extension
Identifiers d1 and/or d2 can be subordinate to a FILLER item.
End of IBM Extension
END-ADD Phrase
This explicit scope terminator serves to delimit the scope of the ADD statement.
END-ADD permits a conditional ADD statement to be nested in another conditional
statement. END-ADD may also be used with an imperative ADD statement.
For more information, see Delimited Scope Statements on page 184.
Chapter 8. Procedure Division Statements 223
ALTER Statement
ALTER Statement
The ALTER statement changes the transfer point specified in a GO TO statement.
Note: The ALTER statement is an obsolete element and encourages the use of
unstructured programming practices; it is to be deleted from the next revision of the
ANSI Standard. The EVALUATE statement provides the same function as the
ALTER statement and helps to ensure that your program will be well-structured.
ALTER procedurename1 TOprocedurename2
PROCEED TO
Figure 118. Format
The ALTER statement modifies the GO TO statement in the paragraph named by
procedure-name-1. Subsequent executions of the modified GO TO statement(s)
transfer control to procedure-name-2.
procedure-name-1
Must name a Procedure Division paragraph that contains only one sentence: a
GO TO statement without the DEPENDING ON phrase.
procedure-name-2
Must name a Procedure Division section or paragraph.
Before the ALTER statement is executed, when control reaches the paragraph
specified in procedure-name-1, the GO TO statement transfers control to the para-
graph specified in the GO TO statement. After execution of the ALTER statement,
however, the next time control reaches the paragraph specified in
procedure-name-1, the GO TO statement transfers control to the paragraph speci-
fied in procedure-name-2.
The ALTER statement acts as a program switch, allowing, for example, one
sequence of execution during initialization and another sequence during the bulk of
file processing. Because altered GO TO statements are difficult to debug, it is pref-
erable to test a switch, and based on the value of the switch, execute a particular
code sequence. For example:
PARAGRAPH-1.
GO TO BYPASS-PARAGRAPH.
PARAGRAPH-1A.
.
.
BYPASS-PARAGRAPH.
.
.
ALTER PARAGRAPH-1 TO PROCEED TO
PARAGRAPH-2.
.
.
PARAGRAPH-2.
.
.
224 COBOL/400 Reference
ALTER Statement
Before the ALTER statement is executed, when control reaches PARAGRAPH-1,
the GO TO statement transfers control to BYPASS-PARAGRAPH. After execution
of the ALTER statement, however, the next time control reaches PARAGRAPH-1,
the GO TO statement transfers control to PARAGRAPH-2.
Segmentation Information
A GO TO statement in a section whose segment-number is greater than or equal to
50 must not be referred to by an ALTER statement in a section with a different
segment-number. All other uses of the ALTER statement are valid and are per-
formed.
Modified GO TO statements in independent segments can sometimes be returned
to their initial states. See the COBOL/400 Users Guide for a further discussion of
segmentation information.
Chapter 8. Procedure Division Statements 225
CALL Statement
CALL Statement
The CALL statement transfers control from one object program to another within
the run unit.
The program containing the CALL statement is the calling program; the program
identified in the CALL statement is the called subprogram. The calling program
must contain a CALL statement at the point where another program is to be called.
Processing of the CALL statement passes control to the first nondeclarative instruc-
tion of the called subprogram. Control returns to the calling program at the instruc-
tion following the CALL statement.
Called subprograms themselves can contain CALL statements, but a called subpro-
gram that contains a CALL statement that directly or indirectly calls the calling
program gives unpredictable results.
CALLidentifier-1
literal-1
USINGidentifier-2
REFERENCE
BY ADDRESS OF
file-name-1
CONTENTidentifier-2
BY
ADDRESS OF
LENGTH OF
literal-2
file-name-1
OVERFLOW imperative-statement-1
ON
END-CALL
Figure 119. Format 1
226 COBOL/400 Reference
CALL Statement
CALLidentifier-1
literal-1
USINGidentifier-2
REFERENCE
BY ADDRESS OF
file-name-1
CONTENTidentifier-2
BY
ADDRESS OF
LENGTH OF
literal-2
file-name-1
EXCEPTION imperative-statement-1
ON
NOTEXCEPTION imperative-statement-2
ON
END-CALL
Figure 120. Format 2
literal-1
Must be nonnumeric, uppercase, and must conform to the rules for formation of
program-names. The first 10 characters of the literal are used to make the
correspondence between the calling program and the called subprogram. The
literal must specify the program-name of the called subprogram.
If literal-1 is specified, the call is classified as a static call because the
PROGRAM-ID is determined at compile time.
identifier-1
Must be an alphanumeric data item. Its contents must conform to the rules for
formation of a program-name. The first 10 characters of identifier-1 are used to
make the correspondence between the calling and the called program.
If identifier-1 is specified, the call is classified as a dynamic call because the
PROGRAM-ID is resolved at run time each time a call is made. If literal-1 is
specified, the PROGRAM-ID is resolved only once.
CALL statement processing passes control to the called subprogram, which
becomes part of the run unit. If a CALL statement names a program that does not
exist in the jobs library list (*LIBL) at run time, an error message is issued.
A called subprogram is in its initial state the first time it is called within a run unit. It
is also in its initial state the first time it is called after a CANCEL statement. On all
Chapter 8. Procedure Division Statements 227
CALL Statement
other entries into the called subprogram, it is in its last-used state, and the reinitial-
ization of any items is the responsibility of the user.
The user return code is set to 0 at the start of the processing of any COBOL
program, and before a call is made to another program. See the RTVJOBA and
DSPJOB commands in the CL Programmers Guide for more information about
return codes.
USING
Included in the CALL statement only if there is a USING phrase in the Proce-
dure Division header of the called subprogram. USING phrases can contain up
to 30 operands, and the number of operands in each must be identical.
For more information about the USING phrase, see The USING Phrase on
page 160.
COBOL/400 programs can pass arguments to other AS/400 programs. The
attributes of the data passed depend on the requirements of the called subpro-
gram. If a called program requires several parameters, you must specify the
identity of each parameter, rather than a group item that consists of the param-
eters.
The sequence of identifiers in the USING phrase of the CALL statement and in
the corresponding USING phrase in the called subprogram's Procedure Division
header determines the correspondence between the identifiers used by the
calling and called programs. This correspondence is by position, rather than by
name.
The values of the parameters referenced in the USING phrase of the CALL
statement are made available to the called subprogram at the time the CALL
statement is executed.
BY REFERENCE Phrase
The value of a parameter passed through the BY REFERENCE phrase is evaluated
when the CALL statement runs. This value is assigned to the corresponding
parameter of the called program. The number of characters in each parameter
must be equal; however, the data descriptions need not be the same.
When a COBOL/400 parameter is passed BY REFERENCE, a pointer to the ori-
ginal data item passes to the called program. Because of this, a change to a
parameter in a called program will result in a change to a data item in a calling
program.
identifier-2
Must be defined as a level-01, level-77, or elementary data item in the File
Section, Working-Storage Section, or Linkage Section.
IBM Extension
It can be:
A data item of any level in the Data Division
A pointer data item (an item defined implicitly or explicitly as USAGE IS
POINTER).
228 COBOL/400 Reference
CALL Statement
ADDRESS OF special register
For information about this special register, see page 82. Note that the
ADDRESS OF a data item is not allowed in this case.
file-name-1
Must appear in an FD entry. It passes a pointer data item that refers to a File
Information Block (FIB).
End of IBM Extension
BY CONTENT Phrase
The value of a parameter passed through the BY CONTENT phrase is evaluated
when the CALL statement runs. The value is assigned to the corresponding
parameter of the called program.
For each COBOL/400 item passed BY CONTENT, a copy of the item is made in
the calling program, and a pointer to this copy passes to the called program.
Changes made to the parameter in the called program do not affect the data item
of the calling program. The number of characters in each parameter must be
equal; however, the data descriptions need not be the same.
identifier-2
Must be defined as a level-01, level-77, or elementary data item in the File
Section, Working-Storage Section, or Linkage Section.
IBM Extension
It can be:
A data item of any level in the Data Division
A pointer data item (an item defined implicitly or explicitly as USAGE IS
POINTER).
ADDRESS OF special register
For information about this special register, see page 82.
ADDRESS OF a data item
For information about this, see page 82.
LENGTH OF special register
For information about this special register, see page 7.
literal-2
Can be:
A nonnumeric literal
A figurative constant
A Boolean literal.
file-name-1
Must appear in an FD entry. It passes a pointer data item that refers to a File
Information Block (FIB).
End of IBM Extension
Chapter 8. Procedure Division Statements 229
CALL Statement
The BY CONTENT and BY REFERENCE phrases apply to the parameters that
follow them until another BY CONTENT or BY REFERENCE phrase is encount-
ered. In the absence of both phrases, BY REFERENCE is assumed.
ON EXCEPTION Phrase
An exception condition occurs when the called subprogram cannot be made avail-
able. At that time, one of the following occurs:
1. If the ON EXCEPTION phrase appears in the CALL statement, control transfers
to imperative-statement-1. Processing then continues according to the rules for
each statement specified in imperative-statement-1.
If a procedure-branching or conditional statement causing explicit transfer of
control runs, control transfers according to the rules for that statement. Other-
wise, once imperative-statement-1 has run, control transfers to the end of the
CALL statement, and the NOT ON EXCEPTION phrase, if specified, is ignored.
2. If the ON EXCEPTION phrase does not appear in the CALL statement, the
NOT ON EXCEPTION phrase, if specified, is ignored.
This phrase handles only the exceptions that result from program existence,
authority, and storage.
NOT ON EXCEPTION Phrase
If an exception condition does not occur (in other words, the called subprogram can
be made available), control transfers to the called program. After control returns
from the called program, the ON EXCEPTION phrase, if specified, is ignored, and
control transfers to the end of the CALL statement (or to imperative-statement-2, if
the NOT ON EXCEPTION phrase is specified).
If control transfers to imperative-statement-2, processing continues according to the
rules for each statement specified in imperative-statement-2.
If a procedure-branching or conditional statement causing explicit transfer of control
runs, control transfers according to the rules for that statement. Otherwise, once
imperative-statement-2 has run, control transfers to the end of the CALL statement.
If you specify this phrase in conjunction with the ON OVERFLOW phrase, an error
will result.
ON OVERFLOW Phrase
The ON OVERFLOW phrase has the same effect as the ON EXCEPTION phrase.
END-CALL Phrase
This explicit scope terminator delimits the scope of the CALL statement.
END-CALL permits a conditional CALL statement to be nested in another condi-
tional statement. END-CALL can also be used with an imperative CALL statement.
For more information, see Delimited Scope Statements on page 184.
230 COBOL/400 Reference
CALL Statement
Program Termination Statements
A main program is the highest-level COBOL program invoked in a run unit. A sub-
program is a COBOL program invoked by another COBOL program.
Table 27 shows the action taken for each program termination statement in both a
main program and a subprogram.
1
If the main program is called by a program written in another language that
does not follow COBOL linkage conventions, return will be to this calling
program.
1a
Execution of the run unit ceases and control is transferred to the operating
system. See the chapter on Interprogram Communication in the COBOL/400
Users Guide for information about run units.
2
The GOBACK statement is an IBM extension.
USING Phrase Example
Note: In the calling program, the code for parts (PARTCODE) and the part
number (PARTNO) are referred to separately. In the called subprogram, the code
for parts and the part number are combined into one data item (PART-ID); there-
fore in the called subprogram, a reference to PART-ID is the only valid reference to
them.
Table 27. Program Termination Actions
Termination
Statement
Main Program
Subprogram
EXIT
PROGRAM
Nonoperational Return to calling
program.
STOP RUN Return to calling
program.
1
(May be the
system and cause job to
end.
1a
)
Return directly to the
program that called the
main program.
1
(May be
the system and cause job
to end.
1a
)
GOBACK
2
Return to calling
program.
1
(May be the
system and cause job to
end.
1a
)
Return to calling
program.
Calling Program Description (PGMA) Called Program Description (PGMB)
WORKING-STORAGE SECTION.
1 PARAM-LIST.
5 PARTCODE PIC A.
5 PARTNO PIC X(4).
5 U-SALES PIC 9(5).
.
.
.
PROCEDURE DIVISION.
.
.
.
CALL PGMB
USING PARAM-LIST.
LINKAGE SECTION.
1 USING-LIST.
1 PART-ID PIC X(5).
1 SALES PIC 9(5).
.
.
.
PROCEDURE DIVISION USING
USING-LIST.
Chapter 8. Procedure Division Statements 231
CALL Statement
CALL Statement Considerations
Call by Identifier
A system pointer that associates an identifier with a specific program object is set
when you first use the identifier in a CALL statement. The value of this pointer
never changes, unless:
You use a CANCEL statement against the identifier, or,
You change the value of the identifier and perform a call using this new value.
The CANCEL statement nulls the pointer; when you next use the identifier in a
CALL statement, the system pointer is set again. You must run the CANCEL state-
ment from the program that originally performed the call.
Important for Compatibility!
If you carry out a call by an identifier to a program that you subsequently delete
or rename, you must use the CANCEL statement to null the system pointer
associated with the identifier.
Length of Parameters
If the length of a list of arguments (in bytes) does not match the expected length,
unexpected results could occur in the called or calling program.
OS/400 Graphics Support
You can use the CALL statement to access the following OS/400 graphics routines:
Graphical Data Display Manager (GDDM), a set of graphics primitives for
drawing pictures
Presentation Graphics Routines (PGR), a set of business charting routines.
You access all these graphics routines with the same format of the CALL
statement:
CALL "GDDM" USINGroutine-name
data-name-1
Figure 121. CALL GDDM
Routine-name is the name of the graphics routine you want to use.
The data-names that follow routine-name are the parameters necessary to use
certain graphics routines. The number of parameters that you must specify varies,
depending on which routine you select. When you select a graphics routine, make
sure each parameter is the correct size and data type as required by that routine.
232 COBOL/400 Reference
CALL Statement
The following are examples of calling graphics routines. Remember, you must use
the CALL literal format and define each parameter as required by the graphics
routine you use.
MOVE "FSINIT" TO OS-4-GRAPHICS-ROUTINE-NAME.
CALL "GDDM" USING OS-4-GRAPHICS-ROUTINE-NAME.
.
.
MOVE "GSFLD" TO OS-4-GRAPHICS-ROUTINE-NAME.
CALL "GDDM" USING OS-4-GRAPHICS-ROUTINE-NAME,
PIC-ROW, PIC-COL,
PIC-DEPTH, PIC-WIDTH.
For more information about graphics routines and their parameters, see the GDDM
Programming Guide and the GDDM Programming Reference.
Chapter 8. Procedure Division Statements 233
CANCEL Statement
CANCEL Statement
The CANCEL statement ensures that the next time the referenced subprogram is
called it will be entered in its initial state.
CANCELidentifier-1
literal-1
Figure 122. Format
literal-1, identifier-1
The name of the subprogram to be canceled. It must be nonnumeric. The
contents must conform to the rules for formation of a program-name (see
PROGRAM-ID Paragraph on page 30).
The first 10 characters of the literal or of the contents of the identifier identify
the connection between the calling program and the called subprogram.
Each literal or contents of the identifier specified in the CANCEL statement
must be the same as the literal or contents of the identifier specified in an
associated CALL statement.
After a CANCEL statement for a called subprogram has been executed, that sub-
program no longer has a logical connection to the program. If a CALL statement is
executed later by any program in the run unit naming the same subprogram, that
subprogram will be entered in its initial state.
A CANCEL statement closes all open files.
You can cancel a called subprogram by either referencing it as the operand of a
CANCEL statement or by terminating the run unit of which the subprogram is a
member.
A CANCEL statement operates only on the program specified, and not on any
program that may have been called by the canceled program.
No action is taken when a CANCEL statement is executed, naming a program that
has not been called in the run unit, or that names a program that was called and
subsequently canceled. In either case, control passes to the next statement.
If a CANCEL statement names a program that does not exist in the library list, an
error message is issued.
Called subprograms may contain CANCEL statements. However, recursive calls
are not allowed; a called subprogram must not contain a CANCEL statement that
directly or indirectly cancels the calling program itself, or any other program higher
than itself in the calling hierarchy. In this case, control is passed to the next state-
ment.
234 COBOL/400 Reference
CANCEL Statement
A program named in a CANCEL statement must not refer to any program that has
been called and has not yet returned control to the calling program. A program
may, however, cancel a program that it did not call, providing that, in the calling
hierarchy, it is higher than or equal to the program it is canceling.
For example:
A calls B and B calls C (When A receives control,
it can cancel C.)
A calls B and A calls C (When C receives control,
it can cancel B.)
Chapter 8. Procedure Division Statements 235
CLOSE Statement
CLOSE Statement
The CLOSE statement terminates the processing of volumes and files, with optional
rewind and/or lock or removal, where applicable.
CLOSEfile-name-1
REEL
UNIT REMOVAL
FOR
NOREWIND
WITH LOCK
Figure 123. Format 1Sequential
CLOSEfilename1
LOCK
WITH
Figure 124. Format 2Indexed and Relative
CLOSEfile-name-1
LOCK
WITH
Figure 125. Format 3TRANSACTION
file-name-1
Designates the file upon which the CLOSE statement is to operate. If more
than one file-name is specified, the files need not have the same organization
or access. File-name-1 must not be a sort or merge file.
A CLOSE statement may be executed only for a file in an open mode. After suc-
cessful execution of a CLOSE statement without the REEL/UNIT phrase:
The record area associated with the file-name is no longer available. Unsuc-
cessful execution of a CLOSE statement leaves availability of the record data
undefined.
An OPEN statement for the file must be executed before any other input/output
statement.
236 COBOL/400 Reference
CLOSE Statement
If the FILE STATUS clause is specified in the FILE-CONTROL entry, the associ-
ated status key is updated when the CLOSE statement is executed. For more
information about the status key, see Common Processing Facilities on page 191.
If the file is in an open status and the execution of a CLOSE statement is unsuc-
cessful, the EXCEPTION/ERROR procedure (if specified) for this file is executed.
If a CLOSE statement for an open file is not processed before a STOP RUN for
this run unit, the file is implicitly closed.
If the SELECT OPTIONAL clause is specified in the file-control entry for this file
and the file is not present at run time, standard end-of-file processing is not per-
formed.
CLOSE Statement Considerations
The following tables illustrate organization, access, device, and volume consider-
ations for the CLOSE statement. The letter codes used in the tables are defined in
the section following the tables.
Table 28. Sequential Organization
ACCESS SEQUENTIAL
DEVICE PRINTER DISKETTE DISK DATABASE FORMATFILE
CLOSE J,K J,K J,K J,K J,K
CLOSE WITH
LOCK
E,J,K E,J,K E,J,K E,J,K E,J,K
REEL/UNIT
REMOVAL
NO REWIND
Table 29. Sequential Organization
ACCESS SEQUENTIAL
DEVICE TAPEFILE
VOLUME SINGLE MULTI
CLOSE G,J,K,L A,G,J,K,L
CLOSE WITH
LOCK
E,G,J,K,L A,E,G,J,K,L
CLOSE NO
REWIND
B,J,K,L A,B,J,K,L
CLOSE
REEL/UNIT
C,L F,G,K,L
CLOSE
REEL/UNIT
FOR
REMOVAL
C,L D,F,G,K,L
Chapter 8. Procedure Division Statements 237
CLOSE Statement
Letter
Code Meaning
An invalid combination.
A No effect on any previous volumes. Any additional volumes are not proc-
essed.
B The current volume is left in its present position. The reel is not rewound.
IBM Extension
The system always rewinds and unloads the tape when REEL/UNIT is
specified on the CLOSE statement.
End of IBM Extension
C Optional, but only syntax-checked (performs no function at run time).
D The current volume is rewound and unloaded. The system is notified that
the volume is logically removed from this run unit. However, the volume
can be accessed again, after processing of a CLOSE statement without
the REEL/UNIT phrase and an OPEN statement for this file.
E COBOL ensures that this file cannot be reopened during this processing of
the program.
For information about file and record locking, see the COBOL/400 Users
Guide.
Table 30. Indexed Organization
ACCESS ANY
DEVICE DISK DATABASE
CLOSE J,K J,K
CLOSE WITH
LOCK
E,J,K E,J,K
REEL/UNIT
REMOVAL
NO REWIND
Table 31. Relative Organization
ACCESS ANY
DEVICE DISK DATABASE
CLOSE J,K,M J,K,M
CLOSE WITH
LOCK
E,J,K,M E,J,K,M
REEL/UNIT
REMOVAL
NO REWIND
238 COBOL/400 Reference
CLOSE Statement
F Close volume procedures. The labels are handled as follows:
F01 The current volume is positioned to read the labels. If this is the
last volume for the file, the next processed READ statement
receives the AT END condition. If this is not the last volume, the
following actions are taken:
1. The current volume is unloaded
2. The beginning standard labels on the next volume are read
3. The next processed READ statement gets the first record on
the newly mounted volume.
F02 The current volume is unloaded. If all of the reels as specified on
the REELS parameter of the Create Tape File (CRTTAPF) or Over-
ride with Tape File (OVRTAPF) CL command have been processed,
the next processed READ statement receives the AT END condi-
tion. If there are more reels, the next volume is mounted, and the
next processed READ statement gets the first record on the newly
mounted volume.
F03 The standard end-of-volume labels are written. The next volume is
mounted. The standard beginning labels are written on the new
volume. The next processed WRITE statement places the next
logical record on the newly mounted volume.
F04 The system end-of-volume procedures for nonlabeled tapes are run.
The next volume is mounted. The system beginning of volume pro-
cedures for nonlabeled tapes are run. The next processed WRITE
statement places the next logical record on the newly mounted
volume.
G The current volume is positioned at its beginning.
J The record area associated with the file-name is no longer available after
successful processing of this statement. Unsuccessful processing of this
statement leaves availability of the record data area undefined.
Labels are processed as follows:
J01 If the file is positioned at its end, the label records are read and
verified, and the file is closed. If the file is not at its end, the file is
closed.
MODE OF FILE
LABEL RECORDS
STANDARD OMITTED
Input F01 F02
Output F03 F04
I-O F01 F02
MODE OF FILE
LABEL RECORDS
STANDARD OMITTED
Input J01 J02
Output J03 J04
I-O J01 J02
Chapter 8. Procedure Division Statements 239
CLOSE Statement
J02 The file is closed.
J03 The standard label records are written, and the file is closed.
J04 The file is closed without any label processing.
K May be processed only for an open file.
L If the ENDOPT keyword has been specified in the Create Tape File
(CRTTAPF) or the Override with Tape File (OVRTAPF) CL command, the
positioning of the tape volume when the file is closed follows the value
specified in that keyword (a value of LEAVE, REWIND, or UNLOAD).
If the ENDOPT keyword has not been specified, the positioning of the tape
volume when the file is closed corresponds to the following ENDOPT
values:
CLOSE NO REWIND statement . . . . LEAVE
All other forms of CLOSE . . . . REWIND
M To extend a relative file boundary beyond the current number of records
and within the file size, use the INZPFM command to add deleted records
before processing the file. You will need to do this when more records
need to be added to the file, and file status 0Q has been received.
Any attempt to extend a relative file beyond its current size results in a
boundary violation.
240 COBOL/400 Reference
COMMIT Statement
IBM Extension
COMMIT Statement
The COMMIT statement provides a way of synchronizing changes to data base
records while preventing other jobs from modifying those records until the COMMIT
is performed. The format of the COMMIT statement is:
COMMIT
Figure 126. COMMIT Statement
When the COMMIT statement is executed, all changes made to files under commit-
ment control since the previous commitment boundary are made permanent. A
commitment boundary is established by the successful execution of a ROLLBACK
or COMMIT statement. If no COMMIT or ROLLBACK has been issued in the
current job, a commitment boundary is established by the first OPEN of any file
under commitment control in the job. Changes are made to all files under commit-
ment control in the job, not just to files under commitment control in the COBOL
program that issues the COMMIT statement.
When a COMMIT is executed, all record locks held by the job since the last com-
mitment boundary for files under commitment control are released and the records
become available to other jobs.
The COMMIT statement only affects files under commitment control. If a COMMIT
is executed and there are no files opened under commitment control, the COMMIT
statement has no effect and no commitment boundary is established.
The COMMIT statement does not:
Modify the I-O-FEEDBACK area for any file
Change the file position indicator for any file
Set a file status value for any file.
For more information on commitment control, see the COBOL/400 Users Guide.
End of IBM Extension
Chapter 8. Procedure Division Statements 241
COMPUTE Statement
COMPUTE Statement
The COMPUTE statement assigns the value of an arithmetic expression to one or
more data items.
With the COMPUTE statement, arithmetic operations can be combined without the
restrictions on receiving data items imposed by the rules for the ADD, SUBTRACT,
MULTIPLY, and DIVIDE statements.
When arithmetic operations are combined, the COMPUTE statement may be more
efficient than the separate arithmetic statements written in series.
COMPUTE identifier1 = arithmeticexpression
ROUNDED
ENDCOMPUTE
Figure 127. Format
identifier-1
Must name either elementary numeric item(s) or elementary numeric-edited
item(s).
arithmetic-expression
May be any arithmetic expression, as defined in Arithmetic Expressions on
page 164.
When the COMPUTE statement is executed, the value of the arithmetic
expression is calculated, and this value is stored as the new value of each data
item referenced by identifier-1.
An arithmetic expression consisting of a single identifier or literal allows the
user to set the value of the data item(s) referenced by identifier-1 equal to the
value of that identifier or literal.
ROUNDED Phrase
For a discussion of the ROUNDED phrase, see ROUNDED Phrase on page 187.
242 COBOL/400 Reference
COMPUTE Statement
SIZE ERROR Phrases
For a discussion of the SIZE ERROR phrases, see SIZE ERROR Phrases on
page 188.
END-COMPUTE Phrase
This explicit scope terminator serves to delimit the scope of the COMPUTE state-
ment. END-COMPUTE permits a conditional COMPUTE statement to be nested in
another conditional statement. END-COMPUTE may also be used with an imper-
ative COMPUTE statement.
For more information, see Delimited Scope Statements on page 184.
Chapter 8. Procedure Division Statements 243
CONTINUE Statement
CONTINUE Statement
The CONTINUE statement allows you to specify a no operation statement. CON-
TINUE indicates that no executable instruction is present.
CONTINUE
Figure 128. Format
The CONTINUE statement may be used anywhere a conditional statement or an
imperative statement may be used. It has no effect on the execution of the
program.
244 COBOL/400 Reference
DELETE Statement
DELETE Statement
The DELETE statement removes a record from an indexed or relative file. For
indexed files, the key may then be reused for record addition. For relative files, the
space is then available for a new record with the same RELATIVE KEY value.
When the DELETE statement is executed, the associated file must be open in I-O
mode.
DELETEfile-name
RECORD
FORMATidentifier-1
IS literal-1
INVALIDimperative-statement-1
KEY
SIZE ERRORimperative-statement-1
ON
NOTSIZE ERRORimperative-statement-2
ON
END-DIVIDE
Figure 133. Format 1
In Format 1, the value of identifier-1 or literal-1 is divided into the value of
| identifier-2; the quotient is then placed in identifier-2. The initial sum is also added
| to each successive occurrence of identifier-2.
Chapter 8. Procedure Division Statements 259
DIVIDE Statement
DIVIDEidentifier-1INTOidentifier-2
literal-1 literal-2
GIVING identifier-3
ROUNDED
SIZE ERRORimperative-statement-1
ON
NOTSIZE ERRORimperative-statement-2
ON
END-DIVIDE
Figure 134. Format 2
DIVIDEidentifier-1BYidentifier-2
literal-1 literal-2
GIVING identifier-3
ROUNDED
SIZE ERRORimperative-statement-1
ON
NOTSIZE ERRORimperative-statement-2
ON
END-DIVIDE
Figure 135. Format 3
In Formats 2 and 3, the value of identifier-1 or literal-1 is divided into (Format 2) or
by (Format 3) the value of identifier-2 or literal-2. The value of the quotient is
stored in each data item referenced by identifier-3.
260 COBOL/400 Reference
DIVIDE Statement
DIVIDEidentifier-1INTOidentifier-2
literal-1 literal-2
GIVING identifier-3
ROUNDED
REMAINDER identifier-4
SIZE ERRORimperative-statement-1
ON
NOTSIZE ERRORimperative-statement-2
ON
END-DIVIDE
Figure 136. Format 4
DIVIDEidentifier-1BYidentifier-2
literal-1 literal-2
GIVING identifier-3
ROUNDED
REMAINDER identifier-4
SIZE ERRORimperative-statement-1
ON
NOTSIZE ERRORimperative-statement-2
ON
END-DIVIDE
Figure 137. Format 5
In Formats 4 and 5, the value of identifier-1 or literal-1 is divided into (Format 4) or
by (Format 5) identifier-2 or literal-2. The value of the quotient is stored in
identifier-3, and the value of the remainder is stored in identifier-4.
Chapter 8. Procedure Division Statements 261
DIVIDE Statement
DIVIDE INTO Example: When IDENT-1 equals 2, QUOTIENT equals 5 after the
processing of the following statement:
DIVIDE IDENT-1 INTO 1 GIVING QUOTIENT.
DIVIDE BY Example: When IDENT-1 equals 60, QUOTIENT equals 4 after the
processing of the following statement:
DIVIDE IDENT-1 BY 15 GIVING QUOTIENT.
For all Formats:
identifier-1, identifier-2
Must name an elementary numeric item.
identifier-3, identifier-4
Must name an elementary numeric or numeric-edited item.
literal
Must be a numeric literal.
ROUNDED Phrase
For Formats 1, 2, and 3, see ROUNDED Phrase on page 187.
For Formats 4 and 5, the quotient used to calculate the remainder is in an interme-
diate field. The value of the intermediate field is truncated rather than rounded.
REMAINDER Phrase
The result of subtracting the product of the quotient and the divisor from the divi-
dend is stored in identifier-4. If identifier-3, the quotient, is a numeric-edited item,
the quotient used to calculate the remainder is an intermediate field that contains
the unedited quotient.
Any subscripts for identifier-4 in the REMAINDER phrase are evaluated after the
result of the divide operation is stored in identifier-3 of the GIVING phrase.
SIZE ERROR Phrases
For Formats 1, 2, and 3, see SIZE ERROR Phrases on page 188.
For Formats 4 and 5, if the size error occurs in the quotient, no remainder calcu-
lation is meaningful. Therefore, the contents of the quotient field (identifier-3) and
the remainder field (identifier-4) are unchanged.
If size error occurs in the remainder, the contents of the remainder field
(identifier-4) are unchanged.
In either of these cases, you must analyze the results to determine which situation
has actually occurred.
For information on the NOT ON SIZE ERROR phrase, see page 189.
262 COBOL/400 Reference
DIVIDE Statement
END-DIVIDE Phrase
This explicit scope terminator serves to delimit the scope of the DIVIDE statement.
END-DIVIDE permits a conditional DIVIDE statement to be nested in another condi-
tional statement. END-DIVIDE may also be used with an imperative DIVIDE state-
ment.
For more information, see Delimited Scope Statements on page 184.
Chapter 8. Procedure Division Statements 263
DROP Statement
IBM Extension
DROP Statement
The DROP statement releases a program device that has been acquired by a
TRANSACTION file.
DROPidentifierFROMfile-name
literal
Figure 138. DROP Statement
literal
identifier
Literal or the contents of identifier indicates the program device name of the
device to be dropped. Literal, if specified, must be nonnumeric and 10 charac-
ters or less in length. Identifier, if specified, must refer to an alphanumeric data
item, 10 characters or less in length.
file-name
File-name must refer to a file with an organization of TRANSACTION, and the
file must be open in order to be used in the DROP statement. If no DROP
statement is issued, program devices attached to a TRANSACTION file are
implicitly released when that file is finally closed.
Program devices specified in a DROP statement must have been acquired by the
TRANSACTION file, either through an explicit ACQUIRE or through an implicit
ACQUIRE at OPEN time.
After successful execution of the DROP statement, the program device is no longer
available for input or output operations through the TRANSACTION file. The
device may be reacquired if necessary. The contents of the record area associated
with a released program device are no longer available, even if the device is reac-
quired.
If the DROP statement is unsuccessful, any applicable USE AFTER
EXCEPTION/ERROR procedures are executed.
The DROP statement can also be used as an aid in recovering from I-O errors.
For more information, see the Transaction File Recovery procedures in the
COBOL/400 Users Guide.
End of IBM Extension
264 COBOL/400 Reference
ENTER Statement
ENTER Statement
The ENTER statement allows the use of more than one source language in the
same source program.
Note: The ENTER statement is an obsolete statement and is to be deleted from
the next revision of the ANSI Standard. It is syntax-checked during compilation but
has no effect on the execution of the program.
Note: The COBOL/400 compiler does not allow another programming language to
be used in the source programs.
ENTERlanguage-name
routine-name .
Figure 139. Format
language-name
A system name that has no defined meaning. It must follow the rules for for-
mation of a user-defined word. At least one character must be alphabetic.
routine-name
Must follow the rules for formation of a user-defined word. At least one char-
acter must be alphabetic.
Chapter 8. Procedure Division Statements 265
EVALUATE Statement
EVALUATE Statement
The EVALUATE statement provides a shorthand notation for a series of nested IF
statements. It can evaluate multiple conditions. That is, the IF statements can be
made up of compound conditions. The subsequent action of the object program
depends on the results of these evaluations.
EVALUATEidentifier1
literal1
expression1
TRUE ALSOidentifier2
FALSE literal2
expression2
TRUE
FALSE
WHEN phrase1imperativestatement1
ALSO phrase2
SEQUENCEalphabet-name
COLLATING IS
USING file-name-2 file-name-3
OUTPUT PROCEDUREproc-name-1
IS THROUGHproc-name-2
THRU
GIVING file-name-4
Figure 154. Format
file-name-1
The name given in the SD entry that describes the record.
No file-name may be repeated in the MERGE statement.
When the MERGE statement is executed, all records contained in file-name-2,
file-name-3, . . . are accepted by the merge program and then merged according
to the key(s) specified.
Null-capable fields are supported, but null values are not. Null values result in a file
status of 90.
290 COBOL/400 Reference
MERGE Statement
ASCENDING/DESCENDING KEY Phrase
This phrase specifies that records are to be processed in an ascending or
descending sequence (depending on the phrase specified), based on the specified
merge keys.
KEY
KEY data items are listed in order of decreasing significance, no matter how
they are divided into KEY phrases. Using the format above as an example:
data-name-1
Is a key data-name. Records are processed in ascending or descending
order on this key.
Data-name-1 specifies a KEY data item on which the merge will be based. Each
such data-name must identify a data item in a record associated with file-name-1.
The data-names following the word KEY are listed from left to right in the MERGE
statement in order of decreasing significance without regard to how they are divided
into KEY phrases. The left-most data-name is the major key, the next data-name is
the next most significant key, and so forth.
The following rules apply:
A specific KEY data item must be physically located in the same position and
have the same data format in each input file; however, it need not have the
same data-name.
If file-name-1 has more than one record description, the KEY data items need
be described in only one of the record descriptions.
KEY data items must be fixed-length items.
KEY data items must not contain an OCCURS clause or be subordinate to an
item that contains an OCCURS clause.
KEY data items can be qualified or reference modified; they cannot be sub-
scripted or indexed.
The total length (in bytes) of the KEY data items must not exceed 256.
The direction of the merge operation depends on the specification of the
ASCENDING or DESCENDING key words as follows:
When ASCENDING is specified, the sequence is from the lowest key value to
the highest key value.
When DESCENDING is specified, the sequence is from the highest key value
to the lowest.
If the KEY data item is alphabetic, alphanumeric, alphanumeric-edited, or
numeric-edited, the sequence of key values depends on the collating sequence
used (see COLLATING SEQUENCE Phrase on page 292 below).
The key comparisons are performed according to the rules for comparison of oper-
ands in a relation condition (see Relation Condition on page 169).
Chapter 8. Procedure Division Statements 291
MERGE Statement
COLLATING SEQUENCE Phrase
This phrase specifies the collating sequence to be used in nonnumeric comparisons
for the KEY data items in this merge operation.
alphabet-name
Must be specified in the SPECIAL-NAMES paragraph alphabet-name clause.
Any one of the alphabet-name clause phrases can be specified with the fol-
lowing results:
When NATIVE is specified, the EBCDIC collating sequence is used for all
nonnumeric comparisons.
When the literal phrase is specified, the collating sequence established by
the specification of literals in the alphabet-name clause is used for all non-
numeric comparisons.
When STANDARD-1 is specified, the ASCII collating sequence is used for
all nonnumeric comparisons.
When STANDARD-2 is specified, the International Reference Version of the
ISO 7-bit code defined in International Standard 646, 7-bit Coded Character
Set for Information Processing Interchange is used.
When the COLLATING SEQUENCE phrase is omitted, the PROGRAM COL-
LATING SEQUENCE clause (if specified) in the OBJECT-COMPUTER paragraph
specifies the collating sequence to be used.
When both the COLLATING SEQUENCE phrase and the PROGRAM COLLATING
SEQUENCE clause are omitted, the EBCDIC collating sequence is used.
USING Phrase
When the USING phrase is specified, all the records on file-name-2, file-name-3,...
(that is, the input files) are transferred automatically to file-name-1. At the time the
MERGE statement is executed, these files must not be open; the compiler gener-
ates code that opens, reads and closes the input files automatically. If
EXCEPTION/ERROR procedures are specified for these files, the COBOL compiler
makes the necessary linkage to these procedures.
All input files must be described in an FD entry in the Data Division, and their
record descriptions must describe records of the same size as the record described
for the merge file. If the elementary items that make up these records are not
identical, input records must have an equal number of character positions as the
merge record.
The input files must have sequential, relative or indexed organization.
GIVING Phrase
When the GIVING phrase is specified, all the merged records in file-name-1 are
automatically transferred to the output file (file-name-4). At the start of execution of
the MERGE statement, the file referenced by file-name-4 must not be open. For
each of the files referenced by file-name-4, the execution of the MERGE statement
causes the following actions to be taken:
The processing of the file is initiated. The initiation is performed as if an OPEN
statement with the OUTPUT phrase had been executed.
292 COBOL/400 Reference
MERGE Statement
The merged logical records are returned and written onto the file. Each record
is written as if a WRITE statement without any optional phrases had been exe-
cuted. The records overwrite the previous contents, if any, of the file.
IBM Extension
If file-name-1 is a logical database file, the records are added to the end of the
file.
End of IBM Extension
If the file referenced by file-name-4 is an INDEXED file then the associated key
data-name for that file must have an ASCENDING KEY phrase in the merge
statement. This same data-name must occupy the identical character positions
in its record as the data item associated with the prime record key for the file.
For a relative file, the relative key data item for the first record returned con-
tains the value '1'; for the second record returned, the value '2', and so on.
After execution of the MERGE statement, the content of the relative key data
item indicates the last record returned to the file.
The processing of the file is terminated. The termination is performed as if a
CLOSE statement without optional phrases had been executed.
Note: When duplicate keys are found when writing to an indexed file, the MERGE
will terminate and the merged data in all GIVING files will be incomplete.
These implicit functions are performed such that any associated USE AFTER
EXCEPTION/ERROR procedures are executed; however, the execution of such a
USE procedure must not cause the execution of any statement manipulating the file
referenced by, or accessing the record area associated with, file-name-4. On the
first attempt to write beyond the externally defined boundaries of the file, any USE
AFTER STANDARD EXCEPTION/ERROR procedure specified for the file is exe-
cuted. If control is returned from that USE procedure or if no such USE procedure
is specified, the processing of the file is terminated.
The output file must be described in an FD entry in the Data Division, and its
record description(s) must describe records of the same size as the record
described for the merge file. If the elementary items that make up these records
are not identical, the output record must have an equal number of character posi-
tions as the merge record.
The output file must have a sequential, relative or indexed organization.
The output file should also be created without a keyed sequence access path.
When the output file has such a path, the MERGE statement cannot override the
collating sequence defined in the data description specifications (DDS).
Chapter 8. Procedure Division Statements 293
MERGE Statement
OUTPUT PROCEDURE Phrase
This phrase specifies the procedure-name(s) of a procedure that is to select or
modify output records from the merge operation.
proc-name-1
Specifies the first (or only) section in the OUTPUT PROCEDURE.
proc-name-2
Identifies the last section of the OUTPUT PROCEDURE.
Procedural statements within the OUTPUT PROCEDURE are restricted as follows:
The OUTPUT PROCEDURE must not contain any SORT or MERGE state-
ments.
The OUTPUT PROCEDURE must consist of one or more sections that are written
consecutively and do not form a part of any INPUT PROCEDURE. The OUTPUT
PROCEDURE must include at least one RETURN statement in order to make
merged records available for processing.
When an OUTPUT PROCEDURE is specified, control passes to it after the merge
file (file-name-1) has been placed in sequence. The compiler inserts a return
mechanism at the end of the last section in the OUTPUT PROCEDURE; when
control passes the last statement in the OUTPUT PROCEDURE, the return mech-
anism terminates the merge, and passes control to the next executable statement
after the MERGE statement. The RETURN statement in the OUTPUT PROCE-
DURE is a request for the next record (see RETURN Statement on page 348).
Note: The OUTPUT PROCEDURE phrase is similar to a basic PERFORM state-
ment. For example, if you name a procedure in an OUTPUT PROCEDURE
phrase, that procedure is executed during the merging operation just as if it were
named in a PERFORM statement. As with the PERFORM statement, execution of
the procedure ends after the last statement executes. The last statement in an
output procedure can be the EXIT statement (see EXIT Statement on page 272).
294 COBOL/400 Reference
MOVE Statement
MOVE Statement
The MOVE statement transfers data from one area of storage to one or more other
areas.
MOVEidentifier1TO identifier2
literal1
Figure 155. Format 1
MOVECORRESPONDINGidentifier1 TO identifier2
CORR
Figure 156. Format 2
identifier-1, literal-1
Sending item
identifier-2
Receiving item or items
When Format 1 is specified, all identifiers may be either group or elementary items.
The data in the sending item is moved into the data item referenced by each
identifier-2 in the order in which it is specified. See Elementary Moves on
page 297 and Group Moves on page 299.
When Format 2 is specified, both identifiers must be group items. CORR is an
abbreviation for, and is equivalent to, CORRESPONDING.
When CORRESPONDING is specified, selected items in identifier-1 are moved to
identifier-2, according to the rules for the CORRESPONDING phrase on page 186.
The results are the same as if each pair of CORRESPONDING identifiers were
referenced in a separate MOVE statement.
An index data item cannot be specified in a MOVE statement.
IBM Extension
You cannot specify a pointer data item in a MOVE statement. To move an address
into a pointer data item, use the SET statement.
A pointer data item can be part of a group that is referred to in a MOVE statement.
A pointer move occurs when:
The sending or receiving item of a MOVE statement contains a pointer,
Both items are at least 16 bytes long and properly aligned, and,
Both are alphanumeric or group items.
Chapter 8. Procedure Division Statements 295
MOVE Statement
If the items being moved are 01-level items, or part of a 01-level structure, they
must be at the same offset relative to a 16-byte boundary. All 01-level items in
Working-storage are aligned on 16-byte boundaries.
For more information about pointer alignment, see Pointer Alignment on
page 154.
A pointer data item can be part of a group that is referred to in a MOVE CORRE-
SPONDING statement; however, movement of the pointer data item will not take
place.
End of IBM Extension
The evaluation of the length of the sending or receiving item may be affected by
the DEPENDING ON phrase of the OCCURS clause (see OCCURS Clause on
page 115).
Any length evaluation, subscripting, or reference modification associated with the
sending item is evaluated only once, immediately before the data is moved to the
first of the receiving items. Any length evaluation, subscripting, or reference modifi-
cation associated with a receiving item is evaluated immediately before the data is
moved into it.
For example, the result of the statement:
MOVE A(B) TO B, C(B).
is equivalent to:
MOVE A(B) TO TEMP.
MOVE TEMP TO B.
MOVE TEMP TO C(B).
where TEMP is defined as an intermediate result item. The subscript B has
changed in value between the time that the first move took place and the time that
the final move to C(B) is executed.
After execution of a MOVE statement, the sending item contains the same data as
before execution (unless a receiving item overlaps the sending item, in which case
the contents are not predictable).
Unexpected results can occur when a redefining item is moved to the redefined
item (that is, if B REDEFINES C and the statement MOVE B TO C is executed).
Unexpected results can also occur when a redefined item is moved to an item
redefining it (from the previous example, unexpected results occur if the statement
MOVE C TO B is executed).
296 COBOL/400 Reference
MOVE Statement
Elementary Moves
An elementary move is one in which the receiving item is an elementary item, and
the sending item is an elementary item or a literal. Any necessary conversion of
data from one form of internal representation to another takes place during the
move, along with any specified editing in, or de-editing implied by, the receiving
item.
De-editing is the logical removal of all editing characters from a numeric-edited
data item in order to determine that item's unedited numeric value.
Each elementary item belongs to one of the following categories:
Alphabeticincludes alphabetic data items and the figurative constant
SPACE.
Alphanumericincludes alphanumeric data items, nonnumeric literals, and all
figurative constants except SPACE. (The figurative constant ZERO is alphanu-
meric only when it is moved to an alphanumeric or alphanumeric-edited item.)
Alphanumeric-editedincludes alphanumeric-edited data items.
Numericincludes numeric data items, numeric literals, and the figurative con-
stant ZERO. (The figurative constant ZERO is numeric only when it is moved
to a numeric or numeric-edited item.)
Numeric-editedincludes numeric-edited data items.
IBM Extension
Booleanincludes Boolean data items and Boolean literals.
End of IBM Extension
The following rules outline the execution of valid elementary moves. When the
receiving item is:
Alphabetic:
Alignment and any necessary space filling occur as described under Alignment
Rules on page 88.
If the size of the sending item is greater than the size of the receiving item,
excess characters on the right are truncated after the receiving item is filled.
Alphanumeric or Alphanumeric-edited:
Alignment and any necessary space filling take place, as described under
Alignment Rules on page 88.
If the size of the sending item is greater than the size of the receiving item,
excess characters on the right are truncated after the receiving item is filled.
If the sending item has an operational sign, the absolute value is used. If the
operational sign occupies a separate character, that character is not moved,
and the size of the sending item is considered to be one less character than
the actual size.
Chapter 8. Procedure Division Statements 297
MOVE Statement
IBM Extension
If the sending item is Boolean, the data is moved as if the sending item were
described as an alphanumeric item of length 1.
End of IBM Extension
Numeric or Numeric-edited:
Except where zeros are replaced because of editing requirements, alignment
by decimal point and any necessary zero filling take place, as described under
Alignment Rules on page 88.
If the receiving item is signed, the sign of the sending item is placed in the
receiving item, with any necessary sign conversion. If the sending item is
unsigned, a positive operational sign is generated for the receiving item.
If the receiving item is unsigned, the absolute value of the sending item is
moved, and no operational sign is generated for the receiving item.
When the sending item is alphanumeric, the data is moved as if the sending
item were described as an unsigned integer.
De-editing allows the moving of a numeric-edited data item into a numeric or
numeric-edited receiver. The compiler accomplishes this by first establishing
the unedited value of the numeric-edited item (this value can be signed), then
moving the unedited numeric value to the receiving numeric or numeric-edited
data item.
For more information, see the COBOL/400 Users Guide.
IBM Extension
Boolean:
For a Boolean receiving item, only the first byte of the sending item is moved.
If the sending item is alphanumeric, the first character of the sending item is
moved. The characters "0" and "1" are equivalent to the Boolean values B"0"
and B"1", respectively.
If the sending item is zero, it is treated as the Boolean literal B"0".
End of IBM Extension
Notes:
1. If the receiving item is alphanumeric or numeric-edited, and the sending item is
a scaled integer (that is, has a P as the rightmost character in its PICTURE
character-string), the scaling positions are treated as trailing zeros when the
MOVE statement is executed.
2. If the receiving item is numeric and the sending item is alphanumeric literal or
ALL literal, then all characters of the literal must be numeric characters.
298 COBOL/400 Reference
MOVE Statement
Table 35 shows valid and invalid elementary moves for each category. In the
figure:
YES = Move is valid.
NO = Move is invalid.
Table 35. Valid and Invalid Elementary Moves
Sending Item
Category
Receiving Item Category
Alpha-
betic
Alphanu-
meric
Alpha-
numeric-
edited
Numeric
Integer
Numeric
Nonin-
teger
Numeric-
edited BOOLEAN
Alphabetic and
SPACE
YES YES YES NO NO NO NO
Alphanumeric YES YES YES YES^ YES^ YES^ YES
Nonnumeric
Literal
YES YES YES YES YES YES YES
Alphanumeric-
edited
YES YES YES NO NO NO NO
Numeric Integer NO YES YES YES YES YES NO
Numeric
Noninteger
NO NO NO YES YES YES NO
Numeric-edited NO YES YES YES YES YES NO
LOW/HIGH-
VALUE
QUOTES
NO YES YES NO NO NO NO
ZERO NO YES YES YES YES YES YES
BOOLEAN NO YES YES NO NO NO YES
Notes to Table 35:
Nonnumeric literal must consist only of numeric characters
Includes numeric literals
Includes Boolean literals
^ Move proceeds as if sending item were an unsigned integer
First character of sending item is moved, regardless of its value
Boolean items are an IBM Extension.
Group Moves
A group move is one in which one or both of the sending and receiving items are
group items. A group move is treated exactly as though it were an alphanumeric
elementary move, except that there is no conversion of data from one form of
internal representation to another. In a group move, the receiving item is filled
without consideration for the individual elementary items contained within either the
sending item or the receiving item. All group moves are valid.
| Neither editing nor de-editing occurs for group moves.
Chapter 8. Procedure Division Statements 299
MOVE Statement
IBM Extension
WHEN-COMPILED Special Register
WHEN-COMPILED is a 16-character alphanumeric data item with the format:
MM/DD/YYhh.mm.ss (MONTH/DAY/YEARhour.minute.second)
WHEN-COMPILED makes available to the object program the date-and-time-
compiled constant carried in the object module at the start of compilation; it is valid
only as the sending item in a MOVE statement. You can move WHEN-COMPILED
special register data to an alphanumeric-edited item.
For example, if compilation began at 2:04 PM on 15 May 1986, WHEN-COMPILED
would contain the value 05/15/8614.04.00.
The TIMSEP parameter of job-related commands (such as CHGJOB) specifies the
time-separation character used in the WHEN-COMPILED special register.
End of IBM Extension
300 COBOL/400 Reference
MULTIPLY Statement
MULTIPLY Statement
The MULTIPLY statement multiplies numeric items and sets the values of data
items equal to the results.
MULTIPLYidentifier1BY identifier-2
literal-1 ROUNDED
ENDMULTIPLY
Figure 157. Format 1
In Format 1, the value of identifier-1 or literal-1 is multiplied by the value of
identifier-2; the product is then placed in identifier-2. This process is then repeated
for each successive occurrence of identifier-2, in the left-to-right order in which
identifier-2 is specified.
MULTIPLYidentifier-1BYidentifier2
literal-1 literal-2
GIVING identifier-3
ROUNDED
END-MULTIPLY
Figure 158. Format 2
In Format 2, the value of identifier-1 or literal-1 is multiplied by the value of
identifier-2 or literal-2. The product is then stored in the data item(s) referenced by
identifier-3.
Chapter 8. Procedure Division Statements 301
MULTIPLY Statement
For all Formats:
identifier-1, identifier-2
Must name an elementary numeric item.
literal
Must be a numeric literal.
For Format-2:
identifier-3
Must name an elementary numeric or numeric-edited item.
The composite of operands must not contain more than 18 digits.
IBM Extension
The composite of all operands in an arithmetic statement can have a maximum
length of 30 digits.
End of IBM Extension
ROUNDED Phrase
For Formats 1 and 2, see ROUNDED Phrase on page 187.
SIZE ERROR Phrases
For Formats 1 and 2, see SIZE ERROR Phrases on page 188.
END-MULTIPLY Phrase
This explicit scope terminator serves to delimit the scope of the MULTIPLY state-
ment. END-MULTIPLY permits a conditional MULTIPLY statement to be nested in
another conditional statement. END-MULTIPLY may also be used with an imper-
ative MULTIPLY statement.
For more information, see Delimited Scope Statements on page 184.
302 COBOL/400 Reference
OPEN Statement
OPEN Statement
The OPEN statement initiates the processing of files. It also checks and/or writes
labels.
The OPEN statement varies depending on the type of file:
Sequential files
Indexed files
Relative files
Transaction files.
Sequential Files
OPENINPUTfilename1
REVERSED
NO REWIND
WITH
OUTPUTfilename2
NO REWIND
WITH
I-Ofilename3
EXTENDfilename4
Figure 159. Format 1Sequential
At least one of the phrases, INPUT, OUTPUT, I-O, or EXTEND, must be specified
with the OPEN keyword. The INPUT, OUTPUT, I-O, and EXTEND phrases may
appear in any order.
Chapter 8. Procedure Division Statements 303
OPEN Statement
file-name
Designates a file upon which the OPEN statement is to operate. If more than
one file is specified, the files need not have the same organization or access.
Each file-name must be defined in an FD entry in the Data Division, and must
not name a sort or merge file. The FD entry must be equivalent to the informa-
tion supplied when the file was defined.
See Table 36 on page 305 for an illustration of sequential organization, access
and device considerations for the OPEN statement.
Indexed and Relative Files
OPENINPUTfile-name-1
OUTPUTfile-name-2
I-Ofile-name-3
Figure 160. Format 2Indexed and Relative
At least one of the phrases, INPUT, OUTPUT, or I-O, must be specified with the
OPEN keyword. The INPUT, OUTPUT, and I-O phrases may appear in any order.
file-name
Designates a file upon which the OPEN statement is to operate. If more than
one file is specified, the files need not have the same organization or access.
Each file-name must be defined in an FD entry in the Data Division, and must
not name a sort or merge file. The FD entry must be equivalent to the informa-
tion supplied when the file was defined.
See Table 37 on page 305 and Table 38 on page 306 for an illustration of relative
and indexed organization, access and device considerations for the OPEN state-
ment.
304 COBOL/400 Reference
OPEN Statement
Transaction Files
OPEN I-Ofile-name
Figure 161. Format 3TRANSACTION
A TRANSACTION file must be opened in the I-O mode.
The OPEN statement can cause a program device to be implicitly acquired for a
TRANSACTION file. For a further discussion about the acquiring of program
devices, see the ACQUIRE Statement on page 219.
OPEN Statement Considerations
Table 36. Sequential Organization
ACCESS SEQUENTIAL
DEVICE PRINTER TAPEFILE DISKETTE DISK DATABASE FORMATFILE
OPEN Verb S L,S S S S,C,X S
INPUT O,A,F,L1,N1,V O,A,F,N1,V O,A,K,F,N1 O,A,K,F,N1 O,A,K,F
OUTPUT R,J,U O,J,L2,N1,U O,J,N1,U O,G,N1,U O,G,N1 O,G
IO O,M,K,T O,M,K O,M,K
NO REWIND O,D
REVERSED O,B
EXTEND O,E,L3,T,W O,W O,E,T O,E
Table 37. Relative Organization
Device DISK DATABASE
Access SEQUENTIAL RANDOM DYNAMIC SEQUENTIAL RANDOM DYNAMIC
OPEN Verb H,S H,S H,S H,S,C,X H,S,C,X H,S,C,X
INPUT O,A,K,N1 O,A O,A,K,N2 O,A,K,N1 O,A O,A,K,N2
OUTPUT O,G,U O,G,U O,G,U O,G O,G O,G
IO O,M,K O,M O,M,K O,M,K O,M O,M,K
NO REWIND
REVERSED
EXTEND
Chapter 8. Procedure Division Statements 305
OPEN Statement
Table 38. Indexed Organization
Device DISK DATABASE
Access SEQUENTIAL RANDOM DYNAMIC SEQUENTIAL RANDOM DYNAMIC
OPEN Verb S S S S,C,X S,C,X S,C,X
INPUT O,A,K,N1 O,A O,A,K,N2 O,A,K,N1 O,A O,A,K,N2
OUTPUT O,G,N1,U O,G,U O,G,U,N2 O,G,N1 O,G O,G,N2
IO O,M,K O,M O,M,K O,M,K O,M O,M,K
NO REWIND
REVERSED
EXTEND
Letter
Code Meaning
Combination is not valid.
A The file is opened for input operations. The file position indicator is set to
the first record in the file. If no records exist in the file, the file position
indicator is set so that processing of the first sequential READ statement
results in an AT END condition.
B OPEN statement processing positions the file at its end. Subsequent
READ statements make the data records available in reverse order,
starting with the last record. REVERSED can only be specified for input
files.
The REVERSED phrase is an obsolete element and is to be deleted from
the next revision of the ANSI Standard.
If the concept of reels has no meaning for the storage medium (for
example, a direct access device), the REVERSED and NO REWIND
phrases do not apply. When the phrases are used in this situation, a file
status of 07 is set for NO REWIND, and a file status of 00 is set for
REVERSED.
IBM Extension
C The file may be placed under commitment control.
See "Commitment Control" in the COBOL/400 Users Guide for more
information.
End of IBM Extension
D The OPEN statement does not reposition the file. The tape must be posi-
tioned at the beginning of the desired file before processing of the OPEN
statement.
If the concept of reels has no meaning for the storage medium (for
example, a direct access device), the REVERSED and NO REWIND
phrases do not apply. When the phrases are used in this situation, a file
status of 07 is set.
306 COBOL/400 Reference
OPEN Statement
IBM Extension
The system keeps track of the current position on the tape and automat-
ically positions the tape to the proper place. When processing a multifile
tape volume, all CLOSE statements should specify the NO REWIND
phrase. When the next file on the volume is opened, the system deter-
mines which direction the tape should be moved to most efficiently get to
the desired file.
End of IBM Extension
E The EXTEND phrase permits opening the file for output operations. OPEN
EXTEND statement processing prepares the file for the addition of
records. These additional records immediately follow the last record in the
file. Subsequent WRITE statements add records as if the file had been
opened for OUTPUT. The EXTEND phrase can be specified when a file is
being created.
The EXTEND phrase is not allowed for files for which the LINAGE clause
has been specified.
F If SELECT OPTIONAL is specified in the file-control entry, OPEN state-
ment processing causes the program to check for the presence or
absence of this file at run time. If the file is absent, the first READ state-
ment for this file causes the AT END condition to occur.
IBM Extension
G Only a physical file is cleared when opened for OUTPUT. When the file is
successfully opened, it contains no records. If an attempt is made to open
a logical file for OUTPUT, the file is opened but no records are deleted.
The file is treated as though the EXTEND phrase had been specified. To
clear a logical file, all the members on which the logical file is based
should be cleared.
End of IBM Extension
H Not allowed for logical file members:
That are based on more than one physical file.
That contain select/omit logic.
J The file is opened to allow only output operations. When the file is suc-
cessfully opened, it contains no records.
IBM Extension
K The first record to be made available to the program can be specified at
run time by using the POSITION parameter on the OVRDBF CL
command. See the CL Reference for more information on this command.
End of IBM Extension
Chapter 8. Procedure Division Statements 307
OPEN Statement
L When label records are specified but not present, or when label records
are present but not specified, processing of the OPEN statement can have
unpredictable results.
L1 The beginning labels are checked.
L2 The labels are checked, then new labels are written.
L3 The following results occur:
Beginning file labels are processed only if this is a single-volume
file.
Beginning volume labels of the last existing volume are checked.
The file is positioned to the existing ending file labels. The labels
are checked and then deleted.
Processing continues as if the file were opened as an output file.
M The file is opened for both input and output operations. The file position
indicator is set to the first record in the file. If no records exist in the file,
the file position indicator is set so that processing of the first sequential
READ statement results in an AT END condition.
N1 Under GENOPT option *NOBLK, the compiler generates code to block
output records and unblock input records if the following conditions are
satisfied:
The file access is sequential.
The organization of the file is sequential or indexed, and the file is
open only for input or output; or the organization of the file is relative,
and the file is open only for input.
The file is assigned to DISK, DATABASE, DISKETTE, or TAPEFILE.
No START statements are specified for the file.
The BLOCK CONTAINS clause does not control the blocking factor for
any files except tape files.
START statements are allowed if you specify both GENOPT option *BLK
and the BLOCK CONTAINS clause.
N2 Also, under GENOPT option *BLK, the BLOCK CONTAINS clause causes
the compiler to generate code that blocks output records and unblocks
input records if the following conditions are satisfied:
The file access is dynamic.
The organization of the file is sequential or indexed, and the file is
open only for input or output; or the organization of the file is relative,
and the file is open only for input.
The file is assigned to DISK or DATABASE.
If the BLOCK CONTAINS clause specifies a record size of zero, the
system default blocking factor applies.
O You can specify this combination.
R You must specify this combination for the device shown.
308 COBOL/400 Reference
OPEN Statement
S The successful execution of an OPEN statement determines the avail-
ability of the file and results in that file being in an open mode. The file is
unavailable if the OPEN operation fails. A file is available if it is physically
present and is recognized by the input-output control system. Table 39 on
page 310 shows the results of opening available and unavailable files.
T If the OPTIONAL phrase is used in the SELECT clause for the file, and
GENOPT(*NOCRTF) is specified in the CRTCBLPGM command, a
compile-time error will occur. If the OPTIONAL phrase is used, and if
GENOPT(*CRTF) is specified in the CRTCBLPGM command, the file will
| be created by the OPEN operation if it is unavailable, and the authority for
| the file will be inherited from the job profile. Tape files must be overridden
to physical files for dynamic file creation. For dynamic file creation, specify
GENOPT(*CRTF) on the CRTCBLPGM command. If the OPTIONAL
phrase is not specified, file status 90 will be returned.
Note: The maximum record length for a file that can be created dynam-
ically is 32 766.
U If the file is unavailable, it will not be created by the OPEN operation if
GENOPT(*NOCRTF) is specified in the CRTCBLPGM command. For
dynamic file creation, specify GENOPT(*CRTF) in the CRTCBLPGM
command. (*NOCRTF is the default unless otherwise specified.) Device
files must be overridden to physical files for dynamic file creation.
Note: The maximum record length for a file that can be created dynam-
ically is 32 766.
V If SELECT OPTIONAL is specified in the file-control entry and
GENOPT(*CRTF) is specified in the CRTCBLPGM command, this combi-
nation is not valid.
W If SELECT OPTIONAL is specified in the file-control entry and
GENOPT(*CRTF) is specified in the CRTCBLPGM command, this combi-
nation is valid.
X If the file contains null-capable fields, a file status of 0P is set.
Chapter 8. Procedure Division Statements 309
OPEN Statement
OPEN Statement Notes
1. The successful execution of the OPEN statement makes the associated record
area available to the program; it does not obtain or release the first data record.
2. An OPEN statement must be successfully executed prior to the execution of
any of the permissible input-output statements, except a SORT or MERGE
statement with the USING or GIVING phrase.
The following table shows the permissible input-output statements for sequen-
tial files. An 'X' indicates that the specified statement may be used with the
open mode given at the top of the column.
Table 39. Availability of a File
File is Available File is Unavailable
INPUT Normal open Open is unsuccessful
INPUT (optional file) Normal open Normal open; the first read causes the
at end condition
I-O Normal open Open is unsuccessful
I-O (optional file) Normal open Open causes the file to be created
OUTPUT Normal open; the file
contains no records
Open causes the file to be created
EXTEND Normal open Open is unsuccessful
EXTEND (optional file) Normal open Open causes the file to be created
Note: If GENOPT(*CRTF) has been specified, and a library-name has not been pro-
| vided (by means of a file override), the file will be created in the library designated by
*CURLIB. If *CURLIB has not been defined, the file will be created in the library QTEMP.
For further information about library names, see the CRTCBLPGM CL command description
in the COBOL/400 Users Guide.
Table 40. Permissible Statements for Sequential Files
Statement
Open Mode
Input Output I-O Extend
READ X X
WRITE X X
REWRITE X
310 COBOL/400 Reference
OPEN Statement
The following table shows the permissible statements for indexed and relative
files. An 'X' indicates that the specified statement, used in the access mode
given for that row, may be used with the open mode given at the top of the
column.
3. A file may be opened for INPUT, OUTPUT, I-O, or EXTEND (sequential files
only) in the same program. After the first OPEN statement execution for a
given file, each subsequent OPEN statement execution must be preceded by a
successful CLOSE file statement execution without the REEL or UNIT phrase
(for sequential files only), or the LOCK phrase.
4. If the FILE STATUS clause is specified in the FILE-CONTROL entry, the asso-
ciated status key is updated when the OPEN statement is executed. For more
information about the status key, refer to Common Processing Facilities on
page 191.
5. If an OPEN statement is issued for a file already in the open status, the
EXCEPTION/ERROR procedure (if specified) for this file is executed and file
status 41 is returned.
Table 41. Permissible Statements for Indexed and Relative Files
File Access
Mode Statement
Open Mode
Input Output I-O Extend
Sequential READ X X
WRITE X
REWRITE X
START X X
DELETE X
Random READ X X
WRITE X X
REWRITE X
START
DELETE X
Dynamic READ X X
WRITE X X
REWRITE X
START X X
DELETE X
Chapter 8. Procedure Division Statements 311
PERFORM Statement
PERFORM Statement
The PERFORM statement transfers control explicitly to one or more procedures
and implicitly returns control to the next executable statement after execution of the
specified procedure(s) or imperative statements is completed.
The PERFORM statement can be:
An out-of-line PERFORM statement
Procedure-name-1 is specified.
An in-line PERFORM statement
Procedure-name-1 is omitted.
An in-line PERFORM must be delimited by the END-PERFORM phrase.
The in-line and out-of-line formats cannot be combined. For example, if
procedure-name-1 is specified, the imperative-statement and the
END-PERFORM phrase must not be specified.
There are four PERFORM statement formats:
Basic PERFORM
TIMES phrase PERFORM
UNTIL phrase PERFORM
VARYING phrase PERFORM.
Basic PERFORM Statement
The procedure(s) referenced in the basic PERFORM statement are executed once,
and control then passes to the next executable statement following the PERFORM
statement.
PERFORMprocedure-name-1
THROUGHprocedure-name-2
THRU
imperative-statementEND-PERFORM
Figure 162. Format 1
procedure-name
Must name a section or paragraph in the Procedure Division.
When both procedure-name-1 and procedure-name-2 are specified, if either is
a procedure-name in a declarative procedure, both must be procedure-names
in the same declarative procedure.
If procedure-name-1 is specified, imperative-statement and the END-PERFORM
phrase must not be specified.
If procedure-name-1 is omitted, imperative-statement and the END-PERFORM
phrase must be specified.
imperative-statement
The statement(s) to be executed for an in-line PERFORM.
312 COBOL/400 Reference
PERFORM Statement
END-PERFORM
Delimits the scope of the in-line PERFORM statement. Execution of an in-line
PERFORM is completed after the last statement contained within it has been
executed.
An in-line PERFORM statement functions according to the same general rules as
an otherwise identical out-of-line PERFORM statement, except that statements con-
tained within the in-line PERFORM are executed in place of the statements con-
tained within the range of procedure-name-1 (through procedure-name-2, if
specified). Unless specifically qualified by the word in-line or out-of-line, all the
rules that apply to the out-of-line PERFORM statement also apply to the in-line
PERFORM.
Whenever an out-of-line PERFORM statement is executed, control is transferred to
the first statement of the procedure named procedure-name-1. Control is always
returned to the statement following the PERFORM statement. The point from
which this control is returned is determined as follows:
If procedure-name-1 is a paragraph name and procedure-name-2 is not speci-
fied, the return is made after the execution of the last statement of the
procedure-name-1 paragraph.
If procedure-name-1 is a section name and procedure-name-2 is not specified,
the return is made after the execution of the last statement of the last para-
graph in the procedure-name-1 section.
If procedure-name-2 is specified and it is a paragraph name, the return is made
after the execution of the last statement of the procedure-name-2 paragraph.
If procedure-name-2 is specified and it is a section name, the return is made
after the execution of the last statement of the last paragraph in the
procedure-name-2 section.
The only necessary relationship between procedure-name-1 and procedure-name-2
is that a consecutive sequence of operations is executed, beginning at the proce-
dure named by procedure-name-1 and ending with the execution of the procedure
named by procedure-name-2.
PERFORM statements may be specified within the performed procedure. If there
are two or more logical paths to the return point, then procedure-name-2 may name
a paragraph that consists only of an EXIT statement; all the paths to the return
point must then lead to this paragraph.
When both procedure-name-1 and procedure-name-2 are specified, GO TO and
PERFORM statements can appear within the sequence of statements contained in
these paragraphs or sections. A GO TO statement should not refer to a procedure-
name outside the range of procedure-name-1 through procedure-name-2. If this is
done, results are unpredictable and are not diagnosed.
When only procedure-name-1 is specified, PERFORM and GO TO statements can
appear within the procedure. A GO TO statement should not refer to a procedure-
name outside the range of procedure-name-1. If this is done, results are unpredict-
able and are not diagnosed.
When the performed procedures include another PERFORM statement, the
sequence of procedures associated with the embedded PERFORM statement must
be totally included in or totally excluded from the performed procedures of the first
Chapter 8. Procedure Division Statements 313
PERFORM Statement
PERFORM statement. That is, an active PERFORM statement whose execution
point begins within the range of performed procedures of another active PERFORM
statement must not allow control to pass through the exit point of the other active
PERFORM statement. In addition, two or more such active PERFORM statements
must not have a common exit.
IBM Extension
Two or more active PERFORM statements can have a common exit point.
End of IBM Extension
Figure 163 illustrates valid sequences of execution for PERFORM statements.
x PERFORM a THRU m x PERFORM a THRU m
a a
d PERFORM f THRU j d PERFORM f THRU j
f h
j m
m f
j
x PERFORM a THRU m x PERFORM a THRU m
a a
f d PERFORM j THRU m
m f
j j
d PERFORM f thru j m EXIT.
Figure 163. Valid PERFORM Statement Execution Sequences
When control passes to the sequence of procedures by means other than a
PERFORM statement, control passes through the exit point to the next executable
statement, as if no PERFORM statement referred to these procedures.
314 COBOL/400 Reference
PERFORM Statement
PERFORM with TIMES Phrase
The procedure(s) referred to in the TIMES phrase PERFORM statement are exe-
cuted the number of times specified by the value in identifier-1 or integer-1.
Control then passes to the next executable statement following the PERFORM
statement.
PERFORMprocedure-name-1phrase-1
THROUGHprocedure-name-2
THRU
phrase-1imperative-statementEND-PERFORM
where phrase1 is:
identifier-1TIMES
integer-1
Figure 164. Format 2
identifier-1
Must name an integer item.
If identifier-1 is zero or a negative number at the time the PERFORM statement
is initiated, control passes to the statement following the PERFORM statement.
After the PERFORM statement has been initiated, any change to identifier-1
has no effect in varying the number of times the procedures are initiated.
PERFORM with UNTIL Phrase
In the UNTIL phrase format, the procedure(s) referred to are performed until the
condition specified by the UNTIL phrase is true. Control is then passed to the next
executable statement following the PERFORM statement.
PERFORMprocedure-name-1phrase-1
THROUGHprocedure-name-2
THRU
phrase-1imperative-statementEND-PERFORM
where phrase-1 is:
UNTILcondition-1
TESTBEFORE
WITH AFTER
Figure 165. Format 3
condition-1
May be any condition described under Conditional Expressions on page 166.
If the condition is true at the time the PERFORM statement is initiated, the
specified procedure(s) are not executed.
Any subscripting associated with the operands specified in condition-1 is evalu-
ated each time the condition is tested.
If the TEST BEFORE phrase is specified or assumed, the condition is tested before
any statements are executed (corresponds to DO WHILE).
Chapter 8. Procedure Division Statements 315
PERFORM Statement
If the TEST AFTER phrase is specified, the statements to be performed are exe-
cuted at least once before the condition is tested (corresponds to DO UNTIL).
In either case, if the condition is true, control is transferred to the next executable
statement following the end of the PERFORM statement. If neither the TEST
BEFORE nor the TEST AFTER phrase is specified, the TEST BEFORE phrase is
assumed.
PERFORM with VARYING Phrase
The VARYING phrase increases or decreases the value of one or more identifiers
or index-names, according to certain rules. (See Varying Phrase Rules on
page 324.)
The Format 4 VARYING phrase PERFORM statement can serially search an entire
7-dimensional table.
PERFORMprocedure-name-1phrase-1
THROUGHprocedure-name-2
THRU
phrase-1imperative-statementEND-PERFORM
where phrase-1 is:
VARYINGidentifier-2
TESTBEFORE index-name-1
WITH AFTER
FROMidentifier-3BYidentifier-4UNTIL condition-1
index-name-2 literal-2
literal-1
AFTERidentifier-5FROMidentifier-6BYidentifier-7UNTIL condition-2
index-name-3 index-name-4 literal-4
literal-3
Figure 166. Format 4
condition-1, condition-2
May be any condition described under Conditional Expressions on page 166.
If the condition is true at the time the PERFORM statement is initiated, the
specified procedure(s) are not executed.
After the condition(s) specified in the UNTIL phrase are satisfied, control is
passed to the next executable statement following the PERFORM statement.
Any subscripting associated with the operands specified in condition-1 or
condition-2 is evaluated each time the condition is tested.
When TEST BEFORE is indicated, all specified conditions are tested before the
first execution, and the statements to be performed are executed, if at all, only
when all specified tests fail. When TEST AFTER is indicated, the statements to be
performed are executed at least once, before any condition is tested. Any sub-
316 COBOL/400 Reference
PERFORM Statement
scripting associated with the operands specified in condition-1 is evaluated each
time the condition is tested.
If neither the TEST BEFORE nor the TEST AFTER phrase is specified, the TEST
BEFORE phrase is assumed.
Varying Identifiers
The way in which operands are increased or decreased depends on the number of
variables specified. In the following discussion, every reference to identifier-n refers
equally to index-name-n (except when identifier-n is the object of the BY phrase).
If identifier-2 or identifier-5 is subscripted, the subscripts are evaluated each time
the content of the data item referenced by the identifier is set or augmented. If
identifier-3, identifier-4, identifier-6, or identifier-7 is subscripted, the subscripts are
evaluated each time the content of the data item referenced by the identifier is used
in a setting or an augmenting operation.
Varying One Identifier
Example
PERFORM procedure-name-1 THROUGH procedure-name-2
VARYING identifier-2 FROM identifier-3
BY identifier-4 UNTIL condition-1
| 1. Identifier-2 is set equal to its starting value, which is identifier-3 (or literal-1).
2. Condition-1 is evaluated as follows:
a. If it is false, steps 3 through 5 are executed.
b. If it is true, control passes directly to the statement following the PERFORM
statement.
3. Procedure-1 and everything up to and including procedure-2 (if specified) are
executed once.
| 4. Identifier-2 is augmented by identifier-4 (or literal-2), and condition-1 is evalu-
ated again.
5. Steps 2 through 4 are repeated until condition-1 is true.
At the end of PERFORM statement execution identifier-2 has a value that exceeds
the last-used setting by the increment/decrement value (unless condition-1 was true
at the beginning of PERFORM statement execution, in which case, identifier-2 con-
tains the current value of identifier-3).
Chapter 8. Procedure Division Statements 317
PERFORM Statement
Figure 167 illustrates the logic of the PERFORM statement when an identifier is
varied with TEST BEFORE. Figure 168 illustrates the logic of the PERFORM
statement when an identifier is varied with TEST AFTER.
Entrance
Set identifier-2 equal to
current FROM value
Condition-1
Execute specified set
of statements
Augment identifier-2 with
current BY value
True
False
Exit
Figure 167. Varying One Identifierwith TEST BEFORE
Entrance
Set identifier-2 to
current FROM value
Execute specified set
of statements
Condition-1
Augment identifier-2
with current BY value
True
Exit
False
Figure 168. Varying One Identifierwith TEST AFTER
318 COBOL/400 Reference
PERFORM Statement
Varying Two Identifiers
Example
PERFORM procedure-name-1 THROUGH procedure-name-2
VARYING identifier-2 FROM identifier-3
BY identifier-4 UNTIL condition-1
AFTER identifier-5 FROM identifier-6
BY identifier-7 UNTIL condition-2
1. identifier-2 and identifier-5 are set to their initial values, identifier-3 and
identifier-6, respectively.
2. condition-1 is evaluated as follows:
a. If it is false, steps 3 through 7 are executed.
b. If it is true, control passes directly to the statement following the PERFORM
statement.
3. condition-2 is evaluated as follows:
a. If it is false, steps 4 through 6 are executed.
b. If it is true, identifier-2 is augmented by identifier-4, identifier-5 is set to the
current value of identifier-6, and step 2 is repeated.
4. procedure-name-1 and everything up to and including procedure-name-2 (if
specified) are executed once.
5. identifier-5 is augmented by identifier-7.
6. Steps 3 through 5 are repeated until condition-2 is true.
7. Steps 2 through 6 are repeated until condition-1 is true.
At the end of PERFORM statement execution:
identifier-5
Contains the current value of identifier-6.
identifier-2
Has a value that exceeds the last-used setting by the increment/decrement
value (unless condition-1 was true at the beginning of PERFORM statement
execution, in which case, identifier-2 contains the current value of identifier-3).
Chapter 8. Procedure Division Statements 319
PERFORM Statement
Figure 169 illustrates the logic of the PERFORM statement when two identifiers are
varied with TEST BEFORE. Figure 170 on page 321 illustrates the logic of the
PERFORM statement when two identifiers are varied with TEST AFTER.
Entrance
Set identifier-2 to
current FROM value
Set identifier-5 to
its current FROM value
Condition-1
Condition-2
Execute specified set
of statements
Augment identifier-5
with current BY value
Augment identifier-2
with current BY value
Set identifier-5 to
its current FROM value
False
False
Exit
True
True
Figure 169. Varying Two Identifierswith TEST BEFORE
| Note: Figure 169 assumes that identifier-2 and identifier-5 are not related. If one
| is dependent on the other (through subscripting, for example), the results may be
| predictable but generally undesirable.
320 COBOL/400 Reference
PERFORM Statement
Entrance
Set identifier-2 to
current FROM value
Set identifier-5 to
current FROM value
Execute specified set
of statements
Condition-2
Condition-1
Augment identifier-5
with current BY value
Augment identifier-2
with current BY value
Exit
True
False
False
True
Figure 170. Varying Two Identifierswith TEST AFTER
Varying Three Identifiers
Example
PERFORM procedure-name-1 THROUGH procedure-name-2
VARYING identifier-2 FROM identifier-3
BY identifier-4 UNTIL condition-1
AFTER identifier-5 FROM identifier-6
BY identifier-7 UNTIL condition-2
AFTER identifier-8 FROM identifier-9
BY identifier-1 UNTIL condition-3
Chapter 8. Procedure Division Statements 321
PERFORM Statement
The actions are the same as those for two identifiers, except that identifier-8 goes
through the complete cycle each time identifier-5 is augmented by identifier-7,
which, in turn, goes through a complete cycle each time identifier-2 is varied.
At the end of PERFORM statement execution:
identifier-5 and identifier-8
Contain the current values of identifier-6 and identifier-9, respectively.
identifier-2
Has a value exceeding its last-used setting by one increment/decrement value
(unless condition-1 was true at the beginning of PERFORM statement exe-
cution, in which case, identifier-2 contains the current value of identifier-3).
322 COBOL/400 Reference
PERFORM Statement
Figure 171 illustrates the logic of the PERFORM statement when three identifiers
are varied.
Entrance
Test
Condition-1
Test
Condition-2
Test
Condition-3
True
Exit
False
True
True
False
False
Execute
Procedure-1
THRU
Procedure-2
Set identifier-8
to its Current
FROM Value
Set identifier-5
to its Current
FROM Value
Augment
identifier-8
with its
Current
BY Value
Augment
identifier-5
with its
Current
BY Value
Augment
identifier-2
with its
Current
BY Value
Identifier-2
Identifier-5
Identifier-8
Set to Initial
FROM Values
C2
D2
D2 C2
Figure 171. Format 4 PERFORM Statement LogicVarying Three Identifiers
| Note: Figure 171 assumes that identifier-5 and identifier-2 are not related. It also
| assumes that identifier-8 and identifier-5 are not related. If, in either case, one is
| dependent on the other (through subscripting for example), the results may be pre-
| dictable but generally undesirable.
Chapter 8. Procedure Division Statements 323
PERFORM Statement
Varying More Than Three Identifiers
In the VARYING phrase, you may extend the examples above by adding up to four
more AFTER phrases, for a total of six AFTER phrases. .
Varying Phrase Rules
No matter how many variables are specified, the following rules apply:
1. In the VARYING/AFTER phrases, when an index-name is specified:
a. The index-name is initialized and incremented or decremented according to
the rules under INDEXED BY Phrase on page 120. (See also SET
Statement on page 369.)
b. In the associated FROM phrase, an identifier must be described as an
integer and have a positive value; a literal must be a positive integer.
c. In the associated BY phrase, an identifier must be described as an integer;
a literal must be a nonzero integer.
2. In the FROM phrase, when an index-name is specified:
a. In the associated VARYING/AFTER phrase, an identifier must be described
as an integer. It is initialized, as described in the SET statement.
b. In the associated BY phrase, an identifier must be described as an integer
and have a nonzero value; a literal must be a nonzero integer.
3. In the BY phrase, identifiers and literals must have nonzero values.
4. Changing the values of identifiers and/or index-names in the VARYING, FROM,
and BY phrases during execution changes the number of times the procedures
are executed.
5. The way in which operands are incremented or decremented depends on the
number of variables specified.
324 COBOL/400 Reference
READ Statement
READ Statement
The READ statement makes a record available to the program.
For sequential access, the READ statement makes the next logical record from a
file available to the object program. For random access, the READ statement
makes a specified record from a direct-access file available to the object program.
When the READ statement is executed, the associated file must be open in INPUT
or I-O mode.
READfile-name
NEXT RECORD
INTOidentifier-1
NO LOCK
WITH
FORMATidentifier-2
IS literal-1
ENDimperative-statement-1
AT
NOTENDimperative-statement-2 END-READ
AT
Figure 172. Format 1Sequential Retrieval using SEQUENTIAL Access
Chapter 8. Procedure Division Statements 325
READ Statement
READfile-nameNEXT
RECORD
FIRST
LAST
PRIOR
INTOidentifier-1
NO LOCK
WITH
FORMATidentifier-2
IS literal-1
ENDimperative-statement-1
AT
NOTENDimperative-statement-2 END-READ
AT
Figure 173. Format 2Sequential Retrieval using DYNAMIC Access
326 COBOL/400 Reference
READ Statement
READfile-name
RECORD INTOidentifier-1
NO LOCK
WITH
KEYdata-name-1
IS
FORMATidentifier-2
IS literal-1
INVALIDimperative-statement-1
KEY
NOTENDimperativestatement2 ENDRETURN
AT
Figure 179. Format
Within an OUTPUT PROCEDURE, at least one RETURN statement must be speci-
fied.
When the RETURN statement is executed, the next record from file-name-1. is
made available for processing by the OUTPUT PROCEDURE.
file-name-1
Must be described in a Data Division SD entry.
If more than one record description is associated with file-name-1, these
records automatically share the same storage; that is, the area is implicitly
redefined. After RETURN statement execution, only the contents of the current
record are available; if any data items lie beyond the length of the current
record, their contents are undefined.
INTO identifier-1
The RETURN INTO statement is equivalent to the statements:
RETURN file-name-1
MOVE record-name TO identifier-1
Moving takes place according to the rules for the MOVE statement without the
CORRESPONDING phrase. Any subscripting, indexing, or reference modifica-
tion associated with identifier-1 is evaluated after the record has been returned
and immediately before it is moved to identifier-1.
The INTO phrase may be specified in a RETURN statement if one or both of
the following are true:
If only one record description is subordinate to the sort-merge file
description entry, and/or
If all record-names associated with file-name-1 and the data item refer-
enced by identifier-1 describe a group item, a numeric-edited item, or an
elementary alphanumeric item.
348 COBOL/400 Reference
RETURN Statement
The record areas associated with file-name-1 and identifier-1 must not be the same
storage area.
AT END Phrases
The imperative-statement specified on the AT END phrase executes after all
records have been returned from file-name-1. No more RETURN statements may
be executed as part of the current output procedure.
If an at end condition does not occur during the execution of a RETURN statement,
then after the record is made available and after executing any implicit move
resulting from the presence of an INTO phrase, control is transferred to the imper-
ative statement specified by the NOT AT END phrase, otherwise control is passed
to the end of the RETURN statement.
END-RETURN Phrase
This explicit scope terminator serves to delimit the scope of the RETURN state-
ment. END-RETURN permits a conditional RETURN statement to be nested in
another conditional statement. END-RETURN may also be used with an imperative
RETURN statement.
For more information, see Delimited Scope Statements on page 184.
Chapter 8. Procedure Division Statements 349
REWRITE Statement
REWRITE Statement
The REWRITE statement logically replaces an existing record in a direct-access
file.
When the REWRITE statement is executed, the associated direct-access file must
be open in I-O mode.
The formats for the REWRITE statement are as follows:
REWRITErecord-name-1
FROMidentifier-1
FORMATidentifier-2
IS literal-1
INVALIDimperative-statement-1
KEY
END imperativestatement1
AT
WHEN condition1imperativestatement2
NEXT SENTENCE
WHEN condition1imperativestatement2
ENDSEARCH
Figure 183. Format 1Serial Search
SEARCH ALL identifier1
END imperativestatement1
AT
WHENdataname1EQUALidentifier3
IS TO literal1
= arithmeticexpression1
conditionname1
ANDdataname2EQUALidentifier4
IS TO literal2
= arithmeticexpression2
conditionname2
imperativestatement2
ENDSEARCH
NEXT SENTENCE
Figure 184. Format 2Binary Search
identifier-1
Can be a data item subordinate to a data item that contains an OCCURS
clause; that is, it can be a part of a multi-dimensional table. In this case, the
data description entry must specify an INDEXED BY phrase for each dimension
of the table.
Identifier-1 can be an index data item.
Identifier-1 must refer to all occurrences within the table element; that is, it must
not be subscripted or reference modified.
Chapter 8. Procedure Division Statements 361
SEARCH Statement
The Data Division description of identifier-1 must contain an OCCURS clause
with the INDEXED BY phrase. For Format-2, the Data Division description
must also contain the KEY IS phrase in its OCCURS clause.
SEARCH statement execution modifies only the value in the index-name asso-
ciated with identifier-1 (and, if present, of index-name-1 or identifier-2). There-
fore, to search an entire two- to seven-dimensional table, it is necessary to
execute a SEARCH statement for each dimension. Before each execution,
SET statements must be executed to reinitialize the associated index-names.
AT END/WHEN Phrases
After imperative-statement-1 or imperative-statement-2 is executed, control passes
to the end of the SEARCH statement, unless imperative-statement-1 or
imperative-statement-2 ends with a GO TO statement.
END-SEARCH Phrase
This explicit scope terminator serves to delimit the scope of the SEARCH state-
ment. END-SEARCH permits a conditional SEARCH statement to be nested in
another conditional statement. If the END-SEARCH phrase is specified, the NEXT
SENTENCE phrase must not be specified.
For more information, see Delimited Scope Statements on page 184.
Serial Search
The Format 1 SEARCH statement executes a serial search beginning at the current
index setting. When the search begins, if the value of the index-name associated
with identifier-1 is not greater than the highest possible occurrence number, the fol-
lowing actions take place:
The condition(s) in the WHEN phrase are evaluated in the order in which they
are written.
If none of the conditions is satisfied, the index-name for identifier-1 is increased
to correspond to the next table element, and step 1 is repeated.
If upon evaluation, one of the WHEN conditions is satisfied, the search is termi-
nated immediately, and the imperative-statement associated with that condition
is executed. The index-name points to the table element that satisfied the con-
dition. If NEXT SENTENCE is specified, control passes to the statement fol-
lowing the closest period.
If the end of the table is reached (that is, the incremented index-name value is
greater than the highest possible occurrence number) without the WHEN condi-
tion being satisfied, the search is terminated, as described in the next para-
graph.
If, when the search begins, the value of the index-name associated with identifier-1
is greater than the highest possible occurrence number, the search immediately
ends, and, if specified, the AT END imperative-statement is executed. If the AT
END phrase is omitted, control passes to the next statement after the SEARCH
statement.
362 COBOL/400 Reference
SEARCH Statement
VARYING Phrase
index-name-1
One of the following actions applies:
If index-name-1 is an index for identifier-1, this index is used for the search.
Otherwise, the first (or only) index-name is used.
If index-name-1 is an index for another table element, then the first (or
only) index-name for identifier-1 is used for the search; the occurrence
number represented by index-name-1 is increased by the same amount as
the search index-name and at the same time.
When the VARYING index-name-1 phrase is omitted, the first (or only) index-
name for identifier-1 is used for the search.
identifier-2
Must be either an index data item or an elementary integer item. During the
search, one of the following actions applies:
If identifier-2 is an index data item, then, whenever the search index is
increased, the specified index data item is simultaneously increased by the
same amount.
If identifier-2 is an integer data item, then, whenever the search index is
increased, the specified data item is simultaneously increased by 1.
WHEN Phrase
condition-1, condition-2
May be any condition described under Conditional Expressions on page 166.
Figure 185 illustrates a Format 1 SEARCH operation containing two WHEN
phrases.
Chapter 8. Procedure Division Statements 363
SEARCH Statement
imperative-
statement-2
imperative-
statement-3
imperative-
statement-1
Index setting:
highest permissible
occurrence number
Increment index-name
for identifier-1
(index-name-1 if
applicable)
Increment index-name-1
(for a different table)
or identifier-2
AT END >
<
condition-1
condition-2
Entrance
False
False
True
True
* These operations are included only when called for in the statement.
** Control transfers to the next sentence, unless the imperative
statement ends with a GO TO statement.
Figure 185. Format 1 SEARCH with Two WHEN Phrases
364 COBOL/400 Reference
SEARCH Statement
Binary Search
The Format 2 SEARCH ALL statement executes a binary search. The search
index need not be initialized by SET statements, because its setting is varied during
the search operation so that its value is at no time less than the value of the first
table element, nor ever greater than the value of the last table element. The index
used is always that associated with the first index-name specified in the OCCURS
clause.
identifier-1
Can be a data item subordinate to a data item that contains an OCCURS
clause; that is, it can be a part of a two- to seven-dimensional table. In this
case, the data description entry must specify an INDEXED BY phrase for each
dimension of the table.
Before the search takes place, the values of all indexes should be set for
higher dimensions of the table to define a specific table of identifier-1 elements.
Identifier-1 must refer to all occurrences within the table element; that is, it must
not be subscripted or indexed.
Identifier-1 cannot be a pointer data item.
The Data Division description of identifier-1 must contain an OCCURS clause
with the INDEXED BY option.
AT END
The AT END imperative-statement is executed.
If the AT END phrase is not specified, control passes to the next statement
after the SEARCH statement.
In either case, the final setting of the index is not predictable.
WHEN Phrase
If the WHEN phrase cannot be satisfied for any setting of the index within this
range, the search is unsuccessful.
If the WHEN option can be satisfied, control passes to imperative-statement-2, and
the index contains the value indicating the occurrence that allowed the WHEN
condition(s) to be satisfied.
condition-name
Each condition-name specified must have only a single value, and each must
be associated with an ASCENDING/DESCENDING KEY identifier for this table
element.
data-name
Must specify an ASCENDING/DESCENDING KEY data item in the identifier-1
table element and must be indexed by the first identifier-1 index-name, along
with other indexes or literals, as required. Each data-name may be qualified.
identifier-3, identifier-4
Must not be an ASCENDING/DESCENDING KEY data item for identifier-1 or
an item that is indexed by the first index-name for identifier-1.
Must not be a pointer data item.
Chapter 8. Procedure Division Statements 365
SEARCH Statement
arithmetic-expression
May be any of the expressions defined under Arithmetic Expressions on
page 164, with the following restriction: Any identifier in the arithmetic-
expression must not be an ASCENDING/DESCENDING KEY data item for
identifier-1 or an item that is indexed by the first index-name for identifier-1.
When an ASCENDING/DESCENDING KEY data item is specified, explicitly or
implicitly, in the WHEN phrase, all preceding ASCENDING/DESCENDING KEY
data-names for identifier-1 must also be specified.
The results of a SEARCH ALL operation are predictable only when:
The data in the table is ordered according to the ASCENDING/DESCENDING
KEY phrase
The contents of the ASCENDING/DESCENDING keys specified in the WHEN
clause provide a unique table reference.
Search Statement Considerations
Index data items cannot be used as subscripts, because of the restrictions on direct
reference to them.
The use of a direct indexing reference together with a relative indexing reference
for the same index-name allows reference to two different occurrences of a table
element for comparison purposes.
When the object of the VARYING option is an index-name for another table
element, one Format 1 SEARCH statement steps through two table elements at
once.
To ensure correct execution of a SEARCH statement for a variable-length table,
make sure the object of the OCCURS DEPENDING ON clause (data-name-1) con-
tains a value that specifies the current length of the table.
The scope of a SEARCH statement may be terminated by any of the following:
An END-SEARCH phrase at the same level of nesting
A separator period
An ELSE or END-IF phrase associated with a previous IF statement.
366 COBOL/400 Reference
SEARCH Statement
SEARCH Example
The following example searches an inventory table for items that match those from
input data. The key is ITEM-NUMBER.
.. 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7
DATA DIVISION.
FILE SECTION.
FD SALES-DATA
BLOCK CONTAINS 1 RECORDS
RECORD CONTAINS 8 CHARACTERS
LABEL RECORDS STANDARD
DATA RECORD IS SALES-REPORTS.
1 SALES-REPORTS PIC X(8).
FD PRINTED-REPORT
BLOCK CONTAINS 1 RECORDS
RECORD CONTAINS 132 CHARACTERS
LABEL RECORDS OMITTED
DATA RECORD IS PRINTER-OUTPUT.
1 PRINTER-OUTPUT PIC X(132).
FD INVENTORY-DATA
BLOCK CONTAINS 1 RECORDS
RECORD CONTAINS 4 CHARACTERS
LABEL RECORDS STANDARD
DATA RECORD IS INVENTORY-RECORD.
1 INVENTORY-RECORD.
3 I-NUMBER PIC 9(4).
3 INV-ID PIC X(26).
3 I-COST PIC 9(8)V99.
WORKING-STORAGE SECTION.
1 EOF-SW PIC X VALUE "N".
1 EOF-SW2 PIC X VALUE "N".
1 SUB1 PIC 99.
1 RECORDS-NOT-FOUND PIC 9(5) VALUE ZEROS.
1 TOTAL-COSTS PIC 9(1) VALUE ZEROS.
1 HOLD-INPUT-DATA.
3 INVENTORY-NUMBER PIC 9999.
3 PURCHASE-COST PIC 9(4)V99.
3 PURCHASE-DATE PIC 9(6).
3 FILLER PIC X(64).
1 PRINTER-SPECS.
3 PRINT-LINE.
5 OUTPUT-ITEM-NUMBER PIC ZZZ9.
5 FILLER PIC X(48) VALUE SPACES.
5 TOTAL-COSTS- PIC $(8).99.
1 PRODUCT-TABLE.
5 INVENTORY-NUMBERS OCCURS 5 TIMES
ASCENDING KEY ITEM-NUMBER
INDEXED BY INDEX-1.
7 ITEM-NUMBER PIC 9(4).
7 ITEM-DESCRIPTION PIC X(26).
7 ITEM-COST PIC 9(8)V99.
Chapter 8. Procedure Division Statements 367
SEARCH Statement
.. 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ...7
PROCEDURE DIVISION.
1-START-IT.
OPEN INPUT SALES-DATA INVENTORY-DATA OUTPUT PRINTED-REPORT.
MOVE HIGH-VALUES TO PRODUCT-TABLE.
PERFORM READ-INVENTORY-DATA.
LOAD-TABLE-ROUTINE.
PERFORM LOAD-IT VARYING SUB1 FROM 1 BY 1 UNTIL SUB1 > 5
OR EOF-SW2 = "Y".
PERFORM 11-READ-IT.
2-MAIN-ROUTINE.
PERFORM PROCESS-DATA UNTIL EOF-SW = "Y".
MOVE TOTAL-COSTS TO TOTAL-COSTS-.
PERFORM WRITE-REPORT THRU WRITE-REPORT-EXIT.
DISPLAY "RECORDS NOT FOUND - " RECORDS-NOT-FOUND
UPON MYTUBE.
STOP RUN.
PROCESS-DATA.
SEARCH ALL INVENTORY-NUMBERS
AT END PERFORM KEY-NOT-FOUND THRU NOT-FOUND-EXIT
WHEN ITEM-NUMBER (INDEX-1) = INVENTORY-NUMBER
MOVE ITEM-NUMBER (INDEX-1) TO OUTPUT-ITEM-NUMBER
MOVE ITEM-COST (INDEX-1) TO TOTAL-COSTS-
ADD ITEM-COST (INDEX-1) TO TOTAL-COSTS
PERFORM WRITE-REPORT THRU WRITE-REPORT-EXIT.
PERFORM 11-READ-IT.
KEY-NOT-FOUND.
ADD 1 TO RECORDS-NOT-FOUND.
NOT-FOUND-EXIT.
EXIT.
LOAD-IT.
MOVE INVENTORY-RECORD TO INVENTORY-NUMBERS (SUB1).
PERFORM READ-INVENTORY-DATA.
WRITE-REPORT.
WRITE PRINTER-OUTPUT FROM PRINTER-SPECS.
WRITE-REPORT-EXIT.
EXIT.
READ-INVENTORY-DATA.
READ INVENTORY-DATA
AT END MOVE "Y" TO EOF-SW2.
11-READ-IT.
READ SALES-DATA INTO HOLD-INPUT-DATA
AT END MOVE "Y" TO EOF-SW.
368 COBOL/400 Reference
SET Statement
SET Statement
The SET statement establishes reference points for table handling operations by
doing one of the following:
1. Placing values associated with table elements into indexes associated with
index-names
2. Incrementing or decrementing an occurrence number
3. Setting the status of an external switch to ON or OFF, or
4. Moving data to condition names to make conditions true.
5. Setting addresses of pointer data items.
Index-names are related to a given table through the INDEXED BY phrase of the
OCCURS clause; they are not further defined in the program.
When the sending and receiving fields in a SET statement share part of their
storage (that is, the operands overlap), the result of the execution of such a SET
statement is undefined.
Format 1: TO Phrase
When this form of the SET statement is executed, the current value of the receiving
field is replaced by the value of the sending field (with conversion).
SETindexname1TOindexname2
identifier1 identifier2
integer1
Figure 186. Format 1TO Phrase
index-name-1, identifier-1
Receiving fields.
Must name either index data items or elementary numeric integer items.
index-name-2
Sending field.
The value before the SET statement is executed must correspond to the occur-
rence number of its associated table.
identifier-2
Sending field.
Must name either an index data item or an elementary numeric integer item.
integer-1
Sending field.
Must be a positive integer.
Chapter 8. Procedure Division Statements 369
SET Statement
Execution of the Format 1 SET statement depends upon the type of receiving field,
as follows:
Index-name receiving fields (index-name-1, index-name-2, and so on) with one
exception are converted to a displacement value representing the occurrence
number indicated by the sending field. To be valid, the resulting index-name
value must correspond to an occurrence number in its associated table
element. For the one exception, when the sending field is an index data item,
the value in the index data item is placed in the index-name without change.
Index data item receiving fields (identifier-1, identifier-2, and so on) are set
equal to the contents of the sending field (which must be either an index-name
or an index data item); no conversion takes place. A numeric integer or literal
sending field must not be specified.
Integer data item receiving fields (identifier-1, identifier-2, and so on) are set to
the occurrence number associated with the sending field, which must be an
index-name. An integer data item, an index data item, or a literal sending field
must not be specified.
Table 48 shows valid combinations of sending and receiving fields in a Format 1
SET statement.
Receiving fields are acted upon in the left-to-right order in which they are specified.
Any subscripting or indexing associated with an identifier's receiving field is evalu-
ated immediately before the field is acted upon.
The value used for the sending field is the value at the beginning of SET statement
execution.
The value for an index-name after execution of a SEARCH or PERFORM state-
ment may be undefined; therefore, a Format 1 SET statement should reinitialize
such index-names before other table-handling operations are attempted.
Table 48. Sending and Receiving Fields for Format 1 SET Statement
Sending Field
Receiving Field
Index-name
Index Data
Item
Integer Data
Item
Index-name Valid Valid
*
Valid
Index Data Item Valid
*
Valid
*
DUPLICATES
WITH IN ORDER
SEQUENCEalphabet-name
COLLATING IS
USING file-name-2
INPUT PROCEDUREprocedure-name-1
IS THROUGHprocedure-name-2
THRU
GIVING file-name-3
OUTPUT PROCEDUREprocedure-name-3
IS THROUGHprocedure-name-4
THRU
Figure 191. Format
file-name-1
The name given in the SD entry that describes the records being sorted.
Null-capable fields are supported, but null values are not. Null values result in a file
status of 90.
374 COBOL/400 Reference
SORT Statement
ASCENDING/DESCENDING KEY Phrase
This phrase specifies that records are to be processed in ascending or descending
sequence (depending on the phrase specified), based on the specified sort keys.
data-name-1
Specifies a KEY data item on which the sort will be based. Each such data-
name must identify a data item in a record associated with file-name-1. The
following rules apply:
1. A specific KEY data item must be physically located in the same position
and have the same data format in each input file. However, it need not
have the same data-name.
2. If file-name-1 has more than one record description, then the KEY data
items need be described in only one of the record descriptions.
3. KEY data items must be fixed-length items.
4. KEY data items must not contain an OCCURS clause or be subordinate to
an item that contains an OCCURS clause.
5. The total length of the KEY data item must not exceed 256 bytes.
6. KEY data items can be qualified or reference modified; they cannot be sub-
scripted or indexed.
SORT lists the KEY data items from left to right in order of decreasing signif-
icance, no matter how they are divided into KEY phrases. The leftmost data-
name is the major key, the next data-name is the next most significant key, and
so forth.
The direction of the sorting operation depends on the specification of the
ASCENDING or DESCENDING key words as follows:
When ASCENDING is specified, the sequence is from the lowest key value to
the highest key value.
When DESCENDING is specified, the sequence is from the highest key value
to the lowest.
If the KEY data item is alphabetic, alphanumeric, alphanumeric-edited, or
numeric-edited, the sequence of key values depends on the collating sequence
used (see COLLATING SEQUENCE Phrase on page 376).
The key comparisons are performed according to the rules for comparison of
operands in a relation condition (see Relation Condition under Conditional
Expressions on page 166).
DUPLICATES Phrase
If the DUPLICATES phrase is specified, and the contents of all the key elements
associated with one record are equal to the corresponding key elements in one or
more other records, the order of these records is as follows:
The order of the associated input files as specified in the SORT statement.
Within a given file the order is that in which the records are accessed from that
file.
The order in which these records are released by an input procedure, when an
input procedure is specified.
If the DUPLICATES phrase is not specified, the order of these records is undefined.
Chapter 8. Procedure Division Statements 375
SORT Statement
COLLATING SEQUENCE Phrase
This phrase specifies the collating sequence to be used in nonnumeric comparisons
for the KEY data items in this sorting operation.
alphabet-name
Must be specified in the alphabet-name clause of the SPECIAL-NAMES para-
graph. Any one of the alphabet-name clause options may be specified. See
SPECIAL-NAMES Paragraph on page 37 for a list of alphabet-name clause
options and their meanings.
When the COLLATING SEQUENCE phrase is omitted, the PROGRAM COL-
LATING SEQUENCE clause (if specified) in the OBJECT-COMPUTER paragraph
specifies the collating sequence to be used.
When both the COLLATING SEQUENCE phrase and the PROGRAM COLLATING
SEQUENCE clause are omitted, the EBCDIC collating sequence is used.
USING Phrase
file-name-2, . . .
The input files.
When the USING phrase is specified, all the records in file-name-2, . . . (that is,
the input files) are transferred automatically to file-name-1. At the time the SORT
statement is executed, these files must not be open; the compiler opens, reads,
makes records available, and closes these files automatically. If
EXCEPTION/ERROR procedures are specified for these files, the compiler makes
the necessary linkage to these procedures. The input files must be sequential, rel-
ative or indexed files.
All input files must specify sequential or dynamic access mode, and must be
described in FD entries in the Data Division.
INPUT PROCEDURE Phrase
This phrase specifies the name of a procedure that is to select or modify input
records before the sorting operation begins.
procedure-name-1
Specifies the first (or only) section or paragraph in the input procedure.
procedure-name-2
Specifies the last section or paragraph in the input procedure.
The input procedure may consist of any procedure needed to select, modify, or
copy the records that are made available one at a time by the RELEASE statement
to the file referenced by file-name-1. The range includes all statements that are
executed as the result of a transfer of control by CALL, EXIT, GO TO, and
PERFORM statements in the range of the input procedure, as well as all state-
ments in declarative procedures that are executed as a result of the execution of
statements in the range of the input procedure. The range of the input procedure
must not cause the execution of any MERGE, RETURN, or SORT statement.
If an input procedure is specified, control is passed to the input procedure before
file-name-1 is sequenced by the SORT statement. The compiler inserts a return
mechanism at the end of the last statement in the input procedure. When control
376 COBOL/400 Reference
SORT Statement
passes the last statement in the input procedure, the records that have been
released to file-name-1 are sorted.
GIVING Phrase
file-name-3, . . .
The output files.
When the GIVING phrase is specified, all the sorted records in file-name-1 are
automatically transferred to the output files (file-name-3, . . . ). At the time the
SORT statement is executed, this file must not be open.
For each of the files referenced by file-name-3, the execution of the SORT state-
ment causes the following actions to be taken:
The processing of the file is initiated. The initiation is performed as if an OPEN
statement with the OUTPUT phrase has been executed.
The sorted logical records are returned and written onto the file. Each record is
written as if a WRITE statement without any optional phrases had been exe-
cuted. The records overwrite the previous contents, if any, of the file.
IBM Extension
If file-name-1 is a logical database file, the records are added to the end of the
file.
End of IBM Extension
If the file referenced by file-name-3 is an INDEXED file then the associated key
data-name for that file must have an ASCENDING KEY phrase in the SORT
statement. This same data-name must occupy the identical character positions
in its record as the data item associated with the prime record key for the file.
For a relative file, the relative key data item for the first record returned con-
tains the value '1'; for the second record returned, the value '2', and so on.
After execution of the SORT statement, the content of the relative key data
item indicates the last record returned to the file.
The processing of the file is terminated. The termination is performed as if a
CLOSE statement without optional phrases had been executed.
Note: When duplicate keys are found when writing to an indexed file, the SORT
will terminate and the sorted data in all GIVING files will be incomplete.
These implicit functions are performed such that any associated USE AFTER
EXCEPTION/ERROR procedures are executed; however, the execution of such a
USE procedure must not cause the execution of any statement manipulating the file
referenced by, or accessing the record area associated with, file-name-3.
On the first attempt to write beyond the externally defined boundaries of the file,
any USE AFTER STANDARD EXCEPTION/ERROR procedure specified for the file
is executed. If control is returned from that USE procedure or if no such USE pro-
cedure is specified, the processing of the file is terminated.
All output files must specify sequential or dynamic access mode, and must be
described in FD entries in the Data Division.
Chapter 8. Procedure Division Statements 377
SORT Statement
The output file must be an indexed, relative or sequential file.
The output file should also be created without a keyed sequence access path.
When the output file has such a path, the MERGE statement cannot override the
collating sequence defined in the data description specifications (DDS).
OUTPUT PROCEDURE Phrase
This phrase specifies the name of a procedure that is to select or modify output
records from the sorting operation.
procedure-name-3
Specifies the first (or only) section or paragraph in the output procedure.
procedure-name-4
Identifies the last section or paragraph in the output procedure.
The output procedure may consist of any procedure needed to select, modify, or
copy the records that are made available one at a time by the RETURN statement
in sorted order from file-name-1. The range of the output procedure includes all
statements that are executed as the result of a transfer of control by CALL, EXIT,
GO TO, and PERFORM statements within the output procedure. The range also
includes all statements in declarative procedures that are executed as a result of
the execution of statements in the range of the output procedure. The range of the
output procedure must not include any MERGE, RELEASE, or SORT statement.
If an output procedure is specified, control passes to it after file-name-1 has been
sequenced by the SORT statement. The compiler inserts a return mechanism after
the last statement in the output procedure, and when control passes that statement,
the return mechanism terminates the sort and passes control to the next executable
statement after the SORT statement. Before entering the output procedure, the
sort procedure reaches a point at which it can select the next record in sorted order
when requested. The RETURN statements in the output procedure are the
requests for the next record.
Note: The INPUT and OUTPUT PROCEDURE phrases are similar to those for a
basic PERFORM statement. For example, if you name a procedure in an OUTPUT
PROCEDURE phrase, that procedure is executed during the sorting operation just
as if it were named in a PERFORM statement. As with the PERFORM statement,
execution of the procedure ends after the last statement executes. The last state-
ment in an input or output procedure can be the EXIT statement (see EXIT
Statement on page 272).
378 COBOL/400 Reference
START Statement
START Statement
The START statement provides a means of positioning within an indexed or relative
file for subsequent sequential record retrieval. This positioning is achieved by com-
paring the key values of records in the file with the value you place in the RECORD
KEY portion of a files record area (for an indexed file), or in the RELATIVE KEY
data item (for a relative file) prior to execution of the START statement.
Note: When the START statement is executed, the associated indexed or relative
file must be open in INPUT or I-O mode.
STARTfile-name 1
KEYEQUAL :
IS TO
=
GREATER
THAN
>
NOT LESS
THAN
NOT <
GREATEROR EQUAL
THAN TO
>=
1
: EXTERNALLY-DESCRIBED-KEY
data-name-1
FORMATidentifier-1
IS literal-1
INVALIDimperative-statement-1
KEY
NOT INVALIDimperative-statement-2 END-START
KEY
Figure 192. Format
file-name-1
Must name a file with sequential or dynamic access. File-name-1 must be
defined in an FD entry in the Data Division, and must not name a sort file.
Chapter 8. Procedure Division Statements 379
START Statement
KEY Phrase
When the KEY phrase is specified, the file position indicator is positioned at the
logical record in the file whose key field satisfies the comparison.
When the KEY phrase is not specified, KEY IS EQUAL (to the prime record key) is
implied.
data-name-1
Can be qualified or reference modified, but it cannot be subscripted.
IBM Extension
Multiple data-names may be specified. All data-names, following the initial
data-name, are syntax-checked only.
End of IBM Extension
When the START statement is executed, a comparison is made between the
current value in the key data-name and the corresponding key field in the file's
index.
If the FILE STATUS clause is specified in the FILE-CONTROL entry, the associ-
ated status key is updated when the START statement is executed. (See Status
Key on page 191.)
INVALID KEY Phrase
If the comparison is not satisfied by any record in the file, an invalid key condition
exists; the value of the file position indicator is undefined, and (if specified) the
INVALID KEY imperative statement runs. (See INVALID KEY Condition on
page 192.)
The INVALID KEY phrase must be specified if no EXCEPTION/ERROR procedure
is explicitly or implicitly specified for this file.
END-START Phrase
This explicit scope terminator serves to delimit the scope of the START statement.
END-START permits a conditional START statement to be nested in another condi-
tional statement. END-START may also be used with an imperative START state-
ment.
For more information, see Delimited Scope Statements on page 184.
Indexed Files
When the KEY phrase is specified, the key data item used for the comparison is
data-name.
When the KEY phrase is not specified, the key data item used for the EQUAL TO
comparison is the prime RECORD KEY. When START statement execution is suc-
cessfully completed, the RECORD KEY becomes the key of reference for subse-
quent READ statements.
380 COBOL/400 Reference
START Statement
data-name-1
Can be any of the following:
The prime RECORD KEY.
An alphanumeric data item within a record description for a file whose left-
most character position corresponds to the leftmost character position of
that record key; it may be qualified. The data item must be less than or
equal to the length of the record key for the file.
The file position indicator points to the first record in the file whose key field satis-
fies the comparison. If the operands in the comparison are of unequal lengths, the
comparison proceeds as if the longer field were truncated on the right to the length
of the shorter field. All other numeric and nonnumeric comparison rules apply,
except that the PROGRAM COLLATING SEQUENCE clause, if specified, has no
effect.
When START statement execution is successful, the RECORD KEY with which
data-name-1 is associated becomes the key of reference for subsequent READ
statements.
When START statement execution is unsuccessful, the key of reference is unde-
fined.
Relative Files
When the KEY phrase is specified, data-name-1 must specify the RELATIVE KEY.
Whether or not the KEY phrase is specified, the key data item used in the compar-
ison is the RELATIVE KEY data item. When START statement execution is suc-
cessful, the file position indicator points to the logical record in the file whose key
satisfies the comparison, and this key becomes the reference for subsequent READ
statements.
When START statement execution is unsuccessful, the key of reference and the file
position indicator are undefined.
START Statement Considerations
The following tables illustrate organization, access, and device considerations for
the START statement. The letter codes used in the tables are defined in the
section following the tables.
Table 49. Sequential Organization
Device Any
Access SEQUENTIAL
START Verb Not Allowed
Chapter 8. Procedure Division Statements 381
START Statement
Table 50. Relative Organization
Device DISK DATABASE
Access SEQUENTIAL RANDOM DYNAMIC SEQUENTIAL RANDOM DYNAMIC
START Verb I,P,A I,P,A I,P,A I,P,A
KEY IS O,E O,E O,E O,E
INVALID KEY O,U1,D O,U1,D O,U1,D O,U1,D
NOT INVALID
KEY
O,U2 O,U2 O,U2 O,U2
FORMAT
Table 51. Indexed Organization
Device DISK DATABASE
Access SEQUENTIAL RANDOM DYNAMIC SEQUENTIAL RANDOM DYNAMIC
START Verb I,P,B I,P,B I,P,B,K I,P,B,K
KEY IS O,G O,G O,G O,G
INVALID KEY O,U1,D O,U1,D O,U1,D O,U1,D
NOT INVALID
KEY
O,U2 O,U2 O,U2 O,U2
FORMAT O,F,J O,F,J
Letter
Code Meaning
Combination is not valid.
A When the KEY phrase is not specified, the file position indicator is set to
the record in the file with a key (relative record number) equal to the REL-
ATIVE KEY data item.
B When the KEY phrase is not specified, the file position indicator is set to
the record with a key equal to the value contained in the RECORD KEY
data item.
D If the comparison is not satisfied by any record in the file, an INVALID
KEY condition exists. The value of the file position indicator is undefined,
and the INVALID KEY imperative statement, if specified, is processed.
The INVALID KEY phrase must be specified if no EXCEPTION/ERROR
procedure is explicitly or implicitly specified for this file.
See INVALID KEY Condition under Common Processing Facilities on
page 191 for more information.
E When the KEY phrase is specified, data-name-1 must specify the RELA-
TIVE KEY. The file position indicator is positioned to the first logical
record currently existing in the file with a key (relative record number) that
satisfies the comparison with the RELATIVE KEY data item.
When the KEY phrase is not specified, KEY IS EQUAL (to the prime
record key) is implied.
Data-name-1 may be qualified; it may not be subscripted.
382 COBOL/400 Reference
START Statement
When the START statement is executed, a comparison is made between
the current value in the key data-name and the corresponding key field in
the file's records.
If the FILE STATUS clause is specified in the FILE-CONTROL entry, the
associated status key is updated when the START statement is executed.
(See Status Key under Common Processing Facilities on page 191.)
IBM Extension
F The value specified in the FORMAT phrase contains the name of the
record format to use for this I-O operation. The system uses this to
specify or select which record format to operate on.
If an identifier is specified, it must be a character-string of ten characters
or less, and it must be the name of one of the following:
A Working-Storage Section entry
A Linkage Section entry
A record-description entry for a previously opened file.
If a literal is specified, it must be an uppercase character-string of ten
characters or less.
A value of all blanks is treated as though the FORMAT phrase were not
specified. If the value is not valid for the file, a FILE STATUS of 9K is
returned and a USE procedure is invoked, if applicable for the file.
End of IBM Extension
G When the KEY phrase is specified, the search argument used for the com-
parison is data-name-1, which can be:
The RECORD KEY itself.
An alphanumeric data item within a record description for the file with
a leftmost character position that corresponds to the leftmost character
position of the key field in the record area. This data item must be
less than or equal to the length of the record key for the file.
This data item can be qualified or reference modified. If the key itself
is not used, the leftmost character position plus the reference modifica-
tion starting position must correspond to the leftmost character position
of the key field.
Note: If the RECORD KEY is defined as COMP, COMP-3, or COMP-4,
the key data item must be the RECORD KEY itself. A partial key field in
the record area cannot be used.
The file position indicator is positioned to the first record in the file with a
record key for a format that satisfies the comparison. If the operands in the
comparison are of unequal length, the comparison proceeds as if the
longer field were truncated on the right to the length of the shorter field.
All other numeric and nonnumeric comparison rules apply, except that the
PROGRAM COLLATING SEQUENCE, if specified, has no effect.
Chapter 8. Procedure Division Statements 383
START Statement
IBM Extension
For a file that specified RECORD KEY IS
EXTERNALLY-DESCRIBED-KEY, the following additional considerations
apply:
The reserved word EXTERNALLY-DESCRIBED-KEY can be specified.
This indicates that the complete key field in the record area should be
used in the comparison.
A series of data names can be specified. This allows a partial key
field in the record area to be used (generic START). These data
names must follow the following rules:
All except the last of the data names specified must be a record
key for a format that was copied in for the file. The record format
in which they are contained does not have to be the one that can
be specified by the FORMAT phrase.
The order of these data names (key fields) must match the order
of the keys as defined in DDS; that is, they must be specified from
most significant field to least significant.
The total number of data names cannot exceed the number of key
fields defined for that record format.
If the last data name specified in the series is not a key field in the
record area, it must have its left byte occupy the same space as
the key field that is defined at that relative position. If the key field
in the record area at this position is a COMP, COMP-3, or
COMP-4 field, only the key field itself can be used as the data
name.
Only the last key can be reference modified, and the reference
modification starting position must equal 1.
The following table shows the action between the KEY IS phrase and
the FORMAT phrase:
G1 The search argument is built using the specified data items.
G2 The file position indicator is set to the first record in the file of the
format specified with a record key that satisfies the comparison
specified in the key phrase.
G3 The search argument is built using the key fields in the record area
for the format specified in the FORMAT phrase.
G4 The file position indicator is set to the first record in the file of the
specified format with a record key equal to the search argument.
FORMAT
Phrase
KEY Phrase
Data-Name
Series
Omitted EXTERNALLY-DESCRIBED-KEY
Yes G1, G2 G3, G4 G3, G2
No G1, G5 G6, G7 G6, G5
384 COBOL/400 Reference
START Statement
G5 The file position indicator is set to the first record in the file with a
common key for the file that satisfies the comparison specified in
the KEY phrase. If there is no common key, the file position indi-
cator is set to the first record in the file.
G6 The search argument is built using the key fields in the record area
for the first record format for the file as defined in the program.
G7 The file position indicator is set to the first record in the file with a
common key for the file that is equal to the search argument. If
there is no common key, the file position indicator is set to the first
record in the file.
End of IBM Extension
I Allowed when the file is opened for INPUT.
J If specified, the file position indicator is set to the first record of the speci-
fied record format that satisfies the comparison. If omitted, the current
record pointer is set to the first record of any format that satisfies the com-
parison.
See the table in G above for a description of how this interacts with
EXTERNALLY-DESCRIBED-KEY and the KEY IS phrase.
IBM Extension
K The meaning of the comparison can be affected by the type of key fields
in the record area defined for the file. Key fields on this system can be
defined as multiple fields, each of which can be in ascending or
descending sequence. The system establishes a sequence (keyed
sequence access path) for the records based on the values contained in
the record key for the format and the sequencing specified in DDS. When
a START statement is processed, the request is interpreted as follows:
For example, when a statement is processed using the comparison of
GREATER THAN, a search is made of these sequenced records for the
first record after the search argument specified by the START statement.
If the file was sequenced using descending keys, the file position indicator
would point to a record with a key less than the one specified and not
greater than that specified in the START statement.
End of IBM Extension
O You can specify this combination.
P Allowed when the file is opened for I-O.
U1 The INVALID KEY phrase must be specified for files in which an appro-
priate USE procedure is not specified.
COBOL Comparison System Result
GREATER THAN AFTER
NOT LESS THAN EQUAL TO or AFTER
Chapter 8. Procedure Division Statements 385
START Statement
U2 After successful completion of a START statement with the NOT INVALID
KEY phrase, control transfers to the imperative statement associated with
the phrase.
386 COBOL/400 Reference
STOP Statement
STOP Statement
The STOP statement halts execution of the object program either permanently or
temporarily.
STOPRUN
literal
Figure 193. Format
literal
May be numeric or nonnumeric, and may be any figurative constant except ALL
literal. If the literal is numeric, it must be an unsigned integer.
Note: STOP literal is an obsolete element and is to be deleted from the next
revision of the ANSI Standard.
When STOP literal is specified, the literal is communicated to the system operator
for batch jobs and to the work station for interactive jobs. Program execution is
suspended. Execution is resumed only after operator intervention.
The operator response determines whether the run unit continues at the next exe-
cutable statement in the sequence, or a STOP RUN is executed.
Operator
Response Action
G (default) Continue at next instruction.
C Terminate execution of the run unit. Escape message LBE9001 is
issued to the caller of the COBOL run unit. For batch jobs, the job
is canceled if the CNLSEV parameter for the job contains a value
that is less than or equal to the severity of the message.
| The output of the STOP literal contains the program-name. The literal is contained
| in the second-level text, and is displayed when the Help key is used.
The STOP literal statement is useful for special situations (a special tape or disk
must be mounted, a specific daily code must be entered, and so forth) when oper-
ator intervention is needed during program execution. However, the ACCEPT and
DISPLAY statements are preferred when operator intervention is needed.
When STOP RUN is specified, execution of the run unit is terminated, and control
is returned to the system. If a STOP RUN statement appears in a sequence of
imperative statements, it must be the last or only statement in the sequence. The
STOP RUN statement closes all files.
Chapter 8. Procedure Division Statements 387
STOP Statement
For use of the STOP RUN statement in calling and called programs, see the table
below.
In each case above, the calling program could be the system. If it is, execution of
the run unit ceases, and control transfers to the operating system.
Also, if the main program is called by a program written in a language that does not
follow COBOL linkage conventions, return will be to this calling program.
Termination
Statement
In a Main Program
In a Subprogram
STOP RUN Return to calling
program.
Return directly to the
program that called the
main program.
388 COBOL/400 Reference
STRING Statement
STRING Statement
The STRING statement strings together the partial or complete contents of two or
more data items or literals into one single data item.
One STRING statement can be written instead of a series of MOVE statements.
STRINGidentifier-1DELIMITEDidentifier-2INTO identifier-3
literal-1 BY literal-2
SIZE
1 6
Column
4 1 25
1 J.B. SMITH 444 SPRING ST., CHICAGO, ILL.
6 67 76
A14725 1/22/76 $2,336
END-SUBTRACT
Figure 197. Format 1
Identifiers and literals preceding the keyword FROM are added together, and this
initial sum is subtracted from and stored immediately in identifier-2. The initial sum
is also subtracted from each successive occurrence of identifier-2, in the left-to-right
order in which identifier-2 is specified.
SUBTRACTidentifier-1FROMidentifier-2
literal-1 literal-2
GIVINGidentifier-3
ROUNDED
END-SUBTRACT
Figure 198. Format 2
All identifiers or literals preceding the key word FROM are added together and this
sum is subtracted from identifier-2 or literal-2. The result of the subtraction is
stored as the new value of each data item referenced by identifier-3.
Chapter 8. Procedure Division Statements 395
SUBTRACT Statement
SUBTRACTCORRESPONDINGidentifier-1 FROM identifier-2
CORR ROUNDED
END-SUBTRACT
Figure 199. Format 3
Elementary data items within identifier-1 are subtracted from, and the results are
stored in, the corresponding elementary data items within identifier-2.
If the composite of operands is 18 digits or less, enough places are carried so that
no significant digits are lost during execution.
IBM Extension
The composite of all operands in an arithmetic statement can have a maximum
length of 30 digits.
End of IBM Extension
For all Formats:
identifier
In Format 1, must name an elementary numeric item.
In Format 2, must name an elementary numeric item, unless the identifier
follows the word GIVING. Each identifier following the word GIVING must
name a numeric or numeric-edited elementary item.
In Format 3, must name a group item.
literal
Must be a numeric literal.
ROUNDED Phrase
For information on the ROUNDED phrase, and for operand considerations, see
ROUNDED Phrase on page 187.
SIZE ERROR Phrases
For information on the SIZE ERROR phrases, and for operand considerations, see
SIZE ERROR Phrases on page 188.
396 COBOL/400 Reference
SUBTRACT Statement
CORRESPONDING Phrase (Format 3)
The CORRESPONDING phrase (CORR) allows operations to be performed on ele-
mentary numeric data-items of the same name if the group items to which they
belong are specified.
The rules for use of the CORRESPONDING phrase with the SUBTRACT statement
are the same as for the ADD statement. See CORRESPONDING Phrase on
page 186 for more information.
END-SUBTRACT Phrase
This explicit scope terminator serves to delimit the scope of the SUBTRACT state-
ment. END-SUBTRACT permits a conditional SUBTRACT statement to be nested
in another conditional statement. END-SUBTRACT may also be used with an
imperative SUBTRACT statement.
For more information, see Delimited Scope Statements on page 184.
Chapter 8. Procedure Division Statements 397
UNSTRING Statement
UNSTRING Statement
The UNSTRING statement causes contiguous data in a sending field to be sepa-
rated and placed into multiple receiving fields.
One UNSTRING statement can be written instead of a series of MOVE statements.
UNSTRING identifier1
DELIMITEDidentifier-2
BY ALL literal-1
ORidentifier-3
ALL literal-2
INTOidentifier-4
DELIMITERidentifier-5 COUNTidentifier-6
IN IN
OVERFLOW imperative-statement-1
ON
NOTOVERFLOW imperative-statement-2
ON
END-UNSTRING
Figure 200. Format
identifier-1
Represents the sending field.
It must be an alphanumeric data item; it cannot be reference modified. Data is
transferred from this field to the receiving fields.
DELIMITED BY Phrase
This phrase specifies delimiters within the data that control the data transfer.
The delimiters are identifier-2, identifier-3, or their corresponding literals. Each
identifier or literal specified represents one delimiter. Each must be an alphanu-
meric data item.
Unless the DELIMITED BY phrase is specified, the DELIMITER IN and COUNT IN
phrases must not be specified.
identifier-2, identifier-3
Each represents one delimiter. Each must be an alphanumeric data item.
398 COBOL/400 Reference
UNSTRING Statement
literal-1, literal-2
Each must be a nonnumeric literal; each may be any figurative constant except
the ALL literal. When a figurative constant is specified, it is considered to be a
1-character nonnumeric literal.
ALL
One or more contiguous occurrences of any delimiters are treated as if they
were only one occurrence, and this one occurrence is moved to the delimiter
receiving field (if specified). The delimiting characters in the sending field are
treated as an elementary alphanumeric item and are moved into the current
delimiter receiving field, according to the rules of the MOVE statement.
When DELIMITED BY ALL is not specified, and two or more contiguous occur-
rences of any delimiter are encountered, the current data receiving field is filled
with spaces or zeros, according to the description of the data receiving field.
If a delimiter contains two or more characters, it is recognized as a delimiter only if
the delimiting characters are contiguous, and in the sequence specified in the
sending field.
When two or more delimiters are specified, an OR condition exists, and each nono-
verlapping occurrence of any one of the delimiters is recognized in the sending field
in the sequence specified. For example, if DELIMITED BY "AB" or "BC" is speci-
fied, then an occurrence of either AB or BC in the sending field is considered a
delimiter; an occurrence of ABC is considered an occurrence of AB. The data-
count fields, the pointer field, and the field-count field must each be an integer item
without the symbol P in the PICTURE character-string.
INTO Phrase
identifier-4
Represents the data receiving fields.
Each must have USAGE DISPLAY. These fields can be defined as:
Alphabetic
Alphanumeric
Numeric (without the symbol P in the PICTURE string).
DELIMITER IN
Represents the delimiter receiving fields.
identifier-5
Must be alphanumeric.
Unless the DELIMITED BY phrase is specified, the DELIMITER IN phrase must
not be specified. They must not be defined as alphanumeric edited or numeric
edited items.
COUNT IN
Identifier-6 is the data-count field for each data transfer. Each field holds the
count of examined characters in the sending field, terminated by the delimiters
or the end of the sending field, for the move to this receiving field; the delim-
iters are not included in this count.
The COUNT IN phrase must not be specified unless the DELIMITED BY
phrase is specified.
Chapter 8. Procedure Division Statements 399
UNSTRING Statement
POINTER Phrase
identifier-7
Contains a value that indicates a relative position in the sending field. When
this phrase is specified, the user must initialize this field before execution of the
UNSTRING statement is begun.
TALLYING IN Phrase
identifier-8
The field-count field is increased by the number of data receiving fields acted
upon in this execution of the UNSTRING statement. When this phrase is speci-
fied, the user must initialize this field before execution of the UNSTRING state-
ment is begun.
ON OVERFLOW Phrases
imperative-statement-1
Executed when:
The pointer value (explicit or implicit) is less than 1
The pointer value (explicit or implicit) exceeds a value equal to the length of
the sending field
All data receiving fields have been acted upon, and the sending field still
contains unexamined characters.
When any of the above conditions occurs, an overflow condition exists, and no
more data is transferred. Then the UNSTRING operation is terminated, the NOT
ON OVERFLOW phrase, if specified, is ignored, and control is transferred to the
end of the UNSTRING statement or, if the ON OVERFLOW phrase is specified, to
imperative-statement-1.
If control is transferred to imperative-statement-1, execution continues according to
the rules for each statement specified in imperative-statement-1. If a procedure
branching or conditional statement that causes explicit transfer of control is exe-
cuted, control is transferred according to the rules for that statement; otherwise,
upon completion of the execution of imperative-statement-1, control is transferred to
the end of the UNSTRING statement.
If at the time of execution of an UNSTRING statement, conditions that would cause
an overflow condition are not encountered, then after completion of the transfer of
data, the ON OVERFLOW phrase, if specified, is ignored. Control is then trans-
ferred to the end of the UNSTRING statement, or if the NOT ON OVERFLOW
phrase is specified, to imperative-statement-2.
If control is transferred to imperative-statement-2, execution continues according to
the rules for each statement specified in imperative-statement-2. If a procedure
branching or conditional statement that causes explicit transfer of control is exe-
cuted, control is transferred according to the rules for that statement. Otherwise,
upon completion of the execution of imperative-statement-2, control is transferred to
the end of the UNSTRING statement.
400 COBOL/400 Reference
UNSTRING Statement
END-UNSTRING Phrase
This explicit scope terminator serves to delimit the scope of the UNSTRING state-
ment. END-UNSTRING permits a conditional UNSTRING statement to be nested
in another conditional statement. END-UNSTRING may also be used with an
imperative UNSTRING statement.
For more information, see Delimited Scope Statements on page 184.
Data Flow
When the UNSTRING statement is initiated, data is transferred from the sending
field to the current data receiving field, according to the following rules (the current
data receiving field is identifier-4):
1. If the POINTER phrase is not specified, the sending field character-string is
examined, beginning with the leftmost character. If the POINTER phrase is
specified, the field is examined, beginning at the relative character position
specified by the value in the pointer field.
2. If the DELIMITED BY phrase is specified, the examination proceeds from left to
right, character-by-character, until a delimiter is encountered. If the end of the
sending field is reached before a delimiter is found, the examination ends with
the last character in the sending field. If there are more receiving fields, the
next one is selected, otherwise, an overflow condition occurs.
3. If the DELIMITED BY phrase is not specified, the number of characters exam-
ined is equal to the size of the current data receiving field, which depends on
its data category:
a. If the receiving field is alphanumeric or alphabetic, the number of charac-
ters examined is equal to the number of characters in the current receiving
field.
b. If the receiving field is numeric, the number of characters examined is
equal to the number of characters in the integer portion of the current
receiving field.
c. If the receiving field is described with the SIGN IS SEPARATE clause, the
number of characters examined is one less than the size of the current
receiving field.
d. If the receiving field is described as a variable-length data item, the number
of characters examined is determined by the size of the current receiving
field at the beginning of the UNSTRING operation.
4. The examined characters (excluding any delimiter characters) are treated as an
alphanumeric elementary item, and are moved into the current data receiving
field, according to the rules for the MOVE statement (see MOVE Statement
on page 295).
5. If the DELIMITER IN phrase is specified, the delimiting characters in the
sending field are treated as an elementary alphanumeric item and are moved to
the current delimiter receiving field, according to the rules for the MOVE state-
ment. If the delimiting condition is the end of the sending field, the current
delimiter receiving field is filled with spaces.
6. If the COUNT IN phrase is specified, a value equal to the number of examined
characters (excluding any delimiters) is moved into the data count field,
according to the rules for an elementary move.
Chapter 8. Procedure Division Statements 401
UNSTRING Statement
7. If the DELIMITED BY phrase is specified, the sending field is further examined,
beginning with the first character to the right of the delimiter.
8. If the DELIMITED BY phrase is not specified, the sending field is further exam-
ined, beginning with the first character to the right of the last character exam-
ined.
9. For each succeeding data receiving field, the preceding procedure is repeated
either until all the characters in the sending field have been transferred, or until
there are no more unfilled data receiving fields.
10. When the POINTER phrase is specified, the value of the pointer field behaves
as if it were increased by 1 for each examined character in the sending field.
When this execution of the UNSTRING statement is completed, the pointer field
contains a value equal to its initial value, plus the number of characters exam-
ined in the sending field.
11. When the TALLYING phrase is specified, then, when this execution of the
UNSTRING statement is completed, the field-count field contains a value equal
to the initial value, plus the number of data receiving areas acted upon.
Note: All subscripting and reference modification is performed only once, at the
beginning of the execution of the UNSTRING statement.
If any of the UNSTRING statement identifiers are subscripted or indexed, the sub-
scripts and indexes are evaluated as follows:
Any subscripting or indexing associated with the sending field, the pointer field,
or the field-count field is evaluated only once, immediately before any data is
transferred to any of the receivers.
Any subscripting or indexing associated with the delimiters, the data and delim-
iter receiving fields, or the data-count fields, is evaluated immediately before
the transfer of data into the affected data item.
Figure 201 on page 403 illustrates the rules of execution for the UNSTRING state-
ment.
402 COBOL/400 Reference
UNSTRING Statement
UNSTRING IDSEND DELIMITED BY DELID OR ALL ""
INTO IDR1 DELIMITER IN IDD1 COUNT IN IDC1 (All the data
IDR2 DELIMITER IN IDD2 receiving fields
IDR3 DELIMITER IN IDD3 COUNT IN IDC3 are defined as
IDR4 COUNT IN IDC4 alphanumeric)
WITH POINTER IDP
TALLYING IN IDT
ON OVERFLOW GO TO OFLOWEXIT.
DELID
IDSEND at execution at execution
1 2 3 4 5 6 7 8 ? ? 9 A B C D E F ?
7
1 2 3 45 6
1 2 3 b b b 4 5 6 7 8 b b b b 9 A B C
IDR1 after IDR2 after IDR3 after IDR4 after
execution execution execution execution
IDD1 IDC1 IDD2 IDD3 IDC3 IDC4
3 ? ? 8
(after execution) (after execution) (after execution)
IDP IDT The order of execution is:
(pointer) (tallying
field) 1 3 characters are placed in IDR1.
2 1 5 2 Because ALL is specified, all consecutive asterisks
are processed, but only one asterisk is placed in ID-D1.
(after execution 3 5 characters are placed in IDR2.
both initialized to
1 before execution) 4 A ? is placed in IDD2. The current receiving field
is now IDR3.
5 A ? is placed in IDD3; IDR3 is filled with spaces;
no characters are transferred, so is placed in IDC3.
6 No delimiter is encountered before 5 characters fill
IDR4; 8 is placed in IDC4, representing the number
of characters examined since the last delimiter.
7 IDP is updated to 21, the total length of the sending
field + 1; IDT is updated to 5, the number of fields
acted upon + 1. Since there are no unexamined characters
in the IDSEND, the OVERFLOW EXIT is not taken.
Figure 201. Results of UNSTRING Statement Execution
UNSTRING Statement Example
The following example illustrates some of the considerations that apply to the
UNSTRING statement.
In the Data Division, the user has defined the following input record to be acted
upon by the UNSTRING statement:
Chapter 8. Procedure Division Statements 403
UNSTRING Statement
1 INV-RCD.
5 CONTROL-CHARS PIC XX.
5 ITEM-INDENT PIC X(2).
5 FILLER PIC X.
5 INV-CODE PIC X(1).
5 FILLER PIC X.
5 NO-UNITS PIC 9(6).
5 FILLER PIC X.
5 PRICE-PER-M PIC 99999.
5 FILLER PIC X.
5 RTL-AMT PIC 9(6).99.
The next two records are defined as receiving fields for the UNSTRING statement.
DISPLAY-REC is to be used for printed output. WORK-REC is to be used for
further internal processing.
1 DISPLAY-REC
5 INV-NO PIC X(6).
5 FILLER PIC X VALUE SPACE
5 ITEM-NAME PIC X(2).
5 FILLER PIC X VALUE SPACE
5 DISPLAY-DOLS PIC 9(6).
1 WORK-REC
5 M-UNITS PIC 9(6).
5 FIELD-A PIC 9(6).
5 WK-PRICE
REDEFINES
FIELD-A PIC 9999V99.
5 INV-CLASS PIC X(3).
The user has also defined the following fields for use as control fields in the
UNSTRING statement.
1 DBY-1 PIC X, VALUE IS ".".
1 CTR-1 PIC 99, VALUE IS ZERO.
1 CTR-2 PIC 99, VALUE IS ZERO.
1 CTR-3 PIC 99, VALUE IS ZERO.
1 CTR-4 PIC 99, VALUE IS ZERO.
1 DLTR-1 PIC X.
1 DLTR-2 PIC X.
1 CHAR-CT PIC 99, VALUE IS 3.
1 FLDS-FILLED PIC 99, VALUE IS ZERO.
404 COBOL/400 Reference
UNSTRING Statement
In the Procedure Division, the user writes the following UNSTRING statement to
move subfields of INV-RCD to the subfields of DISPLAY-REC and WORK-REC:
UNSTRING INV-RCD
DELIMITED BY ALL SPACES
OR "/"
OR DBY-1
INTO ITEM-NAME COUNT IN CTR-1,
INV-NO DELIMITER IN DLTR-1
COUNT IN CTR-2,
INV-CLASS,
M-UNITS COUNT IN CTR-3,
FIELD-A,
DISPLAY-DOLS DELIMITER IN DLTR-2
COUNT IN CTR-4
WITH POINTER CHAR-CT
TALLYING IN FLDS-FILLED
ON OVERFLOW
GO TO UNSTRING-COMPLETE.
Before the UNSTRING statement is issued, the user places the value 3 in the
CHAR-CT (the pointer item), so as not to work with the two control characters at
the beginning of INV-RCD. In DBY-1, a period is placed for use as a delimiter, and
in FLDS-FILLED (the tallying item) the value 0 is placed. The following data is then
read into INV-RCD as shown in Figure 202.
Column
1 1 2 3 4 5 6
ZYFOURPENNYNAILS 7789/BBA 47512 122 379.5
Figure 202. UNSTRING Statement ExampleInput Data
When the UNSTRING statement is executed, the following actions take place:
1. Positions 3 through 18 (FOUR-PENNY-NAILS) of INV-RCD are placed in
ITEM-NAME, left-justified within the area, and the unused character positions
are padded with spaces. The value 16 is placed in CTR-1.
2. Because ALL SPACES is specified as a delimiter, the five contiguous SPACE
characters are considered to be one occurrence of the delimiter.
3. Positions 24 through 29 (707890) are placed in INV-NO. The delimiter char-
acter / is placed in DLTR-1, and the value 6 is placed in CTR-2.
4. Positions 31 through 33 are placed in INV-CLASS. The delimiter is a SPACE,
but because no field has been defined as a receiving area for delimiters, the
SPACE is merely bypassed.
5. Positions 35 through 40 (475120) are examined and are placed in M-UNITS.
The delimiter is a SPACE, but because no receiving field has been defined as
a receiving area for delimiters, the SPACE is bypassed. The value 6 is placed
in CTR-3.
6. Positions 42 through 46 (00122) are placed in FIELD-A and right-justified within
| the area. The leftmost character position is filled with a 0 (zero). The delimiter
Chapter 8. Procedure Division Statements 405
UNSTRING Statement
is a SPACE, but because no field has been defined as a receiving area for
delimiters, the SPACE is bypassed.
7. Positions 48 through 53 (000379) are placed in DISPLAY-DOLS. The period
delimiter character is placed in DLTR-2, and the value 6 is placed in CTR-4.
8. Because all receiving fields have been acted upon and two characters of data
in INV-RCD have not been examined, the ON OVERFLOW exit is taken, and
execution of the UNSTRING statement is completed.
At the end of execution of the UNSTRING statement, DISPLAY-REC contains the
following data:
707890 FOUR-PENNY-NAILS 000379
WORK-REC contains the following data:
475120000122BBA
CHAR-CT (the pointer field) contains the value 55, and FLD-FILLED (the tallying
field) contains the value 6.
Programming Note: One UNSTRING statement can be written instead of a series
of MOVE statements.
406 COBOL/400 Reference
WRITE Statement
WRITE Statement
The WRITE statement releases a logical record for an output or input/output file.
When the WRITE statement is executed, the associated indexed or relative file
must be open in OUTPUT, I-O, or EXTEND mode. The associated sequential file
must be open in OUTPUT or EXTEND mode.
Sequential Files
Sequential files are sequentially organized. The ADVANCING and END-OF-PAGE
phrases control the vertical positioning of each line on a printed page.
Note: The ADVANCING PAGE and END-OF-PAGE phrases must not both be
specified in a single WRITE statement.
If the printed page is held on an intermediate device (a disk, for example), the
format may appear different than the expected output when it is edited or browsed.
WRITErecord-name-1
FROM identifier-1
BEFOREidentifier-2
AFTER ADVANCING integer-1 LINE
LINES
mnemonic-name-1
PAGE
END-OF-PAGEimperative-statement-1
AT EOP
NOTEND-OF-PAGEimperative-statement-2 END-WRITE
AT EOP
Figure 203. Format 1Sequential
record-name-1
Must be defined in a Data Division FD entry. Record-name-1 may be qualified.
It must not be associated with a sort or merge file.
FROM
When FROM is specified, the result is the same as:
MOVE identifier-1 TO record-name-1
WRITE record-name-1
After the WRITE statement is executed, the information is still available in
identifier-1, even though it may not be in record-name-1. (See INTO/FROM
Identifier Phrase on page 192.)
identifier-1
Must be an alphanumeric or numeric edited data item. Data is transferred from
this field to the receiving fields.
Chapter 8. Procedure Division Statements 407
WRITE Statement
identifier-2
Must be an integer data item.
The maximum record size for the file is established at the time the file is created,
and cannot subsequently be changed.
Record-name-1 and identifier-1 must not refer to the same storage area.
After the WRITE statement is executed, the logical record is no longer available in
record-name-1, unless:
The associated file is named in a SAME RECORD AREA clause (in which
case, the record is also available as a record of the other files named in the
SAME RECORD AREA clause), or
The WRITE statement is unsuccessful because of a boundary violation.
In either of these two cases, the logical record is still available in record-name-1.
The file position indicator is not affected by execution of the WRITE statement.
The number of character positions required to store the record in a file may or may
not be the same as the number of character positions defined by the logical
description of that record in the COBOL program. (See PICTURE Clause Editing
on page 133 and USAGE Clause on page 149.)
If the FILE STATUS clause is specified in the File-Control entry, the associated
status key is updated when the WRITE statement is executed, whether or not exe-
cution is successful.
The WRITE statement may not be executed for a sequential file opened in I-O
mode.
ADVANCING Phrase
The ADVANCING phrase controls positioning of the output record on the page.
When this phrase is specified, the following rules apply:
1. When BEFORE ADVANCING is specified, the line is printed before the page is
advanced.
2. When AFTER ADVANCING is specified, the page is advanced before the line
is printed.
3. When identifier-2 is specified, the page is advanced the number of lines equal
to the current value in identifier-2. Identifier-2 must name an elementary
integer data item.
4. When integer is specified, the page is advanced the number of lines equal to
the value of integer.
5. Integer or the value in identifier-2 may be zero.
408 COBOL/400 Reference
WRITE Statement
6. When mnemonic-name is specified, a system-specific action takes place. For
more information on acceptable values for mnemonic-name, see
SPECIAL-NAMES Paragraph on page 37. Mnemonic-name must be equated
with environment-name-1 in the SPECIAL-NAMES paragraph (valid
environment-names are listed in Table 3 on page 39).
Note: This phrase is not valid if a LINAGE clause is specified in the FD entry
for this file.
7. When PAGE is specified, the record is printed on the logical page BEFORE or
AFTER (depending on the phrase used) the device is positioned to the next
logical page. If PAGE has no meaning for the device used, then BEFORE or
AFTER (depending on the phrase specified) ADVANCING 1 LINE is provided.
If the FD entry contains a LINAGE clause, the repositioning is to the first print-
able line of the next page, as specified in that clause. If the LINAGE clause is
omitted, the repositioning is to line 1 of the next succeeding page.
LINAGE-COUNTER Rules: If the LINAGE clause is specified for this file, the
associated LINAGE-COUNTER special register is modified during the execution
of the WRITE statement, according to the following rules:
1. If ADVANCING PAGE is specified, LINAGE-COUNTER is reset to 1.
2. If ADVANCING identifier-2 or integer is specified, LINAGE-COUNTER is
increased by the value in identifier-2 or integer.
3. If the ADVANCING phrase is omitted, LINAGE-COUNTER is increased by
1.
4. When the device is repositioned to the first available line of a new page,
LINAGE-COUNTER is reset to 1.
When this phrase is omitted, automatic line advancing is provided, as if the user
had written AFTER ADVANCING 1 LINE.
END-OF-PAGE Phrase
When END-OF-PAGE is specified, and the logical end of the printed page is
reached during execution of the WRITE statement, the END-OF-PAGE imperative-
statement is executed. When the END-OF-PAGE phrase is specified, the FD entry
for this file must contain a LINAGE clause.
The logical end of the printed page is specified in the associated LINAGE clause.
An END-OF-PAGE condition is reached when execution of a WRITE
END-OF-PAGE statement causes printing or spacing within the footing area of a
page body. This occurs when execution of such a WRITE statement causes the
value in the LINAGE-COUNTER special register to equal or exceed the value spec-
ified in the WITH FOOTING phrase of the LINAGE clause. The WRITE statement
is executed, and then the END-OF-PAGE imperative-statement is executed.
Chapter 8. Procedure Division Statements 409
WRITE Statement
An automatic page overflow condition is reached whenever the execution of any
given WRITE statement (with or without the END-OF-PAGE phrase) cannot be
completely executed within the current page body. This occurs when a WRITE
statement, if executed, would cause the value in the LINAGE-COUNTER to exceed
the number of lines for the page body specified in the LINAGE clause. In this case,
the line is printed BEFORE or AFTER (depending on the option specified) the
device is repositioned to the first printable line on the next logical page, as specified
in the LINAGE clause. If the END-OF-PAGE phrase is specified, the
END-OF-PAGE imperative-statement is then executed.
If the WITH FOOTING phrase of the LINAGE clause is not specified, the automatic
page overflow condition exists because no end-of-page condition (as distinct from
the page overflow condition) can be detected.
If the WITH FOOTING phrase is specified, but the execution of a given WRITE
statement would cause the LINAGE-COUNTER to exceed both the footing value
and the page body value specified in the LINAGE clause, then both the end-of-
page condition and the automatic page overflow condition occur simultaneously.
The key words END-OF-PAGE and EOP are equivalent.
Note: The phrases ADVANCING PAGE and END-OF-PAGE must not both be
specified in a single WRITE statement.
END-WRITE Phrase
This explicit scope terminator serves to delimit the scope of the WRITE statement.
END-WRITE permits a conditional WRITE statement to be nested in another condi-
tional statement. END-WRITE may also be used with an imperative WRITE state-
ment.
For more information, see Delimited Scope Statements on page 184.
Multivolume Files
When end-of-volume is recognized for a multivolume OUTPUT file (tape or sequen-
tial direct-access file), the WRITE statement performs the following operations:
The standard ending volume label procedure
A volume switch
The standard beginning volume label procedure.
410 COBOL/400 Reference
WRITE Statement
Indexed and Relative Files
WRITErecord-name-1
FROMidentifier-1
FORMATidentifier-2
IS literal-1
INVALIDimperative-statement-1
KEY
WRITErecord-name-1
FROMidentifier-1
FORMATidentifier-2
IS literal-1
TERMINALidentifier-3
IS literal-2
STARTINGidentifier-4
AT LINE literal-3
1
BEFOREROLLINGidentifier-5 :
AFTER LINES literal-4
LINE
1
: identifier-6UPidentifier-7
THROUGH literal-5 DOWN literal-6 LINES
THRU LINE
INDICATORidentifier-8 END-WRITE
INDICATORS IS
INDIC ARE