System 38 Cobol Userguide Reference
System 38 Cobol Userguide Reference
System/38-Compatible COBOL
User’s Guide and Reference
Note!
Before using this information and the product it supports, be sure to read the general information
under “Notices” on page xv.
This edition applies to the System/38-Compatible feature of the IBM* ILE* COBOL/400* licensed program, (Program
5763-CB1), Version 3 Release 0 Modification 5, and to all subsequent releases and modifications until otherwise indi-
cated 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 may
address your comments to:
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 to IBM" for a description of the methods. This page imme-
diately precedes the Readers' Comment Form at the back of this publication.
When you send information to IBM, you grant IBM a non-exclusive right to use or distribute the information in any way
it believes appropriate without incurring any obligation to you.
Chapter 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
General Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
The Major Features of System/38-Compatible COBOL . . . . . . . . . . . . . . . 1
Language Level Supported by System/38-Compatible COBOL . . . . . . . . . . 1
Federal Information Processing Standard Flagger . . . . . . . . . . . . . . . . . . 2
How the COBOL Program is Organized . . . . . . . . . . . . . . . . . . . . . . . . 4
The COBOL Divisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Section and Paragraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Entries and Sentences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Clauses and Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Characters and Character Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Character Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
COBOL Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
PICTURE Character Strings . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Separators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Format Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Methods of Referencing Data and Procedures . . . . . . . . . . . . . . . . . . . 15
Qualification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Qualification Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Subscripting and Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Identifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Condition-Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Explicit and Implicit References . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Data Attribute Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Procedure Division Data References . . . . . . . . . . . . . . . . . . . . . 19
Transfers of Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Contents v
Sequential File Updating and Extension . . . . . . . . . . . . . . . . . . . . 188
Indexed File Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Indexed File Updating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Relative File Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Relative File Updating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Relative File Retrieval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Contents vii
FILE STATUS Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
I-O-CONTROL Paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
RERUN Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
SAME Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
MULTIPLE FILE TAPE Clause . . . . . . . . . . . . . . . . . . . . . . . . 293
COMMITMENT CONTROL Clause . . . . . . . . . . . . . . . . . . . . . 293
Contents ix
DB-FORMAT-NAME Special Register . . . . . . . . . . . . . . . . . . . . 373
ACCEPT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
Format 1 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
Format 2 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
Format 3 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
Format 4 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
Format 5 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
Programming Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
ACQUIRE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
CLOSE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
COMMIT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
DELETE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
DISPLAY Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
Format 1 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
Format 2 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
DROP Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
OPEN Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
READ Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
REWRITE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
ROLLBACK Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
START Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
WRITE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
Arithmetic Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
Arithmetic Statement Operands . . . . . . . . . . . . . . . . . . . . . . . . . 420
Size of Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
Overlapping Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Multiple Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Common Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
CORRESPONDING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . 422
GIVING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
ROUNDED Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
SIZE ERROR Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
ADD Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
COMPUTE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
DIVIDE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
MULTIPLY Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
SUBTRACT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Data Manipulation Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
INSPECT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
INSPECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
TALLYING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
REPLACING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
BEFORE/AFTER Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . 434
INSPECT Statement Examples . . . . . . . . . . . . . . . . . . . . . . . 435
MOVE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
General Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
Elementary Moves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
Group Moves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
Format 1 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
Format 2 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
SET Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
STRING Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
STRING Statement Processing . . . . . . . . . . . . . . . . . . . . . . . 442
STRING Statement Example . . . . . . . . . . . . . . . . . . . . . . . . . 443
Contents xi
Merge Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
Environment Division–SORT/MERGE . . . . . . . . . . . . . . . . . . . . . . . 492
File-Control Paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
I-O-Control Paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
Data Division–SORT/MERGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
Procedure Division–SORT/MERGE . . . . . . . . . . . . . . . . . . . . . . . . 494
MERGE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494
SORT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
MERGE Statement and SORT Statement Phrases . . . . . . . . . . . . . . 495
ASCENDING/DESCENDING KEY Phrase . . . . . . . . . . . . . . . . . 496
COLLATING SEQUENCE Phrase . . . . . . . . . . . . . . . . . . . . . . 496
USING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
GIVING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
SORT INPUT PROCEDURE Phrase . . . . . . . . . . . . . . . . . . . . 498
SORT/MERGE OUTPUT PROCEDURE Phrase . . . . . . . . . . . . . . 499
SORT or MERGE INPUT/OUTPUT PROCEDURE Control . . . . . . . 500
RELEASE Statement (Sort Function Only) . . . . . . . . . . . . . . . . . . 500
RETURN Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
SORT/MERGE Programming Notes . . . . . . . . . . . . . . . . . . . . . . 501
SEGMENTATION FEATURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
Segmentation Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
Program Segments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
Fixed Segments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
Independent Segments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
Segmentation Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
Segmentation Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
COBOL Source Program Considerations . . . . . . . . . . . . . . . . . . . 505
Segmentation–Environment Division . . . . . . . . . . . . . . . . . . . . 505
Segmentation–Procedure Division . . . . . . . . . . . . . . . . . . . . . . 505
Segmentation–Special Considerations . . . . . . . . . . . . . . . . . . . . . 506
ALTER Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506
PERFORM Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506
SORT and MERGE Statements . . . . . . . . . . . . . . . . . . . . . . . 506
Calling and Called Programs . . . . . . . . . . . . . . . . . . . . . . . . . 507
Inter-Program Communication Function . . . . . . . . . . . . . . . . . . . . . . 507
Inter-Program Communication Concepts . . . . . . . . . . . . . . . . . . . . . 507
Transfers of Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
Common Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
COBOL Language Considerations . . . . . . . . . . . . . . . . . . . . . . 508
Data Division–Inter-Program Communication . . . . . . . . . . . . . . . . . . . 508
Record Description Entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509
Data Item Description Entries . . . . . . . . . . . . . . . . . . . . . . . . . . 509
Procedure Division–Inter-Program Communication . . . . . . . . . . . . . . . 509
CALL Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510
USING Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511
CANCEL Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
EXIT PROGRAM Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 513
STOP RUN Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514
Inter-Program Communication Function Examples . . . . . . . . . . . . . . . 514
OS/400 Graphics Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517
DEBUGGING FEATURES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517
COBOL Source Language Debugging . . . . . . . . . . . . . . . . . . . . . . . 517
Compile-Time Switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
Run-Time Switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
Appendix E. File Structure Support Summary and Status Key Values . 543
Status Key Values and Meanings . . . . . . . . . . . . . . . . . . . . . . . . . 548
Attribute Data Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
Display Device Attribute Data . . . . . . . . . . . . . . . . . . . . . . . . 551
Communications Device Attribute Data . . . . . . . . . . . . . . . . . . . 551
OPEN-FEEDBACK and I-O-FEEDBACK Data Areas . . . . . . . . . . . . . 552
OPEN-FEEDBACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
I-O-FEEDBACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
Contents xiii
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
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-2501.
Changes or additions to the text are indicated by a vertical line (|) to the left of the
addition or change.
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.
Extensions
To help you, IBM provides several extensions to American National Standard (ANS)
COBOL, X3.23-1974. The more significant extensions include:
Chapter 1. Introduction
General Description
COBOL (Common Business Oriented Language) is a programming language that
resembles English. As its name implies, COBOL is especially suited to the proc-
essing of business problems. COBOL can be used to manipulate large files of data
in a relatively simple way. That is, COBOL emphasizes the description and han-
dling of data items and of input/output records.
The notation used within Table 1 on page 2 has the following interpretation:
2 SEG , 2
| | | |
| | | |
| | | |
| | | └--- Highest level available
| | └------- Minimum level required
| └----------- Module identifier
└--------------- Level supported on this system
Elements that are specified in the COBOL source program and that are not included
in 1975 FIPS COBOL are flagged as described in the following sections.
Full FIPS Flagging: When flagging for the full FIPS level, messages are issued for
all elements specified in the source program that are described in messages
CBL85xx.
Low FIPS Flagging: When flagging for the low FIPS level, messages are issued
for all elements specified in the source program that are described in messages
CBL85xx, CBL84xx, CBL83xx, and CBL82xx.
Figure 1 shows the 1974 Standard COBOL processing modules included in each of
the levels of 1975 FIPS COBOL.
High- Low-
1974 ANS Intermediate Intermediate
Module Name Full FIPS FIPS FIPS Low FIPS
Nucleus 2 NUC 1,2 2 NUC 1,2 1 NUC 1,2 1 NUC 1,2
Table Handling 2 TBL 1,2 2 TBL 1,2 1 TBL 1,2 1 TBL 1,2
Sequential I-O 2 SEQ 1,2 2 SEQ 1,2 1 SEQ 1,2 1 SEQ 1,2
Relative I-O 2 REL ,2 2 REL ,2 1 REL ,2 REL ,2
Indexed I-O 2 INX ,2 INX ,2 INX ,2 INX ,2
Sort-Merge 2 SRT ,2 1 SRT ,2 SRT ,2 SRT ,2
Report Writer RPW ,1 RPW ,1 RPW ,1 RPW ,1
Segmentation 2 SEG ,2 1 SEG ,2 1 SEG ,2 SEG ,2
Library 2 LIB ,2 1 LIB ,2 1 LIB ,2 LIB ,2
Debug 2 DEB ,2 2 DEB ,2 1 DEB ,2 DEB ,2
Inter-Program 2 IPC ,2 2 IPC ,2 1 IPC ,2 IPC ,2
Communication
Communications 2 COM ,2 2 COM ,2 COM ,2 COM ,2
Key:
2 SEG , 2
| | | |
| | | └---Highest level available in 1974 ANS COBOL
| | └------Minimum level required by 1974 ANS COBOL
| └---------Module identifier
└------------Level supported
Chapter 1. Introduction 3
HOW THE COBOL PROGRAM IS ORGANIZED
(Section)1
Paragraphs
Entries
The Environment Division:
Sections
Paragraphs
Entries
Clauses
Phrases
The Data Division:
Sections
(Paragraphs)2
Entries
Clauses
Phrases
The Procedure Division:
Sections
Paragraphs
Statements
Phrases.
1 The Identification Division has only one section. It is therefore unnamed, and
the division is composed only of a series of paragraphs.
2 In the Data Division each section has only one paragraph. The paragraph is
therefore unnamed, and each section is composed of a series of entries.
The four divisions and their functions in solving data processing problems are:
Identification Division: The Identification Division names the program and
allows you to optionally provide documentary information such as the date the
program was written and the date it was compiled, as well as to provide other
information such as authorship and security level.
Environment Division: The Environment Division describes the computer(s) to
be used and specifies the machine(s) and equipment features used by the
program. This description defines the relationship of files of data with
input/output devices.
Data Division: The Data Division defines the nature and characteristics of all
data the program is to process; that is, the data used in input/output operations
and any data developed by the program for internal processing.
Procedure Division: The Procedure Division consists of statements that are
able to process the data in the manner you define. The statements are proc-
essed in the order they are placed in the program unless you define another
order.
Specific rules for the elements in these divisions are given in the reference part
of this manual.
Chapter 1. Introduction 5
CHARACTERS AND CHARACTER STRINGS
Phrases
A phrase is an ordered set of one or more consecutive COBOL character strings
that form a portion of a COBOL clause or statement. A phrase can be used to
modify the basic meaning of the clause or statement.
Characters
In System/38-Compatible COBOL, the smallest unit of data is the character.
Fifty-one Extended Binary Coded Decimal Interchange Code ( EBCDIC) characters
form the COBOL character set:
The 26 letters of the alphabet
The 10 Arabic numerals
Fifteen special characters.
Except in comments and nonnumeric literals (which may use any character within
the EBCDIC set), the 51 characters are the only characters valid in a COBOL
program.
IBM Extension
The apostrophe can be used in place of the quotation mark. See “Compiler
Options” on page 37.
Note: Throughout this manual, the quotation mark is used because it is the default
option. In all cases, the apostrophe can be used only if the default option is over-
ridden.
Table 2 shows these COBOL characters in ascending EBCDIC sequence and their
usage in a COBOL program. These single COBOL characters are put together to
form character strings and separators described in the following sections.
Character Strings
A character string is a character or a sequence of consecutive characters. COBOL
character strings form:
Literals
COBOL words
PICTURE character strings
Comments.
Literals
A literal is a character string that has a value exactly the same as the ordered set
of characters of which it is composed or by the specification of a figurative con-
stant. The three types of literals are:
Nonnumeric
Numeric
Boolean.
IBM Extension
Chapter 1. Introduction 7
CHARACTERS AND CHARACTER STRINGS
You must enclose a nonnumeric literal with quotation marks (or apostrophes, if the
APOST option is in effect). The enclosing apostrophes are not part of the literal.
Any punctuation characters included within a nonnumeric literal are part of the
value of the literal. An embedded quotation mark must be represented by two adja-
cent quotation marks (" "); one quotation mark (") is then part of the value of the
literal.
Every nonnumeric literal is in the alphanumeric data category. Data categories are
defined under “PICTURE Clause” on page 332.
The value of a numeric literal is the number 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.
If a literal conforms to the rules for the formation of numeric literals, but is enclosed
in quotation marks, it is a nonnumeric literal.
IBM Extension
COBOL Words
A COBOL word can be:
A user-defined word
A system name
A reserved word.
Any given COBOL word must be capable of being made unique. It can belong to
only one of these classes.
You can not create a user-defined name that is the same as a system name or a
reserved word; also, system names should all be different from reserved words.
The maximum length of a COBOL word is 30 characters.
The hyphen cannot appear as the first or last character in a user-defined word.
Table 3 shows a list of user-defined words, and gives the rules for forming them.
The function of each user-defined word depends on how it is used in a particular
clause or statement.
The function of each system-name is described with the format in which it appears;
each is defined in the glossary.
Chapter 1. Introduction 9
CHARACTERS AND CHARACTER STRINGS
Keywords are words that are required within a given clause, entry, or statement.
There are three types of keywords:
Verbs, such as ADD, READ, WRITE
Required words, which appear in clause, entry, or statement formats, such as
the word USING in the MERGE statement
Words with a specific functional meaning, such as NEGATIVE or SECTION.
Optional words are words that you can include in a clause, entry or statement.
When you omit an optional word, the meaning of the COBOL program is
unchanged.
The conventions used to represent optional words in this manual are described in
“Format Notation” on page 14.
Special registers are compiler-generated storage areas used primarily to store infor-
mation 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. These
special registers include:
IBM Extension
DB-FORMAT-NAME
(See “Common Input/Output Phrases” on page 370 under “Input/Output
Statements” on page 370.)
IBM Extension
When APOST is specified as a compiler option, the figurative constant QUOTE has
the EBCDIC value of an apostrophe.
Chapter 1. Introduction 11
CHARACTERS AND CHARACTER STRINGS
When a figurative constant is used, the word ALL is redundant and is used for
readability only. The figurative constant, ALL literal, cannot be used with the
DISPLAY, INSPECT, STRING, STOP, or UNSTRING statements.
The singular and plural forms of a figurative constant are equivalent, and you can
use them interchangeably. For example, if DATA-NAME-1 is a 5-character data item,
either of the following statements will fill DATA-NAME-1 with 5 spaces:
MOVE SPACE TO DATA-NAME-1.
MOVE SPACES TO DATA-NAME-1.
In any format, you can substitute a figurative constant for a nonnumeric literal;
however, only the figurative constant ZERO (or ZEROS, or ZEROES) can be substituted
for a numeric literal.
IBM Extension
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, the length of the
figurative constant character string is equal to the length of the associated data
item. This rule applies, for example, when you move a figurative constant to or
compare a figurative constant with another item.
When a figurative constant is not associated with another data item, the length
of the character string is one character. This rule applies, for example, in the
DISPLAY, INSPECT, STRING, STOP, and UNSTRING statements.
Comments
A comment is a character string containing any combination of characters from the
EBCDIC set. A comment serves only to document the program to make the
program code more understandable to anyone who might be reading it. Comments
take two forms:
A comment entry in the Identification Division: For a further description of a
comment entry, see “IDENTIFICATION DIVISION” on page 267.
Separators
A separator is a string of one or more punctuation characters or B" when used to
delimit a Boolean literal. A separator can be placed next to another separator, or
next to a character string. The characters that can be used as separators are
shown in Table 4.
Chapter 1. Introduction 13
FORMAT NOTATION
IBM Extension
Format Notation
In COBOL, basic formats are prescribed for the various elements of the language.
In this manual, these formats are presented in a uniform system of notation that is
explained in the following paragraphs. This notation is designed to assist the pro-
grammer in writing COBOL source statements.
Reserved words are printed entirely in CAPITAL LETTERS. These words have
preassigned meanings in COBOL. If any reserved word is misspelled, it is not
recognized as a reserved word and can cause an error in the program. The
two types of reserved words are keywords and optional words.
– Keywords are required by the syntax of the format unless the portion of the
format containing them is optional. In formats, keywords are shown in
UNDERLINED CAPITAL LETTERS. A missing keyword is considered an error in
the program.
– Optional words are included only for readability. They can be included or
omitted without changing the syntax of the program. Optional words are
CAPITALIZED but not underlined.
Words printed in lowercase letters represent information to be supplied by the
user. All such words are defined in the text of this manual.
For easier reference, some user-defined words are followed by a hyphen and a
digit or letter. This suffix does not change the syntactical definition of the word.
Braces ({ }) enclosing listed items indicate (1) that exactly one of the enclosed
stacked items must be specified, and/or (2) when followed by an ellipsis, that
the enclosed unit or item must be specified at least once.
Square brackets ([ ]) indicate that the enclosed item or unit can be used or
omitted, as requested for the program. When two or more items are stacked
within brackets, one or none of them can be specified. When followed by an
ellipsis, the item or unit can be repeated.
The ellipsis (...) indicates that the immediately preceding unit can occur once or
any number of times in succession. A unit can be a single lowercase word or a
group of lowercase words and one or more reserved words enclosed in
brackets and/or braces. When repetition is used, everything enclosed within
the immediately preceding brackets or braces must be repeated.
The arithmetic and logical operators (+, −, <, >, =) that appear in formats are
required although they are not underlined.
All punctuation and other special characters appearing in formats (except
braces, brackets, ellipsis, commas, and semicolons) are required by the syntax
of the format when they are shown; if they are omitted, an error occurs in the
program. Additional punctuation can be specified, according to the punctuation
rules given later in this manual.
The required clauses and (when written) optional clauses must be written in the
sequence shown in the format except where the accompanying text states oth-
erwise.
Comments, restrictions, and clarifications on the use and meaning of every
format are contained in the description following the format.
╔═════════════════════════════════════════════════════════════════╗
║IBM extensions to American National Standard, COBOL, X3.23-1974, ║
║that are part of a command syntax are boxed like this sentence. ║
╚═════════════════════════════════════════════════════════════════╝
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ COBOL clauses and statements that are syntax-checked, but are treated @
@ as documentation by the System/38-Compatible COBOL compiler, are boxed @
@ like this sentence. @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IBM extensions
IBM Extension
IBM extensions to American National Standard (ANS) COBOL, X3.23-1974, that are
part of the text description begin with the paragraph heading, IBM Extension and
are separated from the regular text as is this paragraph. Note that Chapter 5,
“Interactive Processing Considerations and Example Programs” consists only of IBM
extensions; the entire chapter is boxed like this paragraph.
Qualification
If the user-specified name you select is nested within a hierarchy of names, you
can use the same name several times as long as its position within the hierarchy
can be precisely pinpointed. This is done through qualification. Qualification of a
name is the addition, to the name, of all the other names in the hierarchy that make
it possible to precisely pinpoint the name.
To qualify a name, you would place one or more qualifying phrases after the name.
For example: to qualify a name in the Data Division, you could use Format 1; to
qualify a name in the Procedure Division you could use Format 2; and to qualify a
name from a COPY library, you could use Format 3.
Chapter 1. Introduction 15
METHODS OF REFERENCING
Format 1
┌ ┐
{ data-name-1 } │ { OF } │
{ condition-name } │ { IN } data-name-2 │ . . .
└ ┘
Format 2
┌ ┐
paragraph-name │ { OF } section-name │
│ { IN } │
└ ┘
Format 3
┌ ┐
text-name │ { OF } library-name │
│ { IN } │
└ ┘
In the Procedure Division, two identical paragraph-names must not appear in the
same section. A section-name is the highest and only qualifier available for a
paragraph-name.
The following example illustrates the use of identical names in a section hierarchy:
1 FIELD-A
2 FIELD-B
5 SUB1
7 SUB2
2 FIELD-C
7 SUB1
A hierarchy includes all subordinate entries to the next equal or higher level-
number. Therefore, in the above example all entries are in the hierarchy of
FIELD-A. All entries from FIELD-B to, but not including, FIELD-C are in the hierarchy
of FIELD-B.
In any hierarchy, the name associated with the highest level must be unique and
cannot be qualified.
Enough qualification must be specified to make the name unique; however, it may
not be necessary to specify all the levels of the hierarchy. For example, if more
than one file has records that contain the field EMPLOYEE-NO but only one of the files
has a record named MASTER-RECORD, then specifying EMPLOYEE-NO OF
MASTER-RECORD sufficiently qualifies EMPLOYEE-NO. EMPLOYEE-NO OF MASTER-RECORD
OF MASTER-FILE is valid but unnecessary.
Qualification Rules
The following rules for qualification apply:
Each qualifier must be of a successively higher level and must be within the
same hierarchy as the name it qualifies.
The same name must not appear at two levels in a hierarchy unless it can be
qualified.
If a data-name or condition-name is assigned to more than one data item, the
data item must be qualified each time it is referenced, with this exception: in
the REDEFINES clause, qualification is unnecessary and must not be used.
A paragraph-name must not be duplicated within a section. When a
paragraph-name is qualified by a section-name, the word SECTION must not
appear. A paragraph-name need not be qualified when referred to within the
section in which it appears.
Library-name must be unique in the system. Therefore, the first 10 characters
of library-name must be unique.
Text-name (member-name) must be qualified by the file-name and library-name
in which it resides. If no library is specified, the library list @LIBL is searched.
IBM Extension
File-name is optional for the COPY statement, format 1. If file-name is not speci-
fied, the default is QCBLSRC.
Chapter 1. Introduction 17
METHODS OF REFERENCING
Identifier
An identifier is a term used to reflect that a data-name, if not unique in a program,
must be followed by some syntactically correct combination of qualifiers, subscripts,
or indexes sufficient to ensure uniqueness. The general formats for identifiers are
as follows:
Format 1
┌ ┐ ┌ ┌ ┐ ┐
data-name-1 │ { OF } data-name-2 │ ... │ ( subscript-1 │ , subscript-2 [ , subscript-3 ] │ ) │
│ { IN } │ │ └ ┘ │
└ ┘ └ ┘
Format 2
┌ ┐ ┌
data-name-1 │ { OF } data-name-2 │ ... │ ( { index-name-1 [ { } literal-2 ] }
│ { IN } │ │ { literal-1 }
└ ┘ └
┌ ┌ ┐ ┐ ┐
│ { index-name-2 [ { } literal-4 ]} │ { index-name-3 [ { } literal-6 ] } | | ) |
│ , { literal-3 } │ , { literal-5 } │ │ │
└ └ ┘ ┘ ┘
Condition-Name
A condition-name is a user-defined word that is assigned a specific value or range
of values. A condition-name can alternatively be a user-defined word that is
assigned the status of an IBM-defined switch or device.
The format and restrictions on the combined use of qualification, subscripting, and
indexing of condition-names are the same as that for identifiers except that
data-name-1 is replaced by condition-name-1.
For example, the ACCESS MODE clause in the file-control entry need not be specified.
If the clause is omitted, the compiler provides the default value, ACCESS MODE IS
SEQUENTIAL. This clause is then an implicit attribute. If this same attribute, ACCESS
MODE IS SEQUENTIAL, is specified in the COBOL coding, it is an explicit attribute.
An explicit reference occurs when the data-name of the item is written in a COBOL
statement or when the data-name is copied into the program through a COPY state-
ment. An implicit reference occurs when the data-name is referred to by a COBOL
statement without the name being written in that statement.
Chapter 1. Introduction 19
METHODS OF REFERENCING
Transfers of Control
In the Procedure Division, program flow transfers control from statement to state-
ment in the order they are written unless an explicit control transfer is specified or
no next executable statement exists. (See the note below.) This normal program
flow is an implicit transfer of control.
COBOL also provides explicit transfers of control through the running of a procedure
branching or a conditional statement. Lists of procedure branching and conditional
statements are given under “Procedure Division Organization” in Chapter 10, “Pro-
cedure Division.”
Note: The term next executable statement refers to the next COBOL statement to
which control is transferred according to the rules given above. No next executable
statement can follow:
The last statement in a Declarative procedure that is not being run under
control of another COBOL statement.
The last statement in a COBOL program when the paragraph in which it
appears is not being processed under control of another COBOL statement.
System/38 Environment
Since many programs have been written and are meant to run on a System/38, the
AS/400 system has been designed with the ability to emulate a System/38. By
entering the CL command CALL QCL, you access a “System/38 environment”. When
in this environment you can create, compile, run, and process System/38 programs.
Notes:
1. This manual is written from the viewpoint that you are working with
System/38-Compatible COBOL from within the System/38 environment.
2. CL commands referred to in this manual are CL commands used in the
System/38 environment.
To exit from the System/38 environment back into the AS/400 system environment,
you use the F3 key.
These source files should have a record length of 92. However, the
System/38-Compatible COBOL compiler also supports a record length of 102. In
addition to the usual fields of sequence number (6 characters), last modified date (6
characters), and the data (80 characters), a field of 10 characters that can contain
additional information is placed at the end of the record (positions 93-102). This
information is not used by the COBOL compiler, but is placed on the extreme right
of the compiler listing. You are responsible for placing information into this field. If
you want to use the additional field, create a source file with a record length of 102.
COBOL
SEU Source
Program
To call SEU, enter the CL command STRSEU (Start SEU). You can also use the
CL Command EDTSRC (Edit Source) in the System/38 environment with
TYPE(*CBL). SEU internally treats the type as (CBL38). Refer to the SEU for
further information on this editing facility.
You can enter your source program in a batch manner (for example, from
diskettes) by using the OS/400 copy function:
Diskette Copy
Source
Keying
File
Tape S p o o lin g
Refer to the Data Management Guide for more information on how to use the
copy or spooling function for batch entry of the source program.
The COBOL syntax checker finds invalid entries in the source statements and dis-
plays error messages that allow you to correct the errors before compiling the
program. Since the COBOL syntax checker checks only one statement at a time,
independently of statements that precede or follow it, only syntax errors can be
detected. No interrelational errors, such as undefined names and invalid refer-
ences to names, are detected. These errors are detected by the COBOL compiler
when the program is compiled.
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ │
│ EDIT US W:7 Mbr: TESTPRT Scan: ___________________________ │
┌─┼──g FMT CB......-A+++B++++++++++++++++++++++++++++++++++++++++++++++++++++++++Pgm-i │
SEU can display │ │ 7. ENVIRONMENT DIVISION. │
format lines to │ │ 8. CONFIGURATION SECTION. │
help you make i──┤ │ 9. SOURCE-COMPUTER. IBM-S38 │
changes or key in │ │ 1. INPUT-OUTPUT SECTION. │
entries position │ │ 11. FILE-CONTROL. │
by position. │ │ 12. SELECT FILE-1 ASSIGN TO DATABASE-MASTER. │
│ │ 13. SELECT FILE-2 ASSIGN TO DATABASE-MASTER. │
│ │ 14. DATA DIVISION. │
│ │ 15. FILE SECTION. │
└─┼──g FMT CB......-A+++B++++++++++++++++++++++++++++++++++++++++++++++++++++++++Pgm-i │
│ 16. FD FILE-1 │
│ 17. LABEL RECORDS ARE STANDARD │
│ 18. RECORD CONTAINS 2 CHARACTERS │
│ 19. DATA RECORD IS RECORD1. │
│ ....... │
│ @@@@@@@END OF DATA@@@@@@@ │
┌─┼─── │
You can key in │ │ FMT SEQNBR Cont Area-A Area-B │
an entry field i──┤ │ CB ______ _ ______ _______________________________________________________ │
by field in this area. │ │ _______ │
└─┼─── │
│ │
└────────────────────────────────────────────────────────────────────────────────────────┘
Syntax checking for COBOL source functions is subject to the following rules.
Source code on a line with an asterisk (*) or a slash (/) in column 7 is not
syntax checked. An asterisk indicates a comment line, a slash indicates a
comment line and page eject.
Syntax checking occurs line by line as source code is entered. The error mes-
sages that are generated by lines consisting of incomplete statements disap-
pear when the statements are completed. In the example:
ADD A
TO BCD.
an error message is generated after the first line is entered and disappears
after the second line is entered, when the statement is completed.
Any time a source line is entered or changed, up to 45 lines of source may be
syntax checked as one unit. The length of a single unit of syntax checking is
determined by extending from an entered or changed line as follows:
For a complete description of how to enter a source program using SEU, refer to
the SEU.
If sequence numbers are used in the source program, they must be in ascending
order. If sequence numbers are out of sequence, the compiler accepts them in the
order read and generates a warning message.
IBM Extension
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.
┌───────────┬─┬───────┬────────────────────────────────────────
│ │C| │
│SEQUENCE │O| A │ B
├─────┬─────┤N| │
│PAGE SERIAL│T| │
├─────┼─────┼─|───────┼────────────────────────────────────────
│1 3│4 6│7|8 │12 16 2 24 28
├─┬─┬─┼─┬─┬─┼─|─┬─┬─┬─┼─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
│ │ │1│ │1│ │ |I│D│E│N│T│I│F│I│C│A│T│I│O│N│ │D│I│V│I│S│I│O│N│.│
├─┼─┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼┬┼─┼─┼─┼─┼─┼─┼─┼┬┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │2│ │ | │ │ │ │ │&│ │ │ │ │ │ │ │&│ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │3│ │ |E│N│V│I│R│O│N│M│E│N│T│ │D│I│V│I│S│I│O│N│.│ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │4│ │ |C│O│N│F│I│G│U│R│A│T│I│O│N│ │S│E│C│T│I│O│N│.│ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼┬┼─┼─┼─┼─┼─┼─┼─┼┬┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │5│ │ | │ │ │ │ │&│ │ │ │ │ │ │ │&│ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │6│ │ |I│N│P│U│T│-│O│U│T│P│U│T│ │S│E│C│T│I│O│N│.│ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │7│ │ |F│I│L│E│-│C│O│N│T│R│O│L│.│ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼┬┼─┼─┼─┼─┼─┼─┼─┼┬┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │8│ │ | │ │ │ │ │&│ │ │ │ │ │ │ │&│ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │9│ │ |D│A│T│A│ │D│I│V│I│S│I│O│N│.│ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │1│ │ │ |F│I│L│E│ │S│E│C│T│I│O│N│.│ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │1│1│ │ |F│D│ │ │─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼+│ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │1│2│ │ |W│O│R│K│I│N│G│-│S│T│O│R│A│G│E│ │S│E│C│T│I│O│N│.│
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │1│3│ │ | │1│ │ │D│E│S│C│R│I│P│T│I│O│N│ │─┼─┼─┼+│ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │1│4│ │ | │1│ │ │─┼─┼─┼─┼─┼─┼─┼─┼─┼+│ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼┬┼─┼─┼─┼─┼─┼─┼─┼┬┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │1│5│ │ | │ │ │ │ │&│ │ │ │ │ │ │ │&│ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │1│6│ │ |P│R│O│C│E│D│U│R│E│ │D│I│V│I│S│I│O│N│.│ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │1│7│ │ |D│E│C│L│A│R│A│T│I│V│E│S│.│ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼┬┼─┼─┼─┼─┼─┼─┼─┼┬┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │1│8│ │ | │ │ │ │ │&│ │ │ │ │ │ │ │&│ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │1│9│ │ |E│N│D│ │D│E│C│L│A│R│A│T│I│V│E│S│.│ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │2│ │ │ |S│E│C│T│I│O│N│-│N│A│M│E│ │S│E│C│T│I│O│N│.│ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │2│1│ │ |P│A│R│A│G│R│A│P│H│-│N│A│M│E│ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │2│2│ │/| │ │ │ │C│O│M│M│E│N│T│S│.│ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │2│3│ │D| │ │ │ │D│E│B│U│G│-│S│T│A│T│E│M│E│N│T│S│.│ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │&│ │2│4│ │ | │ │ │ │M│O│V│E│ │"│T│E│S│T│"│ │T│O│ │A│.│ │ │ │
└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘
Special Considerations
Some lines in a COBOL program require additional rules. A discussion of each
follows.
Division Header
A division header must be immediately followed by a period except when a USING
phrase is specified with a Procedure Division header. Except for the USING phrase,
no text can appear on the same line.
Section Header
A section header must be immediately followed by a period except when Procedure
Division segment numbers are specified. In the Environment and Procedure Divi-
sions, a section consists of paragraphs. In the Data Division, a section consists of
Data Division entries.
Successive entries or sentences begin in Area B. The entries are either on the
same line as the last entry or sentence, or they are on the next succeeding non-
blank noncomment line.
Successive clauses begin in Area B. The clauses are either on the same line as
the preceding clause, or on the next succeeding nonblank noncomment line.
A level indicator (FD, SD) must begin in Area A and be followed by a space. For a
further description of level indicators, see “Data Division Organization” in
Chapter 9, “Data Division.”
Program Spacing
In writing a COBOL program, rules for indentation, continued lines, comment lines,
debugging lines, and blank lines must be observed.
Indentation
Within an entry or sentence, successive lines in Area B can have the same format
or can be indented to clarify program logic. The output listing is indented only if the
input statements are indented. Indentation does not affect the syntax of the
program. The amount of indentation can be chosen by the user, subject only to the
restrictions on the width of Area B.
Continuation of Lines
Any sentence, entry, clause, or phrase that requires more than one line can be
continued in Area B of the next succeeding noncomment line. The line being con-
tinued is called the continued line; the succeeding lines are continuation lines.
Area A of a continuation line must contain only spaces.
If there is no hyphen in the continuation area (Column 7) of a line, the last char-
acter of the preceding line is assumed to be followed by a space.
If there is a hyphen in the continuation area of a line, the first nonblank character of
this continuation line immediately follows the last nonblank character of the con-
tinued line without any intervening space. However, this restriction does not apply
to nonnumeric literals.
If the continued line contains a nonnumeric literal without a closing quotation mark,
all spaces at the end of the continued line (through Column 72) are considered to
be part of the literal. The continuation line must contain a hyphen in the continua-
tion area, and the first nonblank character in Area B must be a quotation mark.
The continuation of the literal begins with the character immediately following the
quotation mark.
A pair of quotation marks indicating a single quotation mark in the value of the
literal must occur on the same line. Likewise, both characters composing the sepa-
rator == or B" must be on the same line.
Comment Lines
A comment line is any line with an asterisk or slash in the continuation area of the
line. The comment may be written anywhere in Area A and Area B of that line.
The comment may consist of any combination of characters from the EBCDIC set.
If an asterisk is placed in the continuation area, this comment line is printed in the
output listing immediately following the last preceding line.
If the slash is placed in the continuation area, the current page of the output listing
is ejected, and the comment line is printed on the first line of the next page.
The asterisk or slash and the comment are produced only on the output listing.
They are treated as documentation by the compiler.
Successive comment lines are allowed. Each must begin with an asterisk or slash
in the continuation area.
Comment lines are not allowed before the Identification Division header.
Debugging Lines
A debugging line is any line with a D coded in the continuation area. Rules for the
formation of debugging lines are given under “DEBUGGING FEATURES” in
Chapter 11, “Using the Additional COBOL Functions.”
Blank Lines
Blank lines contain nothing but spaces from Column 7 through Column 72. A blank
line may appear anywhere in a program except immediately preceding a continua-
tion line.
Punctuation rules for each division of the COBOL source program follow.
Identification Division
Commas and semicolons can be used in the comment-entries. The PROGRAM-ID
paragraph must end with a period followed by a space.
Environment Division
Commas or semicolons can separate successive clauses and successive operands
within clauses. The SOURCE-COMPUTER, OBJECT-COMPUTER, SPECIAL-NAMES, and
I-O-CONTROL paragraphs must each end with a period followed by a space. In the
FILE-CONTROL paragraph, each file-control entry must end with a period followed by
a space.
Data Division
Commas or semicolons may separate successive clauses and operands within
clauses. File (FD), Sort/Merge file (SD), and data description entries must each end
with a period followed by a space.
Procedure Division
Commas or semicolons may separate successive statements within a sentence and
successive operands within a statement. Each sentence and each procedure must
end with a period followed by a space.
COPY Statement
Prewritten source program entries can be included in a source program at compile
time. Thus, an installation can use standard file descriptions, record descriptions,
or procedures without recoding them. These entries and procedures can be saved
in files. They are included in the source program by means of the COPY statement
which includes them as part of the source program at compile time.
Format 1
┌ ┐
COPY text-name │ { OF } file name [ -library name ] │
│ { IN } │
└ ┘
┌ { } ┐
│ { { ==pseudo-text-1== } { ==pseudo-text-2== } } │
│ REPLACING { , { identifier-1 } BY { identifier-2 } } . . . │ .
│ { { literal-1 } { literal-2 } } │
│ { { word-1 } { word-2 } } │
└ { } ┘
The effect of processing a COPY statement is that the text associated with text-name
is copied into the source program, logically replacing the entire COPY statement
beginning with the word COPY and ending with the period, inclusive. When the
REPLACING phrase is not specified, the text is copied unchanged.
The text-name is the name of the member to be copied. The text-name must begin
with an alphabetic character. The first ten characters of the text-name are used as
the member name; these first ten characters must, therefore, be unique within one
file.
If text-name is not qualified, QCBLSRC is assumed as the file name. If the file
name is not qualified by a library name, it is assumed to reside in a library in the
library list, @LIBL.
The library name , file name , and text-name must follow the rules for forma-
tion of any AS/400 System/38 environment name.
A COPY statement can appear in the source program anywhere that a character-
string or a separator can appear. However, a COPY statement must not be specified
within the resulting copied text. Each COPY statement must be preceded by a
space, and followed by a period and a space.
Comment lines can appear in copied text. Comment lines in text are copied into
the source program unchanged and are interpreted logically as a single space.
Debugging lines can appear in copied text. When a COPY statement is specified on
a debugging line, the copied text is treated as though it appeared on a debugging
line except that comment lines in the text appear as comment lines in the resulting
source program.
The syntactic correctness of the entire COBOL source program cannot be deter-
mined until all COPY statements have been completely processed, because the syn-
tactic correctness of the copied text cannot be independently determined.
Text copied from a member is placed into the same area of the resultant program
as it is in the member. Copied text must conform to the rules for standard COBOL
format.
IBM Extension
Format 2 COPY statements are used to generate COBOL Data Division statements to
describe files that exist on the system.
Note: The use of the term Format 2 COPY statement throughout this manual is
intended as a reference to the COPY statement, DDS or DD format.
Format 2
╔═════════════════════════════════════════════════════════════════════════════════╗
║ ┌ ┐ ┌ ┐ ║
║ { DD-format-name } │ -I │ │ -INDICATOR │ ║
║ COPY { DD-ALL-FORMATS } │ -O │ │ -INDICATORS │ ║
║ { DDS-format-name } │ -I-O │ │ -INDIC │ ║
║ { DDS-ALL-FORMATS } └ ┘ └ ┘ ║
║ ║
║ { OF } file name [ -library name ] ║
║ { IN } ║
║ ║
║ ┌ { } ┐ ║
║ │ { { ==pseudo-text-1== } { ==pseudo-text-2== } } │ ║
║ │ REPLACING { , { identifier-1 } BY { identifier-2 } } . . . │ . ║
║ │ { { literal-1 } { literal-2 } } │ ║
║ │ { { word-1 } { word-2 } } │ ║
║ └ { } ┘ ║
╚═════════════════════════════════════════════════════════════════════════════════╝
For more detailed information about the Format 2 COPY statement see “Externally
Described/Program Described Files” on page 211.
REPLACING Phrase
In the REPLACING phrase, each operand can consist of one of the following:
pseudo-text, an identifier, a literal, or a COBOL word. When the REPLACING phrase
is specified, each operand-1 from the copied text is replaced by its associated
operand-2.
Pseudo-text-1 must not be null; neither can it consist solely of the space character
and/or of comment lines.
and used in conjunction with the COPY statement. If naming conventions are estab-
lished for such common code, then the REPLACING phrase need not be specified. If
the names will change from one program to another, then the REPLACING phrase
can be used to supply meaningful names for this program.
When the REPLACING phrase is specified, the text is copied, and each properly
matched occurrence of operand-1 within the text is replaced by the associated
operand-2.
IBM Extension
When all operands have been compared and no match is found, the leftmost
text word is copied into the source program.
The next successive uncopied text word is then considered the leftmost text
word, and the comparison process is repeated, beginning with the first
operand-1. The process continues until the rightmost copied text word has
been compared.
A comment line occurring in operand-1 and in the copied text is interpreted for
matching purposes as a single space. A comment line appearing in operand-2
is copied unchanged into the source program.
Debugging lines are not permitted in operand-1. Debugging lines, however,
are permitted in copied text and in operand-2. Text words in a debugging line
are matched as if no D appeared in column 7.
Text words after replacement are placed in the source program according to
standard COBOL format rules.
Notes:
1. Arithmetic and logical operators are considered to be text words and can be
replaced only through the pseudo-text phrase.
2. When a figurative constant is operand-1, it will match only exactly as specified.
For example, if ALL "AB" is specified in the copied text, then "ABAB" is not con-
sidered a match. Only ALL "AB" is considered a match.
The user can use the COPY statement in the Data Division of a program as follows:
1 PAYROLL. COPY PAYREC OF PAYFILE.
In this program, the member is then copied. The resulting entry is treated as if it
had been written as follows:
1 PAYROLL.
2 B PIC S99.
2 C PIC S9(5)V99.
2 D PIC S9999 OCCURS 1 TO 52 TIMES
DEPENDING ON B OF A.
To change some (or all) of the names within the member, the user can use the
REPLACING phrase:
In this program, the member is copied. The resulting entry is treated as if it had
been written as follows:
1 PAYROLL.
2 PAY-CODE PIC S99.
2 GROSS-PAY PIC S9(5)V99.
2 D PIC S9999 OCCURS 1 TO 52
TIMES DEPENDING ON
PAY-CODE OF PAYROLL.
The changes shown are made only for this program. The entry as it appears in the
member remains unchanged.
┌───────────┐
│ COBOL │ ┌───────────┐
│ Source ├───────────g COBOL Compiler ┌───────────g │ Executable│
│ Program │ ┌─g l l │ │ COBOL │
│ │ │ │ │ │ │ Program │
└───────────┘ │ │ m │ │ │
│ │ OS/4 │ └───────────┘
│ │ │ ┌─────────────────────────────┐
┌───────────┬─────────┘ │ └────────────g│ Listing │
│ Externally│ │ │ - Command summary │
│ Described │ │ │ - Compiler options │
│ Files │ │ │ - Source listing │
│ │ │ │ - Verb usage │
└───────────┘ ┌─────────┴─┐ │ - Data Division map │
l │ Copy │ │ - FIPS messages │
│ │ Source │ │ - Cross-reference list │
┌─────┴─────┐ │ Text │ │ - Messages │
│ DDS for │ │ │ └─────────────────────────────┘
│ Externally│ └───────────┘
│ Described │
│ Files │
└───────────┘
During compilation, the compiler syntax checks the COBOL source program line by
line as well as checking the interrelationships between the lines.
Compiler Options
You can specify various compiler options either by using the OPTION parameter of
the CRTCBLPGM command or from within the program by using the PROCESS state-
ment. Any options specified in the PROCESS statement override the corresponding
options on the CRTCBLPGM command. The PROCESS statement is discussed later in
this chapter.
All object names specified and entered with the CRTCBLPGM command must be com-
posed of alphanumeric characters, the first of which must be alphabetic. The
length of the names cannot exceed 10 characters. See the CL Reference for a
detailed description of object naming rules and for a complete description of the CL
command syntax.
When the @NOUNREF option is specified, only names that are referenced or are
needed for data structuring are defined. This option is useful when the program
contains many unreferenced identifiers.
n o
CRTCBLPGM Create COBOL Program
Each parameter on the screen displays a default value. Move the cursor past
items where you want the default value to apply. Type over any items where you
want to set a different value or option. Scroll Up to display the next screen of
additional parameters.
n o
CRTCBLPGM Create COBOL Program
Bottom
F3=Exit F4=List F5=Refresh F11=Keywords F12=Previous F13=Prompter help
p q
Figure 7. The Second CRTCBLPGM Prompt Screen
Note: Any CRTCBLPGM command default can be changed by using the CL command
CHGCMDDFT. For more information, refer to the CL Reference.
If these parameter values are acceptable, press ENTER to process the command.
Press F11 from either screen to display the corresponding parameter keywords and
entry fields, as shown below.
n o
CRTCBLPGM Create COBOL Program
Program . . . . . . . . . .
. . PGM @PGMID____
Library . . . . . . . .
. . . QGPL______
Source file . . . . . . . .
. . SRCFILE QCBLSRC___
Library . . . . . . . .
. . . @LIBL_____
Source member . . . . . . .
. . SRCMBR @PGM______
Source listing options . . .
. . OPTION ___________
+ for more values ___________
Generation options . . . . . . . GENOPT ___________
+ for more values ___________
Generation severity level . . . GENLVL 29____
Print file . . . . . . . . . . . PRTFILE QSYSPRT___
Library . . . . . . . . . . . @LIBL_____
FIPS flagging level . . . . . . FIPS @NO
Flagging severity . . . . . . . FLAG _____
User profile . . . . . . . . . . USRPRF @USER_
Public authority . . . . . . . . PUBAUT @NORMAL
More...
F3=Exit F4=List F5=Refresh F11=Choices F12=Previous F13=Prompter help
p q
Figure 8. The First CRTCBLPGM Prompt Screen, Showing Keywords
n o
CRTCBLPGM Create COBOL Program
Bottom
F3=Exit F4=List F5=Refresh F11=Choices F12=Previous F13=Prompter help
p q
Figure 9. The Second CRTCBLPGM Prompt Screen, Showing Keywords
Following are the descriptions of the keywords and the associated parameters and
options. The defaults are underlined.
PGM
Specifies the qualified name by which the compiled COBOL program is known
and the library in which the compiled program is to be located.
@PGMID
The name is taken from the PROGRAM-ID paragraph in the source program.
program-name
The first program in the batch job is to have this name, and all other pro-
grams are to use the name specified in the PROGRAM-ID paragraph in the
source program.
QGPL
The name of the library in which the created program is stored if no library-
name is specified.
library-name
Enter the name of any library in which the created program is to be stored.
SRCFILE
Specifies the name of the library and source file that contains the COBOL source
program to be compiled.
QCBLSRC
The default source file, QCBLSRC, contains the COBOL source to be compiled.
source-file-name
Enter the name of the file that contains the COBOL source program to be
compiled. This source file should have a record length of 92.
@LIBL
The system searches the library list to find the library in which the source file
is located.
library-name
Enter the name of the library where the source file is stored.
SRCMBR
Specifies the name of the member of the source file that contains the COBOL
source program to be compiled. This parameter can be specified only if the
source file name in the SRCFILE parameter is a data base file.
@PGM
Use the name specified by the PGM parameter as the source file member
name. If @PGMID is specified for the PGM parameter, the SRCMBR parameter is
not used. For a data base source file, the first member is used.
source-file-member-name
Enter the name of the member that contains the COBOL source program.
OPTION
Specifies the options to use when the source program is compiled. Any or all of
the following options can be specified in any order.
@NOXREF
Do not produce a cross-reference listing for the source program.
@XREF
Produce a cross-reference listing for the source program.
@GEN
Create an object program.
@NOGEN
Do not create an object program.
@SEQUENCE
Check the reference numbers for sequence errors. Sequence errors do not
occur if the @LINENUMBER option is specified.
@NOSEQUENCE
Do not check reference numbers for sequence errors.
@NOVBSUM
Do not print verb usage counts.
@VBSUM
Print verb usage counts.
@NONUMBER
The source file sequence numbers are used for reference numbers.
@NUMBER
The user-supplied sequence numbers (columns 1 through 6) are used for
reference numbers.
@LINENUMBER
The compiler-generated sequence numbers are used for reference numbers.
This option combines program source code and source code introduced by
COPY statements into one consecutively numbered sequence. Use this option
if you specify FIPS flagging.
@NOMAP
Do not list the Data Division map.
@MAP
List the Data Division map.
@NOOPTIONS
Do not list the options in effect for this compilation.
@OPTIONS
List the options in effect for this compilation.
@QUOTE
Use the quote (") as delimiter for nonnumeric literals and Boolean literals.
This also specifies that the value of the figurative constant QUOTE has the
EBCDIC value of a quote.
@APOST
Use the apostrophe (') as a delimiter for nonnumeric literals and Boolean
literals. This also specifies that the value of the figurative constant QUOTE has
the EBCDIC value of an apostrophe.
GENOPT
Specify the options to use when the object program is created. The listings
produced by this parameter could be required if a problem occurs in COBOL.
Any or all of the options can be specified in any order.
@NOLIST
Do not list IRP and associated hexadecimal code and any error messages.
@LIST
List IRP and associated hexadecimal code and any error messages.
@NOXREF
Do not produce a cross-reference listing of all objects defined in the IRP.
@XREF:
Produce a cross-reference listing of all objects defined in the IRP.
@NOPATCH
Do not reserve space in the compiled program for a program patch area.
PATCH
Reserve space in the compiled program for a program patch area. The
program patch area can be used for debugging purposes.
@NODUMP
Do not list the program template.
@DUMP
List the program template.
@NOATR
Do not list the attributes for the IRP source.
@ATR
List the attributes for the IRP source.
@RANGE
Process run-time checks for subscript ranges, but not index ranges. Checks
are also performed for substring operations in compiler-generated code.
@NORANGE
Do not perform run-time checks.
@UNREF
Unreferenced data items are included in the object program.
@NOUNREF
Unreferenced data items are not included in the object program. This
reduces the number of ODT (Object Definition Table) entries used, allowing a
larger program to be compiled. The unreferenced data items still appear in
the cross-reference listings produced by specifying OPTION(@REF).
@NOOPTIMIZE
The compiler performs only standard optimizations for the program.
@OPTIMIZE
The compiler generates a program for possibly more efficient processing,
which will possibly require less storage. However, specifying @OPTIMIZE can
substantially increase the time required to compile a program.
GENLVL
Specifies whether an object program is to be generated depending on the
severity-level value of errors encountered during compilation. If errors occur in
a program with a severity level greater than the value specified in this param-
eter, an object program is not generated. For example, if you do not want an
object program generated if you have messages with a severity level of 20 or
greater, specify 19 in this parameter.
29
The default severity level if a value is not specified.
severity-level
Enter a two-digit number, 00 through 29.
PRTFILE
Specifies the name of the library and file to contain the compiler listing. The file
should have a minimum record length of 132. If a file with a record length less
than 132 is specified, information is lost.
QSYSPRT
If a file-name is not specified, the compiler listing is directed to the IBM-sup-
plied file, QSYSPRT.
file-name
Enter the name of the file to which the compiler listing is directed.
@LIBL
The system searches the library list, @LIBL, to find the library in which the file
is located.
library-name
Enter the name of the library in which the file is located.
FIPS
The source program is FIPS flagged for the following specified level. (Select the
@LINENUMBER option to ensure that the reference numbers used in the FIPS flag-
ging messages are unique.)
@NO The source program is not FIPS flagged.
@L FIPS flag for low level and higher.
@LI FIPS flag for low-intermediate level and higher.
@HI FIPS flag for high-intermediate level and higher.
@H FIPS flag for high level.
FLAG
Specifies the minimum severity level of messages to be printed.
All messages are to be printed.
severity-level
Enter a two-digit number that specifies the minimum severity level of mes-
sages that are to be printed. Messages that have severity levels of the
specified value or higher are listed.
USRPRF
Specifies under which user profile the compiled COBOL program is to be run.
The profile of either the program owner or the program user is used to run the
program and control which objects can be used by the program (including what
authority the program has for each object).
@USER
The program user’s user profile is to be used when the program is run.
@OWNER:
The user profiles of both the program’s owner and user are to be used when
the program is run. The collective sets of object authority in both user pro-
files are to be used to find and access objects during the program’s run.
Any objects that are created during the program are owned by the program’s
user.
Note: Specify the USRPRF parameter to reflect the security requirements of your
installation. The security facilities available on the AS/400 system are described
in detail in the Security Reference and the CL Reference.
PUBAUT
Specifies what authority for the program and its description is being granted to
the public. The authority can be altered for all or for specified users after
program creation through the GRTOBJAUT (Grant Object Authority) or RVKOBJAUT
(Revoke Object Authority) commands. (For further information on these com-
mands, see the CL Reference.)
@NORMAL
Will be treated like @CHANGE. The public has only operational rights for the
compiled program. Any user can run the program, but cannot change it or
debug it.
@ALL:
The public has complete authorization for the program.
@NONE:
Will be treated like @EXCLUDE. The public cannot use the program.
Note: Specify the PUBAUT parameter to reflect the security requirements of your
installation. The security facilities available on the AS/400 system are described in
detail in the Security Reference. You may also reference the CL Reference.
TEXT
Lets you enter text that briefly describes the program and its function.
@SRCMBRTXT
Indicates that the text for the object being created is to be the same as the
text for the data base file member containing the COBOL source program. If
the source comes from a device or in-line file, specifying @SRCMBRTXT has the
same effect as specifying @BLANK.
@BLANK
No text is specified.
'text'
Enter text that briefly describes the program and its function. It can be a
maximum of 50 characters in length and must be enclosed in apostrophes.
The apostrophes are not part of the 50-character string.
DUMP
An IBM COBOL debugging aid for IBM service personnel.
ITDUMP
An IBM COBOL debugging aid for IBM service personnel.
PROCESS Statement
The PROCESS statement is an optional part of the COBOL source program. It also lets
you specify compile-time options. Options specified in the PROCESS statement over-
ride the corresponding options specified in the CRTCBLPGM command. The following
table illustrates some of the equivalent PROCESS statement options and CRTCBLPGM
CL command parameters and options.
The PROCESS statement must be placed before the first source statement in the
COBOL program immediately preceding the IDENTIFICATION DIVISION header.
Format
PROCESS option-1 [ option-2 ] . . . [ option-n ] [ . ]
The allowable options for the PROCESS statement are listed below. Defaults are
underlined. The descriptions for these options follow the Figure 8 on page 40
under the OPTION and GENOPT parameters.
NOXREF NOOPTIONS
XREF OPTIONS
GEN QUOTE
NOGEN APOST
SEQUENCE NOLIST
NOSEQUENCE LIST
NOVBSUM GENLVL(nn)
VBSUM
NONUMBER FIPS(xx)
NUMBER
LINENUMBER FLAG(nn)
Batch Compiles
The PROCESS statement is used to separate multiple programs and/or subprograms
to be compiled with a single call of the compiler. In the batch compile environment,
all compiler options specified on the CRTCBLPGM command statement, plus all default
options, plus the options specified on the last PROCESS statement will be in effect for
the compilation. All compiler output is directed to the destinations as specified by
the CRTCBLPGM command statement.
All object programs are stored in the library specified on the PGM parameter. If
program-name is specified for the PGM parameter, the first program in the batch job
has that name, and all other programs use the name specified in the PROGRAM-ID
paragraph in the source program.
Compiler options can both precede and follow the COPY statement within the
PROCESS statement. The last encountered occurrence of an option overrides all pre-
ceding occurrences of that option.
The following example shows the use of the COPY statement within the PROCESS
statement. The COPY statement must be followed by a period. Notice also that in
this example, NOMAP overrides the corresponding option in the library member:
1 PROCESS XREF MYPROG
2 COPY DEFLTS. MYPROG
MAP, SOURCE, LIST DEFLTS
4 NOMAP, FLAG(2) MYPROG
1 IDENTIFICATION DIVISION. MYPROG
For complete information on browsing through a compiler listing, see the SEU.
Compiler Output
The result of compiling a program can include:
A summary of command options.
An options listing: A listing of options in effect for the compilation.
A source listing: A listing of the statements contained in the source program.
A verb usage listing: A listing of the COBOL verbs and the number of times
each verb is used.
A Data Division map: A glossary of compiler-generated information about the
data. Also included is a mapping of user-supplied names to compiler-
generated internal names.
FIPS messages: A list of all FIPS messages for the requested FIPS level and
above.
A cross-reference list.
Compiler messages (including diagnostic statistics).
Compilation statistics.
A listing of the generated program in symbolic form.
An object program.
Command Summary
This summary, which is output after compilation, lists all the compiler options speci-
fied in the CRTCBLPGM command statement and as modified by the PROCESS state-
ment.
Source Listing
Figure 11 on page 51 illustrates a source listing. The statements in the source
program are listed exactly as submitted. The source is not listed if the NOSOURCE
option is specified.
All compiler output pages after the page where the PROGRAM-ID paragraph is listed
have the program-id name listed in the heading prior to the date field. Figure 11
on page 51 displays the following fields:
A Compiler-generated statement number: The numbers appear to the
left of the source program listing. These numbers are referenced in
all compiler output listings except for FIPS messages listings. A
statement number can span several lines, and a line can contain
more than one statement.
B Reference number: The numbers appear to the left of the source
statements. The numbers that appear in this field and the column
heading (shown as SEQNBR in this listing) are determined by an
option specified in the CRTCBLPGM command or in the PROCESS state-
ment, as shown in the following table.
VERB COUNT
ADD 1
CLOSE 2
DISPLAY 1
GO 2
IF 1
MOVE 5
OPEN 2
PERFORM 1
READ 1
STOP 1
WRITE 1
@ @ @ @ @ E N D O F V E R B U S A G E @ @ @ @ @
A Alphabetic
AE Alphabetic edited
AN Alphanumeric
ANE Alphanumeric edited
INDEX Index data item (USAGE INDEX)
BOOLN Boolean
ZONED Zoned decimal
PACKED Packed decimal (COMP or COMP-3)
BINARY Binary (COMP-4)
NE Numeric edited
– LABEL information
– RERUN specified is indicated
– SAME AREA specified is indicated
– CODE-SET specified is indicated
– SAME RECORD AREA specified is indicated
– LINAGE specified is indicated.
For data items, the attributes indicate whether the following
information was specified for the item:
– REDEFINES
– VALUE
– JUSTIFIED
– SYNCHRONIZED
– BLANK WHEN ZERO
– SIGN IS LEADING
– SIGN IS LEADING SEPARATE
– SIGN IS SEPARATE
– INDICATORS.
For table items, the dimensions for the item are listed here in
the form dim ( ). For each dimension, a maximum OCCURS
value is given. When a dimension is variable, it is listed as
such, giving the lowest and highest OCCURS values.
STMT LVL SOURCE NAME SECTION DISP LEN TYPE I-NAME ATTRIBUTES
F G H I J K L M N
FIPS Messages
The FIPS messages, Figure 14 on page 55, are listed when the FIPS option is
specified. Only messages for the requested FIPS level and above are listed.
Figure 14 displays the following fields:
Option Heading
NONUMBER DESCRIPTION AND SEQUENCE NUMBERS FLAGGED
NUMBER DESCRIPTION AND USER-SUPPLIED NUMBERS FLAGGED
LINENUMBER DESCRIPTION AND LINENUMBERS FLAGGED
Q Items grouped by level: These headings subdivide the FIPS mes-
sages by level.
R FIPS violations flagged: The total number of FIPS violations
flagged is included at the end of the FIPS listing.
Cross-Reference List
The cross-reference list, Figure 15, is produced when the XREF option is specified.
It provides a list of all data references and procedure-name references, by state-
ment number, within the source program. Figure 15 displays the following fields:
ALPHA 28 49
ALPHABET 27 28
DEPEND 32 5
DEPENDENTS 31 32
@DUMMY-SECTION 46
FIELD-A 23
FILE-1 18 15 46 55 56 57 62
KOUNT 26 47@ 48@ 49 5 54
LOCATION 4
NAME-FIELD 36 49@
NO-OF-DEPENDENTS 42 5@ 59 6@
NUMBR 3 47@ 48@ 51
RECORD-NO 38 51@
RECORD-1 22 21 53@
@STEP-1 46
@STEP-2 48 54
@STEP-3 52 54
@STEP-4 54
@STEP-5 55
@STEP-6 57 61
@STEP-7 59
@STEP-8 62 58
WORK-RECORD 35 52 53 57@
@ @ @ @ @ E N D O F C R O S S R E F E R E N C E @ @ @ @ @
Messages
Figure 16 shows the messages that are generated during program compilation.
The fields displayed are:
STMT
V
X W
@ MSGID: CBL94 SEVERITY: SEQNBR:
Message . . . . : Unexpected source member type. Y
@ 4 MSGID: CBL47 SEVERITY: 2 SEQNBR: 13
Message . . . . : Invalid program-name 'EXMPLE-PROGRAM'. Y
Accepted as 'EXMPLEPRO'.
@ 18 MSGID: CBL65 SEVERITY: SEQNBR: 27
Message . . . . : Blocking/Deblocking for file 'FILE-1' will Y
be performed by compiler-generated code.
Z MESSAGE SUMMARY
TOTAL INFO(-4) WARNING(5-19) ERROR(2-29) SEVERE(3-39) TERMINAL(4-99)
3 2 1
@ @ @ @ @ E N D O F C O B O L M E S S A G E S @ @ @ @ @
3 The statement number and the reference number do not appear on certain messages that reference missing items. For example,
if the member TYPE (CBL38) is not specified, message CBL94 appears on the listing with no statement or reference number listed.
Z Message statistics: This field lists the total number of messages
and the number of messages by severity level.
The totals listed are the number of messages generated for each
severity by the compiler and will not always be the number listed.
For example, if FLAG(1) is specified, no messages of severity less
than 10 are listed. However, the counts will indicate the number
that would have been printed if they had not been suppressed.
A control language CALL statement can be part of a batch job, entered interactively
by a work station user, or included in a CL program. An example of a control lan-
guage CALL statement is CALL PAYROLL. Payroll is the name of a COBOL program
that is called and then run.
A COBOL program can call another program with the COBOL CALL statement (see
Chapter 11, “Using the Additional COBOL Functions”). Another way to run a
COBOL program is through an application-oriented menu. The work station user
can request an application-oriented menu and then select an option that will call the
appropriate program. The following is an example of an application-oriented menu:
n o
PAYROLL DEPARTMENT MENU
4. Return
Option:__
p q
This menu is normally displayed by a control language program in which each
option calls a separate COBOL program. When a COBOL program ends, the
system returns control to whatever called the program. This could be a work
station user, a CL program (such as the menu handling program), or another
COBOL program.
You can also create a command to run a COBOL program by using a command
definition. Refer to the CL Programmer's Guide for information on using the
command definition. For example, you can create a command, PAY, which calls a
program, PAYROLL. A user-created command can be entered into a batch job, or it
can be entered interactively by a work station user.
If a program ends for some reason other than by encountering a STOP statement or
falling through to the end of the program, the return code is set to 2. See the
RTVJOBA and DSPJOB commands in the CL Reference for more information about
return codes.
The OS/400 functions let you test programs while optionally protecting your pro-
duction files, and let you observe and debug operations as a program runs. No
special source code is required for using the OS/400 functions.
Source code is required for using the COBOL Debugging features and formatted
dump capability. A formatted dump can also be obtained by a user’s response to a
run-time message.
On the AS/400 system, you can copy production files into the test library or you can
create special files for testing in this library. A test copy of a file and its production
copy can have the same name if the files are in different libraries. You can use the
same file name in the program for either testing or normal processing.
Normal Environment
┌───────────────────────────────┐
│ │
Job │ Production Library │
┌───────────┐ ┌────┼────+ Production Files────┐ │
│ Program 1 │ │ │ │ │
│ . │ │ │ │ │
│ . │ │ └──────────────────────────┼────┘
│ . │ │ │
│ Program 5─┼───┤ │
│ . │ │ Test Environment │
│ . │ │ ┌──────────────────────────┼────┐
│ . │ │ │ │ │
│ Program 1 │ │ │ Test Library │ │
└───────────┘ └────┼───────+ Test Files F─────┘ │
│ │
│ │
└───────────────────────────────┘
For testing, you must place the test library name ahead of the production library
name in the library list for the job that contains the program to be tested. For
normal processing, the test library should not be named in the library list for that
job.
Testing a Program
┌───Test────┐
│ │
┌──+│ │
│ │ │
│ └───────────┘
Library │
┌───List─────┐ │
│ │ │ Production
┌─Program─┐ │ Test │ │ ┌─Library 1─┐
│ │ │ Library │ │ │ │
│ ├────+│ Production ├─────┼───+│ │
│ │ │ Library 1 │ │ │ │
└─────────┘ │ Production │ │ └───────────┘
│ Library 2 │ │
│ QTEMP │ │
└────────────┘ │ Production
│ ┌─Library 2─┐
│ │ │
└───+│ │
│ │
└───────────┘
No special statements for testing are contained within the program being tested.
The same program being tested can be run normally without modifications. All
testing functions are specified within the job that contains the program and not
within the program.
Testing functions apply only to the job in which they are specified. A program can
be used concurrently in two jobs: one job that is in a test environment and another
job that is in a normal processing environment.
Testing functions of OS/400 let you interact with a program as it runs to observe
the operations being done. These functions include using breakpoints and traces.
Using Breakpoints
A breakpoint is a statement number or a label in your program where you want the
program to stop. If you use a statement number, it should be a statement number
that appears on the compiler listing of the COBOL source program. If you use a
label as a breakpoint rather than a statement number, the label can be:
Associated with a function performed by your COBOL program (for example,
.OPEN indicates the open file function).
An internal COBOL compiler generated label (for example, .L1 indicates
the first internally generated label).
Note: To determine the internally generated labels for your program, use the
GENOPT parameter on the CRTCBLPGM command to get an IRP listing of the program.
For a batch job, a breakpoint program can be called when a breakpoint is reached.
The breakpoint information is passed to the breakpoint program.
CL Commands:
ENTDBG TESTPRT
ADDBKP STMT(43)
ADDBKP STMT(52)
PGMVAR(KOUNT)
The first breakpoint is used to indicate where you are in the program. The following
is displayed as a result of reaching the first breakpoint.
n o
Display Breakpoint
Statement/Instruction . . . . . . . . . : 43 /18
Program . . . . . . . . . . . . . . . . : TESTPRT
Recursion level . . . . . . . . . . . . : 1
n o
Display Breakpoint
Statement/Instruction . . . . . . . . . : 52 /49
Program . . . . . . . . . . . . . . . . : TESTPRT
Recursion level . . . . . . . . . . . . : 1
Start position . . . . . . . . . . . . : 1
Format . . . . . . . . . . . . . . . . : @CHAR
Length . . . . . . . . . . . . . . . . : @DCL
Variable . . . . . . . . . . . . . . . : 5 KOUNT
Type . . . . . . . . . . . . . . . . : PACKED
Length . . . . . . . . . . . . . . . : 2
' 26'
The following example shows how to display a COBOL variable, RECORD-NO, in the
example program. Because the hyphen is treated by OS/400 as a special char-
acter, RECORD-NO must be enclosed in apostrophes.
ENTDBG TESTPRT
ADDBKP STMT(52)
PGMVAR('RECORD-NO')
To display the value of a table element, the appropriate occurrence numbers (sub-
scripts) must be included with the variable name. Up to three dimensions of sub-
scripting are allowed, and the subscripts must be separated by commas.
The following example shows how to specify the COBOL variable TABLE1 with three
dimensions.
One or more blanks are allowed after each comma separating subscripts, but the
total length of the variable plus subscripts, parentheses, commas, and blanks speci-
fied with the PGMVAR keyword cannot exceed 132 characters. For more information
on how to code variables in CL commands, see the CL Reference.
Variable names can be qualified in the PGMVAR parameter, for example, NAME-FIELD
OF WORK-RECORD in Figure 17 on page 64.
Another technique can be used to display variables that are not elements of a
multi-dimensional table. For example, to display the field KOUNT you can use
COBOL Data Division map to find its COBOL internal name (I-NAME).
Next use the IRP cross-reference listing to find the Object Definition Table (ODT)
number for the internal-name. (See “Create COBOL Program Command” on
page 37 and “PROCESS Statement” on page 46 for information on how to obtain
these listings.) Figure 18 shows the Data Division map and Figure 19 on page 68
shows the IRP cross-reference listing for the example program, TESTPRT.
You can use the following CL commands to add a breakpoint to the example
program at statement 52 that will display the variable KOUNT, using the appropriate
ODT number:
ENTDBG TESTPRT
ADDBKP STMT(52)
PGMVAR('/1C8')
n o
Display Breakpoint
Statement/Instruction . . . . . . . . . : 52 /49
Program . . . . . . . . . . . . . . . . : TESTPRT
Recursion level . . . . . . . . . . . . : 1
Start position . . . . . . . . . . . . : 1
Format . . . . . . . . . . . . . . . . : @CHAR
Length . . . . . . . . . . . . . . . . : @DCL
Variable . . . . . . . . . . . . . . . : /1C8
Type . . . . . . . . . . . . . . . . : PACKED
Length . . . . . . . . . . . . . . . : 2
' 26'
The following chart lists breakpoint names and the COBOL functions that they
handle. These breakpoint names can appear in error messages may help you
relate the statement number (field) to the function being performed.
Breakpoint
Name COBOL Function
.CALEXCP ON OVERFLOW exception monitor
.CLOSE Close file
.CNLEXCP CANCEL exception monitor
.CPF54 Page overflow exception monitor
.CTRL Control-Area processing
.DBUGBLD Debug processing table build routine
.DBUGOUT Debug table maintenance code
.DELETE Delete routine
.EXCKRD Called before doing a delete operation or a rewrite operation
.EXFSGN Generic exception monitor
.EXFSnn Exception monitor for file status nn
.EXINVT Device was acquired but not invited
.EXISLD Called before doing a sequential PUT to an indexed file
.EXNOF File or member not found exception monitor
.EXRWRT Called before doing a rewrite operation to an indexed file with
sequential access
.EXSB23 Subfile record not found exception monitor
.EXSB24 Subfile boundary violation exception monitor
.FCEXCP Function check exception monitor
.FEOV Force end of volume
.GET GET
.GETKEY Reads the record by the key value
.GETREL GET relative
.INIT Initialization code and declares
.INIT2 Initialize return pointer
.LSKA Linage control: before advancing page
.LSKB Linage control: after advancing page
.LSPA Linage control: before advancing n lines
.LSPB Linage control: after advancing n lines
.LSTRT Linage initialization
.NOALTR Unaltered GOTO
.OPEN Open file
.PAGING Paging routine
.PRINIT Printer initialization
.PRPUT Printer PUT
.PSPA Print control: before advancing
.PSPB Print control: after advancing
Breakpoint
Name COBOL Function
.PUTALL PUT
.PUTGET PUTGET
.PUTKEY Indexed keyed PUT
.REWRIT Rewrite
.SIZEXCP Internal size error exception monitor
.STARTR Relative I/O start
.STPEXCP STOP RUN exception monitor
.USETEST Save the CFIB address
Using a Trace
A trace is a record of some or all of the statements in a program that were proc-
essed. The trace can, if requested, contain the values of specific variables used in
the statements.
Program Trace
┌─────────────┐ ┌─────────────────────────────────────────┐
│ STATEMENT │ │ Order of Processing Variables │
│ 1 ...... │ │ 1 ───────g ....... │
│ 2 ...... │ │ 6 ───────g ....... │
│ 3 ...... │ │ 7 ───────g ....... │
│ 4 ...... │ │ 8 ───────g ....... │
│ 5 ...... │ │ 6 ───────g ....... │
│ 6 ...... │ │ 7 ───────g ....... │
│ 7 ...... │ │ 2 ───────g ....... │
│ 8 ...... │ │ 6 ───────g ....... │
│ . │ │ 7 ───────g ....... │
│ . │ │ . │
│ . │ │ . │
└─────────────┘ └─────────────────────────────────────────┘
A trace differs from a breakpoint in that a trace ends depending on which state-
ments and how many statements are traced. The system records the traced state-
ments that were processed. You must request a display of the traced information.
The display shows the sequence in which the statements were processed and, if
requested, the values of variables used in the statements.
You specify what statements the system should trace. Also, you might specify that
variables be displayed only when their value changes from the previous time a
traced statement was processed.
The Display Trace Data command is explained in the IBM System/38 Control Lan-
guage Reference Manual.
See “DEBUGGING FEATURES” on page 517 in Chapter 11, “Using the Additional
COBOL Functions” for more information on COBOL Debug and how to use the
switch.
File Status
The following format can be used to transfer data (OPEN-FEEDBACK or I-O-FEEDBACK
areas) associated with an open file to an identifier.
Format
╔══════════════════════════════════════╗
║ ACCEPT identifier FROM mnemonic-name ║
║ ║
║ [ FOR file-name ] ║
╚══════════════════════════════════════╝
See Chapter 10, “Procedure Division” for more information on specifying this state-
ment.
Appendix E, “File Structure Support Summary and Status Key Values” contains a
discussion of the OPEN-FEEDBACK and I-O-FEEDBACK areas. See the System/38 Envi-
ronment Programmer’s Guide/Reference for a layout and description of the data
areas contained in the feedback areas.
Note: Certain values can only occur on a System/38 and are not applicable to the
AS/400 system.
The output for the dump is sent to the IBM-supplied printer file QPPGMDMP.
The formatted dump (reply D) includes the current file information about the files in
the program, contents of fields, data structures, arrays, and tables for user-defined
COBOL data variables.
If you reply with an F option, the dump also includes a list of compiler-generated
fields and their contents.
Both the D option and the F option will dump the first 256 characters of program
variables. Any variable greater than 256 characters will be truncated.
If you do not desire a dump, specify reply C (cancel with no dump). Reply C is also
the default reply for all COBOL inquiry messages that allow a dump to be obtained.
Through the INQMSGRPY parameter, three reply modes for inquiry messages are pos-
sible. The reply modes are:
@RQD — A reply is required.
@DFT — Take the default reply.
@SYSRPL — Search the System Reply List and if the message is found, take the
default action specified in the list. If the message is not found in the System
Reply List, then take the default specified in the message description.
The System Reply List allows you to specify replies for inquiry messages CBE72,
CBE721, CBE723, CBE724, and CBE725. The replies may be specified individually
or generically. This method of replying to inquiry messages is especially suitable
for batch programs, which would otherwise require a console operator to issue
replies.
To see the entries in the System Reply List, specify the Display Reply List CL
command (DSPRPYL). This allows you to change, remove, and add entries to the
System Reply List.
For more information on message reply modes and the System Reply List, see the
CL Programmer's Guide.
The following list describes the areas of Figure 22 on page 77 indicated by letters:
A The exception for which the dump was requested and the location in the
program where the exception occurred.
B The COBOL statement number of the last I-O operation that was processed
before the exception occurred. This information is produced only if at least
one I-O operation has been processed.
C Current information for each file. This information is produced only if the
program has files.
1 File is open
2 File is locked
3 End of file
4 (Not Used)
5 Optional file
6 Check indexed file for duplicates at open
7 End of page
8 (Reserved)
F Previous status code.
G Beginning of Module Global Table (MGT).
H Last exception code.
I Call level of current program.
J Qualified program name and library.
K Beginning of the Program Global Table (PGT).
L Call level of the main COBOL program.
M Job date (YYMMDD).
N Beginning of user fields.
O Invalid zoned field printed in hexadecimal.
A
MCH122 exception in program EXMPLEDUMP in QTEMP at MI instruction number 49 COBOL statement number 55.
B
Last I-O operation was at statement 52.
C
Have changes been made to the user program since the last time it compiled or
ran successfully?
NO YES
Read on, but consider what has been changed. For example, have operating
procedures changed, are new device files being used, or have program
changes been applied recently? A good starting point for problem determi-
nation can be a changed item.
Are you using the current release of the COBOL compiler? The release number is
printed on the first line of the source listing.
YES NO
Install the current release of the compiler and the program changes that apply
to the release, and recompile the program. Refer to the Software Installation,
for an explanation of installing the compiler.
Did the COBOL compiler loop or wait while compiling a user program?
NO YES
A loop or a wait is a seemingly never-ending compilation for which neither
output nor error messages are produced.
For either condition you can (1) enter service mode for the job, (2) request a
dump of the job, and (3) cancel the job. Refer to the Operator’s Quick
Reference, for descriptions of entering service mode, requesting a dump, and
canceling a job.
Use the program stack layout at the beginning of the dump to investigate the
problem.
Did the COBOL user program loop, or wait while it was being run, or produce incor-
rect output?
NO YES
A loop is a sequence of instructions that is processed repeatedly, and a wait
is a situation in which neither output nor error messages are produced.
For either condition you can (1) enter service mode for the job, (2) request a
dump of the job, and (3) cancel the job. Refer to the Operator’s Quick
Reference, for descriptions of entering service mode, requesting a dump, and
canceling a job.
Use the program stack at the beginning of the dump to investigate the
problem. Also check for program logic errors; if the program appears to be
coded correctly, you can use OS/400 debugging functions or COBOL debug-
ging features to pinpoint the problem. For example, you can trace the proc-
essing of certain statements and display the contents of fields at stopping
points in the program. Refer to Chapter 11, “Using the Additional COBOL
Functions” for a description of COBOL debugging features and to “Debugging
Your Program” for an overview of OS/400 debugging functions.
When you isolate the problem to one or more source statements, try to modify
the COBOL source program to circumvent the error and then recompile the
program.
IBM Extension
You might need to refer to other AS/400 manuals for information about a particular
topic in this chapter. They are listed below:
Communications: Advanced Peer-to-Peer Networking Guide, which is intended
for the programmer responsible for defining or using OS/400 Advanced Peer-to-
| Peer Networking* (APPN*). For writing application programs that use OS/400
| advanced program-to-program communications (APPC), see Communications:
| Advanced Program-to-Program Communications Programmer’s Guide.
DDS Reference, which describes the data description specifications (DDS) that
are used for describing files.
Data Management Guide, which contains information about overriding and
copying files, describing display, printer, tape, and diskette files to the system,
as well as spooling and output queues.
In addition, you might need to refer to the following System/38 publications for infor-
mation about a particular topic in this chapter which would pertain to the AS/400
System/38 environment. They are listed below:
IBM System/38 Control Program Facility Programmer's Guide, SC21-7730,
which explains how to use CPF commands and data description specifications.
IBM System/38 Control Language Reference Manual, SC21-7731, which
describes commands and parameters that are used for various CPF functions.
IBM System/38 Control Program Facility Reference Manual, SC21-7806, which
describes the data description specifications that are used for describing files.
IBM System/38 Data Communications Programmer's Guide, SC21-7825, which
describes commands, parameters, and data description specification keywords
that are used for program-to-program and system-to-device communication
functions.
When required, references are made to prior discussions in earlier chapters of this
book, in order to avoid repetition. The language extensions in this chapter are pre-
sented in the following sequence: Environment Division, Data Division, and Proce-
dure Division.
In addition to the field descriptions (such as field names and attributes), the Data
Description Specifications (DDS) for a display device file:
Specify the line number and position number entries for each field and constant
to format the placement of the record on the screen.
Specify attention functions such as underlining and highlighting fields, reverse
image, or a blinking cursor.
Specify validity checking for data entered at the display work station. Validity
checking functions include:
– Detecting fields where data is required
– Detecting mandatory fill fields
– Detecting incorrect data types
– Detecting data for a specific range
– Checking data for a valid entry
– Performing modulus 10 or 11 check digit verification.
Control screen management functions such as when fields are to be erased,
overlaid, or retained when new data is displayed.
Associate indicators 01 through 99 with function keys designated as type CA or
CF. If a function key is designated as CF, both the modified data record and the
response indicator are returned to the program. If a function key is designated
as CA, the response indicator is returned to the program, but the data record
usually contains default values for input-only fields and the values written to the
format for hidden output/input fields.
Assign an edit code (EDTCDE keyword) or edit word (EDTWRD keyword) to a field
to specify how the field’s values are to be displayed.
Specify subfiles.
the program when the program writes a record to a display and pass to the
program when the program reads a record from the display. Output/input fields
are used when the user is to change or update the data that is written to the
display from the program.
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * C U S T OM E R MA S T E R I NQU I R Y F I L E - - C U S M I NQ
A *
A R E F ( CU SMS T P )
A R CU S PMT T E X T ( ' C U S T OM E R P R OM P T ' )
A CA 0 1 ( 1 5 ' E ND OF P R OG R A M ' )
A 1 3 ' C U S T OM E R MA S T E R I NQU I R Y '
A 3 3 ' C U S T OM E R N UMB E R '
A CU S T R I 3 2 0
A 9 9 E R R M S G ( ' C U S T OM E R N UMB E R NO T F OUND +
A P R E S S R E S E T , T H E N E N T E R VAL I D N UMB E +
A R ' 9 9 )
A 5 3 ' U S E F 1 T O E ND P R OG R A M , U S E E N T E R +
A K E Y T O R E T UR N T O P R OM P T SCR E E N '
A R CU S F L D S T E X T ( ' C U S T OM E R D I S P L AY ' )
A CA 0 1 ( 1 5 ' E ND OF P R OG R A M ' )
A OV E R L A Y
A 8 3 ' N AM E '
A N AM E R 8 1 1
A 9 3 ' ADD R E S S '
A ADD R R 9 1 1
A 1 0 3 ' C I T Y '
A C I T Y R 1 0 1 1
A 1 1 3 ' S T A T E '
A S T A T E R 1 1 1 1
A 1 1 2 1 ' Z I P COD E '
A Z I P R 1 1 3 1
A 1 2 3 ' A / R B A L A NC E '
A AR B AL R 1 2 1 7 E D T CD E ( J )
A
A
This display device file contains two record formats: CUSPMT and CUSFLDS.
1 The attributes for the fields in this file are defined in the CUSMSTP field reference file.
2 Function key 1 (CA1) is associated with indicator 15, with which the user ends the program.
3 The ERRMSG keyword identifies the error message that is displayed if indicator 99 is set on in the
program that uses this record format.
4 The OVERLAY keyword is used for the record format CUSFLDS so that the CUSPMT record on the display
will not be erased when the CUSFLDS record is written to the display.
5 The constants such as 'Name', 'Address', and 'City' describe the fields that are written out by the
program.
6 The line and position entries identify where the fields or constants are written on the display.
Figure 23. Example of the Data Description Specifications for a Display Device File
When the program requests an output operation, it passes the output record to
OS/400. OS/400 provides the necessary device control information to display the
record. OS/400 also adds any constant information specified for the record format
when the record is displayed.
When a record passes to a program, the fields are arranged in the order in which
they are specified in the DDS. The order in which the fields are displayed is based
on the display positions (line numbers and positions) assigned to the fields in the
DDS. Therefore, the order in which the fields are specified in the DDS and the
order in which they appear on the screen need not be the same.
Indicators
Indicators are Boolean data items that can have the values B"" or B"1".
When you define a record format for a file using DDS, you decide the options that
are to be controlled by indicators, and the indicators that are to reflect particular
responses.
Indicators can be passed with data records in a record area, or outside the record
area in a separate indicator area.
The number and order of indicators defined in the DDS for a record format for a file
determines the number and order in which the data description entries for the indi-
cators in the record format must be coded in the program.
If a COPY statement, Format 2, is used to copy indicators into a source program, the
indicators are defined in the order in which they are specified in the DDS for the file.
The file control entry for a file that had INDARA specified in its DDS must have the
separate indicator area attribute, SI, as part of the assignment-name in the ASSIGN
clause.
device–file name–SI
file name must refer to a file that has the file level keyword INDARA specified in its
DDS.
WORKSTATION–INVSCRNS–SI
Special Considerations
The special considerations for the clauses used with the Boolean data follow. All
other rules for clauses are the same as those for other data as described under
“Data Description Entry” in Chapter 9, “Data Division”
OCCURS Clause: When the OCCURS clause and the INDICATOR clause are both
specified at an elementary level, a table of Boolean data items is defined with each
element in the table corresponding to an external indicator. The first element in the
table corresponds to the indicator number specified in the INDICATOR clause; the
second element corresponds to the indicator that sequentially follows the indicator
specified by the INDICATOR clause.
then SWITCHES (1) corresponds to indicator 16, SWITCHES (2) corresponds to indi-
cator 17,..., and SWITCHES (10) corresponds to indicator 25.
VALUE Clause: The VALUE clause specifies the initial content of a Boolean data
item. The allowable values for Boolean literals are B"", B"1", and ZERO.
INDICATORS Phrase
When the INDICATORS phrase is used in READ, REWRITE, and WRITE statements (see
Figure 26 on page 100) it specifies which indicators are to be read, rewritten, and
written.
The identifier specified in the INDICATORS phrase can be either of the following:
An elementary Boolean data item
A group item with elementary Boolean data items subordinate to it.
The contents of the identifier are not checked, but are copied to or from the begin-
ning of the record, on a byte by byte basis; indicator numbers are ignored.
If the INDICATORS phrase is omitted, the data in the indicator fields in the record are
still passed in the record area. The INDICATORS phrase is only used to copy indica-
tors into the record area before a WRITE or REWRITE statement, or out of the record
area after a READ statement.
Figure 25 on page 98 shows a program that uses indicators in the record area but
does not use the INDICATORS phrase in any I-O statement. The associated DDS for
the file is shown in Figure 24 on page 97.
Figure 26 on page 100 shows a program that uses indicators in the record area
and the INDICATORS phrase in the I-O statements. The associated DDS for the file is
the same as that shown for the program in Figure 24 on page 97.
Figure 28 on page 103 shows a program that uses indicators in a separate indi-
cator area, defined in WORKING-STORAGE by using the Format 2 COPY statement. The
associated DDS for the file is shown in Figure 27 on page 102.
Figure 29 on page 105 shows a program that uses indicators in a separate indi-
cator area, defined in a table in WORKING-STORAGE. The associated DDS for the file
is the same as that shown for the program in Figure 27 on page 102.
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * D I S P L AY F I L E DD S F OR I ND I CA T OR E X AMP L E S
A *
A R F OR MA T 1 C F 0 1 ( 9 9 ' E ND OF P R OG R A M ' )
A C F 0 5 ( 5 1 ' DA I L Y R E P OR T ' )
A C F 0 9 ( 5 2 ' MO N T H L Y R E P OR T ' )
A *
A 1 0 1 0 ' D E P AR TME N T N UMB E R : '
A D E P T NO 5 I 1 0 3 2
A 2 0 2 6 ' P R OD U C E MO N T H L Y R E P OR T S '
A 0 1 D S P A T R ( B L )
A *
A 2 4 0 1 ' F 5 = DA I L Y R E P OR T '
A 2 4 2 6 ' F 9 = MO N T H L Y R E P OR T '
A 2 4 5 3 ' F 1 = T E RM I NA T E '
A
A
A
1 The INDARA keyword is not used; indicators are stored in the record area with the data fields.
2 One record format, FORMAT1, is specified.
3 Three indicators are associated with three F keys. Indicator 99 will be set on when F key 1 is
pressed, and so on.
4 One field is defined for input.
5 Indicator 01 is defined to cause the associated constant field to blink if the indicator is on.
6 The F key definitions are documented on the work station screen.
Figure 24. Example of a Program Using Indicators in the Record Area without Using the INDICATORS Phrase in the
I-O Statement–Data Description Specifications
1 The separate indicator area attribute, SI, is not coded in the ASSIGN clause.
2 The Format 2 COPY statement, defines data fields and indicators in the record area.
3 Because the file does not have a separate indicator area, response and option indicators are defined
in the order in which they are used in the DDS, and the indicator numbers are treated as documenta-
tion.
4 All indicators used by the program are defined with meaningful names in data description entries in
WORKING-STORAGE. Indicator numbers are omitted here because they have no effect.
5 For each indicator, a meaningful level 88 condition-name is associated with a value for that indicator.
6 Initialize group level to zeros.
7 IN1 in WORKING-STORAGE is set on if it is the first day of the month.
8 Indicators appropriate to output of FORMAT1 are copied to the record area.
9 FORMAT1 is written to the work station screen with both data and indicator values in the record area.
1% The INDICATORS phrase is not necessary because there is no separate indicator area and indicator
values have been set in the record area through the previous MOVE CORRESPONDING statement.
11 FORMAT1, including both data and indicators, is read from the screen.
12 The response indicators for FORMAT1 are copied from the record area to the data description entries
in WORKING-STORAGE.
13 If F key 5 has been pressed, a program call is processed.
Figure 25 (Part 2 of 2). Example of a Program Using Indicators in the Record Area without Using the INDICATORS
Phrase in the I-O Statement
1 The separate indicator area attribute, SI, is not coded in the ASSIGN clause.
2 The Format 2 COPY statement, defines data fields and indicators in the record area.
3 Because the file does not have a separate indicator area, response and option indicators are
defined in the order in which they are used in the DDS, and the indicator numbers are treated as
documentation.
4 All indicators used by the program are defined with meaningful names in data description entries in
WORKING-STORAGE. Indicator numbers are omitted here because they have no effect. Indicators
should be defined in the order needed by the display file.
5 IN1 in WORKING-STORAGE is set on if it is the first day of the month.
6 FORMAT1 is written to the work station screen:
The INDICATORS phrase causes the contents of the variable OPTION-INDICS to be copied to the
beginning of the record area.
Data and indicator values are written to the work station screen.
7 FORMAT1, including both data and indicators, is read from the work station screen.
8 The INDICATORS phrase causes bytes to be copied from the beginning of the record area to
RESPONSE-INDICS.
9 If F key 5 has been pressed, a program call is processed.
Figure 26 (Part 2 of 2). Example of a Program Using Indicators in the Record Area and the INDICATORS phrase in
the I-O Statements
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * D I S P L AY F I L E DD S F OR I ND I CA T OR E X AMP L E S
A *
A I ND A R A
A R F OR MA T 1 C F 0 1 ( 9 9 ' E ND OF P R OG R A M ' )
A C F 0 5 ( 5 1 ' DA I L Y R E P OR T ' )
A C F 0 9 ( 5 2 ' MO N T H L Y R E P OR T ' )
A *
A 1 0 1 0 ' D E P AR TME N T N UMB E R : '
A D E P T NO 5 I 1 0 3 2
A 2 0 2 6 ' P R OD U C E MO N T H L Y R E P OR T S '
A 0 1 D S P A T R ( B L )
A *
A 2 4 0 1 ' F 5 = DA I L Y R E P OR T '
A 2 4 2 6 ' F 9 = MO N T H L Y R E P OR T '
A 2 4 5 3 ' F 1 = T E RM I NA T E '
A
A
A
1 The INDARA keyword is specified, indicators are stored in a separate indicator area, not in the record
area. Except for this specification, the DDS for this file is the same as that shown in Figure 24 on
page 97.
Figure 27. Example of a Program Using Indicators in a Separate Indicator Area, defined in WORKING-STORAGE by
using the Format 2 COPY Statement
1 The separate indicator area attribute, SI, is specified in the ASSIGN clause.
2 The Format 2 COPY statement, generates data descriptions in the record area for data fields only.
The data description entries for the indicators are not generated because a separate indicator area
has been specified for the file.
3 The Format 2 COPY statement, with the INDICATOR attribute, INDIC, defines data description entries in
WORKING-STORAGE for all indicators used in the DDS for the record format for the file.
4 Because the file has a separate indicator area, the indicator numbers used in the data description
entries are not treated as documentation.
5 IN1 in the separate indicator area for FORMAT1 is set on if it is the first day of the month.
6 The INDICATORS phrase is required to send indicator values to the work station screen.
7 The INDICATORS phrase is required to receive indicator values from the work station screen. If F key
5 has been pressed, IN51 is set on.
8 If IN51 has been set on, a program call is processed.
Figure 28 (Part 2 of 2). Example of a Program Using Indicators in a Separate Indicator Area, defined in
WORKING-STORAGE by using the Format 2 COPY Statement
1 The separate indicator area attribute, SI, is specified in the ASSIGN clause.
2 The Format 2 COPY statement, generates fields in the record area for data fields only.
3 A table of 99 Boolean data items is defined in WORKING-STORAGE. The INDICATOR clause for this data
description entry causes these data items to be associated with indicators 1 through 99 respectively.
The use of such a table may result in improved performance as compared to the use of a group item
with multiple subordinate entries for individual indicators; however, you must consider the number of
references and indicators for example, to realize improved performance.
4 A series of data items is defined in WORKING-STORAGE to provide meaningful subscript names with
which to refer to the table of indicators. The use of such data items is not required.
5 INDIC-TABLE (1) in the separate indicator area for FORMAT1 is set on if it is the first day of the
month.
6 The INDICATOR phrase is required to send indicator values to the work station screen.
7 The INDICATOR phrase is required to receive indicator values from the work station screen. If F key 5
has been pressed, INDIC-TABLE (51) is set on.
8 If INDIC-TABLE (51) has been set on, a program call is processed.
Figure 29 (Part 2 of 2). Example of a Program Using Indicators in a Separate Indicator Area, Defined in a Table in
WORKING-STORAGE
Subfiles
Subfiles can be specified in the DDS for a display file or mixed file to allow the user
to handle multiple records of the same type on a display (see Figure 30 on
page 107). A subfile is a group of records that is read from or written to a display
device. For example, a program reads records from a data base file and creates a
subfile of output records. When the entire subfile has been written, the program
sends the entire subfile to a display device in one write operation. The work station
user can change data or enter additional data in the subfile; the program then
reads the entire subfile from the display device into the program and processes
each record in the subfile individually.
Records to be included in a subfile are specified in the DDS for the file. The
number of records that can be contained in a subfile must also be specified in the
DDS. One file can contain more than one subfile; however, only twelve subfiles can
be active concurrently for a device. Twelve subfiles can be displayed on a device
at the same time.
The DDS for a subfile consists of two record formats: a subfile record format and a
subfile control record format. The subfile record format contains the field
descriptions of all the records in the subfile. Specification of the subfile control
record format on the READ or WRITE statement causes the physical read, write, or
setup operations of a subfile to take place. Figure 31 on page 109 shows an
example of the DDS for a subfile record format, and Figure 32 on page 111 shows
an example of the DDS for a subfile control record format.
Note: In a mixed file, the formats used for defining the subfile records and the
subfile control record can be used only in I-O operations to display devices.
n o
Customer Name Search
p q
Figure 30. Subfile Display
To use a subfile for a display file or mixed file in a COBOL program, the SUBFILE
phrase must be specified with the input/output operation. The valid subfile oper-
ations are:
READ SUBFILE file-name RECORD
WRITE SUBFILE record-name
REWRITE SUBFILE record-name.
In COBOL, subfiles can be processed sequentially with the READ SUBFILE NEXT
MODIFIED statement, or processed randomly by specifying a relative key value.
The TRANSACTION file must be an externally described file. In COBOL, all access to
the subfile is done with a relative record number. If the SUBFILE phrases are used
with a TRANSACTION file, the SELECT statement in the Environment Division must
state that ACCESS MODE IS DYNAMIC and must specify the RELATIVE KEY to be used.
If more than one display device is acquired by a display file or mixed file, there is a
separate subfile for each individual display device. If a subfile has been created for
a particular display device acquired by a TRANSACTION file, all input operations that
refer to a record format for the subfile are processed against the subfile belonging
to that device. See the discussions on the TERMINAL phrase later in this chapter for
information about how to determine which device is used. Any operations that ref-
erence a record format name that is not designated as a subfile are processed as
an input/output operation directly to the display device.
Use of Subfiles
Some typical uses of subfiles include:
Display only. The work station user reviews the display.
Display with selection. The user requests more information about one of the
items on the display.
Modification. The user modifies one or more of the records.
Input only, with no validity checking. A subfile is used for a data entry func-
tion.
Input only, with validity checking. A subfile is used for a data entry function,
but the records are checked.
Combination of tasks. A subfile can be used for a display with modification.
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * DD S F OR T H E D I S P L AY D E V I CE F I L E ARC0 1 0D
A * ACCOU N T S R ECE I VAB L E I N T E R AC T I V E P A YME N T UP DA T E
A *
A R S UB F I L E 1 S F L
A T E X T ( ' S UB F I L E F OR C U S T OM E R P A YME N T ' )
A *
A ACP PM T 4A I 5 4 T E X T ( ' ACC E P T P A YME N T ' )
A VAL U E S ( ' * Y E S ' ' * NO ' )
A 5 1 D S P A T R ( R I MD T )
A N 5 1 D S P A T R ( ND P R )
A *
A CU S T 5 B 5 1 5 T E X T ( ' C U S T OM E R N UMB E R ' )
A 5 2 D S P A T R ( R I )
A 5 3 D S P A T R ( ND )
A 5 4 D S P A T R ( P R )
A *
A AMP A I D 8 0 2 B 5 2 4 T E X T ( ' A MO U N T P A I D ' )
A CH ECK ( F E )
A AU T O ( R AB )
A CM P ( G T 0 )
A 5 2 D S P A T R ( R I )
A 5 3 D S P A T R ( ND )
A 5 4 D S P A T R ( P R )
A *
A ECPMSG 3 1A O 5 3 7 T E X T ( ' E X C E P T I ON M E S S AG E ' )
A 5 2 D S P A T R ( R I )
A 5 3 D S P A T R ( ND )
A 5 4 D S P A T R ( B L )
A *
A OV R PM T 8 Y 2O 5 7 0 T E X T ( ' OV E R P A YME N T ' )
A E D T CD E ( 1 )
A 5 5 D S P A T R ( B L )
A 5 6 D S P A T R ( ND )
A *
A S T S CD E 1A H T E X T ( ' S T A T U S COD E ' )
Figure 31 (Part 1 of 2). Data Description Specifications for a Subfile Record Format
The data description specifications (DDS) for a subfile record format describe the records in the subfile:
1 The SFL keyword identifies the record format as a subfile.
2 The line and position entries define the location of the fields on the display.
3 The VALUES keyword specifies that the user can only specify @YES or @NO as values for the ACPPMT
field.
4 The usage entries define whether the named field is to be an output (O), input (I), output/input (B), or
hidden (H) field.
5 The entry CHECK(FE) specifies that the user cannot skip to the next input field without pressing one of
the field exit keys.
6 The entry AUTO(RAB) specifies that data entered into the field AMPAID is to be automatically right-
justified, and the leading characters are to be filled with blanks.
7 The entry CMP(GT ) specifies that the data entered for the field AMPAID is to be compared to zero to
ensure that the value is greater than zero.
8 The EDTCDE keyword specifies the desired editing for output field OVRPMT. EDTCDE(1) indicates that
the field OVRPMT is to be printed with commas, decimal point, and no sign. Also, a zero balance will
be printed and leading zeros will be suppressed.
9 The DSPATR keyword is used to specify the display attributes for the named field when the corre-
sponding indicator status is true. The attributes specified are BL (blink), RI (reverse image), PR
(protect), MDT (set modified data tag), and ND (nondisplay).
Figure 31 (Part 2 of 2). Data Description Specifications for a Subfile Record Format
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
The subfile control record format defines the attributes of the subfile, the search input field, constants, and
command keys. The keywords used indicate the following:
1 SFLCTL identifies this record as a subfile control record and names the associated subfile record
(SUBFILE1).
2 SFLSIZ indicates the total number of records to be included in the subfile (17).
3 SFLPAG indicates the total number of records in a page (17).
4 SFLCLR indicates when the subfile should be cleared (when indicator 61 is on).
5 SFLDSP indicates when to display the subfile (when indicator 62 is on).
6 SFLDSPCTL indicates when to display the subfile control record (when indicator 62 is on).
7 The LOCK keyword prevents the work station user from using the keyboard when the CONTROL1
record format is initially displayed.
8 HELP allows the user to press the Help key and sets indicator 99 on.
9 SFLMSG identifies the constant as a message that is displayed if indicator 99 is on.
In addition to the control information, the subfile control record format also defines the constants to be
used as column headings for the subfile record format.
Figure 32. Data Description Specifications for a Subfile Control Record Format
A display file is capable of having multiple program devices when the MAXDEV
parameter of the CRTDSPF CL command is greater than 1.
A mixed file is capable of having multiple program devices when the MAXPGMDEV
parameter of the CRTMXDF CL command is greater than 1. Once the mixed file has
been created, the required devices must be added to it by means of the
ADDDSPDEVE, the ADDCMNDEVE, and/or the ADDBSCDEVE CL commands.
COBOL determines at run time whether a file is a single device file or a multiple
device file based on whether the file is capable of having multiple devices. The
actual number of devices acquired does not affect whether a file is considered a
single or multiple device file. Determination of whether a file is a single or a mul-
tiple device file is not done at compilation time based on the current description of
the display or mixed file.
For multiple device files, if a particular program device is to be used in an I-O state-
ment, that device is specified by the TERMINAL phrase. The TERMINAL phrase can
also be specified for a single device file.
The following example illustrates the use of multiple device files. The program uses
a mixed file, and is intended to be run in batch mode. The program acquires termi-
nals and invites those terminals via a sign-on screen. After the terminals are
invited, they are polled. If nobody signs on before the wait time expires, the
program ends. If the user enters a valid password, he is allowed to update an
employee file by calling another COBOL program. Once the update is complete, the
device is invited again and the terminals are polled again.
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines *Num ber of sheets per pa d ma y va ry slightly.
D a t a T y p e/ ( b A / P / S / B A / S / X / Y / N / I / W )
C ond itio nin g
Location
And/Or/Comment (A/O/*)
N a m e T y p e ( b / R / K / S //O )
U s a g e/ ( b / O / I / B / H / M )
Co ndition Na me
N am e Length
Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D ec im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A*
A* DD S F OR THE M I XED F I L E MU L T
A*
A R S I GNON I NV I T E
A O 5 / b
/ ' b
20 / b
/ /b /b /b /b /b/b/b/b/b/b/b/ b/ b/ b/ b/ b/ b
/ '
A DSPATR ( R I )
A O 6 / ' b
20 / b/ '
A DSPATR ( R I )
A O 6 / b/ '
38 ' b
A DSPATR ( R I )
The format SIGNON has
A O 7 / ' b
20 / b/ '
the keyword INVITE
A DSPATR ( R I )
a s s oAc i a t e d w i t h i t . T h i s O 7 27 'M D F '
m e aAn s that, if format SIGNON DSPATR ( H I B L )
A O 7 / b/ '
38 ' b
i s u sAe d i n a W R I T E s t a t e m e n t , DSPATR ( R I )
the A
device to which it is O 8 / ' b
20 / b/ '
w r i t iAn g w i l l b e i n v i t e d . DSPATR ( R I )
A O 8 38 ' b/ b/ '
A DSPATR ( R I )
A O 9 / ' /b /b /b /b /b/b/b/b/b/b/b/ b/ b/ b/ b/ b/ b
20 /b/b
/ b
/ '
A DSPATR ( R I )
A O /
20 / ' P L E A S E L OGO N '
20
A DSPATR ( H I )
A P A S S WO R D 1 /0 A I 20/ 4 3D S P A T R ( PC ND )
A W R O NG 2 /0 A O 2 1 4 3
A R UPDA T E
A O 3 5 ' UP DA T E OF P E R S ON N E L F I L E '
A DSPATR ( B L )
A O 7 5 ' T YP E I N E MP L O Y E E N UMB E R +
A TO B E UPDA T ED '
A N UM 7A I 7 4 4D S P A T R ( R I PC )
A R E MP L O Y E E
A O 3 5 ' E MP L O Y E E N UMB E R '
A N UM 7A B 3 2 5D S P A T R ( PC )
A O 5 5 ' E MP L O Y E E N AM E '
A N AM E 3 /0 A B 5 2 5D S P A T R ( PC )
A O 7 5 ' E MP L O Y E E ADD R E S S '
A O 9 5 ' S TR E E T '
A S TRE E T 3 /0 A B 9 2 5D S P A T R ( PC )
A O 1 1 5 ' AP AR T ME N T N UMB E R '
A A P T NO 5A B 1 1 2 5D S P A T R ( PC )
A O 13 5 ' C I T Y '
A C I T Y 2 /0 A B 13 2 5D S P A T R ( PC )
A O 15 5 ' P R OV I NC E '
A P R OV 2 /0 A B 15 2 5D S P A T R ( PC )
A R R E CO V E R Y
A O 3 5 ' THE E MP L O Y E E N UMB E R Y OU +
A HAV E G I VEN I S I NVA L I D '
A O 6 5 ' T YP E Y TO RE TRY '
A O 8 5 ' T YP E N TO E X I T '
A AN SWE R 1X I /
10 5D S P A T R ( R I PC )
A VA L U E S ( ' Y ' ' N ' )
A
A
A
A
A
A
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A *
A * DD S F OR T H E P H Y S I CA L F I L E P A S S WO R D
A *
A UN I QU E
A R P A S S WO R D S
A P A S S K E Y 1 0
A P A S S WO R D 1 0
A K P A S S K E Y
A
A
A
A
A
A
A
A
A
A
A
A
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A *
A * DD S F OR T H E P H Y S I CA L F I L E T E RM
A * WH I C H CON T A I N S T H E L I S T OF T E RM I NA L S
A *
A R T E RM
A T E RM 1 0
A
A
A
A
A
A
A
A
A
A
A
A
A
A
1 ATTR is the mnemonic-name associated with the function-name ATTRIBUTE-DATA. ATTR will be used in
the ACCEPT statement to obtain attribute data for the TRANSACTION file MULTIPLE-FILE. See item 9A.
2 File MULT must have been created using the CRTMXDF CL command, where the ACQPGMDEV parameter
has a value of @NONE and the MAXPGMDEVE parameter has a value greater than 1. The WAITRCD
parameter specifies the wait-time for READ operations on the file. The WAITRCD parameter must have
a value greater than 0. In addition, the required devices must have been added to the file by the
ADDDSPDEVE CL command.
3 MULTIPLE-FS2 is the extended file status for the TRANSACTION file MULTIPLE-FILE. This variable has
been declared in the WORKING-STORAGE section of the program. See item 7.
4 MULTIPLE-CONTROL-AREA is the control area for the TRANSACTION file MULTIPLE-FILE. This variable will
be used to determine which program device was signed on to. See item 15.
5 The data description for MULTIPLE-REC has been defined using the COPY DDS statement. Note that
only the fields which are copied are named fields. Refer to the DDS of this example for comments
regarding the DDS used.
6 Format SIGNON is the format with the INVITE keyword. This is the format that will be used to invite
devices via the WRITE statement.
7 This is the declaration for the extended file-status MULTIPLE-FS2. It is a 4-byte field which is subdi-
vided into a major return code (first two bytes) and a minor return code (last two bytes).
8 STATION-ATTR is the structure which will be used by the ACCEPT statement to hold the attribute data
for the TRANSACTION file MULTIPLE-FILE. See item 9A.
9 In this statement the extended file status MULTIPLE-FS2 is being written.
9A This is an example of accepting attribute-data for the TRANSACTION file MULTIPLE-FILE. Because we
are not interested in a specific program device, but rather the last program device used, the FOR
phrases are not used with the ACCEPT.
1% This statement opens the TRANSACTION file MULTIPLE-FILE. Since the ACQPGMDEV parameter of the
CRTMXDF command has the value @NONE, no program devices are implicitly acquired during this open.
11 This statement acquires the program device contained in the variable LIST-OF-TERMINALS (COUNTER),
for the TRANSACTION file MULTIPLE-FILE.
12 This WRITE statement is inviting the program device specified in the TERMINAL phrase. We know it is
inviting the program device because the format SIGNON has the DDS keyword INVITE associated with
it. Refer to item 13.
13 This READ statement will read from any invited program device. See item 12. If the wait time
expires before anyone inputs to the invited devices, the extended file status will be set to “0310” and
processing will continue. See item 14.
14 In this statement, the extended file status for MULTIPLE-FILE is being checked to see if the wait-time
expired.
15 The program device name stored in the control area is used to determine which program device was
signed on to. See item 4.
16 This DROP statement detaches the program device contained in the variable LIST-OF-TERMINALS from
the TRANSACTION file MULTIPLE-FILE.
Figure 33 (Part 10 of 10). Example of the Use of Multiple Device Files
Packed or binary data (COMP, COMP-3, or COMP-4) should not be sent to a display
station as output data. Such data can contain display station control characters
which can cause unpredictable results.
Environment Division
File-Control Entry
The TRANSACTION file must be named by a file-control entry in the FILE-CONTROL par-
agraph. This entry also specifies other information related to the file.
Format
╔══════════════════════════════════════════════════════════════════╗
║ SELECT file-name ║
║ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ║
║ ASSIGN TO assignment-name-1 @ [ , assignment-name-2 ] ... @ ║
║ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ║
║ ║
║ ORGANIZATION IS TRANSACTION ║
║ ║
║ ┌ ┐ ║
║ │ ACCESS MODE IS { SEQUENTIAL } │ ║
║ │ { DYNAMIC, RELATIVE KEY IS data-name-3 } │ ║
║ └ ┘ ║
║ ║
║ ┐ ║
║ [ FILE STATUS IS data-name-1 { , data-name-5 } │ ║
║ ┘ ║
║ ║
║ [ CONTROL-AREA is data-name-6 ] . ║
╚══════════════════════════════════════════════════════════════════╝
ASSIGN Clause
The ASSIGN clause associates the TRANSACTION file with a display file, communi-
cations file, BSC file, or mixed file through the use of assignment-name-1.
Format
┌ ┐
device │ – file name [ – attribute ] │
└ ┘
Device specifies the type of device associated with the file. The value must be
WORKSTATION.
Attribute specifies the file level option for a separate indicator area, SI. See
“Indicators” on page 92 earlier in this chapter.
ORGANIZATION Clause
The ORGANIZATION clause specifies the logical structure of a file. TRANSACTION
organization signifies interaction between a COBOL program and either a work
station user or another system.
In some cases, all records are homogenous; that is, a logical transaction is com-
pleted with one exchange of records. In other situations, a series of records is
passed back and forth in a logical progression with various record types either
being selected by the initiator or as part of the processing based on input data
values.
For files with TRANSACTION organization, the access mode can be SEQUENTIAL or
DYNAMIC.
When ACCESS IS DYNAMIC is specified, records in the file can be accessed sequen-
tially or randomly, depending on the form of the specific input/output request.
Random accessing of a TRANSACTION file is only valid if subfile processing is being
processed. For subfile processing, ACCESS IS DYNAMIC must be specified.
Data-name-5 identifies the extended file status data item, which contains major and
minor return codes. These major and minor return codes can, in some cases, indi-
cate I-O errors when the file status code does not.
CONTROL-AREA Clause
The CONTROL-AREA clause specifies device dependent and system dependent infor-
mation that is used to control input/output operations for TRANSACTION files.
1 data-name-6.
2 data-name-12 PIC X(2).
(Function key feedback field)
2 data-name-11 PIC X(1).
(Program device name)
2 data-name-10 PIC X(1).
(Record format)
The data items associated with data-name-6 must be 2, 12, or 22 characters long.
Based upon this length, the compiler assumes the availability of key feedback
bytes, the program device name, and record format.
Note: For a mixed file, the actual name of a device may be different than the
program device name (data-name-11).
Information is moved into data-name-6 for each READ operation from a file that has
been assigned to a WORKSTATION device type. The information is valid only if the
READ operation is successfully completed (provided the wait time has not expired).
Enter key
1-24 Function keys 1 through 24
9 Roll Up key
91 Roll Down key
92 Print key
93 Help key
94 Clear key
95 Home key
99 Undefined
Any function keys for which feedback information is desired must be defined for
the display file or mixed file using DDS. The Print key must also be optioned by
a response indicator before feedback information can be provided in the func-
tion key field of the CONTROL-AREA data-name.
TERMINAL-ID: The program device name.
FORMAT-NAME: The DDS record format name that was referenced by the last I-O
statement processed.
Data Division
Format
╔══════════════════════════════════════════════════════════════════════╗
║ ┌ ║
║ │ FD file-name ║
║ └ ║
║ ║
║ ┌ ┐ ║
║ │ RECORD CONTAINS [ integer-3 TO ] integer-4 CHARACTERS │ ║
║ └ ┘ ║
║ ║
║ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ║
║ @ LABEL { RECORD IS } { OMITTED } @ ║
║ @ { RECORDS ARE } { STANDARD } @ ║
║ @ @ ║
║ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ║
║ ║
║ ┌ ┐ ║
║ │ DATA { RECORD IS } data-name-3 [ , data-name-4 ] . . . │ . ║
║ │ { RECORDS ARE } │ ║
║ └ ┘ ║
║ ║
║ ┐ ║
║ { record-description-entry } . . . │ ║
║ ┘ ║
╚══════════════════════════════════════════════════════════════════════╝
The LABEL RECORDS clause specifies whether or not labels are present. This clause
is required in every file description entry. This clause is syntax-checked, but is
treated as documentation.
The RECORD CONTAINS clause and the DATA RECORDS clause are described in
Chapter 9, “Data Division.”
Procedure Division
See Appendix E, “File Structure Support Summary and Status Key Values” for a
file structure support summary.
ACCEPT Statement
The ACCEPT statement retrieves information (attribute data) about a particular
program device associated with a TRANSACTION file.
This format of the ACCEPT statement may only be used for files with an organization
of TRANSACTION. If the file is not open at the time the ACCEPT statement is proc-
essed, processing stops and message CBE725 is issued and the program stops
running. Mnemonic-name must be associated with the function-name
ATTRIBUTE-DATA in the SPECIAL-NAMES paragraph.
If file-name is not specified, the default file for the ACCEPT statement is the first
TRANSACTION file specified in a SELECT clause of the FILE-CONTROL paragraph.
If both FOR phrases are omitted (indicating the default TRANSACTION file is being
used) the ACCEPT statement uses the program device from which a READ, WRITE,
REWRITE, or ACCEPT (Attribute Data) operation on the default file was most recently
processed. If the only prior operation on the file was an OPEN, the ACCEPT statement
uses the program device implicitly acquired by the file when the file was opened.
When both FOR phrases are omitted, a program device must have been acquired in
order to use this format of the ACCEPT statement.
Program device attributes are moved into identifier-1 from the appropriate attri-
bute data format, according to the rules for a group MOVE without the CORRESPONDING
phrase.
The ATTRIBUTE-DATA mnemonic name can be used only to obtain information about
a program device acquired by a TRANSACTION file. Attribute data does not provide
information about the status of a completed or attempted I-O operation. To obtain
information about I-O operations, use the Format 3 ACCEPT statement with the
I-O-FEEDBACK or OPEN-FEEDBACK mnemonic names. For more information about
these mnemonic names, see “ACCEPT Statement” on page 373.
ACQUIRE Statement
The ACQUIRE statement acquires a program device for a TRANSACTION file.
Format
╔══════════════════════════════════════╗
║ ACQUIRE { identifier } FOR file-name ║
║ { literal } ║
╚══════════════════════════════════════╝
File-name must be the name of a file with an organization of TRANSACTION, and the
file must be open when the ACQUIRE statement is processed. A compilation error
message is issued if the organization is not TRANSACTION.
Successful completion of the ACQUIRE operation makes the program device avail-
able for input and output operations. If the ACQUIRE is unsuccessful, the file status
value is set to 9H and any applicable USE AFTER EXCEPTION/ERROR procedure is
called.
Only one program device may be implicitly acquired when a file is opened. If a file
is a mixed file, the single implicitly acquired program device is determined by the
ACQPGMDEV parameter of the CRTMXDF CL command. If the file is a display file, the
single implicitly acquired program device is determined by the first entry in the DEV
parameter of the CRTDSPF, CHGDSPF, or OVRDSPF CL command. Additional program
devices must be explicitly acquired. If the file is a communications or BSC file, the
single implicitly acquired device is determined by the DEV parameter of the CRTCMNF,
CRTBSCF, CHGCMNF, CHGBSCF, OVRCMNF, or OVRBSCF CL command. Communications
and BSC files can never acquire multiple program devices.
The ACQUIRE statement can also be used as an aid in recovering from I-O errors.
For more information, see “Transaction File Recovery” on page 257.
CLOSE Statement
The CLOSE statement terminates the processing of files.
Format 2
╔═══════════════════════════════════════╗
║ CLOSE file-name-1 [ WITH LOCK ] ║
║ ║
║ [ file-name-2 [ WITH LOCK ] ] . . . ║
╚═══════════════════════════════════════╝
DROP Statement
The DROP statement releases a program device that has been acquired by a
TRANSACTION file.
Format
╔═════════════════════════════════════╗
║ DROP { identifier } FROM file-name ║
║ { literal } ║
╚═════════════════════════════════════╝
Literal or the contents of identifier indicates the program device name of the
device to be dropped. Literal, if specified, must be non-numeric 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 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 processing 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 reacquired.
The DROP statement can also be used as an aid in recovering from I-O errors. For
more information, see “Transaction File Recovery” on page 257.
OPEN Statement
The OPEN statement initiates the processing of files.
A TRANSACTION file must be opened in the I-O mode. For a further discussion of the
OPEN statement, see “OPEN Statement” on page 389.
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 “ACQUIRE Statement” on page 127.
FORMAT Phrase
The literal or identifier specified must be a character-string of 10 characters or less
in length.
Multiple data records, each with a different format, can be concurrently active for a
TRANSACTION file. If the FORMAT phrase is specified, it must specify a valid format
name that is defined to the system, and the I-O operation must be processed on a
data record of the same format. If the format is an invalid name or if it does not
exist, the FILE STATUS data item, if specified, is set to a value of 9K and the con-
tents of the record area are undefined.
When the FORMAT phrase is not specified, DB-FORMAT-NAME can be used if the file
contains a default record format name. The default value is always moved to the
DB-FORMAT-NAME special register.
INDICATORS Phrase
The identifier specified in the INDICATORS phrase must be either an elementary
Boolean data item specified without the OCCURS clause or a group item that has
elementary Boolean data items subordinate to it.
When a data record is read, indicators can be read with it. The indicators can be
used to pass information about the data record and how it was entered into the
user program.
The user determines, when he defines a format using DDS, what functions are to
be controlled by indicators, and which indicator(s) controls a particular function.
SUBFILE Phrase
When the SUBFILE phrase is specified, it indicates that all formats referenced by the
statement are subfiles. When SUBFILE is not specified in a TRANSACTION I-O state-
ment, it indicates that none of the formats referenced by the statement are subfiles.
This information is not verified at compile-time. If it is specified incorrectly, an
incorrect program is generated; when the program is run, the FILE STATUS data
item, if specified, is set to a value of 92 (logic error), and the contents of the record
are undefined.
When SUBFILE is not specified, the RELATIVE KEY data item associated with the file,
if specified, is not referenced or changed by the I-O operation.
When SUBFILE is specified, a RELATIVE KEY data item must be defined for the file.
Its value is referenced, and sometimes changed, by the I-O operation. See each
I-O statement associated with SUBFILE operations for a detailed description of when
and how the RELATIVE KEY data item is changed.
The SUBFILE phrase can be specified only for display files, and for display devices
in a mixed file.
TERMINAL Phrase
When the TERMINAL phrase is specified, it indicates a specific program device is to
be used for a READ, WRITE, or REWRITE operation on a TRANSACTION file.
The TERMINAL phrase can be omitted for I-O operations on single device files, since
the single device is always used.
If the TERMINAL phrase is omitted for an I-O operation on a TRANSACTION file that has
acquired multiple program devices, the program device that last attempted a READ,
WRITE, REWRITE, ACQUIRE, DROP, or ACCEPT (Attribute Data) operation on the file is
used. If the only prior operation on the file was an OPEN, the default program
device used is the program device implicitly acquired by the TRANSACTION file when
the file was opened. A run-time error message occurs if no program device is
acquired when the file is opened.
For a READ statement with both the TERMINAL phrase and the NO DATA phrase speci-
fied, the imperative-statement in the NO DATA phrase is processed only if data is not
immediately available from the program device specified by the TERMINAL phrase.
If the TERMINAL phrase is specified and the data-item or literal has a value of
blanks, the phrase is treated at run time as if it were not specified.
READ Statement
The READ statement makes available a record from a device, using a named format.
If the format is a subfile, the READ statement makes available a specified record
from that subfile.
Format 4 is used only to read a format that is not a subfile. The RELATIVE KEY data
item, if specified in the FILE-CONTROL entry, is not used. The Format 4 READ state-
ment is not valid for a subfile record. However, a Format 4 READ statement for the
subfile control record format must be used to place those subfile records that were
updated on a display into the subfile.
If the data is available, it is returned in the record area. The names of the record
format and the program device are returned in the I-O-FEEDBACK area in the
CONTROL-AREA.
The READ statement is valid only when there are acquired devices for the file. If a
READ is processed and there are no acquired devices, the file status is set to 92
(logic error).
The manner in which the Format 4 READ statement functions depends on:
If the READ is for a single device file or a multiple device file
If a specific program device has been requested through the TERMINAL phrase
If a specific record format has been requested through the FORMAT phrase
If the NO DATA phrase has been specified.
The following chart shows the possible combinations of phrases, and the function
processed for a single device file or a multiple device file. For example, if TERMINAL
is N, FORMAT is N, and NO DATA is N, then the single device is D and multiple device
is A.
Code A–Read From Invited Program Device (Multiple Device Files only)
This type of READ receives data from the first invited program device that has data
available. An invited program device is a work station or communications device
(LU1, BSC, or APPC) that has been invited to send input. Inviting is done by writing to
the program device with a format that has the DDS keyword INVITE specified.
Once an invited program device is actually read from, it is no longer invited. That
program device will not be used for input by another READ statement unless rein-
vited, or unless a READ is directed to it specifying the TERMINAL phrase or FORMAT
phrase.
The record format returned from the program device is determined by the system.
This READ can complete without returning any data in the following cases:
1. There are no invited devices. This is the AT END condition, which occurs when:
There are no invited devices.
For an APPC device, another READ is done after a detach signal is received.
For an LU1 device, the session is terminated by the host.
2. A controlled cancel of the job occurs. This results in a file status value of 9A
and a major-minor return code value of 0309.
3. The NO DATA phrase is omitted and the specified wait time expires. This results
in a file status value of 00 and a major-minor return code value of 0310. The
specified wait time is the value entered on the WAITRCD parameter for the file.
4. The NO DATA phrase is specified and there is no data immediately available
when the READ is processed.
If data is available, it is returned in the record area. The record format is returned
in the I-O-FEEDBACK area and in the CONTROL-AREA.
A compilation time message is issued and the NO DATA phrase is ignored. See the
table entry for the same combination of phrases with the NO DATA phrase omitted.
4 If the phrase is specified and the data item or literal is blank, the phrase is treated at run time as if it were not specified.
This function of the READ statement never causes program processing to stop and
wait until data is available. Either the data is immediately available or the NO DATA
imperative-statement is processed.
This READ function can be used to periodically check if data is available from a par-
ticular program device (either the default program device or one specified by the
TERMINAL phrase). This checking for data is done in the following manner:
1. The program device is determined as follows:
a. If the TERMINAL phrase was omitted or contains blanks, the default program
device is used. The default program device is the one used by the last
attempted READ, WRITE, REWRITE, ACQUIRE, or DROP statement. If none of the
above I-O operations were previously processed, the default program
device is the first program device acquired.
b. If the TERMINAL phrase was specified, the indicated program device is used.
2. A check is done to determine if data is available and if the program device is
invited.
3. If data is available, that data is returned in the record area and the program
device is no longer invited. If no data is immediately available, the NO DATA
imperative-statement is processed and the program device remains invited.
4. If the program device is not invited, the AT END condition exists and the file
status is set to 10.
This READ always waits for data to be made available. Even if the job receives a
controlled cancel, or a WAITRCD time is specified for the file, the program will never
regain control from the READ statement. This READ operation is processed in the
following manner:
1. The program device is determined as follows:
a. If the TERMINAL phrase is omitted or contains a blank value, the default
program device is used. The default program device is the program device
used by the last attempted READ, WRITE, REWRITE, ACQUIRE, DROP or ACCEPT
(Attribute Data) statement. If none of these operations has been done, the
program device implicitly acquired when the file was opened is used. If
there are no acquired devices, the AT END condition exists.
b. If the TERMINAL phrase is specified, the indicated program device is used.
2. The record format is determined as follows:
a. If the FORMAT phrase is omitted or contains blanks, the record format
returned is determined by the system.
b. If the FORMAT phrase is specified, the indicated record format is returned. If
the data available does not match the requested record format, a file status
of 9K is set.
3. Program stops running until data becomes available. The data is returned in
the record area after the READ statement is processed. If the program device
was previously invited, it will no longer be invited after this READ statement.
4. The AT END condition can only occur for LU1 or APPC devices. When there are
multiple LU1 or APPC devices acquired for a TRANSACTION file, each individual
device can cause an AT END condition to occur. The AT END condition occurs
when:
For an APPC device, another READ is done after a detach signal is received.
Since a detach signal can be sent with or without data, check the major-
minor return codes to determine if there was any data.
For an LU1 device, the session is terminated by the host.
AT END Phrase
FORMAT Phrase
NO DATA Phrase
When the NO DATA phrase is specified, the READ statement will determine whether
data is immediately available. If data is available, the data is returned in the record
area. If no data is immediately available, imperative-statement-1 is processed.
The NO DATA phrase prevents the READ statement from waiting for data to become
available.
TERMINAL Phrase
If the TERMINAL phrase is omitted for a READ of a TRANSACTION file that has acquired
multiple program devices, the default program device is used. See the general dis-
cussion about the TERMINAL phrase in the “Common Processing Facilities” section
earlier in this chapter for details about how the default program device is deter-
mined.
Format 5 is used only to read a format that is a subfile. The AT END phrase can
only be used when the NEXT MODIFIED phrase is specified. The INVALID KEY
phrase must not be used when the NEXT MODIFIED phrase is specified.
Format 5 cannot be used for communications devices. If the subfile format of the
READ statement is used for a communications device, the READ fails and a file status
of 90 is set.
Random Access of Subfile Records: The NEXT MODIFIED phrase must not be used
to randomly access records in a subfile. The INVALID KEY phrase can only be used
for random access of subfile records.
Sequential Access of Subfile Records: The NEXT MODIFIED phrase must be speci-
fied to access subfile records sequentially. The AT END phrase can only be speci-
fied with the NEXT MODIFIED phrase.
When NEXT MODIFIED is not specified, the data record made available is the record
in the subfile with a relative record number that corresponds to the value of the
RELATIVE KEY data item.
When the NEXT MODIFIED phrase is not specified, and if the RELATIVE KEY data item
contains a value other than the relative record number of a record in the subfile, the
INVALID KEY condition exists and the processing of the READ statement is unsuc-
cessful.
When the NEXT MODIFIED phrase is specified, the record made available is the first
record in the subfile that has been modified (has the Modified Data Tag on).
The value of the RELATIVE KEY data item is updated to reflect the relative record
number of the record made available to the program.
If NEXT MODIFIED is specified and there is no user-modified record in the subfile with
a relative record number greater than the relative record number contained in the
RELATIVE KEY data item, the AT END condition exists. Imperative-statement-2, or
any applicable USE AFTER ERROR/EXCEPTION procedure, if any, is then run.
FORMAT Phrase
When a format-name is not specified, the format used is last record format written
to the display device that contains input fields, input/output fields, or hidden fields.
If no such format exists for the display file, the format used is the record format of
the last WRITE operation to the display device.
The FORMAT phrase should always be specified for multiple format files to ensure
correct results. For more information on the FORMAT phrase, see “Common Proc-
essing Facilities” on page 130.
TERMINAL Phrase
See Format 4 above for general considerations concerning the TERMINAL phrase.
For a Format 5 READ, if the TERMINAL phrase is omitted for a file that has multiple
devices acquired for it, a record is read from the subfile associated with the default
program device. See the general discussion about the TERMINAL phrase in the
“Common Processing Facilities” on page 130 for more details about how the
default program device is determined.
If the RELATIVE KEY data item at the time of the processing of the READ statement
contains a value that does not correspond to a relative record number for the
subfile, the INVALID KEY condition exists and the processing of the READ statement
is unsuccessful.
For a Format 5 READ, the INVALID KEY phrase should be specified if the NEXT
MODIFIED phrase is not specified and there is no applicable USE procedure specified
for the file-name.
If both an INVALID KEY phrase and a USE procedure are specified for the file when
the INVALID KEY condition occurs, control transfers to the INVALID KEY imperative-
statement, and the USE procedure is not run.
AT END Phrase
If NEXT MODIFIED is specified and there is no user-modified record in the subfile, the
AT END condition exists, and the processing of the READ statement is unsuccessful.
The AT END phrase should be specified when the NEXT MODIFIED phrase is used,
and no applicable USE procedure is specified for the file-name. If the AT END
phrase and a USE procedure are both specified for a file, and the AT END condition
arises, control transfers to the AT END imperative statement and the USE procedure
is not run.
For a further discussion of the READ statement (and a related topic, the INTO
phrase), the INVALID KEY phrase, and the AT END phrase, see “READ Statement” on
page 393.
REWRITE Statement
The REWRITE statement is used to replace a subfile record that already exists in the
subfile.
Format 2–TRANSACTION
╔═══════════════════════════════════════════════════╗
║ REWRITE SUBFILE record-name [ FROM identifier-1 ] ║
║ ║
║ FORMAT IS { identifier-2 } ║
║ { literal-1 } ║
║ ║
║ ┌ ┐ ║
║ │ TERMINAL IS { identifier-3 } │ ║
║ │ { literal-2 } │ ║
║ └ ┘ ║
║ ║
║ ┌ ┌ ┐ ┐ ║
║ │ { INDICATOR │ IS │ } │ ║
║ │ { INDICATORS │ ARE │ } identifier-4 │ ║
║ │ { INDIC └ ┘ } │ ║
║ └ ┘ ║
║ ║
║ [ INVALID KEY imperative-statement ] ║
╚═══════════════════════════════════════════════════╝
FORMAT Phrase
The record format specified in the FORMAT phrase must be the record format
accessed on the previous read operation. The contents of identifier-2 or
literal-1 must be the name of the subfile format accessed on the previous READ.
For more information on the FORMAT phrase, see “Common Processing Facilities” on
page 130.
TERMINAL Phrase
The TERMINAL phrase indicates which program device’s subfile is to have a record
rewritten. If the TERMINAL phrase is specified, literal-2 or identifier-3 must
refer to a work station that has been acquired by the TRANSACTION file. If literal-2
or identifier-3 contains blanks, the TERMINAL phrase has no effect. The program
device specified by the TERMINAL phrase must have been acquired, either explicitly
or implicitly, and must have a subfile associated with the device.
If the TERMINAL phrase is omitted from a TRANSACTION file that has acquired multiple
program devices, the subfile used is the subfile associated with the last program
device from which a READ of the TRANSACTION file was attempted.
The REWRITE statement cannot be used for communications devices. If the REWRITE
statement is used for a communications device, the operation fails and a file status
of 90 is set.
If, at the time of the rewrite operation, the RELATIVE KEY data item contains a value
that does not correspond to the relative record number of the record from the pre-
vious read operation, the INVALID KEY condition exists.
The INVALID KEY phrase should be specified for files for which an appropriate USE
procedure is not specified. Undesirable results may occur if the INVALID KEY
phrase is not specified, and no USE procedure is specified.
For a further discussion of the REWRITE statement (and the related topic, the FROM
phrase) and the INVALID KEY phrase, see “REWRITE Statement” on page 402.
WRITE Statement
The WRITE statement releases a logical record to the file.
TERMINAL Phrase
The TERMINAL phrase specifies the program devices to which the output record is to
be sent.
If only a single program device was acquired by the TRANSACTION file, the TERMINAL
phrase can be omitted. That program device is always used for the WRITE.
If the TERMINAL phrase is omitted for a WRITE operation to a TRANSACTION file that
has acquired multiple program devices, the default program device is used. See
the general discussion about the TERMINAL phrase in the “Common Processing
Facilities” section earlier in this chapter for details about how the default program
device is determined.
STARTING Phrase
The STARTING phrase specifies the starting line number for the record formats that
use the variable start line keyword. This phrase is only valid for display devices.
The actual line number on which a field begins can be determined from the fol-
lowing equation:
If the value specified for the STARTING phrase is within the screen area, any fields
outside of the screen area are ignored.
To use the STARTING phrase, the DDS record level keyword SLNO(@VAR) must be
specified for the format being written. If the record format does not specify this
keyword, the STARTING phrase is ignored at run time.
The DDS keyword CLRL also affects the STARTING phrase. CLRL controls how much
of the screen is cleared when the WRITE statement is processed.
ROLLING Phrase
The ROLLING phrase allows you to move lines displayed on the work station screen.
All or some of the lines on the screen can be rolled up or down. The lines vacated
by the rolled lines are cleared, and can have another screen format written into
them. This phrase is only valid for display devices.
ROLLING is specified in the WRITE statement that is writing a new format to the work
station screen. You must specify whether the write is before or after the roll, the
range of lines you want to roll, how many lines you want to roll these lines, and
whether the roll operation is up or down.
After lines are rolled, the fields on these lines retain their DDS display attributes, for
example, underlining, but lose their DDS usage attributes, for example, input-
capability. Fields on lines that are written and then rolled (BEFORE ROLLING phrase)
also lose their usage attributes.
If any part of a format is rolled, the entire format loses its usage attributes. If more
than one format exists, only the rolled formats lose their usage attributes.
When you specify the ROLLING phrase, the following general rules apply:
The DDS record level keyword ALWROL must be specified for every record format
written in a WRITE statement containing the ROLLING phrase.
Other DDS keywords mutually exclusive with the ALWROL keyword must not be
used.
Either of the DDS keywords, CLRL or OVERLAY, must be specified for a record
format that is to be written and rolled to prevent the display screen from being
cleared when that record format is written.
All the identifiers and literals must represent positive integer values.
The roll starting line number (identifier-5 or literal-4) must not exceed the
ending line number (identifier-6 or literal-5).
The contents of lines that are rolled outside of the window specified by the
starting and ending line numbers disappear.
Figure 34 on page 143 shows an example of rolling. An initial screen format, FMT1
is written on the work station screen. The program processes this screen format
and is now ready to write the next screen format, FMT2, to the work station screen.
Part of FMT1 is rolled down two lines before FMT2 is written to the work station
screen.
┌─────────────────────────────────────────────────────────────────────┐
│ │
│ UPDATE CUSTOMER ORDER RECORD │ Line 3
│ │
│ │
│ TO END THIS JOB, PRESS F7 KEY │ Line 8
│ │
│ │
│ ENTER YOUR OPERATOR NUMBER: ___ │ Line 13
│ ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── F┐
│ │ Line 14 │
│ ENTER CUSTOMER NUMBER: _____ │ Line 15 │
│ │ │
│ PRESS F3 KEY TO DISPLAY OPTION MENU │ Line 17 ├───┐
│ │ │ │
│ │ │ │
│ │ Line 2 │ │
│ ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── F┘ │
│ │ │
│ │ ┌─────────┘
└─────────────────────────────────────────────────────────────────────┘ │
│
│ These 7 lines of
DISPLAY AFTER PROCESSING THE WRITE STATEMENT └+FMT1 will be
rolled down 2
┌─────────────────────────────────────────────────────────────────────┐ lines.
│ │
│ UPDATE CUSTOMER ORDER RECORD │ Line 3
│ │
│ │
│ TO END THIS JOB, PRESS F7 KEY │ Line 8
│ │
│ │
│ ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── F┐
│ ITEM NUMBER ORDERED: _____ │ Line 12 │
│ │ ├─┐
│ QUANTITY ORDERED: ______ │ Line 14 │ │
│ ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── F┘ │
│ │ │
│ ENTER CUSTOMER NUMBER: XXXXX │ Line 17 │
│ │ │
│ PRESS F3 KEY TO DISPLAY OPTION MENU │ Line 19 │
│ │ │
│ │ ┌───────┘
│ │ │
└─────────────────────────────────────────────────────────────────────┘ │
│ These 3 lines of
└+FMT2 have been
written over the
previous lines.
Processing of the following WRITE statement causes part of FMT1 to be rolled down
two lines, and FMT2 to be written to the work station screen:
WRITE SCREENREC FORMAT "FMT2"
AFTER ROLLING LINES 14 THROUGH 2
DOWN 2 LINES
Format 5 can only be used for display devices. If the subfile form of the WRITE
statement is used for any other type of device, the WRITE operation fails and a file
status of 90 is set.
If the format is a subfile, and SUBFILE is specified, the RELATIVE KEY clause must
have been specified on the SELECT clause for the file being written. The record
written to the subfile is the record in the subfile identified by the format name that
has a relative record number equal to the value of the RELATIVE KEY data item.
TERMINAL Phrase
See Format 4 above for general considerations concerning the TERMINAL phrase.
The TERMINAL phrase specifies which program device’s subfile is to have a record
written to it. If the TERMINAL phrase is specified, literal-2 or identifier-3 must
refer to a work station associated with the TRANSACTION file. If literal-2 or
identifier-3 contains a value of blanks, the TERMINAL phrase is treated as if it was
not specified. The work station specified by the TERMINAL phrase must have been
acquired, either explicitly or implicitly.
If the TERMINAL phrase is omitted, the subfile used is the subfile associated with the
default program device. See the general discussion about the TERMINAL phrase in
the “Common Processing Facilities” section earlier in this chapter for details about
how the default program device is determined.
The INVALID KEY condition exists if a record is already in the subfile with that record
number, or if the relative record number specified is greater than the maximum
allowable subfile record number. The INVALID KEY phrase should be specified in
the WRITE SUBFILE statement for all files for which an appropriate USE procedure is
not specified.
For a further discussion of the WRITE statement, the FROM phrase, and the INVALID
KEY phrase, see “WRITE Statement” on page 412. For information on the FORMAT
phrase, see “Common Processing Facilities” on page 130.
USE Statement
The USE statement specifies procedures for input/output error handling that are in
addition to the standard procedures provided by the input/output control system.
Format
╔════════════════════════════════════════════════════════════╗
║ USE AFTER STANDARD { ERROR } ║
║ { EXCEPTION } ║
║ ║
║ PROCEDURE ON { file-name-1 [ , file-name-2 ] . . . } ║
║ { I-O } . ║
╚════════════════════════════════════════════════════════════╝
See “Declaratives” on page 364 for a further discussion of the USE statement.
Figure 35 on page 146 shows a basic inquiry program that uses the COBOL
TRANSACTION file. The associated DDS for the files is also shown.
The data description specifications (DDS) for the display device file (CUSMINQ) to be
used by this program describe two record formats: CUSPMT and CUSFLDS.
The CUSPMT record format contains the constant 'Customer Master Inquiry', which
identifies the display. It also contains the prompt 'Customer Number' and the input
field (CUST) into which the work station user enters the customer number. Five
underscores appear under the input field CUST on the screen where the user is to
enter the customer number. The error message 'Customer number not found' is
also included in this record format. This message is displayed if indicator 99 is set
on by the program. In addition, this record format defines a function key that the
user can press to end the program. When the user presses function key 01, indi-
cator 15 is set on in the COBOL program. This indicator is then used to end the
program.
The CUSFLDS record format contains the constants 'Name', 'Address', 'City', 'State',
'Zip Code', and 'A/R Balance', which identify the fields to be written out from the
program. This record format also describes the fields that correspond to these con-
stants. All of these fields are described as output fields (blank in position 38)
because they are filled in by the program; the user does not enter any data into
these fields. To enter another customer number, the user presses the Enter key in
response to this record. Notice that the CUSFLDS record is to overlay the CUSPMT
record. Therefore, when the CUSFLDS record is written to the screen, the CUSPMT
record remains on the screen.
In addition to describing the constants, fields, and attributes for the screen, the
record formats also define the line numbers and horizontal positions in which the
constants and fields are to be displayed.
Note: The field attributes are defined in a physical file (CUSMSTP) used for field ref-
erence purposes, instead of in the DDS for the display file.
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * C U S T OM E R MA S T E R I NQU I R Y F I L E - - C U S M I NQ
A *
A R E F ( CU SMS T P )
A R CU S PMT T E X T ( ' C U S T OM E R P R OM P T ' )
A CA 0 1 ( 1 5 ' E ND OF P R OG R A M ' )
A 1 3 ' C U S T OM E R MA S T E R I NQU I R Y '
A 3 3 ' C U S T OM E R N UMB E R '
A CU S T R I 3 2 0
A 9 9 E R R M S G ( ' C U S T OM E R N UMB E R NO T F OUND +
A P R E S S R E S E T , T H E N E N T E R VAL I D N UMB E +
A R ' 9 9 )
A 5 3 ' U S E F 1 T O E ND P R OG R A M , U S E E N T E R
A K E Y T O R E T UR N T O P R OM P T SCR E E N '
A R CU S F L D S T E X T ( ' C U S T OM E R D I S P L AY ' )
A CA 0 1 ( 1 5 ' E ND OF P R OG R A M ' )
A OV E R L A Y
A 8 3 ' N AM E '
A N AM E R 8 1 1
A 9 3 ' ADD R E S S '
A ADD R R 9 1 1
A 1 0 3 ' C I T Y '
A C I T Y R 1 0 1 1
A 1 1 3 ' S T A T E '
A S T A T E R 1 1 1 1
A 1 1 2 1 ' Z I P COD E '
A Z I P R 1 1 3 1
A 1 2 3 ' A / R B A L A NC E '
A AR B AL R 1 2 1 7 E D T CD E ( J )
A
A
Figure 35 (Part 1 of 6). Example of a TRANSACTION Inquiry Program Using a Single Display Device
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * * P H Y S I CA L CU SMS T P C U S T OM E R MA S T E R F I L E
A R CU SMS T T E X T ( ' C U S T OM E R MA S T E R R E CO R D ' )
A CU S T 5 T E X T ( ' C U S T OM E R N UMB E R ' )
A N AM E 2 5 T E X T ( ' C U S T OM E R N AM E ' )
A ADD R 2 0 T E X T ( ' C U S T OM E R ADD R E S S ' )
A C I T Y 2 0 T E X T ( ' C U S T OM E R C I T Y ' )
A S T A T E 2 T E X T ( ' S T A T E ' )
A Z I P 5 0 0 T E X T ( ' Z I P COD E ' )
A S R H COD 6 T E X T ( ' C U S T OM E R N UMB E R S E ARCH COD E ' )
A CU S T Y P 1 0 0 T E X T ( ' C U S T OM E R T Y P E 1 = GO V 2 - SCH +
A 3 = B U S 4 = P V T 5 =O T ' )
A AR B AL 8 0 2 T E X T ( ' ACCOU N T S R EC B A L ANC E ' )
A OR D B A L 8 0 2 T E X T ( ' A / R AM T I N OR D E R F I L E ' )
A L S T AM T 8 0 2 T E X T ( ' L A S T A MO U N T P A I D I N A / R ' )
A L S T DA T 6 0 2 T E X T ( ' L A S T DA T E P A I D I N A / R ' )
A CRD L MT 8 0 2 T E X T ( ' C U S T OM E R CR E D I T L I M I T ' )
A S L S Y R 1 0 0 2 T E X T ( ' C U S T OM E R S AL E S T H I S Y E AR ' )
A S L S L Y R 1 0 0 2 T E X T ( ' C U S T OM E R S AL E S L A S T Y E AR ' )
A K CU S T
The data description specifications (DDS) for the data base file that is used by this program describe one
record format: CUSMST. Each field in the record format is described, and the CUST field is identified as the
key field for the record format.
Figure 35 (Part 2 of 6). Example of a TRANSACTION Inquiry Program Using a Single Display Device
SEQNBR@...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 ...+... 9 ...+...
1 IDENTIFICATION DIVISION.
2 PROGRAM-ID. EXMPLE766.
3 @ EXAMPLE TRANSACTION INQUIRY PROGRAM USING 1 DISPLAY DEVICE
4 AUTHOR. PROGRAMMER NAME.
5 INSTALLATION. TORONTO COBOL DEVELOPMENT CENTRE.
6 DATE-WRITTEN. 8/3/88.
7 DATE-COMPILED. 8/3/88 15:36:14 .
8 ENVIRONMENT DIVISION.
9 CONFIGURATION SECTION.
1 SOURCE-COMPUTER. IBM-S38.
11 OBJECT-COMPUTER. IBM-S38.
12 INPUT-OUTPUT SECTION.
13 FILE-CONTROL.
14 SELECT CUST-DISPLAY
15 ASSIGN TO WORKSTATION-CUSMINQ
16 ORGANIZATION IS TRANSACTION
17 CONTROL-AREA IS WS-CONTROL.
18 SELECT CUST-MASTER
19 ASSIGN TO DATABASE-CUSMSTP
2 ORGANIZATION IS INDEXED
21 ACCESS IS RANDOM
22 RECORD KEY IS CUST OF CUSMST
23 FILE STATUS IS CM-STATUS.
24 DATA DIVISION.
25 FILE SECTION.
26 FD CUST-DISPLAY
27 LABEL RECORDS ARE OMITTED.
28 1 DISP-REC.
29 COPY DDS-ALL-FORMATS OF CUSMINQ.
3
31 FD CUST-MASTER
32 LABEL RECORDS ARE STANDARD.
33 1 CUST-REC.
34 COPY DDS-CUSMST OF CUSMSTP.
35
36 WORKING-STORAGE SECTION.
37 1 ONE PIC 1 VALUE B"1".
38 1 CM-STATUS PIC X(2).
39 1 WS-CONTROL.
4 2 WS-IND PIC X(2).
41 2 WS-FORMAT PIC X(1).
The SEU listing of the Identification, Environment, and Data Division statements for this example program
is shown here. In particular, note the FILE-CONTROL and FD entries.
Figure 35 (Part 3 of 6). Example of a TRANSACTION Inquiry Program Using a Single Display Device
The Data Division for this example program is shown after compilation to illustrate the data structures
generated by the COPY statements, DDS formats.
Figure 35 (Part 4 of 6). Example of a TRANSACTION Inquiry Program Using a Single Display Device
The Data Division for this example program is shown after compilation to illustrate the data structures
generated by the COPY statements, DDS formats.
Figure 35 (Part 5 of 6). Example of a TRANSACTION Inquiry Program Using a Single Display Device
Figure 35 (Part 6 of 6). Example of a TRANSACTION Inquiry Program Using a Single Display Device
The WRITE operation in statement 79 writes the CUSPMT record to the display. This
record prompts the user to enter a customer number. If the user enters a customer
number and presses the Enter key, the next READ operation then reads the record
back into the program.
The READ operation in statement 84 uses the customer number (CUST) field to
retrieve the corresponding CUSMST record from the CUSMSTP file. If no record is
found in the CUSMSTP file, indicator 99 is set on. The GO TO operation in statement
86, which is processed when indicator 99 is set on, causes the program to branch
back to the beginning. The message 'Customer number not found' is displayed
because it is conditioned by indicator 99 in the DDS for the file, and the keyboard is
locked. The user must press the Reset key in response to this message to unlock
the keyboard. The user can then enter another customer number.
If the READ operation retrieves a record from the CUSMSTP file, the WRITE operation
writes the CUSFLDS record to the display work station. This record contains the cus-
tomer's name, address, and accounts receivable balance.
The user then presses the Enter key, and the program branches back to the begin-
ning of the calculations. The user can enter another customer number or end the
program. To end the program, the user presses the function key 01, which sets on
indicator 15 in the program.
When indicator 15 is on, the program closes all files and processes the EXIT
PROGRAM statement, which causes the program to return control to the calling COBOL
program.
This is the initial display written by the WRITE operation in statement 82:
n o
Customer Master Inquiry
p q
This display appears if a record is found in the CUSMSTP file for the customer
number entered in response to the first display:
n o
Customer Master Inquiry
p q
This display appears if the CUSMSTP file does not contain a record for the customer
number entered in response to the first display:
n o
Customer Master Inquiry
Customer number not found press reset, then enter valid number
p q
Figure 36 on page 153 shows an example order inquiry program, ORD22, that uses
subfiles. The associated DDS is also shown, except for the DDS for the customer
master file, CUSMSTP. Refer to Figure 35 on page 146 for the DDS for CUSMSTP.
ORD22 displays all the detail order records for the requested order number. The
program prompts the user to enter the order number that is to be reviewed. The
order number is checked against the order header file, ORDHDRP. If the order
number exists, the customer number accessed from the order header file is
checked against the customer master file, CUSMSTP. All order detail records in
ORDDTLP for the requested order are read and written to the subfile. A write for the
subfile control record format is processed, and the detail order records in the subfile
are displayed on the screen for the user to review. The program is ended by
pressing function key 12.
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * * P H Y S I CA L OR D HD R P OR D E R H E AD E R F I L E
A R OR D HD R T E X T ( ' OR D E R H E AD E R R E CO R D ' )
A CU S T 5 T E X T ( ' C U S T OM E R N UMB E R ' )
A OR D E R 5 0 0 T E X T ( ' OR D E R N UMB E R ' )
A OR DD A T 6 0 0 T E X T ( ' DA T E OR D E R WA S E N T E R E D ' )
A CU S OR D 1 5 T E X T ( ' C U S T OM E R P URCHA S E OR D E R +
A N UMB E R ' )
A S HP V I A 1 5 T E X T ( ' S H I P P I NG I N S T R UC T I ON S ' )
A OR D S T S 1 0 0 T E X T ( ' OR D E R S T A T U S 1 PC S 2CN T 3CHK +
A 4 RD Y 5 P R T 6 PCK ' )
A O P R N AM 1 0 T E X T ( ' OP E R A T OR N AM E WHO E N T E R E D +
A T H E OR D E R ' )
A OR D AM T 8 0 2 T E X T ( ' TO T AL DOL L AR A MO U N T OF +
A T H E OR D E R ' )
A CU S T Y P 1 0 0 T E X T ( ' C U S T OM E R T Y P E 1 = GO V 2 = SCH +
A 3 = B U S 4 = P V T 5 =O T ' )
A I N V N UM 5 0 0 T E X T ( ' I N VO I C E N UMB E R ' )
A P R T DA T 6 0 0 T E X T ( ' DA T E OR D E R WA S P R I N T E D ' )
A OP N S T S 1 0 0 T E X T ( ' OR D E R OP E N S T A T U S 1 =OP E N +
A 2 =CL OS E 3 - CA NC E L ' )
A TO T L I N 3 0 0 T E X T ( ' TO T AL L I NE I T EMS I N OR D E R ' )
A AC T M T H 2 0 0 T E X T ( ' ACCO U N T I NG MO N T H OF S AL E ' )
A AC T Y R 2 0 0 T E X T ( ' ACCO U N T I NG Y E AR OF S A L E ' )
A S T A T E 2 T E X T ( ' S T A T E ' )
A AMP A I D 8 0 2 T E X T ( ' TO T AL DOL L AR A MO U N T P A I D ' )
A K OR D E R
A
A
A
GX21-7754-1 UM/050*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
D a t a T y p e /( b A / P / S / B / F A / S / X / Y / N / I / W / D / M )
T y p e o f N a m e o f S p e c /( b / R / H / J / K / S / O )
Conditioning
Location
U s a g e (/ b / O / I / B / H / M / N / P )
And/Or/Comment (A/O/*)
Co ndition Na me
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * * P H Y S I CA L OR DD T L P OR D E R D E T A I L F I L E
A T E X T ( ' WA R E HO U S E L OC A T I O N ' )
A *
A R OR DD T L T E X T ( ' OR D E R D E T A I L R E COR D ' )
A *
A CU S T 5 CH ECK ( MF )
A C O L H D G ( ' C U S T OM E R ' ' N UMB E R ' )
A *
A OR D E R 5 0 CO L H DG ( ' OR D E R ' ' N UMB E R ' )
A *
A L I NN UM 3 0
A CO L H DG ( ' L I N E ' ' NO . ' )
A T E X T ( ' L I NE N UMB E R OF L I NE I N OR D E R ' +
A )
A *
A I T EM 5 0 CH ECK ( M1 0 )
A CO L H DG ( ' I T E M ' ' N UMB E R ' )
A Q T YOR D 3 0
A CO L H DG ( ' QU A N T I T Y ' ' OR D E R E D ' )
A T E X T ( ' QUAN T I T Y OR D E R E D ' )
A *
A D E SCR P 3 0 C O L H D G ( ' I T E MD E S C R I P T I O N ' )
A *
A P R I CE 6 2 CM P ( G T 0 )
A CO L H DG ( ' P R I C E ' )
A T E X T ( ' S E L L I NG P R I CE ' )
A E D T CD E ( J )
A E X T E N S 8 2 CO L H DG ( ' E X T E N S I ON ' )
A T E X T ( ' E X T E N S I ON A MO U N T OF Q T YOR D X +
A P R I CE ' )
A *
A W H S L OC 3 CH ECK ( MF )
A CO L H DG ( ' B I N ' ' NO . ' )
A *
A OR DD A T 6 0 T E X T ( ' DA T E OR D E R WA S +
A E N T E R E D ' )
A CU S T Y P 1 0 R A NG E ( 1 5 )
A CO L H DG ( ' C U S T ' ' T Y P E ' )
A T E X T ( ' C U S T OM E R T Y P E 1 = GO V 2 = SCH +
A 3 = B U S 4 = P V T 5 =O T ' )
A *
A S T A T E 2 CH ECK ( MF )
A CO L H DG ( ' S T A T E ' )
A *
A *
A AC T M T H 2 0 CO L H DG ( ' ACC T ' ' MT H ' )
A T E X T ( ' ACCO U N T I NG MO N T H OF S A L E ' )
A *
A AC T Y R 2 0 CO L H DG ( ' ACC T ' ' Y E AR ' )
A T E X T ( ' ACCO U N T I NG Y E AR OF S AL E ' )
A K OR D E R
A K L I NN UM
A
GX21-7754-1 UM/050*
D ATA D E S C R I P T IO N S P E C I F I C AT IO N S Printed in U.S.A.
International Business Machines
*Number of she ets per p ad may vary slightly.
D a t a T y p e /( b A / P / S / B / F A / S / X / Y / N / I / W / D / M )
T y p e o f N a m e o f S p e c /( b / R / H / J / K / S / O )
C onditioning
Location
U s a g e (/ b / O / I / B / H / M / N / P )
And/Or/Comment (A/O/*)
C o nd ition Nam e
Reference (R)
Sequence
Number
Form Type
Positions
Indicator
Indicator
Indicator
Reserved
D ecim al
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * * OR D 2 2 0 D E X I S T I NG OR D E R R E V I EW
A *
A R S UB 1 S F L
A I T EM 5 0 1 0 2 T E X T ( ' I T EM N UMB E R ' )
A Q T YOR D 3 0 1 0 9 T E X T ( ' QUAN T I T Y OR D E R E D ' )
A D E SCR P 3 0 1 0 1 4 T E X T ( ' I T EM D E S C R I P T I ON ' )
A P R I CE 6 0 2 1 0 4 6 T E X T ( ' S E L L I NG P R I CE ' )
A E X T E N S 8 0 2 1 0 5 6 E D T CD E ( J )
A T E X T ( ' E X T E N S I ON A MO U N T OF *
A Q T YOR D X P R I CE ' )
A R S UBC T L 1 S F L C T L ( S UB 1 )
A 5 8 S F L CL R
A 5 7 S F L D S P
A N 5 8 S F L D S PC T L
A T E X T ( ' L
A S F L S I Z ( 5 7 )
A S F L P AG ( 1 4 )
A 5 7 S F L E ND
A OV E R L A Y
A L OC K
A N 4 5
AON 4 7 ROL L UP ( 9 7 ' CON T I N U E D I S P L AY ' )
A CA 1 2 ( 9 8 ' E ND OF P R OG R A M ' )
A S E TOF F ( 5 7 ' D I S P L AY S UB F I L E ' )
A S E TOF F ( 5 8 ' OF F =D I S P L AY S UBC T L ON =C L +
A E AR S UB F I L E ' )
A 1 2 ' E X I S T I NG OR D E R I NQ U I R Y '
A 3 2 ' OR D E R '
A OR D E R 5 Y 0 0 B 3 8 T E X T ( ' OR D E R N UMB E R ' )
A 6 1 E R RM SG ( ' OR D E R N UMB E R NO T F OUND ' 6 1 )
A 4 7 E R R M S G ( ' NO L I NE S F OR T H I S OR D E R ' 4 7 )
A 6 2 E R R M S G ( ' NO C U S T OM E R R E COR D F OU ND FO+
A R T H I S OR D E R ' 6 2 )
A 4 2 ' DA T E '
A OR DD A T 6 0 0 4 7 T E X T ( ' DA T E OR D E R WA S E N T E R E D ' )
A 5 2 ' CU S T # '
A CU S T 5 5 9 T E X T ( ' C U S T OM E R N UMB E R ' )
A N AM E 2 5 3 1 6 T E X T ( ' C U S T OM E R N AM E ' )
A ADD R 2 0 4 1 6 T E X T ( ' C U S T OM E R ADD R E S S ' )
A C I T Y 2 0 5 1 6 T E X T ( ' C U S T OM E R C I T Y ' )
A S T A T E 2 6 1 6 T E X T ( ' S T A T E ' )
A Z I P 5 0 0 6 3 1 T E X T ( ' Z I P COD E ' )
A 1 4 4 ' TO T AL '
A OR D AM T 8 0 2 1 5 1 T E X T ( ' T O T AL DOL L AR A MO U N T OF T H E +
A OR D E R ' )
A 2 4 4 ' S T A T U S '
A S T S OR D 1 2 2 5 1
A 3 4 4 ' OP E N '
A S T S OP N 1 2 3 5 1
A 4 4 4 ' C U S T OM E R OR D E R '
A C U S OR D 1 5 4 5 9 T E X T ( ' C U S T OM E R P URCHA S E OR D E R +
A N UMB E R ' )
A 5 4 4 ' S H I P V I A '
A S HP V I A 1 5 5 5 9 T E X T ( ' S H I P P I NG I N S T R UC T I ON S ' )
A 6 4 4 ' P R I N T E D DA T E '
A P R T DA T 6 0 0 6 5 7 T E X T ( ' DA T E OR D E R WA S P R I N T E D ' )
A 7 2 9 ' I N VO I C E '
A I NVN UM 5 0 0 7 3 8 T E X T ( ' I N VO I C E N UMB E R ' )
A 7 6 4 ' MT H '
A AC T M T H 2 0 0 7 6 8 T E X T ( ' ACCOU N T I NG MO N T H OF S AL E ' )
A 7 7 2 ' Y E AR '
A AC T Y R 2 0 0 7 7 7 T E X T ( ' ACCOU N T I NG Y E AR OF S AL E ' )
A 8 2 ' I T EM '
A 8 8 ' Q T Y '
A 8 1 4 ' I T EM D E S CR I P T I ON '
A 8 4 6 ' P R I CE '
A 8 5 5 ' E X T E N S I ON '
This is the initial order entry prompt display written to the workstation:
n o
Existing Order Inquiry Total
Status
Order Open
Date Customer order
Cust # Ship via
Printed date
Invoice Mth Year
Item Qty Item description Price Extension
p q
This display appears if there are detail order records for the customer whose order
number was entered in the first display:
n o
Existing Order Inquiry Total 742656
Status 7-INVOICED
Order 17924 TESTCASE HARDWARE CO Open 2-CLOSED
Date 11587 124 BURNSIDE DR Customer order TESTCS179331I
Cust # 112 KANKAKEE Ship via TRUCKCO
IL 691 Printed date 42578
Invoice 17924 Mth 12 Year 87
Item Qty Item description Price Extension
331 3 TORQUE WRENCH 75LB 14 INCH 9115 273.45
331 1 TORQUE WRENCH W/GAUGE 2 LB 15777 157.77
44529 4 WOOD CHISEL - 3 1/4 684 273.6
44958 2 POWER DRILL - 3/8 REV 82 164.
4612 3 WROUGHT IRON RAILING 4FTX6FT 793 237.9
4621 1 WROUGHT IRON HAND RAIL 4X4FT 7178 71.78
4792 5 ESCUTCHEON BRASS 15X4INCHES 44488 2,224.4
4818 2 DOOR CHIME ELECTRIC 6 NOTE 1422 2,84.4
4881 4 AWNING ALUMINUM 4FT STRIPED 432 1,72.8
489 1 AWNING FIBERGLASS STRIPED 6FT 21954 219.54
p q
This display appears if the ORDHDRP file does not contain a record for the order
number entered on the first display:
n o
Existing Order Inquiry Total
Status
Order 124 Open
Date Customer order
Cust # Ship via
Printed date
Invoice Mth Year
Item Qty Item description Price Extension
p q
Figure 37 on page 167 shows an example payment update program, ARC1, with
the related DDS and example display screens. For the DDS for the customer
master file, CUSMSTP, refer to Figure 35 on page 146.
In this example, payments from customers are registered. The clerk is prompted to
enter one or more customer numbers and the amount of money to be credited to
each customer’s account. The program checks the customer number and uncondi-
tionally accepts any payment for an existing customer who has invoices out-
standing. If an overpayment will result from the amount of the payment from a
customer, the clerk is given the option to accept or reject the payment. If no cus-
tomer record exists for a customer number, an error message is issued. Payments
can be entered until the clerk ends the program by pressing function key 12.
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * * L OG I C A L OR D HD R L OR D E R F I L E OF OR D HD R
A R OR D HD R P F I L E ( OR D HD R P )
A *
A CU S T
A I N V N UM
A OR D E R
A OR DD A T
A CU S OR D
A S HP V I A
A OR D S T S
A O P R N AM
A OR D AM T
A CU S T Y P
A P R T DA T
A OP N S T S
A TO T L I N
A AC T M T H
A AC T Y R
A S T A T E
A AMP A I D
A K CU S T
A K I N Y N UM
A
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber of sheets per pa d ma y va ry slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * DD S F OR T H E D I S P L AY D E V I CE F I L E ARC0 1 0D
A * ACCO U N T S R ECE I VAB L E I N T E R AC T I V E P A YME N T UP DA T E
A *
A R S UB F I L E 1 S F L
A T E X T ( ' S UB F I L E F OR C U S T OM E R P A YME N T ' )
A *
A ACP P M T 4A I 5 4 T E X T ( ' ACC E P T P A YME N T ' )
A VA L U E S ( ' * Y E S ' ' * NO ' )
A 5 1 D S P A T R ( R I MD T )
A N 5 1 D S P A T R ( ND P R )
A *
A CU S T 5 B 5 1 5 T E X T ( ' C U S T OM E R N UMB E R ' )
A 5 2 D S P A T R ( R I )
A 5 3 D S P A T R ( ND )
A 5 4 D S P A T R ( P R )
A *
A AMP A I D 8 0 2 B 5 2 4 T E X T ( ' A MO U N T P A I D ' )
A CH ECK ( F E )
A AU T O ( R AB )
A CM P ( G T 0 )
A 5 2 D S P A T R ( R I )
A 5 3 D S P A T R ( ND )
A 5 4 D S P A T R ( P R )
A *
A ECPMSG 3 1A O 5 3 7 T E X T ( ' E X C E P T I ON M E S S AG E ' )
A 5 2 D S P A T R ( R I )
A 5 3 D S P A T R ( ND )
A 5 4 D S P A T R ( P R )
A *
A OV R P M T 8 Y 2O 5 7 0 T E X T ( ' OV E R P A YME N T ' )
A E D T CD E ( 1 )
A 5 5 D S P A T R ( B L )
A N 5 6 D S P A T R ( ND )
A *
A S T S CD E 1A H T E X T ( ' S T A T U S COD E ' )
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber of sheets per pa d ma y va ry slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
This is the initial display that is written to the work station to prompt the user to
enter the customer number and payment:
n o
Customer Payment Update Prompt Date 3/2/94
Customer Payment
_____ __________
_____ __________
_____ __________
_____ __________
_____ __________
_____ __________
_____ __________
_____ __________
_____ __________
_____ __________
_____ __________
_____ __________
_____ __________
_____ __________
_____ __________
_____ __________
_____ __________
p q
The user enters the customer numbers and payments:
n o
Customer Payment Update Prompt Date 3/2/94
Customer Payment
345 2
45 3
36 25
125 2
22799 45
419 75
11 5
495 25
133 35
569 4
p q
Payments that would result in overpayments or that have invalid customer numbers
are left on the display and appropriate messages are added:
n o
Customer Payment Update Prompt Date 3/2/94
p q
The user indicates which payments to accept:
n o
Customer Payment Update Prompt Date 3/2/94
p q
n o
Customer Payment Update Prompt Date 3/2/94
p q
The input records contain the key for the record, the depositor name, and the
amount of the transaction.
When the input record is read, the program tests whether this is a transaction
record (in which case, all fields of the record are filled) or a record requesting
sequential retrieval of a specific generic class (in which case, only the
INPUT-GEN-FLD of the input record contains data).
Random access is used for the updating and printing of the transaction records.
Sequential access is used for the retrieval and printing of all records within one
generic class.
5763CB1 COBOL SOURCE LISTING
STMT SEQNBR -A 1 B..+....2....+....3....+....4....+....5....+....6....+....7..IDENTFCN S COPYNAME CHG/DATE
1 1 IDENTIFICATION DIVISION.
2 2 PROGRAM-ID. UPDATEIND.
3 3
4 4 ENVIRONMENT DIVISION.
5 5 CONFIGURATION SECTION.
6 6 SOURCE-COMPUTER. IBM-S38.
7 7 OBJECT-COMPUTER. IBM-S38.
8 8 INPUT-OUTPUT SECTION.
9 9 FILE-CONTROL.
1 1 SELECT MASTER-FILE ASSIGN TO DISK-INDEXFILE
11 11 ORGANIZATION IS INDEXED
12 12 ACCESS IS DYNAMIC
13 13 RECORD KEY IS MASTER-KEY
14 14 FILE STATUS IS MASTER-FILE-STATUS.
15 15 SELECT INPUT-FILE ASSIGN TO DISK-FILEH
16 16 FILE STATUS IS INPUT-FILE-STATUS.
17 17 SELECT PRINT-FILE ASSIGN TO PRINTER-OSYSPRT
18 18 FILE STATUS IS PRINT-FILE-STATUS.
19 19 DATA DIVISION.
2 2 FILE SECTION.
21 21 FD MASTER-FILE LABEL RECORDS STANDARD.
22 22 1 MASTER-RECORD.
23 23 5 MASTER-KEY.
24 24 1 MASTER-GEN-FLD PICTURE X(5).
25 25 1 MASTER-DET-FLD PICTURE X(5).
26 26 5 MASTER-FLD1 PICTURE X(1).
27 27 5 MASTER-NAME PICTURE X(2).
28 28 5 MASTER-BAL PICTURE S9(5)V99.
29 29 FD INPUT-FILE LABEL RECORDS STANDARD.
3 3 1 INPUT-REC.
31 31 5 INPUT-KEY.
32 32 1 INPUT-GEN-FLD PICTURE X(5).
33 33 1 INPUT-DET-FLD PICTURE X(5).
34 34 5 INPUT-NAME PICTURE X(2).
35 35 5 INPUT-AMT PICTURE S9(5)V99.
36 36 FD PRINT-FILE LABEL RECORDS OMITTED
37 37 LINAGE 12 LINES FOOTING AT 9.
Each input record represents the summary sales for one week of one year. The
records for the first week of the last five years (in ascending order) are the first five
input records. The records for the second week of the last five years are the next
five input records, and so on. Thus, five input records fill one output record.
The RELATIVE KEY for the RELATIVE-FILE is not specified because it is not required
for sequential access unless the START statement is used.
5763CB1 COBOL SOURCE LISTING
STMT SEQNBR -A 1 B..+....2....+....3....+....4....+....5....+....6....+....7..IDENTFCN S COPYNAME CHG/DATE
1 1 IDENTIFICATION DIVISION.
2 2 PROGRAM-ID. CREATEREL.
3 3
4 4 ENVIRONMENT DIVISION.
5 5 CONFIGURATION SECTION.
6 6 SOURCE-COMPUTER. IBM-S38.
7 7 OBJECT-COMPUTER. IBM-S38.
8 8 SPECIAL-NAMES. REQUESTOR IS REQUESTOR.
9 9 FILE-CONTROL.
1 1 SELECT RELATIVE-FILE ASSIGN TO DISK-FILED
11 11 ORGANIZATION IS RELATIVE
12 12 ACCESS IS SEQUENTIAL
13 13 FILE STATUS RELATIVE-FILE-STATUS.
14 14 SELECT INPUT-FILE ASSIGN TO DISK-FILEC
15 15 FILE STATUS INPUT-FILE-STATUS.
16 16
17 17 DATA DIVISION.
18 18 FILE SECTION.
19 19 FD RELATIVE-FILE LABEL RECORDS ARE STANDARD.
2 2 1 RELATIVE-RECORD-1.
21 21 5 RELATIVE-RECORD OCCURS 5 TIMES INDEXED BY REL-INDEX.
22 22 1 RELATIVE-YEAR PICTURE 99.
23 23 1 RELATIVE-WEEK PICTURE 99.
24 24 1 RELATIVE-UNIT-SALES PICTURE S9(6).
25 25 1 RELATIVE-DOLLAR-SALES PICTURE S9(9)V99.
26 26 FD INPUT-FILE LABEL RECORDS STANDARD.
27 27 1 INPUT-RECORD.
28 28 5 INPUT-YEAR PICTURE 99.
29 29 5 INPUT-WEEK PICTURE 99.
3 3 5 INPUT-UNIT-SALES PICTURE S9(6).
31 31 5 INPUT-DOLLAR-SALES PICTURE S9(9)V99.
32 32 WORKING-STORAGE SECTION.
33 33 77 INPUT-FILE-STATUS PICTURE XX.
34 34 77 RELATIVE-FILE-STATUS PICTURE XX.
35 35 1 WORK-RECORD.
36 36 5 WORK-YEAR PICTURE 99 VALUE .
37 37 5 WORK-WEEK PICTURE 99.
38 38 5 WORK-UNIT-SALES PICTURE S9(6).
39 39 5 WORK-DOLLAR-SALES PICTURE S9(9)V99.
4 4 1 ERROR-INFO.
41 41 5 OP-NAME PICTURE X(5).
42 42 5 FILLER PICTURE X(1)
43 43 VALUE " ERROR ON ".
44 44 5 FILE-NAME PICTURE X(13).
45 45 5 FILLER PICTURE X(16)
46 46 VALUE " FILE STATUS IS ".
The input record represents the summary sales record for one week of the pre-
ceding year. The RELATIVE KEY for the RELATIVE-FILE is present in the input record
as INPUT-WEEK. The RELATIVE KEY is used to check that the record was correctly
written.
5763CB1 COBOL SOURCE LISTING
STMT SEQNBR -A 1 B..+....2....+....3....+....4....+....5....+....6....+....7..IDENTFCN S COPYNAME CHG/DATE
1 1 IDENTIFICATION DIVISION.
2 2 PROGRAM-ID. UPDATEREL.
3 3
4 4 ENVIRONMENT DIVISION.
5 5 CONFIGURATION SECTION.
6 6 SOURCE-COMPUTER. IBM-S38.
7 7 OBJECT-COMPUTER. IBM-S38.
8 8 INPUT-OUTPUT SECTION.
9 9 FILE-CONTROL.
1 1 SELECT RELATIVE-FILE ASSIGN TO DISK-FILED
11 11 ORGANIZATION IS RELATIVE
12 12 ACCESS IS SEQUENTIAL
13 13 RELATIVE KEY INPUT-WEEK
14 14 FILE STATUS STATUS-VALUE.
15 15 SELECT INPUT-FILE ASSIGN TO DISK-FILES
16 16 FILE STATUS STATUS-VALUE.
17 17
18 18 DATA DIVISION.
19 19 FILE SECTION.
2 2 FD RELATIVE-FILE LABEL RECORDS STANDARD.
21 21 1 RELATIVE-RECORD PICTURE X(15).
22 22 FD INPUT-FILE LABEL RECORDS STANDARD.
23 23 1 INPUT-RECORD.
24 24 5 INPUT-YEAR PICTURE 99.
25 25 5 INPUT-WEEK PICTURE 99.
26 26 5 INPUT-UNIT-SALES PICTURE S9(6).
27 27 5 INPUT-DOLLAR-SALES PICTURE S9(9)V99.
28 28 WORKING-STORAGE SECTION.
29 29
3 3 1 INPUTEND PICTURE X VALUE SPACE.
31 31 88 THE-END-OF-INPUT VALUE "E".
32 32 1 WORK-RECORD.
33 33 5 FILLER PICTURE X(21).
34 34 5 CURRENT-WORK-YEARS PICTURE X(84).
35 35 5 NEW-WORK-YEAR.
36 36 1 WORK-YEAR PICTURE 99.
37 37 1 WORK-WEEK PICTURE 99.
38 38 1 WORK-UNIT-SALES PICTURE S9(6).
39 39 1 WORK-DOLLAR-SALES PICTURE S9(9)V99.
4 4 66 WORK-OUT-RECORD RENAMES
41 41 CURRENT-WORK-YEARS THROUGH NEW-WORK-YEAR.
42 42 1 ERROR-MESSAGE.
43 43 5 OP-NAME PICTURE X(7).
44 44 5 FILLER PICTURE X(1)
45 45 VALUE " ERROR ON ".
46 46 5 FILE-NAME PICTURE X(13).
47 47 5 FILLER PICTURE X(16)
48 48 VALUE " FILE STATUS IS ".
49 49 5 STATUS-VALUE PICTURE X(2).
5 5
The records of the INPUT-FILE contain one required field (INPUT-WEEK), which is the
RELATIVE KEY for RELATIVE-FILE, and one optional field (END-WEEK). An input record
containing data in INPUT-WEEK and spaces in END-WEEK requests a printout for that
one specific RELATIVE-RECORD; the record is retrieved through random access. An
input record containing data in both INPUT-WEEK and END-WEEK requests a printout of
all the RELATIVE-FILE records within the RELATIVE KEY range of INPUT-WEEK through
END-WEEK, inclusive; these records are retrieved through sequential access.
5763CB1 COBOL SOURCE LISTING
STMT SEQNBR -A 1 B..+....2....+....3....+....4....+....5....+....6....+....7..IDENTFCN S COPYNAME CHG/DATE
1 1 IDENTIFICATION DIVISION.
2 2 PROGRAM-ID. RETRIEVAL.
3 3
4 4 ENVIRONMENT DIVISION.
5 5 CONFIGURATION SECTION.
6 6 SOURCE-COMPUTER. IBM-S38.
7 7 OBJECT-COMPUTER. IBM-S38.
8 8 SPECIAL-NAMES. REQUESTOR IS REQUESTOR.
9 9 INPUT-OUTPUT SECTION.
1 1 FILE-CONTROL.
11 11 SELECT RELATIVE-FILE ASSIGN TO DISK-FILED
12 12 ORGANIZATION IS RELATIVE
13 13 ACCESS IS DYNAMIC
14 14 RELATIVE KEY INPUT-WEEK
15 15 FILE STATUS IS RELATIVE-FILE-STATUS.
16 16 SELECT INPUT-FILE ASSIGN TO DISK-FILEF
17 17 FILE STATUS IS INPUT-FILE-STATUS.
18 18 SELECT PRINT-FILE ASSIGN TO PRINTER-QSYSPRT
19 19 FILE STATUS IS PRINT-FILE-STATUS.
2 2
21 21 DATA DIVISION.
22 22 FILE SECTION.
23 23 FD RELATIVE-FILE LABEL RECORDS STANDARD.
24 24 1 RELATIVE-RECORD-1.
25 25 5 RELATIVE-RECORD OCCURS 5 TIMES INDEXED BY REL-INDEX.
26 26 1 RELATIVE-YEAR PICTURE 99.
27 27 1 RELATIVE-WEEK PICTURE 99.
28 28 1 RELATIVE-UNIT-SALES PICTURE S9(6).
29 29 1 RELATIVE-DOLLAR-SALES PICTURE S9(9)V99.
3 3 FD INPUT-FILE LABEL RECORDS STANDARD.
31 31 1 INPUT-RECORD.
32 32 5 INPUT-WEEK PICTURE 99.
33 33 5 END-WEEK PICTURE 99.
34 34 FD PRINT-FILE LABEL RECORDS OMITTED.
35 35 1 PRINT-RECORD.
36 36 5 PRINT-WEEK PICTURE 99.
37 37 5 FILLER PICTURE X(5).
38 38 5 PRINT-YEAR PICTURE 99.
39 39 5 FILLER PICTURE X(5).
4 4 5 PRINT-UNIT-SALES PICTURE ZZZ,ZZ9.
41 41 5 FILLER PICTURE X(5).
42 42 5 PRINT-DOLLAR-SALES PICTURE $$$$,$$$,$$$.99.
You might need to refer to other AS/400 manuals for information about a particular
topic in this chapter. They are listed below:
CallPath/400 Planning and Installation Guide, GA21-9601, SC21-9601, which
provides the following information:
– Communications information that is common among AS/400 communi-
cations support, such as:
- Setting and changing communication values
- Starting and stopping communications
– Communication configuration information, such as defining lines, control-
lers, and devices
– Information about defining and using display station pass-through
– Information about the 3270 remote attachment.
Database Guide, which contains a detailed discussion of the AS/400 system
data base structure. This manual also describes how to define files to the
system using data description specifications (DDS) keywords.
Data Management Guide, which contains information about overriding and
copying files, describing display, printer, tape, and diskette files to the system,
as well as spooling and output queues.
In addition, you might need to refer to the following System/38 publications for infor-
mation about a particular topic in this chapter which would pertain to the AS/400
System/38 environment. They are listed below:
IBM System/38 Control Program Facility Programmer's Guide, SC21-7730,
which explains how to use CPF commands and data description specifications.
IBM System/38 Data Communications Programmer's Guide, SC21-7825, which
described commands, parameters, and data description specification keywords
that are used for program-to-program and system-to-device communication
functions.
The files are kept online and serve as the connecting link between a program and
the device used for I-O. The actual device association is made when the file is
processed. In some instances, this type of I-O control allows the user to change
the attribute of the file (and, in some cases, change the device) used in a program
without changing the program.
C O BO L program FILEX
Printer
The COBOL device name in the ASSIGN clause defines the COBOL functions that
can be processed on the selected file. At compilation time, certain COBOL func-
tions are valid only for a specific COBOL device name; therefore, in this respect,
COBOL is device dependent. The following are examples of device dependency:
For example, assume that the file name FILEY is associated in the COBOL program
with the FORMATFILE device. The device FORMATFILE is an independent device type;
therefore, no line or page control specifications are valid in the COBOL program in
the WRITE ADVANCING statement. When the program is run, the actual I-O device is
specified in the description of FILEY; for example, the device might be a printer, in
which case only the default line and page control or those defined in the DDS would
be used:
C O BO L program FILEY
SELECT file-nam e
D E V (Q PR IN T )
A S S IG N TO F O R M AT F ILE -F ILE Y
Printer
FILEX
C om pile
Tim e D E V (Q P R IN T )
C O BO L Program
F ILE A
Diskette
Run D E V (Q D K T )
Tim e
In the preceding example, the Override to Diskette File command (OVRDKTF) allows
the program to run with an entirely different device file than was specified at compi-
lation time.
Not all file redirections or overrides are valid. At run time, checking occurs to
ensure that the specifications within the COBOL program are valid for the file being
processed. OS/400 allows some file redirections even if device specifics are con-
tained in the program. For example, if the COBOL device name is PRINTER and the
actual file the program uses is not a printer, OS/400 ignores the COBOL print
spacing and skipping specifications.
There are other file redirections that OS/400 does not allow and that cause
program termination. For example, if the COBOL device name is DATABASE or DISK
and a keyed READ operation is specified in the program, the program is terminated if
the actual file the program uses is not a disk or data base file.
See “System Override Considerations” on page 209 for more detailed information
on valid file redirections and file overrides.
Spooling
The AS/400 system provides for the use of input and output spooling functions.
Each AS/400 file description contains a spool attribute that determines whether
spooling is used for the file at run time. The COBOL program is not aware that
spooling is being used. The actual physical device from which a file is read or to
which a file is written is determined by the spool reader or the spool writer.
Output Spool
Output spooling is valid for batch and interactive jobs. The description of the file
that is specified in COBOL by the system-name contains the specification for
spooling as shown in the following example:
C O BO L program Q PR IN T O u tp u t
File Queue
R un Tim e
P rint W riter
Printer D evice
File override commands can be used at run time to override the spooling options
that are specified in the file description, such as the number of copies to be printed.
In addition, AS/400 spooling support allows a user to redirect a file after the
program has run. For example, the user can direct the printer output to a different
device, such as a diskette.
Input Spool
Input spooling is valid only for inline data files in batch jobs. If the input data read
by COBOL comes from a spooled file, COBOL is not aware of which device the data
was spooled in from.
Diskette
F ILE A C O BO L program
*NO
*YES
S pooled
File
The simplest form of overriding a file is to override some attributes of the file. For
example, FILE(OUTPUT) with COPIES(2) is specified when a printer file is created.
Then, before the COBOL program is run, the number of printed copies of output can
be changed to 3. The override command is as follows:
OVRPRTF FILE(OUTPUT) COPIES(3)
Another form of file overriding is to redirect the COBOL program to access a dif-
ferent file. When the override redirects the program to a file of the same type (such
as a printer file to another printer file), the file is processed in the same manner as
the original file.
When the override redirects the program to a file of a different type, the overriding
file is processed in the same manner as the original file would have been proc-
essed. However, device dependent specifications in the COBOL program are
ignored and the defaults are taken by the system.
Not all file redirections are valid. For example, an indexed file for a COBOL
program can only be overridden to another indexed file with a keyed access path.
Note: In particular, associated card files cannot be redirected because the com-
piler uses a single operation (PUTGET) to punch one record and read the next. This
operation is valid only to a card device capable of both reading and punching.
Multiple member processing can be accomplished for a data base file, by overriding
a data base file to process all members. You should note the following exceptions:
A data base source file used for a COBOL program, cannot be overridden to
process all members. Specifying OVRDBF MBR(@ALL) will result in the termination
of the compile.
A data base file used for a COPY statement, cannot be overridden to process all
members. Specifying OVRDBF MBR(@ALL) will cause the COPY statement to be
ignored.
It is the COBOL programmer’s responsibility to ensure that file overrides are applied
properly.
The ALCOBJ command can be used to specify the desired lock state. If no ALCOBJ
command is used for a job, OS/400 places the following lock states on data base
files when it opens the them:
INPUT Shared-for-read
I-O Shared-for-update
EXTEND Shared-for-update
OUTPUT Shared-for-update
The shared-for-read lock state allows another user to open the file with a lock state
of shared-for-read, shared-for-update, shared-no-update, or exclusive-allow-read,
but the user cannot specify the exclusive use of the file. The shared-for-update lock
state allows another user to open the file with shared-for-read or shared-for-update
lock state.
In order for programs to share a data base file, the file should be opened by the
first program (the program with the highest call level in the stack) in a way that will
allow subsequent programs to share the same file. If a subsequent program
requests a function that was excluded by the first program, an abnormal termination
occurs.
OS/400 places a shared-for-read on the device file and an exclusive lock state on
the device. Another user can open the device file, but cannot use the same phys-
ical device.
The lock state placed on the file by OS/400 can be changed if you use the ALCOBJ
command.
Note: When a COBOL program opens a physical file for OUTPUT, that file will be
subject to an exclusive lock for the period of time necessary to clear the member.
For more information see the “OPEN Statement” on page 389.
Even when all of the above conditions are met, certain OS/400 restrictions can
cause blocking and unblocking to not be processed. In these cases, performance
improvements will not be realized.
The I-O-FEEDBACK area is not updated after each read or write for files in which
multiple records are blocked and unblocked by COBOL. See “I-O-FEEDBACK” on
page 552 for more information.
For data base files, you may not see all changes as they occur, if the changes are
made in different programs.
Both externally described files and program described files must be defined in the
COBOL program within the INPUT-OUTPUT SECTION and the FILE SECTION. However,
record descriptions in the FILE SECTION for externally described files can be
defined with the Format 2 COPY statement.
Device-dependent functions such as forms control are not extracted by the Format
2 COPY operation. Only field level descriptions are extracted.
(For more information on the Format 2 COPY statement, see Figure 51 on page 219
and the accompanying text).
Note: Actual file processing within the Procedure Division is the same, whether
the file is externally described or program described.
These specifications result from the DDS for the file and the OS/400 create file
command that is used for the file.
If the user chooses, he can use an externally described file within the program by
specifying the file as program described (specifying the coding for the record
description in the source). In this case, the compiler does not copy in the external
field-level description of the file at compilation time. This approach can be used in
conversion where existing programs use program described files and new programs
use externally described files to refer to the same file.
Figure 45 on page 213 shows some typical relationships between COBOL pro-
grams and files on the AS/400 system.
1 The COBOL program uses the field level description of a file that is defined to
OS/400. The COBOL user coded a Format 2 COPY statement for his record
description. At compilation time, the compiler copies in the external field-level
description and translates it into a syntactically correct COBOL record
description. The file must exist at compilation time.
2 An externally described file is used as a program described file in the COBOL
program. The entire record description for the file is coded in the COBOL
program. This file does not have to exist at compilation time.
3 A file is described to OS/400 only to the record level. The entire record
description must be coded in the COBOL program. This file does not have to
exist at compilation time.
4 A file-name can be specified for compilation time, and a different file-name
can be specified for run time. A COBOL Format 2 COPY statement generates
the record description for the file at compilation time. At run time, a different
library list or a file override command can be used so that a different file is
accessed by the program. The file description copied in at compilation time is
used to describe the input records used at run time.
Note: For externally described files, the two file formats must be the same. Other-
wise, a level check error will occur.
Figure 45. Typical Relationships between COBOL and the Files on the AS/400 system
Data Description Specifications (DDS) are used to describe files at the field level to
OS/400. Each record format in an externally described file is identified by a unique
record format name.
The record format specifications describe the fields in a record and the location of
the fields in a record. The fields are located in the record in the order specified in
DDS. The field description generally includes the field name, the field type (char-
acter, binary, zoned decimal, or packed decimal), and the field length (including the
number of decimal positions in a numeric field). Instead of being specified in the
record format for a physical or logical file, the field attributes can be defined in a
field reference file (see Figure 46 on page 215).
The keys for a record format are specified in DDS. When you use a Format 2 COPY
statement, a table of comments is generated in the source program listing showing
how the keys for the format are defined in DDS.
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber of sheets per pa d ma y va ry slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * * F L DR E F D S T R E F D I S T R I B U T I ON A P P L I CA T I ON F I E L D R E F E R E NC E
A R D S T R E F T E X T ( ' D I S T R I B U T I ON F I E L D R E F ' )
A * C OMMO N F I E L D S U S ED A S R E F E R E NC E
A B A SDA T 6 0 E D T CD E ( Y )
A T E X T ( ' B A S E DA T A F I E L D ' )
A * F I E L D S U S E D B Y C U S T OM E R MA S T E R F I L E
A CU S T 5 CH ECK ( MF )
A C O L H D G ( ' C U S T OM E R ' ' N UMB E R ' )
A N AM E 2 0 C O L H D G ( ' C U S T OM E R N AM E ' )
A ADD R R R E F F L D ( N AM E )
A C O L H D G ( ' C U S T OM E R ADD R E S S ' )
A C I T Y R R E F F L D ( N AM E )
A C O L H D G ( ' C U S T OM E R C I T Y ' )
A S T A T E 2 CH ECK ( MF )
A CO L H DG ( ' S T A T E ' )
A S R H COD 6 CH ECK ( MF )
A CO L H DG ( ' S E A R C H ' ' COD E ' )
A T E X T ( ' C U S T OM E R N UMB E R S E ARCH COD E ' )
A Z I P 5 0 CH ECK ( MF )
A CO L H DG ( ' Z I P ' ' COD E ' )
A CU S T Y P 1 0 R A NG E ( 1 5 )
A CO L H DG ( ' C U S T ' ' T Y P E ' )
A T E X T ( ' C U S T OM E R T Y P E 1 = GO V 2 = SCH 3 = B +
A U S 4 = P T 5 =O T H ' )
A AR B A L 8 2 CO L H DG ( ' ACC T S R EC ' ' B A L ANC E ' )
A E D T CD E ( J )
A OR D B A L R R E F F L D ( AR B AL )
A CO L H DG ( ' A / R AM T I N ' ' OR D E R F I L E ' )
A L S T AM T R R E F F L D ( AR B AL )
A CO L H DG ( ' L A S T ' ' A MO U N T ' ' P A I D ' )
A T E X T ( ' L A S T A MO U N T P A I D I N A / R ' )
A
A
A
A
This example of a field reference file shows the definitions of the fields that are used by the CUSMSTL
(customer master logical) file. The field reference file normally contains the definitions of fields that are
used by other files. The following text describes some of the entries for this field reference file.
1 The BASDAT field is edited by the Y edit code, as indicated by the keyword EDTCDE (Y). If this field is
used in an externally described output file for a COBOL program, the COBOL-generated field is com-
patible with the data type specified in the DDS. The field is edited when the record is written.
When the field is used in a program described output file, compatibility with the DDS fields in the file
is the user’s responsibility. When DDS is not used to create the file, appropriate editing of the field in
the COBOL program is the user’s responsibility.
2 The CHECK(MF) entry specifies that the field is a mandatory fill field when it is entered from a display
work station. Mandatory fill means that all characters for the field must be entered from the display
work station.
3 The ADDR and CITY fields share the same attributes that are specified for the NAME field, as indicated
by the REFFLD keyword.
4 The RANGE keyword, which is specified for the CUSTYP field, ensures that the only valid numbers that
can be entered into this field from a display work station are 1 through 5.
5 The COLHDG keyword provides a column head for the field if it is used by the Interactive Data Base
Utilities (IDU).
6 The ARBAL field is edited by the J edit code, as indicated by the keyword EDTCDE(J).
7 A text description (TEXT keyword) is provided for some fields. The TEXT keyword is used for doc-
umentation purposes and appears in various listings.
Figure 46 (Part 2 of 2). Example of a Field Reference File
The following pages provide examples of DDS usage and the COBOL code which
would result from the use of a Format 2 COPY statement. (See “Format 2 COPY
Statement, DDS or DD Formats” on page 219 for a detailed description of the
Format 2 COPY statement).
Figure 47 on page 217 shows the DDS for a logical file and Figure 48 on
page 218 shows the COBOL code generated.
Figure 49 on page 218 describes the same file but includes the ALIAS
keyword, and Figure 50 on page 219 shows the COBOL code generated.
Actual file processing within the Procedure Division is the same for both program
described and externally described files.
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * * L OG I C A L CU SMS T L C U S T OM E R MA S T E R F I L E
A UN I QU E
A * R CU S R EC P F I L E ( CU SMS T P )
A T E X T ( ' C U S T OM E R MA S T E R R E CO R D ' )
A CU S T
A N AM E
A ADD R
A C I T Y
A S T A T E
A Z I P
A S R H COD
A CU S T Y P
A AR B AL
A OR D B A L
A L S T AM T
A L S T DA T
A CRD L MT
A S L S Y R
A S L S L Y R
A K CU S T
1 A logical file for processing the customer master physical file (CUSMSTP) is defined and named
CUSMSTL.
2 The UNIQUE keyword indicates that duplicate key values for this file are not allowed.
3 One record format (CUSREC) is defined for the CUSMSTL file, which is to be based upon the physical
file CUSMSTP.
4 The CUST field is identified as the key field for this file.
5 If field attributes (such as length, data type, and decimal positions) are not specified in the DDS for
a logical file, the attributes are obtained from the corresponding field in the physical file. Any field
attributes specified in the DDS for the logical file override the attributes for the corresponding field in
the physical file. The definition of the fields in the physical file could refer to a field reference file.
A field reference file is a data description file consisting of field names and their definitions, such as
size and type. When a field reference file is used, the same fields that are used in multiple record
formats have to be defined only once in the field reference file.
Figure 47. Example of Data Description Specifications
n o
1
CUS-MASTER.
COPY DDS-CUSREC OF CUSTMAST-CUSLIB.
@I-O FORMAT: CUSREC FROM FILE CUSTMAST OF LIBRARY CUSLIB CUSREC
@ CUSTOMER MASTER RECORD CUSREC
@THE KEY DEFINITIONS FOR THE RECORD FORMAT CUSREC CUSREC
@NUMBER NAME RETRIEVAL TYPE ALTSEQ CUSREC
@1 CUST ASCENDING AN NO CUSREC
5 CUSREC. CUSREC
6 CUST PIC X(5). CUSREC
@ CUSTOMER NUMBER CUSREC
6 NAME PIC X(2). CUSREC
@ CUSTOMER NAME CUSREC
6 ADDR PIC X(2). CUSREC
@ CUSTOMER ADDRESS CUSREC
6 CITY PIC X(2). CUSREC
@ CUSTOMER CITY CUSREC
6 STATE PIC X(2). CUSREC
@ STATE ABBREVIATION CUSREC
6 ZIP PIC S9(5) COMP-3. CUSREC
@ ZIP CODE CUSREC
6 SRHCOD PIC X(6). CUSREC
@ CUSTOMER NAME SEARCH CODE CUSREC
6 CUSTYP PIC 9(1). CUSREC
@ CUSTOMER TYPE CUSREC
6 ARBAL PIC S9(6)V9(2) COMP-3. CUSREC
@ ACCT/REC BALANCE CUSREC
p q
Figure 48. Example of the Results of the Format 2 COPY Statement (DDS)
Figure 46 on page 215 shows an example of the field reference file that defines
the attributes for the fields used in the data base file.
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * * L OG I C A L CU SMS T L C U S T OM E R MA S T E R F I L E
A UN I QU E
A * R CU S R EC P F I L E ( CU SMS T P )
A T E X T ( ' C U S T OM E R MA S T E R R E CO R D ' )
A CU S T A L I A S ( C U S T OM E R _N U M B E R )
A N AM E A L I A S ( C U S T OM E R _N A M E )
A ADD R A L I A S ( ADD R E S S )
A C I T Y
A S T A T E
A Z I P
A S R H COD A L I A S ( S E A R C H _C O D E )
A CU S T Y P A L I A S ( C U S T OM E R _ T Y P E )
A AR B AL A L I A S ( A CC T _R E C _B A L A NC E )
A OR D B A L
A L S T AM T
A L S T DA T
A CRD L MT
A S L S Y R
A S L S L Y R
A K CU S T
1 The name associated with the Alias keyword, which will be included in the program.
Figure 49. Example of Data Description Specifications with ALIAS
IBM Extension
Format 2
╔═════════════════════════════════════════════════════════════════════════════════╗
║ ┌ ┐ ┌ ┐ ║
║ { DD-format-name } │ -I │ │ -INDICATOR │ ║
║ COPY { DD-ALL-FORMATS } │ -O │ │ -INDICATORS │ ║
║ { DDS-format-name } │ -I-O │ │ -INDIC │ ║
║ { DDS-ALL-FORMATS } └ ┘ └ ┘ ║
║ ║
║ { OF } file name [ -library name ] ║
║ { IN } ║
║ ║
║ ┌ { } ┐ ║
║ │ { { ==pseudo-text-1== } { ==pseudo-text-2== } } │ ║
║ │ REPLACING { , { identifier-1 } BY { identifier-2 } } . . . │ . ║
║ │ { { literal-1 } { literal-2 } } │ ║
║ │ { { word-1 } { word-2 } } │ ║
║ └ { } ┘ ║
╚═════════════════════════════════════════════════════════════════════════════════╝
The Format 2 COPY statement (DDS or DD option) can be used to create COBOL
Data Division statements to describe a file that exists on the system. These
descriptions are based on the version of the file in existence at compile time. They
The Format 2 COPY statement can be used only in the Data Division, and it is the
user’s responsibility to precede the statement with a group level item that has a
level-number less than 05.
The DDS option copies in the internal DDS format field names.
When the DD option is used, any Alias names present replace the corresponding
DDS field names. All underscores in the Alias names are translated into hyphens
before any replacing occurs.
The format-name is the name of the DDS record format definition that is to be trans-
lated into COBOL data description entries. The format-name must follow the rules
for formation of any System/38 environment name.
File name is the name of an AS/400 system file. The generated DDS entries repre-
sent the record format defined in the file. The file must be created before the
program is compiled.
Library name is optional. If it is not specified, the current job library list is used as
the default value.
For all other file types the description generated varies as follows:
If -I is specified, the generated data description entries contain either:
– The input and input/output fields for a nonsubfile format
– The input, output, and input/output fields for a subfile format.
The use of the INDICATOR attribute is discussed under “INDICATOR Attribute of the
Format 2 COPY Statement” on page 223.
For example, if we assume that the file CUSTMASTER contains two formats: CUSADR
and CUSTDETL ; then the following COPY statements could be specified.
SELECT FILE-X
ASSIGN TO DATABASE-CUSTMASTER.
.
.
.
FD FILE-X
LABEL RECORDS ARE STANDARD.
1 FILE-X-RECS.
COPY DDS-ALL-FORMATS OF
CUSTMASTER-QGPL. (See Note 1.)
.
.
.
WORKING-STORAGE SECTION.
1 ADR-REC.
COPY DDS-CUSTADR OF
CUSTMASTER. (See Note 2.)
1 DETAIL-REC.
COPY DDS-CUSTDETL OF
CUSTMASTER. (See Note 2.)
Notes:
1. This COPY statement generates only one storage area for all formats.
2. These COPY statements generate separate storage areas.
5 file-name-RECORD
PIC X(size of largest record).
Notes:
1. See Figure 52 on page 223 for the appropriate COBOL definition.
Indicator Structures
If indicators are requested, and exist in the format, an additional group name (06
level) is generated at the beginning of the structure, followed by entries (07 level)
for the relevant individual indicators.
6 format-name-(I or O)-INDIC.
7 INxx PIC 1 INDIC xx.
For example:
6 SAMPLE1-I-INDIC.
7 IN1 PIC 1 INDIC 1.
7 IN4 PIC 1 INDIC 4.
7 IN5 PIC 1 INDIC 5.
7 IN7 PIC 1 INDIC 7.
6 FLD1 PIC ... .
6 FLD2 PIC ... .
If the INDICATOR attribute is specified, data description entries are generated for
indicators, but not for data fields. The data description entries that are generated
are determined by which one of the usage attributes (I, O, or I-O) is specified or
assumed in the COPY statement.
If ...I-INDICATOR... is specified, data description entries for input (response)
indicators are generated for indicators used in the input record area.
If the INDICATOR attribute is not specified, whether data description entries are gen-
erated for indicators depends on whether the file had the keyword INDARA specified
in the DDS at the time it was created.
If INDARA was not specified, data description entries are generated for both data
fields and indicators.
If INDARA was specified, data description entries are generated for data fields
only, not for indicators.
For example:
1 RCUSREC.
COPY DDS-CUSREC-I OF CUSFILE.
@ I-O FORMAT: CUSREC FROM FILE CUSFILE OF LIBRARY CUSLIB CUSREC
@ THE KEY DEFINITIONS FOR RECORD FORMAT CUSREC
@ NUMBER NAME RETRIEVAL TYPE ALTSEQ
@ 1 ARBAL ASCENDING SIGNED NO
@ 2 AREACD DESCENDING ABSVAL NO
5 CUSREC.
6 ARBAL PIC S9(7)V9(2) COMP-3 CUSREC
6 AREACD PIC S9(3) COMP-3. CUSREC
6 BOSTAZ PIC X(1). CUSREC
6 CNTCT PIC X(15). CUSREC
6 CRCHKZ PIC S9(2). CUSREC
6 CSTAT PIC X(1). CUSREC
6 CUSTNZ PIC S9(6). CUSREC
6 DLORD PIC S9(6). CUSREC
6 DSCPCZ PIC S9(2)V9(3) COMP-3. CUSREC
6 INDUS PIC S9(2). CUSREC
6 NAME1 PIC X(25). CUSREC
6 NAME2 PIC X(25). CUSREC
6 NAME3 PIC X(25). CUSREC
6 NAME4 PIC X(25). CUSREC
6 PHONE PIC S9(7) COMP-3. CUSREC
6 PRICIZ PIC S9(2). CUSREC
6 SHPINZ PIC X(25). CUSREC
6 SLSMAZ PIC X(3). CUSREC
6 TAXCDZ PIC S9(2). CUSREC
6 TERMSZ PIC S9(2). CUSREC
Data items that are subordinate to the data item specified in a MOVE CORRESPONDING
statement do not correspond and are not moved when they contain a REDEFINES
clause or are subordinate to a redefining item.
The format-name can be a COBOL reserved word only if the REPLACING phrase is
used to change the copied occurrence of the format-name.
The REPLACING phrase cannot be used to change the name of a key field when
EXTERNALLY-DESCRIBED-KEY is used.
Floating point key fields are not allowed. In cases where some formats exist with a
floating point key field and other formats do not, you should use one or more
Format 2 COPY statements with specific format names, rather than using the
ALL-FORMATS option.
Note: If you have not specified your own program collating sequence, you may
create a record containing floating point fields in your COBOL program by moving
LOW-VALUES to the entire record before moving in the values of the non-floating-point
fields. This will give the floating point fields in the record a value of zero. Note that
the above method is only recommended if valid floating point fields with a value of
zero are desirable for your particular application.
For example:
5763CB1 COBOL SOURCE LISTING
STMT SEQNBR -A 1 B..+....2....+....3....+....4....+....5....+....6....+....7..IDENTFCN S COPYNAME CHG/DATE
DDS field names can contain characters that are not allowed in the COBOL lan-
guage. For example, the field name CUSTN# can be used as an abbreviation for
customer number. This format can be used in a Format 2 COPY statement if the
REPLACING phrase is used to change the invalid characters to valid COBOL charac-
ters.
Access Path
The description of an externally described file contains the access path that
describes how records are to be retrieved from the file. Records can be retrieved
based on an arrival sequence (nonkeyed) access path or on a keyed sequence
access path.
The arrival sequence access path is based on the order in which the records are
stored in the file. Records are added only to the end of the file.
For the keyed sequence access path, the sequence in which records are retrieved
from the file is based on the contents of the key field(s) defined in the DDS for the
file. For example, in the DDS shown in Figure 47 on page 217, CUST is defined as
the key field. The keyed sequence access path is updated whenever records are
added, deleted, or the contents of a key field change.
The key for a file is determined by the valid keys for the record types in that file.
The file’s key is determined in the following manner:
If all record types in a file have the same number of key fields defined in DDS
that are identical in attributes, the key for the file consists of all fields in the key
for the record types. (The corresponding fields do not have to have the same
name.) For example, if the file has three record types and the key for each
record type consists of fields A, B, and C, then the file’s key consists of fields
A, B, and C. That is, the file’s key is the same as the records’ key.
If all record types in the file do not have the same key fields, the key for the file
consists of the key fields common to all record types. For example, a file has
three record types and the key fields are defined as follows:
– REC1 contains key field A.
– REC2 contains key fields A and B.
– REC3 contains key fields A, B, and C.
Then the file’s key is field A, the key field common to all record types.
If no key field is common to all record types, any keyed reference to the file will
always return the first record in the file.
In COBOL you must specify a RECORD KEY for an indexed file to identify the record
you want to process. COBOL compares the key value with the key of the file or
record, and processes the specified operation on the record whose key matches
the RECORD KEY value.
Level Checking
When a COBOL program uses an externally described file, OS/400 provides a level
check function. This function ensures that the format has not changed since com-
pilation time.
If a file is recreated using an existing format, any existing COBOL programs that use
that format can still be used (assuming that no other conflicts such as a change of
keys exist) without recompilation.
Note: COBOL does not provide level checking for program described files.
The file must be created on the system before the program can be run. This can
be done by using one of the Create File commands.
DDS can be used with the Create File commands. For a COBOL indexed file, a
keyed access path must be created. This can be done by specifying a key in DDS
when the file is created. The record key in COBOL must match the key defined
when the file was created.
The file operations that are valid for a printer file are WRITE, OPEN, and CLOSE. For a
complete description of these operations, see Chapter 10, “Procedure Division.”
FORMATFILE must be used when the file is an externally described printer file. See
“FORMATFILE Files” on page 231 for information on the DDS for externally
described printer files.
The ADVANCING phrase cannot be specified in WRITE statements for files assigned to
FORMATFILE.
LINAGE Clause
When the LINAGE clause is specified for a file assigned to PRINTER, all spacing and
paging controls are handled internally by compiler generated code. At OPEN time,
the printer is positioned to a new physical page and the LINAGE-COUNTER is set to 1.
All spacing or paging for following WRITE statements for the file is controlled inter-
nally, and the physical page size is ignored. For a file that has a LINAGE clause
and is assigned to PRINTER, paging consists of spacing to the end of the logical
page (page body) and then spacing past the bottom and top margins.
Use of the LINAGE clause degrades performance. The LINAGE clause should be
used only as necessary. If the physical paging is acceptable, the LINAGE clause is
not necessary.
The LINAGE clause should not be used for files assigned to FORMATFILE.
FORMATFILE Files
Externally described printer files must be assigned to a device of FORMATFILE. The
term FORMATFILE is used because the FORMAT phrase is valid in WRITE statements
for the file, and the data formatting is specified in the DDS for the file.
When you have specified a device of FORMATFILE, you can obtain formatting of
printed output in two ways:
1. Choose which formats to print in which order by using appropriate values in the
FORMAT phrases specified for WRITE statements. For example, use one format
once per page to produce a heading, and use another format to produce the
detail lines on the page.
2. Choose the appropriate options to be taken when each format is printed by
setting indicator values and passing these indicators through the INDICATOR
phrase for the WRITE statement. For example, fields may be underlined, blank
lines may be produced before or after the format is printed, or the printing of
certain fields may be skipped.
The use of external descriptions for printer files has the following advantages over
program descriptions:
Multiple lines can be printed by one WRITE statement. When multiple lines are
written by one WRITE statement and the END-OF-PAGE condition is reached, the
END-OF-PAGE imperative statement is processed after all of the lines are printed.
It is possible to print lines in the overflow area, and onto the next page before
the END-OF-PAGE imperative statement is processed.
Use of the ADVANCING phrase for FORMATFILE files causes a compilation error to be
issued. Advancing of lines is controlled in a FORMATFILE file through DDS keywords
such as SKIPA and SKIPB, and through the use of line numbers.
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * P H Y S I CA L F I L E DD S F OR P E R S ON N E L F I L E I N F OR MA T F I L E E X AMP L E
A
A * R P E R S R EC
A E MP L NO 6 S
A N AM E 3 0
A ADD R E S S 1 3 5
A ADD R E S S 2 2 0
A B I R T HDA T E 6
A MA R S T A T 1
A S P O U S E N AM E 3 0
A N U MC H I L D 2 S
A K E MP L NO
A
A
A
A
A
A
A
A
Figure 56 (Part 1 of 2). Example of the Use of Externally Described Printer Files Assigned to a Device of
FORMATFILE
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber of sheets per pa d ma y va ry slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * P R I N T E R F I L E DD S F OR F OR MA T F I L E E X AMP L E
A *
A I NDAR A R E F ( P E R S F I L E )
A R H E A D I NG S K I P B ( 1 ) S P AC E A ( 3 )
A 1 5 ' P E R S ON N E L L I S T I NG '
A UND E R L I N E
A 3 3 ' - OR D E R E D B Y '
A OR D E R T Y P E 1 5 4 6
A 8 0DA T E E D T CD E ( Y )
A 9 3 T I ME
A 1 1 5 ' P AG E : '
A + 1 P AGN B R E D T CD E ( 3 )
A *
A R D E T A I L S P AC E A ( 3 )
A * L I NE 1
A 1 ' N AM E : '
A N AM E R 1 1 UND E R L I N E
A 5 5 ' E MP L OY E E N UMB E R : '
A E MP L NO R 7 3
A 8 7 ' DA T E OF B I R T H : '
A B I R T HDA T E R 1 0 3 S P AC E A ( 1 )
A * L I NE 2
A 1 ' ADD R E S S : '
A ADD R E S S 1 R 1 1
A 5 5 ' MA R I T A L S T A T U S : '
A MA R S T A T R 7 3
A 0 1 8 7 ' S POU S E ' ' S N AM E : '
A 0 1 S P O U S E N AM E R 1 0 3
A * L I NE 3
A ADD R E S S 2 R 1 1 S P AC E B ( 1 )
A 5 5 ' CH I L DR E N : '
A N U MC H I L D R 7 3 E D T CD E ( 3 )
A
A
A
1 INDARA specifies that a separate indicator area is to be used for the file.
2 HEADING is the format name which provides headings for each page.
3 SKIPB(1) and SPACEA(3) are used to:
1. Skip to line 1 of the next page before format HEADING is printed.
2. Leave 3 blank lines after format HEADING is printed.
4 DATE, TIME and PAGNBR are used to have the current date, time and page number printed automat-
ically when format HEADING is printed.
5 DETAIL is the format name used to print the detail line for each employee in the personnel file.
6 SPACEA(3) causes 3 lines to be left blank after each employee detail line.
7 SPACEA(1) causes a blank line to be printed after the field BIRTHDATE is printed. As a result, subse-
quent fields in the same format are printed on a new line.
8 01 means that these fields are printed only if the COBOL program turns indicator 01 on and passes
it when format DETAIL is printed.
9 EDTCDE(3) is used to remove leading zeros when printing this numeric field.
Figure 56 (Part 2 of 2). Example of the Use of Externally Described Printer Files Assigned to a Device of
FORMATFILE
All data base files are created by OS/400 Create File commands.
To write standard ANS COBOL X3.23-1974 to access an indexed file, the file must
be created with certain characteristics. The following table lists these character-
istics and what controls them.
Characteristic Control
The file must be a physical file. The CL command CRTPF
The file cannot have records with duplicate The DDS keyword UNIQUE
key values.
The file cannot be a shared file. The CL command CRTPF
A key must be defined for the file. DDS
The key fields identify the records in an indexed file. The user specifies the key
field in the RECORD KEY clause of the SELECT statement. The RECORD KEY data item
must be defined within a record description for the indexed file. If there are multiple
record descriptions for the file, only one need contain the RECORD KEY data-name.
However, the same positions within the record description that contain the RECORD
KEY data item are accessed in the other record descriptions as the KEY value for
any references to the other record descriptions for that file.
Valid RECORD KEYS: The DDS for the file specifies the field(s) to be used as
the key field. If the file has multiple key fields, the key fields must be contiguous in
each record unless RECORD KEY IS EXTERNALLY-DESCRIBED-KEY is specified.
When the DDS specifies only one key field for the file, the RECORD KEY must be a
single field of the same length as the key field defined in the DDS.
If a Format 2 COPY statement is specified for the file, the RECORD KEY clause must
specify one of the following:
The name used in the DDS for the key field if the name is not a COBOL
reserved word.
The name used in the DDS for the key field with -DDS added to the end if the
name is a COBOL reserved word.
The data-name defined with the proper length and at the proper location in a
program described record description for the file.
EXTERNALLY-DESCRIBED-KEY. This keyword specifies that the key(s) defined in
DDS for each record format are to be used for accessing the file. These keys
can be noncontiguous. They can be defined at different positions within the
record format.
When the DDS specifies multiple contiguous key fields, the RECORD KEY data-name
must be a single field with its length equal to the sum of the lengths of the multiple
key fields in the DDS. If a Format 2 COPY statement is specified for the file, there
must also be a program described record description for the file that defines the
RECORD KEY data-name with the proper length and at the proper position in the
record.
“START Statement” in Chapter 10, “Procedure Division” lists the rules for speci-
fying a search argument that refers to a partial key.
Figure 59 on page 241 and Figure 60 on page 242 show examples of how to use
DDS to describe the access path for indexed files.
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A R F OR MA T A P F I L E ( OR DD T L P )
A T E X T ( ' ACC E S S P A T H F OR I ND E X E D F I L E ' )
A F L DA 1 4
A OR D E R N 5 S 0
A F L DB 1 0 1
A K OR D E R N
A
A
A
A
A
A
A
A
A
A
A
A
A
A
Figure 59 (Part 1 of 2). Using Data Description Specifications to Define the Access Path for an Indexed File
Data description specifications must be used to create the access path for a program described indexed
file.
In the DDS for the record format FORMATA for the logical file ORDDTLL, the field ORDERN, which is five digits
long, is defined as the key field. The definition of ORDERN as the key field establishes the keyed access for
this file. Two other fields, FLDA and FLDB, describe the remaining positions in this record as character
fields.
The program described input field ORDDTLL is described in the FILE-CONTROL section in the SELECT clause
as an indexed file.
The COBOL descriptions of each field in the FD entry must agree with the corresponding description in the
DDS file. The RECORD KEY data item must be defined as a five-digit numeric integer beginning in position
15 of the record.
Figure 59 (Part 2 of 2). Using Data Description Specifications to Define the Access Path for an Indexed File
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber o f sheets per pad may vary slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A R F OR MA T P F I L E ( OR DD T L P )
A T E X T ( ' ACC E S S P A T H F OR I ND E X E D F I L E ' )
A F L DA 1 4
A OR D E R N 5 S 0
A I T EM 5
A F L DB 9 6
A K OR D E R N
A K I T EM
A
A
A
A
A
A
A
A
A
A
A
A
Figure 60. Using Data Description Specifications to Define the Access Path (a Composite Key) for an Indexed File
In this example, the data description specifications define two key fields for the
record format FORMAT in the logical file ORDDTLL. For the two fields to be used as a
composite key for a program described indexed file, the key fields must be contig-
uous in the record.
The COBOL description of each field must agree with the corresponding description
in the DDS file. A ten-character item beginning in position 15 of the record must be
defined in the RECORD KEY clause of the file-control entry. The COBOL descriptions
of the DDS fields ORDERN and ITEM would be subordinate to the 10-character item
defined in the RECORD KEY clause.
To write standard ANS COBOL X3.23-1974 to access a relative file, the file must be
created with certain characteristics. The following table lists these characteristics
and what controls them.
Characteristic Control
The file must be a physical file. The CL command CRTPF
The file cannot be a shared file. The CL command CRTPF
No key can be specified for the file. DDS
Characteristic Control
Select/omit level keywords cannot be used for DDS
the file.
For a COBOL file with an organization of RELATIVE, the Reorganize Physical File
Member (RGZPFM) CL command can:
Remove all deleted records from the file. Since COBOL initializes all relative file
records to deleted records, any record that has not been explicitly written will
be removed from the file. This causes the relative record numbers of all
records after the first deleted record in the file to change.
Change the relative record numbers if the file has a key and the arrival
sequence is changed to match a key sequence (with the KEYFILE parameter).
Either result of the CL command RGZPFM causes the COBOL concept of a relative file
to change.
To write standard ANS COBOL X3.23-1974 to access a sequential file, the file must
be created with certain characteristics. The following table lists these character-
istics and what controls them.
Characteristic Control
The file must be a physical file. The CL command CRTPF
The file cannot be a shared file. The CL command CRTPF
The device specified in the assignment-name
must match the actual device to which the file
is assigned.
No key can be specified for the file. DDS
To process a keyed sequence file as a relative file in COBOL, the file must be a
physical file, or a logical file whose members are based on one physical file
member. To process a keyed sequence file as a sequential file in COBOL, the file
must be a physical file, or a logical file that is based on one physical file member
and that does not contain select/omit logic.
A file with an arrival sequence access path can be processed in COBOL as a file
with RELATIVE or SEQUENTIAL organization. However, the file must be a physical file
or a logical file where each member of the logical file is based on only one physical
file member.
When sequential access is specified for a logical file, records in the file are
accessed through the access path created by the user with create file options.
Users can expect lengthy delays in OPEN OUTPUT processing for extremely large rel-
ative files (over 1,000,000 records), such as when @NOMAX is specified on the create
file command.
┌─────┬─────┬──────┬────────┬──────┬───────┬───────┬─────────┬────────┬───────┬────────┬────────┐
│ │ │ │ │ │ │ │ │ │ │ │ SELECT │
│ │ │ │ │ │ │ │ │ │ │ │ CLAUSE │
│ ORG │ ACC │ DEV │ OPEN │ READ │ WRITE │ START │ REWRITE │ DELETE │ CLOSE │ FORMAT │ KEY IS │
├─────┼─────┼──────┼────────┼──────┼───────┼───────┼─────────┼────────┼───────┼────────┼────────┤
│ S │ S │ ANY │ INPUT │ X │ │ │ │ │ X │ │ │
│ S │ S │ ANY │ OUTPUT │ │ X(F1) │ │ │ │ X │ A1 │ │
│ S │ S │ ANY │ I-O │ X │ │ │ X │ │ X │ │ │
│ S │ S │ ANY │ EXTEND │ │ X │ │ │ │ X │ │ │
├─────┼─────┼──────┼────────┼──────┼───────┼───────┼─────────┼────────┼───────┼────────┼────────┤
│ I │ S │ D/DB │ INPUT │ X │ │ X │ │ │ X │ B1 │ C1 │
│ I │ S │ D/DB │ OUTPUT │ │ X(F1) │ │ │ │ X │ B1 │ C1 │
│ I │ S │ D/DB │ I-O │ X │ │ X │ X │ X │ X │ B1 │ C1 │
├─────┼─────┼──────┼────────┼──────┼───────┼───────┼─────────┼────────┼───────┼────────┼────────┤
│ I │ R │ D/DB │ INPUT │ X │ │ │ │ │ X │ B1 │ D1 │
│ I │ R │ D/DB │ OUTPUT │ │ X(F1) │ │ │ │ X │ B1 │ D1 │
│ I │ R │ D/DB │ I-O │ X │ X │ │ X │ X │ X │ B1 │ D1 │
├─────┼─────┼──────┼────────┼──────┼───────┼───────┼─────────┼────────┼───────┼────────┼────────┤
│ I │ D │ D/DB │ INPUT │ X │ │ X │ │ │ X │ B1 │ D1 │
│ I │ D │ D/DB │ OUTPUT │ │ X(F1) │ │ │ │ X │ B1 │ D1 │
│ I │ D │ D/DB │ I-O │ X │ X │ X │ X │ X │ X │ B1 │ D1 │
├─────┼─────┼──────┼────────┼──────┼───────┼───────┼─────────┼────────┼───────┼────────┼────────┤
│ R │ S │ D/DB │ INPUT │ X │ │ X │ │ │ X │ │ C1 │
│ R │ S │ D/DB │ OUTPUT │ │ X(G1) │ │ │ │ X │ │ C1 │
│ R │ S │ D/DB │ I-O │ X │ │ X │ X │ X │ X │ │ C1 │
├─────┼─────┼──────┼────────┼──────┼───────┼───────┼─────────┼────────┼───────┼────────┼────────┤
│ R │ R │ D/DB │ INPUT │ X │ │ │ │ │ X │ │ E1 │
│ R │ R │ D/DB │ OUTPUT │ │ X(G1) │ │ │ │ X │ │ E1 │
│ R │ R │ D/DB │ I-O │ X │ X │ │ X │ X │ X │ │ E1 │
├─────┼─────┼──────┼────────┼──────┼───────┼───────┼─────────┼────────┼───────┼────────┼────────┤
│ R │ D │ D/DB │ INPUT │ X │ │ X │ │ │ X │ │ E1 │
│ R │ D │ D/DB │ OUTPUT │ │ X(G1) │ │ │ │ X │ │ E1 │
│ R │ D │ D/DB │ I-O │ X │ X │ X │ X │ X │ X │ │ E1 │
├─────┼─────┼──────┼────────┼──────┼───────┼───────┼─────────┼────────┼───────┼────────┼────────┤
│ T │ S │ W │ I-O │ X │ X │ │ │ │ X │ H1 │ │
├─────┼─────┼──────┼────────┼──────┼───────┼───────┼─────────┼────────┼───────┼────────┼────────┤
│ T │ D │ W │ I-O │ X(K1)│ X(K1) │ │ X │ │ X │ I1 │ J1 │
├─────┴─────┴──────┴────────┼──────┴───────┴───────┴─────────┼────────┴───────┴────────┴────────┤
│ORG: │ ACC: │ DEV: │
│ │ │ │
│ S = Sequential │ S = Sequential │ ANY = Any Device │
│ R = Relative │ R = Random │ D = DISK │
│ I = Indexed │ D = Dynamic │ DB = DATABASE │
│ T = TRANSACTION │ │ W = WORKSTATION │
└───────────────────────────┴────────────────────────────────┴──────────────────────────────────┘
When commitment control is used for data base files, records in those files are
subject to either a high lock level LCKLVL (@ALL) or a low lock level LCKLVL(@CHG).
With a low lock level (@CHG), all records that are changed (rewritten, deleted, or
added) in files under commitment control are locked until a COMMIT or ROLLBACK
statement is successfully processed. With a high lock level (@ALL), all records
accessed, whether for input or output, are locked until a COMMIT or ROLLBACK is suc-
cessfully processed. For both record locking levels, no other job can modify data in
locked records until the COMMIT or ROLLBACK has been successfully completed. (A
locked record can only be modified within the same job and through the same
physical or logical file.)
The lock level also governs whether locked records can be read. With a high lock
level (@ALL), you cannot read locked records in a data base file.
With a low lock level (@CHG), you can read locked records in a data base file, pro-
vided the file is opened as INPUT in your job.
Other jobs, where files are not under commitment control, can always read locked
records, regardless of the lock level used, provided the files are opened as INPUT.
Because it is possible in some cases for other jobs to read locked records, data
can be accessed before it is permanently committed to a data base. If a ROLLBACK
statement is processed after another job has read locked records, the data
accessed will not reflect the contents of the data base.
Figure 62 on page 248 shows record locking considerations for files with and
without commitment control.
┌────────┬────────────┬──────────────────────────────────┬───────────────────────────────────┐
│ VERB │ OPEN MODE │ LOCK LEVEL │ DURATION OF RECORD LOCK │
│ │ │ ├───────────────────────────────────┘
│ │ │ │ Next I-O COMMIT or
│ │ │ │ Operation ROLLBACK
│ │ │ │ │ │
│ │ │ │ m m
├────────┼────────────┼──────────────────────────────────┼────────────────┬──────────────────┐
│ │ │ │ DELETE │
│ DELETE │ I-O │ Without Commitment Control │ │ │
│ │ │ │ . │
│ │ ├─────────────────────────┬────────┤ │ │
│ │ │ With Commitment │ @CHG │ .──────────────────────────────g│
│ │ │ Control ├────────┤ │ │
│ │ │ │ @ALL │ .──────────────────────────────g│
├────────┼────────────┼─────────────────────────┴────────┼────────────────┼──────────────────┤
│ │ │ │ READ │
│ READ │ INPUT │ Without Commitment Control │ │ │
│ │ │ │ . │
│ │ ├─────────────────────────┬────────┤ │ │
│ │ │ With Commitment │ @CHG │ . │
│ │ │ Control ├────────┤ │ │
│ │ │ │ @ALL │ .──────────────────────────────g│
├────────┼────────────┼─────────────────────────┴────────┼────────────────┼──────────────────┤
│ │ │ │ READ │
│ READ │ I-O │ Without Commitment Control │ │ │
│ │ │ │ .───────────g │
│ │ ├─────────────────────────┬────────┤ │ │
│ │ │ With Commitment │ @CHG │ .───────────g │
│ │ │ Control ├────────┤ │ │
│ │ │ │ @ALL │ .──────────────────────────────g│
├────────┼────────────┼─────────────────────────┴────────┼────────────────┼──────────────────┤
│ │ │ │ REWRITE │
│ REWRITE│ I-O │ Without Commitment Control │ │ │
│ │ │ │ . │
│ │ ├─────────────────────────┬────────┤ │ │
│ │ │ With Commitment │ @CHG │ .──────────────────────────────g│
│ │ │ Control ├────────┤ │ │
│ │ │ │ @ALL │ .──────────────────────────────g│
├────────┼────────────┼─────────────────────────┴────────┼────────────────┼──────────────────┤
│ │ │ │ START │
│ START │ INPUT │ Without Commitment Control │ │ │
│ │ │ │ . │
│ │ ├─────────────────────────┬────────┤ │ │
│ │ │ With Commitment │ @CHG │ . │
│ │ │ Control ├────────┤ │ │
│ │ │ │ @ALL │ .──────────────────────────────g│
├────────┼────────────┼─────────────────────────┴────────┼────────────────┼──────────────────┤
│ │ │ │ START │
│ START │ I-O │ Without Commitment Control │ │ │
│ │ │ │ .───────────g │
│ │ ├─────────────────────────┬────────┤ │ │
│ │ │ With Commitment │ @CHG │ .───────────g │
│ │ │ Control ├────────┤ │ │
│ │ │ │ @ALL │ .──────────────────────────────g│
├────────┼────────────┼─────────────────────────┴────────┼────────────────┼──────────────────┤
│ │ │ │ WRITE │
│ WRITE │ I-O │ Without Commitment Control │ │ │
│ │ │ │ . │
│ │ ├─────────────────────────┬────────┤ │ │
│ │ │ With Commitment │ @CHG │ .──────────────────────────────g│
│ │ │ Control ├────────┤ │ │
│ │ │ │ @ALL │ .──────────────────────────────g│
├────────┼────────────┼─────────────────────────┴────────┼────────────────┼──────────────────┤
│ │ │ │ WRITE │
│ WRITE │ OUTPUT │ Without Commitment Control │ │ │
│ │ │ │ . │
│ │ ├─────────────────────────┬────────┤ │ │
│ │ │ With Commitment │ @CHG │ .──────────────────────────────g│
│ │ │ Control ├────────┤ │ │
│ │ │ │ @ALL │ .──────────────────────────────g│
└────────┴────────────┴─────────────────────────┴────────┴────────────────┴──────────────────┘
Figure 62. Record Locking Considerations with and without Commitment Control
Note: A WRITE is not considered an update operation; therefore, the record lock
will not be released.
A file under commitment control can be closed or opened without affecting the
status of changes made since the last commitment boundary. A COMMIT must still
be issued to make the changes permanent, or a ROLLBACK issued to cancel the
changes. A COMMIT statement, when processed, leaves files in the same open or
closed state as before processing.
All files under commitment control within the same job must be journaled to the
same journal.
Commitment control must also be specified outside the COBOL language through
the OS/400 control language (CL). The Begin Commitment Control (BGNCMTCTL) CL
command establishes the capability for commitment control and sets the level of
record locking at the high level (@ALL), or the low level (@CHG). The BGNCMTCTL
command does not automatically initiate commitment control for a file. That file
must also be specified in the COMMITMENT CONTROL clause of the I-O-CONTROL para-
graph within the COBOL program. The commitment control environment is normally
ended by using the End Commitment Control (ENDCMTCTL) CL command. This
causes any uncommitted changes for data base files under commitment control to
be cancelled. (An implicit ROLLBACK is processed.)
Note: The ability to prevent reading of uncommitted data that has been changed
is a function of commitment control and is only available if you are running under
commitment control. Normal (non-commit) data base support is not changed by the
commitment control extension, and allows reading of locked records when a file
that is opened only for input is read. Try to use files consistently. Typically, files
should always be run under commitment control or never be run under commitment
control.
GX21-7754-1 UM/060*
D ATA D E S C R IP T IO N S P E C IF IC AT IO N S Printed in U.S.A.
International Business Machines
*Num ber of sheets per pa d ma y va ry slightly.
D a t a T y p e /( b A / P / S / B A / S / X / Y / N / I / W )
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
Segmentation
Use of segmentation increases the compile and run times of the COBOL program.
The segmentation feature is provided only for compatibility with other systems. It is
not necessary to be concerned with storage management when using AS/400
COBOL programs.
Debugging
COBOL source language debugging is provided to help the COBOL programmer
debug a program that is not functioning as expected. Use of this facility increases
the compile and run times of a COBOL program.
*NORANGE Option
This option of the GENOPT parameter of the CRTCBLPGM command removes the run-
time checks for subscript ranges. If frequent references to tables are made and the
subscripts always reference elements within the table, use of this option can
improve performance.
Indicators
If you use indicators in a separate indicator area (INDARA keyword specified in DDS)
instead of in the record area, the use of the OCCURS clause to specify a table with up
to 99 indicators can improve performance.
Commitment Control
Generally, the use of commitment control increases the run time of a COBOL
program. In addition, the record locking which results from the use of commitment
control by a job may cause delays for other users attempting to access the same
file.
Program Loops
When a program repeatedly processes the same series of instructions, and it is
apparent that this will continue indefinitely, the program is in a loop. To identify
loops, you can use information known about the program itself, as follows:
Time: If the actual run time is substantially exceeding the expected run time,
the program could be in a loop.
I-O operations: If no input/output operations are taking place and I-O is
expected to be occurring repeatedly, the program is probably in a loop.
A possible variation of this case is when a conditional statement exists, but the
condition cannot be met or the statement does not branch (through a GO TO state-
ment) to a paragraph outside the range of the loop.
For a job failure (either because of user or system error), files under commitment
control are restored as part of job termination to the files’ status at the previous
commitment boundary.
Because files under commitment control are rolled back after system or process
failure, this feature may be used to aid in restarting. You can create a separate
record to store data which may be useful should it become necessary to restart a
job. This restart data can include items such as totals, counters, record key values,
relative key values, and other relevant processing information from an application.
By having the above restart data in a file under commitment control, that data too
will be permanently stored in the data base when a COMMIT statement is issued.
When a ROLLBACK occurs after job or process failure, you may retrieve a record of
the extent of processing successfully processed before failure. Note that the above
method is only a suggested programming technique and will not always be suitable,
depending on the application.
For potentially recoverable I-O errors on TRANSACTION files, the system initiates
action in addition to the steps that must be taken in the application program to
attempt error recovery.
By examining the file status after an I-O operation, the application program can
determine whether a recovery from an I-O error on the TRANSACTION file may be
possible. If the File Status Key has a value of 9N, the application program may be
able to recover from the I-O error. A recovery procedure must be coded as part of
the application program and varies depending on whether a single device was
acquired by the TRANSACTION file or whether there were multiple devices attached.
For a description of major/minor return codes that may aid in diagnosing I-O errors
on the TRANSACTION file, see the Data Management Guide.
Conditioning
Location
And/Or/Comment (A/O/*)
N a m e T y p e /( b / R / K / S / O )
Co ndition Na me
U s a g e (/b / O / I / B / H / M )
N am e Length Functions
Referen ce (R)
Sequence
Number
Form Type
Positions
In dicator
In dicator
In dicator
Reserved
D e c im a l
Not (N)
Not (N)
Not (N)
Line Pos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
A * D I S P L AY F I L E F OR E R R OR R E COV E R Y E X AMP L E
A *
A I ND A R A
A R F OR MA T 1 C F 0 1 ( 0 1 ' E ND OF P R OG R A M ' )
A *
A 1 2 2 8 ' E N T E R I NP U T '
A I NP U T F L D 5 I 1 2 4 2
A 2 8 2 6 ' F 1 = T E RM I NA T E '
A
A
A
A
A
A
A
A
A
A
A
A
1 This defines processing that takes place when an I-O error occurs on RECOVFILE.
2 This prints out information to help in diagnosing the problem.
3 If the file-status equals 9N (temporary error), and no previous error recovery has been attempted for
this I-O operation, error recovery is now attempted.
4 If recovery was previously attempted, it is not attempted now. This is done to avoid program
looping.
5 Recovery consists of dropping, then reacquiring, the program device on which the I-O error
occurred.
6 The mainline of the program consists of writing to and reading from a device until the user signals
an end to the program by pressing F1.
7 If the WRITE operation failed but recovery was done, the WRITE is attempted again.
8 If the READ operation failed, processing will continue by writing to the device again, and then
attempting the READ again.
Figure 64 (Part 4 of 4). Example of Error Recovery Procedure
Initialization of Storage
The first time a COBOL program in a run unit is called, its storage is initialized.
Storage is initialized again under the following conditions:
The run unit is terminated, then reinitiated.
The program is cancelled (COBOL CANCEL statement, RPG/400 FREE operation,
CL command RCLRSC), then called again.
The following examples illustrate the use of the EXIT PROGRAM and STOP RUN state-
ments in different parts of a run unit.
The example in Figure 65 on page 263 shows a single run unit.
The example in Figure 66 on page 264 shows multiple run units.
The example in Figure 67 on page 265 shows a run unit with a shared
program that is both a subprogram and a main program.
CALL
RUN UNIT A LEVEL
┌─ ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ──┐
│ │
┌─────────────────┐
│ │ PGMA │ │
│ │ n
│ │ Main │ │
│ Program COBOL │
│ └────────┬────────┘ │
│
│ ┌─────────────┴──────────────┐ │
│ │
│ │ │ │
┌────────┴────────┐ ┌────────┴────────┐
│ │ PGMB │ │ PGMC │ │
│ │ │ │ n + 1
│ │ │ │ │ │
│ COBOL │ │ Non-COBOL │
│ └────────┬────────┘ └────────┬────────┘ │
│ │
│ │ │ │
┌───────────┴─────────┐ ┌─────────┴────────────┐
│ │ │ │ │ │
┌──────┴───────┐ ┌───┴────────┴───┐ ┌────────┴───────┐
│ │ PGMD │ │ PGME │ │ PGMF │ │
│ │ │ │ │ │ n + 2
│ │ │ │ │ │ │ │
│ COBOL │ │ COBOL │ │ Non-COBOL │
│ └──────────────┘ └────────────────┘ └────────────────┘ │
└─ ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ──┘
┌─────────────────┐
│ PGMA │
│ │ n
│ │
│ Non-COBOL │
└────────┬────────┘
│
┌─────────────┴──────────────┐
RUN UNIT B │ │ RUN UNIT C
┌─ ── ── ── ── ── ── ┼─ ── ── ── ──┐ ┌─ ── ── ── ┼─ ── ── ── ── ── ── ─ ─┐
┌────────┴────────┐ │ │ ┌────────┴────────┐ │
│ │ PGMB │ │ PGMC │
│ │ │ │ │ │ │ n + 1
│ │ Main │ │ Main │
│ Program COBOL │ │ │ │ Program COBOL │ │
│ └────────┬────────┘ └────────┬────────┘
│ │ │ │ │
│ │ ┌─ ── ── ── ──┘ │
┌───────────┴──┼──────┐ │ ┌─────────┴────────────┐ │
│ │ │ └── ─┼─ ── ─┐ │
┌──────┴───────┐ │ ┌───┴────────┴───┐ ┌────────┴───────┐ │
│ │ PGMD │ │ PGME │ │ │ PGMF │
│ │ │ │ │ │ │ │ n + 2
│ │ │ │ │ │ │ │
│ Non-COBOL │ │ │ COBOL │ │ COBOL │ │
│ └──────────────┘ └────────────────┘ │ └────────────────┘
└─ ── ── ── ── ── ── ── ┼─ ── ── ── ── ── ── ──┘ │
└─ ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ──┘
CALL
LEVEL
┌─────────────────┐
│ PGMA │
│ │ n
│ │
│ Non-COBOL │
└────────┬────────┘
│
┌─────────────┴──────────────┐
RUN UNIT B │ │
┌── ── ── ── ── ── ──│── ── ── ── ─┐ │
│ ┌────────┴────────┐ │ ┌────────┴────────┐
│ PGMB │ │ PGMC │
│ │ │ │ │ │ n + 1
│ Main │ │ │
│ │ Program COBOL │ │ │ Non-COBOL│
└────────┬────────┘ └────────┬────────┘
│ │ └─ ── ── ── ─┐ │
│ │ │
│ ┌───────────┴─────────┐ ┌─────────┴────────────┐
│ RUN│ UNIT E │ │ RUN│ UNIT F
│ │ ┌─ ── ┼─ ── ── ┼─ ── ┐ ┌─ ── ── ──│── ── ── ┐
┌──────┴───────┐ │ ┌───┴────────┴───┐ │ │ ┌────────┴───────┐ │
│ │ PGMD │ │ PGME │ │ │ PGMF │
│ │ │ │ │ │ │ │ │ │ n + 2
│ │ │ │ │ │ │Main │
│ Non-COBOL │ │ │ COBOL │ │ │ │Program COBOL │ │
│ └──────────────┘ └────────────────┘ │ └────────────────┘
└─ ── ── ── ── ── ── ┘ │ └─ ── ── ── ── ── ── ┘
└── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ──┘
The local data area can be used to pass any desired information between pro-
grams in a job. This information may be free-form data, such as informal mes-
sages, or may consist of a fully structured or formatted set of fields.
When a job is submitted, the submitting job’s local data area is copied into the sub-
mitted job’s local data area. If there is no submitting job, the local data area is
initialized to blanks.
A COBOL program can access the local data area for its job with the ACCEPT and
DISPLAY statements, using a mnemonic name associated with the function-name
LOCAL-DATA.
There is only one local data area associated with each job. If several work stations
are acquired by a single job, still only one local data area exists for that job. There
is not a local data area for each individual work station.
File Considerations
A file cannot be received as a parameter in a COBOL program. If a file is defined in
both a calling program and a called program, it is treated as two separate files.
The contents of the record area and the current record pointer in each program are
independent, unless shared files are specified in CL commands.
IDENTIFICATION DIVISION
The Identification Division must be the first division in every COBOL source
program. This division names the source program and the object program. (A
source program is the user-written COBOL program. An object program is the output
from a compilation.)
The user may also include the date the program was written, the date of compila-
tion, and other such documentary information about the program in the Identifica-
tion Division.
Format
IDENTIFICATION DIVISION.
PROGRAM-ID. program-name.
[ AUTHOR. [ comment-entry ] . . . ]
[ INSTALLATION. [ comment-entry ] . . . ]
[ DATE-WRITTEN. [ comment-entry ] . . . ]
[ DATE-COMPILED. [ comment-entry ] . . . ]
[ SECURITY. [ comment-entry ] . . . ]
The Identification Division must begin with the words IDENTIFICATION DIVISION fol-
lowed by a period and a space.
Coding Example
┌───────────┬─┬───────┬───────────────────────────────────────────────────────────────────
│ │C| │
│SEQUENCE │O| A │ B
├─────┬─────┤N| │ COBOL STATEMENT
│PAGE SERIAL│T| │
├─────┼─────┼─|───────┼───────────────────────────────────────────────────────────────────
│1 3│4 6│7|8 │12 16 2 24 28 32 36 4 44
├─┬─┬─┼─┬─┬─┼─|─┬─┬─┬─┼─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
│ │ │1│ │1│ │ |I│D│E│N│T│I│F│I│C│A│T│I│O│N│ │D│I│V│I│S│I│O│N│.│ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼─┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │2│ │ |P│R│O│G│R│A│M│-│I│D│.│ │S│A│M│P│L│E│.│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │3│ │ |A│U│T│H│O│R│.│ │A│ │P│R│O│G│R│A│M│M│E│R│.│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │4│ │ |I│N│S│T│A│L│L│A│T│I│O│N│.│ │R│O│C│H│E│S│T│E│R│ │L│A│B│.│ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │5│ │ |D│A│T│E│ │W│R│I│T│T│E│N│.│ │ │8│/│1│1│/│8│8│.│ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │6│ │ |D│A│T│E│-│C│O│M│P│I│L│E│D│.│ │ │8│/│1│2│/│8│8│.│ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │&│ │ │7│ │ |S│E│C│U│R│I│T│Y│ │N│O│N│-│C│O│N│F│I│D│E│N│T│I│A│L│.│ │ │ │ │ │ │ │ │ │ │ │
├─┼─┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │ │ │ │8│ │ | │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘
PROGRAM-ID Paragraph
The first paragraph of the Identification Division must be the PROGRAM-ID paragraph.
The PROGRAM-ID paragraph specifies the name by which the program is known to
the system.
The name by which the program is known to the system can be overridden by the
PGM parameter of the CRTCBLPGM command. See “Create COBOL Program
Command” on page 37 for more information on the PGM parameter.
The system does not include the hyphen as an allowable character; therefore, if
any of the second through tenth characters are hyphens, they are converted to
zeros.
To avoid such conversions, the user should not specify program-names with
leading numerics or embedded hyphens.
The comment-entries serve only as documentation and do not affect the syntax of
the program. The comment-entries in the optional paragraphs may be any combi-
nation of characters from the EBCDIC set and may be written in Area B on one or
more lines. A hyphen is not permitted in the continuation area of Identification Divi-
sion statements.
The DATE-COMPILED paragraph provides the compilation date of the source listing.
When the comment-entry is specified, the entire entry is replaced with the current
date. When the comment-entry is omitted, the compiler adds the current date to
the DATE-COMPILED paragraph.
ENVIRONMENT DIVISION
The Environment Division, the second division of all COBOL source programs, iden-
tifies the following:
The computer on which the source program is to be compiled
The computer on which the object program is to be run
The specific main storage size required to run the object program
The linkage between the logical concept of the files and their records, and the
physical aspects of the devices on which data is stored.
The Environment Division has two sections: the Configuration Section and the
Input-Output Section.
The following shows the general format of the sections and paragraphs in the Envi-
ronment Division, and defines the order of presentation in the source program.
Format
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. source-computer-entry
OBJECT-COMPUTER. object-computer-entry
[ SPECIAL-NAMES. special-names-entry ]
┌
│ INPUT-OUTPUT SECTION.
└
FILE-CONTROL. { file-control-entry } . . .
┐
[ I-O-CONTROL. input-output-control-entry ] │
┘
The Environment Division must begin with the words ENVIRONMENT DIVISION fol-
lowed by a period and a space.
Coding Example
┌───────────┬─┬───────┬───────────────────────────────────────────────────────────────────
│ │C| │
│SEQUENCE │O| A │ B
├─────┬─────┤N| │ COBOL STATEMENT
│PAGE SERIAL│T| │
├─────┼─────┼─|───────┼───────────────────────────────────────────────────────────────────
│1 3│4 6│7|8 │12 16 2 24 28 32 36 4 44
├─┬─┬─┼─┬─┬─┼─|─┬─┬─┬─┼─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
│ │ │2│ │1│ │ |E│N│V│I│R│O│N│M│E│N│T│ │D│I│V│I│S│I│O│N│.│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼─┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │2│ │ |C│O│N│F│I│G│U│R│A│T│I│O│N│ │S│E│C│T│I│O│N│.│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │3│ │ |S│O│U│R│C│E│-│C│O│M│P│U│T│E│R│ │I│B│M│-│S│3│8│.│ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │4│ │ |O│B│J│E│C│T│-│C│O│M│P│U│T│E│R│ │I│B│M│-│S│3│8│.│ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │5│ │ |S│P│E│C│I│A│L│-│N│A│M│E│S│.│ │C│ │1│ │I│S│ │P│A│G│E│-│T│O│P│.│ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │6│ │ |I│N│P│U│T│-│O│U│T│P│U│T│ │S│E│C│T│I│O│N│.│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │7│ │ |F│I│L│E│-│C│O│N│T│R│O│L│.│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │8│ │ | │ │ │ │S│E│L│E│C│T│ │─┼─┼─┼─┼─┼─┼─┼─+ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │&│ │ │9│ │ | │ │ │ │O│R│G│A│N│I│Z│A│T│I│O│N│─┼─┼─┼─┼─┼─┼─+ │ │ │ │ │ │ │ │ │ │ │ │ │ │
└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘
Configuration Section
The Configuration Section describes the computer that compiles the source
program and the computer that runs the object program. This section optionally
relates IBM-defined function names to user-defined mnemonic-names, specifies the
collating sequence to be used, specifies a substitution for the currency sign, and/or
interchanges the functions of the comma and the period.
In the Configuration Section, the comma or semicolon can optionally separate suc-
cessive clauses within a paragraph. In each paragraph, there must be one period;
the period must be placed immediately after the last entry in the paragraph.
Format
CONFIGURATION SECTION.
OBJECT-COMPUTER. computer-name
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ ┌ ┐ @
@ │ { WORDS } │ @
@ │ , MEMORY SIZE integer { CHARACTERS } │ @
@ │ { MODULES } │ @
@ └ ┘ @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
[ , SEGMENT-LIMIT IS segment-number ].
┌
│ SPECIAL-NAMES. [ function-name IS mnemonic-name ] ...
└
[ function-name-2
┐
{IS mnemonic-name, ON STATUS IS condition-name-1 [, OFF STATUS IS condition-name-2]}│
{ }│
{IS mnemonic-name, OFF STATUS IS condition-name-2 [, ON STATUS IS condition-name-1]}│
{ }│ ...
{ON STATUS IS condition-name-1 [, OFF STATUS IS condition-name-2 ] }│
{ }│
{OFF STATUS IS condition-name-2 [, ON STATUS IS condition-name-1 ] }│
┘
┌ ┐
│ {STANDARD-1 }│
│ {NATIVE }│
│ { ┌ ┐ }│
│ { │ { THROUGH } literal-2 │ }│
│ {literal-1 │ { THRU } │ }│
│, alphabet-name IS { │ ALSO literal-3 [, ALSO literal-4 ] ... │ }│ ...
│ { └ ┘ }│
│ { ┌ ┌ ┐ ┐ }│
│ { │ │ { THROUGH } literal-6 │ │ }│
│ { │ literal-5 │ { THRU } │ │...}│
│ { │ │ ALSO literal-7 [, ALSO literal-8 ] ... │ │ }│
│ { └ └ ┘ ┘ }│
└ ┘
SOURCE-COMPUTER Paragraph
The SOURCE-COMPUTER paragraph describes the computer that compiles the source
program. The computer name should be coded as: IBM-S38.
With the exception of the WITH DEBUGGING MODE clause, the SOURCE-COMPUTER para-
graph is syntax-checked, but is treated as documentation. The WITH DEBUGGING
MODE clause is described under “DEBUGGING FEATURES” on page 517.
OBJECT-COMPUTER Paragraph
The OBJECT-COMPUTER paragraph identifies the computer that runs the object
program. Computer-name must be the first entry in the OBJECT-COMPUTER paragraph.
The other clauses can be specified in any order. The computer-name should be
coded as: IBM-S38.
When the PROGRAM COLLATING SEQUENCE clause is omitted, the EBCDIC collating
sequence is used. See Appendix F, “EBCDIC and ASCII Collating Sequences” for
the complete EBCDIC collating sequence.
SEGMENT-LIMIT Clause
The SEGMENT-LIMIT clause is described under “SEGMENTATION FEATURE” on
page 503.
SPECIAL-NAMES Paragraph
The SPECIAL-NAMES paragraph relates IBM-specified function-names to user-
specified mnemonic-names. This paragraph specifies a collating sequence that is
associated with an alphabet-name, a substitute character for the currency sign, and
the interchange of the comma and decimal point in PICTURE clauses and numeric
literals. The clauses can be specified in any order.
Function-Name-1 Clause
Note: Card devices are not supported by System/38-Compatible COBOL, even
though the devices are accepted by the syntax checker.
Table 6 shows the actions that are associated with mnemonic names for
function-name-1. Each of these functions can appear only once in the
SPECIAL-NAMES paragraph.
Function-Name-2 Clause
Function-name-2 can be defined as UPSI- through UPSI-7 or as SYSTEM-SHUTDOWN.
User Program Status Indicator (UPSI): Function-name-2 can define eight 1-byte
program switches, UPSI- through UPSI-7.
Each UPSI is a User Program Status Indicator switch. At least one condition-name
must be associated with each UPSI switch specified. UPSI- through UPSI-7 are
COBOL names that identify program switches defined outside the COBOL program
Each switch represents one byte from the eight-character SWS parameter of the
control language CHGJOB, SBMJOB, JOB, and JOBD commands as follows:
Each condition-name is formed according to the rules for a user-defined word, and
the condition-name must contain at least one alphabetic character.
In the Procedure Division, the UPSI switch status is tested through the associated
condition-name(s). Each condition-name is the equivalent of a level-88 item. The
associated mnemonic-name, if specified, is considered the conditional variable and
can be used for qualification.
Programming Notes: UPSI switches are useful for processing special conditions
within a program, such as year-beginning or year-ending processing. At the begin-
ning of the Procedure Division, an UPSI switch can be tested; if it is ON, the special
branch is taken.
Coding Example
This coding example assigns mnemonic-names to some commonly used function-
names in the SPECIAL-NAMES paragraph.
Alphabet-Name Clause
The alphabet-name clause provides a means of relating an alphabet-name to a
specified character code set or collating sequence.
The EBCDIC collating sequence is used when NATIVE is specified or when the
alphabet-name clause is omitted.
The ASCII (American National Standard Code for Information Interchange) collating
sequence is used when STANDARD-1 is specified.
Literal Phrase: The literal phrase of the alphabet-name clause processes internal
data in collating sequences other than NATIVE or STANDARD-1.
When the literal phrase is specified, the collating sequence to be used is specified
by the user 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, the literal 112 repres-
ents the EBCDIC character ?, the literal 234 represents the EBCDIC character Z,
the literal 241 represents the EBCDIC numeric character 0.
Each character in a nonnumeric literal represents that character in the EBCDIC
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 within the EBCDIC set remains unchanged.
Within one alphabet-name clause, a given character must not be specified
more than once.
Each nonnumeric literal associated with a THROUGH or ALSO phrase must be one
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 char-
acter 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
When the ALSO phrase is specified, the EBCDIC characters specified as
literal-1, literal-3, literal-4, and so on are assigned to the same position
in this collating sequence. For example, if “D” ALSO “N” ALSO 112 ALSO “%” is
specified, then for this collating sequence the characters D, N, ?, and % are all
considered to be in the same position in the collating sequence.
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 the ALSO phrase is specified, the last character specified (or defaulted to
| when any characters within the native collating sequence are not explicitly speci-
| fied) is considered to be the HIGH-VALUE character for procedural statements 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
| given above was 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 the ALSO phrase is specified, the first character specified is the LOW-VALUE
character. If the ALSO phrase example given above were specified as the low-order
characters of the collating sequence, then the LOW-VALUE character would be D.
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:
They compare as true because the values “7”, “8”, and “9” all occupy the same
position (HIGH-VALUE) in this USER-SEQUENCE collating sequence.
When the CURRENCY SIGN clause is omitted, only the dollar sign ($) may be used as
the PICTURE symbol for the currency sign.
Input-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.
Files
COBOL supports three categories of files: data base files, device files and DDM
files.
A data base file is subdivided into groups of records called members. Every file
has at least one member.
There are two types of data base 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 data base 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 attached to the system. A device file
controls the transfer of data between the physical device or a remote system, and
the program.
This manual uses the term file to refer to any of these device types.
DDM Files
Distributed Data Management (DDM) allows you to access data that resides 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.
For more information about accessing remote files, refer to the DDM Guide.
Paragraphs
The Input-Output Section is divided into two paragraphs: the FILE-CONTROL para-
graph, which names and associates the files with the external media, and the
I-O-CONTROL paragraph, which defines special input/output techniques to be used.
Format
┌
│ INPUT-OUTPUT SECTION.
└
FILE-CONTROL. { file-control-entry } . . .
┐
[ I-O-CONTROL. input-output-control-entry ] │ .
┘
The exact contents of the Input-Output Section depend on the file organization and
access methods used to process the file. The following summary gives some back-
ground for the file processing techniques available in System/38-Compatible
COBOL.
The following paragraphs describe both the types of data organization, and the
access modes available in COBOL. See Chapter 7, “System/38-Compatible
COBOL Programming Considerations” for information about COBOL file processing
in relation to AS/400 file processing.
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: With this organization, records are placed in the file
consecutively, without keys, in the order they are written (arrival sequence). Once
established, this relationship does not change, with the exception that a file can be
extended. Both data base files and device files can have sequential organization.
Indexed Organization: With this organization, each record in the file has one
embedded key that is associated with an index. The index provides a logical path
to the data records according to the contents of the associated embedded record
key data item (key sequence).
When records are inserted, updated, or deleted, they are identified solely by the
value of their record key. Thus, the value in each record key data item must be
unique and must not be changed when the record is updated. The key used for
any specific input/output request is known as the key of reference.
IBM Extension
A logical file that is opened for OUTPUT does not remove all records in the physical
file on which it is based. Instead, the file is opened to allow only write operations,
and the records are added to the file.
Relative Organization: With this organization, each record in the file is identified
by its relative record number. The file can be thought of as a serial string of areas,
each of which can contain one record. Each of these areas is identified by a rela-
tive record number; record storage and retrieval are based on this number. For
example, the first record area is addressed by relative record number 1, and the
tenth is addressed by relative record number 10, whether or not records have been
written in the second through ninth record areas. Relative files must be assigned to
DISK or DATABASE.
New relative files opened for OUTPUT are initialized with all records deleted. In the
absence of command language override, the number of records in a newly created
file is the number of records specified at file creation time including all increments.
Any attempt to extend a relative file beyond its current size results in a boundary
violation.
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
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: This access method allows records of a file to be read
and written in a serial manner. The order of reference is implicitly determined by
the position of a record in the file.
Random Access Mode: This access method allows records to be read and
written in a user-specified manner. The control of successive references to the file
is expressed by specifically defined keys supplied by the user.
In the sequential access mode, the sequence in which records are accessed is
determined by the RECORD KEY value.
In the random access mode, the sequence in which records are accessed is con-
trolled by the user. The desired record is accessed by placing the value of its
record key in the RECORD KEY data item defined for that file.
In the dynamic access mode, the user can change from sequential access to
random access by using appropriate input/output statements.
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, the sequence in which records are accessed is con-
trolled by the user. The desired record is accessed by placing its relative record
number in a RELATIVE KEY data item.
In the dynamic access mode, the user can change from sequential access to
random access by using appropriate input/output statements.
FILE-CONTROL Paragraph
The FILE-CONTROL paragraph contains one or more file-control entries. A file-control
entry associates a file in the COBOL program with an external medium, and this
entry allows specification of file organization, access mode, and other information.
The format of a file-control entry varies with the type of file described. The formats
for the FILE-CONTROL paragraph are as follows:
Note: Card devices are not supported by System/38-Compatible COBOL, even
though the card devices and related language elements are accepted by the syntax
checker.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ ┌ ┌ ┐ ┐ @
@ │ RESERVE integer-1 │ AREA │ │ @
@ │ │ AREAS │ │ @
@ └ └ ┘ ┘ @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
[ ORGANIZATION IS SEQUENTIAL ]
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ ┌ ┌ ┐ ┐ @
@ │ RESERVE integer-1 │ AREA │ │ @
@ │ │ AREAS │ │ @
@ └ └ ┘ ┘ @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ORGANIZATION IS INDEXED
┌ ┐
│ { SEQUENTIAL } │
│ ACCESS MODE IS { RANDOM } │
│ { DYNAMIC } │
└ ┘
╔══════════════════════════╗ ╔═════════════════╗
RECORD KEY IS { ║ EXTERNALLY-DESCRIBED-KEY ║ } [ ║ WITH DUPLICATES ║ ]
╚══════════════════════════╝ ╚═════════════════╝
{ data-name-2 }
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ ┌ ┌ ┐ ┐ @
@ │ RESERVE integer-1 │ AREA │ │ @
@ │ │ AREAS │ │ @
@ └ └ ┘ ┘ @
@ @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ORGANIZATION IS RELATIVE
┌ ┐
│ { SEQUENTIAL [ , RELATIVE KEY IS data-name-3 ] } │
│ { } │
│ ACCESS MODE IS { { RANDOM } , RELATIVE KEY IS data-name-3 } │
│ { { DYNAMIC } } │
└ ┘
The keyword FILE-CONTROL can appear only once, at the beginning of the
FILE-CONTROL paragraph. The word FILE-CONTROL must begin in Area A, and it
must be followed by a period and a space.
Each file-control entry must begin in Area B with a SELECT clause. The order in
which other clauses appear is not significant.
Each clause within a file-control entry can optionally be separated from the next by
a comma or semicolon followed by a space. Each file-control entry ends with a
period and a space.
Each data-name must appear in a Data Division data description entry. Each data-
name can be qualified but cannot be subscripted or indexed.
SELECT Clause
Each file-name specified in a SELECT clause must have 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.
Sequential File Considerations: The OPTIONAL phrase can be specified only for
input files with sequential organization. It must be specified for input files that are
not necessarily present each time the program is run.
ASSIGN Clause
The ASSIGN clause associates a file with an external medium. The assignment-
name makes the association between the file and the 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.
Device: This part of assignment-name specifies the type of device that the file will
use. The compiler can then check whether the file is described and used in a con-
sistent manner. See “Device Independence/Device Dependence” on page 206 for
further information.
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. For example,
assignment-name could be TAPEFILE-ABCD and ABCD could be created with a Create
diskette (CRTDKTF) CL command. The compiler would provide no diagnostics unless
the I-O verbs were used in an inconsistent manner for TAPEFILE. At run time,
OS/400 could either issue an escape message or ignore the function if it was not
applicable to the device. See the System/38 CPF Programmer's Guide for further
information on overriding files in relation to the System/38 environment.
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 associated with the file should
correspond to that given in the assignment-name.
For more information on how to use externally described printer files see
“FORMATFILE Files” on page 231.
Note: See “DISK and DATABASE File Considerations” on page 236 for further
information.
For data base 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 Data Base
File (OVRDBF) CL command must be used at run time to specify the member name.
This file name is the name of the OS/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.
The file name can be changed at run 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 in the
assignment-name.
Hopper must be either P or S to specify the primary or secondary hopper for card
device files. If neither P nor S is specified for a card device file, the HOPPER param-
eter on the Create Card File (CRTCRDF) or Change Card File (CHGCRDF) CL com-
mands is used.
Note: These commands are only supported on System/38.
Association must be any single-digit number from 0 through 9. It can be used only
if the primary (P) hopper is specified for the file. All unit record card files that have
the same association number are assigned to the same unit record card device,
and must use the same external file name (see Appendix B, “Associated Card File
Processing”).
SI indicates that a separate indicator area has been specified in the DDS for a
FORMATFILE or WORKSTATION file. See “Indicators” on page 92 for more information
on the use of the SI attribute.
The valid entries for each field of the assignment-name vary with the device. The
valid combinations of fields are shown in Figure 68 on page 287.
RESERVE Clause
The RESERVE clause is syntax-checked, but is treated as documentation.
ORGANIZATION Clause
The ORGANIZATION clause specifies the logical structure of the file. The file organ-
ization 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 data base files, the ORGANIZATION clause indicates the current program usage
of the file in the program. Therefore, the same data base 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 specified in other programs
that use this file.
Notes:
1. 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.
2. Card devices are not supported by the System/38-Compatible COBOL even
though the devices are accepted by the syntax checker.
AS/400 Default
File system.
Device Name File Name Hopper Associ- SI
ation
READER O QCARD96 O O N
PUNCH O QCARD96 O O N
PUNCHPRINT O QCARD96 O O N
PRINT O QCARD96 O O N
PRINTER O QPRINT N N N
FORMATFILE R N N O
TAPEFILE O QTAPE N N N
DISKETTE O QDKT N N N
DISK R N N N
DATABASE R N N N
WORKSTATION R N N O
R=Required
O=Optional
N=Not Allowed
Indexed File Considerations: For files with indexed organization, the access
mode can be SEQUENTIAL, RANDOM, or DYNAMIC.
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.
When ACCESS IS RANDOM is specified, the value placed in the RECORD KEY data item
specifies the record to be accessed.
When ACCESS IS DYNAMIC is specified, records in the file can be accessed sequen-
tially or randomly, depending on the form of the specific input/output request.
Relative File Considerations: For files with relative organization, the access
mode can be SEQUENTIAL, RANDOM, or DYNAMIC.
When ACCESS IS RANDOM is specified, the value placed in the RELATIVE KEY data
item specifies the record to be accessed.
When ACCESS IS DYNAMIC is specified, records in the file can be accessed sequen-
tially or randomly, depending on the form of the specific input/output request.
RELATIVE KEY Phrase: The RELATIVE KEY phrase specifies the relative record
number for a specific record in a relative file.
When ACCESS IS SEQUENTIAL is specified, the RELATIVE KEY phrase need not be
specified unless the START statement is used. When the START statement is used,
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 the RELATIVE KEY data item and a START statement is not
used, the value is ignored and processing begins with the first record in the file.
IBM Extension
When the file is opened, the POSITION parameter on the OVRDBF CL command can
be used to set the current record pointer. This causes processing to begin with a
record other than the first record. See the CL Reference for further information.
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.
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 data base. 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.
To ensure that the proper duplicate record is updated or deleted in a file that allows
duplicates and is processed randomly, the last input/output statement processed
prior to the processing of the REWRITE or DELETE statement must be a successfully
processed READ statement for the record to be deleted or rewritten.
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.
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), or COMP-4.
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.
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 key(s) for this
file are those that are externally described in DDS. The keys are determined by the
record formats that are copied by the COPY statement, DDS or DD format, under the
FD for this file.
The key can start at different offsets within the buffer for each format. In this situ-
ation, 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 adjacent)
fields. When using EXTERNALLY-DESCRIBED-KEY for a logical file, the key fields
defined for a record format in DDS must also be fields defined in that format.
Therefore, fields renamed in DDS, or fields that are part of concatenated fields in
DDS cannot be used as keys. 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 field(s) defined for the first record format that was copied.
This can cause unpredictable results.
Data-name-1 is the status key data item. Data-name-1 must be defined in the Data
Division as a two-character alphanumeric item and must not be defined in the File
Section.
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 run status of the statement. 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 E, “File Structure Support Summary and Status Key Values” for a
description of the possible values. See Chapter 7, “System/38-Compatible COBOL
Programming Considerations” for more information on blocking output records and
unblocking input records.
IBM Extension
An extended file status data item may be specified for TRANSACTION file processing.
See Chapter 5, “Interactive Processing Considerations and Example Programs” for
more information.
I-O-CONTROL Paragraph
The I-O-CONTROL paragraph specifies when checkpoints are to be taken and what
storage areas are to be shared by different files and optimization techniques. The
I-O-CONTROL paragraph is optional in a COBOL program.
Format
┌
│ I-O-CONTROL.
└
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ [ RERUN ON assignment-name @
@ @
@ EVERY integer-1 RECORDS OF file-name-1 ] . . . @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
┌ ┌ ┐ ┐
│ │ RECORD │ │
│ SAME │ SORT │ AREA FOR file-name-2 { , file-name-3 } . . . │ . . .
│ │ SORT-MERGE │ │
└ └ ┘ ┘
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ ┌ @
@ │ MULTIPLE FILE TAPE CONTAINS @
@ └ @
@ file-name-4 [ POSITION integer-2 ] @
@ @
@ ┐ ┐ @
@ [ file-name-5 [ POSITION integer-3 ] │ . . . │ . . . @
@ ┘ ┘ @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
╔═════════════════════════════════════════╗
║ ┌ ║
║ │ COMMITMENT CONTROL FOR file-name-6 ║
║ └ ║
║ ║
║ ┐ ║ ┐
║ [ , file-name-7 ] . . . │ ║ . │
║ ┘ ║ ┘
╚═════════════════════════════════════════╝
The keyword I-O-CONTROL can appear only once, at the beginning of the
I-O-CONTROL paragraph. The word I-O-CONTROL must begin in Area A, and it must
be followed by a period followed by a space.
Each clause within the I-O-CONTROL entry can optionally be separated from the next
by a comma or semicolon followed by a space. The clauses, when present, must
be specified in the order shown. Clauses can be specified on the same line as the
I-O-CONTROL paragraph header, or on separate lines. The I-O-CONTROL entry ends
with a period followed by a space.
RERUN Clause
The RERUN clause is syntax-checked, but is treated as documentation.
SAME Clause
The SAME clause specifies that two or more files are to use the same main storage
area during processing. The files named in a SAME clause need not have the same
organization or access.
The following discussion describes only the SAME RECORD AREA and SAME AREA
clauses. The SAME SORT AREA and SAME SORT-MERGE AREA clauses are discussed
under “SORT/MERGE” on page 491.
The SAME RECORD AREA clause and SAME AREA clause are intended to make efficient
use of main storage. However, the virtual storage architecture of the AS/400
system eliminates the need for these clauses, and the clauses are supported for
compatibility rather than for performance. Use of the SAME RECORD AREA actually
degrades performance.
The SAME RECORD AREA clause specifies that two or more files are to use the same
main storage area for processing the current record. All the files can be open at
the same time. A record in the shared storage area is considered to be both a
record of each opened output file in this SAME RECORD AREA clause, and a logical
record of the most recently read input file in this SAME RECORD AREA clause.
More than one SAME RECORD AREA clause can be included in a program; however,
the following restriction applies:
A specific file-name must not appear in more than one SAME RECORD AREA
clause.
The COMMITMENT CONTROL clause can specify only files assigned to a device type of
DATABASE. Files under commitment control may have an organization of sequential,
relative or indexed, and may have any access mode valid for a particular organiza-
tion.
The system locks records contained in files under commitment control when these
records are accessed. Records remain locked until released by a COMMIT or
ROLLBACK statement. For more information about record locking for files under com-
mitment control, see “Commitment Control Considerations” on page 247.
Note: Always try to use files in a consistent manner to avoid record locking prob-
lems, and to avoid reading records that have not yet been permanently committed
to the data base. Typically, a file should either always be accessed under commit-
ment control or never be accessed under commitment control.
External Data
External data is contained in files. A file is a collection of data records existing on
some input/output device. A file can be thought of as a group of physical records;
it can also be thought of as a group of logical records. The Data Division source
statements describe the relationship between physical and logical records. (See
the Glossary for definitions of these items.)
A physical record is a unit of data that is treated as an entity when it is moved into
or out of auxiliary storage. The size of a physical record is determined by the par-
ticular 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.
Record description entries, which follow the FD (file description) entry for a specific
file, describe the logical records in the file. These entries also describe the cate-
gory and format of data within each field of the logical record and different values
the data might be assigned.
The FD entry specifies 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),
and labeling information.
Once the relationship between physical and logical records has been established,
only logical records are made available to the COBOL program. Thus, in this
manual, a reference to records means logical records unless the term physical
records is used.
Internal Data
Program logic can develop additional data within storage. Such data is called
internal data.
The concept of logical records applies to internal data as well as to external data.
Internal 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 entries.
Data Relationships
The relationships of all data to be used in a program are defined in the Data Divi-
sion through a system of level indicators and level-numbers.
A level indicator, together with its descriptive entry, identifies each file description in
a program. Level indicators are the highest level of any data hierarchy with which
they are associated.
A level-number, together with its descriptive entry, indicates the properties of spe-
cific 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 be subordinate to level indicators, they can also be used independently to
describe internal data or data common to two or more programs.
Format
DATA DIVISION.
┌
│
│ FILE SECTION.
│
└
┌
│ [ file-description-entry,{record-description-entry } . . . ] . . .
└ ┐
┐ │
[ sort-merge-file-description-entry, { record-description-entry } . . . ] │ . . . │
┘ │
┌ ┘
│ WORKING-STORAGE SECTION.
└
┌
│ [ data-description-entry ] . . .
└
┐ ┐
[ record-description-entry ] . . . │ . . . │
┌ ┘ ┘
│ LINKAGE SECTION.
└
┌
│ [ data-description-entry ] . . .
└
┐ ┐
[ record-description-entry ] . . . │ . . . │
┘ ┘
The Data Division must begin with the words DATA DIVISION followed by a period
and a space.
In the source program, the Data Division sections must appear in the order shown.
Coding Example
┌───────────┬─┬───────┬────────────────────────────────────────
│ │C| │
│SEQUENCE │O| A │ B
├─────┬─────┤N| │
│PAGE SERIAL│T| │
├─────┼─────┼─|───────┼────────────────────────────────────────
│1 3│4 6│7|8 │12 16 2 24 28
├─┬─┬─┼─┬─┬─┼─|─┬─┬─┬─┼─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
│ │ │3│ │1│ │ |D│A│T│A│ │D│I│V│I│S│I│O│N│.│ │ │ │ │ │ │ │ │ │ │
├─┼─┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │2│ │ |F│I│L│E│ │S│E│C│T│I│O│N│.│ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │3│ │ |F│D│ │ │F│I│L│E│-│N│A│M│E│ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │4│ │ | │ │ │ │B│L│O│C│K│ │─┼─┼─┼─┼+│ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │5│ │ | │ │ │ │R│E│C│O│R│D│ │─┼─┼─┼─┼+│ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │6│ │ | │ │ │ │L│A│B│E│L│ │R│E│C│O│R│D│ │─┼─┼+│ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │7│ │ | │ │ │ │L│I│N│A│G│E│ │─┼─┼─┼─┼+│ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │8│ │ | │ │ │ │D│A│T│A│ │R│E│C│O│R│D│ │I│S│ │─┼─┼─┼+│.│
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │9│ │ | │1│ │ │D│E│S│C│R│I│P│T│I│O│N│.│ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │1│ │ │ |W│O│R│K│I│N│G│-│S│T│O│R│A│G│E│ │S│E│C│T│I│O│N│.│
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │1│1│ │ | │1│ │ │N│A│M│E│-│D│E│S│C│R│I│P│T│I│O│N│.│ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │1│2│ │ | │1│ │ │R│E│C│O│R│D│-│D│E│S│C│R│I│P│T│I│O│N│.│ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │&│ │1│3│ │ | │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘
DATA DIVISION.
FILE SECTION.
FD INPUT-DATA
BLOCK CONTAINS 1 RECORDS
RECORD CONTAINS 8 CHARACTERS
LABEL RECORDS ARE STANDARD
DATA RECORDS ARE GEN-INFO SALES-DATA.
1 GEN-INFO.
3 EMPLOYEE-NAME.
5 FIRST-NAME PIC X(12).
5 LAST-NAME PIC X(12).
3 SOC-SEC-NUMBER PIC 9(9).
3 CHECK-SSN
REDEFINES SOC-SEC-NUMBER PIC X(9).
3 AGE PIC 99.
3 BIRTH-DATE.
5 B-MONTH PIC 99.
5 B-DAY PIC 99.
5 B-YEAR PIC 99.
3 ANNUAL-SALARY PIC 9(5)V99.
3 CHECK-SALARY
REDEFINES ANNUAL-SALARY PIC X(7).
@ THIS REDEFINES WILL BE USED TO SEE IF THE FIELD IS BLANK.
3 RECORD-ID PIC X.
3 FILLER PIC X(31).
1 SALES-DATA.
3 SALES-SSN PIC 9(9).
3 SALES-LOCATION PIC XX.
88 MICHIGAN VALUE IS "MI"
88 EASTERN-REGION VALUES ARE "PA" "NY"
88 HEADQUARTERS VALUES ARE "BA" THRU "BZ".
3 TOTAL-COMMISSION PIC 9(5)V99.
3 RECORD-CODE PIC X.
3 FILLER PIC X(61).
FD REPORT-OUT
LABEL RECORDS ARE OMITTED
RECORD CONTAINS 132 CHARACTERS
LINAGE IS 66 LINES
FOOTING 6 LINES AT TOP 4 LINES AT BOTTOM 4
DATA RECORD IS PRINT-OUT.
1 PRINT-OUT PIC X(132).
WORKING-STORAGE SECTION.
1 RECORDS-IN PIC 9(6) VALUE ZEROS.
1 DECLARATIVE-ERRORS PIC 9(4) VALUE ZEROS.
1 EOF-SW PIC X VALUE ZERO.
1 BAD-DATA-COUNTER PIC 9(3) VALUE ZEROS.
1 CHECK-IT PIC XX.
1 PRINT-FIELDS-EDITED.
3 FILLER PIC X(14) VALUE SPACES.
3 TOTAL-SALARY PIC $$$,$$$.99BB.
3 COMMISSION-COSTS PIC $@@,@@@,@@@.99B.
3 FILLER PIC X(65) VALUE ALL "-".
3 FILLER PIC X(12)
VALUE "---END---JOB".
1 SALARY-COUNTER PIC 9(6)V99 VALUE ZEROS.
1 COMMISSION-COUNTER PIC 9(6)V99 VALUE ZEROS.
File Section
The File Section contains a description of all externally stored data (FD) and a
description of each sort-merge file (SD) used in the program.
The File Section must begin with the header FILE SECTION followed by a period.
The File Section contains file description entries and sort-merge file description
entries. Each entry is followed by its associated record description entry (or
entries).
In a COBOL program, the file description entries (beginning with the level indicators
FD and SD) represent the highest level of organization in the File Section. The file
description entry provides information about the physical structure and identification
of a file, and gives the record-name(s) associated with that file. For further
description of the format and the clauses required in a file description entry, see
“File Description Entry” on page 300. See “Data Division–SORT/MERGE” on
page 493 for a complete discussion of the sort-merge file description entry.
The record description entry consists of a set of data description entries that
describe the records contained within a particular file. More than one record
description entry can be specified; each is an alternative description of the same
storage area. For the format and the clauses required within the record description
entry, see “Data Description” on page 309 in this chapter.
IBM Extension
The record description entry for a file can be specified using the Format 2 COPY
statement. 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 “Format 2 COPY Statement, DDS
or DD Formats” on page 219 for further information.
Data areas described in the File Section should not be considered available for
processing unless the file containing the data area is open.
Working-Storage Section
The Working-Storage Section can contain description records that are not part of
data files but are developed and processed internally. These records are used for
report description, counters, and other functions necessary in processing data.
The Working-Storage Section must begin with the section header WORKING-STORAGE
SECTION followed by a period. The Working-Storage Section contains record
description entries and data description entries for noncontiguous data items.
Linkage Section
The Linkage Section describes data made available from another program.
Record description entries and data 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 can be used
to describe items in the Linkage Section with one exception: the VALUE clause
cannot be specified for any items other than level-88 items. See “Inter-Program
Communication Function” on page 507 for additional information.
Format 1–FilesT
┌
│ FD file-name
└
┌ ┐
│ BLOCK CONTAINS [ integer-1 TO ] integer-2 { RECORDS } │
│ { CHARACTERS } │
└ ┘
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ LABEL { RECORD IS } { STANDARD } @
@ { RECORDS ARE } { OMITTED } @
@ ┌ @
@ │ VALUE OF user-name-1 IS { data-name-1 } @
@ │ { literal-1 } @
@ └ @
@ ┌ ┐ ┐ @
@ │ , user-name-2 IS { data-name-2 } │ ... │ @
@ │ { literal-2 } │ │ @
@ └ ┘ ┘ @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
┌ ┐
│ DATA { RECORD IS } data-name-3 [ , data-name-4 ] ... │ .
│ { RECORDS ARE } │
└ ┘
┐
{ record-description-entry } ... │ ...
┘
┌ ┐
│ BLOCK CONTAINS [ integer-1 TO ] integer-2 { RECORDS } │
│ { CHARACTERS } │
└ ┘
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ LABEL { RECORD IS } { STANDARD } @
@ { RECORDS ARE } { OMITTED } @
@ ┌ @
@ │ VALUE OF user-name-1 IS { data-name-1 } @
@ │ { literal-1 } @
@ └ @
@ ┌ ┐ ┐ @
@ │ , user-name-2 IS { data-name-2 } │ ... │ @
@ │ { literal-2 } │ │ @
@ └ ┘ ┘ @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
┌ ┐
│ DATA { RECORD IS } data-name-3 [ , data-name-4 ] ... │
│ { RECORDS ARE } │
└ ┘
[ CODE-SET is alphabet-name ] .
┐
{ record-description-entry } ... │ ...
┘
┌ ┐
│ BLOCK CONTAINS [ integer-1 TO ] integer-2 { RECORDS } │
│ { CHARACTERS } │
└ ┘
┌ ┐
│ DATA { RECORD IS } data-name-3 [ , data-name-4 ] ... │
│ { RECORDS ARE } │
└ ┘
[ CODE-SET is alphabet-name ] .
┌ ┐
│ BLOCK CONTAINS [ integer-1 TO ] integer-2 { RECORDS } │
│ { CHARACTERS } │
└ ┘
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ LABEL { RECORD IS } { STANDARD } @
@ { RECORDS ARE } { OMITTED } @
@ @
@ ┌ @
@ │ VALUE OF user-name-1 IS { data-name-1 } @
@ │ { literal-1 } @
@ └ @
@ ┌ ┐ ┐ @
@ │ , user-name-2 IS { data-name-2 } │ ... │ @
@ │ { literal-2 } │ │ @
@ └ ┘ ┘ @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
┌ ┐
│ DATA { RECORD IS } data-name-3 [ , data-name-4 ] ... │
│ { RECORDS ARE } │
└ ┘
┌ ┌ ┐
│ LINAGE IS { data-name-5 } LINES │ , WITH FOOTING AT { data-name-6 } │
│ { integer-5 } │ { integer-6 } │
└ └ ┘
┌ ┐ ┌ ┐ ┐
│ , LINES AT TOP { data-name-7 } │ │ , LINES AT BOTTOM { data-name-8 } │ │ .
│ { integer-7 } │ │ { integer-8 } │ │
└ ┘ └ ┘ ┘
┐
{ record-description-entry } ... │ ...
┘
The file description entry must begin with the level indicator FD followed by a space.
The clauses that follow file-name are optional in many cases; the order of their
appearance is not significant.
However, at least one record description entry must follow the FD entry. When
more than one record description entry is specified, each entry implies a redefinition
of the same storage area. The last clause in the FD entry must be immediately fol-
lowed by a period and a space.
File-Name
The file-name must follow the level indicator, and must be the same as that speci-
fied in the associated file control entry.
The file-name must follow the rules of formation for a user-defined word; at least
one character must be alphabetic. The file-name must be unique within this
program.
The BLOCK CONTAINS clause specifies the size of a physical record. When the BLOCK
CONTAINS clause is omitted, the compiler assumes that records are not blocked.
Thus, this clause can be omitted when each physical record contains only one
complete logical record.
Format
┌ ┐
│ BLOCK CONTAINS [ integer-1 TO ] integer-2 { RECORDS } │
│ { CHARACTERS } │
└ ┘
When neither the CHARACTERS nor RECORDS phrase is specified, the CHARACTERS
phrase is assumed.
RECORDS Phrase: When the RECORDS phrase is specified, the physical record
size is the number of logical records contained in each physical record.
Note: Maximum record size is 32 767; maximum block size is 32 767. These
maximums include any control bytes required for variable blocked records; thus, the
maximum size data record for a variable-blocked record is 32 759.
If only integer-2 is specified, it specifies the exact character size of the physical
record. When integer-1 and integer-2 are both specified, they represent, respec-
tively, the minimum and maximum character size of the physical record.
Note: Each variable record contains a 4-byte header and each block contains a
4-byte header when the data is transferred to tape. However, these 4-byte headers
are provided by the system and are of no concern to the COBOL user except that
the maximum size of a variable record is restricted to 32 759.
When variable records are used, the BLOCK CONTAINS clause specifies the maximum
physical record length, while the logical record length for each record is inferred by
the compiler from the record name used in a WRITE statement. If an explicit length
is required after a READ statement, the user can obtain it through the I-O-FEEDBACK
mnemonic-name.
Format
[ RECORD CONTAINS [ integer-3 TO ] integer-4 CHARACTERS ]
The RECORD CONTAINS clause is never required because the size of each record is
completely defined in the record description entries. When this clause is specified,
the following rules apply:
Integer-3 and integer-4 must be unsigned, nonzero integers.
When both integer-3 and integer-4 are specified, integer-3 specifies the size
of the smallest data record, and integer-4 specifies the size of the largest data
record.
Integer-4 must not be specified alone unless all the records are the same size.
If all records are the same size, integer-4 specifies the exact number of char-
acters in the record.
The record size must be specified as the number of character positions needed
to store the record internally; that is, size is specified in terms of the number of
bytes occupied internally by the record’s characters, regardless of the number
of characters used to represent the item within the record. The size of a record
is determined according to the rules for obtaining the size of a group item. For
a further description of record size, see “USAGE Clause” on page 322 in this
chapter.
Note: When the RECORD CONTAINS clause is omitted, the record lengths are deter-
mined by the compiler from the record descriptions. When one of the entries within
a record description contains an OCCURS DEPENDING ON clause, the compiler uses
the maximum value of the variable length item to calculate the record length.
Programming Note: The system supports variable length physical records only for
files on tape. For all other files, the logical records are truncated or padded to the
length of the record as defined in the CRTxxxF CL command. User length in the
following table is defined as the largest record associated with the given file, as
specified by its record description.
Format
LABEL { RECORD IS } { STANDARD }
{ RECORDS ARE } { OMITTED }
IBM Extension
The LABEL RECORDS clause can be changed at run time by specifying the REELS
parameter of the Override with Tape File (OVRTAPF) CL command. See the CL
Reference for more information on this command.
OMITTED Phrase: The OMITTED phrase specifies that no labels exist for this file.
This phrase must be specified for files assigned to READER, PUNCHPRINT, PRINT,
and PRINTER. (See “FILE-CONTROL Paragraph” on page 281.)
Notes:
1. Card devices are not supported by System/38-Compatible COBOL, even though
the devices are accepted by the syntax checker.
VALUE OF Clause
The VALUE OF clause is syntax-checked, but is treated as documentation. It speci-
fies the description of an item in the label records associated with this file.
Format
┌
│ VALUE OF user-name-1 IS { data-name-1 }
│ { literal-1 }
└
┌ ┐ ┐
│ , user-name-2 IS { data-name-2 } │ ... │
│ { literal-2 } │ │
└ ┘ ┘
User-name: This name follows the rules for the formation of a user-defined word.
Format
┌ ┐
│ DATA { RECORD IS } data-name-3 [ , data-name-4 ] . . . │
│ { RECORDS ARE } │
└ ┘
Data-name-3 and data-name-4 are the names of data records and must have 01
level-number record descriptions that have the same name associated with them.
The specification of more than one data-name indicates that this file contains more
than one type of data record. Two or more record descriptions for this file occupy
the same storage area. These records need not have the same description or
length. The order in which the data-names are listed is not significant.
LINAGE Clause
The LINAGE clause specifies the depth of a logical page in terms of the number of
lines. This clause also optionally specifies the line number at which the footing area
begins, as well as the top and bottom margins of the logical page.
At run time, the printer file being used determines the physical page size. This
information is used to issue appropriate space and eject commands to produce the
logical page as defined in the LINAGE clause. Thus, the logical page can contain
multiple physical pages, or one physical page can contain multiple logical pages.
Format
┌ ┌ ┐
│ LINAGE IS { data-name-5 } LINES │ , WITH FOOTING AT { data-name-6 } │
│ { integer-5 } │ { integer-6 } │
└ └ ┘
┌ ┐ ┌ ┐ ┐
│ , LINES AT TOP { data-name-7 } │ │ , LINES AT BOTTOM { data-name-8 } │ │
│ { integer-7 } │ │ { integer-8 } │ │
└ ┘ └ ┘ ┘
The LINAGE clause can be specified only for files assigned to the device PRINTER.
See “FILE-CONTROL Paragraph” on page 281.
Integer-5 or the value in data-name-5 specifies 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 Phrase: Integer-6 or the value in data-name-6 specifies the first
line number of the footing area within the page body. The footing line number must
be greater than zero, but it must not be greater than the number for the last line of
the page body. The footing area extends between those two lines. If this phrase is
not specified, the assumed value is equal to that of the page body (integer-5 or
data-name-5).
Figure 69 on page 308 illustrates the use of each phrase of the LINAGE clause.
LINAGE Clause Considerations: The logical page size specified in the LINAGE
clause is the sum of all values specified in each phrase except the FOOTING phrase.
If the LINES AT TOP and/or the LINES AT BOTTOM phrases are zero, each logical
page immediately follows the preceding logical page with no additional spacing pro-
vided.
┌──────────────────────────────────────────────────────┐
│ U U │
│ (top │ │
│ LINES AT TOP integer-7 margin) │ │
│ │ │ │
│ & │ │
├─────────────────────────────────────────────────┼────┤
│ U │ │
│ │ │ │
│ │ Logical│
│ Page Page │
│ Body Depth │
│ │ │ │
│ WITH FOOTING integer-6─────────────────┼────────┼────┤
│ U │ │ │
│ Footing │ │ │
│ Area │ │ │
│ & & │ │
│ LINAGE integer-5────────────────────────────────┼────┤
│ U │ │
│ (bottom │ │
│ LINES AT BOTTOM integer-8 margin) │ │
│ & & │
└──────────────────────────────────────────────────────┘
If more than one FD has a LINAGE clause, then when LINAGE-COUNTER special reg-
ister is referred to in the PROCEDURE DIVISION, the user must qualify each
LINAGE-COUNTER with its related file-name. For example, LINAGE-COUNTER OF
FILE-A.
The value in LINAGE-COUNTER at any given time is the line number at which the
device is positioned within the current page. LINAGE-COUNTER can be referred to in
Procedure Division statements; LINAGE-COUNTER must not be modified by these
statements.
CODE-SET Clause
The CODE-SET clause is valid only for files assigned to TAPEFILE or DISKETTE. This
clause specifies the character code that is used to represent data on a magnetic
tape file or diskette file.
Format
[ CODE-SET IS alphabet-name ]
The CODE-SET clause specifies the algorithm for converting the character codes on
the input/output medium from or to the internal EBCDIC character set.
IBM Extension
If the CODE-SET clause is omitted, the CODE parameter of the Create Diskette File
(CRTDKTF) or the Create Tape File (CRTTAPF) CL command is used.
The CODE-SET clause can be changed at run time by specifying the CODE parameter
on the Override with Diskette File (OVRDKTF) or the Override with Tape File
(OVRTAPF) CL command. See the CL Reference for more information on these com-
mands.
Data Description
All the data used in a COBOL program is described using a uniform system of rep-
resentation. The basic concepts of data description are discussed in this chapter,
as well as the actual COBOL clauses used to describe data.
For example, in a department store’s customer file, 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, and other perti-
nent information.
Level Concepts
Because records must be divided into logical subdivisions, the concept of levels is
inherent in the structure of a record. Once a record has been subdivided, it can be
further subdivided to provide more detailed data references.
The basic subdivisions of a record (that is, those fields that are not further subdi-
vided) are called elementary items. Thus, a record can be made up of a series of
elementary items, or it can itself be an elementary item.
Level-Numbers
A system of level-numbers specifies the organization of elementary and group
items into records. Special level-numbers are also used to identify data items used
for special purposes.
Each group and elementary item in a record requires a separate entry, and each
must be assigned a level-number. The following level-numbers are used to struc-
ture records:
01 This level-number specifies the record itself and is the most inclusive
level-number possible. A level-01 entry can be either a group item or
an elementary item.
02-49 These level-numbers specify group and elementary items within a
record. Less inclusive data items are assigned higher (not neces-
sarily consecutive) level-numbers.
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 that are higher than the level-number of this group
item.
IBM Extension
Elementary items or group items that are immediately subordinate to one group
item can have unequal level-numbers. For example, group item A consists of items
B, C, and D:
1 A.
5 B PIC X(4).
4 C PIC X(2).
2 D PIC 99.
IBM does not recommend such coding practices, and this extension is provided only
for compatibility.
Figure 70 illustrates the level-number concept. Notice that all groups immediately
subordinate to the level-01 entry have the same level-number. Notice also that
elementary items from different subgroups do not necessarily have the same level-
number, and that elementary items can be specified at any level within the hier-
archy. Figure 70 shows the COBOL record-description entry in the left portion of
the figure; it shows the subdivision of the entry in the right portion of the figure.
Note: Level-numbers 01 through 09 can also be written as 1 through 9.
│F───────────────────────────────────+RECORD-ENTRYF──────────────────────────────────────+│
│ │
│F─────────────────────GROUP-1─────────────+│F────────────GROUP-2──────────────+│ │
│ │ │ │
│F───SUBGROUP-1─────+│F────SUBGROUP-2──────+│F──────SUBGROUP-3────+│ │ │
│ │ │ │ │ │
├─────────┬──────────┼──────────┬───────────┼──────────┬───────────┼────────────┼─────────┤
│ ELEM -1 │ ELEM-2 │ ELEM-3 │ ELEM-4 │ ELEM-5 │ ELEM-6 │ SUBGROUP-4 │ GROUP-3 │
└─────────┴──────────┴──────────┴───────────┴──────────┴───────────┴────────────┴─────────┘
Special Level-Numbers
Special level-numbers identify items that do not structure a record. The following
are special level-numbers:
Note: Level-77 and level-01 entries in the Working-Storage Section and Linkage
Section must be given unique data-names because neither can be qualified. If sub-
ordinate data-names can be qualified, they need not be unique.
Indentation
Successive data description entries can begin in the same column as preceding
entries, or they can be indented according to level-number. Indentation is useful for
documentation, but it does not affect the action of the compiler.
Classes of Data
All data used in a COBOL program can be divided into four classes and six catego-
ries. Every elementary item in a program belongs to one of the classes as well as
one of the categories. Every group item belongs to the alphanumeric class even if
the subordinate elementary items belong to another class and category. Figure 71
on page 313 shows the relationship of data classes and categories.
IBM Extension
Boolean data is an IBM extension that provides a means of modifying and passing
the values of the indicators associated with the display screen formats. A Boolean
value of 0 is the off status of the indicator, and a Boolean value of 1 is the on
status of the indicator.
Level of
Item Class Category
Elementary Alphabetic Alphabetic
Boolean Boolean
Numeric Numeric
Alphanumeric Numeric edited
Alphanumeric edited
Alphanumeric
Group Alphanumeric Alphabetic
Boolean
Numeric
Numeric edited
Alphanumeric edited
Alphanumeric
Numeric Items: When a numeric item is the receiving item, the following rules
apply:
The data is aligned on the assumed decimal point (PICTURE character V) and, if
necessary, truncated or padded with zeros. (An assumed decimal point is one
that has logical meaning but does not exist as a character in the data.)
If an assumed decimal point is not explicitly specified, the receiving item is
treated as though an assumed decimal point is specified immediately to the
right of the field. The data is then treated as in the preceding rule.
Numeric Edited Items: The data is aligned on the decimal point and, if neces-
sary, truncated or padded with zeros at either end, except when editing causes
replacement of leading zeros.
The standard data format uses the decimal system to represent numbers no matter
what base is used by the system. The nonnumeric data can contain any characters
that are in the native character set, that is, nonnumeric data is not limited to just the
COBOL character set or the nonnumeric COBOL characters.
When an arithmetic item is moved from a longer field to a shorter one, the compiler
truncates the data to the number of characters represented in the shorter item’s
PICTURE character-string.
For example, if a sending field with PICTURE S99999 and containing the value
+12345 is moved to a COMPUTATIONAL receiving field with PICTURE S99, the data is
truncated to +45.
Signed Data
There are two categories of algebraic signs used in COBOL: operational and editing.
Operational Signs
Operational signs (+, -) are associated with signed numeric items and indicate their
algebraic properties. The internal representation of an algebraic sign depends on
the item’s USAGE clause and optionally upon its SIGN clause. Zero is considered a
unique value regardless of the operational sign. An unsigned field is always
assumed to be positive or zero.
Editing Signs
Editing signs are associated with numeric edited items. Editing signs are PICTURE
symbols (+, -, CR, DB) that identify the sign of the item in edited output.
Format 1
level-number { data-name-1 }
{ FILLER }
[ REDEFINES data-name-2 ]
┌ ┐
│ { PICTURE } IS character-string │
│ { PIC } │
└ ┘
┌ ┐
│ { DISPLAY } │
│ { COMPUTATIONAL } │
│ { COMP } │
│ { ╔═════════════════╗ } │
│ [ USAGE IS ] { ║ COMPUTATIONAL-3 ║ } │
│ { ║ COMP-3 ║ } │
│ { ║ COMPUTATIONAL-4 ║ } │
│ { ║ COMP-4 ║ } │
│ { ╚═════════════════╝ } │
│ { INDEX } │
└ ┘
┌ ┐
│ [ SIGN IS ] { LEADING } [ SEPARATE CHARACTER ] │
│ { TRAILING } │
└ ┘
┌
│ OCCURS { integer-1 TO integer-2 TIMES DEPENDING ON data-name-3 }
│ { integer-2 TIMES }
└
┌ ┐
│ { ASCENDING } KEY IS data-name-4 [ , data-name-5 ] . . . │ . . .
│ { DESCENDING } │
└ ┘
┐
┌ ┐ │
│ INDEXED BY index-name-1 [ , index-name-2 ] . . . │ │
└ ┘ │
┘
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ ┌ ┌ ┐ ┐ @
@ │ { SYNCHRONIZED } │ LEFT │ │ @
@ │ { SYNC } │ RIGHT │ │ @
@ └ └ ┘ ┘ @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
┌ ┐
│ { JUSTIFIED } RIGHT │
│ { JUST } │
└ ┘
[ VALUE IS literal ] .
Format 2
┌ ┐
66 data-name-1 RENAMES data-name-2 │ { THROUGH } data-name-3 │ .
│ { THRU } │
└ ┘
Format 3
┌ ┐
88 condition-name { VALUE IS } literal-1 │ { THROUGH } literal-2 │
{ VALUES ARE } │ { THRU } │
└ ┘
┌ ┌ ┐ ┐
│ literal-3 │ { THROUGH } literal-4 │ │ . . . .
│ │ { THRU } │ │
└ └ ┘ ┘
Format 1
This format is used for record description entries in all sections and for level-77
entries in the Working-Storage and Linkage Sections. The following rules apply:
Level-number can be any number from 01 through 49 or 77. Level-numbers
from 01 through 09 can be coded as 1 through 9.
Format 2
This format regroups previously defined items. The following rules apply:
A level-66 entry cannot rename another level-66 entry, nor can it rename a
level-01, level-77, or level-88 entry.
All level-66 entries associated with one record must immediately follow the last
data description entry in that record.
The entry must end with a period followed by a space.
Format 3
This format describes condition-names. A condition-name is a user-specified name
that associates value(s) and/or a range(s) of values with a conditional variable.
A conditional variable is a data item that can assume one or more values that can,
in turn, be associated with a condition-name. The following rules for condition-
name entries apply:
Any entry beginning with level-number 88 is a condition-name entry.
The condition-name entries associated with a particular conditional-variable
must immediately follow the conditional variable entry. The conditional variable
can be any elementary data description entry except another condition-name,
index data item, or level-66 entry.
A condition-name can be associated with a group item data description entry.
The following rules apply:
– The condition-name value must be specified as a nonnumeric literal or figu-
rative constant.
– The size of the condition-name value must not exceed the sum of the sizes
of all the elementary items within the group.
– No element within the group may contain a JUSTIFIED or SYNCHRONIZED
clause.
– No USAGE other than USAGE IS DISPLAY may be specified within the group.
Condition-names can be specified both at the group level and at subordinate
levels within the group.
The relation test implied by the definition of a condition-name at the group level
is processed in accordance with the rules for comparison of nonnumeric oper-
ands regardless of the nature of elementary items within the group.
Either a space or a comma or a semicolon followed by a space, must separate
successive operands.
Each entry must end with a period followed by a space.
Examples of both elementary and group condition-name entries are given under
“VALUE Clause” on page 328 in this chapter.
Level-Numbers
The level-number specifies the hierarchy of data within a record and also identifies
special-purpose data entries.
Format
level-number
Format
data-name
FILLER
In a data description entry, either the data-name or the keyword FILLER must be the
first word following the level-number. The data-name identifies a data item by
referring to the field, not to a particular value. This data item can assume a
number of different values during the course of a program.
The keyword FILLER specifies an elementary item in a record that is never explicitly
referred to. The word FILLER can be written anywhere in Area B.
IBM Extension
A FILLER item can be used as a group item definition. Subordinate data items can
then be referenced by the appropriate data-name.
REDEFINES Clause
The REDEFINES clause allows the same storage area to be described by different
data description entries.
Format
level-number data-name-1 REDEFINES data-name-2
Level-number and data-name-1 are not part of the REDEFINES clause itself, and are
included in the format only for clarity.
If specified, the REDEFINES clause must be the first entry following data-name-1.
The level-number of data-name-1 and data-name-2 must be identical and must not
be level-66 or level-88.
Implicit redefinition is assumed when more than one level-01 entry subordinate to
an FD entry is written. In such level-01 entries, the REDEFINES clause must not be
specified.
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.
The data description entry for data-name-2 cannot contain a REDEFINES clause or an
OCCURS clause. However, data-name-2 can itself be subordinate to an item that con-
tains either clause. If data-name-2 is subordinate to an OCCURS clause, it must not
be subscripted or indexed in the REDEFINES clause.
The redefined item, the redefining item, and any items subordinate to them cannot
contain an OCCURS DEPENDING ON clause.
When data-name-1 is specified with a level-number other than 01, it must specify a
storage area of the same size as data-name-2.
Multiple redefinitions of the same storage area are permitted. The entries giving the
new descriptions of the storage area must immediately follow the description of the
redefined area without intervening entries that define new character positions. Mul-
tiple 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.
Data-name-1 and any subordinate entries must not contain any VALUE clauses. This
rule does not apply to condition-name entries.
Data items within an area can be redefined without their lengths being changed.
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.
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 does not supersede the pre-
vious description. Thus, if B REDEFINES A has been specified, either of the two
procedural statements MOVE X TO B and MOVE Y TO A could be processed at any
point in the program.
In the first case, the area described as B would assume the value of X. In the
second case, the same physical area (described now as A) would assume the value
of Y. If the second statement is processed immediately after the first, the value of
Y replaces the value of X in the one storage area.
The USAGE clause of a redefining data item need not be the same as that of a rede-
fined 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 (held in B) is 1111 0000 1111 1000.
Redefining B does not change the bit configuration of the data in the storage area.
Therefore, the two statements, ADD B TO A and ADD C TO A give different results.
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), and the bit configuration (truncated to two decimal digits) in the
storage area has the binary value -48.
Unexpected results can 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 processed). Unex-
pected results can also occur when a redefined item is moved to a redefining item
(from the previous example, unexpected results occur if the statement MOVE C TO B
is processed).
The REDEFINES clause can be specified for an item within the scope of any 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 can also be specified for an item subordinate to a redefining
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.
USAGE Clause
The USAGE clause specifies the format of a data item in storage. 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 cannot contradict the explicit usage of a group to which the elementary item
belongs.
The USAGE clause specifies the format in which data is represented in storage.
Consideration must be given to how the data is used in the Procedure Division.
Format
┌ ┐
│ { DISPLAY } │
│ { COMPUTATIONAL } │
│ { COMP } │
│ { ╔═════════════════╗ } │
│ [ USAGE IS ] { ║ COMPUTATIONAL-3 ║ } │
│ { ║ COMP-3 ║ } │
│ { ║ COMPUTATIONAL-4 ║ } │
│ { ║ COMP-4 ║ } │
│ { ╚═════════════════╝ } │
│ { INDEX } │
└ ┘
When the USAGE clause is not specified at either the group or elementary level,
USAGE IS DISPLAY is assumed.
DISPLAY Phrase
The DISPLAY phrase can be explicit or implicit. It specifies that the data item is
stored in character form, one character per eight-bit byte. This corresponds to the
form in which information is represented for keyboard input or for printed output.
USAGE IS DISPLAY is valid for the following types of items:
Alphabetic
Alphanumeric
Alphanumeric edited
Numeric edited
Boolean
Zoned decimal (numeric).
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.
Computational Phrases
The term computational refers to the following phrases of the USAGE clause:
COMPUTATIONAL or COMP (packed decimal)
IBM Extension
The COMPUTATIONAL phrase is specified for packed decimal items. Such an item
appears in storage as two digits per byte, with the sign contained in the four right-
most bits of the rightmost byte. A packed decimal item can contain any of the
digits 0 through 9 plus a sign. If the PICTURE of a packed decimal item does not
contain an S, the sign position is occupied by a bit configuration that is interpreted
as positive.
IBM Extension
The COMPUTATIONAL-3 phrase is specified for packed decimal items and is consid-
ered by the compiler to be equivalent to the COMPUTATIONAL phrase.
The COMPUTATIONAL-4 phrase is specified for binary data items. Such items have
decimal equivalents consisting of the decimal digits 0 through 9, plus a sign.
The amount of storage occupied by a binary data item depends on the number of
decimal digits defined in its PICTURE clause:
Digits in Storage
PICTURE Clause Occupied
1 through 4 2 bytes
5 through 9 4 bytes
10 through 18 8 bytes
INDEX Phrase
The USAGE IS INDEX clause specifies that the data item named has an indexed
format and, therefore, is an index data item. The index data item is an elementary
item that can be used to save index-name values for future reference.
┌───────────────────────────────────────────────────────────────────────────────────────────────┐
│ ITEM DESCRIPTION VALUE INTERNAL REPRESENTATION@ │
├───────────────────────────────────────────────────────────────────────────────────────────────┤
│ Zoned PIC S9999 DISPLAY +1234 F1 F2 F3 F4 │
│ Decimal -1234 F1 F2 F3 D4 │
│ 1234 F1 F2 F3 F4 │
│ │
│ PIC 9999 DISPLAY +1234 F1 F2 F3 F4 │
│ -1234 F1 F2 F3 F4 │
│ 1234 F1 F2 F3 F4 │
│ │
│ PIC S9999 DISPLAY SIGN LEADING +1234 F1 F2 F3 F4 │
│ -1234 D1 F2 F3 F4 │
│ 1234 F1 F2 F3 F4 │
│ │
│ PIC S9999 DISPLAY SIGN TRAILING SEPARATE +1234 F1 F2 F3 F4 4E │
│ -1234 F1 F2 F3 F4 6O │
│ 1234 F1 F2 F3 F4 4E │
│ │
│ PIC S9999 DISPLAY SIGN LEADING SEPARATE +1234 4E F1 F2 F3 F4 │
│ -1234 6O F1 F2 F3 F4 │
│ 1234 4E F1 F2 F3 F4 │
├───────────────────────────────────────────────────────────────────────────────────────────────┤
│ Packed PIC S9999 {COMP } +1234 1 23 4F │
│ Decimal {COMP-3} -1234 1 23 4D │
│ │
│ PIC 9999 {COMP } +1234 1 23 4F │
│ {COMP-3} -1234 1 23 4F │
├───────────────────────────────────────────────────────────────────────────────────────────────┤
│ Binary PIC S9999 COMP-4 +1234 4 D2 │
│ -1234 FB 2E │
│ │
│ PIC 9999 COMP-4 +1234 4 D2 │
│ -1234 4 D2 │
├───────────────────────────────────────────────────────────────────────────────────────────────┤
│ @ The internal representation of each byte is shown as two hex digits. │
│ The bit configuration for each digit is as follows: │
│ │
│ Hex Digit Bit Configuration Hex Digit Bit Configuration │
│ │
│ 8 1 │
│ 1 1 9 11 │
│ 2 1 A 11 │
│ 3 11 B 111 │
│ 4 1 C 11 │
│ 5 11 D 111 │
│ 6 11 E 111 │
│ 7 111 F 1111 │
├───────────────────────────────────────────────────────────────────────────────────────────────┤
│ 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. │
└───────────────────────────────────────────────────────────────────────────────────────────────┘
SIGN Clause
The SIGN clause specifies the position and mode of representation of the opera-
tional sign for a numeric entry.
Format
┌ ┐
│ [ SIGN IS ] { LEADING } [ SEPARATE CHARACTER ] │
│ { TRAILING } │
└ ┘
The SIGN clause can 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
either explicitly or implicitly.
Only one SIGN clause can apply to any one data description entry. The SIGN clause
is required only when an explicit description of the properties and/or position of the
operational sign is necessary.
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.
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 conver-
sion takes place automatically.
If no SIGN clause is specified for a signed numeric data description entry, the posi-
tion and mode of representation for the operational sign is determined as explained
in the USAGE clause description.
OCCURS Clause
The OCCURS clause specifies tables whose elements can be referred to by indexing
or subscripting. This clause is described under “Data Division–Table Handling” on
page 476.
INDICATOR Clause
The INDICATOR clause is discussed under “Data Description Entry–Boolean Data”
on page 94.
SYNCHRONIZED Clause
The SYNCHRONIZED clause specifies the alignment of an elementary item on a proper
boundary in storage.
Format
┌ ┌ ┐ ┐
│ { SYNCHRONIZED } │ LEFT │ │
│ { SYNC } │ RIGHT │ │
└ └ ┘ ┘
JUSTIFIED Clause
The JUSTIFIED clause overrides standard positioning rules for a receiving item of
the alphabetic or alphanumeric categories.
Format
┌ ┐
│ { JUSTIFIED } RIGHT │
│ { JUST } │
└ ┘
The JUSTIFIED clause can be specified only at the elementary level. JUST is an
abbreviation for JUSTIFIED and has the same meaning.
The JUSTIFIED clause must not be specified for a numeric item or for any item for
which editing is specified. The JUSTIFIED clause must not be specified with
level-66 (RENAMES) or level-88 (condition-name) entries.
IBM Extension
When the JUSTIFIED clause is specified for a receiving item, the data is aligned at
the rightmost character position in the receiving item, and:
If the sending item is larger than the receiving item, the leftmost characters are
truncated.
If the sending item is smaller than the receiving item, the unused character
positions at the left are filled with spaces.
When the JUSTIFIED clause is omitted, the rules for standard alignment are fol-
lowed.
The following shows the difference between standard and justified alignment when
the receiving field has a length of five character positions:
Format
[ BLANK WHEN ZERO ]
The BLANK WHEN ZERO clause can be specified only for elementary numeric or
numeric edited items. When it is specified for a numeric item, the item is consid-
ered to be a numeric edited item.
If the BLANK WHEN ZERO clause is specified, the item contains nothing but spaces
when its value is zero.
The BLANK WHEN ZERO clause must not be specified for level-66 or level-88 items.
The BLANK WHEN ZERO clause and the asterisk (*) suppression symbol must not be
specified for the same entry.
VALUE Clause
The VALUE clause specifies the initial contents of a data item, or the value(s) associ-
ated with a condition-name. The two formats for the VALUE clause are as follows:
Format 1
[ VALUE IS literal ]
Format 2
┌ ┐
88 condition-name { VALUE IS } literal-1 │ { THROUGH } literal-2 │
{ VALUES ARE } │ { THRU } │
└ ┘
┌ ┌ ┐ ┐
│ literal-3 │ { THROUGH } literal-4 │ │ . . . .
│ │ { THRU } │ │
└ └ ┘ ┘
Level-number 88 and condition-name are not part of the Format 2 VALUE clause
itself, and are included in the format only for clarity. The use of the VALUE clause
differs with the Data Division section in which it is specified.
File and Linkage Sections: The VALUE clause can only be used in condition-
name entries.
General Considerations
The keywords THRU and THROUGH are equivalent.
The VALUE clause must not be specified for any item whose length is variable; that
is, it is a group item that has an OCCURS DEPENDING ON clause subordinate to it.
For group entries, the VALUE clause must not be specified if the entry or an entry
subordinate to it contains any of the following clauses: JUSTIFIED, SYNCHRONIZED, or
USAGE (other than USAGE DISPLAY).
The VALUE clause must not conflict with other clauses in the data description entry
or in the data description of this entry’s hierarchy. The following rules apply:
Wherever a literal is specified, a figurative constant can be substituted.
If the item is numeric, all VALUE clause literals must be numeric literals. If the
literal defines the value of a Working-Storage item, the literal is aligned
according to the rules for numeric moves with one additional restriction: the
literal must not have a value that requires truncation of nonzero digits. If the
literal is signed, the associated PICTURE character-string must contain a sign
symbol (S).
All numeric literals in a VALUE clause of an item must have a value that is within
the range of values indicated by the PICTURE clause for that item. For example,
for PICTURE 99PPP, the literal must be zero or within the range 1000 through
99000. For PICTURE PPP99, the literal must be within the range .00000 through
.00099.
If the item is an alphabetic, alphanumeric, alphanumeric edited, or numeric
edited item, all VALUE clause literals must be nonnumeric literals. The number
of characters in the literal must not exceed the size of the item.
IBM Extension
If the item is Boolean, the VALUE clause literal must be a Boolean literal.
The functions of the editing characters in a PICTURE clause are ignored in deter-
mining the initial appearance of the item described. However, editing charac-
ters are included in determining the size of the item. Therefore, any editing
character must be included in the literal. For example, if the item is defined as
PICTURE +999.99 and the value is to be +12.34, then the VALUE clause should
be specified as VALUE "+12.34".
A maximum of 32 767 bytes can be initialized by means of a single VALUE
clause.
Format 1 Considerations
This format specifies the initial value of a data item in storage. Initialization is inde-
pendent of any BLANK WHEN ZERO or JUSTIFIED clause specified.
A Format 1 VALUE clause must not be specified for an entry that contains or is sub-
ordinate to an entry that contains a REDEFINES or OCCURS clause.
If the VALUE clause is specified at the group level, the literal must be a nonnumeric
literal or a figurative constant. The group area is initialized without consideration for
the subordinate entries within this group. In addition, the VALUE clause must not be
specified for subordinate entries within this group.
Format 2 Considerations
This format associates a value, values, and/or range(s) of values with a condition-
name. Each such condition-name requires a separate level-88 entry.
The VALUE clause is required in a condition-name entry and must be the only clause
in the entry. Each condition-name entry is associated with a preceding conditional
variable. Thus, every level-88 entry must always be preceded either by the entry
for the conditional variable or by another level-88 entry when several condition-
names apply to one conditional variable. Such level-88 entries implicitly have the
PICTURE characteristics of the conditional variable.
When literal-1 THRU literal-2, literal-3 THRU literal-4, and so on are speci-
fied, the condition-name is associated with more than one range of values.
If the literals are numeric, literal-1 must be less than literal-2, literal-3
must be less than literal-4, and so on.
If the literals are nonnumeric, literal-1 must appear before literal-2 in the
program collating sequence, literal-3 must appear before literal-4 in the
program collating sequence, and so on.
One or more single values and one or more ranges of values can be specified in a
single Format 2 VALUE clause.
The type of literal in a condition-name entry must be consistent with the data type
of the conditional variable. In the following example, CITY-COUNTY-INFO, COUNTY-NO,
and CITY are conditional variables; the associated condition-names immediately
follow the level-number 88. The PICTURE associated with COUNTY-NO limits the
condition-name value to a two-digit numeric literal. The PICTURE associated with
CITY limits the condition-name value to a three-character nonnumeric literal. Any
values for the condition-names associated with CITY-COUNTY-INFO cannot exceed
five characters, and the literal (because this is a group item) must be nonnumeric:
5 CITY-COUNTY-INFO.
88 BRONX VALUE "3NYC".
88 BROOKLYN VALUE "24NYC".
88 MANHATTAN VALUE "31NYC".
88 QUEENS VALUE "41NYC".
88 STATEN-ISLAND VALUE "43NYC".
1 COUNTY-NO PICTURE 99.
88 DUTCHESS VALUE 14.
88 KINGS VALUE 24.
88 NEW-YORK VALUE 31.
88 RICHMOND VALUE 43.
1 CITY PICTURE X(3).
88 BUFFALO VALUE "BUF".
88 NEW-YORK-CITY VALUE "NYC".
88 POUGHKEEPSIE VALUE "POK".
5 POPULATION...
The following example shows the use of the THRU phrase. In this example, the
number of miles a person drives to work each day is categorized.
5 MILEAGE PIC 9(2)V9.
88 LOW VALUE THRU 9.9.
88 MED VALUE 1. THRU 19.9.
88 HIGH VALUE 2. THRU 99.9.
PICTURE Clause
The PICTURE clause specifies the general characteristics and editing requirements
of an elementary item.
Format
┌ ┐
│ { PICTURE } IS character-string │
│ { PIC } │
└ ┘
The PICTURE clause must be specified for every elementary item except an indexed
data item. The PICTURE clause can be specified only at the elementary level. PIC
is an abbreviation for PICTURE and has the same meaning.
IBM Extension
+, –, CR, DB
These symbols are used as editing sign control symbols. Each symbol
represents the character position into which the editing sign control symbol
will be 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.
* Each asterisk (check protect symbol) in the character-string represents a
leading numeric character position into which an asterisk will be placed when
that position contains a zero. Each asterisk is counted in the size of the item.
The asterisk used as the zero suppression symbol and the BLANK WHEN ZERO
clause must not appear in the same entry.
‘cs’ The currency symbol in the character-string represents a character position
into which a currency symbol is to be placed. The currency symbol in a
character-string is represented either by the symbol $ or by the single char-
acter 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.
Note: Because the currency symbol can be replaced in the CURRENCY SIGN
clause, the term ‘cs’ is used throughout this book rather than the actual cur-
rency symbol ($).
Figure 73 on page 335 gives the order in which PICTURE clause symbols must be
specified.
A B P X Z 9 / , + − @ ‘cs’
Second 1 1 2 1 1 1 1 2 2
+ + CR Z Z + + A 1 1
Symbol B 0 / , . { - } { - } { } ' c s ' { * } { * } {- } {- }
DB 'cs' 'cs' 9
X
S V P P 1
B x x x x x x x x x x x x x x x x x
0 x x x x x x x x x x x x x x x x x
/ x x x x x x x x x x x x x x x x x
, x x x x x x x x x x x x x x x x
Nonfloating
Insertion
Symbols . x x x x x x x x x x
+
{ }
-
+
{- } x x x x x x x x x x x x x x
CR
{D B } x x x x x x x x x x x x x x
'cs' x
Z
{* } x x x x x x x
Z
{* } x x x x x x x x x x x
Floating +
Insertion { }
-
x x x x x x
Symbols +
{- } x x x x x x x x x x
'cs' x x x x x x
P x x x x x x x x x x
9 x x x x x x x x x x x x x x x
A
x x x x x
X
S
Other
Symbols
V x x x x x x x x x x x x
P x x x x x x x x x x x x
P x x x x x
1
Nonfloating insertion symbols + and -, floating insertion symbols Z, *, +, -, and 'cs', and other symbol P appear twice in the above
table. The leftm ost column and upperm ost row for each symbol represents its use to the left of the decim al point position. The
second appearance of the sym bol in the table represents its use to the right of the decim al point position.
2
$ is the default value for the currency symbol. This value can be replaced by a character specified in the currency SIGN clause.
An X at an intersection indicates that the sym bol(s) at the top of the column can, in a given character string, appear anywhere to
t he lef t o f t h e s y m bo l(s ) a t t he lef t o f t h e ro w.
Braces (
{ }) i n d i c a t e i t e m s t h a t a r e m u t u a l l y e x c l u s i v e .
At least one of the sym bols A, X, Z, 9, or *, or at least two of the sym bols +, -, or 'cs' must be present in a PICTU RE string.
Note: The numeral ‘1’ in the Other Symbols categories represents an IBM Exten-
sion to ANS COBOL X3.23-1974.
For example, the following two PICTURE clause specifications are equivalent:
PICTURE IS $99999.99CR
PICTURE IS $9(5).99CR
The following five symbols can each appear only once in one PICTURE
character-string:
S V . CR DB 1
IBM Extension
tary numeric items, the group is considered alphanumeric, and the literal must
therefore be nonnumeric.
The USAGE clause of the item can be DISPLAY or COMPUTATIONAL.
IBM Extension
Any associated VALUE clause must specify a nonnumeric literal. The literal is
treated exactly as specified; no editing is performed.
Alphanumeric edited items are subject to only one type of editing–simple
insertion using the symbols , B, and /.
There are four types of insertion editing: simple insertion, special insertion, fixed
insertion, and floating insertion. There are two types of suppression and replace-
ment editing: zero suppression and replacement with asterisks, and zero sup-
pression 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 in Table 8.
Simple Insertion Editing: This type of editing is valid for alphabetic, alphanu-
meric edited, and numeric edited items. The valid insertion symbols for each cate-
gory are shown in Table 9 on page 339.
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 10 on page 339.
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 will be inserted.
The actual decimal point and the assumed decimal point (the symbol V) must not
both be specified in one PICTURE character-string.
Fixed Insertion Editing: This type of editing is valid only for numeric edited items.
The following insertion symbols are used:
‘cs’ (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
leftmost character position in the character-string.
When either + or − is used as a symbol, it must represent either the leftmost or
rightmost character position in the character-string.
Floating Insertion Editing: This type of editing is valid only for numeric edited
items. The following symbols are used:
‘cs’ + −
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 in which
these characters can be inserted.
The leftmost floating insertion symbol in the character-string represents the leftmost
limit at which this character can appear in the data item. The rightmost floating
insertion symbol represents the rightmost limit at which this 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 can replace all characters at or to the right of this limit.
Any simple insertion symbols (B / ,) within or to the immediate right of the string
of floating insertion symbols are considered part of the floating character-string.
To avoid truncation, the minimum size of the PICTURE character-string must be the
sum of:
The number of character positions in the sending item
The number of nonfloating insertion symbols in the receiving item
One character for the floating insertion symbol.
Zero Suppression and Replacement Editing: This type of editing is valid only
for numeric edited items.
The symbols Z and @ are used for zero suppression. These symbols are mutually
exclusive in the PICTURE clause.
Zero suppression editing is specified by using a string of one or more of the allow-
able symbols to represent leftmost character positions in which zero suppression
and replacement editing can be processed.
Any simple insertion symbols (B / ,) within or to the immediate right of the string
of floating editing symbols are considered part of the string.
The asterisk as a suppression symbol and the BLANK WHEN ZERO clause must not be
specified for the same entry.
Examples of zero suppression and replacement editing are shown in Table 15.
RENAMES Clause
The RENAMES clause specifies alternative, possibly overlapping, groupings of ele-
mentary data items. This clause allows a single data-item to rename a group of
data items within a record.
Format
┌ ┐
66 data-name-1 RENAMES data-name-2 │ { THROUGH } data-name-3 │ .
│ { THRU } │
└ ┘
Note: Level-number 66 and data-name-1 are not part of the RENAMES clause itself,
and are included in the format only for clarity.
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.
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 occupying storage
between data-name-2 and data-name-3.
When both data-name-2 and data-name-3 are specified, the following occurs:
If data-name-2 is an elementary item, data-name-1 is defined as a group item
starting with data-name-2 and ending with data-name-3, or the last elementary
item in data-name-3, if it is a group item.
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.
Valid and invalid specifications of the RENAMES clause are given in Figure 74 on
page 345.
EXAMPLE 1 (Valid)
1 RECORD-I. │ │
5 DN-1... . │i───────────RECORD-I────────────g│
5 DN-2... . ├───────┬────────┬────────┬───────┤
5 DN-3... . │ DN-1 │ DN-2 │ DN-3 │ DN-4 │
5 DN-4... . ├───────┴────────┴────────┼───────┘
66 DN-6 RENAMES DN-1 THROUGH DN-3. │i─────────DN-6──────────g│
EXAMPLE 2 (Valid)
1 RECORD-II. │i───────────RECORD-II───────────g│
5 DN-1. │i──────── DN-1 ────────g│ │
1 DN-2... . ├────────┬───────────────┼────────┤
1 DN-2A... . │ DN-2 │ DN-2A │ DN-5 │
5 DN-1A REDEFINES DN-1. ├────────┴───────────────┼────────┘
1 DN-3A... . │i─────── DN-1A ────────g│
1 DN-3... . ├────────┬──────┬────────┤
1 DN-3B... . │ DN-3A │ DN-3 │ DN-3B │
5 DN-5... . ├────────┴──────┼────────┘
66 DN-6 RENAMES DN-2 THROUGH DN-3. │i──── DN-6 ───g│
EXAMPLE 3 (Invalid)
1 RECORD-III │i───────────RECORD-III──────────g│
5 DN-2. │i───────DN-2──────────g│ │
1 DN-3... . ├─────────┬─────────────┼─────────┤
1 DN-4... . │ DN-3 │ DN-4 │ DN-5 │
5 DN-5... . └─────────┴─────────────┴─────────┘
66 DN-6 RENAMES DN-2 THROUGH DN-3. DN-6 is indeterminate.
EXAMPLE 4 (Invalid)
1 RECORD-IV. │i───────────RECORD-IV───────────g│
5 DN-1. │i───────DN-1──────────g│ │
1 DN-2A... . ├──────────┬────────────┼─────────┤
1 DN-2B... . │ DN-2A │ DN-2B │ DN-3 │
1 DN-2C REDEFINES DN-2B. └──────────┼────────────┼─────────┘
15 DN-2... . │i─ DN-2C ──g│
├─────┬──────┤
│DN-2 │ DN-2D│
15 DN-2D... . └─────┴──────┘
5 DN-3... . DN-4 is indeterminate
Declaratives
The Declarative section provides a method of calling procedures that are run when
an exceptional condition occurs that is to be tested by the COBOL programmer.
When Declarative sections are specified, they must be grouped at the beginning of
the Procedure Division. Declarative sections are preceded by the keyword
DECLARATIVES and followed by the keywords END DECLARATIVES.
If Declarative sections are specified, the entire Procedure Division must be divided
into sections.
Procedures
A procedure is a paragraph, group of paragraphs, a section, or a group of sections
within the Procedure Division. A procedure-name is a user-defined name that iden-
tifies a section or a paragraph.
A section consists of a section header followed by zero, one, or more than one
successive paragraphs. A section-header is a section-name followed by the
keyword SECTION, an optional segment-number, followed by a period and a space.
Segment-numbers are explained under “Segmentation Feature” in Chapter 11,
“Using the Additional COBOL Functions.” A section-name is a user-defined word
that identifies a section. A section-name, because it cannot be qualified, must be
unique. A section ends immediately before the next section header, at the end of
the Procedure Division, or, in the Declaratives portion, at the keywords END
DECLARATIVES.
Format 1
PROCEDURE DIVISION [ USING data-name-1 [ , data-name-2 ] . . . ] .
┌
│ DECLARATIVES.
└
┐
END DECLARATIVES. │
┘
Format 2
┌ ┐
PROCEDURE DIVISION │ USING data-name-1 [ , data-name-2 ] . . . │ .
└ ┘
{ paragraph-name. [ sentence ] . . . } . . .
Coding Example
┌───────────┬─┬───────┬──────────────────────────────────────────────────────
│ │C| │
│SEQUENCE │O| A │ B
├─────┬─────┤N| │
│PAGE SERIAL│T| │
│1 3│4 6│7|8 │12 16 2 24 28 32 36
├─┬─┬─┼─┬─┬─┼─|─┬─┬─┬─┼─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
│ │ │4│ │1│ │ |P│R│O│C│E│D│U│R│E│ │D│I│V│I│S│I│O│N│.│ │ │ │ │ │ │ │ │ │ │ │ │
├─┼─┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │2│ │ |D│E│C│L│A│R│A│T│I│V│E│S│.│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │3│ │ |S│E│C│T│I│O│N│-│N│A│M│E│ │S│E│C│T│I│O│N│.│ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │4│ │ |P│A│R│A│G│R│A│P│H│-│N│A│M│E│S│.│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │5│ │ | │ │ │ │P│R│O│G│R│A│M│M│I│N│G│ │S│T│A│T│E│M│E│N│T│S│.│ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │6│ │/| │ │ │ │C│O│M│M│E│N│T│S│.│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │7│ │ |E│N│D│ │D│E│C│L│A│R│A│T│I│V│E│S│.│ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │8│ │ |S│E│C│T│I│O│N│-│N│A│M│E│ │S│E│C│T│I│O│N│.│ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │││ │ │9│ │ |P│A│R│A│G│R│A│P│H│-│N│A│M│E│.│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─┼┼┼─┼─┼─┼─┼─|─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│ │&│ │1│ │ │ | │ │ │ │P│R│O│G│R│A│M│M│I│N│G│ │S│T│A│T│E│M│E│N│T│S│.│ │ │ │ │
└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘
Categories of Sentences
There are three categories of sentences: conditional sentences, imperative sen-
tences, and compiler-directing sentences.
Categories of Statements
Three categories of statements are used in COBOL: conditional statements, imper-
ative statements, and compiler-directing statements.
Categories of Expressions
Two categories of expressions are used in COBOL: arithmetic expressions and con-
ditional expressions.
PROCEDURE DIVISION.
DECLARATIVES.
ERROR-IT SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON INPUT-DATA.
ERROR-ROUTINE.
IF CHECK-IT = "3" ADD 1 TO DECLARATIVE-ERRORS.
END DECLARATIVES.
BEGIN-NON-DECLARATIVES SECTION.
1-BEGIN-IT.
OPEN INPUT INPUT-DATA OUTPUT REPORT-OUT.
11-READ-IT.
READ INPUT-DATA RECORD
AT END MOVE "Y" TO EOF-SW.
IF EOF-SW NOT = "Y" ADD 1 TO RECORDS-IN.
2-MAIN-ROUTINE.
PERFORM PROCESS-DATA UNTIL EOF-SW = "Y".
PERFORM FINAL-REPORT THRU FINAL-REPORT-EXIT.
DISPLAY "TOTAL RECORDS IN = " RECORDS-IN UPON WORK-STATION.
DISPLAY "DECLARATIVE ERRORS = " DECLARATIVE-ERRORS
UPON WORK-STATION.
STOP RUN.
PROCESS-DATA.
IF RECORD-ID = "G"
PERFORM PROCESS-GEN-INFO
ELSE
IF RECORD-CODE = "C"
PERFORM PROCESS-SALES-DATA
ELSE
PERFORM UNKNOWN-RECORD-TYPE.
Arithmetic Expressions
Arithmetic expressions are used as operands of certain conditional and arithmetic
statements. An arithmetic expression can consist of any of the following:
An identifier described as a numeric elementary item
A numeric literal
Identifiers and literals, as defined in Items 1 and 2, separated by arithmetic
operators
Two arithmetic expressions, as defined in Items 1, 2, and/or 3, separated by an
arithmetic operator
An arithmetic expression, as defined in Items 1, 2, 3, and/or 4, enclosed in
parentheses.
Arithmetic Operators
The five binary arithmetic operators and two unary arithmetic operators shown in
Table 19 can be used in arithmetic expressions. The arithmetic operators are
represented by specific characters that must be preceded and followed by a space.
When parentheses are not used, or when parenthesized expressions are at the
same level of inclusiveness, the following hierarchical order is implied:
1. Unary operator
2. Exponentiation
3. Multiplication and division
4. Addition and subtraction.
An arithmetic expression can begin only with a left parenthesis, a unary operator, or
a variable (that is, an identifier or literal). An arithmetic expression can end only
with a right parenthesis or a variable. An arithmetic expression must contain at
least one reference to an identifier or literal. There must be a one-to-one corre-
spondence between left and right parentheses in an arithmetic expression; each left
parenthesis is placed to the left of its corresponding right parenthesis.
Note: The results of exponentiation are truncated after the thirteenth fractional
digit. The results of exponentiation when the exponent is noninteger are accurate
to seven digits.
┌──────────────┬────────────────────────────────────────────┐
│ │ Second Symbol │
│ ├──────────────────┬───────┬─────────┬───┬───┤
│ │ │ │ │ │ │
│ First │ Variable │ @ │ Unary + │ ( │ ) │
│ Symbol │ (identifier │ / │ Unary - │ │ │
│ │ or literal) │ @@ │ │ │ │
│ │ │ + │ │ │ │
│ │ │ - │ │ │ │
├──────────────┼──────────────────┼───────┼─────────┼───┼───┤
│ │ │ │ │ │ │
│ Variable │ - │ p │ - │ - │ p │
│ (identifier │ │ │ │ │ │
│ or literal) │ │ │ │ │ │
│ │ │ │ │ │ │
├──────────────┼──────────────────┼───────┼─────────┼───┼───┤
│ │ │ │ │ │ │
│ @ / @@ + - │ p │ - │ p │ p │ - │
│ │ │ │ │ │ │
├──────────────┼──────────────────┼───────┼─────────┼───┼───┤
│ │ │ │ │ │ │
│ Unary + or │ p │ - │ - │ p │ - │
│ Unary - │ │ │ │ │ │
│ │ │ │ │ │ │
├──────────────┼──────────────────┼───────┼─────────┼───┼───┤
│ │ │ │ │ │ │
│ ( │ p │ - │ p │ p │ - │
│ │ │ │ │ │ │
├──────────────┼──────────────────┼───────┼─────────┼───┼───┤
│ │ │ │ │ │ │
│ ) │ - │ p │ - │ - │ p │
│ │ │ │ │ │ │
└──────────────┴──────────────────┴───────┴─────────┴───┴───┘
Conditional Expressions
A conditional expression causes the object program to select alternative paths of
control, depending on the truth value of a test. Conditional expressions can be
specified in IF, PERFORM, and SEARCH statements. A conditional expression can be
specified in simple conditions and in complex conditions. Both simple and complex
conditions can be enclosed within any number of paired parentheses; parentheses
do not change the category of the condition.
Simple Conditions
There are five simple conditions: class condition, condition-name condition, relation
condition, sign condition, and switch-status condition. A simple condition has a
truth value of true or false. When a simple condition is enclosed in paired paren-
theses, its truth value is not changed.
Class Condition
The class condition determines whether a data item is alphabetic or numeric.
Format
identifier IS [ NOT ] { NUMERIC }
{ ALPHABETIC }
If the PICTURE of the identifier being tested does not contain an operational sign, the
identifier is determined to be numeric only if the contents are numeric and an oper-
ational sign is not present.
If the PICTURE of the identifier being tested does contain an operational sign, the
identifier is determined to be numeric only if the item is an elementary item, the
contents are numeric, and a valid operational sign is present.
In the EBCDIC collating sequence, valid embedded operational positive signs are
hexadecimal F, C, E, and A. Negative signs are hexadecimal D and B. The pre-
ferred positive sign is hexadecimal F, and the preferred negative sign is
hexadecimal D. For items described with the SIGN IS SEPARATE clause, valid oper-
ational signs are + (hex 4E) and - (hex 60).
The NUMERIC test cannot be used with an identifier described either as alphabetic or
as a group item that contains one or more signed elementary items. The identifier
being tested is determined to be alphabetic only if the contents consist of any com-
bination of the alphabetic characters A through Z and the space.
Condition-Name Condition
A condition-name condition causes a conditional variable to be tested to determine
whether its value is equal to any of the values associated with the condition-name
(level-88 item).
Format
condition-name
IF PRIMARY-OTHER...
(which tests for values 1, 2, 3, 5, 6)
IF PRIMARY-FOUR...
(which tests for value 4)
IF JUNIOR-HI...
(which tests for values 7, 8, 9)
IF SENIOR-HI...
(which tests for values 10, 11, 12)
Relation Condition
A relation condition causes a comparison between two operands, either of which
can be an identifier, a literal, or an arithmetic expression.
Format
{ GREATER THAN }
{ LESS THAN }
operand-1 IS [ NOT ] { EQUAL TO } operand-2
{ > }
{ < }
{ = }
Operand-1 is the subject of the relation condition; operand-2 is the object of the
relation condition. Operand-1 and operand-2 can each be an identifier, a literal, or
an arithmetic expression. The relation condition must contain at least one refer-
ence to an identifier. Except when two numeric operands are compared, operand-1
and operand-2 must have the same USAGE.
Rules for numeric and nonnumeric comparisons are given in the following para-
graphs. If either of the operands is a group item, nonnumeric comparison rules
apply. Figure 77 summarizes the permissible comparisons.
┌─────────────────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────┐
│ │ SECOND OPERAND │
│ ├───────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┤
│ │ │ │ │ │ │ FC │ ZR │ │ │ │ │ │ │ │
│ First Operand │ GR │ AL │ AN │ ANE │ NE │ NNL │ NL │ ZD │ BI │ PD │ AE │ BO │ IN │ IDI │
├─────────────────────────────┼───────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│ Group (GR) │ NN │ NN │ NN │ NN │ NN │ NN │ NN │ NN │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ Alphabetic (AL) │ NN │ NN │ NN │ NN │ NN │ NN │ NN │ NN │ │ │ │ │ │ │
├─────────────────────────────┼───────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│ Alphanumeric (AN) │ NN │ NN │ NN │ NN │ NN │ NN │ NN │ NN │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ Alphanumeric edited (ANE) │ NN │ NN │ NN │ NN │ NN │ NN │ NN │ NN │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ Numeric edited (NE) │ NN │ NN │ NN │ NN │ NN │ NN │ NN │ NN │ │ │ │ │ │ │
├─────────────────────────────┼───────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│ Figurative constants, except│ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ ZERO (FC) and nonnumeric │ NN │ NN │ NN │ NN │ NN │ │ │ NN │ │ │ │ │ │ │
│ literal (NNL) │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ Figurative constant ZERO │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ (ZR) and numeric litreal │ NN │ NN │ NN │ NN │ NN │ │ │ NU │ NU │ NU │ NU │ │ IO@ │ │
│ (NL) │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─────────────────────────────┼───────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│ Zoned decimal (ZD) │ NN │ NN │ NN │ NN │ NN │ NN │ NU │ NU │ NU │ NU │ NU │ │ IO@ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ Binary (BI) │ │ │ │ │ │ │ NU │ NU │ NU │ NU │ NU │ │ IO@ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ Packed decimal (PD) │ │ │ │ │ │ │ NU │ NU │ NU │ NU │ NU │ │ IO@ │ │
├─────────────────────────────┼───────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤
│ Arithmetic expression (AE) │ │ │ │ │ │ │ NU │ NU │ NU │ NU │ NU │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ Boolean data item (BO) or │ │ │ │ │ │ │ │ │ │ │ │ BO │ │ │
│ Boolean literal │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ Index-name (IN) │ │ │ │ │ │ │ IO@ │ IO@ │ IO@ │ IO@ │ │ │ IO │ IV │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ Index data item (IDI) │ │ │ │ │ │ │ │ │ │ │ │ │ IV │ IV │
├─────────────────────────────┴───────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┤
│ BO = Comparison as described for Boolean operands. │
│ NN = Comparison as described for nonnumeric operands. │
│ NU = Comparison as described for numeric operands. │
│ IO = Comparison as described for two index-names (by occurrence number). │
│ IV = Comparison as described for index data items (by value). │
│ Blank = Comparison is not allowed. │
│ _______________ │
│ @ Valid only if the numeric item is an integer. │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Note: The Boolean Data Item or Boolean Literal (First Operand row), and BO
(Second Operand column) represent an IBM Extension to ANS COBOL X3.23-1974.
IBM Extension
When a nonnumeric and a numeric operand are compared, the following rules
apply:
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 elementary
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 then compared with the nonnumeric operand. For further dis-
cussion of the rules for alphanumeric and group move operations, see the
“MOVE Statement” on page 436.
Numeric and nonnumeric operands can be compared only when their USAGE, explic-
itly or implicitly, is 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.
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 kinds of operands to consider:
operands of equal size and operands of unequal size.
If all pairs of characters through the last pair test as equal, the operands are con-
sidered 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.
Note: Valid comparisons for index-names and index data items are discussed
under “Table Handling” in Chapter 11, “Using the Additional COBOL Functions.”
Sign Condition
The sign condition determines whether or not the algebraic value of a numeric
operand is less than, greater than, or equal to zero.
Format
{ POSITIVE }
operand IS [ NOT ] { NEGATIVE }
{ ZERO }
The operand is POSITIVE if its value is greater than zero, NEGATIVE if its value is
less than zero, and ZERO it its value is equal to zero. An unsigned operand is
POSITIVE or ZERO.
When NOT is specified, one algebraic test is processed 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.
Switch-Status Condition
The switch-status condition determines the on or off status of an UPSI switch.
Format
condition-name
The switch-status condition tests the value associated with the condition-name.
The result of the test is true if the UPSI switch is set to the position corresponding
to condition-name.
Complex Conditions
A complex condition is a condition in which one or more logical operators act upon
one or more conditions. Complex conditions include:
Negated simple conditions
Combined conditions
Negated combined conditions.
Each logical operator must be preceded and followed by a space. The logical
operators and their meanings are shown in Table 22 on page 360.
The truth value of a complex condition depends on the truth values of the simple
conditions and negated simple conditions that make up the complex condition. The
logical operators tell the compiler how to combine these individual truth values.
Format
NOT simple-condition
The negated simple-condition gives the opposite truth value as the simple condi-
tion. That is, if the truth value of the simple-condition is true, then the truth value of
that same negated simple-condition is false.
Placing a negated simple-condition within parentheses does not change its truth
value. For example, the following two statements are equivalent:
NOT A IS EQUAL TO B.
Combined Conditions
Two or more conditions can be logically connected to form a combined condition.
Format
condition { { AND } condition } . . .
{ { OR } }
Parentheses are never needed when either AND or OR (but not both) are used exclu-
sively in one combined condition. However, parentheses might be needed to find a
final truth value when a combination of AND, OR, and NOT is used. There must a
one-to-one correspondence between left and right parentheses with each left
parenthesis to the left of its corresponding right parenthesis.
Table 23 summarizes the way in which conditions and logical operators can be
combined and parenthesized. Figure 78 illustrates the relationships between
logical operators and conditions C1 and C2 where C1 and C2 are any conditions as
defined above.
Table 23. Valid Combinations of Conditions, Logical Operators, and Parentheses in a Condi-
tional Expression
Permissible Position in Conditional Elements
When Not Leftmost, When Not Rightmost,
Can Be Immediately Can Be Immediately
Condition Element Leftmost Preceded By: Followed By: Rightmost
Simple-Condition Yes OR OR Yes
NOT AND
AND )
(
OR No Simple-Condition Simple-Condition No
AND ) NOT
(
NOT Yes OR Simple-Condition No
AND (
(
( Yes OR Simple-Condition No
NOT NOT
AND (
(
) No Simple-Condition OR Yes
) AND
)
┌───────┬────────┬────────┬────────┬─────────┬────────┬─────────┬────────┐
│Values │ Values │ C1 AND │ C1 OR │ NOT (C1 │ NOT C1 │ NOT (C1 │ NOT C1 │
│for C1 │ for C2 │ C2 │ C2 │ AND C2) │ AND C2 │ OR C2) │ OR C2 │
├───────┼────────┼────────┼────────┼─────────┼────────┼─────────┼────────┤
│True │ True │ True │ True │ False │ False │ False │ True │
├───────┼────────┼────────┼────────┼─────────┼────────┼─────────┼────────┤
│False │ True │ False │ True │ True │ True │ False │ True │
├───────┼────────┼────────┼────────┼─────────┼────────┼─────────┼────────┤
│True │ False │ False │ True │ True │ False │ False │ False │
├───────┼────────┼────────┼────────┼─────────┼────────┼─────────┼────────┤
│False │ False │ False │ False │ True │ True │ True │ True │
└───────┴────────┴────────┴────────┴─────────┴────────┴─────────┴────────┘
Figure 78. How Logical Operators Affect the Evaluation of Conditions
2. Within nested parentheses, evaluation proceeds from the least inclusive condi-
tion to the most inclusive condition.
If parentheses are not used (or are not at the same level of inclusiveness), the
combined condition is evaluated in the following order:
1. Arithmetic expressions.
2. Simple-conditions in the following order:
a. Relation
b. Class
c. Condition-name
d. Switch-status
e. Sign.
3. Negated simple-conditions in the same order as item 2.
4. Combined conditions, in the following order:
a. AND
b. OR.
5. Negated combined conditions in the following order:
a. AND
b. OR.
6. Consecutive operands at the same evaluation-order level are evaluated from
left to right. However, the truth value of a combined condition can sometimes
be determined without evaluating the truth value of all the component condi-
tions.
The component conditions of a combined condition are evaluated from left to right.
If the truth value of one condition is not affected by the evaluation of further ele-
ments of the combined condition, these elements are not evaluated. However, the
truth value of the condition will always be the same (as if the condition had been
evaluated in full), as described earlier in this paragraph.
For example:
Format
{ ┌ ┐ }
{ │ GREATER THAN │ }
{ │ LESS THAN │ }
relation-condition { { AND } [ NOT ] │ EQUAL TO │ object } . . .
{ { OR } │ > │ }
{ │ < │ }
{ │ = │ }
{ └ ┘ }
Format
[ DECLARATIVES.
[ paragraph-name. [ sentence ] . . . ] . . . } . . .
END DECLARATIVES. ]
In the Declaratives portion of the Procedure Division, each section header (with an
optional segment number) must be followed by a period and a space, and must be
followed by a USE statement followed by a period and a space. No other text can
appear on the same line. There are two forms of the USE statement:
USE AFTER EXCEPTION/ERROR
USE FOR DEBUGGING.
The USE statement itself is never processed; instead, the USE statement defines the
conditions that will cause processing of the immediately following procedural para-
graphs, which specify the actions to be taken. After the procedure is run, control is
returned to the routine that activated it.
Within a Declarative procedure, except for the USE statement itself, there must be
no reference to any nondeclarative procedure.
Format
{ file-name-1 [ , file-name-2 ] . . . }
{ INPUT }
USE AFTER STANDARD { EXCEPTION } PROCEDURE ON { OUTPUT } .
{ ERROR } { I-O }
{ EXTEND }
The words EXCEPTION and ERROR are synonymous and can be used interchangeably.
File-Name Phrase
This phrase is valid for sequential, indexed, and relative files. When this phrase is
specified, the procedure is run only for the file(s) named. No file-name can refer to
a sort-merge file. For any given file, only one EXCEPTION/ERROR procedure can be
specified. For example, if an input file is specifically named in one EXCEPTION/ERROR
procedure, there must not also be an EXCEPTION/ERROR procedure for all INPUT files.
IBM Extension
INPUT Phrase
This phrase is valid for sequential, indexed, and relative files. When this phrase is
specified, the procedure is applicable to all files opened in INPUT mode.
OUTPUT Phrase
This phrase is valid for sequential, indexed, and relative files. When this phrase is
specified, the procedure is applicable to all files opened in OUTPUT mode.
I-O Phrase
This phrase is valid for sequential, indexed, and relative files. When this phrase is
specified, the procedure is applicable to all files opened in I-O mode.
IBM Extension
EXTEND Phrase
This phrase is valid for sequential files only. When this phrase is specified, the
procedure is applicable to all files opened in EXTEND mode.
Programming Notes
EXCEPTION/ERROR Declarative procedures can be used to check the status key
values whenever an input/output error occurs. Additional information about the file
causing the error can be obtained by using data from the mnemonic-names
OPEN-FEEDBACK and I-O-FEEDBACK.
For example, an OPEN OUTPUT statement establishes a Declarative procedure for this
file, and the file is then closed without error. During later processing, if a logic error
occurs, control will go to the Declarative procedure established when the file was
opened OUTPUT.
If there is no applicable USE procedure in the program when an I-O error occurs,
processing can continue. Unless the program is terminated, or some other action
taken, other errors may occur, causing undesirable results.
Conditional Statements
A conditional statement specifies that a truth value of a condition is to be deter-
mined, and that the subsequent action of the object program depends on this truth
value. Table 16 on page 350 gives a list of the conditional statements.
Only the IF statement is discussed in this section; the other conditional statements
are discussed elsewhere in this manual.
IF Statement
The IF statement causes a condition to be evaluated, and provides for alternative
actions in the program, depending on that value.
Format
┌ ┐
│ ╔══════╗ │ ┌ ┐
IF condition │ ║ THEN ║ │ { statement-1 } │ { ELSE statement-2 } │
│ ╚══════╝ │ { NEXT SENTENCE } │ { ELSE NEXT SENTENCE } │
└ ┘ └ ┘
IBM Extension
If the condition tested is true, one of the following actions takes place:
Statement-1, if specified, is processed. If statement-1 contains a procedure
branching statement, control is transferred according to the rules for that state-
ment. If statement-1 does not contain a procedure-branching statement, the
ELSE phrase, if specified, is ignored, and control passes to the next executable
sentence.
NEXT SENTENCE, if specified, is processed; that is, the ELSE phrase, if specified,
is ignored, and control passes to the next executable sentence.
Nested IF Statements
The presence of one or more IF statements within an initial IF statement consti-
tutes a nested IF statement.
Figure 79 on page 369 shows the possible true/false combinations for the following
nested IF statement:
IF condition-1
statement-1-1
IF condition-2
IF condition-3
statement-3-1
ELSE
statement-3-2
ELSE
statement-2-2
IF condition-4
IF condition-5
statement-5-1
ELSE
statement-5-2.
True
┌───────────┐............
IF │condition-1│ &
│ │ statement 1-1
False │ │ │
┌F────────────┴───────────┘ │
│ │
│ │
│ ┌──────────────┘ True
│ & ┌───────────┐............
│ IF │condition-2│ .
│ │ │ .
│ False │ │ .
│ ┌───────────────┴───────────┘ .
│ │ ...................... True
│ │ & ┌───────────┐............
│ │ IF │condition-3│ &
│ │ │ │ statement 3-1─────────────+┐
│ │ False │ │ │
│ │ ┌─────────────┴───────────┘ │
│ │ └───────────────+ELSE statement 3-2 │
│F──┼────────────────────────────────────┘ │
│ │ │
│ └──────────────────+ELSE statement 2-2 │
│ ┌────────┘ True │
│ & ┌───────────┐............ │
│ IF │condition-4│ . │
│ │ │ . │
│ False │ │ . │
│F────────────────────────────┴───────────┘ . │
│ ..................... True │
│ & ┌───────────┐............ │
│ IF │condition-5│ & │
│ │ │ statement 5-1──+│
│ False │ │ │
│ ┌─────────────┴───────────┘ │
│ └───────────────+ELSE statement 5-2 │
│F──────────────────────────────────────────────────┘ │
│ │
│ │
└────────────────+Next sentence in COBOL source programF─────────────┘
For example, the following series of simple IF statements give results equivalent to
those achieved using the preceding nested IF statement example:
statement-1-1.
PARA-1.
statement-2-2.
IF condition-5 statement-5-1
ELSE statement-5-2.
PARA-2.
next-executable-statement.
Notice that Figure 79 on page 369 also illustrates the logic flow for the preceding
series of simple IF statements.
Input/Output Statements
COBOL input/output statements transfer data to and from files. In COBOL, the unit
of data made available to the program is a record, and the COBOL user need be
concerned only with such records. Provision is automatically made for such oper-
ations as the movement of data into buffers and/or internal storage, validity
checking, error correction (when feasible), and unblocking and blocking of records.
The description of the file in the Environment Division and the Data Division
governs which input/output statements are allowed in the Procedure Division.
For information about COBOL file processing in relation to AS/400 file processing,
see Chapter 7, “System/38-Compatible COBOL Programming Considerations.” See
Appendix E, “File Structure Support Summary and Status Key Values” for a file
structure support summary.
Status Key
If the FILE STATUS clause is specified in the file-control entry, a value is placed in
the specified status key (the two-character data item named in the FILE STATUS
clause) during processing of any request on that file; the value indicates the status
of that request. The value is placed in the status key before processing of any
EXCEPTION/ERROR Declarative or INVALID KEY/AT END phrase associated with the
request.
The first character of the status key is known as status key 1; the second character
is known as status key 2. Combinations of possible values and their meanings are
shown in Appendix E, “File Structure Support Summary and Status Key Values.”
When an INVALID KEY condition occurs, the input/output statement that caused the
condition is unsuccessful. If the INVALID KEY phrase is not specified for a file, an
EXCEPTION/ERROR procedure must be specified.
The following illustrate the use of the INTO/FROM identifier phrase in an input/output
statement:
READ file-name RECORD INTO identifier.
WRITE record-name FROM identifier.
IBM Extension
The current record pointer can be positioned to any record in the file, at the
time the OPEN is issued, by using the POSITION parameter of the Override with
Data Base File (OVRDBF) command.
For a sequential access READ statement, or a dynamic access READ NEXT state-
ment, the following considerations apply:
– If an OPEN or START statement positioned the current record pointer, the
record identified by the current record pointer is made available. If this
record does not exist, the next existing record is made available.
– If a previous READ statement positioned the current record pointer, the
current record pointer is updated to point to the next existing record in the
file; that record is then made available.
IBM Extension
For a dynamic access READ FIRST statement, the current record pointer is posi-
tioned to point to the first record in the file; that record is then made available.
For a dynamic access READ LAST statement, the current record pointer is posi-
tioned to point to the last record in the file; that record is then made available.
For a dynamic access READ PRIOR statement, the current record pointer is posi-
tioned to point to the previous existing record in the file; that record is then
made available.
The setting of the current record pointer is affected only by the OPEN, START,
RETURN, READ, and ROLLBACK statements. The concept of the current record pointer
has no meaning for files with an access mode of random, for TRANSACTION files, or
for output files.
IBM Extension
ACCEPT Statement
The function of the ACCEPT statement is to obtain low volume data. The processing
of an ACCEPT statement causes the transfer of data into the specified identifier.
There is no editing or error checking of the incoming data. The formats of the
ACCEPT statement are as follows:
Format 1
ACCEPT identifier [ FROM mnemonic-name ]
Format 2
{ DATE }
ACCEPT identifier FROM { DAY }
{ TIME }
Format 3
╔══════════════════════════════════════╗
║ ACCEPT identifier FROM mnemonic-name ║
║ ║
║ [ FOR file-name ] ║
╚══════════════════════════════════════╝
Format 4
╔════════════════════════════════════════════╗
║ ACCEPT identifier-1 FROM mnemonic-name ║
║ ║
║ @@@@@@@@@@@@@@@@@@@@@@@@@@@@ ║
║ @ ┌ ┐ @ ║
║ @ │ FOR { identifier-2 } │ @ ║
║ @ │ { literal } │ @ ║
║ @ └ ┘ @ ║
║ @@@@@@@@@@@@@@@@@@@@@@@@@@@@ ║
╚════════════════════════════════════════════╝
Format 1 Considerations
This format is used to transfer data from an input/output device to the identifier.
Identifier can be any fixed length group item, or an elementary alphabetic, alphanu-
meric, or zoned decimal item.
When the FROM phrase is omitted, the ACCEPT statement obtains input from the job
input stream for batch jobs, and from the work station for interactive jobs.
The job input stream is CL request data. If there is no data in the input stream, an
exception occurs. See Chapter 4, “Running and Debugging Your Program” for
further information on the placement of input data for a batch job.
When the input is from the job input stream, the following rules apply:
An input record size of 80 characters is assumed.
If the identifier is up to 80 characters in length, the input data must appear as
the first character within the input record. Any characters beyond the length of
identifier are truncated.
If the identifier is longer than 80 characters, succeeding input records are read
until the storage area of the identifier is filled. If the length of the identifier is
not an exact multiple of 80 characters, the last input record is truncated.
When the device is the work station, the input record size is 62. When the device
is the system operator’s message queue, the input record size is 58. The following
steps occur:
1. A system-generated inquiry message containing the program-name, the text
“AWAITING REPLY FOR POSITION(S)”, and the beginning and ending positions is
automatically sent to the system operator’s message queue or the work station
operator. Previous DISPLAYs can also appear on the ACCEPT screen.
2. Processing is suspended.
3. The reply is moved into the identifier, and processing is resumed after a reply is
made by the operator to the inquiry in step 1. The reply value is made avail-
able to the program as it was entered, in uppercase or lowercase.
4. If the identifier is longer than the input record size, then succeeding input
records are read (steps 1-3) until the identifier is filled.
If the incoming reply is longer than the identifier, the character positions beyond the
length of identifier are truncated.
The source of input data is dependent upon the type of program initiation as
follows:
Format 2 Considerations
This format is used to transfer the system date or system time to the identifier,
using the rules for the MOVE statement without the CORRESPONDING phrase. Identifier
can be a group item, or an elementary alphanumeric, alphanumeric edited,
numeric, or numeric edited item.
IBM Extension
DATE has the implicit PICTURE 9(6). The sequence of data elements from left to
right is: two digits for year of century, two digits for month of year, two digits for
day of month. Thus July 4, 1976 is expressed as 760704.
DAY has the implicit PICTURE 9(5). The sequence of data elements from left to right
is: two digits for year of century, three digits for day of year. Thus, July 4, 1976 is
expressed as 76186.
TIME has the implicit PICTURE 9(8). The sequence of data elements from left to
right is: two digits for hour of day, two digits for minute of hour, two digits for
second of minute, two digits for hundredths of second. Thus 12.25 seconds after
2:41 p.m. is expressed as 14411225.
Format 3 Considerations
This format is used to transfer feedback information from an active file to the identi-
fier. The identifier can be any fixed-length group item or an elementary alphabetic,
alphanumeric, or zoned decimal item. The file must be defined in an FD entry, and
must be open prior to the processing of the ACCEPT statement. If the file is not
open, the contents of identifier remain unchanged.
When the FOR phrase is specified, the feedback information is from the file specified
in the phrase. When the FOR phrase is not specified, the feedback information is
from the last file opened or used in an input or output operation.
See Appendix E, “File Structure Support Summary and Status Key Values” for a
discussion of the I-O-FEEDBACK and OPEN-FEEDBACK areas. See the System/38 CPF
Programmer's Guide for a layout and description of the data areas contained in the
feedback areas.
Format 4 Considerations
This format is used to transfer data to identifier-1 from the system-defined local
data area created for a job.
This format is only applicable when the mnemonic-name in the SPECIAL-NAMES para-
graph is associated with the function-name LOCAL-DATA.
The move into identifier-1 takes place according to the rules for the MOVE state-
ment for a group move without the CORRESPONDING phrase.
When the FOR phrase is specified, it is syntax checked during compilation but
treated as comments during processing. The value of literal or identifier-2 indi-
cates the program device name of the device that is associated with the local data
area. There is only one local data area for each job, and all devices in a job
access the same local data area. Literal, if specified, must be nonnumeric and
ten characters or less in length. Identifier-2, if specified, must refer to an alpha-
numeric data item, ten characters or less in length.
Format 5 Considerations
See “ACCEPT Statement” on page 126 for a discussion of Format 5.
Programming Notes
The Format 1 ACCEPT statement is useful for exceptional situations in a program
when operator intervention (to supply a given message, code, or exception indi-
cator) is required. The operator must, of course, be supplied with the appropriate
messages with which to reply.
The Format 2 ACCEPT statement allows the programmer access to the current date
(in two formats) and time of day, as carried by the system. This can be useful in
identifying when a particular run of a program was processed. It can also be used
to supply the date in headings, footings, and so on.
IBM Extension
ACQUIRE Statement
The ACQUIRE statement acquires a program device for a TRANSACTION file. See
Chapter 5, “Interactive Processing Considerations and Example Programs” on
page 89 for a discussion of this statement and the format shown below.
Format
╔══════════════════════════════════════╗
║ ACQUIRE { identifier } FOR file-name ║
║ { literal } ║
╚══════════════════════════════════════╝
CLOSE Statement
The CLOSE statement terminates the processing of volumes and files. REWIND,
LOCK, and REMOVAL phrases are specified, as applicable. The formats of the CLOSE
statement are as follows:
Format 1
┌ ┌ ┐ ┐
│ { REEL } │ WITH NO REWIND │ │
│ { UNIT } │ FOR REMOVAL │ │
CLOSE file-name-1 │ └ ┘ │
│ WITH { NO REWIND } │
│ { LOCK } │
└ ┘
┌ ┌ ┌ ┐ ┐ ┐
│ │ { REEL } │ WITH NO REWIND │ │ │
│ │ { UNIT } │ FOR REMOVAL │ │ │
│ , file-name-2 │ └ ┘ │ │ . . .
│ │ WITH { NO REWIND } │ │
│ │ { LOCK } │ │
└ └ ┘ ┘
Format 2
╔═══════════════════════════════════════╗
║ CLOSE file-name-1 [ WITH LOCK ] ║
║ ║
║ [ file-name-2 [ WITH LOCK ] ] . . . ║
╚═══════════════════════════════════════╝
Each file-name designates a file upon which the CLOSE statement is to operate.
These files:
Need not have the same organization or access mode
Must not be sort or merge files.
A CLOSE statement without the REEL/UNIT phrase can be successfully processed for
a file. In this case, an OPEN statement for the file must be processed before any
other input/output statement can refer explicitly or implicitly to the file. This is true
for all input/output statements except a SORT/MERGE statement with the USING or
GIVING phrases.
If the FILE STATUS clause is specified in the file-control entry, the associated status
key is updated when the CLOSE statement is processed.
If the file is open and the processing of a CLOSE statement is unsuccessful, the
EXCEPTION/ERROR procedure for the file, if specified, is run.
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 performed.
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.
Note: Card devices are not supported by System/38-Compatible COBOL, even
though the devices are accepted by the syntax checker.
Sequential Organization
┌─────────┬──────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ACCESS │ S E Q U E N T I A L │
├─────────┼─────────┬─────────┬─────────┬────────────┬─────────┬──────────┬──────────┬──────────┬────────────┤
│ DEVICE │ READER │ PUNCH │ PRINT │ PUNCHPRINT │ PRINTER │ DISKETTE │ DISK │ DATABASE │ FORMATFILE │
┌───────┴─────────┼─────────┼─────────┼─────────┼────────────┼─────────┼──────────┼──────────┼──────────┼────────────┤
│ CLOSE │ K, J │ K, J │ K, J │ K, J │ K, J │ K , J │ K, J │ K, J │ K, J │
├─────────────────┼─────────┼─────────┼─────────┼────────────┼─────────┼──────────┼──────────┼──────────┼────────────┤
│ CLOSE WITH │ K, J, E │ K, J, E │ K, J, E │ K, J, E │ K, J, E │ K, J, E │ K, J, E │ K, J, E │ K, J, E │
│ LOCK │ │ │ │ │ │ │ │ │ │
├─────────────────┼─────────┼─────────┼─────────┼────────────┼─────────┼──────────┼──────────┼──────────┼────────────┤
│ REEL/UNIT │ - │ - │ - │ - │ - │ - │ - │ - │ - │
├─────────────────┼─────────┼─────────┼─────────┼────────────┼─────────┼──────────┼──────────┼──────────┼────────────┤
│ REMOVAL │ - │ - │ - │ - │ - │ - │ - │ - │ - │
├─────────────────┼─────────┼─────────┼─────────┼────────────┼─────────┼──────────┼──────────┼──────────┼────────────┤
│ NO REWIND │ - │ - │ - │ - │ - │ - │ - │ - │ - │
└─────────────────┴─────────┴─────────┴─────────┴────────────┴─────────┴──────────┴──────────┴──────────┴────────────┘
┌──────────┬───────────────────────────────┐
│ ACCESS │ SEQUENTIAL │
├──────────┼───────────────────────────────┤ ┌──────────┬────────────────────────┐
│ DEVICE │ TAPEFILE │ │ ACCESS │ ANY │
├──────────┼──────────────┬────────────────┤ ├──────────┼────────────┬───────────┤
│ VOLUME │ SINGLE │ MULTI │ │ DEVICE │ DISK │ DATABASE │
┌───────┴──────────┼──────────────┼────────────────┤ ┌───────────┴──────────┼────────────┼───────────┤
│ CLOSE │ K, J, G │ K, J, G, A │ │ CLOSE │ K, J │ K, J │
├──────────────────┼──────────────┼────────────────┤ ├──────────────────────┼────────────┼───────────┤
│ CLOSE WITH LOCK │ K, J, G, E │ K, J, G, A, E │ │ CLOSE WITH LOCK │ K, J, E │ K, J, E │
├──────────────────┼──────────────┼────────────────┤ ├──────────────────────┼────────────┼───────────┤
│ CLOSE NO REWIND │ K, J, B │ K, J, B, A │ │ REEL/UNIT │ - │ - │
├──────────────────┼──────────────┼────────────────┤ ├──────────────────────┼────────────┼───────────┤
│ CLOSE REEL/UNIT │ C │ K, F, G │ │ REMOVAL │ - │ - │
├──────────────────┼──────────────┼────────────────┤ ├──────────────────────┼────────────┼───────────┤
│ CLOSE REEL/UNIT │ C │ K, F, D, G │ │ NO REWIND │ - │ - │
│ FOR REMOVAL │ │ │ └──────────────────────┴────────────┴───────────┘
├──────────────────┼──────────────┼────────────────┤
│ CLOSE REEL/UNIT │ C │ K, F, B │
│ WITH NO REWIND │ │ │
└──────────────────┴──────────────┴────────────────┘
Relative Organization
┌──────────┬────────────────────────┐
│ ACCESS │ ANY │
├──────────┼────────────┬───────────┤
│ DEVICE │ DISK │ DATABASE │
┌───────────┴──────────┼────────────┼───────────┤
│ CLOSE │ K, J │ K, J │
├──────────────────────┼────────────┼───────────┤
│ CLOSE WITH LOCK │ K, J, E │ K, J, E │
├──────────────────────┼────────────┼───────────┤
│ REEL/UNIT │ - │ - │
├──────────────────────┼────────────┼───────────┤
│ REMOVAL │ - │ - │
├──────────────────────┼────────────┼───────────┤
│ NO REWIND │ - │ - │
└──────────────────────┴────────────┴───────────┘
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 spec-
ified on the CLOSE statement.
┌────────────────────────┐
│ LABEL RECORDS │
┌──────────────────────┼────────────┬───────────┤
│ MODE OF FILE │ STANDARD │ OMITTED │
├──────────────────────┼────────────┼───────────┤
│ Input │ F1 │ F2 │
├──────────────────────┼────────────┼───────────┤
│ Output │ F3 │ F4 │
├──────────────────────┼────────────┼───────────┤
│ I-O │ F1 │ F2 │
└──────────────────────┴────────────┴───────────┘
F1 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.
F2 The current volume is unloaded. If all of the reels as specified on
the REELS parameter of the Create Tape File (CRTTAPF) or Override
with Tape File (OVRTAPF) CL command have been processed, the
next processed READ statement receives the AT END condition. 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.
F3 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.
F4 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:
┌────────────────────────┐
│ LABEL RECORDS │
┌──────────────────────┼────────────┬───────────┤
│ MODE OF FILE │ STANDARD │ OMITTED │
├──────────────────────┼────────────┼───────────┤
│ Input │ J1 │ J2 │
├──────────────────────┼────────────┼───────────┤
│ Output │ J3 │ J4 │
├──────────────────────┼────────────┼───────────┤
│ I-O │ J1 │ J2 │
└──────────────────────┴────────────┴───────────┘
J1 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.
J2 The file is closed.
J3 The standard label records are written, and the file is closed.
J4 The file is closed without any label processing.
K May be processed only for an open file.
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
processed. The format of the COMMIT statement is:
Format
╔════════╗
║ COMMIT ║
╚════════╝
When the COMMIT statement is processed, 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 processing 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 commitment control in the
job, not just to files under commitment control in the COBOL program that issues
the COMMIT statement.
When a COMMIT is processed, all record locks held by the job since the last commit-
ment 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
processed and there are no files opened under commitment control, the COMMIT
statement has no effect and no commitment boundary is established.
DELETE Statement
The DELETE statement logically removes a record from an indexed or relative file.
The format of the DELETE statement is as follows:
Format
╔═════════════════════════════╗
║ ┌ ┐ ║
DELETE file-name RECORD ║ │ FORMAT IS { identifer } │ ║
║ │ { literal } │ ║
║ └ ┘ ║
╚═════════════════════════════╝
If the FILE STATUS clause is specified in the FILE-CONTROL entry, the associated
status key is updated when the DELETE statement is processed.
The current record pointer is not affected by the processing of the DELETE state-
ment.
The following tables illustrate organization, access, and device considerations for
the DELETE statement. The letter codes used in the tables are defined in the
section following the tables.
Sequential Organization
┌────────┬──────────────┐
│ Device │ Any │
├────────┼──────────────┤
│ Access │ SEQUENTIAL │
┌─────────────┴────────┼──────────────┤
│ DELETE Verb │ Not Allowed │
└──────────────────────┴──────────────┘
Relative Organization
┌─────────┬────────────────────────────────┬────────────────────────────────┐
│ Device │ DISK │ DATABASE │
├─────────┼────────────┬─────────┬─────────┼────────────┬─────────┬─────────┤
│ Access │ SEQUENTIAL │ RANDOM │ DYNAMIC │ SEQUENTIAL │ RANDOM │ DYNAMIC │
┌─────────┴─────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ DELETE Verb │ A, P, Z │ B, P, Z │ B, P, Z │ A, P, Z │ B, P, Z │ B, P, Z │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ INVALID KEY │ - │ O, U │ O, U │ - │ O, U │ O, U │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FORMAT │ - │ - │ - │ - │ - │ - │
└───────────────────┴────────────┴─────────┴─────────┴────────────┴─────────┴─────────┘
Indexed Organization
┌─────────┬────────────────────────────────┬────────────────────────────────┐
│ Device │ DISK │ DATABASE │
├─────────┼────────────┬─────────┬─────────┼────────────┬─────────┬─────────┤
│ Access │ SEQUENTIAL │ RANDOM │ DYNAMIC │ SEQUENTIAL │ RANDOM │ DYNAMIC │
┌─────────┴─────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ DELETE Verb │ A, P, Z │ D, P, Z │ D, P, Z │ A, P, Z │ D, P, Z │ D, P, Z │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ INVALID KEY │ - │ O, U │ O, U │ - │ O, U │ O, U │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FORMAT │ - │ - │ - │ - │ S, F │ S, F │
└───────────────────┴────────────┴─────────┴─────────┴────────────┴─────────┴─────────┘
Letter
Code Meaning
– An invalid combination.
A The last input/output statement must have been a successfully processed
READ statement. When the DELETE statement is processed, the system log-
ically removes the record retrieved by that READ statement.
B The system logically removes the record identified by the contents of the
RELATIVE KEY data item. If the file does not contain such a record, an
INVALID KEY condition exists. The space is then available for a new
record with the same RELATIVE KEY value.
D The system logically removes the record identified by the contents of the
RECORD KEY data item. If the file does not contain such a record, an
INVALID KEY condition exists.
IBM Extension
15 The key field in the record area is the location in the buffer selected in accordance with a record format or specification in order to
build a search argument.
If the DUPLICATES phrase was specified for this file, the last input/output
statement processed for this file before processing of the DELETE statement
must have been a successfully processed READ statement. The record
read by that statement is the record that is deleted.
In this case, the FORMAT phrase is not used to find the record to be deleted.
The READ statement is required to ensure that the proper record is deleted
when there are duplicates. If a successful read operation did not occur
before the delete operation:
The file status key, if defined, is set to 94.
The USE AFTER STANDARD EXCEPTION/ERROR procedure, if specified, is
run.
The delete operation is not processed.
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 must be operated on.
The literal or identifier must be a character-string of ten characters or less.
If an identifier is specified, 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.
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 called, if applicable for the file.
O Optional.
P Allowed when the file is opened for I-O.
S Required when processing a file that has multiple record formats and has
unique keys.
U The INVALID KEY phrase must be specified for files in which an applicable
USE procedure is not specified.
IBM Extension
Z The action of this statement can be inhibited at program run time by the
inhibit write (INHWRT) parameter of the Override with Data Base File
(OVRDBF) CL command. When this parameter is specified, non-zero file
status codes are not set for data dependent errors. Duplicate key and data
conversion errors are examples of data dependent errors.
See the CL Reference for more information on this command.
DISPLAY Statement
The DISPLAY statement transfers low-volume data to an output device.
Format 1
┌ ┐
DISPLAY { identifier-1 } │ , identifier-2 │
{ literal-1 } │ , literal-2 │
└ ┘
Format 2
╔════════════════════════════════════════════════════════╗
║ ┌ ┐ ║
║ DISPLAY { identifier-1 } │ { , identifier-2 } │ . . . ║
║ { literal-1 } │ { , literal-2 } │ ║
║ └ ┘ ║
║ ║
║ UPON mnemonic-name ║
║ ║
║ @@@@@@@@@@@@@@@@@@@@@@@@@@@ ║
║ @ ┌ ┐ @ ║
║ @ │ FOR { identifier-3} │ @ ║
║ @ │ { literal-3 } │ @ ║
║ @ └ ┘ @ ║
║ @@@@@@@@@@@@@@@@@@@@@@@@@@@ ║
╚════════════════════════════════════════════════════════╝
Format 1 Considerations
The DISPLAY statement transfers the contents of each operand to the output device
in the left-to-right order in which the operands are listed. When a DISPLAY statement
is processed, the data contained in the sending field is transferred to the output
device. The size of the sending field is the total character count of all operands
listed. If the total character count is less than the maximum logical record size, the
remaining rightmost characters are padded with spaces. If the total character count
exceeds the maximum, as many records are written as are needed to display all
operands. Any operand being displayed when the end of a record is reached is
continued in the next record.
IBM Extension
Signed values in numeric fields cause the last character to show both the sign and
number. For example, if SIGN WITH SEPARATE CHARACTER is not specified and two
numeric items have the values -34 and 34, they are displayed as 3M and 34,
A literal can be any figurative constant except the ALL literal. When a figurative
constant is specified as one of the operands, only a single occurrence of the figura-
tive constant is displayed.
When the UPON phrase is omitted, the DISPLAY statement sends output to the
REQUESTOR. When the UPON phrase is specified, mnemonic-name must be associ-
ated in the SPECIAL-NAMES paragraph with either the work station (REQUESTOR) or the
system operator’s message queue (CONSOLE or SYSTEM-CONSOLE).
Maximum Logical
Output Record Size
When a program in a batch job processes a DISPLAY statement without the UPON
phrase, or with an UPON phrase associated with the REQUESTOR, the output is sent to
the job log in an informational message of severity 80. You can change the
severity of this message using the Change Message Description (CHGMSGD) CL
command.
For an interactive job that uses display device files, DISPLAY statements are not
normally used. If you do use them, the following considerations apply.
When an interactive job processes a DISPLAY statement, the logical record appears
on the screen in the Program Messages display.
n o
Display Program Messages
Job E41.QPGMR.4541 started 8/23/88 13:6:39
THIS IS AN EXAMPLE DISPLAY STATEMENT
AND THIS IS ANOTHER
COBOL STOP literal in program SAMPDISP (C G)
F3=Exit F12=Previous
p q
This display contains messages from the current program processing, as well as
messages relating to other activities in the session.
The display device file on the screen when a DISPLAY statement is processed deter-
mines whether program processing is suspended as a result of the DISPLAY state-
ment processing.
If the parameter RSTDSP(@NO) is specified when the display device file is
changed or created (CHGDSPF or CRTDSPF command), DISPLAY statement proc-
essing suspends program processing, and the Program Messages display
appears on the screen. You must press the Enter key to resume program proc-
essing. The previous display returns to the screen immediately.
If the parameter RSTDSP(@YES) is specified when the display device file is
changed or created (CHGDSPF or CRTDSPF command), DISPLAY statement proc-
essing does not suspend program processing. The Program Messages display
appears on the screen, and remains on the screen until one of the following
happens:
– The program processes a nonsubfile READ or WRITE statement for that file.
The Program Messages Display then disappears, and the display device
file is returned to the screen.
– The program terminates.
Note: If you want to suspend program processing, code an ACCEPT statement
after the DISPLAY statement. Program processing is suspended until you press
the Enter key.
To view output records after the program terminates, press the F10 key from the
Command Entry display.
When a program started by a work station operator sends a DISPLAY to the system
operator’s station (separate from the work station), program processing is not sus-
pended.
The location of the output data is dependent upon the type of program initiation as
follows:
Mnemonic-Name Mnemonic-Name
Method of Associated with Associated with UPON
Initiation SYSTEM-CONSOLE REQUESTOR Phrase Omitted
BATCH System operator’s Job log Job log
message queue
INTERACTIVE System operator’s Work station Work station
message queue
IBM Extension
Format 2 Considerations
This format is used to transfer data to the system-defined local data area created
for a job.
This format is only applicable when the mnemonic-name in the SPECIAL-NAMES para-
graph is associated with the function name LOCAL-DATA.
The FOR phrase, when specified, is syntax checked during compilation but is treated
as comments during processing. The value of literal-3 or identifier-3 indicates
the program device name of the device that is writing data to the local data area.
There is only one local data area for each job, and all devices in a job access the
same local data area. Literal-3, if specified, must be nonnumeric and ten charac-
ters or less in length, and identifier-3, if specified, must refer to an alphanumeric
data item ten characters or less in length.
IBM Extension
DROP Statement
The DROP statement releases a program device that was acquired by a TRANSACTION
file.
Format
╔═════════════════════════════════════╗
║ DROP { identifier } FROM file-name ║
║ { literal } ║
╚═════════════════════════════════════╝
OPEN Statement
The OPEN statement initiates file processing. It also checks and/or writes labels.
The formats of the OPEN statement are as follows:
Each file-name designates a file upon which the OPEN statement is to operate. The
files specified 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 compatible with the information supplied to the
system when the file was defined.
At least one of the phrases (INPUT, OUTPUT, I-O, or EXTEND) must be specified.
These phrases can appear in any order. More than one file name can be specified
in each phrase.
A file can be opened for INPUT, OUTPUT, I-O, or EXTEND in the same program.
After the first OPEN statement is processed for a file, each subsequent OPEN state-
ment processing must be preceded by a successful CLOSE file statement processing
without the LOCK phrase.
The following tables illustrate organization, access, and device considerations for
the OPEN statement. The letter codes used in the tables are defined in the section
following the tables.
Note: Card devices are not supported by the System/38-Compatible COBOL, even
though the devices are accepted by the syntax checker.
Sequential Organization
┌───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ACCESS │ S E Q U E N T I A L │
├───────┼─────────┬───────┬───────┬────────────┬─────────┬──────────┬──────────┬───────┬──────────┬────────────┤
│DEVICE │ READER │ PUNCH │ PRINT │ PUNCHPRINT │ PRINTER │ TAPEFILE │ DISKETTE │ DISK │ DATABASE │ FORMATFILE │
┌─┴───────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│OPEN Verb│ S │ S │ S │ S │ S │ L, S │ S │ S │ S, C │ S │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│INPUT │ R, A, F │ - │ - │ - │ - │ O, A, F,│ O, A, F, │ O, A, │ O, A, K, │ O, A, K, F │
│ │ │ │ │ │ │ L1, N │ N │ K,F,N │ F, N │ │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│OUTPUT │ - │ R, J │ R, J │ R, J │ R, J │ O, J, │ O, J, N │ O, G, │ O, G, N │ O, G │
│ │ │ │ │ │ │ L2, N │ │ N │ │ │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│I-O │ - │ - │ - │ - │ - │ - │ - │ O, M, │ O, M, K │ O, M, K │
│ │ │ │ │ │ │ │ │ K │ │ │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│NO REWIND│ - │ - │ - │ - │ - │ O, D │ - │ - │ - │ - │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│REVERSED │ - │ - │ - │ - │ - │ O, B │ - │ - │ - │ - │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│EXTEND │ - │ - │ - │ - │ - │ O, E, │ - │ O, E │ O, E │ - │
│ │ │ │ │ │ │ L3 │ │ │ │ │
└─────────┴─────────┴───────┴───────┴────────────┴─────────┴──────────┴──────────┴───────┴──────────┴────────────┘
Relative Organization
┌─────────┬────────────────────────────────┬────────────────────────────────┐
│ Device │ DISK │ DATABASE │
├─────────┼────────────┬─────────┬─────────┼────────────┬─────────┬─────────┤
│ Access │ SEQUENTIAL │ RANDOM │ DYNAMIC │ SEQUENTIAL │ RANDOM │ DYNAMIC │
┌─────────┴─────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ OPEN Verb │ H, S │ H, S │ H, S │ H, S, C │ H, S, C │ H, S, C │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ INPUT │ O, A, K, N │ O, A │ O, A, K │ O, A, K, N │ O, A │ O, A, K │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ OUTPUT │ O, G, N │ O, G │ O, G │ O, G, N │ O, G │ O, G │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ I-O │ O, M, K │ O, M │ O, M, K │ O, M, K │ O, M │ O, M, K │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ NO REWIND │ - │ - │ - │ - │ - │ - │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ REVERSED │ - │ - │ - │ - │ - │ - │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ EXTEND │ - │ - │ - │ - │ - │ - │
└───────────────────┴────────────┴─────────┴─────────┴────────────┴─────────┴─────────┘
Indexed Organization
┌─────────┬────────────────────────────────┬────────────────────────────────┐
│ Device │ DISK │ DATABASE │
├─────────┼────────────┬─────────┬─────────┼────────────┬─────────┬─────────┤
│ Access │ SEQUENTIAL │ RANDOM │ DYNAMIC │ SEQUENTIAL │ RANDOM │ DYNAMIC │
┌─────────┴─────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ OPEN Verb │ S │ S │ S │ S, C │ S, C │ S, C │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ INPUT │ O, A, K, N │ O, A │ O, A, K │ O, A, K, N │ O, A │ O, A, K │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ OUTPUT │ O, G, N │ O, G │ O, G │ O, G, N │ O, G │ O, G │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ I-O │ O, M, K │ O, M │ O, M, K │ O, M, K │ O, M │ O, M, K │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ NO REWIND │ - │ - │ - │ - │ - │ - │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ REVERSED │ - │ - │ - │ - │ - │ - │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ EXTEND │ - │ - │ - │ - │ - │ - │
└───────────────────┴────────────┴─────────┴─────────┴────────────┴─────────┴─────────┘
Letter
Code Meaning
– An invalid combination.
A The file is opened for input operations. The current record pointer is set to
the first record in the file. If no records exist in the file, the current record
pointer 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.
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.
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 LEAVE phrase. When
the next file on the volume is opened, the system determines which direc-
tion the tape should be moved to most efficiently get to the desired file.
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.
F If SELECT OPTIONAL is specified in the file-control entry, OPEN statement
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 statement 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.
IBM Extension
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 current
record pointer is set to the first record in the file. If no records exist in the
file, the current record pointer is set so that processing of the first sequen-
tial READ statement results in an AT END condition.
N The compiler generates code to block output records or unblock input
records if the conditions listed in “Unblocking Input Records and Blocking
Output Records” on page 210 are satisfied.
O Optional.
R Required.
S The successful processing of an OPEN statement determines the availability
of the file and results in that file being open. Before successful processing
of the OPEN statement for a file, no statement, except a SORT or MERGE
statement with the USING or GIVING phrase, that refers explicitly or implic-
itly to that file can be processed. The successful processing of the OPEN
statement makes the associated record area available to the program. It
does not obtain or release a data record.
If the FILE STATUS clause is specified in the file-control entry, the associ-
ated status key is updated when the OPEN statement is processed.
If an OPEN statement is issued for a file that is already open, the
EXCEPTION/ERROR procedure for this file, if specified, is processed. See
Appendix E, “File Structure Support Summary and Status Key Values” for
the file status codes.
READ Statement
At run time, the READ statement makes a record available before processing of any
statement following the READ statement.
For sequential access, the READ statement makes available the next logical record
from a file. For random access, the READ statement makes available a specified
record from a file.
[ INTO identifier-1 ]
╔════════════════════════════════╗
║ ┌ ┐ ║
║ │ FORMAT IS { identifier-2 } │ ║
║ │ { literal-1 } │ ║
║ └ ┘ ║
╚════════════════════════════════╝
[ AT END imperative-statement ]
[ INTO identifier-1 ]
╔════════════════════════════════╗
║ ┌ ┐ ║
║ │ FORMAT IS { identifier-2 } │ ║
║ │ { literal-1 } │ ║
║ └ ┘ ║
╚════════════════════════════════╝
[ AT END imperative-statement ]
╔════════════════════════════════╗
║ ┌ ┐ ║
║ │ FORMAT IS { identifier-2 } │ ║
║ │ { literal-1 } │ ║
║ └ ┘ ║
╚════════════════════════════════╝
File-name must be defined in a Data Division FD entry, and must not name a sort or
merge file. If more than one record-description entry is associated with file-name,
these records automatically share the same storage area. That is, they are implic-
itly redefined.
After a READ statement is processed, only those data items within the range of the
current record are replaced. Data items stored beyond this range are undefined.
Figure 80 on page 396 illustrates this concept.
ABCDEFGHIJKLMNOPQRSTUVWXYZ
123456789123456789
123456789123456789??????????
The following tables illustrate organization, access, and device considerations for
the READ statement. The letter codes used in the tables are defined in the section
following the tables.
Note: Card devices are not supported by System/38-Compatible COBOL, even
though the devices are accepted by the syntax checker.
Sequential Organization
┌───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ACCESS │ S E Q U E N T I A L │
├───────┼─────────┬───────┬───────┬────────────┬─────────┬──────────┬──────────┬───────┬──────────┬────────────┤
│DEVICE │ READER │ PUNCH │ PRINT │ PUNCHPRINT │ PRINTER │ TAPEFILE │ DISKETTE │ DISK │ DATABASE │ FORMATFILE │
┌─┴───────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│READ Verb│ A, I, │ - │ - │ - │ - │ A, I, G1,│ A, I, G1,│ A, I, │ A, I, P, │ A, I, G1, │
│ │ G1, N │ │ │ │ │ N, V │ N, V │ P, G1,│ G1, N │ N │
│ │ │ │ │ │ │ │ │ N │ │ │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│NEXT │ - │ - │ - │ - │ - │ - │ - │ - │ - │ - │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│LAST │ - │ - │ - │ - │ - │ - │ - │ - │ - │ - │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│FIRST │ - │ - │ - │ - │ - │ - │ - │ - │ - │ - │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│PRIOR │ - │ - │ - │ - │ - │ - │ - │ - │ - │ - │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│INTO │ O, B │ - │ - │ - │ - │ O, B │ O, B │ O, B │ O, B │ O, B │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│AT END │ O, E, D1│ - │ - │ - │ - │ O, E, D1 │ O, E, D1 │ O, E, │ O, E, D1 │ O, E, D1 │
│ │ │ │ │ │ │ │ │ D1 │ │ │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│INVALID │ │ - │ - │ - │ - │ - │ - │ - │ - │ - │
│ KEY │ │ │ │ │ │ │ │ │ │ │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│FORMAT │ │ - │ - │ - │ - │ - │ - │ - │ - │ - │
└─────────┴─────────┴───────┴───────┴────────────┴─────────┴──────────┴──────────┴───────┴──────────┴────────────┘
Relative Organization
┌─────────┬────────────────────────────────┬────────────────────────────────┐
│ Device │ DISK │ DATABASE │
├─────────┼────────────┬─────────┬─────────┼────────────┬─────────┬─────────┤
│ Access │ SEQUENTIAL │ RANDOM │ DYNAMIC │ SEQUENTIAL │ RANDOM │ DYNAMIC │
┌─────────┴─────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ READ Verb │ A, I, P, │ A, I, P,│ A, I, P │ A, I, P, │ A, I, P,│ A, I, P │
│ │ G2 │ G3 │ │ G2 │ G3 │ │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ NEXT │ - │ - │ O, Z1 │ - │ - │ O, Z1 │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FIRST │ - │ - │ - │ - │ - │ - │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ LAST │ - │ - │ - │ - │ - │ - │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ PRIOR │ - │ - │ - │ - │ - │ - │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ INTO │ O, B │ O, B │ O, B │ O, B │ O, B │ O, B │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ AT END │ O, E, D2 │ - │ O, E, D2│ O, E, D1 │ - │ O, E, D2│
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ INVALID KEY │ - │ O, U │ O, U │ - │ O, U │ O, U │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FORMAT │ - │ - │ - │ - │ - │ - │
└───────────────────┴────────────┴─────────┴─────────┴────────────┴─────────┴─────────┘
Indexed Organization
┌─────────┬────────────────────────────────┬────────────────────────────────┐
│ Device │ DISK │ DATABASE │
├─────────┼────────────┬─────────┬─────────┼────────────┬─────────┬─────────┤
│ Access │ SEQUENTIAL │ RANDOM │ DYNAMIC │ SEQUENTIAL │ RANDOM │ DYNAMIC │
┌─────────┴─────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ READ Verb │ A, I, P, │ A, I, P,│ A, I, P │ A, I, P, │ A, I, P,│ A, I, P │
│ │ G4 │ G5 │ │ G4 │ G5 │ │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ NEXT │ - │ - │ O, Z2 │ - │ - │ O, Z3 │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FIRST │ - │ - │ - │ - │ - │ O, Z3 │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ LAST │ - │ - │ - │ - │ - │ O, Z3 │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ PRIOR │ - │ - │ - │ - │ - │ O, Z3 │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ INTO │ O, B │ O, B │ O, B │ O, B │ O, B │ O, B │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ AT END │ O, E, D2 │ - │ O, E, D2│ O, E, D1 │ - │ O, E, D2│
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ INVALID KEY │ - │ O, U │ O, U │ - │ O, U │ O, U │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FORMAT │ - │ - │ - │ O, F, X │ O, F, W │ O, F, Y │
└───────────────────┴────────────┴─────────┴─────────┴────────────┴─────────┴─────────┘
Letter
Code Meaning
— An invalid combination.
A If the FILE STATUS clause is specified in the file-control entry, the associ-
ated status key is updated when the READ statement is processed.
Following the unsuccessful processing of any READ statement, the contents
of the associated record area and the position of the current record pointer
are undefined.
B The INTO identifier phrase makes a READ statement equivalent to:
READ file-name RECORD
MOVE record-name TO identifier
After successful processing of the READ statement, the current record
becomes available both in the record-name and identifier.
When the INTO identifier phrase is specified, the current record is moved
from the input area to the identifier area according to the rules for the MOVE
statement without the CORRESPONDING phrase. Any subscripting or indexing
associated with identifier is evaluated after the record has been read and
immediately before it is transferred to identifier.
The INTO identifier phrase cannot be specified when the file contains
records of various sizes, as indicated by their record descriptions. The
storage area associated with identifier and the record area associated with
the file-name cannot be the same storage area.
D1 When the AT END condition is recognized, a successful CLOSE statement,
followed by a successful OPEN statement, must be processed for this file
before processing a READ statement.
D2 When the AT END condition is recognized, a sequential access READ state-
ment for this file must not be processed without first processing one of the
following:
A successful CLOSE statement followed by a successful OPEN statement.
A successful START statement for this file.
A successful random access READ statement for this file.
A successful READ file-name FIRST or READ file-name LAST where per-
mitted.
E If no next logical record exists in the file when the READ statement is proc-
essed, an AT END condition occurs, and READ statement processing is
unsuccessful. The following actions are taken, in the order listed:
1. If the FILE STATUS clause is specified, the status key is updated to
indicate an AT END condition.
2. If the AT END phrase is specified, control is transferred to the AT END
imperative-statement. Any EXCEPTION/ERROR procedure for this file is
not run.
3. If the AT END phrase is not specified, any EXCEPTION/ERROR procedure
for this file is run.
The AT END phrase must be specified if no explicit or implicit
EXCEPTION/ERROR procedure is specified for this file.
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.
The literal or identifier must be a character-string of ten characters or less.
If an identifier is specified, 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.
A value of all blanks is treated as though the FORMAT phrase was not speci-
fied. If the value is not valid for the file, a FILE STATUS of 9K is returned
and a USE procedure is called, if applicable for the file.
IBM Extension
For a file that allows duplicate keys (the DUPLICATES phrase is speci-
fied in the file-control entry), the records with duplicate key values are
made available in the order specified when the file was created. The
system options are first-in first-out (FIFO), last-in first-out (LIFO), and
‘no specific sequence’.
G5 The record in the file with a key value equal to that of the RECORD KEY data
item is then made available. If the file does not contain such a record, the
INVALID KEY condition exists, and READ statement processing is unsuc-
cessful.
IBM Extension
For a file that allows duplicate keys (the DUPLICATES phrase is specified in
the file-control entry), the first record with the specified key value is made
available. The first record is determined by the order specified when the
file was created. The system options are first-in first-out (FIFO), last-in
first-out (LIFO), and ‘no specific sequence’.
The program receives no indication that the above actions occurred during
the read operation.
W If specified, the key as defined for the specified format is used to get a
record of that format. If a record of that format is not found, a record-not-
found condition is returned. This occurs even when there are records that
have the defined key, but that have a different record format.
If the format is omitted, the common key for the file is used to get the first
record of any format that has that common key value. The common key
for a file consists of the key fields common to all formats of a file for
records residing on the data base. The common key for a file is the left-
most key fields that are common across all record formats in the file. The
common key is built from the data in the record description area using the
first record format defined in the program for the file.
X If specified, the next record in the keyed sequence access path that has
the requested format is made available. If omitted, the next record in the
keyed sequence access path is made available.
Y
┌──────────────────────────────────┐
│ FORMAT Phrase │
├─────────────────┬────────────────┤
│ Specified │ Omitted │
┌───────────────┼─────────────────┼────────────────┤
│ NEXT │ Y1 │ Y2 │
├───────────────┼─────────────────┼────────────────┤
│ PRIOR │ Y3 │ Y4 │
├───────────────┼─────────────────┼────────────────┤
│ FIRST │ Y5 │ Y6 │
├───────────────┼─────────────────┼────────────────┤
│ LAST │ Y7 │ Y8 │
├───────────────┼─────────────────┼────────────────┤
│ None of │ Y9 │ Y1 │
│ the Above │ │ │
└───────────────┴─────────────────┴────────────────┘
Y1 The next record in the keyed sequence access path having the spec-
ified format is made available.
Y2 The next record in the keyed sequence access path is made avail-
able regardless of its format.
Y3 The record in the keyed sequence access path preceding the record
identified by the current record pointer having the specified format is
made available.
Y4 The record in the keyed sequence access path preceding the record
identified by the current record pointer is made available regardless
of its format.
Y5 The first record in the keyed sequence access path having the speci-
fied format is made available.
Y6 The first record in the keyed sequence access path is made avail-
able regardless of its format.
Y7 The last record in the keyed sequence access path having the speci-
fied format is made available.
Y8 The last record in the keyed sequence access path is made available
regardless of its format.
Y9 The key as defined for the specified format is used to get a record of
that format. If a record of that format is not found, a record-not-
found condition is returned. This occurs even when there are
records that have the defined key, but that have a different record
format.
Y1 The common key for the file is used to get the first record of any
format that has that common key value. The common key for a file
consists of the key fields common to all formats of a file for records
residing on the data base. The common key for a file consists of the
leftmost key fields that are common across all record formats in the
file. The common key is built from the data in the record description
area using the first record format defined in the program for the file.
Z1 When specified, a sequential read is done (see G2). When omitted, a
random read is done (see G3).
Z2 When specified, a sequential read is done (see G4). When omitted, a
random access read is done (see G5).
Z3 When specified, a sequential read is done (see G4). If NEXT, FIRST, LAST
and PRIOR are all omitted, a random access read is done (see G5).
REWRITE Statement
The REWRITE statement logically replaces an existing record in a file. When the
REWRITE statement is processed, the associated file must be open. The formats for
the REWRITE statement are as follows:
Format 1
REWRITE record-name [ FROM identifier-1 ]
╔════════════════════════════════╗
║ ┌ ┐ ║
║ │ FORMAT IS { identifier-2 } │ ║
║ │ { literal-1 } │ ║
║ └ ┘ ║
╚════════════════════════════════╝
Format 2–TRANSACTION
╔═══════════════════════════════════════════════════╗
║ REWRITE SUBFILE record-name [ FROM identifier-1 ] ║
║ ║
║ FORMAT IS { identifier-2 } ║
║ { literal-1 } ║
║ ║
║ ┌ ┐ ║
║ │ TERMINAL IS { identifier-3 } │ ║
║ │ { literal-2 } │ ║
║ └ ┘ ║
║ ║
║ ┌ ┌ ┐ ┐ ║
║ │ { INDICATOR │ IS │ } │ ║
║ │ { INDICATORS │ ARE │ } identifier-4 │ ║
║ │ { INDIC └ ┘ } │ ║
║ └ ┘ ║
║ ║
║ [ INVALID KEY imperative-statement ] ║
╚═══════════════════════════════════════════════════╝
Record-name:
Must be the name of a record in the File Section
Must have the same number of character positions as the record being
replaced
Must not be subscripted or indexed
Can be qualified.
The current record pointer is not affected by processing of the REWRITE statement.
If the FILE STATUS clause is specified in the file-control entry, the associated status
key is updated when the REWRITE statement is processed.
The following tables illustrate organization, access, and device considerations for
the REWRITE statement. The letter codes used in the tables are defined in the
section following the tables.
Note: Card devices are not supported by System/38-Compatible COBOL, even
though the devices are accepted by the syntax checker.
Sequential Organization
┌───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ACCESS │ S E Q U E N T I A L │
├───────┼─────────┬───────┬───────┬────────────┬─────────┬──────────┬──────────┬───────┬──────────┬────────────┤
│DEVICE │ READER │ PUNCH │ PRINT │ PUNCHPRINT │ PRINTER │ TAPEFILE │ DISKETTE │ DISK │ DATABASE │ FORMATFILE │
┌─┴───────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│REWRITE │ - │ - │ - │ - │ - │ - │ - │ A, P │ A, P │ - │
│ Verb │ │ │ │ │ │ │ │ │ │ │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│FROM │ - │ - │ - │ - │ - │ - │ - │ O, B │ O, B │ - │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│INVALID │ - │ - │ - │ - │ - │ - │ - │ - │ - │ - │
│ KEY │ │ │ │ │ │ │ │ │ │ │
├─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│FORMAT │ - │ - │ - │ - │ - │ - │ - │ - │ - │ - │
└─────────┴─────────┴───────┴───────┴────────────┴─────────┴──────────┴──────────┴───────┴──────────┴────────────┘
Relative Organization
┌─────────┬────────────────────────────────┬────────────────────────────────┐
│ Device │ DISK │ DATABASE │
├─────────┼────────────┬─────────┬─────────┼────────────┬─────────┬─────────┤
│ Access │ SEQUENTIAL │ RANDOM │ DYNAMIC │ SEQUENTIAL │ RANDOM │ DYNAMIC │
┌─────────┴─────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ REWRITE Verb │ A, P, Z │ S, P, Z │ S, P, Z │ A, P, Z │ S, P, Z │ S, P, Z │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FROM │ O, B │ O, B │ O, B │ O, B │ O, B │ O, B │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ INVALID KEY │ - │ U, H, J │ U, H, J │ - │ U, H, J │ U, H, J │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FORMAT │ - │ - │ - │ - │ - │ - │
└───────────────────┴────────────┴─────────┴─────────┴────────────┴─────────┴─────────┘
Indexed Organization
┌─────────┬────────────────────────────────┬────────────────────────────────┐
│ Device │ DISK │ DATABASE │
├─────────┼────────────┬─────────┬─────────┼────────────┬─────────┬─────────┤
│ Access │ SEQUENTIAL │ RANDOM │ DYNAMIC │ SEQUENTIAL │ RANDOM │ DYNAMIC │
┌─────────┴─────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ REWRITE Verb │ A, E, P, Z │ D, P, Z │ D, P, Z │ A, E, P, Z │ D, P, Z │ D, P, Z │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FROM │ O, B │ O, B │ O, B │ O, B │ O, B │ O, B │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ INVALID KEY │ U, G, J │ U, H, J │ U, H, J │ U, G, J │ U, H, J │ U, H, J │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FORMAT │ - │ - │ - │ - │ M, F │ M, F │
└───────────────────┴────────────┴─────────┴─────────┴────────────┴─────────┴─────────┘
Letter
Code Meaning
— An invalid combination.
A The last input/output statement processed for this file must have been a
successfully processed READ statement. When the REWRITE statement is
processed, the record retrieved by that READ statement is replaced.
B The FROM identifier phrase makes a REWRITE statement equivalent to:
MOVE identifier TO record-name
REWRITE record-name.
After successful processing of the REWRITE statement, the current record is
no longer available in record-name, but is still available in identifier.
Record-name and identifier cannot both refer to the same storage area.
D The record to be replaced is specified by the value in the RECORD KEY data
item. If the file does not contain such a record, an INVALID KEY condition
exists.
IBM Extension
E The value of the RECORD KEY data item must not have been changed since
the record was read.
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.
The literal or identifier must be a character-string of ten characters or less.
If an identifier is specified, 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.
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 called, if applicable for the file.
G Processed when the value contained in the RECORD KEY of the record to be
replaced does not equal the RECORD KEY data item of the last retrieved
record from the file.
H Processed when the record specified by the key field in the record area is
not found.
J When an INVALID KEY condition exists, the updating operation does not
take place. The data in record-name is unaffected.
M Optional when processing a file that has one record format.
O Optional.
P Allowed when the file is opened for I-O.
S The record to be replaced is specified by the value in the RELATIVE KEY
data item. If the file does not contain such a record, an INVALID KEY con-
dition exists.
U The INVALID KEY phrase must be specified for files in which an applicable
USE procedure is not specified.
IBM Extension
Z The action of this statement can be inhibited at program run time by the
inhibit write (INHWRT) parameter of the Override with Data Base File
(OVRDBF) CL command. When this parameter is specified, nonzero file
status codes are not set for data dependent errors. Duplicate key and
data conversion errors are examples of data dependent errors.
See the CL Reference for more information on this command.
IBM Extension
ROLLBACK Statement
The ROLLBACK statement provides a way to cancel one or more changes to data
base records when the changes should not remain permanent. The format of the
ROLLBACK statement is:
Format
╔══════════╗
║ ROLLBACK ║
╚══════════╝
When the ROLLBACK statement is processed, any changes made to files under com-
mitment control since the last commitment boundary are removed from the data
base.16 A commitment boundary is the previous occurrence of a ROLLBACK or COMMIT
statement. If no COMMIT or ROLLBACK has been issued, the commitment boundary is
the first OPEN of a file under commitment control. Removal of changes takes place
for all files under commitment control in the job, and not just for files under commit-
ment control in the COBOL program that issues the ROLLBACK.
16 When a file is cleared while being opened for OUTPUT, processing of a ROLLBACK statement does not restore cleared records to the
file.
Once the ROLLBACK is successfully processed, all record locks held by the job for
files under commitment control are released and the records become available to
other jobs.
The ROLLBACK has no effect on files not under commitment control. If a ROLLBACK is
processed and there are no files under commitment control, the ROLLBACK is
ignored.
A file under commitment control can be opened or closed without affecting the
status of changes made since the last commitment boundary. A COMMIT must still
be issued to make the changes permanent. A ROLLBACK, when processed, leaves
files in the same open or closed state as before processing.
START Statement
The START statement provides a way of positioning within an indexed or relative file
for subsequent sequential retrieval. This positioning is achieved by comparing the
key values of records in the file with the value you place in the RECORD KEY portion
of a file’s record area (for an indexed file), or in the RELATIVE KEY data item (for a
relative file) prior to processing of the START statement. The format for the START
statement is as follows:
Format
┌ ┐
│ { EQUAL TO } │
│ { = } ╔═══════════════════════════════════════╗ │
│ { GREATER THAN } { ║ EXTERNALLY-DESCRIBED-KEY ║ } │
START file-name │ KEY IS { > } { ╚═════════════╗ ║ } │
│ { NOT LESS THAN } { data-name-1 ║ [ , data-name-2 ] . . . ║ } │
│ { NOT < } ╚═════════════════════════╝ │
└ ┘
╔════════════════════════════════╗
║ ┌ ┐ ║
║ │ FORMAT IS { identifier-1 } │ ║
║ │ { literal-1 } │ ║
║ └ ┘ ║
╚════════════════════════════════╝
File-name must be defined in an FD entry in the Data Division. It must not name a
sort or merge file.
If the FILE STATUS clause is specified in the FILE-CONTROL paragraph, the associ-
ated status key is updated when the START statement is processed.
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.
Sequential Organization
┌────────┬──────────────┐
│ Access │ SEQUENTIAL │
├────────┼──────────────┤
│ Device │ Any │
┌─────────────┴────────┼──────────────┤
│ START Verb │ Not Allowed │
└──────────────────────┴──────────────┘
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, U, D │ - │ O, U, D │ O, U, D │ - │ O, U, D │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FORMAT │ - │ - │ - │ - │ - │ - │
└───────────────────┴────────────┴─────────┴─────────┴────────────┴─────────┴─────────┘
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, U, D │ - │ O, U, D │ O, U, D │ - │ O, U, D │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FORMAT │ - │ - │ - │ O, F, J │ - │ O, F, J │
└───────────────────┴────────────┴─────────┴─────────┴────────────┴─────────┴─────────┘
Letter
Code Meaning
– An invalid combination.
A When the KEY phrase is not specified, the current record pointer is set to
the record in the file with a key (relative record number) equal to the
RELATIVE KEY data item.
B When the KEY phrase is not specified, the current record pointer 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 position of the current record pointer is undefined,
and the INVALID KEY imperative-statement, if specified, is processed.
E When the KEY phrase is specified, data-name-1 must specify the RELATIVE
KEY. The current record pointer is positioned to the first logical record cur-
rently existing in the file with a key (relative record number) that satisfies
the comparison with the RELATIVE KEY data item.
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.
The literal or identifier must be a character-string of ten characters or less.
If an identifier is specified, 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.
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 called, if applicable for the file.
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.
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 current record pointer 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.
IBM Extension
┌────────────────────────────────────────────────┐
│ KEY Phrase │
┌──────────┼──────────────┬─────────────┬───────────────────┤
│ FORMAT │ Data-Name │ │ EXTERNALLY- │
│ Phrase │ Series │ Omitted │ DESCRIBED-KEY │
├──────────┼──────────────┼─────────────┼───────────────────┤
│ Yes │ G1, G2 │ G3, G4 │ G3, G2 │
├──────────┼──────────────┼─────────────┼───────────────────┤
│ No │ G1, G5 │ G6, G7 │ G6, G5 │
└──────────┴──────────────┴─────────────┴───────────────────┘
G5 The current record pointer 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 current record
pointer 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 current record pointer 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 current record pointer is set to the first
record in the file.
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:
O Optional.
P Allowed when the file is opened for I-O.
U The INVALID KEY phrase must be specified for files in which an appropriate
USE procedure is not specified.
WRITE Statement
The WRITE statement releases a record to the system. The formats for the WRITE
statement are as follows:
┌ ┐
│ { { identifer-2 } { LINE } } │
│ { { integer } { LINES } } │
│ { BEFORE } ADVANCING { } │
│ { AFTER } { { mnemonic-name } } │
│ { { PAGE } } │
└ ┘
┌ ┐
│ AT { END-OF-PAGE } imperative-statement │
│ { EOP } │
└ ┘
╔════════════════════════════════╗
║ ┌ ┐ ║
║ │ FORMAT IS { identifier-2 } │ ║
║ │ { literal-1 } │ ║
║ └ ┘ ║
╚════════════════════════════════╝
Record-name:
Must be the name of a record in the File Section of the Data Division
Can be qualified
Cannot be associated with a sort or merge file.
The maximum record size for a data base file is established at the time the file is
defined to the system (using the Create Physical File (CRTPF) or the Create Logical
File (CRTLF) CL command) and cannot be changed. If the record length defined in
the program is incompatible with the record length defined to the system, the fol-
lowing occurs during output to the file:
When the program record length is greater than the length defined to the
system, the records are truncated to the system length. If the file is empty, the
program record length is used.
When the program record length is less than the record length defined in the
system, the records are padded with blanks to make them the size specified in
the system.
Processing of the WRITE statement releases a record to the file associated with
record-name. After processing of a WRITE statement, the record is no longer avail-
able in record-name unless either of the following is true:
The associated file is named in a SAME RECORD AREA clause. In this case, the
record is also available as a record of the files named in the SAME RECORD AREA
clause.
The WRITE statement is unsuccessful due to a boundary violation (beyond
extent).
If either of the above conditions is true, the record is still available in record-name.
The current record pointer is not affected by processing of the WRITE statement.
The number of character positions required to store the record in a file can be, but
is not necessarily, the same as the number of character positions defined by the
description of the record in the COBOL program. (See “PICTURE Clause” on
page 332 and “USAGE Clause” on page 322.)
If the FILE STATUS clause is specified in the file-control entry, the associated status
key is updated when the WRITE statement is processed.
When an attempt is made to write beyond the externally defined boundaries of the
file, WRITE statement processing is unsuccessful, and an EXCEPTION/ERROR condition
exists. The status key, if specified, is updated. If an explicit or implicit
EXCEPTION/ERROR procedure is specified for the file, the procedure is run. If no such
procedure is specified, the results are unpredictable.
The following tables illustrate organization, access, and device considerations for
the WRITE statement. The letter codes used in the tables are defined in the section
following the tables.
Note: Card devices are not supported by System/38-Compatible COBOL, even
though the devices are accepted by the syntax checker.
Sequential Organization
┌─────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ACCESS │ S E Q U E N T I A L │
├─────────┼─────────┬───────┬───────┬────────────┬─────────┬──────────┬──────────┬───────┬──────────┬────────────┤
│DEVICE │ READER │ PUNCH │ PRINT │ PUNCHPRINT │ PRINTER │ TAPEFILE │ DISKETTE │ DISK │ DATABASE │ FORMATFILE │
┌─┴─────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│WRITE │ - │ Q, T │Q, T │ Q, T │Q, T │V, Q, S, T│ V, Q, T │Q, S, │Q, S, T, Z│ Q, T │
│ Verb │ │ │ │ │ │ │ │T, Z │ │ │
├───────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│FROM │ - │ O, B │O, B │ O, B │O, B │O, B │ O, B │O, B │O, B │ O, B │
├───────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│INVALID │ - │ - │ - │ - │ - │ - │ - │ - │ - │ - │
│ KEY │ │ │ │ │ │ │ │ │ │ │
├───────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│ADVANCING │ - │ O, D2 │O, D2 │ O, D2 │O, D1 │ - │ - │ - │ - │ - │
├───────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│AT END- │ - │ - │ - │ - │O, E1 │ - │ - │ - │ - │ O, E2 │
│OF-PAGE │ │ │ │ │ │ │ │ │ │ │
├───────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│FORMAT │ - │ - │ - │ - │ - │ - │ - │ - │ - │ N, F │
├───────────┼─────────┼───────┼───────┼────────────┼─────────┼──────────┼──────────┼───────┼──────────┼────────────┤
│INDICATORS │ - │ - │ - │ - │ - │ - │ - │ - │ - │ I │
└───────────┴─────────┴───────┴───────┴────────────┴─────────┴──────────┴──────────┴───────┴──────────┴────────────┘
Relative Organization
┌─────────┬────────────────────────────────┬────────────────────────────────┐
│ Device │ DISK │ DATABASE │
├─────────┼────────────┬─────────┬─────────┼────────────┬─────────┬─────────┤
│ Access │ SEQUENTIAL │ RANDOM │ DYNAMIC │ SEQUENTIAL │ RANDOM │ DYNAMIC │
┌─────────┴─────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ WRITE Verb │ Q, K, Z │ P,Q,M,Z │ P,Q,M,Z │ Q, K, Z │ P,Q,M,Z │ P,Q,M,Z │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FROM │ O, B │ O, B │ O, B │ O, B │ O, B │ O, B │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ INVALID KEY │ O, J1, J, │ O, J1, │ O, J1, │ O, J1, J, │ O, J1, │ O, J1, │
│ │ U │ J2,J,U │ J2,J,U │ U │ J2,J, U │ J2,J,U │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ ADVANCING │ - │ - │ - │ - │ - │ - │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ AT END-OF-PAGE │ - │ - │ - │ - │ - │ - │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FORMAT │ - │ - │ - │ - │ - │ - │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ INDICATORS │ - │ - │ - │ - │ - │ - │
└───────────────────┴────────────┴─────────┴─────────┴────────────┴─────────┴─────────┘
Indexed Organization
┌─────────┬────────────────────────────────┬────────────────────────────────┐
│ Device │ DISK │ DATABASE │
├─────────┼────────────┬─────────┬─────────┼────────────┬─────────┬─────────┤
│ Access │ SEQUENTIAL │ RANDOM │ DYNAMIC │ SEQUENTIAL │ RANDOM │ DYNAMIC │
┌─────────┴─────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ WRITE Verb │ G,H1,Q,Z │ G, H2, │ G, H2, │ G, H1, Q, │ G, H2, │ G, H2, │
│ │ │ P, Q, Z │ P, Q, Z │ Z │ P, Q, Z │ P, Q, Z │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FROM │ O, B │ O, B │ O, B │ O, B │ O, B │ O, B │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ INVALID KEY │ O, J1, J4, │ O, J1, │ O, J1, │ O, J1, J4, │ O, J1, │ O, J1, │
│ │ J, U │ J3,J,U │ J3,J,U │ J, U │ J3,J, U │ J3,J,U │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ ADVANCING │ - │ - │ - │ - │ - │ - │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ AT END-OF-PAGE │ - │ - │ - │ - │ - │ - │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ FORMAT │ - │ - │ - │ N, F │ N, F │ N, F │
├───────────────────┼────────────┼─────────┼─────────┼────────────┼─────────┼─────────┤
│ INDICATORS │ - │ - │ - │ - │ - │ - │
└───────────────────┴────────────┴─────────┴─────────┴────────────┴─────────┴─────────┘
Letter
Code Meaning
— An invalid combination.
A When the KEY phrase is not specified, the current record pointer is set to
the record in the file with a key (relative record number) equal to the
RELATIVE KEY data item.
B The FROM identifier phrase makes a WRITE statement equivalent to:
MOVE identifier TO record-name
WRITE record-name.
After successful processing of the WRITE statement, the current record is
no longer available in record-name, but is still available in identifier.
Record-name and identifier cannot both refer to the same storage area.
D1 When not specified, a default of AFTER ADVANCING 1 LINE is used. When
specified, the following rules apply:
When BEFORE ADVANCING is specified, the line is printed before the
page advances.
When AFTER ADVANCING is specified, the page advances before the line
is printed.
When identifier-2 is specified, the page advances the number of
lines equal to the current value in identifier-2. Identifier-2 must
name an elementary integer data item. Identifier-2 can be zero.
When integer is specified, the page advances the number of lines
equal to the value of integer. Integer can be zero.
When a mnemonic-name is specified, a page eject or space sup-
pression occurs. The mnemonic-name must be equated with
function-name-1 in the SPECIAL-NAMES paragraph. This phrase is not
valid if a LINAGE clause is specified in the FD entry for this file.
When PAGE is specified, the record is printed on the logical page
BEFORE or AFTER (depending on the phrase specified) the device is
positioned to the next logical page. If PAGE has no meaning for the
device used, BEFORE or AFTER ADVANCING 1 LINE is provided
(depending on the phrase specified).
If the FD entry contains a LINAGE clause, the device is positioned to the
first printable line of the next page, as specified in that clause. If the
LINAGE clause is omitted, the device is positioned to line 1 of the next
page.
If the LINAGE clause is specified for this file, the associated
LINAGE-COUNTER special register is modified during the processing of
the WRITE statement, according to the following rules:
– If ADVANCING PAGE is specified, LINAGE-COUNTER is reset to 1.
– If ADVANCING identifier-2 or integer is specified, LINAGE-COUNTER
is incremented by the value of identifier-2 or integer.
– If the ADVANCING phrase is omitted, LINAGE-COUNTER is incremented
by 1.
– When the device is repositioned to the first printable line of a new
page, LINAGE-COUNTER is reset to 1.
IBM Extension
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.
The literal or identifier must be a character-string of ten characters or less.
If an identifier is specified, 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.
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 called, if applicable for the file.
G When the WRITE statement is processed, the system releases the record.
Before the WRITE statement is processed, the user must set the key fields
in the record area to the desired value.
IBM Extension
If the DUPLICATES phrase is specified, record key values for a format need
not be unique (see “FILE-CONTROL Paragraph” on page 281, “RECORD
KEY Clause (Indexed File)” on page 289.) In this case, the system stores
the records so that later sequential access to the records allows retrieval
in the order specified in DDS.
J4 An INVALID KEY condition exists when the value of the key field in
| the record area is not greater than that for the previous record. Note
| that any signs on the record keys are ignored, even if the keys are
| defined as signed numeric in the DDS for the file.
IBM Extension
If DUPLICATES are allowed, this condition exists only if the RECORD KEY
is less than that for the previous record.
K The first record released has relative record number 1, the second has
number 2, the third has number 3, and so on. If the RELATIVE KEY is spec-
ified in the file-control entry, the relative record number of the record just
released is placed in the RELATIVE KEY during processing of the WRITE
statement.
M The RELATIVE KEY must contain the desired relative record number for this
record before the WRITE statement is issued. When the WRITE statement is
processed, this record is placed at the specified relative record number
position in the file, if this position is vacant.
N Required if there is more than one record format for the file.
O Optional.
P Allowed when the file is opened for I-O.
Q Allowed when the file is opened for OUTPUT.
S Allowed when the file is opened for EXTEND.
T When an attempt is made to write beyond the externally defined bounda-
ries of the file, the processing of the WRITE statement is unsuccessful and
an EXCEPTION/ERROR condition exists. The contents of record-name are
unaffected. If specified, the status key is updated, and if an explicit or
implicit EXCEPTION/ERROR procedure is specified for the file, the procedure
is run. If no such procedure is specified, the results are unpredictable.
U The INVALID KEY phrase must be specified for files in which an applicable
USE procedure is not specified.
V When end-of-volume is recognized for a multivolume OUTPUT file, the WRITE
statement processes the following operations in the following order:
1. The standard ending volume label procedure is run.
2. A volume switch occurs.
3. The standard beginning volume label procedure is run.
No indication that an end-of-volume has occurred is returned to the
program.
IBM Extension
Z The action of this statement can be inhibited at program run time by the
INHWRT parameter of the OVRDBF CL command. When this parameter is
specified, non-zero file status codes are not set for data dependent errors.
Duplicate key and data conversion errors are examples of data dependent
errors.
See the CL Reference for more information on this command.
Arithmetic Statements
Arithmetic statements are used for computations. Individual operations are speci-
fied by the ADD, SUBTRACT, MULTIPLY, and DIVIDE statements. The COMPUTE state-
ment can be used to symbolically combine these operations in a formula.
Size of Operands
The maximum size of each operand is 18 decimal digits. The composite of oper-
ands (a hypothetical data item resulting from the superimposition of the operands
aligned by an assumed decimal point) must not contain more than 18 decimal
digits.
For the ADD and SUBTRACT statements, the composite of operands is determined by
superimposing all operands in a given statement except those following the word
GIVING.
For the COMPUTE statement, the restriction on composite of operands does not apply.
For example, the items A, B, and C are defined in the Data Division as follows:
1 A PICTURE S9(7)V9(5).
1 B PICTURE S9(11)V99.
1 C PICTURE S9(12)V9(3).
PICTURE S9(12)V9(5)
IBM Extension
Overlapping Operands
When operands in an arithmetic statement share part of their storage (that is, when
the operands overlap), the result of the processing of such a statement is unpre-
dictable.
Multiple Results
When an arithmetic statement has multiple results, processing conceptually pro-
ceeds as follows:
The statement processes all arithmetic operations to find the result to be placed
in the receiving items and stores that result in a temporary location.
A sequence of statements transfers or combines the value of this temporary
result with each single receiving field. The statements are considered to be
written in the same left-to-right order that the multiple results are listed.
ADD A, B, C TO C, D(C), E.
TEMP is a compiler-supplied temporary result field. When the addition operation for
D(C) is processed, the subscript C contains the new value of C.
Notes:
1. The compiler does not generate a temporary result field when only one identi-
fier is specified in the following cases: in the ADD statement, Format 1, pre-
ceding the keyword TO; in the SUBTRACT statement, Format 1, preceding the
keyword FROM; and in the MULTIPLY and DIVIDE statements, Format 1.
2. In all arithmetic statements, it is the user’s responsibility to define data with
enough digits and decimal places to ensure the desired accuracy in the final
result. Refer to Appendix C, “Intermediate Result Fields” on page 537 for
more information.
Common Phrases
There are several phrases common to the arithmetic statements. They are the
CORRESPONDING phrase, the GIVING phrase, the ROUNDED phrase, and the SIZE ERROR
phrase. Their description precedes the descriptions of the individual statements.
CORRESPONDING Phrase
The CORRESPONDING phrase allows operations to be processed on elementary items
of the same name simply by specifying the group items to which they belong.
The CORRESPONDING phrase is valid in the ADD, SUBTRACT, and MOVE statements. The
abbreviation CORR is equivalent to the keyword CORRESPONDING.
Both identifiers following the keyword CORRESPONDING must name group items. In
this discussion, these identifiers are referred to as d1 and d2.
A pair of subordinate data items, one from d1 and one from d2, correspond if the
following conditions are true:
In an ADD or SUBTRACT statement, both of the subordinate items are elementary
numeric data-items.
In a MOVE statement, at least one of the subordinate items is elementary.
The two subordinate items have the same name and the same qualifiers up to
but not including d1 and d2.
The subordinate items are not identified by the keyword FILLER.
The subordinate items do not include a REDEFINES, RENAMES, OCCURS, or USAGE
IS INDEX clause in their descriptions; if such a subordinate item is a group item,
the items subordinate to it are also ignored. However, d1 and d2 themselves
can contain or be subordinate to items containing a REDEFINES or OCCURS clause
in their descriptions.
For example, two data hierarchies are defined as follows:
5 ITEM-1 OCCURS 6 INDEXED BY X.
1 ITEM-A ...
1 ITEM-B ...
1 ITEM-C REDEFINES ITEM-B ...
5 ITEM-2.
1 ITEM-A ...
1 ITEM-B ...
1 ITEM-C ...
If ADD CORR ITEM-2 TO ITEM-1(X) is specified, ITEM-A and ITEM-A(X) and
ITEM-B and ITEM-B(X) are considered to be corresponding and are added
together. ITEM-C and ITEM-C(X) are not included because ITEM-C(X) includes a
REDEFINES clause in its data description. ITEM-1 is valid as either d1 or d2.
Neither d1 nor d2 is described as a level 66, 77 or 88 item, or as a FILLER or
USAGE IS INDEX item.
IBM Extension
GIVING Phrase
If the GIVING phrase is specified, the value of the identifier that follows the word
GIVING is set equal to the calculated result of the arithmetic operation. Because
this identifier is not involved in the computation, it can be a numeric edited item.
ROUNDED Phrase
After decimal point alignment, the number of places in the fraction of the result of
an arithmetic operation is compared with the number of places provided for the
fraction of the resultant identifier.
If the size of the fractional result exceeds the number of places provided for its
storage, truncation occurs unless the ROUNDED phrase is specified. When the
ROUNDED phrase is specified, the least significant digit of the resultant identifier has
its absolute value increased by 1 whenever the most significant digit of the excess
is greater than or equal to 5.
In the ADD, SUBTRACT, and COMPUTE statements, the size error condition applies only
to final results. In the MULTIPLY and DIVIDE statements, the size error condition
applies both to final results and to intermediate results.
If the ROUNDED phrase is specified, rounding takes place before size error checking.
When a size error occurs, the subsequent action of the program depends on
whether or not the SIZE ERROR phrase is specified.
If the SIZE ERROR phrase is not specified and a size error condition occurs, the
value of the affected resultant identifier is unpredictable. When multiple receivers
are specified, those that do not have a size error are not affected by receivers that
do have the error.
If the SIZE ERROR phrase is specified and a size error condition occurs, the error
results are not placed in the receiving identifier. After completion of the processing
of the arithmetic operation, the imperative-statement in the SIZE ERROR phrase is
processed.
statement is not processed until all of the individual additions or subtraction have
been completed.
ADD Statement
The ADD statement causes two or more numeric operands to be summed and the
result to be stored. The formats of the ADD statement are as follows:
Format 1
┌ ┐
ADD { identifier-1 } │ , identifier-2 │ . . . TO identifier-m [ ROUNDED ]
{ literal-1 } │ , literal-2 │
└ ┘
┌ ┐
│ , identifier-n [ ROUNDED ] │ . . . [ ON SIZE ERROR imperative-statement ]
└ ┘
Format 2
┌ ┐
ADD { identifier-1 } { identifier-2 } │ , identifier-3 │ . . .
{ literal-1 } { literal-2 } │ , literal-3 │
└ ┘
┌ ┐
GIVING identifier-m [ ROUNDED ] │ , identifier-n [ ROUNDED ] │ . . .
└ ┘
Format 3
ADD { CORRESPONDING } identifier-1 TO identifier-2 [ ROUNDED ]
{ CORR }
In Formats 1 and 2, each identifier, except those following the keyword GIVING must
name an elementary numeric item. In Format 2, each identifier following the
keyword GIVING must name an elementary numeric or numeric edited item. In
Format 3, each identifier must name a group item. In all formats, each literal must
be a numeric literal.
In Format 1, all identifiers or literals preceding the keyword TO are added together,
and this sum is added to and stored immediately in identifier-m. If specified, the
sum is then added to and stored immediately in identifier-n, and so on.
In Format 1, if the destination identification (after TO) is the same as the source
identification (before TO), the source is modified immediately and the result is used
on the remaining destination identifications.
In Format 2, at least two operands must precede the keyword GIVING. The values
of these operands are added together, and the sum is stored as the new value of
identifier-m, and, if specified, identifier-n, and so on.
If Format 3, elementary data items within identifier-1 are added to and stored in
the corresponding elementary items within identifier-2.
For the ROUNDED and SIZE ERROR phrases, and for operand considerations, refer to
the preceding “Common Phrases” on page 422 in this section.
COMPUTE Statement
The COMPUTE statement assigns the value of an arithmetic expression to one or
more data items.
Format
┌ ┐
COMPUTE identifier-1 [ ROUNDED ] │ , identifier-2 [ ROUNDED ] │ . . .
└ ┘
The COMPUTE statement allows the user to combine arithmetic operations without the
restrictions on the composite operands and/or receiving data items imposed by the
rules for the ADD, SUBTRACT, MULTIPLY, and DIVIDE statements.
The identifiers that appear to the left of the equal sign (=) must name either ele-
mentary numeric items or elementary numeric edited items.
When the COMPUTE statement is processed, the value of the arithmetic expression is
calculated; then this value is stored as the new value of identifier-1,
identifier-2, and so on, in turn.
For the ROUNDED and SIZE ERROR phrases, and for operand considerations, see
“Common Phrases” on page 422.
DIVIDE Statement
The DIVIDE statement divides one numeric data item into others and sets the
values of data items equal to the quotient and remainder. The formats of the
DIVIDE statement are:
Format 1
DIVIDE { identifier-1 } INTO identifier-2 [ ROUNDED ]
{ literal-1 }
┌ ┐
│ , identifier-3 [ ROUNDED ] │ . . . [ ON SIZE ERROR imperative-statement ]
└ ┘
Format 2
DIVIDE { identifier-1 } { INTO } { identifier-2 } GIVING identifier-3 [ ROUNDED ]
{ literal-1 } { BY } { literal-2 }
┌ ┐
│ , identifier-3 [ ROUNDED ] │ . . . [ ON SIZE ERROR imperative-statement ]
└ ┘
Format 3
DIVIDE { identifier-1 } { INTO } { identifier-2 } GIVING identifier-3 [ ROUNDED ]
{ literal-1 } { BY } { literal-2 }
Each identifier except those following the keywords GIVING and REMAINDER must
name an elementary numeric item. Each identifier following the keywords GIVING
and REMAINDER must name an elementary numeric or numeric edited item. Each
literal must be a numeric literal.
In Format 1, if the destination identification (after INTO) is the same as the source
identification (before INTO), the source is modified immediately and the result is
used on the remaining destination identifications.
The remainder is defined as the result of subtracting the product of the quotient and
the divisor from the dividend. If identifier-3 (the quotient) is a numeric edited
field, the quotient used to calculate the remainder is an intermediate field that con-
tains the unedited quotient.
For the ROUNDED and SIZE ERROR phrases, and for operand considerations, see
“Common Phrases” on page 422.
In addition to the conditions for common phrases, the following considerations apply
when the ROUNDED and SIZE ERROR phrases are used in Format 3.
When the ROUNDED phrase is specified, the quotient used to calculate the
remainder is an intermediate field which contains the quotient truncated rather
than rounded.
When the ON SIZE ERROR phrase is specified and the size error condition occurs
on the quotient, no remainder calculation is meaningful. Therefore, the con-
tents of the quotient field (identifier-3) and the remainder field (identifier-4)
are unchanged.
When the ON SIZE ERROR phrase is specified and the size error occurs on the
remainder, the contents of the remainder field (identifier-4) are unchanged.
Note: In the two preceding cases, the user must analyze the results to determine
which situation has actually occurred.
MULTIPLY Statement
The MULTIPLY statement causes numeric items to be multiplied and sets the values
of data items equal to the results. The formats of the MULTIPLY statement are:
Format 1
MULTIPLY { identifier-1 } BY identifier-2 [ ROUNDED ]
{ literal-1 }
┌ ┐
│ , identifier-3 [ ROUNDED ] │ . . . [ ON SIZE ERROR imperative-statement ]
└ ┘
Format 2
MULTIPLY { identifier-1 } BY { identifier-2 } GIVING identifier-3 [ ROUNDED ]
{ literal-1 } { literal-2 }
┌ ┐
│ , identifier-4 [ ROUNDED ] │ . . . [ ON SIZE ERROR imperative-statement ]
└ ┘
Each identifier except those following the keyword GIVING must name an elemen-
tary numeric item. Each identifier following the keyword GIVING must name an ele-
mentary numeric or numeric edited item. Each literal must be a numeric literal.
In Format 1, if the destination identification (after BY) is the same as the source
identification (before BY), the source is modified immediately and the result is used
on the remaining destination identifications.
For the ROUNDED and SIZE ERROR phrases, and for operand considerations, see
“Common Phrases” on page 422.
SUBTRACT Statement
The SUBTRACT statement causes either one, or the sum of two or more numeric
items to be subtracted from one or more numeric items and the result to be stored.
The formats of the SUBTRACT statement are:
Format 1
┌ ┐
SUBTRACT { identifier-1 } │ , identifier-2 │ . . . FROM identifier-3 [ ROUNDED ]
{ literal-1 } │ , literal-2 │
└ ┘
Format 2
┌ ┐
SUBTRACT { identifier-1 } │ , identifier-2 │ . . . FROM { identifier-3 }
{ literal-1 } │ , literal-2 │ { literal-3 }
└ ┘
┌ ┐
GIVING identifier-4 [ ROUNDED ] │ , identifier-5 [ ROUNDED ] │ . . .
└ ┘
Format 3
SUBTRACT { CORRESPONDING } identifier-1 FROM identifier-2 [ ROUNDED ]
{ CORR }
In Formats 1 and 2, each identifier except those following the keyword GIVING must
name an elementary numeric item. In Format 2, each identifier following the
keyword GIVING must name a numeric elementary or numeric edited elementary
item. In Format 3, each identifier must name a group item. In all formats, each
literal must be a numeric literal.
In Format 1, all identifiers or literals preceding the keyword FROM are added
together, and this sum is subtracted from and stored immediately in identifier-3,
and then, if specified, subtracted from and stored immediately in identifier-4, and
so on.
In Format 1, if the destination identification (after FROM) is the same as one of the
identifications (before FROM), the source is modified immediately and the result is
used on the remaining destination identifications.
In Format 2, all identifiers or literals preceding the keyword FROM are added
together and this sum is subtracted from identifier-3 or literal-3. The result of
the subtraction is stored as the new value of identifier-4, and, if specified,
identifier-5, and so on.
In Format 3, elementary data items within identifier-1 are subtracted from and
stored in the corresponding elementary data items within identifier-2.
For the ROUNDED and SIZE ERROR phrases, and for operand considerations, see
“Common Phrases” on page 422.
When the sending and receiving fields of a data manipulation statement share a
part of their storage (that is, when the operands overlap), the result of the proc-
essing of such a statement is unpredictable.
INSPECT Statement
The INSPECT statement specifies that characters in a data item are to be counted,
replaced, or counted and replaced. The formats of the INSPECT statement are:
Format 1
INSPECT identifier-1 TALLYING
{ { { { ALL } { identifier-3 } }
{ , identifier-2 FOR { ,{ { LEADING } { literal-1 } }
{ { { CHARACTERS }
{ {
┌ ┐ } }
│ { BEFORE } INITIAL { identifier-4 } │ } . . . } . . .
│ { AFTER } { literal-2 } │ } }
└ ┘ } }
Format 2
INSPECT identifier-1 REPLACING
{ ┌ ┐
{ CHARACTERS BY { identifier-6 } │ { BEFORE } INITIAL { identifier-7 } │
{ { literal-4 } │ { AFTER } { literal-5 } │
{ └ ┘
{ {
{ { { ALL } { { identifier-5 } BY { identifier-6 }
{ { , { LEADING } { , { literal-3 } { literal-4 }
{ { { FIRST } {
{ { {
}
} }
┌ ┐ } } }
│ { BEFORE } INITIAL { identifier-7 } │ } ... } ... }
│ { AFTER } { literal-5 } │ } } }
└ ┘ } } }
}
}
Format 3
INSPECT identifier-1 TALLYING
{
{ {
{ , identifier-2 FOR { { { ALL } { identifier-3 } }
{ { , { { LEADING } { literal-1 } }
{ { { CHARACTERS }
{
{
}
┌ ┐ } }
│ { BEFORE } INITIAL { identifier-4 } │ } . . . } . . .
│ { AFTER } { literal-2 } │ } }
└ ┘ } }
}
REPLACING
{ ┌ ┐ }
{ CHARACTERS BY { identifier-6 } │ { BEFORE } INITIAL { identifier-7 } │ }
{ { literal-4 } │ { AFTER } { literal-5 } │ }
{ └ ┘ }
{ { { }
{ { { ALL } { { identifier-5 } BY { identifier-6 } }
{ { , { LEADING } { , { literal-3 } { literal-4 } }
{ { { FIRST } { }
{ }
{ ┌ ┐ } } }
{ │ { BEFORE } INITIAL { identifier-7 } │ } ... } ... }
{ │ { AFTER } { literal-5 } │ } } }
{ └ ┘ } } }
{ }
{ }
Either the TALLYING or the REPLACING phrase must be specified. Both the TALLYING
and REPLACING phrases can be specified. If both TALLYING and REPLACING are spec-
ified (Format 3), all tallying is processed before any replacement is made.
All other identifiers except identifier-2 (the count field) must be elementary alpha-
betic, alphanumeric, or zoned decimal items. Each is treated according to its data
category. Each data category is treated as follows:
Alphabetic or alphanumeric items are treated as a character-string.
Alphanumeric edited, numeric edited, or unsigned numeric (zoned decimal)
items are treated as though redefined as alphanumeric, and the INSPECT state-
ment refers to the alphanumeric item.
Signed numeric (zoned decimal) items are treated as though moved to an
unsigned zoned decimal item of the same length, and then treated as though
redefined as alphanumeric. The INSPECT statement refers to the alphanumeric
item.
Each literal must be nonnumeric and can be any figurative constant except ALL.
When the TALLYING/REPLACING operands are the compared operands, the following
comparison rules apply:
1. When both the TALLYING and REPLACING phrases are specified, the INSPECT
statement is processed as if an INSPECT TALLYING statement were specified and
immediately followed by an INSPECT REPLACING statement.
2. The first operand is compared with an equal number of leftmost contiguous
characters in the inspected item. The operand matches the inspected charac-
ters only if both are equal, character for character.
3. If no match occurs for the first operand, the comparison is repeated for each
successive operand until either a match is found or all operands have been
acted upon.
4. If a match is found, tallying or replacing takes place as described in
TALLYING/REPLACING phrase descriptions. In the inspected item, the first char-
acter following the rightmost matching character is now considered the leftmost
character position. The process described in comparison rules 2 and 3 is then
repeated.
5. If no match is found, the first character in the inspected item following the left-
most inspected character is now considered the leftmost character position.
The process described in comparison rules 2 and 3 is then repeated.
6. If the CHARACTERS phrase is specified, an implied 1-character operand is used in
the process described in rules 2 and 3. The implied character is considered to
always match the inspected character of the item inspected.
7. The actions taken in comparison rules 1 through 6–which are defined as the
comparison cycle–are repeated until the rightmost character in the inspected
item has either been matched or has been considered as the leftmost character
position. Inspection then terminates.
At end of inspection:
Note: When the BEFORE/AFTER phrase is specified, the preceding results are modi-
fied as described in the BEFORE/AFTER phrase description.
INSPECT
The following example shows an INSPECT statement.
.. 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7
DATA DIVISION.
WORKING-STORAGE SECTION.
1 ID-1 PIC X(1) VALUE "ACADEMIANS".
1 CONTR-1 PIC 99 VALUE .
1 CONTR-2 PIC 99 VALUE ZEROS.
PROCEDURE DIVISION.
@ THIS ILLUSTRATES AN INSPECT STATEMENT WITH 2 VARIABLES.
1-BEGIN-PROCESSING.
DISPLAY CONTR-1 SPACE CONTR-2.
11-MAINLINE-PROCESSING.
PERFORM COUNT-IT THRU COUNT-EXIT.
STOP RUN.
COUNT-IT.
INSPECT ID-1
TALLYING CONTR-1
FOR CHARACTERS BEFORE INITIAL "AD"
CONTR-2
FOR ALL "MIANS".
DISPLAY-COUNTS.
DISPLAY "CONTR-1 = " CONTR-1.
DISPLAY "CONTR-2 = " CONTR-2.
DISPLAY "@@@@@@@@@EOJ@@@@@@@@@".
COUNT-EXIT.
EXIT.
Resultant Output:
CONTR-1 = 2
CONTR-2 = 1
@@@@@@@@@EOJ@@@@@@@@@
TALLYING Phrase
Identifier-2 is the tallying field and must be an elementary integer item defined
without the symbol P in its PICTURE character-string. Identifier-2 must be initial-
ized before the INSPECT statement is processed.
REPLACING Phrase
Identifier-5 or literal-3 is the comparison operand. Identifier-6 or literal-4
is the replacement field.
The comparison operand and the replacement field must be the same length. The
following replacement rules apply:
If the comparison operand is a figurative constant, it is considered to be a one-
character nonnumeric literal. Each character in the inspected item equivalent
to the figurative constant is replaced by the single-character replacement field,
which must be one character in length.
BEFORE/AFTER Phrases
The keywords BEFORE and AFTER should not be used in the same statement.
When either of these phrases is specified, the preceding actions for tallying and
replacing are modified.
When the BEFORE phrase is specified, tallying and/or replacement of the inspected
item begins at the leftmost character and continues until the first occurrence of the
delimiter is encountered. If no delimiter is present in the inspected item, tallying
and/or replacement continues to the rightmost character.
When the AFTER phrase is specified, tallying and/or replacement of the inspected
item begins with the first character to the right of the delimiter and continues to the
rightmost character in the inspected item. If no delimiter is present in the inspected
item, no tallying or replacement takes place.
When the BEFORE/AFTER phrase is not specified, the following actions take place
when the INSPECT TALLYING statement is processed:
If the ALL phrase is specified, the tallying field is increased by one for each
nonoverlapping occurrence in the inspected item of the comparison operand.
This process begins at the leftmost character position and continues to the
rightmost.
If the LEADING phrase is specified, the tallying field is increased by one for each
contiguous nonoverlapping occurrence of the comparison operand in the
inspected item, provided the leftmost such occurrence is at the point where
comparison began in the first comparison cycle for which the comparison
operand is eligible to participate.
If the CHARACTERS phrase is specified, the tallying field is increased by one for
each character (including the space character) in the inspected item. Thus,
processing of the INSPECT TALLYING statement increases the value in the tal-
lying field by the number of characters in the inspected item.
When the BEFORE/AFTER phrase is not specified, the following actions take place
when the INSPECT REPLACING statement is processed:
If the CHARACTERS phrase is specified, the replacement field must be 1 character
in length. Each character in the inspected field is replaced by the replacement
field. This process begins at the leftmost character and continues to the right-
most.
If the ALL phrase is specified, each nonoverlapping occurrence of the compar-
ison operand in the inspected item is replaced by the replacement field, begin-
ning at the leftmost character and continuing to the rightmost.
If the LEADING phrase is specified, each contiguous nonoverlapping occurrence
of the comparison operand in the inspected item is replaced by the replace-
ment field, provided that the leftmost such occurrence is at the point where
comparison began in the first comparison cycle for which this replacement field
is eligible to participate.
If the FIRST phrase is specified, the leftmost occurrence of the comparison
operand in the inspected item is replaced by the replacement field.
INSPECT ID-1 TALLYING COUNTR FOR CHARACTERS AFTER INITIAL "S" REPLACING ALL
"A" BY "O".
INSPECT ID-1 TALLYING COUNTR FOR LEADING "" REPLACING FIRST "A" BY "2"
AFTER INITIAL "C".
Note: The INSPECT statement is useful for filling all or part of a data item with
spaces or zeros. It is also useful for counting the number of times a specific char-
acter (for example, zero, space, asterisk) occurs in a data item. In addition, it can
be used to translate characters from one collating sequence to another.
MOVE Statement
The MOVE statement transfers data from one area of storage to one or more other
areas. The formats of the MOVE statement are as follows:
Format 1
MOVE { identifier-1 } TO identifier-2 [ , identifier-3 ] . . .
{ literal }
Format 2
MOVE { CORRESPONDING } identifier-1 TO identifier-2
{ CORR }
General Considerations
Identifier-1 or literal is the sending area. Identifier-2, identifier-3, and so
on are the receiving areas.
is equivalent to
where TEMP has been defined as an intermediate result item. The subscript B
changed in value between the time the first move took place and the time the final
move to C (B) was processed.
After processing of a MOVE statement, a sending field contains the same data as
before processing, unless a receiving field overlaps the sending field.
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 processed). Unex-
pected 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 processed).
Elementary Moves
An elementary move is one in which both the sending and receiving items are ele-
mentary items. Each elementary item belongs to one of the following categories:
Numeric: Includes numeric data items, numeric literals, and the figurative con-
stant ZERO/ZEROS/ZEROES
Alphabetic: Includes alphabetic data items and the figurative constant
SPACE/SPACES.
Both identifiers following the keyword CORRESPONDING must name group items. In
this discussion, these identifiers are referred to as d1 and d2.
A pair of subordinate data items, one from d1 and one from d2, correspond if the
following conditions are true:
At least one of the subordinate items is elementary.
The two subordinate items have the same name and the same qualifiers up to
but not including d1 and d2.
The subordinate items are not identified by the keyword FILLER.
The subordinate items do not include a REDEFINES, RENAMES, OCCURS, or USAGE
IS INDEX clause in their descriptions; if such a subordinate item is a group item,
the items subordinate to it are also ignored. However, d1 and d2 themselves
can contain or be subordinate to items containing a REDEFINES or OCCURS clause
in their description.
For example, two data hierarchies are defined as follows:
5 ITEM-1 OCCURS 6 INDEXED BY X.
1 ITEM-A ...
1 ITEM-B ...
1 ITEM-C REDEFINES ITEM-B ...
5 ITEM-2.
1 ITEM-A ...
1 ITEM-B ...
1 ITEM-C ...
If MOVE CORR ITEM-2 TO ITEM-1(X) is specified, ITEM-A and ITEM-A(X), and ITEM-B
and ITEM-B(X) are considered to be corresponding and the moves are processed.
ITEM-C and ITEM-C(X) are not included because ITEM-C(X) includes a REDEFINES
clause in its data description. ITEM-1 is valid as either d1 or d2.
Neither d1 nor d2 is described as a level 66, 77 or 88 item, or as a FILLER or
USAGE IS INDEX item.
IBM Extension
IBM Extension
– If the size of the sending item is greater than the size of the receiving item,
excess characters at the right are truncated after the receiving item is filled.
IBM Extension
For a Boolean receiving field, only the first byte of the sending item is moved.
Note: If the receiving field is alphanumeric or numeric edited, and the sending
field is a scaled integer (that is, it 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 processed.
Figure 82 shows valid and invalid elementary moves for each category.
Group Moves
A group move is one in which one or both of the sending and receiving fields are a
group item. A group move is treated exactly as though it were an alphanumeric
elementary move except that data is not converted from one form of internal repre-
sentation to another. In a group move, the receiving area is filled without consider-
ation for the individual elementary items contained within either the sending area or
the receiving area. See “OCCURS Clause” on page 476 for additional information.
┌───────────────┬─────────────────────────────────────────────────────────────────────────────────────┐
│ │ Receiving Item Category │
│ Sending ├────────────┬──────────────┬──────────────┬─────────┬────────────┬─────────┬─────────┤
│ Item │ │ │ Alphanumeric │ Numeric │ Numeric │ Numeric │ │
│ Category │ Alphabetic │ Alphanumeric │ Edited │ Integer │ Noninteger │ Edited │ Boolean │
├───────────────┼────────────┼──────────────┼──────────────┼─────────┼────────────┼─────────┼─────────┤
│ Alphabetic │ YES │ YES │ YES │ NO │ NO │ NO │ NO │
│ and SPACE │ │ │ │ │ │ │ │
├───────────────┼────────────┼──────────────┼──────────────┼─────────┼────────────┼─────────┼─────────┤
│ Alphanumeric │ YES │ YES │ YES │ YES │ YES │ YES │ YES │
├───────────────┼────────────┼──────────────┼──────────────┼─────────┼────────────┼─────────┼─────────┤
│ Nonnumeric │ YES │ YES │ YES │ YESz │ YESz │ YESz │ YES │
│ Literal │ │ │ │ │ │ │ │
├───────────────┼────────────┼──────────────┼──────────────┼─────────┼────────────┼─────────┼─────────┤
│ Alphanumeric │ YES │ YES │ YES │ NO │ NO │ NO │ NO │
│ Edited │ │ │ │ │ │ │ │
├───────────────┼────────────┼──────────────┼──────────────┼─────────┼────────────┼─────────┼─────────┤
│ Numeric │ NO │ YES │ YES │ YES │ YES │ YES │ NO │
│ Integer │ │ │ │ │ │ │ │
├───────────────┼────────────┼──────────────┼──────────────┼─────────┼────────────┼─────────┼─────────┤
│ Numeric │ NO │ NO │ NO │ YES │ YES │ YES │ NO │
│ Noninteger │ │ │ │ │ │ │ │
├───────────────┼────────────┼──────────────┼──────────────┼─────────┼────────────┼─────────┼─────────┤
│ Numeric │ NO │ YES │ YES │ NO │ NO │ NO │ NO │
│ Edited │ │ │ │ │ │ │ │
├───────────────┼────────────┼──────────────┼──────────────┼─────────┼────────────┼─────────┼─────────┤
│ LOW/HIGH- │ NO │ YES │ YES │ NO │ NO │ NO │ NO │
│ VALUES QUOTES │ │ │ │ │ │ │ │
├───────────────┼────────────┼──────────────┼──────────────┼─────────┼────────────┼─────────┼─────────┤
│ ZERO │ NO │ YES │ YES │ YES │ YES │ YES │ YES │
├───────────────┼────────────┼──────────────┼──────────────┼─────────┼────────────┼─────────┼─────────┤
│ Boolean │ NO │ YES │ YES │ NO │ NO │ NO │ YES │
├───────────────┴────────────┴──────────────┴──────────────┴─────────┴────────────┴─────────┴─────────┤
│ YES = move is valid │
│ NO = move is invalid │
│ ______________________ │
│ z Moved only if an unsigned integer. │
│ Includes numeric literals. │
│ Includes Boolean literals. │
│ Compiler assumes alphanumeric item is an unsigned integer. │
│ Compiler assumes item is a or a 1. │
└─────────────────────────────────────────────────────────────────────────────────────────────────────┘
Note: Boolean in the Sending Item Category and in the Receiving Item Category
represents an IBM Extension to ANS COBOL X3.23-1974.
Format 1 Considerations
When Format 1 is specified, the identifiers can be either group or elementary items.
The data in the sending area is moved into the first receiving area (identifier-2);
then it is moved from the sending area into the second receiving area
(identifier-3), and so on.
Format 2 Considerations
CORRESPONDING Phrase: The CORRESPONDING phrase allows data to be moved
between elementary items of the same name simply by specifying the group items
to which they belong.
SET Statement
IBM Extension
The SET statement is used to alter the status of external switches and the values of
conditional variables. See “SET Statement” on page 488 for the Format 3 and
Format 4.
Format 1
╔════════════════════════════════════════════════════════════╗
║ SET mnemonic-name-1 [ , mnemonic-name-2 ] . . . TO { ON } ║
║ { OFF } ║
╚════════════════════════════════════════════════════════════╝
Format 2
╔═══════════════════════════════════════════════════════════╗
║ SET condition-name-1 [ , condition-name-2 ] . . . TO TRUE ║
╚═══════════════════════════════════════════════════════════╝
The status of each external switch associated with the specified mnemonic-name is
modified such that the truth value resultant from evaluation of a condition-name
associated with that switch will reflect an on status if the ON phrase is specified, or
an off status if the OFF phrase is specified. For additional information, refer to
“Switch-Status Condition” on page 359 earlier in this chapter.
Format 2 allows conditional items to be set to their stated values. The literal in the
VALUE clause associated with the condition-name is moved to the conditional vari-
able according to the rules for elementary moves.
If multiple condition-names are specified, the results are the same as those
obtained if a separate SET statement were written for each condition-name in the
same order specified in the SET statement.
STRING Statement
The STRING statement gives the programmer the ability to concatenate the partial or
complete contents of two or more data items into a single data item.
Format
┌ ┐
STRING { identifier-1 } │ , identifier-2 │ . . . DELIMITED BY { identifier-3 }
{ literal-1 } │ , literal-2 │ { literal-3 }
└ ┘ { SIZE }
┌ ┌ ┐ ┐
│ , { identifier-4 } │ , identifier-5 │ . . . DELIMITED BY { identifier-6 } │
│ { literal-4 } │ , literal-5 │ { literal-6 } │ . . .
│ └ ┘ { SIZE } │
└ ┘
[ ON OVERFLOW imperative-statement ]
Each literal must be a nonnumeric literal; each can be any figurative constant
except the ALL literal. When a figurative constant is specified, it is considered a
one-character nonnumeric literal.
All identifiers except identifier-8 (the pointer item) must have USAGE DISPLAY,
explicitly or implicitly.
When the sending field or any of the delimiters are elementary numeric items, they
must be described as integers, and their PICTURE character-strings must not contain
the symbol P.
The pointer field is identifier-8, which must be an elementary integer data item
large enough to contain a value equal to the length of the receiving area plus one.
The pointer field must not contain the symbol P in its PICTURE character-string.
After STRING statement processing is completed, only that part of the receiving field
into which data was transferred is changed. The rest of the receiving field contains
the data that was present before this processing of the STRING statement.
Figure 83 on page 443 illustrates the rules of processing for the STRING statement.
Results:
ID-8
(pointer)
after Processing
┌───┬───┐
│ 1 │ 6 │
└───┴───┘
(initialized to 1 before processing)
In the Data Division, the programmer has defined the following fields:
1 RPT-LINE PICTURE X(12).
1 LINE-POS PICTURE 99.
1 LINE-NO PICTURE 9(5) VALUE 1.
1 DEC-POINT PICTURE X VALUE ".".
The user wants to construct an output line consisting of portions of the information
from RCD-01. The line is to consist of a line number, customer name and address,
invoice number, date due, and balance due, truncated to the dollar figure shown.
J.B.␣SMITH␣␣␣␣␣
444␣SPRING␣ST.,␣CHICAGO,␣ILL.␣␣␣␣␣
A14275
$4,736.85
$2,4.
9/22/76
$2,336.85
1/22/76
In the Procedure Division, the user initializes RPT-LINE to SPACES and sets LINE-POS
(which is to be used as the pointer field) to 4. Then he issues this STRING
statement:
┌───────────────────────────────────────────────────────┐
│ Column │
│ 4 1 25 │
│ │ │ │ │
│ │ │ │ │
│ m m m │
│ 1 J.B. SMITH 444 SPRING ST., CHICAGO, ILL. │
│ │
│ 6 67 76 │
│ │ │ │ │
│ │ │ │ │
│ m m m │
│ A14725 1/22/76 $2,336 │
└───────────────────────────────────────────────────────┘
Figure 84. STRING Statement Example Output Data
UNSTRING Statement
The UNSTRING statement causes contiguous data in a sending field to be separated
and placed into multiple receiving fields.
Format
UNSTRING identifier-1
┌ ┌ ┐ ┐
│ DELIMITED BY [ ALL ] { identifier-2 } │ , OR [ ALL ] { identifier-3 } │ . . . │
│ { literal-1 } │ { literal-2 } │ │
└ └ ┘ ┘
┌ ┐
│ , identifier-7 [ , DELIMITER IN identifier-8 ] [ , COUNT IN identifier-9 ] │ . . .
└ ┘
[ ON OVERFLOW imperative-statement ]
Each literal must be a nonnumeric literal; each may be any figurative constant
except ALL literal. When a figurative constant is specified, it is considered to be a
one-character nonnumeric literal.
Sending Field
Identifier-1 is the sending field. It must be an alphanumeric data item. Data is
transferred from this field to the receiving fields.
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 specified,
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, and the search for another
delimiter resumes with C.
When the DELIMITED BY ALL phrase is not specified, and two or more contiguous
occurrences 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.
When the DELIMITED BY ALL phrase is specified, one or more contiguous occur-
rences of any delimiter are treated as if they were only one occurrence, and this
one occurrence is moved to the delimiter receiving field (if specified). The delim-
iting 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.
The DELIMITER IN and COUNT IN phrases can be specified only if the DELIMITER BY
phrase is specified.
These fields must not be defined as alphanumeric edited or numeric edited items.
Data is transferred to these fields from the sending field.
COUNT IN Phrase: The data-count fields for each data transfer are identifier-6,
identifier-9, and so on. These identifiers must be described as elementary
numeric integer data items; they cannot contain the symbol P in their PICTURE
clauses. Each field holds the count of delimited characters in the sending field to
be transferred to this receiving field; the delimiters are not included in this count.
The data-count fields, the pointer field, and the field-count field must each be
integer items without the symbol P in the PICTURE character-strings.
current data receiving field, the preceding procedure is repeated–either until all
of the characters in the sending field have been transferred, or until there are
no more unfilled data receiving fields.
When the POINTER phrase is specified, the contents of the pointer field behaves
as if incremented by one for each examined character in the sending field.
When this processing 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.
When the TALLYING phrase is specified and the processing of the UNSTRING
statement is completed, the tallying identifier contains a value equal to the
initial value plus the number of data receiving areas acted upon; this count
includes any null fields.
When an overflow condition exists, the processing of the UNSTRING statement is
terminated. If the ON OVERFLOW phrase has been specified, that imperative-
statement is processed. If the ON OVERFLOW phrase has not been specified,
control passes to the next executable statement. An overflow condition exists
when:
– An UNSTRING statement is initiated and the value in the pointer field is less
than 1 or greater than the length of the sending field.
– Or, all data receiving fields have been acted upon during UNSTRING state-
ment processing, and the sending field still contains unexamined charac-
ters.
Note: If any of the UNSTRING statement identifiers are subscripted or indexed, the
subscripts 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.
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 85 on page 449 illustrates the processing rules for the UNSTRING statement.
In the Data Division, the user has defined the following input record to be acted
upon by the 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.
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 86.
┌───────────────────────────────────────────────────────────────────────┐
│ Column │
│ │
│ 1 1 2 3 4 5 6 │
│ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │
│ m m m m m m m │
│ ZYFOUR-PENNY-NAILS 7789/BBA 47512 122 379.5 │
└───────────────────────────────────────────────────────────────────────┘
Figure 86. UNSTRING Statement Example–Input Data
When the UNSTRING statement is processed, 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 char-
acters are considered to be one occurrence of the delimiter.
3. Positions 24 through 29 (7789) are placed in INV-NO. The delimiter character
/ 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 (47512) 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 (122) are placed in FIELD-A and right-justified within
the area. The high-order digit position is filled with a 0 (zero). The delimiter is
a SPACE, but because no field has been defined as a receiving area for delim-
iters, the SPACE is bypassed.
7. Positions 48 through 53 (379) 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 proc-
essing of the UNSTRING statement is completed.
At the end of processing of the UNSTRING statement, DISPLAY-REC contains the fol-
lowing data:
47512122BBA
CHAR-CT (the pointer field) contains the value 55, and FLD-FILLED (the tallying field)
contains the value 6.
Note: One UNSTRING statement can be written instead of a series of MOVE state-
ments.
ALTER Statement
The ALTER statement changes the transfer point specified in a GO TO statement.
Format
ALTER procedure-name-1 TO [ PROCEED TO ] procedure-name-2
┌ ┐
│ , procedure-name-3 TO [ PROCEED TO ] procedure-name-4 │ . . .
└ ┘
Before the ALTER statement is processed, when control reaches PARAGRAPH-1, the GO
TO statement transfers control to BYPASS-PARAGRAPH. After processing of the ALTER
statement, however, the next time control reaches PARAGRAPH-1, the GO TO state-
ment transfers control to PARAGRAPH-2.
Note: The ALTER statement acts as a program switch, allowing, for example, one
sequence of processing during initialization and another sequence during the bulk
of file processing. Because altered GO TO statements are difficult to debug, it is
preferable to test a switch, and based on the value of the switch, process a partic-
ular code sequence.
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 proc-
essed.
EXIT Statement
The EXIT statement provides a common end point for a series of procedures.
Format
EXIT [ PROGRAM ].
The EXIT statement must appear in a sentence by itself, and this sentence must be
the only sentence in the paragraph. The EXIT statement lets the user assign a
procedure-name to a given point in a program.
The EXIT statement has no other effect on the compilation or running of the
program.
If an EXIT statement is not written, the end of the sequence is difficult to determine
unless the user knows the logic of the program.
GO TO Statement
The GO TO statement transfers control from one part of the Procedure Division to
another. The formats of the GO TO statement are as follows:
Format 1
GO TO [ procedure-name-1 ]
Format 2
GO TO procedure-name-1 [ , procedure-name-2 ] . . . , procedure-name-n
DEPENDING ON identifier
Format 1–Unconditional GO TO
The GO TO statement transfers control to the first statement in the paragraph or
section named in procedure-name-1 unless the GO TO statement has been modified
by an ALTER statement.
Format 2–Conditional GO TO
Control is transferred to one of a series of procedures, depending on the value of
identifier. Identifier must name an elementary integer item. When identifier
has a value of one, control is transferred to the first statement in the procedure
named by procedure-name-1; if it has a value of two, control is transferred to the
first statement in the procedure named by procedure-name-2, and so on.
If the value of identifier is anything other than a value within the range 1 through
n (where n is the number of procedure-names specified in this GO TO statement),
the GO TO statement is ignored. Instead, control passes to the next statement in the
normal sequence of processing.
PERFORM Statement
The PERFORM statement transfers control explicitly to one or more procedures and
implicitly returns control to the next executable statement after processing of the
specified procedure(s) is completed. The formats of the PERFORM statement are as
follows:
Format 1
┌ ┐
PERFORM procedure-name-1 │ { THROUGH } procedure-name-2 │
│ { THRU } │
└ ┘
Format 2
┌ ┐
PERFORM procedure-name-1 │ { THROUGH } procedure-name-2 │ { identifier-1 } TIMES
│ { THRU } │ { integer-1 }
└ ┘
Format 3
┌ ┐
PERFORM procedure-name-1 │ { THROUGH } procedure-name-2 │ UNTIL condition-1
│ { THRU } │
└ ┘
Format 4
┌ ┐
PERFORM procedure-name-1 │ { THROUGH } procedure-name-2 │
│ { THRU } │
└ ┘
┌
│ AFTER { identifier-4 } FROM { identifier-5 }
│ { index-name-4 } { index-name-5 }
│ { literal-5 }
└
┌
│ AFTER { identifier-7 } FROM { identifier-8 }
│ { index-name-7 } { index-name-8 }
│ { literal-8 }
└
┐ ┐
BY { identifier-9 } UNTIL condition-3 │ │
{ literal-9 } │ │
│ │
┘ ┘
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 PERFORM
statement. That is, an active PERFORM statement whose processing 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 state-
ment. In addition, two or more such active PERFORM statements must not have a
common exit.
IBM Extension
Figure 87 on page 458 illustrates valid sequences of processing for PERFORM state-
ments.
The preceding rules refer to all four formats of the PERFORM statement. The fol-
lowing sections give rules applying to each individual format.
Format 1
Format 1 is the basic PERFORM statement. The procedure(s) referred to is proc-
essed once, and then control passes to the next executable statement following the
PERFORM statement.
Format 2
Format 2 uses the TIMES phrase. Identifier-1 must name an integer item. The
procedure(s) referred to is processed 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. The following rules apply:
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 reference to identifier-1
or change in the value of identifier-1 has no effect in varying the number of
times the procedures are run.
Format 3
Format 3 uses the UNTIL phrase. The procedure(s) referred to is processed until
the condition specified by the UNTIL phrase is true. Control is then passed to the
next executable statement following the PERFORM statement.
If condition-1 is true at the time the PERFORM statement is encountered, the speci-
fied procedure(s) is not processed.
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.────────┴─────┘ ║
╚══════════════════════════════╝
Format 4
Format 4 uses the VARYING phrase. This phrase increments or decrements one or
more identifiers or index-names according to the following rules. Once the
condition(s) specified in the UNTIL phrase is satisfied, control is passed to the next
executable statement following the PERFORM statement.
No matter how many variables are specified, the following rules apply:
In the VARYING/AFTER phrases, when an index-name is specified:
– The index-name is initialized and incremented or decremented according to
the rules for the SET statement. For a description of the SET statement, see
“TABLE HANDLING” on page 469.
– 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.
– In the associated BY phrase, an identifier must be described as an integer;
a literal must be a nonzero integer.
In the FROM phrase, when an index-name is specified:
– In the associated VARYING/AFTER phrase, an identifier must be described as
an integer. It is initialized as described in the SET statement.
– 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.
In the BY phrase, identifiers and literals must have a nonzero value.
Changing the values of identifiers and/or index-names in the VARYING, AFTER,
FROM, and BY phrases during processing changes the number of times the pro-
cedures are run.
Figure 88 on page 460 is a flowchart illustrating the logic of the PERFORM statement
when one identifier is varied.
Exec ution of
PERFORM
Statem ent Begins
Test True
C o n d it io n -1 Exit
False
Execute
Procedure-1
THRU
Procedure-2
Augment
ide n tifie r-1
w it h it s
Current
BY Value
The following example shows a PERFORM statement varying one identifier. This
PERFORM logic is processed 100 times.
.. 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... 7
DATA DIVISION.
WORKING-STORAGE SECTION.
1 SUB1 PIC 999.
1 TOTAL-HOLD PIC 99 VALUE 57.
1 HOLD-2 PIC 99 VALUE 1.
1 HOLD-THE-SUM PIC 99 VALUE ZERO.
1 TABLE-ELEMENT.
3 ELEMENTS-OF-TABLE PIC 9 OCCURS 1 TIMES.
PROCEDURE DIVISION.
1-START-PROCESSING.
@ THIS PERFORM LOGIC IS PROCESSED 1 TIMES.
PERFORM SAMPLE-PERFORM THRU PERFORM-EXIT
VARYING SUB1 FROM 1 BY 1 UNTIL SUB1 GREATER THAN 1.
@ THIS ADD STATEMENT IS PROCESSED AFTER PERFORM IS DONE.
ADD TOTAL-HOLD HOLD-2 GIVING HOLD-THE-SUM.
DISPLAY "TOTAL OF TWO VARIABLES = " HOLD-THE-SUM.
PERFORM ANOTHER-WAY-TO-INITIALIZE THRU AWTI-EXIT.
@ THE TABLE WILL BE ALL ZEROS AND SHOULD PRINT AS SUCH.
DISPLAY "THE TABLE " TABLE-ELEMENT.
STOP RUN.
SAMPLE-PERFORM.
MOVE ZEROS TO ELEMENTS-OF-TABLE (SUB1).
PERFORM-EXIT.
EXIT.
ANOTHER-WAY-TO-INITIALIZE.
MOVE ZEROS TO TABLE-ELEMENT.
AWTI-EXIT.
EXIT.
Figure 89 on page 463 is a flowchart illustrating the logic of the PERFORM statement
when two identifiers are varied.
The following example shows a PERFORM statement varying two identifiers. This
PERFORM logic is processed 126 times. This program searches a table and gives a
total of female employees.
.. 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7
DATA DIVISION.
FILE SECTION.
FD PRINTED-REPORT
LABEL RECORDS OMITTED.
1 PRINT-OUT PIC X(132).
FD EMPLOYEE-DATA
BLOCK CONTAINS 1 RECORDS
RECORD CONTAINS 8 CHARACTERS
LABEL RECORDS STANDARD
DATA RECORD IS EMPLOYEE-RECORD.
1 EMPLOYEE-RECORD PIC X(9).
WORKING-STORAGE SECTION.
1 RECORDS-IN PIC 9(5) VALUE ZEROS.
1 EOF-SW PIC X VALUE "N".
1 HOLD-INPUT-RECORD.
3 EMPLOYEE-SEX PIC 9.
88 MALE VALUE IS 1.
88 FEMALE VALUE IS 2.
3 EMPLOYEE-RACE PIC 9.
88 RACE-CODES VALUES ARE 1 THRU 7.
3 EMPLOYEE-JOB-CLASS PIC 99.
88 JOB-CLASS VALUES ARE 1 THRU 18.
3 FILLER PIC X(76) VALUE SPACES.
1 EMPLOYEE-TABLE.
3 E-SEX OCCURS 2 TIMES.
5 E-RACE OCCURS 7 TIMES.
7 E-JOB OCCURS 18 TIMES PIC 99.
1 SUB1 PIC 99.
1 SUB2 PIC 99.
1 SUB3 PIC 99.
1 TOTAL-WOMEN PIC 9(5) VALUE ZEROS.
PROCEDURE DIVISION.
1-START-IT.
OPEN INPUT EMPLOYEE-DATA OUTPUT PRINTED-REPORT.
MOVE ZEROS TO EMPLOYEE-TABLE.
2-READ-IT.
READ EMPLOYEE-DATA RECORD INTO HOLD-INPUT-RECORD
AT END MOVE "Y" TO EOF-SW.
ADD 1 TO RECORDS-IN.
3-MAINLINE-LOGIC.
@ THE PERFORM STATEMENT USING 2 VARIABLES WILL BE DONE 126
@ TIMES
PERFORM LOAD-TABLE UNTIL EOF-SW = "Y".
Exec ution of
PERFORM
Statem ent Begins
Id e n tifie r-1
Id e n tifie r-4
S e t to Initia l
FR O M Values
C1
Test True
C o n d it io n -1 Exit
False
Test True
C o n d itio n - 2
False
Execute
S e t ide ntifie r-4
Procedure-1
to its C urrent
THRU
F R O M Va lu e
Procedure-2
Augment Augment
id e n tifie r-4 ide n tifie r-1
w it h it s w it h it s
Current Current
BY Value BY Value
C1
PERFORM FIND-NUMBER-OF-WOMEN
VARYING SUB2 FROM 1 BY 1 UNTIL SUB2 > 7
AFTER SUB3 FROM 1 BY 1 UNTIL SUB3 > 18.
PERFORM WRITE-REPORT THRU WR-EXIT.
DISPLAY "TOTAL RECORDS IN " RECORDS-IN.
STOP RUN.
LOAD-TABLE.
MOVE EMPLOYEE-SEX TO SUB1.
MOVE EMPLOYEE-RACE TO SUB2.
MOVE EMPLOYEE-JOB-CLASS TO SUB3.
ADD 1 TO E-JOB (SUB1 SUB2 SUB3).
PERFORM 2-READ-IT.
FIND-NUMBER-OF-WOMEN.
ADD E-JOB (2 SUB2 SUB3) TO TOTAL-WOMEN.
WRITE-REPORT.
The actions are the same as for varying two identifiers except that identifier-7
goes through the complete cycle each time that identifier-4 is augmented by
identifier-6 or literal-6, which in turn goes through a complete cycle each time
identifier-1 is varied.
Figure 90 on page 465 is a flowchart illustrating the logic of the PERFORM statement
when three identifiers are varied.
Exec ution of
PERFORM
Statem ent Begins
Id e n tifie r-1
Id e n tifie r-4
Id e n tifie r-7
S e t to Initia l
FR O M Values
Test True
C2 C o n d it io n -1 Exit
False
Test True
D2 C o n d itio n - 2
False
Test True
C o n d it io n - 3
False
Execute
S et iden tifier-7 S e t ide ntifie r-4
Procedure-1
to its C urrent to its C urrent
THRU
F R O M Va lu e F R O M Va lu e
Procedure-2
D2 C2
The following example shows a PERFORM statement varying three identifiers. This
PERFORM logic is run 250 times.
.. 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7
DATA DIVISION.
WORKING-STORAGE SECTION.
1 SUB1 PIC 99.
1 SUB2 PIC 99.
1 SUB3 PIC 99.
1 TEST-IT PIC 99 VALUE .
1 TOTAL-RECS PIC 99 VALUE ZEROS.
1 COMPANY-TABLE.
5 DIVISION-IN OCCURS 1 TIMES.
1 DIVISION-NAME PIC X(1).
1 DIVISION-NUMBER PIC 9(4).
1 SECTION-IN OCCURS 5 TIMES.
15 UNIT-IN OCCURS 5 TIMES.
2 UNIT-NAME PIC X(5).
2 UNIT-NUMBER PIC 9(4).
PROCEDURE DIVISION.
1-START-PROCESSING.
@ THIS PERFORM LOGIC IS PROCESSED 25 TIMES
PERFORM ZERO-OUT-BIG-TABLE
VARYING SUB1 FROM 1 BY 1 UNTIL SUB1 > 1
@ SUB1 IS VARIED LAST
AFTER SUB2 FROM 1 BY 1 UNTIL SUB2 > 5
@ SUB2 IS VARIED SECOND
AFTER SUB3 FROM 1 BY 1 UNTIL SUB3 > 5.
@ SUB3 IS VARIED FIRST
PERFORM ADDRESS-THE-VARIABLES THRU ATV-EXIT.
DISPLAY "VARIABLE TEST-IT = " TEST-IT.
STOP RUN.
ZERO-OUT-BIG-TABLE.
MOVE ZEROS TO UNIT-IN (SUB1 SUB2 SUB3).
ADDRESS-THE-VARIABLES.
IF UNIT-NUMBER OF UNIT-IN OF SECTION-IN OF DIVISION-IN
OF COMPANY-TABLE (3 4 5) =
ADD 1 TO TEST-IT.
ATV-EXIT.
EXIT.
Note: The procedures run by a PERFORM statement are, in effect, a closed subrou-
tine that can be entered from many other points in the program.
The Format 4 PERFORM statement is especially useful in table handling. One Format
4 PERFORM statement can serially search an entire three-dimensional table.
Segmentation Information
A PERFORM statement appearing in a permanent segment can have in its range only
one of the following:
Sections, each of which has a segment number less than 50
Sections and/or paragraphs wholly contained in a single independent segment.
A PERFORM statement that appears in an independent segment can have in its range
only one of the following:
Sections, each of which has a segment number less than 50
Control is passed to the performed procedures only once for each processing of the
PERFORM statement.
STOP Statement
The STOP statement halts the object program either temporarily or permanently.
Format
STOP { RUN }
{ literal }
The literal can be numeric or nonnumeric, and can be any figurative constant
except ALL literal. If the literal is numeric, it must be an unsigned integer.
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 processing is sus-
pended. Processing 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 processed.
Operator
Response Action
G (default) Continue at next instruction.
C Terminate processing of the run unit. Escape message CBE91 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 followed by the literal.
If the literal cannot be contained in the length of one line of the display device, the
Help key must be used to display the entire literal.
When STOP RUN is specified, processing of the run unit is terminated. If a STOP RUN
statement appears in a sequence of imperative statements, it must be the last or
the only statement in the sequence. All files should be closed before a STOP RUN
statement is processed. If you do not close the files, they are closed by compiler
generated code. An implicit STOP RUN is always generated after the last statement
in the source program.
Note: The STOP literal statement is useful for special situations when operator
intervention is needed during program processing.
Compiler-Directing Statements
Compiler-directing statements provide instructions to the COBOL compiler. The
compiler-directing statements are COPY, ENTER, and USE.
ENTER Statement
The COBOL/38 compiler does not allow modules written in another source language
to be incorporated into COBOL programs. Therefore, the ENTER statement is not
required or used by the COBOL/38 compiler, but is only treated as a comment. See
the “CALL Statement” on page 510 for details about incorporating other object pro-
grams in COBOL programs.
Format
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ ENTER language-name [ routine-name ] . @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
TABLE HANDLING
Tables are often used in data processing. A table is a set of logically consecutive
items, each of which has the same data description as the other items in the set.
The items in a table can be described as separate contiguous items. However, this
approach may not be satisfactory for two reasons. From a documentation stand-
point, the homogeneity of the data items is not apparent; secondly, repetitive coding
to reference unique data-names becomes a severe problem. Thus, a method of
data reference is used which makes it possible to refer to all or to part of one table
as an entity.
The occurrence number is known as a subscript and the technique of supplying the
occurrence number of individual table elements is called subscripting. A related
technique, called indexing, is also available for table references. Both subscripting
and indexing are described in subsequent sections.
Table Definition
System/38-Compatible COBOL allows tables in one, two or three dimensions.
To define a one-dimensional table, the user writes an OCCURS clause as part of the
definition of a table element. However, the OCCURS clause must not appear in a
data description entry that has a 01, 66, 77, or 88 level-number. For example:
1 TABLE-ONE.
5 ELEMENT-ONE OCCURS 3 TIMES.
1 ELEMENT-A PIC X(4).
1 ELEMENT-B PIC 9(4).
TABLE-ONE is the group item that contains the table. ELEMENT-ONE is an element of
a one-dimensional table that occurs three times. ELEMENT-A and ELEMENT-B are ele-
mentary items subordinate to ELEMENT-ONE.
TABLE-TWO is the group item that contains the table. ELEMENT-ONE is an element of
a one-dimensional table that occurs three times. ELEMENT-TWO is an element of a
two-dimensional table that occurs three times within each occurrence of
ELEMENT-ONE. ELEMENT-A and ELEMENT-B are elementary items subordinate to
ELEMENT-TWO.
TABLE-THREE is the group item that contains the table. ELEMENT-ONE is an element
of a one-dimensional table that occurs three times. ELEMENT-TWO is an element of a
two-dimensional table that occurs three times within each occurrence of
ELEMENT-ONE. ELEMENT-THREE is an element of a three-dimensional table that
occurs two times within each occurrence of ELEMENT-TWO. Figure 91 on page 471
shows the storage layout for TABLE-THREE.
Table References
Whenever the user refers to a table element, or to any item associated with a table
element, the reference must indicate which occurrence is intended.
For a one-dimensional table, the occurrence number of the desired element gives
the complete information. For tables of more than one dimension, an occurrence
number for each dimension must be supplied. In the three-dimensional table
defined in the previous discussion, for example, a reference to ELEMENT-THREE must
supply the occurrence number for ELEMENT-ONE, ELEMENT-TWO, and ELEMENT-THREE.
Either subscripting or indexing, described in the following paragraphs, can be used
to supply the necessary references.
Subscripting
Subscripting is a method of providing table references through the use of sub-
scripts. A subscript is an integer value that specifies the occurrence number of a
table element. Subscripts can be used only when reference is made to an indi-
vidual item within a table element.
Format
┌ ┐ ┌ ┐
{ data-name-1 } │ { OF } data-name-2 │ . . . ( subscript-1 │ , subscript-2 [ , subscript-3 ] │ )
{ condition-name } │ { IN } │ └ ┘
└ ┘
Data-name-1 must be the name of a table element. (Note that when qualification is
used, it is data-name-1 that is subscripted, not data-name-2.)
A literal subscript must be an integer, and it must have a value of one or greater.
The literal can have a positive sign or it may be unsigned. Negative subscript
values are not permitted. For example, the following are valid literal subscript refer-
ences to TABLE-THREE:
ELEMENT-THREE (1, 2, 1)
The set of one to three subscripts must be written within a balanced pair of paren-
theses immediately following data-name-1 or its last qualifier. One or more spaces
can optionally precede the opening parenthesis.
When more than one subscript is specified, each subscript must be separated from
the next by either a space or a comma and a space.
When more than one subscript is required, the subscripts are written in the order of
successively less inclusive data dimensions. For example, in the table reference
ELEMENT-THREE (3, 2, 1), the first value (3) refers to the occurrence within
ELEMENT-ONE, the second value (2) refers to the occurrence within ELEMENT-TWO, and
the third value (1) refers to the occurrence within ELEMENT-THREE.
The lowest possible subscript value is 1; this value points to the first occurrence
within the table element. The next sequential elements are pointed to by subscripts
with values 2, 3, and so on. The highest permissible subscript value in any partic-
ular table element is the maximum number of occurrences specified in the OCCURS
clause. For example, in TABLE-THREE the highest possible subscript value for
ELEMENT-ONE is 3, for ELEMENT-TWO is 3, and for ELEMENT-THREE is 2.
If the RANGE option is specified or implied (see “PROCESS Statement” on page 46),
the system ensures 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 applies to subscripts only. The RANGE option does not verify that
indexes are valid.
.. 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7
DATA DIVISION.
WORKING-STORAGE SECTION.
1 SUB1 PIC 99.
1 SUB2 PIC 99.
1 SUB3 PIC 99.
1 TEST-IT PIC 99 VALUE .
1 TOTAL-RECS PIC 99 VALUE ZEROS.
1 COMPANY-TABLE.
5 DIVISION-IN OCCURS 1 TIMES.
1 DIVISION-NAME PIC X(1).
1 DIVISION-NUMBER PIC 9(4).
1 SECTION-IN OCCURS 5 TIMES.
15 UNIT-IN OCCURS 5 TIMES.
2 UNIT-NAME PIC X(5).
2 UNIT-NUMBER PIC 9(4).
PROCEDURE DIVISION.
1-START-PROCESSING.
PERFORM ZERO-OUT-BIG-TABLE
VARYING SUB1 FROM 1 BY 1 UNTIL SUB1 > 1
@ SUB1 IS VARIED LAST
AFTER SUB2 FROM 1 BY 1 UNTIL SUB2 > 5
@ SUB2 IS VARIED SECOND
AFTER SUB3 FROM 1 BY 1 UNTIL SUB3 > 5.
@ SUB3 IS VARIED FIRST
PERFORM ADDRESS-THE-VARIABLES THRU ATV-EXIT.
DISPLAY "VARIABLE TEST-IT = " TEST-IT.
STOP-RUN.
ZERO-OUT-BIG-TABLE.
MOVE ZEROS TO UNIT-IN (SUB1 SUB2 SUB3).
ADDRESS-THE-VARIABLES.
IF UNIT-NUMBER OF UNIT-IN OF SECTION-IN OF DIVISION-IN
OF COMPANY-TABLE (3 4 5) =
ADD 1 TO TEST-IT.
ATV-EXIT.
EXIT.
Indexing
Indexing is the method of providing table references through the use of indexes.
An index is a compiler-generated storage area used to store table element occur-
rence numbers. For System/38-Compatible COBOL, the index contains a value that
is an offset into the table.
Format
┌ ┐
{ data-name-1 } │ { OF } data-name-2 │ . . . ( { index-name-1 [ { } literal-2 ] }
{ condition-name } │ { IN } │ { literal-1 }
└ ┘
┌ ┌ ┐ ┐
│ , { index-name-2 [ { } literal-4 ] } │ { index-name-3 [ { } literal-6 ] } │ │ )
│ { literal-3 } │ , { literal-5 } │ │
└ └ ┘ ┘
Data-name-1 must be the name of a table element. (Note that when qualification is
used, it is data-name-1 that is indexed rather than data-name-2.)
The RANGE option (see “Create COBOL Program Command” on page 37) does not
cause the system to verify that index values are valid. It is your responsibility to
ensure valid index values.
One or more index references (direct or relative) can be specified together with
literal subscripts.
Table Initialization
A table can contain static values or dynamic values. Static values remain the same
through every run of the object program. When this is true, the initial values of table
elements can be specified in Working-Storage in one of two ways:
The table can be described as a record containing contiguous subordinate data
description entries, each of which contains a VALUE clause for the initial value.
The record is then redescribed through a REDEFINES entry that contains a sub-
ordinate entry with an OCCURS clause. Because of the OCCURS clause, the subor-
dinate entries of the redefined entry are repeated. For example:
1 TABLE-ONE.
5 ELEMENT-ONE PICTURE X VALUE "1".
5 ELEMENT-TWO PICTURE X VALUE "2".
5 ELEMENT-THREE PICTURE X VALUE "3".
5 ELEMENT-FOUR PICTURE X VALUE "4".
1 TABLE-TWO REDEFINES TABLE-ONE.
5 OCCURS-ELEMENT OCCURS 4 TIMES
PICTURE X.
If the subordinate entries do not require separate handling, the VALUE of the
entire entry can be given in the entry that names the table. The lower level
entries then contain OCCURS clauses, and show the hierarchical structure of the
table. The subordinate entries must not contain VALUE clauses. For example:
1 TABLE-ONE VALUE "1234".
5 TABLE-TWO OCCURS 4 TIMES
PICTURE X.
Dynamic values may change during one run of the object program, or from one run
to another. If the dynamic values are always the same at the beginning of object
program run, they can be initialized in the same manner as static values. If the
initial values change from one run to the next, then the table can be defined without
initial values, and the changed values can be placed in the table before any table
reference is made.
Tables can be initialized to a common value by a MOVE to the group item that
defines the entire table. For example:
MOVE SPACES TO TABLE-ONE.
However, care should be exercised when this method is used with a table con-
taining non-display type elements. For example:
1 BINARY-TABLE.
5 BINARY-COUNT OCCURS 4 TIMES
PIC 9999 COMP-4.
.
.
.
MOVE ZEROS TO BINARY-TABLE.
The MOVE statement does not fill BINARY-TABLE with binary zeros, but with display-
type zeros, hex “FO”.
The following example shows two ways of initializing a table with zeros:
. 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7
DATA DIVISION.
WORKING-STORAGE SECTION.
1 SUB1 PIC 999.
1 TABLE-OF-ELEMENTS.
3 ELEMENTS-OF-TABLE PIC 9 OCCURS 1 TIMES.
PROCEDURE DIVISION.
1-START-PROCESSING.
PERFORM SAMPLE-PERFORM THRU PERFORM-EXIT
VARYING SUB1 FROM 1 BY 1 UNTIL SUB1 GREATER THAN 1.
PERFORM ANOTHER-WAY-TO-INITIALIZE THRU AWTI-EXIT.
@ THE TABLE WILL BE ALL ZEROS AND SHOULD PRINT AS SUCH.
DISPLAY "THE TABLE " TABLE-OF-ELEMENTS.
STOP-RUN.
┌─ SAMPLE-PERFORM.
┌─┤ MOVE ZEROS TO ELEMENTS-OF-TABLE (SUB1).
Initializing │ │ PERFORM-EXIT.
Table to ─┤ └─ EXIT.
Zeros │ ┌─ ANOTHER-WAY-TO-INITIALIZE.
└─┤ MOVE ZEROS TO TABLE-OF-ELEMENTS.
│ AWTI-EXIT.
└─ EXIT.
OCCURS Clause
The OCCURS clause eliminates the need to specify separate entries for repeated data
items; it also supplies the information necessary for the use of subscripts or
indexes. The formats of the OCCURS clause are as follows:
DEPENDING ON data-name-1
┌ ┐
│ { ASCENDING } KEY IS data-name-2 [ data-name-3 ] . . . │ . . .
│ { DESCENDING } │
└ ┘
┌ ┐
│ INDEXED BY index-name-1 [ index-name-2 ] ... │
└ ┘
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.
Whenever the subject is used in any statement–other than SEARCH or USE FOR
DEBUGGING, or unless it is the object of a REDEFINES clause–the subject must be sub-
scripted or indexed. When it is subscripted or indexed, the subject refers to one
occurrence within the table element.
Whenever the subject is used in a SEARCH or USE FOR DEBUGGING statement, or when
it is the object of a REDEFINES clause, the subject must not be subscripted or
indexed. When it is not subscripted or indexed, the subject represents the entire
table length.
The table must contain less than 32 768 occurrences, the length of a table element
must be less than 32 K bytes, and the length of the whole table must be less than
32 K bytes.
All data-names used in the OCCURS clause can be qualified; they cannot be sub-
scripted or indexed.
Because three subscripts or indexes are allowed, three nested levels of the Format
1 OCCURS clause are allowed.
Data-name-1 is the object of the OCCURS DEPENDING ON clause. The object is the
data item whose current value represents the current number of occurrences of the
subject item. The object of the OCCURS DEPENDING ON clause:
Must be described as a positive integer. That is, if data-name-1 is described as
a signed item, at run time it must contain positive data.
Must not occupy any storage position within the range of this table. That is, the
object must not occupy any storage position from the first character position in
this table through the last character position in this record description entry.
Must contain a value within the range of integer-1 and integer-2, inclusive.
The value of the object of the OCCURS DEPENDING ON clause specifies that part of the
table element available to the object program. Items whose occurrence numbers
exceed the value of the object are not available. If, during processing, the value of
the object is reduced, the contents of items whose occurrence numbers exceed the
new value of the object are unpredictable.
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 cannot be specified as subordinate to another OCCURS clause. However, the
Format 1 OCCURS clause may be specified as subordinate to the OCCURS DEPENDING
ON clause; in this case, a table of up to three dimensions may be specified.
The order is determined by the rules for comparison of operands. (See “Simple
Conditions” on page 354, “Relation Condition” on page 356.)
Data-name-2 must be the name of the subject entry or the name of an entry subor-
dinate to the subject entry. If data-name-2 names the subject entry, that entire entry
becomes the ASCENDING/DESCENDING KEY and is the only key that can be specified
for this table element. If data-name-2 does not name the subject entry, then
data-name-2, data-name-3, and so on:
Must be subordinate to the subject of the table entry itself
Must not be subordinate to any other entry that contains an OCCURS clause
Must not themselves contain an OCCURS clause.
The keys for EMPLOYEE-TABLE are subordinate to that entry, and the key for
WEEK-RECORD is subordinate to that subordinate entry.
When the ASCENDING/DESCENDING KEY phrase is specified, the following rules apply:
Keys must be listed in decreasing order of significance.
A key can have USAGE DISPLAY or COMPUTATIONAL.
IBM Extension
The user is responsible for ensuring that the data present in the table is
arranged in ascending or descending key sequence according to the collating
sequence in use.
INDEXED BY Phrase
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 state-
Format
[ USAGE IS ] INDEX
An index data item is a two-byte elementary item that can be used to save index-
name values for future reference. Through the SET statement, an index data item
can be assigned an index-name value. The index-name value corresponds to the
displacement for an occurrence number in the table, that is (occurrence-number -
1) * entry length.
An index data item can be referred to directly only in a SEARCH statement, a SET
statement, a relation condition, the USING phrase of the Procedure Division header,
or the USING phrase of the CALL statement. An index data item can be part of a
group item referred to in a MOVE statement or an input/output statement.
An index data item saves binary values that represent a table occurrence number;
however, it is not itself necessarily defined as part of any table. Thus, when it is
referenced directly in a SEARCH or SET statement, or indirectly in a MOVE or
input/output statement, there is no conversion of values when the statement is
processed.
The USAGE IS INDEX clause may be written at any level. If a group item is described
with the USAGE IS INDEX clause, it is the elementary items within the group that are
index data items; the group itself is not an index data item, and the group name
cannot be used in SEARCH and SET statements or in relation conditions. The USAGE
clause of an elementary item cannot contradict the USAGE clause of a group to
which the item belongs.
The SYNCHRONIZED, JUSTIFIED, PICTURE, BLANK WHEN ZERO, or VALUE clauses cannot
be used to describe group or elementary items described with the USAGE IS INDEX
clause.
Since the format of an index data item is implementation dependent, an index data
item should not be defined in the File Section.
Relation Conditions
Comparisons involving index-names and/or index data items conform to the fol-
lowing 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.
Figure 92 shows permissible comparisons for index-names and index data items.
┌──────────────────┬─────────────────────────────────────────────────────────────────────────────┐
│ │ SECOND OPERAND │
│ ├─────────────────┬──────────────────┬─────────────────────┬──────────────────┤
│ │ │ Index Date │ Data-Name (numeric │ Numeric Literal │
│ First Operand │ Index-name │ Item │ integer only) │ (integer only) │
├──────────────────┼─────────────────┼──────────────────┼─────────────────────┼──────────────────┤
│ Index-Name │ Compare │ Compare │ Compare │ Compare │
│ │ occurrence │ without │ occurrence │ occurrence │
│ │ numbers │ conversion │ number with │ number with │
│ │ │ │ data-name │ literal │
├──────────────────┼─────────────────┼──────────────────┼─────────────────────┼──────────────────┤
│ Index Data │ Compare │ Compare │ Invalid │ Invalid │
│ Item │ without │ without │ │ │
│ │ conversion │ conversion │ │ │
├──────────────────┼─────────────────┼──────────────────┼─────────────────────┼──────────────────┤
│ Data-Name │ Compare │ Invalid │ Invalid │ Invalid │
│ (numeric │ occurrence │ │ │ │
│ integer only) │ number with │ │ │ │
│ │ data-name │ │ │ │
├──────────────────┼─────────────────┼──────────────────┼─────────────────────┼──────────────────┤
│ Numeric │ Compare │ Invalid │ Invalid │ Invalid │
│ Literal │ occurrence │ │ │ │
│ (integer only) │ number with │ │ │ │
│ │ literal │ │ │ │
└──────────────────┴─────────────────┴──────────────────┴─────────────────────┴──────────────────┘
Figure 92. Permissible Comparisons for Index-Names and Index Data Items
SEARCH Statement
The SEARCH statement searches a table for an element that satisfies the specified
condition, and adjusts the associated index to indicate that element. The formats
for the SEARCH statement are:
Format 1
┌ ┐
SEARCH identifier-1 │ VARYING { identifier-2 } │ [ AT END imperative-statement-1 ]
│ { index-name-1 } │
└ ┘
┌ ┐
│ WHEN condition-2 { imperative-statement-3 } │ . . .
│ { NEXT SENTENCE } │
└ ┘
Format 2
SEARCH ALL indentifier-1 [ AT END imperative-statement-1 ]
┌ ┐
│ { data-name-2 { IS EQUAL TO } { identifier-4 } } │
│ { { IS = } { literal-2 } } │
│ AND { { arithmetic-expression-2 } } │ . . .
│ { } │
│ { condition-name-2 } │
└ ┘
{ imperative-statement-2 }
{ NEXT SENTENCE }
The Data Division description of identifier-1 must contain an OCCURS clause with
the INDEXED BY phrase.
When specified in the SEARCH statement, identifier-1 must refer to all occurrences
within the table element; it must not be subscripted or indexed.
SEARCH statement processing modifies only the value in the index-name associated
with identifier-1 (and, if present, of index-name-1 or identifier-2). Therefore, to
search an entire two- or three-dimensional table, a SEARCH statement must be proc-
essed for each dimension. Before each processing, SET statements must be proc-
essed to reinitialize the associated index-names.
In the AT END and WHEN phrases, control passes to the next sentence after the
imperative-statement is processed if any of the specified imperative-statements do
not end with a GO TO statement.
Format 1
Format 1 SEARCH statement processing causes a serial search, beginning at the
current index setting.
If the value of the index-name associated with identifier-1 is not greater than the
highest possible occurrence number, when the search begins the following actions
take place:
1. The conditions in the WHEN phrases are evaluated in the order they are written.
2. If none of the conditions are satisfied, the index-name for identifier-1 is incre-
mented to correspond to the next table element, and step 1 is repeated.
3. If upon evaluation, one of the WHEN conditions is satisfied, the search terminates
immediately, and the imperative-statement associated with that condition is
processed. The index-name identifies the table element that satisfied the condi-
tion.
4. 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 begin satisfied, the search terminates as described in the next paragraph.
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 processed.
If the AT END phrase is omitted, control passes to the next sentence.
Each WHEN phrase condition can be any condition as described under in “Condi-
tional Expressions” on page 354.
VARYING Identifier-2 Phrase: When this phrase is specified, the first (or only)
index-name for identifier-1 is used for the search.
Format 2
Format 2 SEARCH ALL statement processing causes a binary search to be made.
The search index need not be initialized by SET statements, because its setting is
varied during the search operation. The index used is always the index that is asso-
ciated with the first index-name specified in the OCCURS clause.
If the WHEN phrase cannot be satisfied for any setting of the index within this range,
the search is unsuccessful. If the AT END phrase is specified, the AT END
imperative-statement is processed. If the AT END phrase is not specified, control is
passed to the next sentence. In either case, the final setting of the index is not
predictable.
The results of a SEARCH ALL operation are predictable only when both of the fol-
lowing apply:
The data in the table is ordered in ascending or descending key sequence.
The contents of the ASCENDING/DESCENDING keys specified in the WHEN phrase
provide a unique table reference.
Exec ution of
SEAR CH Begins
GT AT E N D * * * * *
* Imperative
Statement-1
LT o r =
Tru e W H E N C o n d itio n -1 * * *
Im perative
C o n d it io n -1
S tatem ent-2
False
* * Tru e W H E N C o n d itio n -2 * * * * *
Im perative
C o n d itio n - 2 S tatem ent-3
False
* *
Increm ent Index-
N a m e -1 (fo r
another table)
o r Id e n tifie r-2
* I n d e x s e t t i n g e q u a l s h i g h e s t p e r m i s s i b l e o c c u r r e n c e n u m b e r.
* * These operations are included only when called for in the statement.
Programming Notes
Index data items cannot be used as subscripts or indexes, 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 refer-
ence to two different occurrences of a table element for comparison purposes.
When the object of the VARYING phrase is an index-name for another table element,
one Format 1 SEARCH statement looks at two table elements at once.
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.
.. 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.
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.
@@@@@@@@@END OF MAIN PROGRAM@@@@@@@@
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.
@@@@@@@@@END OF EXAMPLE SEARCH PROGRAM@@@@@@@@
SET Statement
The SET statement establishes reference points for table handling operations by
setting index-names to values associated with table elements. The SET statement
may be used to transfer values between index-names and other elementary data
items. The formats of the SET statement when it is used for table handling are
described here. For information on the other formats allowed for SET statements,
see “SET Statement” on page 440.
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 processing of such a SET
statement is undefined.
Format 3
Format 3
SET { identifier-1 [ , identifier-2 ] . . . } TO { identifier-3 }
{ index-name-1 [ , index-name-2 ] . . . } { index-name-3 }
{ integer-1 }
When this form of the SET statement is processed, the value of the sending field
replaces (with or without conversion) the current value of the receiving field.
Figure 94 on page 490 shows valid combinations of sending and receiving fields in
a Format 3 SET statement.
Processing of the Format 3 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.
Receiving fields are acted upon in the left-to-right order they are specified. Any
subscripting or indexing associated with an identifier receiving field is evaluated
immediately before the field is acted upon.
The value used for the sending field is its value at the beginning of SET statement
processing.
Format 4
Format 4
SET index-name-4 [ , index-name-5 ] . . . { UP BY } { identifier-4 }
{ DOWN BY } { integer-2 }
When this form of the SET statement is processed, the value of the receiving field is
incremented (UP BY) or decremented (DOWN BY) by the value in the sending field.
When the Format 4 SET statement is processed, the contents of the receiving field
are incremented (UP BY) or decremented (DOWN BY) by the value of identifier-4 or
integer-2. Receiving fields are acted upon in the left-to-right order they are speci-
fied. The value of the sending field at the beginning of SET statement processing is
used for all receiving fields.
┌───────────────────┬────────────────────────────────────────────────────────┐
│ │ RECEIVING FIELD │
│ ├────────────────┬──────────────────┬────────────────────┤
│ SENDING FIELD │ Index-name │ Index Data Item │ Integer Data Item │
├───────────────────┼────────────────┼──────────────────┼────────────────────┤
│ Index-Name │ Valid │ Valid@ │ Valid │
├───────────────────┼────────────────┼──────────────────┼────────────────────│
│ Index data item │ Valid@ │ Valid │ │
├───────────────────┼────────────────┼──────────────────┼────────────────────│
│ Integer data item │ Valid │ │ │
├───────────────────┼────────────────┼──────────────────┼────────────────────│
│ Integer literal │ Valid │ │ │
├───────────────────┴────────────────┴──────────────────┴────────────────────┤
│ @ No conversion takes place. │
└────────────────────────────────────────────────────────────────────────────┘
Figure 94. Sending and Receiving Fields for Format 3 SET Statements
SORT/MERGE
Arranging records in a particular order or sequence is a common requirement in
data processing; such record ordering can be accomplished using sort or merge
operations. While both operations accomplish record ordering, the functions and
capabilities of a sort and a merge are different.
A sort produces an ordered file from one or more input files that can be completely
unordered as to sort sequence. Thus, the sort operation must accept unordered
input and produce ordered output.
A merge produces an ordered file from two or more input files, each of which is
already ordered in the merge sequence.
IBM Extension
COBOL has special language features that assist in sort and merge operations so
that the user need not program these operations in detail.
Sort/Merge Concepts
Sorting and merging have always constituted a large percentage of the workload in
business data processing. COBOL standardizes the specification of these oper-
ations, making them easy to specify and modify. In addition, the COBOL user can
alternatively use the AS/400 logical file support to process these operations as sep-
arate command language (CL) commands. The COBOL language supports these
operations through the file-control entry in the Environment Division, the SD (sort-
merge-file-description) entry in the Data Division, and the SORT and MERGE state-
ments in the Procedure Division.
The sort or merge file is described through the file-control entry in the Environment
Division, and the SD entry in the Data Division. The sort or merge file is the
working file used during the sort or merge; it can be considered an internal file. As
such, blocking and internal storage allocation for this file are not under the control
of the COBOL user. However, a sort or merge file, like any file, is a set of records,
and a sort-merge file description can be considered a particular type of file
description.
The sort-merge file is processed through a Procedure Division SORT or MERGE state-
ment. The statement specifies the key field(s) within the record upon which the
sort or merge is to be arranged. Keys can be specified as ascending or
descending. When more than one key is specified, a mixture of the two sequences
is allowed. The sequence of sorted or merged records conforms to the mixture of
keys specified.
Sort Concepts
Through the SORT statement, the COBOL user has access to input procedures (used
before sorting) and output procedures (used after sorting) that can add, delete,
alter, edit, or otherwise modify the records in the input and/or output files. A
COBOL program can contain any number of sorts, each with its own independent
input and/or output procedures. During SORT statement processing, these proce-
dures are automatically run at the specified point in processing; thus, extra passes
through the sort file are avoided.
A COBOL program containing a sort is usually organized so that one or more input
files are read and operated on by an input procedure. Within the input procedure a
RELEASE statement (analogous to the WRITE statement) places a record in the sort
file. That is, when input procedure processing is completed, a sort file has been
created by placing records one at a time into the sort file through the RELEASE state-
ment. If the user does not wish to modify the records before the sorting operation
begins, the SORT statement USING phrase releases the unmodified records to the
sort file.
After all the input records have been placed in the sort file, the sorting operation is
run. This operation arranges the entire set of sort file records in the sequence
specified by the key(s).
After completion of the sorting operation, sorted records can be made available
from the sort file, one at a time, through a RETURN statement for modification in an
output procedure. If the user does not wish to modify the sorted records, the SORT
statement GIVING option names the sorted output file.
Merge Concepts
Through the MERGE statement, the COBOL user has access to output procedures
(used after merging) that can modify the records in the output file. The COBOL
program can contain any number of merge operations, each with its own inde-
pendent output procedures. During MERGE statement processing, these procedures
are automatically run at the specified point in processing.
The merge operation compares keys within the records of the input files and
arranges the records within the merged file in the sequence specified by the key(s).
Merged records can then be made available, one at a time, through a RETURN state-
ment for modification in an output procedure. If the user does not wish to modify
the merged records, the MERGE statement GIVING phrase names the merged output
file.
Environment Division–SORT/MERGE
In the Environment Division, the user must write file-control entries for each file
used as input to or output from a sort or merge operation. The user must also write
a file-control entry for each unique sort-file or merge-file.
File-Control Paragraph
See “FILE-CONTROL Paragraph” on page 281 for a description of input and output
files of a sort or merge operation.
I-O-Control Paragraph
In the I-O-Control paragraph, the SAME SORT AREA or SAME SORT-MERGE AREA clause
is used.
Format
┌ ┌ ┐ ┐
│ │ RECORD │ │
│ SAME │ SORT │ AREA FOR file-name-2 { , file-name-3 } . . . │ . . .
│ │ SORT-MERGE │ │
└ └ ┘ ┘
The SAME SORT AREA and SAME SORT-MERGE AREA clauses are syntax-checked, but
are treated as documentation.
Restrictions on the specification of SAME RECORD AREA clause are given under
“I-O-CONTROL Paragraph” on page 292.
Data Division–SORT/MERGE
In the File Section, the user must write an FD entry for each file that is input to or
output from the sort/merge operation, as well as a record description entry. In addi-
tion, there must be an SD (sort-merge-file-description) entry for each sort or merge
file.
The level indicator SD identifies the beginning of the SD entry, and must precede the
file-name. The file-name must specify a sort or merge file.
The clauses that follow file-name are optional, and their order of appearance is not
significant. Both the RECORD CONTAINS clause and the DATA RECORDS clause are
described in Chapter 9, “Data Division”
One or more record description entries must follow the SD entry. However, no
input/output statements may be processed for this file.
The following example illustrates the File Section entries needed for a sort or
merge file:
SD SORT-FILE.
1 SORT-RECORD PICTURE X(8).
Procedure Division–SORT/MERGE
The Procedure Division contains MERGE and SORT statements to describe the merge
and sort operations and, optionally, sort input procedures and/or sort/merge output
procedures. A sort input procedure must contain a RELEASE statement that makes
each record available to the sorting operation. A sort/merge output procedure must
contain a RETURN statement that makes a sorted/merged record available to the
output procedure.
The Procedure Division can contain more than one SORT and/or MERGE statement.
These statements can appear anywhere except in the Declaratives portion or in the
sort input or sort/merge output procedures.
Files specified in the USING and GIVING phrases of the SORT and MERGE statements
must be described explicitly or implicitly in their file-control entries as having
sequential organization.
USE procedures are not run if they reference files specified on a USING or GIVING
phrase of a SORT or MERGE statement. If these files are also referenced in an I-O
statement within an output procedure or a SORT input procedure, a USE procedure
for the file specified is called when necessary.
MERGE Statement
The MERGE statement combines two or more identically sequenced files that have
already been sorted in an identical ascending/descending key sequence on one or
more keys. This statement makes records available in merged order to an output
procedure or output file.
Format
MERGE file-name-1 ON { ASCENDING } KEY data-name-1 [ , data-name-2 ] . . .
{ DESCENDING }
┌ ┐
│ ON { ASCENDING } KEY data-name-3 [ , data-name-4 ] . . . │ . . .
│ { DESCENDING } │
└ ┘
{ ┌ ┐ }
{ OUTPUT PROCEDURE IS section-name-1 │ { THROUGH } section-name-2 │ }
{ │ { THRU } │ }
{ └ ┘ }
{ GIVING file-name-5 }
File-name-1 is the name given in the SD entry that describes the records being
merged. No file-name may be repeated in the MERGE statement.
See “MERGE Statement and SORT Statement Phrases” for details about the
phrases of the MERGE statement.
SORT Statement
The SORT statement accepts records from one or more files, sorts them according to
the specified key(s), and makes records available either through an output proce-
dure or in an output file.
Format
SORT file-name-1 ON { ASCENDING } KEY data-name-1 [ , data-name-2 ] . . .
{ DESCENDING }
┌ ┐
│ ON { ASCENDING } KEY data-name-3 [ , data-name-4 ] . . . │ . . .
│ { DESCENDING } │
└ ┘
{ ┌ ┐ }
{ INPUT PROCEDURE IS section-name-1 │ { THROUGH } section-name-2 │ }
{ │ { THRU } │ }
{ └ ┘ }
{ }
{ USING file-name-2 [ , file-name-3 ] . . . }
{ ┌ ┐ }
{ OUTPUT PROCEDURE IS section-name-3 │ { THROUGH } section-name-4 │ }
{ │ { THRU } │ }
{ └ ┘ }
{ GIVING file-name-4 }
File-name-1 is the name given in the SD entry that describes the records being
sorted.
Each data-name specifies a KEY data item on which the sort-merge will be based.
Each such data-name must identify a data item in a record associated with
file-name-1. 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, then 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.
The total length (in bytes) of the KEY data items must not exceed 248.
KEY data items can be qualified; they cannot be subscripted or indexed.
The KEY data items are listed in order of decreasing significance, regardless of how
they are divided into KEY phrases. Using the SORT format as an example,
data-name-1 is the most significant key and records are processed in ascending or
descending order on that key; data-name-2 is the next most significant key and
within data-name-1 records are processed on data-name-2 in ascending or
descending order. Within data-name-2, records are processed on data-name-3 in
ascending or descending order; within data-name-3, records are processed on
data-name-4 in ascending or descending key sequence.
When STANDARD-1 is specified, the ASCII collating sequence is used for all non-
numeric 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 nonnumeric
comparisons.
When the COLLATING SEQUENCE phrase is omitted, the PROGRAM COLLATING 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 input files are transferred automatically to
file-name-1. At the time the SORT or MERGE statement is processed, these files
must not be open; the COBOL compiler opens, reads, makes records available, and
closes these files automatically.
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
sort or merge file. If the elementary items that make up these records are not
identical, the user must describe the input records as having the same number of
character positions as the sort record.
GIVING Phrase
When the GIVING phrase is specified, all the sorted or merged records in
file-name-1 are automatically transferred to the output file (MERGE file-name-5 or
SORT file-name-4). At the time the SORT or MERGE statement is processed, this file
must not be open; the COBOL compiler opens, writes, and closes the output file
automatically. The records overwrite the previous contents, if any, of the file.
IBM Extension
If file-name-1 is a logical data base file, the records are added to the end of the
file.
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 sort or merge file. If the elementary items that make up these records are not
identical, the user must describe the output record as having the same number of
character positions as the sort or merge record.
Section-name-1 specifies the first (or only) section in the input procedure.
Section-name-2 (when specified) identifies the last section of the input procedure.
The input procedure must consist of one or more sections that are written consec-
utively and do not form a part of any output procedure. The input procedure must
include at least one RELEASE statement in order to transfer records to the sort-file.
Control must not be passed to the input procedure except when a related SORT
statement is being processed because the RELEASE statement in the input proce-
dure has no meaning unless it is controlled by a SORT statement. The input proce-
dure can include any procedures needed to select, create, or modify records. The
following restrictions apply to the procedural statements within an input procedure:
The input procedure must not contain any SORT or MERGE statements.
The input procedure must not contain any transfers of control to points outside
the input procedure. The processing of a CALL statement to another program,
or the processing of USE Declaratives is not considered a transfer of control
outside an input procedure. Hence, they are allowed to be activated within
these procedures.
IBM Extension
If control transfers via a PERFORM statement to a point outside the input proce-
dure, a conditional level message is issued but compilation continues.
The remainder of the Procedure Division must not contain any transfers of
control to points inside the input procedure with the exception of the return of
control from a Declaratives Section.
IBM Extension
If control transfers via a PERFORM statement to a point inside the input procedure
from elsewhere in the Procedure Division, a conditional level message is issued
but the compilation continues.
If an input procedure is specified, control is passed to the input procedure when the
SORT program input phase is ready to receive the first record. The compiler inserts
a return mechanism at the end of the last section of the input procedure and when
control passes the last statement in the input procedure, the records that have
been released to file-name-1 are sorted. The RELEASE statement transfers records
from the Input Procedure to the sort file, which is then used in the input phase of
the sort operation.
Section-name-3 specifies the first (or only) section in the output procedure.
Section-name-4 (when specified) identifies the last section of the output procedure.
The output procedure must consist of one or more sections that are written consec-
utively and are not part of any input procedure. The output procedure must include
at least one RETURN statement in order to make sorted/merged records available for
processing.
When all the records are sorted/merged, control is passed to the output procedure.
The RETURN statement in the output procedure is a request for the next record.
Control must not be passed to the output procedure except when a related SORT or
MERGE statement is being processed because RETURN statements in the output pro-
cedure have no meaning unless they are controlled by a SORT or MERGE statement.
The output procedure can consist of any procedures needed to select, modify, or
copy the records that are being returned one at a time from the sort/merge file.
There are three restrictions on the procedural statements within the output
procedure:
The output procedure must not contain any SORT or MERGE statements.
The output procedure must not contain any transfers of control to points outside
the output procedure. The processing of a CALL statement to another program,
or the processing of USE Declaratives are not considered as transfers of control
outside an output procedure. Hence, they are allowed to be activated within
these procedures.
IBM Extension
If control transfers via a PERFORM statement to a point outside the output proce-
dure, a conditional level message is issued but compilation continues.
The remainder of the Procedure Division must not contain any transfers of
control to points inside the output procedure with the exception of the return of
control from a Declaratives Section.
IBM Extension
If control transfers via a PERFORM statement to a point inside the output proce-
dure from elsewhere in the Procedure Division, a conditional level message is
issued but the compilation continues.
When an output procedure is specified, control passes to it after the sort/merge file
(file-name-1) has been placed in sequence by the sort/merge operation. The
COBOL compiler inserts a return mechanism at the end of the last section in the
output procedure; when control is passed to the last statement in the output proce-
dure, the return mechanism terminates the sort or merge, and passes control to the
next executable statement after the SORT or MERGE statement.
The RELEASE statement can be specified only within an input procedure associated
with a SORT statement. Within an input procedure at least one RELEASE statement
must be specified.
When the RELEASE statement is processed, the current contents of record-name are
placed in the sort file; that is, made available to the initial phase of the sort opera-
tion.
Format
RELEASE record-name [ FROM identifier ]
Record-name must specify a record associated with the SD entry for file-name-1.
Record-name can be qualified.
When the FROM identifier phrase is specified, the RELEASE statement is equivalent
to the statement MOVE identifier to record-name followed by the statement
RELEASE record-name. Moving takes place according to the rules for the MOVE state-
ment without the CORRESPONDING phrase.
Identifier and record-name must not refer to the same storage area.
When control passes from the input procedure, the sort file consists of all those
records placed in it by processing of RELEASE statements.
RETURN Statement
The RETURN statement transfers records from the final phase of a sort or merge
operation to an input/output area. This statement is similar to the READ statement.
The RETURN statement can be specified only within an output procedure associated
with a SORT or MERGE statement. Within an output procedure at least one RETURN
statement must be specified.
Format
RETURN file-name RECORD [ INTO identifier ] AT END imperative-statement
When the RETURN statement is processed, the next record from file-name is made
available for processing by the output procedure.
If more than one record description is associated with file-name, these records
automatically share the same storage; that is, the area is implicitly redefined. After
RETURN statement processing, 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.
When the INTO identifier phrase is specified, the RETURN statement is equivalent
to the statement RETURN file-name followed by the statement MOVE record-name TO
identifier. Moving takes place according to the rules for the MOVE statement
without the CORRESPONDING phrase. Any subscripting or indexing associated with
identifier is evaluated after the record has been returned and immediately before it
is moved to identifier.
The record areas associated with file-name and identifier must not be the same
storage area.
After all records have been returned from file-name, the AT END imperative-
statement is processed, and no more RETURN statements can be processed.
Storage Pool Size: A minimum storage pool size of 200 K is recommended, and
300 K is recommended for the average storage pool size. Processing sort/merge
operations and other applications, especially interactive applications, in the same
storage pool increases response time and increases sort/merge run time.
Number of Records: Run time increases when the number of records included in
the sort increases. The sort/merge operation builds a work record for each input
record in the sort. For efficiency, pass only required records to the sort.
Record Size: Run time increases when the records are longer. To minimize run
time, do not include fields that contain unnecessary information.
Number of Key Fields: Run time increases when there are more sort/merge key
fields. As keys, character fields are more efficient than packed or binary signed
fields.
Number and Types of Files: Because the sort must move each record two times
(from the file to the work record area, and from the work file to the output file),
consider the characteristics of the file.
A logical file on the AS/400 system can be a subset of a physical file, a combina-
tion of physical files, and/or a restructuring of a group of fields from one or more
physical files. Because of the added flexibility, use of logical files as input to the
sort/merge operation can increase the run time of the sort/merge operation. If pos-
sible, use a physical file for input to the sort/merge.
Processing a file from a unit record device, such as a diskette, is much slower than
processing a file from the data base or from tape. If a file is heavily used during a
job or a series of jobs, run time can be improved by copying the file into the data
base.
SEGMENTATION FEATURE
It is not necessary to be concerned with storage management when writing
System/38-Compatible COBOL programs. Segmentation, however, is available for
compatibility with other systems.
Segmentation Concepts
Although it is not required, the Procedure Division of a source program is usually
written as a consecutive group of sections, each of which is made up of a series of
related operations that process a particular function. Thus, the entire Procedure
Division is made up of a number of logical subdivisions. Segmentation allows the
programmer to physically divide the Procedure Division into segments, each of
which has specific physical and logical attributes.
When Segmentation is used, the entire Procedure Division must be divided into
sections. Each section must then be classified as to its physical and logical attri-
butes. Classification is specified by means of segment-numbers. All sections given
the same segment-number make up one program segment.
Program Segments
There are three types of program segments: fixed permanent, fixed overlayable,
and independent.
Fixed Segments
Fixed permanent segments and fixed overlayable segments make up the fixed
portion, the part of the Procedure Division that is logically treated as if it were
always physically present in main storage. Fixed-portion segment-numbers must
be integers from 0 through 49.
Independent Segments
Logically, an independent segment can overlay and be overlaid by other segments
during program processing.
An independent segment is made available in its initial state the first time control is
passed to it (explicitly or implicitly) during program processing.
Segmentation Logic
In a segmented program, the sections are classified by a system of segment-
numbers according to the following criteria:
Frequency of Reference–Much used sections, or those that must be available
for reference at all times, should usually be within fixed permanent segments.
Less frequently used sections should usually be within either fixed overlayable
or independent segments, depending on the program logic.
Frequency of Use–The more frequently a section is referred to, the lower its
segment-number; the less frequently it is referred to, the higher its segment-
number.
Logical Relationships–Sections that frequently communicate with each other
should be given identical segment-numbers.
Segmentation Control
Except for specific transfers of control, the logical sequence and the physical
sequence of program instructions are the same. The compiler inserts any
instructions necessary to initialize a segment. It is not necessary to transfer control
to the beginning of a segment, or to the beginning of a section within a segment.
Instead, control can be transferred to any paragraph in the Procedure Division.
Segmentation–Environment Division
In the OBJECT-COMPUTER paragraph, the SEGMENT-LIMIT clause allows the user to
reclassify fixed permanent segments while retaining the properties of fixed portion
segments for the reclassified segments.
Format
[ , SEGMENT-LIMIT IS segment-number ] .
Segmentation–Procedure Division
In the Procedure Division of a segmented program, section classification is speci-
fied through segment-numbers in the section headers.
Format
section-name SECTION [ segment-number ] .
All sections with the same segment-number make up one program segment. Such
sections need not be contiguous in the source program.
Segmentation–Special Considerations
When segmentation is used, there are restrictions on the ALTER, PERFORM, SORT, and
MERGE statements.
There are also special considerations for calling and called programs.
ALTER Statement
A GO TO statement in an independent segment must not be referred to by an ALTER
statement in a different segment. All other uses of the ALTER statement are valid
and are processed, even if the GO TO statement referred to is in a fixed overlayable
segment.
PERFORM Statement
A PERFORM statement in the fixed portion can have in its range, in addition to any
Declarative procedures whose processing is caused within that range, only one of
the following:
Sections and/or paragraphs in the fixed portion
Sections and/or paragraphs contained within a single independent segment.
A PERFORM statement in an independent segment can have within its range, in addi-
tion to any Declarative procedures whose processing is caused within that range,
only one of the following:
Sections and/or paragraphs in the fixed portion
Sections and/or paragraphs wholly contained in the same independent segment
as the PERFORM statement.
Transfers of Control
In the Procedure Division, a calling program can transfer control to a called
program, and a called program can itself transfer control to yet another called
program. However, a called program must not directly or indirectly call its caller.
For example, if program A calls program B, program B calls program C, and
program C then calls program A, the results are unpredictable.
Common Data
Program interaction can require that both programs have access to the same data.
In a calling program, the common data items are described in the same manner as
other File and Working-Storage Section items. Storage is allocated for these items
in the calling program. In a called program, common data items are described in
the Linkage Section. Storage is not allocated to them in the called program.
Because a calling program can itself be a called program, common data items can
be described in the Linkage Section of the calling program. In this case, storage is
not allocated for these items in the calling program itself, but rather in the program
that called the calling program. For example, program A calls program B which
calls program C. Data items in program A can be described in the Linkage
Sections of programs B and C, and the one set of data can be made available to
all three programs.
When control is transferred from the calling to the called program, the programmer
must furnish a list of the common data items in both programs. The sequence of
identifiers in both lists determines the match of identifiers between the calling and
called programs. A corresponding pair of identifiers in the list names a single set of
data that is available to both programs. While the called program is run, any refer-
ence to one of these identifiers is a reference to the corresponding data of the
calling program.
In the Procedure Division, the list of common data items is established through the
USING phrase, which names those data items available to both programs. In the
called program, only those items named in the USING list of the called program are
available from the data storage of the calling program.
A CALL statement in the calling program transfers control to the first nondeclarative
procedural statement in the called program. When the called program has com-
pleted its run, control is returned to the calling program by an EXIT PROGRAM state-
ment. The entire run unit can be ended by a STOP RUN statement in either program.
Format
LINKAGE SECTION.
┌
│ { 77 } data-name/FILLER clause
│ { 1-49 }
└
[ REDEFINES clause ]
[ INDICATOR clause ]
[ JUSTIFIED clause ]
[ OCCURS clause ]
[ PICTURE clause ]
[ SIGN clause ]
[ SYNCHRONIZED clause ]
┐
[ USAGE clause ] . │ . . .
┘
[ 88 condition-name VALUE clause. ] . . .
[ 66 RENAMES clause. ] . . .
The Linkage Section has meaning only if this program functions under control of a
CALL statement that contains the USING phrase, or a call statement from another
language.
The Linkage Section describes data available within the calling program and
referred to in both the calling and called programs. Items described in the Linkage
Section do not have space allocated for them in the called program. Procedure
Division references to these data items are resolved at object time by equating the
reference in the called program to the location used in the calling program. For
index-names, no such correspondence is established. Index-name references in the
calling and called programs always refer to separate indexes. Index-name values
can be passed by first moving them to an index data item and passing that index
data item.
Items defined in the Linkage Section can be referred to in the Procedure Division
only if they are one of the following:
Operands of a USING phrase in this program
Data items subordinate to such a USING phrase operand
Items associated with such a USING operand (such as condition-names or
index-names).
Other data description clauses are optional and, when necessary, can complete the
description of the item. Except for level-88 condition-names, the VALUE clause must
not be specified.
Reference to common data is provided through the USING phrase, which can be
specified in the CALL statement and in the Procedure Division header of the called
program.
The EXIT PROGRAM statement allows termination of called program processing. The
STOP RUN statement allows termination of the run unit.
CALL Statement
The CALL statement transfers control from one object program to another within the
run unit. 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 program. Control returns to the calling program at the instruction
following the CALL statement.
Called programs themselves can contain CALL statements, but a called program
that contains a CALL statement that directly or indirectly calls the calling program
gives unpredictable results.
Format
┌ ┐
CALL { identifier-1 } │ USING data-name-1 [ . data-name-2 ] . . . │
{ literal-1 } │ │
└ ┘
[ ON OVERFLOW imperative-statement ]
Literal-1 must be nonnumeric and must conform to the rules for formation of a
program-name. The first ten characters of the literal are used to make the corre-
spondence between the calling program and the called program. The literal must
specify the program-name of the called program.
Identifier-1 must be an alphanumeric data item. Its contents must conform to the
rules for formation of a program-name (see “PROGRAM-ID Paragraph” on
page 268). The first ten characters of identifier-1 are used to make the corre-
spondence between the calling and called program.
CALL statement processing passes control to the called program which becomes
part of the run unit. If a CALL statement names a program that does not exist in the
job’s library list (@LIBL) at run-time, an error message is issued.
A called program is in its initial state the first time it is called within a run unit, and
the first time it is called after a CANCEL statement for the called program has been
processed.
On all other entries into the called program, it is in its last-used state, and the rein-
itialization of any items is the responsibility of the user. See Chapter 7,
“System/38-Compatible COBOL Programming Considerations” for more information
about calling programs.
The user return code is part of the job attributes. You can write a CL program con-
taining the RTVJOBA command to access the return code to control processing in
your application. The return code can also be displayed interactively by any of the
interfaces that display job attributes. See the CL Programmer's Guide for the list of
valid return codes and the CL Reference for information on the the RTVJOBA
command.
USING Phrase
The USING phrase makes data items in a calling program available to a called
program. COBOL supports the passing of arguments to other AS/400 programs.
The attributes of the data passed depends on the definition requirements of the
called program.
The following discussion of the USING phrase assumes that the calling and called
programs are written in COBOL.
Format
USING data-name-1 [ , data-name-2 ] . . .
In a calling program, the USING phrase is valid for the CALL statement; each USING
data-name must be defined as a level-01 or level-77 item anywhere in the Data
Division. The maximum number of data-names that can be specified is 30.
IBM Extension
In the USING phrase of the calling program CALL statement, the data-names can
have level-numbers other than 01 or 77. These data-names can be indexed or sub-
scripted, and can be qualified.
Formats for these individual items show the correct syntax for specifying the USING
phrase.
The USING phrase is specified if, and only if, the called program is to operate under
control of a CALL statement and that CALL statement itself contains a USING phrase.
That is, for each CALL USING statement in a calling program, there must be a corre-
sponding USING phrase specified in the called program.
The order of appearance of USING data-names in both calling and called programs
determines the correspondence of single sets of data available to both programs.
The correspondence is positional and not by name. Corresponding data-names
must contain the same number of characters, although their data descriptions need
not be the same. For index-names, no correspondence is established; index-
names in calling and called programs always refer to separate indexes.
The data-names specified in a CALL USING statement name data items available to
the calling program that can be referred to in the called program. A given data-
name can appear more than once.
When the USING phrase is specified, the program runs as if each reference to a
USING data-name in the called program Procedure Division is replaced by a refer-
ence to the corresponding USING data-name in the calling program.
Examples that illustrate the USING phrase are given in Table 25 on page 513 and
in “Inter-Program Communication Function Examples” later in this chapter.
CANCEL Statement
The CANCEL statement releases the storage occupied by a called program.
Format
┌ ┐
CANCEL { identifier-1 } │ , identifier-2 │ . . .
{ literal-1 } │ , literal-2 │
└ ┘
Each literal or identifier specified in the CANCEL statement must be nonnumeric. The
contents must conform to the rules for formation of a program-name (see
“PROGRAM-ID Paragraph” on page 268). The first ten characters of the literal or
identifier are used to make the correspondence between the calling and called
program.
Each literal or identifier specified in the CANCEL statement must be the same as the
literal or identifier specified in the associated CALL statement(s).
The program named in a CANCEL statement can be entered in its initial state again
after the CANCEL statement is processed: the program is entered in its initial state if
a CALL statement that names the program is processed by any program in the run
unit. A CALL statement is the only means by which a logical relationship to a can-
celed program can be reestablished.
| A CANCEL statement only operates on the program specified, and not on any
| program that may have been called by the canceled program.
No action results from the processing of a CANCEL statement that names a program
that has not been called in the run unit, or that names a program that was called
but is at present 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 programs can contain CANCEL statements. However, a called program must
not contain a CANCEL statement that directly or indirectly cancels a calling program.
In this case control is passed to the next 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
can, however, cancel a program that it did not call. For example, if A calls B and B
calls C, when A receives control, it can cancel C; or if A calls B and A calls C,
when C receives control, it can cancel B.
Note: In the calling program, the code for parts (PARTCODE) and the part number
(PARTNO) are referred to separately. In the called program, the code for parts and
the part number are combined into one data item (PART-ID); therefore in the called
program, a reference to PART-ID is the only valid reference to them.
Format
EXIT PROGRAM.
through the exit point to the first sentence of the next paragraph. For more infor-
mation, see “Inter-Program Communication Considerations” on page 262.
When STOP RUN is specified, processing of the run unit is terminated. If a STOP RUN
statement appears in a sequence of imperative statements, it must be the last or
the only statement in the sequence. All files should be closed before a STOP RUN
statement is processed. If you do not close the files, they are closed by compiler-
generated code. For more information, see “Inter-Program Communication
Considerations” on page 262.
An implicit STOP RUN is always generated after the last statement in the source
program.
The following example illustrates a dynamic CALL. The dynamic CALL differs in in
the way it is processed from the static CALL that is illustrated in the preceding
example.
IDENTIFICATION DIVISION.
PROGRAM-ID. CALLDYNA.
.
.
.
DATA DIVISION.
.
.
.
WORKING-STORAGE SECTION.
1 IDENT PICTURE X(1).
.
.
.
1 RECORD-2 PIC X.
1 RECORD-1.
5 SALARY PIC S9(5)V99.
5 RATE PIC S9V99.
5 HOURS PIC XXX.
.
.
.
PROCEDURE DIVISION.
.
.
.
MOVE "PROG" TO IDENT.
CALL IDENT USING RECORD-1, RECORD-2.
.
.
.
CANCEL IDENT.
.
.
.
STOP RUN.
The following called program can be associated with either of the calling programs
in the two preceding examples.
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG.
.
.
.
DATA DIVISION.
.
.
.
LINKAGE SECTION.
1 PAYREC.
1 PAY PIC S9(5)V99.
1 HOURLY-RATE PIC S9V99.
1 HOURS PIC S99V9.
1 CODECHAR PIC 9.
.
.
.
PROCEDURE DIVISION USING PAYREC CODECHAR.
.
.
.
EXIT PROGRAM.
Processing in these examples begins in the calling program, which can be either
CALLSTAT or CALLDYNA. When the first CALL statement is processed, control is trans-
ferred to the first statement of the Procedure Division in the called program, PROG.
Note that in each of the calling programs the operand of the first USING phrase is
identified as RECORD-1.
When PROG receives control, the values within RECORD-1 are made available to PROG;
however, in PROG they are referred to as PAYREC.
Note that the PICTURE character-strings within PAYREC and CODE contain the same
number of characters as RECORD-1 and RECORD-2, although the descriptions are not
identical.
When processing within PROG reaches the EXIT PROGRAM statement, control is
returned to the calling program, and processing continues in that program.
In any given running of these two calling programs, if the values within RECORD-1
are changed between the time of the first CALL and another CALL, the values passed
at the time of the second CALL statement are the changed, not the original, values.
If the user wishes to use the original values, then he must ensure that they have
been saved.
You access all these graphics routines with the same format of the CALL statement:
Format
CALL "GDDM" USING routine-name [ , data-name-1 ] . . .
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.
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 OS4-GRAPHICS-ROUTINE-NAME.
CALL "GDDM" USING OS4-GRAPHICS-ROUTINE-NAME.
.
.
MOVE "GSFLD" TO OS4-GRAPHICS-ROUTINE-NAME.
CALL "GDDM" USING OS4-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.
DEBUGGING FEATURES
The debugging features specify the conditions under which procedures are to be
monitored during the program run.
COBOL source language debugging statements are provided. The user decides
what to monitor and what information to retrieve for debugging purposes. The
COBOL debugging features simply provide access to pertinent information.
Compile-Time Switch
In the SOURCE-COMPUTER paragraph of the Configuration Section, the WITH DEBUGGING
MODE clause acts as a compile-time switch.
Format
SOURCE-COMPUTER. computer-name
The WITH DEBUGGING MODE clause serves as a compile-time switch for the debugging
statements written in the source program.
When WITH DEBUGGING MODE is specified, all debugging sections and debugging
lines are compiled as specified in this chapter. When WITH DEBUGGING MODE is
omitted, all debugging sections and debugging lines are treated as documentation.
Run-Time Switch
The run-time switch dynamically activates the debugging code that is generated
when WITH DEBUGGING MODE is specified. Two commands, ENTCBLDBG and ENDCBLDBG
are provided to control the run-time switch.
To ensure that the run-time debug switch is set correctly, you should use the
System/38-Compatible COBOL CL command ENTCBLDBG within the System/38 envi-
ronment.
To display the prompt screen, press the F4 key immediately after entering the
command. The following screen will be displayed.
n o
ENTCBLDBG Enter COBOL Debug
Bottom
F3=Exit F4=List F5=Refresh F11=Keywords F12=Previous F13=Prompter help
p q
To view the keywords associated with the parameter and option shown above,
press the F11 key. The following screen will be displayed.
n o
ENTCBLDBG Enter COBOL Debug
Bottom
F3=Exit F4=List F5=Refresh F11=Choices F12=Previous F13=Prompter help
p q
To set the run-time switch off, enter the command ENDCBLDBG in the System/38 envi-
ronment.
As indicated above, the prompt screen will be displayed if you press the F4 key.
n o
ENDCBLDBG End COBOL Debug
Bottom
F3=Exit F4=List F5=Refresh F11=Keywords F12=Previous F13=Prompter help
p q
Similarly, By pressing the F11 key the following keyword screen will be displayed.
n o
ENDCBLDBG End COBOL Debug
Bottom
F3=Exit F4=List F5=Refresh F11=Choices F12=Previous F13=Prompter help
p q
When debugging mode is specified, through the run-time switch, all the debugging
sections and debugging lines (D in column 7) compiled into the program are acti-
vated.
The ENTCBLDBG command must be entered for each COBOL program (main program
or called program) to be debugged in the next COBOL run unit. At the end of the
run unit, all run-time switches that are on are set off. If a switch must be set off
before the processing of a COBOL run unit, the ENDCBLDBG command should be
used.
When debugging mode is suppressed, through the run-time switch, any USE FOR
DEBUGGING Declarative procedures are inhibited. However, all debugging lines (D in
column 7) remain in effect.
When WITH DEBUGGING MODE is not specified in the SOURCE-COMPUTER paragraph, the
run-time switch has no effect on the running of the program.
Format
{ [ ALL REFERENCES OF ] identifier-1 }
USE FOR DEBUGGING ON { file-name-1 }
{ procedure-name-1 }
{ ALL PROCEDURES }
┌ ┐
│ [ ALL REFERENCES OF ] identifier-2 │
│ file-name-2 │ . . .
│ procedure-name-2 │
│ ALL PROCEDURES │
└ ┘
When specified, all debugging sections must be written immediately after the
DECLARATIVES header. Except for the USE FOR DEBUGGING sentence there must be
no reference to any nondeclarative procedure within the debugging procedure.
A debugging section for a specific operand is processed only once as the result of
the processing of a single statement, no matter how many times the operand is
specified in the statement. An exception to this rule is that each specification of a
subscripted or indexed identifier where the subscripts or indexes are different
causes the calling of the debugging Declarative. For a PERFORM statement that
causes repeated processing of a procedure, any associated procedure-name
debugging Declarative section is processed each time the procedure is run.
Statements appearing outside the debugging sections must not refer to procedure-
names defined within the debugging sections.
Except for the USE FOR DEBUGGING sentence itself, statements within a debugging
Declarative section can only refer to procedure-names defined in a different USE
procedure through the PERFORM statement. Procedure-names within debugging
Declarative sections must not appear in USE FOR DEBUGGING sentences.
Table 26 on page 522 defines the points during the program run when the USE FOR
DEBUGGING procedures are processed. Identifier-n, file-name-n, and procedure-
name-n refer to the first and all subsequent specifications of that type of operand in
one USE FOR DEBUGGING sentence. Any particular identifier, file-name, or procedure-
name can appear in only one USE FOR DEBUGGING sentence, and only once in that
sentence.
References to the DEBUG-ITEM special register can be made only from within a
debugging Declarative procedure.
Notes:
1. Operands acted upon but not explicitly named in such statements as ADD, MOVE,
or SUBTRACT CORRESPONDING never cause activation of a USE FOR DEBUGGING pro-
cedure when such statements are processed.
2. If an operand is specified in a phrase that is not processed, the associated
debugging section is not processed.
3. A SEARCH or SEARCH ALL statement that refers to an identifier that normally
requires subscripting or indexing does not call the USE FOR DEBUGGING proce-
dures.
4. When a USE FOR DEBUGGING operand is used as a qualifier, such a reference in
the program does not activate the debugging procedures.
The DEBUG-ITEM special register provides information about the conditions causing
debugging section processing.
Before each debugging section is processed, DEBUG-ITEM is filled with spaces. The
contents of the DEBUG-ITEM subfields are then updated according to the rules for
the MOVE statement, with one exception: DEBUG-CONTENTS is updated as if the move
were an alphanumeric to alphanumeric elementary move without conversion of data
from one form of internal representation to another. After updating, each field
contains:
DEBUG-LINE: The compiler-generated statement number, right justified and
padded on the left with zeros. For example, 000112.
DEBUG-NAME: The first 30 characters of the name causing debugging section
processing. All qualifiers are separated by the word OF (subscripts or indexes
are not entered in DEBUG-NAME).
DEBUG-SUB-1, DEBUG-SUB-2, DEBUG-SUB-3: If the DEBUG-NAME is subscripted or
indexed, the occurrence number of each level is entered in the respective
DEBUG-SUB-n. If the item is not subscripted or indexed, these fields remain
spaces.
Debugging Lines
A debugging line is any line in a source program with a D coded in column 7 (the
continuation area). If a debugging line contains nothing but spaces in Area A and
Area B, it is considered a blank line.
Each debugging line must be written so that a syntactically correct program results
whether the debugging lines are compiled into the program or syntax-checked, but
are treated as documentation.
When the WITH DEBUGGING MODE clause is specified in the SOURCE-COMPUTER para-
graph, all debugging lines are compiled as part of the object program.
When the WITH DEBUGGING MODE clause is omitted, all debugging lines are syntax-
checked, but are treated as documentation.
FIPS FLAGGER
The FIPS (Federal Information Processing Standard) Flagger can be specified.
Depending on the compiler option specified, it identifies source statements and
clauses that do not conform to a specified level of the federal standard. For infor-
mation on the FIPS Flagger, see “Federal Information Processing Standard Flagger”
on page 2.
Character-String Considerations
The maximum length of a nonnumeric literal is 160 characters. See “Literals” on
page 7.
Identification Division
The system uses the first 10 characters of the program-name specified in the
PROGRAM-ID paragraph. See “PROGRAM-ID Paragraph” in Chapter 8, “Identifica-
tion and Environment Divisions.”
Environment Division
The DEV parameter of an Override command can change the device type that the
file will use. See “FILE-CONTROL Paragraph” on page 281.
COBOL programs can process data base files. The ORGANIZATION of the file indi-
cates the current program usage. See “File Processing Summary” and
“FILE-CONTROL Paragraph, ORGANIZATION Clause” in Chapter 8, “Identification
and Environment Divisions.”
The OVRDBF command can set the current record pointer when the file is opened.
See “FILE-CONTROL Paragraph, ACCESS MODE Clause” in Chapter 8, “Identifi-
cation and Environment Divisions.”
The DUPLICATES phrase can be specified for the RECORD KEY clause. See
“FILE-CONTROL Paragraph, RECORD KEY Clause (Indexed File)” in Chapter 8,
“Identification and Environment Divisions.” Additional information is given in dis-
cussions of the READ, REWRITE, DELETE, and WRITE statements in Chapter 10, “Pro-
cedure Division.”
The keywords specified for the data item in DDS can modify record sequence. In
particular if the DDS keyword DESCEND is used when the field is specified as a key,
the sequence can be a descending key sequence. See “FILE-CONTROL Para-
graph, RECORD KEY Clause (Indexed File)” in Chapter 8, “Identification and Envi-
ronment Divisions.”
Data Division
Elementary items or group items immediately subordinate to one group item can
have unequal level-numbers. See “Data Description Concepts, Level-Numbers” in
Chapter 9, “Data Division.”
The OVRTAPF command can change the LABEL RECORDS clause at run time. See
“File Description Entry, LABEL RECORDS Clause” in Chapter 9, “Data Division.”
If the CODE-SET clause is omitted, the CODE parameter of the CRTDKTF or the CRTTAPF
command is used. The OVRDKTF or the OVRTAPF command can change the
CODE-SET clause at run time. See “File Description Entry, CODE-SET Clause” in
Chapter 9, “Data Division.”
For the USING phrase of the CALL statement, data-names can have level-numbers
that are not 01 or 77, and the data-names can be indexed, subscripted, or qualified.
See “CALL Statement, USING Phrase” in Chapter 11, “Using the Additional
COBOL Functions.”
A FILLER item can be used as a group item definition. See “Data-Name or FILLER
Clause” in Chapter 9, “Data Division.”
The key specified for an OCCURS clause can have USAGE of COMPUTATIONAL-3 or
COMPUTATIONAL-4. See “OCCURS Clause” on page 476.
The JUSTIFIED clause can be specified for alphanumeric edited items. See “JUSTI-
FIED Clause” in Chapter 9, “Data Division.”
Procedure Division
The mnemonic-names OPEN-FEEDBACK and I-O-FEEDBACK are used for file informa-
tion and are accessed through an ACCEPT statement format. See “ACCEPT
Statement” on page 373.
The AT END phrase can be omitted for the READ statement. See “Common
Input/Output Phrases” on page 370.
The FORMAT phrase is valid for DELETE, READ, REWRITE, START, and WRITE state-
ments. See “DELETE Statement”, “READ Statement”, “REWRITE Statement”,
“START Statement”, and “WRITE Statement” in Chapter 10, “Procedure Division.”
The system always rewinds and unloads the tape when REEL/UNIT is specified in
the CLOSE statement. See “CLOSE Statement” on page 377.
The INHWRT parameter of the OVRDBF command can inhibit the DELETE, READ, and
WRITE statements. See “DELETE Statement”, “READ Statement”, and “WRITE
Statement” in Chapter 10, “Procedure Division.”
For a file with duplicate primary keys allowed, a READ statement must immediately
precede a DELETE or REWRITE statement to ensure proper deletion. See “DELETE
Statement” and “REWRITE Statement” in Chapter 10, “Procedure Division.”
For the DISPLAY statement, COMPUTATIONAL-4 items are converted to zoned decimal
items and signed noninteger numeric literals are allowed. See “DISPLAY
Statement” on page 385.
The DISPLAY statement can be used to transfer data to a job’s local data area. See
“DISPLAY Statement” on page 385.
A logical file opened for OUTPUT does not remove all records in the physical file on
which it is based. The OVRDBF command can specify the first record to be made
available to the program at run time. See “OPEN Statement” in Chapter 10, “Pro-
cedure Division.”
FIRST, PRIOR, and LAST can be specified on the READ statement for indexed files
with dynamic access. See “READ Statement” in Chapter 10, “Procedure Division.”
For the WRITE statement, the mnemonic-name phrase can be used for stacker
selection on a card punch file. See “WRITE Statement”
Note: Card devices are not supported by System/38-Compatible COBOL, even
though the devices are accepted by the syntax checker. in Chapter 10, “Procedure
Division.”
The two additional formats of the SET statement can be used to set mnemonic-
names to on or off and to set condition-names to true. See “SET Statement” in
Chapter 10, “Procedure Division.”
Two active PERFORM and GO TO statements can have a common exit point. See
“PERFORM Statement” in Chapter 10, “Procedure Division.”
The COMMIT statement can be used to synchronize changes to records in data base
files under commitment control, while preventing other jobs from accessing or modi-
fying those records until the COMMIT is complete. See “COMMIT Statement” in
Chapter 10, “Procedure Division.”
The ROLLBACK statement can be used to cancel data base changes from files under
commitment control when the changes should not remain permanent. See
“ROLLBACK Statement” in Chapter 10, “Procedure Division.”
The Format 2 COPY statement is used to create Data Division entries for externally
described files in a program. See “COPY Statement” on page 30.
TRANSACTION Files
The data organization for work stations, display files, BSC files, communications
files, and mixed files is TRANSACTION. TRANSACTION files have special formats for the
file-control entry, file description entry, and the input/output statements.
TRANSACTION file considerations are in Chapter 5, “Interactive Processing Consider-
ations and Example Programs.”
Considerations for the TRANSACTION file description entry are the same as those for
other file description entries.
Boolean data provides a means of modifying and passing the values of the indica-
tors associated with the display screen formats. See “Indicators” on page 92.
The ACQUIRE statement can be used to acquire a program device for a TRANSACTION
file. See “ACQUIRE Statement” in Chapter 5, “Interactive Processing Consider-
ations and Example Programs.”
Compiler Options
Sequence checking can be suppressed at compile time. The apostrophe or the
quotation mark can be used as a separator according to the compiler option speci-
fied. See “Create COBOL Program Command” on page 37 and “PROCESS
Statement” on page 46.
The 5424 Multi-Function Card Unit (MFCU) can process more than one card proc-
essing function in a single pass through the unit. If a card has already been par-
tially punched, the MFCU can read the card, punch additional information into the
card, and print up to 128 characters of information on the card. COBOL supports
these combined functions through normal control language. This support is based
on the concept of associated files.
COBOL handles each combined function as a separate logical file; each such logical
file has its own file structure and processing requirements. Therefore, the user
must define each function as if it were a unique file. However, because such com-
bined function files refer to one physical unit, the user must define the logical files
as being associated with each other, and relate them to each other during proc-
essing. The following sections explain the programming requirements for associ-
ated card file processing in System/38-Compatible COBOL.
Environment Division
Associated card file processing requires certain information in the SELECT and
ASSIGN clauses.
SELECT Clause
A unique system file-name must be defined for each of the functions (reading,
punching, and printing) to be combined.
ASSIGN Clause
For associated card files, the ASSIGN clause assignment-name must specify the
primary (P) hopper of the 5424 MFCU and the association. The following format is
valid:
Format
{ READER }
{ PUNCH } [ - system-name ] - P-association
{ PRINT }
{ PUNCHPRINT }
The association must be the same one-digit integer for all associated logical files.
This tells the compiler that each logical file is part of a particular associated card
file processing structure that is assigned to one physical unit. Any two, or all three,
of the functions READER, PUNCH, or PRINT can each be specified once. When the
function PUNCHPRINT is specified for an associated file, READER can be the only other
function specified for that association.
More than one associated card file processing structure can be defined in a
program; however, the structures must not be processed concurrently. Each such
structure must have a unique association entry.
Data Division
An FD entry and a 1 record description entry must be defined in the File Section of
the Data Division for each associated logical file.
Procedure Division
All associated files within one associated card file processing structure must be
opened before a READ or WRITE statement is processed for any file in the structure.
Similarly, no associated files can be closed until all READ and WRITE statements
have been processed. When all such statements have been processed, all of the
associated files must be closed.
An OPEN, READ, WRITE, or CLOSE statement for one of the associated files cannot be
processed without concurrent processing of the other associated files. That is, all
processing of associated files must reflect the association.
For associated files with the functions of read (READER), punch (PUNCH), print (PRINT),
and punchprint (PUNCHPRINT), the following processing rules apply:
1. An OPEN statement must be processed for each file; with the INPUT phrase spec-
ified for the READER file and the OUTPUT phrase specified for the PUNCH, PRINT,
and PUNCHPRINT files.
2. To make the logical input record available, a READ statement must first be proc-
essed for the READER file.
3. The next input/output operation processed for an associated file must be a
WRITE statement for the associated PUNCH file. However, before the WRITE state-
ment is processed, all data to be punched must be moved to the record speci-
fied for the associated PUNCH file.
Note: An alternative method is to move the additional data to be punched to
the appropriate fields of the input record, and then to process a WRITE state-
ment for the PUNCH file using the FROM identifier phrase, where the identifier is
the record-name specified for the READER file.
4. The WRITE statement for the PRINT file must be the next input/output statement
processed for any of the associated files. Before the WRITE statement for the
PRINT file is processed, you must format the data to be printed by moving it to
the record specified for the PRINT file.
5. Steps 1 through 4 are repeated for all other records in the READER file.
6. When the PUNCHPRINT file is specified, a WRITE statement for the PUNCHPRINT file
must be the next input/output statement following the READ statement for the
READER file. Before the WRITE statement for the PUNCHPRINT file is processed,
you must format the data to be punched and printed by moving it to the record
specified for the PUNCHPRINT file.
When both PUNCH and PRINT files are associated, the stacker selection, if specified,
in the WRITE statement for the PRINT file overrides any stacker selection specified
for the PUNCH file.
When the READER file is specified for an associated card file, a READ until the AT END
condition is detected must be done. This forces punch and/or print operations to
occur for the last record read.
is replaced by
The compiler first determines the maximum value that the ir can contain by proc-
essing the statement in which the ir occurs.
If an operand in this statement is a data-name, the value used for the data-
name is equal to the numerical value of the PICTURE for the data-name (that is,
PICTURE 9V99 has the value 9.99).
If an operand is a literal, the literal is treated as though it had a PICTURE, and
the numerical value of the PICTURE is used (that is, the literal +127.3 has an
implied PICTURE S999V9).
If an operand is an intermediate result, the PICTURE determined for the interme-
diate result in a previous operation is used. The numerical value of that
PICTURE is used.
If the operation is division:
– If op2 is a data-name, the value used for op2 is the minimum nonzero
value of the digit in the PICTURE for the data-name (that is, PICTURE 9V99
has the value 0.01).
– If op2 is an intermediate result, the intermediate result is treated as though
it had a PICTURE, and the minimum nonzero value of the digits in this
PICTURE is used.
When the maximum value of the ir is determined by the above procedures, i is set
equal to the number of integers in the maximum value.
Table 28 indicates the action of the compiler when handling intermediate results.
Interactive Messages
In an interactive environment, messages are displayed on the work station screen.
They can appear on the current display as a result of processing a program or in
response to your keyed input to prompts, menus, or command entry displays. The
messages can also appear on request, as a result of a display command or an
option on a menu.
The interactive messages for the COBOL licensed program begin with a CSC, a
CBE, or a CBL prefix.
The CSC messages are issued by the COBOL syntax checker when SEU is
used to enter your COBOL source.
The CBE messages provide you with additional information about system oper-
ation during run-time.
The CBL messages are compiler-generated messages. See Compilation Mes-
sages below for a further description.
Compilation Messages
Compiler-generated messages indicate conditions encountered during program
compilation.
The CBL messages are printed in the program listing and include the messages
issued when FIPS (Federal Information Processing Standard) flagging is requested.
Severity Levels
System/38-Compatible COBOL provides the following message severity levels:
Severity Meaning
00 Informational: This level is used to convey information to the user
that may be of interest to him. No error has occurred. Informational
messages are listed only when the FLAG () option is specified.
10 Warning: This level indicates that an error was detected but is not
serious enough to interfere with the running of the program.
The compiler always attempts to provide full diagnostics of all source text in the
program, even when errors have been detected. If the compiler cannot continue on
a given statement, the message states that the compiler cannot continue and that it
will ignore the rest of the statement. When this occurs, the programmer should
examine the entire statement.
Substitution variables and valid reply values are determined by the program
sending the message, not by the message description stored in the message file.
However, certain elements of a message description can be changed: for example,
the text, severity level, default response, or dump list. To effect such changes, you
need to define another message description using an Add Message Description
(ADDMSGD) command, place the modified description in a user-created message
file,17 and specify that file in the Override Message File (OVRMSGF) command. Using
the OVRMSGF command allows the compiler to retrieve messages from the specified
file. See the ADDMSGD and OVRMSGF commands in the CL Programmer's Guide, the
CL Reference, and in the System/38 Environment Programmer’s Guide/Reference
for additional information.
17 If an IBM-supplied message must be changed and replaced in its message file, call your service representative.
Table 30 on page 548 contains status key values and their meanings.
CARD PUNCHPRINT
WORK STATION
CARD READER
FORMATFILE
CARD PRINT
DISKETTE
DISK SEQ
PRINTER
TAPE
DEVICE TYPE
Environment Division
RERUN...RECORDS C C C C C C C C C C C C C C C C
SAME O O O O O O O . O O O O O O O O
AREA C C C C C C C C C C C C C C C C
RECORD AREA O O O O O O O . O O O O O O O O
SORT AREA C . . . . C C . . . . . . . . .
SORT MERGE AREA C . . . . C C . . . . . . . . .
MULTIPLE FILE TAPE . . . . . C . . . . . . . . . .
COMMITMENT CONTROL . . . . . . D D D D D D D . . .
SELECT R R R R R R R R R R R R R R R R
ASSIGN R R R R R R R R R R R R R R R R
OPTIONAL I . . . . I I . . . . . . . I I
ORGANIZATION O O O O O O O R R R R R R R O O
SEQUENTIAL O O O O O O O . . . . . . . O O
RELATIVE . . . . . . . R R R . . . . . .
INDEXED . . . . . . . . . . R R R . . .
TRANSACTION . . . . . . . . . . . . . R . .
ACCESS O O O O O O O O R R O R R O O O
SEQUENTIAL O O O O O O O O . . O . . O O O
RANDOM . . . . . . . . R . . R . . . .
DYNAMIC . . . . . . . . . R . . R S . .
RESERVE C C C C C C C C C C C C C . C C
RELATIVE KEY . . . . . . . O R R . . . S . .
RECORD KEY . . . . . . . . . . R R R . . .
DUPLICATES . . . . . . . . . . D D D . . .
FILE STATUS O O O O O O O O O O O O O O O O
CONTROL-AREA . . . . . . . . . . . . . O . .
DATA DIVISION
LABEL RECORDS X X X X X R X X X X X X X X X X
STANDARD . . . . . O R R R R R R R O R R
OMITTED R R R R R O . . . . . . . O . .
CARD PUNCHPRINT
WORK STATION
CARD READER
FORMATFILE
CARD PRINT
DISKETTE
DISK SEQ
PRINTER
TAPE
DEVICE TYPE
VALUE OF C C C C C C C C C C C C C C C C
BLOCK CONTAINS O O O O O O O O O O O O O O O O
RECORD CONTAINS O O O O O O O O O O O O O O O O
DATA RECORDS O O O O O O O O O O O O O O O O
CODE-SET . . . . . O . . . . . . . . O .
LINEAGE . . . . O . . . . . . . . . . .
PROCEDURE DIVISION
OPEN R R R R R R R R R R R R R R R R
INPUT R . . . . O O O O O O O O . O O
OUTPUT . R R R R O O O O O O O O . O O
I-O . . . . . . O O O O O O O R . O
NO REWIND . . . . . I . . . . . . . . . .
REVERSED . . . . . I . . . . . . . . . .
EXTEND . . . . . O O . . . . . . . . O
CLOSE R R R R R R R R R R R R R R R R
REEL/UNIT . . . . . O . . . . . . . . . .
REMOVAL . . . . . O . . . . . . . . . .
NO REWIND . . . . . O . . . . . . . . . .
NO REWIND . . . . . O . . . . . . . . . .
WITH LOCK O O O O O O O O O O O O O O O O
READ I . . . . I I I I I I I I I I I
NEXT . . . . . . . . . I . . I . . .
FIRST . . . . . . . . . . . . D . . .
LAST . . . . . . . . . . . . D . . .
PRIOR . . . . . . . . . . . . D . . .
INTO I . . . . I I I I I I I I I I I
AT END I . . . . I I I . I I . I I I I
INVALID KEY . . . . . . . . I I . I I B . .
FORMAT . . . . . . D . . . D D D I . R
NEXT MODIFIED . . . . . . . . . . . . . B . .
SUBFILE . . . . . . . . . . . . . B . .
Appendix E. File Structure Support Summary and Status Key Values 545
Table 29 (Page 3 of 4). File Structure Support
CARD PUNCHPRINT
WORK STATION
CARD READER
FORMATFILE
CARD PRINT
DISKETTE
DISK SEQ
PRINTER
TAPE
DEVICE TYPE
INDICATORS . . . . . . . . . . . . . I . .
TERMINAL . . . . . . . . . . . . . O . .
NO DATA . . . . . . . . . . . . . O . .
WRITE . O O O O O O O O O O O O O O O
FROM . O O O O O O O O O O O O O O O
INVALID KEY . . . . . . . O O O O O O B . .
ADVANCING . O O O O . . . . . . . . . . .
AT END-OF-PAGE . . . . O . . . . . . . . . . .
FORMAT . . . . . . D . . . D D D R . R
STARTING . . . . . . . . . . . . . O . .
ROLLING . . . . . . . . . . . . . O . .
INDICATORS . . . . . . . . . . . . . O . .
SUBFILE . . . . . . . . . . . . . B . .
TERMINAL . . . . . . . . . . . . . O . .
START . . . . . . . O . O O . O . . .
KEY . . . . . . . O . O O . O . . .
INVALID KEY . . . . . . . O . O O . O . . .
FORMAT . . . . . . . . . . D D D . . .
REWRITE . . . . . . O O O O O O O B . .
FROM . . . . . . O O O O O O O B . .
INVALID KEY . . . . . . . . O O . O O B . .
FORMAT . . . . . . . . . . . D D B . .
INDICATORS . . . . . . . . . . . . . B . .
SUBFILE . . . . . . . . . . . . . S . .
TERMINAL . . . . . . . . . . . . . O . .
DELETE . . . . . . . O O O O O O . . .
INVALID KEY . . . . . . . . O O . O O . . .
FORMAT . . . . . . . . . . . D D . . .
USE O O O O O O O O O O O O O O O O
EXCEPTION/
O O O O O O O O O O O O O O O O
ERROR
CARD PUNCHPRINT
WORK STATION
CARD READER
FORMATFILE
CARD PRINT
DISKETTE
DISK SEQ
PRINTER
TAPE
DEVICE TYPE
FOR DEBUGGING O O O O O O O O O O O O O O O O
COMMIT . . . . . . D D D D D D D . . .
ROLLBACK . . . . . . D D D D D D D . . .
ACQUIRE . . . . . . . . . . . . . O . .
DROP . . . . . . . . . . . . . O . .
Appendix E. File Structure Support Summary and Status Key Values 547
Status Key Values and Meanings
1 Sequence error REWRITE to an indexed file with sequential access and key for
REWRITE ≠ key from previous READ, or WRITE to an indexed
file with sequential access and key values for succeeding writes
are not in ascending sequence.
2 Duplicate key when duplicates CPF4759, CPF5008, CPF5026, CPF5034, CPF5084, CPF5085,
are not allowed or WRITE to an indexed file with sequential access and key
values for succeeding writes are not in ascending sequence.
0 Other errors:
File not found CPF4101 if a USE is applicable for the file.
Member not found CPF4102 if a USE is applicable for the file.
Level check error CPF4131.
Unexpected I-O The following exceptions are monitored generically:
exceptions
CPF4101 through CPF4399
CPF4501 through CPF4699
CPF4701 through CPF4899
CPF5001 through CPF5099
CPF5101 through CPF5399
CPF5500 through CPF5699
These exceptions are caught and FILE STATUS is set to 90.
If a USE procedure is applicable, it is processed. Otherwise,
the program ends and gives the operator the exception and
the option to cancel, take a partial dump, or take a full dump.
9 Other Errors (continued)
CPF4741.
A Job has been cancelled in a Escape message sent during a READ from invited program
controlled manner by CL device (multiple device files only).
command CNLJOB, TRMSBS,
TRMCPF, or PWRDWNSYS
Appendix E. File Structure Support Summary and Status Key Values 549
Table 30 (Page 3 of 3). Status Key Values and Meanings
Status
Key When Set (OS/400 Exceptions
1 2 Meaning Monitored, Condition Detected)
9 Other Errors (continued)
H ACQUIRE operation failed Resource owned by another program, or unavailable. (9H is the
result when an ACQUIRE operation causes any of the OS/400
exceptions monitored for 90 or 9N to occur).
OPEN failed because file CPF4285, CPF4293, CPF4326, CPF4327, CPF4328, CPF4329.
P cannot be placed under com-
mitment control
Appendix E. File Structure Support Summary and Status Key Values 551
Attribute Data Formats
OPEN-FEEDBACK
The OPEN-FEEDBACK area is part of the open data path (ODP) that contains informa-
tion about the OPEN operation. This information is set during OPEN processing and is
available as long as the file is open.
This area provides information about the file that the program is using. It contains:
Information about the file that is currently open, such as:
– File name
– File type.
Information that depends on the type of file that is opened, such as:
– Printer size
– Screen size
– Diskette or tape labels.
I-O-FEEDBACK
The system updates the I-O-FEEDBACK area each time a block of records is trans-
ferred between OS/400 and the program. A block of records can contain one or
more records.
The I-O-FEEDBACK area is not updated after each read or write for files in which
multiple records are blocked and unblocked by COBOL. If the I-O-FEEDBACK area is
needed after each read or write in the program, the user can do either of the
following:
Prevent the compiler from generating blocking and unblocking code by not sat-
isfying one of the conditions listed under “Unblocking Input Records and
Blocking Output Records” in Chapter 7, “System/38-Compatible COBOL Pro-
gramming Considerations.”
Specify SEQONLY(@NO) on the Override with Data Base File (OVRDBF) CL
command.
Preventing the compiler from generating blocking and unblocking code is more effi-
cient than specifying SEQONLY(@NO).
Even when the compiler generates blocking and unblocking code, certain OS/400
restrictions can cause blocking and unblocking to not be processed. In these
cases, a performance improvement will not be realized. However, the
I-O-FEEDBACK area will be updated after each read or write.
The I-O-FEEDBACK area contains information about the I-O operation. This area
consists of a common area and a device-dependent area. The device-dependent
area varies in length and content depending on the file type. This area follows the
I-O-FEEDBACK common area and can be obtained by specifying the receiving identi-
fier large enough to include the common area and the appropriate device-
dependent area.
The I-O-FEEDBACK area contains information about the last I-O operation, such as:
Device name
Device type
AID character
Error information for some devices.
See the System/38 CPF Programmer's Guide. for a layout and description of the
data areas contained in the OPEN-FEEDBACK and I-O-FEEDBACK areas.
Appendix E. File Structure Support Summary and Status Key Values 553
Attribute Data Formats
230 E6 11100110 W 87
231 E7 11100111 X 88
232 E8 11101000 Y 89
233 E9 11101001 Z 90
.
.
240 F0 11110000 48
241 F1 11110001 1 49
242 F2 11110010 2 50
243 F3 11110011 3 51
244 F4 11110100 4 52
245 F5 11110101 5 53
246 F6 11110110 6 54
247 F7 11110111 7 55
248 F8 11111000 8 56
249 F9 11111001 9 57
.
.
255 FF
Each word in the list is preceded by an identifier that is associated with one of the
following meanings:
Blank A System/38-Compatible COBOL reserved word from the 1974 ANS
standard.
1 A System/38-Compatible COBOL reserved word that is an IBM exten-
sion to the 1974 ANS standard.
2 A COBOL reserved word from the 1974 ANS standard that is not used
by System/38-Compatible COBOL. These words should not be used if
compatibility is important to an installation. If used, a diagnostic
message will be issued.
3 A CODASYL COBOL reserved word that is not included in the 1974
ANS standard and is not supported by System/38-Compatible COBOL
as an extension. If used, a diagnostic message will be issued. These
words are included for compatibility.
2 TABLE
TALLYING
TAPE
3 TENANT
TERMINAL
2 TERMINATE
3 TEST
2 TEXT
THAN
1 THEN
THROUGH
THRU
TIME
TIMES
TO
TOP
TRAILING
1 TRANSACTION
1 TRUE
2 TYPE
UNIT
UNSTRING
UNTIL
UP
3 UPDATE
UPON
USAGE
3 USAGE-MODE
USE
USING
VALUE
VALUES
VARYING
WHEN
WITH
3 WITHIN
WORDS
WORKING-STORAGE
WRITE
ZERO
ZEROES
ZEROS
+
−
*
/
**
>
<
=
On a System/38 the default record sequence for files which allow duplicate keys is
FIFO. On the AS/400 system the default is ‘no specific sequence’. Users should
consider specifying the FIFO keyword in the DDS when creating such files in the
System/38 environment, to maintain consistency with files created on a System/38.
File position indicator - the concept of a current record pointer has been
changed to a file position indicator.
Reserved words - new reserved words have been added.
I/O status - new I/O status values have been added.
Pseudo-text-1 on the COPY statement must not consist entirely of a separator
comma or a separator semicolon.
A data item appearing in the USING phrase of the Procedure Division header
must not have a REDEFINES clause in its data description entry.
If the FOOTING phrase is not specified, no end-of-page condition independent of
the page overflow condition exists.
The NO REWIND phrase cannot be specified in a CLOSE statement having the
REEL/UNIT phrase.
The CANCEL statement closes all open files.
When a receiving item is a variable length data item and contains the object of
the DEPENDING ON phrase, the maximum length of the item will be used.
Within the VARYING ... AFTER phrase of the PERFORM statement, identifier-2
is augmented before identifier-5 is set.
Any subscripts for identifier-4 in the DIVIDE statement REMAINDER phrase are
evaluated after the result of the DIVIDE operation is stored in identifier-3 of
the GIVING phrase.
The phrase ADVANCING PAGE and END-OF-PAGE must not both be in a single
WRITE statement.
The picture character-string of an alphabetic item can contain only the symbol
"A". There is no editing allowed for the alphabetic data category.
When a data item described by a PICTURE containing the character "P" is refer-
enced, the digit positions specified by "P" will be considered to contain zeros in
the following operations:
1. Any operation requiring a numeric sending operand
2. A MOVE statement where the sending operand is numeric and its PICTURE
character-string contains the symbol "P"
3. 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
4. A comparison operation where both operands are numeric.
On the COPY statement, if text-name has not been qualified, QLBLSRC is assumed
as the file name. Also the qualification rules of text-name have changed.
An index name is a compiler generated storage area that is 4 bytes in length
and not 2 bytes in length as in System/38 COBOL.
Note: The length of index data-items has changed from 2 bytes to 4 bytes. There-
fore, System/38 or System/38-Compatible COBOL programs that use index data-
items as parameters or arguments will require recompilation. Also, files created by
System/38 or System/38-Compatible COBOL that include items with usage index will
need to be recreated to be used by COBOL/400 programs.
For further information on migrating from System/38 to the AS/400 system, see the
System/38 to AS/400 Migration Aid User’s Guide and Reference.
For further information about COBOL/400 see the COBOL/400 User’s Guide, and the
COBOL/400 Reference.
auxiliary storage. All addressable storage other than class condition. A condition that specifies that the
main storage. character content of a data item as all alphabetic or all
numeric.
binary item. Numeric data that is represented inter-
nally as a number in the base 2 numbering system; clause. A set of consecutive character-strings that
internally, each bit of the item is a binary digit with the specify a characteristic of an entry. There are three
sign as the leftmost bit. types of clauses: data, environment, and file.
binary synchronous communications (BSC). A data collating sequence. The order in which characters
communications line protocol that uses a standard set are arranged within the computer for sorting, combining,
of transmission and control character sequences to or comparing.
send binary-coded data over a communications line.
Contrast with synchronous data link control. column. One of two or more vertical sections of
printed lines on a page. Each field in the report is a
block. A group of records that are recorded or proc- single column.
essed as a unit.
combined condition. A condition that is the result of
Boolean data. A category of data items that are connecting two or more conditions with the AND or the
limited to a value of 1 or 0. OR logical operator.
Boolean literal. A literal composed of a Boolean char- comment. A remark, criticism, or suggestion about
acter enclosed in double quotation marks and preceded something. A comment is ignored by a compiler.
by a B; for example, B"1".
commitment boundary. Any time there are no out-
bottom margin. A blank area that follows the page standing changes for a data base file in a commitment
body. controlled environment.
boundary violation. An attempt to write beyond the commitment control. A means of grouping file oper-
externally defined boundaries of a sequential file. ations that allows the processing of a group of data
base changes as a single unit through the COMMIT
breakpoint. A place in a program (specified by a command or the removal of a group of data base
command or a condition) where the system stops proc- changes as a single unit through the ROLLBACK
essing of that program and gives control to the display command.
station user or to a specified program.
common key. The key fields that are common to all
BSC file. A device file created by the user to support record formats in the file starting with the first key field
BSC. Contrast with communications file. (the most significant) and ending with the last key field
(the least significant).
called program. A program that is called up and run
from within another program (a calling program) or by a communications file. A device file created by the
command. user to support LU1 SDLC communications. Contrast
with BSC file.
calling program. A program that requests the running
of another program (a called program). communications device. A BSC, LU1, or APPC device
used through a BSC, communications, or mixed file. In
character. Any letter, number, or other symbol in the COBOL, these files are defined as ORGANIZATION IS
data character set that is part of the organization, TRANSACTION.
control, or representation of data.
compilation. Translation of a source program (such as
character constant. The actual character value (a RPG or COBOL specifications) into a program in
symbol, quantity, or constant) in a source program that machine language.
is itself data, instead of a reference to a field that con-
tains the data. Contrast with numeric constant. compile time. The time during which a source
program is translated by a compiler into a machine-
character set. All the valid COBOL characters. language program.
compound condition. A statement that tests two or currency symbol. The character defined by the
more relational expressions. The result can be true or CURRENCY SIGN clause in the SPECIAL-NAMES paragraph.
false. If no CURRENCY SIGN clause is present, the currency sign
is used. See currency sign.
computer-name. A system-name that identifies the
computer upon which the program is to be compiled or current record. The record that is available in the
run. record area associated with the file.
condition. An expression in a program for which a current record pointer. A method of identifying a
truth value can be determined at run time. Conditions record that is used in the sequential processing of the
include the simple conditions (relational condition, class next record.
condition, condition-name condition, switch-status condi-
tion, sign condition) and the complex conditions data base. The collection of all data base files stored
(negated simple conditions, combined conditions, in the system.
negated combined conditions).
data clause. A clause in a data description entry in
condition-name. A name assigned to a specific value, the Data Division that describes a particular character-
set of values, or range of values within the complete set istic of a data item.
of values that a conditional variable can have.
data communications file. A generic term for a com-
condition-name condition. A statement that the value munications file or a BSC file. See also communications
of a conditional variable is one of a set (or range) of file and BSC file.
values assigned to a condition-name associated with
data description entry. An entry in the Data Division
the conditional variable.
that describes the characteristics of a data item.
conditional expression. A simple condition or a
data description specifications (DDS). A description
complex condition specified in an IF, a PERFORM, or a
of the user’s data base or device files that is entered
SEARCH statement. See also simple condition and
into the system in a fixed-form. The description is then
complex condition.
used to create files.
conditional statement. A statement that controls
Data Division. One of the four main parts of a COBOL
program flow based on the result of the evaluation of a
program. The Data Division describes the files to be
condition.
used in the program and the records contained within
conditional variable. A data item, one or more of the files. It also describes any internal working-storage
which has a condition-name assigned to it. records that are needed.
Configuration Section. A section of the Environment data item. A character or a set of consecutive charac-
Division of a program which describes the overall spec- ters (excluding literals in either case) defined as a unit
ifications of the source and object computers. of data by the COBOL program.
connective. A word or a punctuation character that data name. A user-defined word that names a data
associates a data-name, paragraph-name, condition- item. When used in the general formats, data name
name, or text-name with its qualifier; links two or more represents a word that cannot be subscripted, indexed,
operands in a series; or forms a conditional expression. or qualified unless specifically permitted by the rules of
that format. See also identifier.
declaratives. A set of one or more special-purpose Environment Division. One of the four main parts of
sections at the beginning of the Procedure Division that a COBOL program. The Environment Division describes
can be used for input/output error checking or debug- the computers on which the source program is compiled
ging. and those on which the object program is run; it also
provides a connection between the logical concept of
delimiter. A character or a sequence of characters files and their records, and the physical characteristics
that marks the beginning and end of a unit of data but of the devices on which files are stored.
is not part of that unit of data.
exception. Something that does not conform to the
descending key. The values by which data is normal.
arranged from the highest value to the lowest value of
the key field, in accordance with the rules for comparing exponent. A number, indicating to which power
data items. Contrast with ascending key. another number (the base) is to be raised. In COBOL,
exponentiation is indicated with the symbol ** followed
descending key sequence. The arrangement of data by an exponent.
in order from the highest value of the key field to the
lowest value of the key field. Contrast with ascending EXTEND mode. A method of adding records to the
key sequence. end of a sequential file, when the file is opened.
device file. A file that contains a description of how external decimal item. See zoned decimal item.
data is to be presented to a program from a device or
how data is to be presented to the device from the externally described data. Data contained in a file in
program. Devices can be display stations, printers, a which the fields in the records are described outside of
diskette unit, or a communications line. the program (such as with DDS, IDDU, SQL), and are
used by a program when the file is processed. Contrast
digit. Any of the numerals from 0 through 9. with program-described data.
direct file. A data base file in which records are externally described file. A file in which the record
assigned specific record positions by the relative record fields are described to the system when the file is
number. Contrast with indexed file. created, and used by the program when the file is proc-
essed. Contrast with program described file.
distributed data management (DDM). A function of
the operating system that allows an application program figurative constant. A reserved word that represents
or user on one system to use data files stored on a numeric or character value, or a string of repeated
remote systems. The system must be connected by a values. The word can be used instead of a literal to
communications network, and the remote systems must represent the value.
also be using DDM.
FILE-CONTROL. The name and header of an Environ-
division. One of the four major parts in a COBOL ment Division paragraph in which the data files for a
program: Identification, Environment, Data, and Proce- given source program are named and assigned to spe-
dure. cific input/output devices.
division header. The reserved words and punctuation file description entry. An entry in the FILE SECTION of
that indicate the beginning of one of the four divisions of the Data Division that contains information about the
a COBOL program. identification, the physical organization, and the record
name of a file.
dynamic processing. A method of reading from or
writing to a file in a nonsequential order (see random
file organization. The permanent file arrangement indicator. An internal switch used by a program to test
established at the time that a file is created. a field or record or to tell when certain operations are to
be performed.
FILE SECTION. A section of the Data Division that
contains descriptions of all externally stored data (or input file. A file from which data is read while the
files) used in a program. Such information is given in program is running.
one or more file description entries.
input mode. An open mode in which records can be
file separator. The pages to be produced at the read from the file.
beginning of each output file and used to separate the
file from the other files being sent to an output device. input-output file. A file that is opened in the I-O
mode.
function-name. An IBM-defined name that identifies
system logical units, system-supplied information, Input-Output Section. The section of the Environment
printer control characters, and program switches. Division that names the files and external media needed
by an application program. It also provides information
group item. A named set of consecutive elementary required for the sending and handling of data when the
or group items. program is run.
hierarchy. A set of entries that includes all subordi- Input Procedure. A procedure that provides special
nate entries to the next equal or higher level number. processing of records when they are released to the
sort function.
Identification Division. One of the four main parts of
a COBOL program. In addition to identifying the source integer. A positive or negative whole number.
program and the object program, this part may also
describe the author’s name, the location where written, internal decimal item. See packed decimal item.
and the date written.
INVALID KEY condition. A run-time condition in
identifier. A data-name that is unique or is made which the value of a key for an indexed or direct file
unique by a combination of qualifiers, subscripts, and/or does not give a correct reference to the file.
indexes.
invited device. A display station or communications
imperative statement. A statement that specifies that device that was written to using a DDS format that had
an action is to be taken unconditionally. the INVITE option specified. For multiple device files,
the READ statement will read from any invited program
implementer-name. An IBM-defined name that device if no particular program device is specified for
includes assignment names, computer names, function input using the TERMINAL phrase and no specific FORMAT
names, and language names. is requested.
index. A computer storage position or register, the I-O-CONTROL. The name and the header for an Envi-
contents of which identify a particular element in a ronment Division paragraph in which program require-
table. ments for specific input/output techniques are specified.
These techniques include rerun checkpoints, the
index data item. A data item in which the contents of sharing of same areas by several data files, and the
an index can be stored without conversion to subscript use of a storage-resident cylinder index.
form.
I-O mode. An open mode where records can be read
index name. A user-defined word that names an from, written to, or deleted from the file.
index.
job separator. The pages or cards placed at the
indexed data name. A data name identifier that is beginning of the output for each job that has spooled
subscripted with one or more index names. file entries on the output queue. Each separator con-
tains information that identifies the job such as its
indexed file. A file that records the key and the posi- name, the job user’s name, the job number, and the
tion of each record in a separate part of the file, called time and date the job was run.
the index.
logical operator. A reserved word that defines the next executable statement. The statement to which
logical connection between conditions or negates a control is transferred after the current statement has fin-
condition: OR (logical connective–either or both), AND ished running.
(logical connective–both), and NOT (logical negation).
next record. The record that logically follows the
current record of a file.
nonnumeric item. A data item that is alphanumeric, overlay. To write over (and therefore destroy) an
alphabetic, or Boolean. existing file.
nonnumeric literal. A character string bounded by packed decimal format. Representation of a decimal
quotation marks, which literally means itself. See also value in which each byte within a field represents two
literal. numeric digits except the rightmost byte, which contains
one digit in bits 0 through 3 and the sign in bits 4
numeric character. Any one of the digits 0 through 9. through 7. For all other bytes, bits 0 through 3 repre-
sent one digit; bits 4 through 7 represent one digit. For
numeric constant. The actual numeric value to be example, the decimal value +123 is represented as
used in processing, instead of the name of a field con- 0001 0010 0011 1111. Contrast with zoned decimal
taining the data. A numeric constant can contain any of format.
the numeric digits 0 through 9, a sign (plus or minus),
and a decimal point. Contrast with character literal. packed decimal item. A numeric data item that is
represented internally in packed decimal format.
numeric edited item. A numeric item whose PICTURE
character-string contains valid editing characters. paragraph. In the Procedure Division, a paragraph-
name followed by a period and a space and by zero,
numeric item. A data item that must be numeric. If one, or more sentences. In the Identification and Envi-
signed, the item can also contain a representation of an ronment Divisions, a header followed by zero, one, or
operational sign. more sentences.
object program. A set of instructions in machine paragraph header. A reserved word, followed by a
runnable form. The object program is produced by a period and a space that indicates the beginning of a
compiler from a source program. paragraph in the Identification and Environment Divi-
sions.
OBJECT-COMPUTER. The name of an Environment
Division paragraph in which the computer upon which paragraph name. A user-defined word that identifies
the program will be run is described. and begins a paragraph in the Procedure Division.
open mode. The condition of a file after the program parameter. A variable or a constant that is used to
processes an OPEN statement for that file and before the pass values between calling and called programs.
program processes a CLOSE statement for that file. The
particular open mode is specified in the OPEN statement phrase. An ordered set of one or more consecutive
as either INPUT, OUTPUT, I-O, or EXTEND. COBOL character-strings that forms part of a clause or a
Procedure Division statement.
operand. The object of a verb or an operator; that is,
an operand is the data or equipment governed or physical file. A description of how data is to be pre-
directed by a verb or operator. sented to or received from a program and how data is
actually stored in the data base. A physical file con-
operational sign. An algebraic sign associated with a tains one record format and one or more members.
numeric data item or a numeric constant that indicates Contrast with logical file.
whether the item is positive or negative.
physical record. A unit of data that is moved into or
optional word. A reserved word included in a specific out of the computer. Same as block.
format only to improve the readability of a COBOL state-
ment or entry. procedure. One or more successive paragraphs or
sections within the Procedure Division, which direct the
output file. A file that is opened in either output mode computer to perform some action or series of related
or extend mode. actions.
output mode. An open mode in which records can be Procedure Division. One of the four main parts of a
written to a file. COBOL program. The Procedure Division may contain
instructions for solving a problem. The Procedure Divi-
OUTPUT PROCEDURE. A procedure that provides sion may contain imperative-statements, conditional
special processing of records when they are returned statements, paragraphs, procedures, and sections.
from the sort or merge function.
process. A systematic sequence of operations to record. A collection of related data or words, treated
produce a specified result. as a unit; such as one name, address, or telephone
number. See also logical record.
program-described data. Data contained in a file for
which the fields in the records are described in the record area. A storage area in which a record
program that processes the file. Contrast with described in a record description entry in the File
externally described data. Section is processed.
program-described file. In System/38-Compatible record description entry. The total set of data
COBOL, a file that does not have any COPY statement, description entries associated with a particular record.
DDS format, coded as part of the record description
entry for the file. The fields in the file’s records are record key. A key field whose contents identify a
described only in the program that processes the file. record within an indexed file.
Contrast with externally described file.
relational character. One of the characters that
program device. A symbolic device that a program expresses a relationship between two operands: =
uses instead of a real device (identified by the device (equal to), > (greater than), < (less than).
name). When the program uses a program device, the
system redirects the operation to the appropriate real relational condition. A condition that relates two arith-
device. metic expressions and/or data items.
program name. A user-defined word that identifies a relational operator. A reserved word, a relational
COBOL source program. character, a group of consecutive reserved words, or a
group of consecutive reserved words and relational
pseudo-text. A sequence of character-strings and/or characters used to construct a relational condition.
separators bounded by, but not including, pseudo-text
delimiters. Pseudo-text is used in the COPY REPLACING relative file. See direct file.
statement for replacing text strings.
relative key. An unsigned number that can be used
pseudo-text delimiter. Two equal signs (==) used to directly by the system to locate a record in a file. Same
define the beginning and end of pseudo-text. as relative record number.
punctuation character. A character used to separate relative organization. The file organization in which
COBOL elements or to identify a particular type of each record is uniquely identified by a positive number
COBOL element: a comma, semicolon, period, quotation value that specifies the position in the file relative to the
mark, left or right parenthesis, or space. first record.
qualified data-name. An identifier that is composed of relative record number. A number that specifies the
a data-name followed by one or more sets of either of location of a record in relation to the beginning of a data
the connectives OF or IN followed by a data-name qual- base file member, or subfile. For example, the first
ifier. record in a data base file, member, or subfile has a rel-
ative record number of 1.
qualifier. In data processing, all names in a qualified
name other than the far right which is called the simple reserved word. A special word that has a specific
name. meaning to the system as defined in a programming
language.
random processing. A method of processing in which
specific records can be read from, written to, or deleted routine. A set of statements in a program that causes
from a file order requested by the program that is using the system to perform an operation or a series of
them. related operations.
read-from-invited-program-devices operation. An run time. The time during which the instructions of a
input operation that waits for input from any one of the computer program are processed by a processing unit.
invited program devices for a user-specified time. Con-
trast with read-from-one-program-device operation. run unit. A set of one or more programs that run as a
set to solve a problem. A set starts with the first COBOL
read-from-one-program-device operation. An input program in the program stack and includes all programs
operation that will not complete until the specified
section header. A combination of words, followed by special character. A character that is neither numeric
a period and a space, that indicates the beginning of a nor alphabetic. Special characters in COBOL include: +
section in the Environment, Data, or Procedure Division. - @ / = $ , . " ) ( ; < >
section-name. A user-defined word that names a special-character word. A reserved word that is an
section in the Procedure Division. arithmetic operator or a relational character.
sector. An area on a disk track or a diskette track to SPECIAL-NAMES. The names of an Environment
record information. Division paragraph and the paragraph itself in which
names supplied by IBM are related to mnemonic-names
sentence. A unit of self-contained text. specified by the programmer. In addition, this para-
graph can be used to exchange the functions of the
separator. A punctuation character used to set apart comma and the period or to specify a substitution char-
character strings. See also file separator and job sepa- acter for the currency sign in the PICTURE string.
rator.
special registers. Compiler-generated data items
sequential access. A method of reading from, writing used to store information produced by specific COBOL
to, or removing records from a file based on the way features (for example, the DEBUG-ITEM special register).
the records are arranged in the file.
spooled file. A file that hold output data waiting to be
sequential processing. A method of processing in printed, or input data waiting to be processed by the
which records are read, written to, or deleted in the program.
order determined by the value of the key field.
standard data format. The format in which data is
serial search. A search in which the records of a set described as it appears when it is printed, rather than
of records are consecutively examined, beginning with how it is stored by the computer.
the first record and ending with the last record.
statement. An instruction in a program. A statement
sign condition. A condition that states that the value combines COBOL reserved words and user-defined
of a data item is less than, equal to, or greater than operands.
zero.
storage area. A portion of main storage into which
simple condition. One of the conditions chosen from data is read or from which it is written.
the set: relation condition, class condition, condition-
name condition, switch-status condition, and sign condi- subfile. A group of records of the same record format
tion. that can be displayed at the same time at a work
station. The system sends the entire group of records
single device file. A device file created with only one to the work station in a single operation and receives
program device defined for it. Printer files, card files, the group in another operation.
diskette files, tape files, communications files, and BSC
files are single device files. Display files and mixed files subject of entry. A data-name or reserved word that
created with a maximum number of one program device appears immediately after a level indicator or level-
are also single device files. Contrast with multiple number in a Data Division entry. It serves to reference
device file. the entry.
sort file. A temporary file that contains all the records subprogram. A called program. A subprogram is
to be sorted by a SORT statement. The sort file is combined with the calling program at run time to
created and used by the sort function only. produce a run unit and is below the calling program in
the program stack.
sort-merge file description entry. An entry in the File
Section that describes a sort file or a merge file. subscript. A positive number or variable, whose value
refers to a particular element in a table.
Index 591
blocking output records 210 Calls between programs 1
blocking, automatic 370 CANCEL statement
Boolean data facilities 126 example 513
See also indicators format 512
comparison rules 358 inter-program communication concepts 262
description 92 card file processing 533
format 94, 316 card files, associated 533
sending/receiving items 439 categories
Boolean literal of data, concepts 312
characters permitted in 8 of statements 349
Boolean literal delimiters (B" and ") CBL9001, escape message 38
placement rules for 29 Change Debug (CHGDBG) CL command 61
bottom page margin in LINAGE clause 306, 307 Change Job (CHGJOB) CL command 75
boundary Change Job Description (CHGJOBD) CL
alignment 327 command 75
commitment 247 change/date field 51
brackets, square character codes and CODE-SET clause 309
optional 14 character set 314
use of 38 Character set for COBOL 6
breakpoints 63 ascending EBCDIC sequence 6
considerations 69 IBM extension 6
data-name considerations 66 character string
example 63 alphabetic 6
browsing through a compiler listing 48 and item size 314
BSC (Binary Synchronous Communications) 575 in INSPECT statement 430
BSC files numeric 6
data organization for 530 picture 12
support 90 representation in PICTURE clause 334
business problems, processing of 1 special 6
used as literal 7
uses of 7
C character-string considerations, IBM
CALL GDDM
extensions 527
See graphics support
characters
CALL QCL, CL command 21
in a user-defined word 9
CALL statement 510
meaning of in COBOL 6
control language 59
permitted in a numeric literal 8
dynamic 510
permitted in Boolean literal 8
examples 514
used in PICTURE clause 332
formats 510
valid as separators 13
inter-program communication concepts 510
characters allowed
ON OVERFLOW phrase 510
user-defined word 9
segmentation considerations 506
characters and character strings 6
static 510
CHARACTERS phrase
USING phrase 511
of BLOCK CONTAINS clause 304
called program
of INSPECT statement 434
segmentation considerations 506
checking syntax 1
calling for HELP 88
CHGCMDDFT, CL command 39
calling program
CHGJOB, CL command 75
segmentation considerations 506
Index 593
coding example (continued) comment-entry 29
initialize a table to zero 476 as a comment 12
INSPECT statement 433 entry 12
PERFORM statement 459, 462, 466 in Identification Division 267
Procedure Division 352 use 12
SEARCH statement 486 COMMIT statement
SPECIAL-NAMES paragraph 274 format 381
subscripting 473 commitment boundary 247
coding, COBOL, forms 21 commitment control 255
coding/entering programs 21 considerations 247
COLLATING SEQUENCE phrase example program 250
alphabet-name clause and 275 recovery after failure using 257
of SORT/MERGE statements 497 recovery with 257
collating sequences COMMITMENT CONTROL clause 293
EBCDIC and ASCII 555 format 292
user-specified 275 common data concepts 309
column common keys 228
sequence error indicator 50 common phrases, arithmetic statements
column 7 CORRESPONDING phrase 422
continuation area 25 GIVING phrase 423
D denotes debugging line 524 ROUNDED phrase 423
columns 1 through 6 for sequence numbers 24 SIZE ERROR phrase 423
combined arithmetic operations 425 common processing facilities 130
combined condition current record pointer 371
format 360 INTO/FROM phrases 371
combined relation condition, abbreviated 363 invalid key condition 371
examples 363 status key 370
comma (,) COMMUNICATION module 2
editing character 6 communications
in Configuration Section 270 considerations, inter-program 262
in data description entry 317, 318 inter-program 262
in File-Control entry 284 recovery 257
in I-O-CONTROL paragraph 292 example program 258
programming use 6 communications files
punctuation character 6 data organization for 530
separator, rules for using 13 support 90
series connective 10 comparison rules
comma and decimal point, interchanging 277 Boolean operands 358
command summary 49 INSPECT statement 431
command, CL START statement 407
See CL commands compilation
comment with a remote AS/400 file 278
forms of 12 WITH DEBUGGING MODE 517
comment line 31, 34 compilation date in source listing 269
punctuation characters valid in 30 compilation statistics 49
rules 29 compile-time
successive 29 messages 541
with asterisk 29 options 46
with slash 29 compiled programs, running 59
Index 595
considerations, system dependent (continued) control transfer
DATA DIVISION considerations (continued) changed by ALTER statement 452
COPY DDS statement 219 inter-program communication concepts 507
index literals 474 PERFORM statement 457
item size 304 control transfer rules
LINAGE clause 307 Declarative procedures 364
OCCURS clause 476 explicit, GO TO statement 454
RECORD CONTAINS clause 304 control transfers, explicit and implicit 20
SORT/MERGE statement 495 CONTROL-AREA clause 124
subscript literals 472 control, commitment 255
ENVIRONMENT DIVISION considerations considerations 247
ASSIGN clause 284 example program 250
RECORD KEY clause 289 recovery after failure using 257
RESERVE clause 286 recovery with 257
SAME AREA or SAME RECORD AREA conventions
clause 292 used to represent keywords 10
SAME SORT-MERGE AREA clause 493 used to represent optional words 10
general considerations used to represent reserved words 10
indexed file 288 used to represent user-defined words 9
library-name 17 conversion of data
program-name 268 DISPLAY statement and 385
relative file 288 COPY DDS, use with indicators 130, 223
source program library 30 copy function 22
source statements 22 COPY statement 30
text-name 17 and externally described data 220
user-defined words 9 and floating point 226
PROCEDURE DIVISION considerations and record description entry 299
arithmetic statements 420 data field structures 222
CALL statement 510 DDS and use of 219
GO TO DEPENDING ON statement 454 DDS results 218, 223
INSPECT statement 429 example 34
STOP statement 467 EXTERNALLY-DESCRIBED-KEY 220
UNSTRING statement 445 format 30
constant, figurative 11, 12 phrases 30
contents of DEBUG-ITEM special register 523 REPLACING phrase 33
continuation area use with TRANSACTION files 90
column 7 25 COPY statement, format 2 93
D denotes debugging line 524 COPY, within PROCESS statement 48
continuation line copyname 51
rules 29 CORRESPONDING phrase 422, 440
control flow FILLER items ignored 319
PERFORM statement 458 MOVE statement considerations 436
SEARCH ALL statement 483 count field in INSPECT statement 430
SEARCH statement 481 COUNT IN phrase of UNSTRING statement 447
Control Language (CL) CR (credit) PICTURE symbol 334
CALL statement 59 sign control symbol 340
control of segmentation 504 Create Diskette File (CRTDKTF) CL
control return, in PERFORM statement 457 command 309
control screen management functions 90 Create Job Description (CRTJOBD) CL
command 75
Index 597
data Data Division (continued)
binary 122 data description 309
packed 122 data-names 16
referencing 15 entries 28
requesting from job stream 60 Environment Division 5
data alignment example 297
in an elementary MOVE statement 438 file description entry 125, 298, 300
nonnumeric items 314 function of 5
numeric items 313 Identification Division 5
data area, local 266 inter-program communications concepts 508
and ACCEPT statement 373 order of 5
and DISPLAY statement 385 organization 296
LOCAL-DATA mnemonic-name 273 format 315
data attribute specification 19 Procedure Division 5
data base changes, synchronizing or punctuation in 30
canceling 527 sort/merge considerations 493
data base support table handling considerations
file description entry 300 OCCURS clause 476
logical record 295 USAGE IS INDEX clause 480
physical record 295 Data Division map 49, 52
data base, canceling changes to 530 data field structures 222
data categories data format, standard 8, 314
PICTURE clause 336 data hierarchies
data category of nonnumeric literal 8 concepts 309
data class type 53 used in qualification 15
data classes, description 312 data item
data communications file 90, 122 description entry concepts 310
data conversion level of 53
DISPLAY statement 385 data item description entry 94, 314
in an elementary MOVE statement 438 ADD statement considerations 424
numeric items 336 breaking apart 445
SET statement 489 concatenating 441
data description general description 314
arithmetic statement operands 422 general format 296
data description entry joining together 441
Boolean data 94 MOVE statement considerations 436
general description 314 subject of OCCURS clause 477
general formats 314 SUBTRACT statement considerations 428
data description specifications (DDS) 575 data manipulation statements
and externally described files 211 INSPECT statement 429
and FORMATFILE files 231 MOVE statement 436
and multiple device files 112 STRING statement 441
and program described files 229 UNSTRING statement 445
example for field reference file 215 data organization, description 279
example for keyed access path 241 data receiving fields (UNSTRING) 446
example for record format 217 data record size specification 306
use of keywords 214 data records
Data Division 5, 30, 125 in file on another system 278
concepts 295 DATA RECORDS clause
creation of entries 530 format 306
Index 599
Declaratives (continued) descending file considerations 246
general format 364 DESCENDING KEY phrase of OCCURS
section requirements when used 347 clause 478
DECLARATIVES keyword descriptions
begins Declaratives 347 COBOL 1
begins in Area A 25, 26, 28 System/38 COBOL 1
decrementing index-name values 490 DEV parameter, Override command 527
decrementing operands 459 device
default attributes are implicit 19 IBM-defined 19
defined field 56 invited
definitions See invited devices
Boolean literal 8 program
character string 7 See program device
COBOL clause 5 program, accessing information about 530
COBOL entry 5 device dependencies 205
COBOL paragraph 5 device file
COBOL phrase 6 ASSIGN clause and 284
COBOL section 5 multiple 112
COBOL sentence 5 single 112
COBOL statement 5 device independence 206
COBOL word 8 device-dependent area, length of 552
figurative constants 11 devices, APPC 135
keywords 10 diagnostic levels 541
literal 7 diagnostic messages 541
numeric literal 8 listing 57
separator 13 severity levels 57
special character words 11 suppressing 1
special registers 10 direct and relative index usage 486
DELETE statement (input/output) 382 direct indexing, 474
access considerations 382 disk device type 543
device considerations 382 DISK files
format 382 considerations 236
organization considerations 382 processing methods 236
with duplicate keys 384 displacement 53
DELIMITED BY ALL phrase (UNSTRING) 446 display device file 122
DELIMITED BY phrase data description specifications for 90
and STRING statement processing 442 example program 112
delimiter record format 90
for Boolean literal 126 subfiles 106
for pseudo-text 13 display file 107
in INSPECT statement 434 display file support 90
in STRING statement 441 DISPLAY phrase of USAGE clause 322
in UNSTRING statement 445 display screen formats
DEPENDING ON phrase of GO TO COBOL coding form and 22
statement 454 DISPLAY statement
DEPENDING ON phrase of OCCURS format 385
clause 477 mnemonic-name and 273
format 477 display, split-end 48
DESCEND, DDS keyword 527 displaying variables, techniques 67
Index 601
equal sign (=) examples (continued)
punctuation character 6 DDS for a record format with Alias
relation character 6 keyword 218
rules for using 13 DDS for field reference file 215
separator, rules for using 13 DDS for subfiles 109
use 6 diagnostic messages listing 57
EQUAL TO relational operator Environment Division coding 270
in WHEN phrase of SEARCH ALL 484 error recovery 257
error conditions FIPS messages listing 55
REWRITE statement considerations 405 fixed insertion editing 340
error correction, automatic 370 floating insertion editing 341
error messages 542 FORMATFILE file 231
errors generic START using a program described
interrelational 22 file 237
loop 256 generic START using an externally described
escape message CBL9001 38 file 237
evaluation results 361 Identification Division coding 268
example programs indicators 96
See also examples initialize a table to zero 476
commitment control 250 INSPECT statement 433, 435
error recovery procedure 257 inter-program communication 514
FORMATFILE file creation 231 mixed files 113
indexed file creation 190 multiple display files 113
indexed file updating 192 PERFORM statement 459, 462, 466
mixed file creation 113 Procedure Division 352
multiple display file creation 113 Procedure Division coding 349
relative file creation 197 record description concepts 311
relative file retrieval 201 record format specifications 215
relative file updating 199 REDEFINES clause 319
sequential file creation 185 RENAMES clause 345
sequential file updating and extension 188 ROLLING phrase 141
TRANSACTION file processing 131 SEARCH statement 486
TRANSACTION program 146 simple insertion editing 338
work station support 145 source listing 50
examples SPECIAL-NAMES paragraph 272
See also example programs STRING statement 443
access path for indexed file 241 subscripting 472
breakpoint 63 trace 72
COBOL formatted dump 74 UNSTRING statement 450
COBOL program skeleton coding 27 verb usage by count listing 52
commitment control 247 work station application programs 145
compiler options listing 49, 50 zero suppression and replacement editing 342
COPY DDS results 218, 224 exception monitoring, MONMSG command 38
COPY statement 34 EXCEPTION/ERROR Declarative
cross reference listing 56 EXTEND phrase 365
Data Division 302 file-name phrase 365
Data Division coding 297 format 365
Data Division map 52 I-O phrase 365
DDS for a display device file 90 status key 370
DDS for a record format 217
Index 603
File Description (FD) entry File-Control entry (continued)
See FD (File Description) entry sort/merge considerations 492
file feedback TRANSACTION file processing entry 122
See OPEN-FEEDBACK mnemonic-name FILE-CONTROL paragraph
file label specification 305 formats 281
file locking function of 284
Allocate Object command 209 file-name
COBOL 209 CLOSE statement operand 377
lock states 209 DELETE statement operand 382
shared files 209 formation rules 9
file processing in FD entry 303
access paths 244 OPEN statement specification 390
associated card 533 READ statement considerations 395
DATABASE 236 SD entry operand 493
DISK 236 SELECT clause operand 284
example programs 185 formats 282
feedback information 376 SORT statement operand 495
FORMATFILE 229 sort/merge file operand 492
indexed organization 236 START statement specification 408
initiating 389 file-names 53
methods 244 file(s) 295
PRINTER 229 auxiliary storage 543
relative organization 242 BSC
sequential organization 243 data organization for 530
specific 229 support 90
summary 279 communications 90, 530
file QCBLSRC, record length 21 data communications 90, 122
file recovery DATABASE versus DISK 236
after a failure 257 device 284
file recovery 257 externally described
with commitment control 257 OS/400 37
File Section specifications 216
general description 298 FORMATFILE 231
general formats 299 indexed 236
VALUE clause considerations 329 input 371, 497
FILE STATUS clause 124, 291 logical 278
CLOSE statement 378 mixed, data organization for 530
DELETE statement 382 multiple device 112
formats 282 organization 244
INVALID KEY condition 370 output 293
READ statement 398 physical 278
REWRITE statement 403 printer, externally described 527
START statement 408 program described 211, 229
file status information QCBLMSG 542
obtaining 74 relative 242
related exceptions 548 sequential 243
values 548 single device 112
file structure support summary 543 source, maximum record length 21
File-Control entry TRANSACTION 89
file processing entries 281
Index 605
group level names 222 IF statement
group moves 439 format 367
nested 368
imperative-statement 349
H categories of 349
header
implicit attribute 19
division 27
implicit control transfers 19
paragraph 28
implicit references 19
section 27
Procedure Division 19
hexadecimal digit bit configurations 325
IN as qualifier connective 15
hierarchy
incrementing index-name values 490
levels of 17
incrementing operands
HIGH-VALUE(S) 11
PERFORM VARYING rules 459
hyphen (-)
indentation, rules 28
allowed in user-defined word 9
indentation, to clarify logic 28
in continuation area, meaning 29
independent clause 125
in program-name, conversion of 268
independent segment 503
produced when copying Alias names 220
calling and called programs 507
index 473
I qualifier connective 10
I-O files INDEX usage 479
EXCEPTION/ERROR Declarative 365 index-name 474
I-O option of OPEN statement 390 and File Section 480
indexed file considerations 389 assigning values 488
relative file considerations 389 comparison rules 480
TRANSACTION file considerations 129 in PERFORM statement 459
I-O-CONTROL paragraph passing values of, in CALL 509
formats 292 rules of formation 9, 479
order of clauses optional 292 SET statement operand 488
sort/merge considerations 493 values 488
I-O-FEEDBACK mnemonic-name 552 INDEXED BY phrase
and ACCEPT statement 376 OCCURS clause 476
extended file status 124 formats 476
IBM extensions xviii, 527 SEARCH statement requirements 482
IBM-defined device 19 indexed data item 480
IBM-defined switch 19 comparison rules 481
Identification Division indexed file 236
format 267 File-Control entry 287
function of 5 format 281
punctuation in 30 INDEXED I-O module, 1974 Standard 2
identifier 348 indexed organization 279
ACCEPT statement operand 373 indexes
breaking apart 445 assigning values 488
DISPLAY statement operand 385 conditional variable 330
general format 18 indexing 473
in sign test 359 INDEXED BY phrase rules 479
INSPECT statement operand 429 of data-name 528
replacing characters in 430 subscripting 18
INDICATOR clause 95
Index 607
internal decimal item KEY phrase
See packed decimal item of OCCURS clause 478
internal name 53 of START statement 408
internal representation key sequence
operational sign 314 ascending 418, 491
interrelational errors 22 descending 418, 478, 491
interrelationships between program lines 37 keys
INTO identifier phrase of READ statement 398 common 228
INTO phrase of RETURN statement 501 record 228
INTO/FROM identifier phrase 371 keyword
INVALID KEY condition DECLARATIVES 28
actions taken 371 END DECLARATIVES 28
EXCEPTION/ERROR Declarative and 366 keywords
statements that recognize 371 representation in manuals 10
INVALID KEY phrase 137, 139
DELETE statement and 382
START statement considerations 407
L
label processing
status key 370
OPEN statement 392
WRITE statement 412
READ statement 400
invited devices
WRITE statement 419
definition 133
LABEL RECORDS clause
item, attributes of the 53
format 305
required entry 305
J label specification 305
Job (JOB) CL command 75 language concepts, inter-program
job’s local data area, transfer to 529 communication 507
JOB, CL command 75 language extension
jobs TRANSACTION file 89
batch 37 language level
interactive 37 of Communication module 2
joining data items together 441 of Debug module 2
JUSTIFIED clause 327 of Indexed I-O module 2
example of results 328 of Inter-program Communication module 2
format 327 of Library module 2
VALUE clause considerations 330 of Nucleus module 2
of Report Writer module 2
of Segmentation module 2
K of Sequential I-O module 2
key
of Sort-Merge module 2
status 370
of Table Handling module 2
key fields
supported by System/38-Compatible
common keys and 228
COBOL 1
defined by DDS 228
language structure, description 1
descending keys 246
language-name
for indexed files 236
as system-name 9
in the record area 383
in ENTER statement 468
partial keys 237
LAST phrase, READ statement 396
RECORD KEY clause 228
left parenthesis
record keys and 228
punctuation character 6
separator, rules for using 13
Index 609
local data area (continued) maximum number (continued)
LOCAL-DATA mnemonic-name 273 Sort/Merge keys 496
LOCK phrase maximum record length of source files 21
CLOSE statement 378 maximum size of nonnumeric literal 7
locking by COBOL, file 209 maximum value
locking by COBOL, record 209 of an index 474
locking, file and record 209 subscript 472
logic of segmentation 504 meaning of characters in COBOL 6
logical connective 359 period (.) 6
meaning and use 359 menu, application-oriented 59
logical connectives, definition of 10 merge
logical file 278 concepts 492
considerations 240 MERGE statement
logical operators 34 format 494
logical page positioning phrases 495
LINAGE-COUNTER and 308 segmentation considerations 506
logical page size sort/merge OUTPUT PROCEDURE 499
LINAGE clause specifies 306 merged records 495
logical record 295 message number, FIPS 55
BLOCK CONTAINS CHARACTER, clause message reply modes 75
and 304 message statistics 58
level concepts 310 message, escape, CBL9001 38
size specification 304 messages
loop errors 256 compile-time 541
exceptions 256 compiler 49
refid-inter.considerations 262 modifying 542
loop, tracing a 255 numbers 542
loops in a program 255 severity codes 541
LOW VALUE(S) 11 diagnostic, suppressing 1
LOW-VALUE/LOW-VALUES figurative FIPS 49, 55
constant 11 interactive 541
level of diagnostic 49
methods of data reference 15
M methods of referencing procedures 15
manual
MFCU (Multi-Function Card Unit) 533
purpose xvii
5424 533
margins of pages in LINAGE clause 307
minimum size
maximum length
numeric item 336
data description entry 314
minimum value
numeric literal 8
index 474
of table 477
subscript 472
PICTURE character-string 332
minus sign (-)
Sort/Merge keys 496
arithmetic operator 7
table element 478
editing character 7
VALUE clause initialization 330
floating insertion symbol 340
maximum number
in numeric literal 8
characters in numeric item 336
sign 7
delimiters in UNSTRING statement 445
sign control symbol 339
digits in numeric item 336
use 7
GO TO statement procedure-names 454
lines on printed page 306
Index 611
OPEN-FEEDBACK mnemonic-name 552
O and ACCEPT statement 376
Object Definition Table (ODT) 38
operand length
object naming rules 38
arithmetic 14
object of OCCURS DEPENDING ON clause 477
logical 14
object program 267
relational comparisons 357
and table values 475
operands
processing suspension (STOP) 467
overlapping 421
object time
operation
See run-time
read-from-invited-program-devices 133
OBJECT-COMPUTER paragraph 271
read-from-one-program-device 133
format 271
operation order for arithmetic expressions 353
PROGRAM COLLATING SEQUENCE clause
operational sign 314
relation conditions 272
in an elementary MOVE statement 438
SPECIAL-NAMES paragraph and 272
in class test 355
syntax checker restriction 24
in numeric item 336
occurrence number
S PICTURE symbol specifies 333
index-name 481
SIGN clause 326
subscript identifiers 472
operator
OCCURS clause 94
arithmetic 34
ASCENDING/DESCENDING KEY phrase 478
logical 34
DEPENDING ON phrase 477
relational 357
fixed-length tables 477
unary 353
formats 476
operator response
INDEXED BY phrase 479
ACCEPT statement 373
variable-length tables 477
STOP statement 467
ODT 38
option
OF qualifier connective 10
*NORANGE 255
omission of optional words 10
NOUNREF 38
OMITTED phrase of LABEL RECORDS 305
option indicators 92
ON OVERFLOW phrase
OPTION parameter 37
and STRING statement processing 442
OPTIONAL phrase of SELECT clause 284
and UNSTRING processing 448
format 282
CALL statement 510
optional words
one operand, varying 459
omission of 10
open file, data transfer 74
representation in manuals 10
OPEN INPUT statement
options
indexed file considerations 390
compile-time 46
relative file considerations 390
PROCESS statement 47
OPEN OUTPUT statement
OR condition, multiple UNSTRING 446
LINAGE clause 307
OR logical connective 10
OPEN statement 129, 389
OR NOT logical connective 10
access considerations 390
order of clauses
CLOSE statement 377
I-O-CONTROL paragraph 292
device considerations 390
order of paragraphs, Identification Division 268
for TRANSACTION file 129
order of symbols in PICTURE clause 335
formats 389
ordering records using sort/merge 491
initializes LINAGE-COUNTER 308
ORGANIZATION clause 123
organization considerations 390
default is SEQUENTIAL 286
sets current record pointer 371
formats 282
Index 613
period (.) (continued) PICTURE clause (continued)
in Configuration Section 270 floating insertion editing 340
in data description entry 317, 318 format 332
in File-Control entry 284 simple insertion editing 338
in I-O-CONTROL paragraph 292 special insertion editing 339
punctuation character 6 symbol order 335
separator, rules for using 13 symbols used 332
permanent segment, definition 503 VALUE clause considerations 329
permanent segments zero suppression and replacement 342
ALTER statement 453 plus sign (+)
permissible comparisons arithmetic operator 6
relation-condition 356 editing character 6
PGR in numeric literal 8
See graphics support sign 6
phrase 6 SIGN clause 326
ADVANCING 230 POINTER phrase
AT END 135, 138 and STRING statement processing 442
FORMAT 130, 135, 137 and UNSTRING processing 448
INDICATORS 95, 130 positive data, and sign control symbols 340
INVALID KEY 137, 139 positive numeric data
modifier of clause or statement 6 SIGN clause 326
NEXT MODIFIED 136 unsigned 314
NO DATA 135 prerequisite publication xvii
REPLACING 32 Presentation Graphics Routines
ROLLING 141 See graphics support
STARTING 141 primary keys, duplicate allowed 529
SUBFILE 131 printer file, externally described 527
TERMINAL 131, 135, 137, 139, 140, 144 printing, preparation of data 534
phrases 6 PRIOR phrase, READ statement 396
clause 6 problem determination 86
qualifying 15 procedure 347
statements 6 Declarative 364
physical file 278 EXCEPTION/ERROR 365
physical page size for debugging 521
logical page size 306 general format 364
physical record procedure branching statement 20
definition 295 ALTER statement 452
physical record size GO TO statement 454
BLOCK CONTAINS clause 303 in IF statement 367
specifications 303 PERFORM statement 455
picture character strings 12 STOP statement 467
PICTURE character-string Procedure Division 126, 347
DECIMAL-POINT IS COMMA clause 277 arithmetic expressions 352
item size 314 arithmetic statements 420
PICTURE clause 94 conditional expressions 354
character-string representation 334 conditional statements 367
data categories 336 data manipulation statements 429
editing 338 data references 19
editing sign function 314 Declaratives 364
fixed insertion editing 339 example 349
Index 615
program exception/errors 88 qualification (continued)
program exceptions, monitoring for 60 rules 17
program lines, interrelationships between 37 qualification of data-name 528
program loops 255 qualifier connective 10
program running 62 qualifier, definition 15
program segments 503 qualifying data-names 16
fixed qualifying phrases 15
permanent 503 quotation mark (')
independent 503 placement rules for 29
program spacing 28 punctuation character 7
program stopping points 88 rules for using 13
program switch specified in PROCESS statement 47
ALTER statement 453 QUOTE(S) 11
program syntax, debugging line 524 quotient, in division 425
program termination 60
program testing 62
program-id name 50
R
random access 280
PROGRAM-ID paragraph 268
DELETE statement 382
format 268
indexed files 288
program-name 268
of subfile records 136
formation rules 9
READ statement 393
program, using same in several jobs 63
relative files 288
programs
WRITE statement 414
coding and entering 21
read from invited program devices
debugging 60
controlled job termination 133
multiple 47
invited program device errors 133
pseudo-text
name of program device read
replacement rules 32
See CONTROL-AREA clause
pseudo-text delimiter
no data available
(==) separator, rules for using 13
See NO DATA phrase
placement rules for 13
no program devices invited
publication, prerequisite xvii
See AT END phrase
publications, list of related xvii
operation 133
punctuation character
record format name read
defined as separator 13
See CONTROL-AREA clause
enclose nonnumeric literal 8
time out on wait for data 134
with nonnumeric literal 8
READ statement
punctuation in nonnumeric literal 8
access considerations 396
punctuation rules 30
device considerations 396
punctuation, as separators 13
for TRANSACTION file 131
purpose of manual xvii
formats 393
INTO identifier phrase 371
Q organization considerations 396
QCBLMSG message file 542 sets current record pointer 371
QCBLSRC file, record length 21 read-from-one-program-device operation 133
qualification 15 receiving field
CORRESPONDING phrase rules 422 alignment rules and 313
explicit 15 in group MOVE statement 439
implicit 15 in STRING statement 442
of UPSI condition-names 274 in UNSTRING statement 447
Index 617
release program device restrictions of condition-names 19
See DROP statement restrictions on indexing 18
RELEASE statement restrictions on subscripting 18
format 500 retrieving compiler options 48
releasing a record read for update 210 retrieving/saving source entries 30
REMAINDER phrase of DIVIDE statement return of control from called program 262
format 426 RETURN statement for sort/merge 501
processing rules 426 format 501
RENAMES clause sets current record pointer 371
data-name-2 phrase 343 REVERSED phrase of OPEN statement 390
data-name-2 THRU data-name-3 phrase 343 REWRITE statement 138, 402
format 343 access considerations 403
general format 315 device considerations 403
level-66 item 312 for TRANSACTION file 138
specification examples 345 format 402
repetitive processing of PERFORM FROM identifier phrase and 371
statement 458 organization considerations 403
replacement editing 342 right parenthesis
replacement of file records 402 punctuation character 7
replacement rules for library-text 31 rules for using 13
REPLACING phrase right-padding of items 313
of COPY statement 33 ROLLBACK statement 406
of INSPECT statement 433 format 406
processing 33 sets current record pointer 371
REPLACING, with format 2 COPY 226 ROLLING phrase 141
reply list, system 75 ROUNDED phrase 423
reply modes, message 75 ADD statement 423
Report Writer module 2 COMPUTE statement 423
reporting COBOL problems 88 DIVIDE statement 423
representation MULTIPLY statement 423
of keywords in manuals 10 processing rules 423
of optional words in manuals 10 routine-name
of reserved words in manuals 10 formation rules 9
of user-defined words in manuals 9 in ENTER statement 468
RERUN clause 292 SUBTRACT statement 423
formats 292 RSMBKP, CL commands 63
RESERVE clause 282 rules
reserved word overall punctuation 30
in COBOL 9 PROCESS statement 47
list 563 punctuation 30
printed in capital letters 14 rules for forming user-defined words 9
representation in manuals 10 rules for qualification 17
types 10 rules for using separators 13
connectives 10 run status, status key usage 291
figurative constants 10 run unit
key 10 CALL statement transfer control 508
optional 10 run-time
special registers 10 debugging switch 518
special-character 10 run-time switches, debug 74
use of 10
Index 619
sequential file (continued) single device files 112
EXCEPTION/ERROR Declarative phrases 365 SIZE ERROR phrase 423
FILE-CONTROL Paragraph 281 COMPUTE statement 423
format 281 DIVIDE statement 423
OPEN statement considerations 389 MULTIPLY statement 423
organization 279 SUBTRACT statement 423
READ statement and 396 size of DEBUG-CONTENTS 523
REWRITE statement 403 size of operands in nonnumeric comparisons 358
SEQUENTIAL I-O module, 1974 Standard 2 SIZE, STRING statement delimiter 441
series connective, definition of 10 slash (/)
SET statement comment line 29
and conditional variables 440 source code with 23
and external switches 440 SORT statement
and multidimensional table search 486 format 495
formats 440, 488 phrases 496
initializes index 474 segmentation considerations 506
TO phrase 488 sort/merge OUTPUT procedure 500
UP/DOWN BY phrase 490 SORT-MERGE module, 1974 Standard 2
valid field combinations 489 Sort/Merge
SEU concepts 491
See Source Entry Utility (SEU) considerations 501
severity level, changing 542 Data Division–SD entry 493
severity levels, message 541 Environment Division 492
severity of messages 542 File Description (SD) entry 493
severity-level field 57 FILE-CONTROL paragraph required for 284
sharing storage format 493
file records 292 File-Control entry 491
SI attribute 93, 286 I-O-Control entry 493
sign or AS/400 logical file support 491
currency 340 Procedure Division
in a numeric literal 8 MERGE statement 494
operational 314, 326, 333, 336, 355, 438 RELEASE statement 500
SIGN clause 326 RETURN statement 501
format 326 SORT statement 495
minus (-) 7 SORT/MERGE statement phrases 496
operational sign representation 314 source code
plus (+) 6 with asterisk 23
S PICTURE symbol 333 with slash 23
sign condition Source Entry Utility (SEU) 575
format 359 browsing a compiler listing 48
sign control, fixed insertion editing 340 entering a source program 22
SIGN IS SEPARATE CHARACTER clause source files 21
description and format 326 source language debugging
signed decimal items, conversion to 529 compile-time switch 518
signed numeric item DEBUG-ITEM special register 523
SIGN clause specification 326 debugging lines 524
simple condition run-time switch 518
negation of 360 USE FOR DEBUGGING procedures 521
simple insertion editing 338 source listing 50
Index 621
START statement (continued) STOP RUN statement
device considerations 408 description and format 467
format 407 inter-program communication 262
generic 237 STOP statement 467
INVALID KEY phrases 409 ALL literal figurative constant restrictions 11
organization considerations 408 format 467
relative key 289 stopping points 88
sets current record pointer 372 storage
starting line number auxiliary 543
duplicate record keys, DUPLICATES storage allocation, calling and called
phrase 289 programs 509
formula 141 storage format, USAGE clause specifies 322
WRITE statement, for TRANSACTION file 140 storage layout of table, example 470
STARTING phrase 141 storage of records
statement 5, 347 illustrated 312
ACCEPT 126 REDEFINES clause and 319
ACQUIRE 127 storage required 38
categories 349 STRING statement 5, 441
CLOSE 128 ALL literal figurative constant restriction 11
COBOL, CALL 59 examples 443
conditional 349, 368 format 441
copy 30 literals 7
DROP 129 nonnumeric literals 7
generic START 237 strings of characters 6
imperative 349 STRSEU, CL command 21
OPEN 129 structures
procedure branching 20 data field 222
PROCESS 37, 46 format (record) level 221
READ 131 indicator 222, 223
REWRITE 138 subfield contents of DEBUG-ITEM special
USE 145 register 524
WRITE 140 subfile
statement number 53, 57 access 107, 132
compiler-generated 50 special register DB-FORMAT-NAME 108
statement-to-statment transfers 20 specified in DDS 106
statements use of 108
consecutive 20 valid operations 107
phrase 5 SUBFILE phrase 131
Procedure Division 5 subfile records
rules for use 5 random access of 136
sentence 5 sequential access of 136
statements and clauses, summary of 567 subject
static values of a table 475 of abbreviated combined
statistics, compilation 49 relation-condition 363
status key values 548 of OCCURS clause, definition 476
STATUS KEY, file processing of relation condition 356
OPEN statement 393 Submit Job (SBMJOB) CL command 75
use 370 subordinate entries 16
WRITE statement 414 subprograms 47
Index 623
SYSTEM/38 library name TERMINAL phrase 131, 135, 137, 139, 140, 144
and Library-name 31 with READ (nonsubfile), description 139
in COPY statement 31 with READ statement, formats 131
System/38-Compatible COBOL with READ SUBFILE, description 137
compiler, calling 37 with REWRITE statement, format 138
features of 1 with WRITE (nonsubfile), description 140
Language level supported by 1 with WRITE statement (nonsubfile),
programming considerations 205 format 140
with WRITE SUBFILE, format 144
termination of processing
T EXIT PROGRAM statement 513
table
STOP RUN statement 467
definition 469
termination, program 60
length 477
test library 61
table element
testing a program 62
definition 469
testing function, OS/400 60
length 477
text-name
table handling
COPY statement operand 30
Data Division 476
formation rules 9
OCCURS clause 476
qualification format 16
Procedure Division 480
THEN phrase
reinitializing index-names 488
format 367
relation conditions 481
used as separator 367
SEARCH statement 481
TIME, ACCEPT statement 373
SET statement 488
TIMES phrase of PERFORM statement 458
table definition 469
TO phrase, SET statement 488
table initialization 475
top page margin in LINAGE clause 307
table references 471
traces 63, 71
UP/DOWN BY phrase 490
considerations 73
USAGE IS INDEX clause 480
example 72
table handling concepts
tracing a loop 255
table definition 486
TRAILING phrase of SIGN clause 326
table initialization 475
TRANSACTION files
table references
Boolean data facilities 126
indexing 473
considerations for 530
subscripting 472
data description specifications for 90
Table Handling module, 1974 Standard 2
Data Division considerations 125
table layout, example 470
Environment Division considerations 122
table of valid and invalid moves 439
example programs 145
table references
externally described 90
and SEARCH ALL results 484
language extensions for 89
indexing 473
Procedure Division considerations 126
subscripting 472
processing externally described 92
table values, defining 475
program described 122
TALLYING phrase
TRANSACTION organization 123
INSPECT statement 433
transfer of control
UNSTRING statement 446
ALTER statement change 453
tape rewinding/unloading 529
and sort/merge OUTPUT PROCEDURE 499
techniques, displaying variables 67
explicit and implicit 20
sort INPUT PROCEDURE 498
Index 625
valid characters in COBOL WRITE ADVANCING statement 416
ascending EBCDIC sequence 6 LINAGE clause and 308
valid characters in CURRENCY SIGN WRITE statement 412
clause 277 access considerations 414
valid COBOL characters, IBM extension 6 ADVANCING phrase 415
valid processing sequence, PERFORM device considerations 414
statement 457 END-OF-PAGE phrase 415
valid RECORD KEYS 237 for TRANSACTION file 140
validity checking 90 format 412
validity checking, automatic 370 FROM identifier phrase 371
VALUE clause 95 INVALID KEY phrase 415
example of condition-name entries 331 mnemonic-names and 273
format 328 modifies LINAGE-COUNTER 308
VALUE OF clause 306 organization considerations 414
value, of numeric literal 8 ROLLING phrase 141
variable length table 477 STARTING phrase 141
format 477
variable, conditional 317, 330, 355
variables, techniques for displaying 67
Z
ZERO
varying operands in PERFORM statement 459
as Boolean literal 12
VARYING phrase
as figurative constant 11
PERFORM statement 459
zero (0)
SEARCH statement 481
as unique value 314
verb usage by count listing 52
insertion symbol 333
verb usage listing 49
zero filling
verbs
INSPECT statement 436
as keyword 10
zero suppression and replacement editing 342
lists 351
ZERO, ZEROES, ZEROS figurative constant 11
violation 280, 414
used as Boolean literal 126
violations flagged, FIPS 55
ZERO(S)(ES) 11
zoned decimal item 323
W RECORD KEY data item 290
WHEN phrase of SEARCH ALL statement 483 zoned decimal items, conversion to 529
WITH FOOTING phrase of LINAGE clause 307
WITH NO REWIND phrase of CLOSE 379
word 15
in COBOL 8
key 14
optional 10
reserved 14
user-defined 9
words, reserved 563
work station 145
work station support 89
See also TRANSACTION files
Working-Storage Section
general description 299
general format 296
level-77 and level-01 names unique 312
VALUE clause considerations 329
Printed in U.S.A.
SC9-1814-