COBOL Programming Guide
COBOL Programming Guide
Programming Guide
Version 2 Release 2
SC26-9049-05
COBOL for OS/390 & VM
Programming Guide
Version 2 Release 2
SC26-9049-05
Note!
Before using this information and the product it supports, be sure to read the general information under “Notices” on
page 609.
iv Programming Guide
Example: password protection for a VSAM Sort special registers . . . . . . . . . . 184
indexed file . . . . . . . . . . . . . 152 Changing DFSORT defaults with control
Working with VSAM data sets under OS/390 and statements . . . . . . . . . . . . . 185
OS/390 UNIX . . . . . . . . . . . . . 152 Allocating storage for sort or merge operations 186
Defining VSAM files under OS/390 . . . . . 153 Using checkpoint/restart with DFSORT under
Creating alternate indexes . . . . . . . . 154 OS/390 . . . . . . . . . . . . . . . 186
Allocating VSAM files . . . . . . . . . 156 Sorting under CICS . . . . . . . . . . . 187
Sharing VSAM files through RLS . . . . . . 157 CICS SORT application restrictions . . . . . 187
Defining VSAM data sets under CMS . . . . . 158
Improving VSAM performance . . . . . . . 159 Chapter 12. Handling errors . . . . . 189
Requesting dumps . . . . . . . . . . . 189
Chapter 10. Processing line-sequential Creating a formatted dump. . . . . . . . 189
files . . . . . . . . . . . . . . . 163 Creating a system dump . . . . . . . . 190
Defining line-sequential files and records in Handling errors in joining and splitting strings . . 190
COBOL . . . . . . . . . . . . . . . 163 Handling errors in arithmetic operations . . . . 191
Allowable control characters . . . . . . . 164 Example: checking for division by zero . . . . 191
Describing the structure of a line-sequential file 164 Handling errors in input and output operations 191
Defining and allocating line-sequential files . . . 165 Using the end-of-file condition (AT END) . . . 193
Coding input-output statements for line-sequential Coding ERROR declaratives . . . . . . . 194
files . . . . . . . . . . . . . . . . 165 Using file status keys . . . . . . . . . . 194
Opening line-sequential files . . . . . . . 166 Example: file status key . . . . . . . . . 195
Reading records from line-sequential files . . . 166 Using VSAM return codes (VSAM files only) 196
Adding records to line-sequential files . . . . 167 Example: checking VSAM status codes . . . . 196
Closing line-sequential files. . . . . . . . 167 Coding INVALID KEY phrases . . . . . . 198
Handling errors in line-sequential files . . . . . 168 Example: FILE STATUS and INVALID KEY . . 198
Handling errors when calling programs . . . . 199
Chapter 11. Sorting and merging files 169 Writing routines for handling errors . . . . . . 199
Sort and merge process . . . . . . . . . . 170
Describing the sort or merge file . . . . . . . 170 Part 2. Compiling and debugging
Describing the input to sorting or merging . . . 171 your program . . . . . . . . . . 201
Example: describing sort and input files for
SORT . . . . . . . . . . . . . . . 171
Coding the input procedure . . . . . . . . 172
Chapter 13. Compiling under OS/390 203
Describing the output from sorting or merging . . 173 Compiling with JCL . . . . . . . . . . . 203
Coding the output procedure . . . . . . . . 173 Using a cataloged procedure . . . . . . . 204
Coding considerations when using DFSORT on Writing JCL to compile programs. . . . . . 213
OS/390 . . . . . . . . . . . . . . 174 Compiling under TSO . . . . . . . . . . 215
Example: coding the output procedure when Example: ALLOCATE and CALL for compiling
using DFSORT . . . . . . . . . . . . 174 under TSO . . . . . . . . . . . . . 215
Restrictions on input and output procedures . . . 175 Example: CLIST for compiling under TSO . . . 216
Defining sort and merge data sets under OS/390 175 Starting the compiler from an assembler program 216
Defining sort and merge files under CMS . . . . 176 Defining compiler input and output . . . . . . 218
Sorting variable-length records . . . . . . . 176 Data sets used by the compiler under OS/390 218
Requesting the sort or merge . . . . . . . . 177 Defining the source code data set (SYSIN) . . . 220
Setting sort or merge criteria . . . . . . . 177 Specifying source libraries (SYSLIB) . . . . . 220
Example: sorting with input and output Defining the output data set (SYSPRINT) . . . 221
procedures . . . . . . . . . . . . . 178 Directing compiler messages to your terminal
Choosing alternate collating sequences . . . . 179 (SYSTERM) . . . . . . . . . . . . . 221
Sorting on windowed date fields . . . . . . 179 Creating object code (SYSLIN or SYSPUNCH) 221
Preserving the original sequence of records with Creating an associated data file (SYSADATA) 222
equal keys . . . . . . . . . . . . . 180 Defining the output IDL data set (SYSIDL) . . 222
Determining whether the sort or merge was Defining the debug data set (SYSDEBUG) . . . 222
successful . . . . . . . . . . . . . . 180 Specifying compiler options under OS/390 . . . 223
Stopping a sort or merge operation prematurely 181 Specifying compiler options with the PROCESS
Improving sort performance with FASTSRT . . . 181 (CBL) statement . . . . . . . . . . . 223
FASTSRT requirements for JCL (OS/390 only) 181 Example: specifying compiler options using JCL 224
FASTSRT requirements for sort input and Example: specifying compiler options under
output files . . . . . . . . . . . . . 181 TSO . . . . . . . . . . . . . . . 224
Checking for sort errors with NOFASTSRT . . . 183 Compiler options and compiler output under
Controlling sort behavior . . . . . . . . . 184 OS/390 . . . . . . . . . . . . . . 224
Compiling multiple programs (batch compilation) 226
Contents v
Example: batch compilation . . . . . . . 226 External data . . . . . . . . . . . . 267
Specifying compiler options in a batch QSAM input/output buffers . . . . . . . 267
compilation . . . . . . . . . . . . . 227 DATEPROC . . . . . . . . . . . . . . 267
Example: precedence of options in a batch DBCS . . . . . . . . . . . . . . . . 269
compilation . . . . . . . . . . . . . 228 DECK . . . . . . . . . . . . . . . . 269
Example: LANGUAGE option in a batch DIAGTRUNC . . . . . . . . . . . . . 269
compilation . . . . . . . . . . . . . 229 DISK/PRINT . . . . . . . . . . . . . 270
Correcting errors in your source program . . . . 230 DLL . . . . . . . . . . . . . . . . 270
Generating a list of compiler error messages . . 230 DUMP . . . . . . . . . . . . . . . 271
Messages and listings for compiler-detected DYNAM . . . . . . . . . . . . . . . 272
errors . . . . . . . . . . . . . . . 231 EXIT . . . . . . . . . . . . . . . . 272
Format of compiler error messages . . . . . 231 EXPORTALL . . . . . . . . . . . . . 272
Severity codes for compiler error messages . . 232 FASTSRT . . . . . . . . . . . . . . . 273
FLAG . . . . . . . . . . . . . . . . 274
Chapter 14. Compiling under OS/390 FLAGMIG . . . . . . . . . . . . . . 275
UNIX . . . . . . . . . . . . . . . 235 FLAGSTD . . . . . . . . . . . . . . 275
IDLGEN . . . . . . . . . . . . . . . 277
Setting environment variables under OS/390 UNIX 235
INTDATE . . . . . . . . . . . . . . 278
Specifying compiler options under OS/390 UNIX 236
LANGUAGE . . . . . . . . . . . . . 279
Compiling and linking with the cob2 command 237
LIB . . . . . . . . . . . . . . . . . 280
Defining input and output . . . . . . . . 237
LINECOUNT . . . . . . . . . . . . . 280
Creating a DLL . . . . . . . . . . . . 238
LIST . . . . . . . . . . . . . . . . 281
Example: using cob2 to compile under OS/390
MAP . . . . . . . . . . . . . . . . 281
UNIX . . . . . . . . . . . . . . . 238
NAME . . . . . . . . . . . . . . . 282
cob2 . . . . . . . . . . . . . . . 239
NUMBER . . . . . . . . . . . . . . 283
cob2 input and output files . . . . . . . . 240
NUMPROC . . . . . . . . . . . . . . 283
Compiling using scripts . . . . . . . . . . 241
OBJECT . . . . . . . . . . . . . . . 284
OFFSET . . . . . . . . . . . . . . . 285
Chapter 15. Compiling under CMS 243 OPTIMIZE . . . . . . . . . . . . . . 285
Accessing the compiler (CP LINK and ACCESS) 243 Unused data items: . . . . . . . . . . 286
Specifying a source program to compile . . . . 244 OUTDD . . . . . . . . . . . . . . . 286
COBOL2 . . . . . . . . . . . . . . 244 PGMNAME . . . . . . . . . . . . . . 287
Using compiler-directing statements . . . . . . 245 PGMNAME(COMPAT) . . . . . . . . . 287
Specifying compiler options under CMS . . . . 246 PGMNAME(LONGUPPER). . . . . . . . 288
Using parentheses in COBOL2 . . . . . . 246 PGMNAME(LONGMIXED) . . . . . . . 288
Abbreviating compiler options . . . . . . 246 PGMNAME usage notes. . . . . . . . . 288
Using logical line-editing characters . . . . . 247 QUOTE/APOST . . . . . . . . . . . . 289
Additional compiler options under CMS . . . 247 RENT . . . . . . . . . . . . . . . . 289
Differences in compiler options under CMS . . 248 RMODE . . . . . . . . . . . . . . . 290
Precedence of compiler options under CMS . . 248 SEQUENCE . . . . . . . . . . . . . . 291
Files used by the compiler under CMS . . . . 248 SIZE . . . . . . . . . . . . . . . . 291
Naming generated files under CMS . . . . . . 251 SOURCE . . . . . . . . . . . . . . . 292
Overriding FILEDEF . . . . . . . . . . 251 SPACE . . . . . . . . . . . . . . . 293
Using system-generated names . . . . . . 251 SQL . . . . . . . . . . . . . . . . 293
Correcting errors . . . . . . . . . . . . 252 SSRANGE . . . . . . . . . . . . . . 294
Error messages from COBOL2 . . . . . . . 252 TERMINAL . . . . . . . . . . . . . . 295
TEST . . . . . . . . . . . . . . . . 295
Chapter 16. Compiler options . . . . 257 TRUNC . . . . . . . . . . . . . . . 297
Option settings for COBOL 85 Standard TRUNC example 1 . . . . . . . . . . 298
conformance. . . . . . . . . . . . . . 259 TRUNC example 2 . . . . . . . . . . 299
Conflicting compiler options . . . . . . . . 259 TYPECHK . . . . . . . . . . . . . . 300
ADATA . . . . . . . . . . . . . . . 261 VBREF . . . . . . . . . . . . . . . 301
ANALYZE . . . . . . . . . . . . . . 261 WORD . . . . . . . . . . . . . . . 301
ADV . . . . . . . . . . . . . . . . 262 XREF . . . . . . . . . . . . . . . . 302
ARITH . . . . . . . . . . . . . . . 262 YEARWINDOW . . . . . . . . . . . . 303
AWO . . . . . . . . . . . . . . . . 263 ZWB . . . . . . . . . . . . . . . . 304
BUFSIZE . . . . . . . . . . . . . . . 263 Compiler-directing statements . . . . . . . . 304
CMPR2 . . . . . . . . . . . . . . . 264
COMPILE . . . . . . . . . . . . . . 265 Chapter 17. Debugging . . . . . . . 309
CURRENCY . . . . . . . . . . . . . . 265 Debugging with source language . . . . . . . 310
DATA . . . . . . . . . . . . . . . . 266 Tracing program logic . . . . . . . . . 310
vi Programming Guide
Finding and handling input-output errors . . . 311 DB2 coprocessor . . . . . . . . . . . 358
Validating data . . . . . . . . . . . . 311
Finding uninitialized data . . . . . . . . 311 Chapter 20. Running COBOL
Generating information about procedures . . . 312 programs under IMS . . . . . . . . 359
Debugging using compiler options . . . . . . 313
Compiling and linking COBOL programs for
Finding coding errors . . . . . . . . . 314
running under IMS . . . . . . . . . . . 359
Finding line sequence problems . . . . . . 315
Checking for valid ranges . . . . . . . . 315
Selecting the level of error to be diagnosed . . 316 Chapter 21. Running COBOL
Finding program entity definitions and programs under OS/390 UNIX . . . . 361
references . . . . . . . . . . . . . 317 Running in OS/390 UNIX environments . . . . 361
Listing data items . . . . . . . . . . . 318 Setting and accessing environment variables . . . 362
Getting listings . . . . . . . . . . . . . 319 Setting environment variables that affect
Example: short listing . . . . . . . . . 320 execution . . . . . . . . . . . . . . 362
Example: SOURCE and NUMBER output . . . 323 Resetting environment variables . . . . . . 363
Example: embedded map summary . . . . . 325 Accessing environment variables . . . . . . 363
Terms used in MAP output. . . . . . . . 326 Example: accessing environment variables . . . 363
Symbols used in LIST and MAP output . . . 326 Calling UNIX/POSIX APIs . . . . . . . . . 364
Example: nested program map . . . . . . 328 fork, exec, and spawn . . . . . . . . . 364
Reading LIST output . . . . . . . . . . 328 Samples . . . . . . . . . . . . . . 365
Example: XREF output - data-name Accessing main program parameters . . . . . 365
cross-references. . . . . . . . . . . . 340 Example: accessing main program parameters 366
Example: XREF output - program-name
cross-references. . . . . . . . . . . . 341 Chapter 22. Running COBOL
Example: embedded cross-reference . . . . . 341 programs under CMS . . . . . . . . 369
Example: OFFSET compiler output . . . . . 342 Run-time restrictions under CMS . . . . . . . 369
Example: VBREF compiler output . . . . . 343 Handling QSAM files under CMS . . . . . . 369
Preparing to use the debugger. . . . . . . . 343 Run-time message IGZ0002S . . . . . . . . 370
Contents vii
Creating and freeing instances of classes . . . 390 Coordinating procedural code with interface
Manipulating object references . . . . . . 391 actions . . . . . . . . . . . . . . 452
Invoking methods . . . . . . . . . . . 391 Integrating procedural code into OO systems 452
Example: defining a client . . . . . . . . 392 Changing procedural code . . . . . . . . 453
Defining a subclass . . . . . . . . . . . 393 Converting from procedure-oriented to OO
CLASS-ID paragraph for defining a subclass 394 programs . . . . . . . . . . . . . . . 453
REPOSITORY paragraph for defining a subclass 394 Identifying objects . . . . . . . . . . . 454
WORKING-STORAGE SECTION for defining a Analyzing data flow and usage . . . . . . 454
subclass . . . . . . . . . . . . . . 395 Reallocating code to objects . . . . . . . 454
Defining a subclass method . . . . . . . 395 Writing the object-oriented code . . . . . . 455
Example: defining a subclass (with methods) 396
Defining a metaclass . . . . . . . . . . . 405
Part 5. Working with more
CLASS-ID paragraph for defining a metaclass 406
REPOSITORY paragraph for defining a complex applications . . . . . . . 457
metaclass . . . . . . . . . . . . . . 406
WORKING-STORAGE SECTION for defining a Chapter 28. Using subprograms . . . 459
metaclass . . . . . . . . . . . . . . 406 Main programs, subprograms, and calls . . . . 459
Defining a metaclass method . . . . . . . 406 Ending and reentering main programs or
Changing the definition of a class or subclass 407 subprograms . . . . . . . . . . . . . 460
Changing a client program . . . . . . . . 407 Transferring control to another program . . . . 461
Example: defining a metaclass (with methods) 408 Making static calls. . . . . . . . . . . 462
Making dynamic calls . . . . . . . . . 462
Chapter 25. System Object Model. . . 415 Performance considerations of static and
SOM Interface Repository . . . . . . . . . 415 dynamic calls . . . . . . . . . . . . 464
Accessing the SOM Interface Repository . . . 415 Making both static and dynamic calls . . . . 465
Populating the SOM Interface Repository . . . 416 Example: static and dynamic CALL statements 465
SOM environment variables . . . . . . . . 417 NODYNAM restriction (CMS only) . . . . . 467
Example: sample JCL for an object-oriented Calling nested COBOL programs . . . . . . 468
application . . . . . . . . . . . . . 418 Making recursive calls . . . . . . . . . . 472
SOM services . . . . . . . . . . . . . 420 Calling to and from object-oriented programs . . 472
SOM methods and functions . . . . . . . 420 Using procedure pointers . . . . . . . . . 472
Class initialization . . . . . . . . . . . 421 Calling a C function-pointer . . . . . . . 473
Changing SOM class interfaces . . . . . . 422 Calling to alternate entry points . . . . . . 473
Making programs reentrant . . . . . . . . 474
Chapter 26. Using SOM IDL-based
class libraries . . . . . . . . . . . 425 Chapter 29. Sharing data . . . . . . 475
SOM objects . . . . . . . . . . . . . . 425 Passing data . . . . . . . . . . . . . . 475
SOM IDL . . . . . . . . . . . . . . . 426 Describing arguments in the calling program 477
Mapping IDL to COBOL . . . . . . . . . 427 Describing parameters in the called program 477
Using IDL operations. . . . . . . . . . 427 Coding the LINKAGE SECTION . . . . . . . 477
Expressing IDL attributes . . . . . . . . 428 Coding the PROCEDURE DIVISION for passing
Common IDL types . . . . . . . . . . 429 arguments . . . . . . . . . . . . . . 478
Complex IDL types . . . . . . . . . . 432 Grouping data to be passed . . . . . . . 478
Passing COBOL arguments and return values 435 Handling null-terminated strings . . . . . . 478
Example: using a SOM IDL-based class library 440 Using pointers to process a chained list . . . 479
Handling errors and exceptions . . . . . . . 442 Passing return code information . . . . . . . 482
Passing environment variables. . . . . . . 443 Understanding the RETURN-CODE special
Checking the exception type field . . . . . 443 register . . . . . . . . . . . . . . 482
Handling exceptions . . . . . . . . . . 443 Using PROCEDURE DIVISION RETURNING . .
Example: checking SOM exceptions . . . . . 443 .. . . . . . . . . . . . . . . . . 482
Creating and initializing object instances . . . . 445 Specifying CALL . . . RETURNING . . . . . . 483
Looking at the IDL file . . . . . . . . . . 446 Sharing data by using the EXTERNAL clause. . . 483
Avoiding memory leaks . . . . . . . . . . 447 Sharing files between programs (external files) . . 483
Example: COBOL variable-length string class 448 Example: using external files . . . . . . . 484
Source code for helper routines . . . . . . . 450
Chapter 30. Creating a DLL or a DLL
Chapter 27. Wrapping or converting application . . . . . . . . . . . . 489
procedure-oriented programs . . . . 451 Dynamic link libraries (DLLs) . . . . . . . . 489
OO view of COBOL programs. . . . . . . . 451 Compiling programs to create DLLs . . . . . . 490
Wrapping procedure-oriented programs . . . . 452 Linking DLLs . . . . . . . . . . . . . 491
Contents ix
Intrinsic functions evaluated in fixed-point Processing of PRTEXIT . . . . . . . . . . 580
arithmetic . . . . . . . . . . . . . . 565 Parameter list for PRTEXIT . . . . . . . . 581
Integer functions . . . . . . . . . . . 565 Processing of ADEXIT . . . . . . . . . . 582
Mixed functions . . . . . . . . . . . 565 Parameter list for ADEXIT . . . . . . . . 582
Floating-point data and intermediate results . . . 566 Error handling for exit modules . . . . . . . 583
Exponentiations evaluated in floating-point Example: SYSIN user exit . . . . . . . . . 583
arithmetic . . . . . . . . . . . . . 567
Intrinsic functions evaluated in floating-point Appendix D. Sample programs . . . . 587
arithmetic . . . . . . . . . . . . . 567 IGYTCARA: batch application . . . . . . . . 587
ON SIZE ERROR and intermediate results. . . . 567 Input data for IGYTCARA . . . . . . . . 588
Arithmetic expressions in nonarithmetic statements 568 Report produced by IGYTCARA . . . . . . 589
Running IGYTCARA . . . . . . . . . . 590
Appendix B. Complex OCCURS IGYTCARB: interactive program . . . . . . . 592
DEPENDING ON . . . . . . . . . . 569 Running IGYTCARB . . . . . . . . . . 592
Example: complex ODO . . . . . . . . . . 569 IGYTSALE: nested program application . . . . 595
How length is calculated . . . . . . . . 570 Input data for IGYTSALE . . . . . . . . 597
Setting values of ODO objects . . . . . . . 570 Reports produced by IGYTSALE . . . . . . 598
Effects of change in ODO object value . . . . . 570 Running IGYTSALE . . . . . . . . . . 602
Preventing index errors when changing ODO Language elements and concepts that are
object value . . . . . . . . . . . . . 571 illustrated . . . . . . . . . . . . . . 604
Preventing overlay when adding elements to a
variable table . . . . . . . . . . . . 571 Notices . . . . . . . . . . . . . . 609
Trademarks . . . . . . . . . . . . . . 610
Appendix C. EXIT compiler option . . 575
Using the user-exit work area . . . . . . . . 576 Glossary . . . . . . . . . . . . . 611
Calling from exit modules . . . . . . . . . 576
Processing of INEXIT. . . . . . . . . . . 577 List of resources . . . . . . . . . . 633
Parameter list for INEXIT . . . . . . . . 577 COBOL for OS/390 & VM . . . . . . . . . 633
Processing of LIBEXIT . . . . . . . . . . 578 Related publications . . . . . . . . . . . 633
Processing of LIBEXIT with nested COPY
statements . . . . . . . . . . . . . 578
Parameter list for LIBEXIT . . . . . . . . 579
Index . . . . . . . . . . . . . . . 635
x Programming Guide
About this book
Welcome to IBM COBOL for OS/390 & VM, IBM’s latest host COBOL compiler!
This version of IBM COBOL for OS/390 & VM is fully source and object
compatible with COBOL for MVS & VM Version 1, with the exception of programs
containing object-oriented language constructs, which must be recompiled to
enable support for OS/390 SOMobjects.
IBM COBOL for OS/390 & VM is referred to as “COBOL for OS/390 & VM”
throughout this publication.
IBM Language Environment for OS/390 & VM provides the run-time environment
and run-time services required to run your COBOL for OS/390 & VM programs.
You will find information on link-editing and running programs in the IBM
Language Environment Programming Guide and IBM Language Environment
Programming Reference.
For a comparison of commonly used COBOL for OS/390 & VM and IBM
Language Environment for OS/390 & VM terms, see “Comparison of
commonly-used terms” on page xiii.
Abbreviated terms
Certain terms are used in a shortened form in this book. Abbreviations for the
product names used most frequently in this book are listed alphabetically in the
following table. Abbreviations for other terms, if not commonly understood, are
shown in italics the first time they appear, and are listed in the glossary in the back
of this book.
If an optional item appears above the main path, that item has no effect on the
execution of the statement and is used only for readability.
If you can choose from two or more items, they appear vertically, in a stack.
If you must choose one of the items, one item of the stack appears on the main
path.
If one of the items is the default, it appears above the main path and the
remaining choices are shown below.
An arrow returning to the left, above the main line, indicates an item that can be
repeated.
If the repeat arrow contains a comma, you must separate repeated items with a
comma.
A repeat arrow above a stack indicates that you can repeat the items in the
stack.
v Keywords appear in uppercase (for example, FROM). They must be spelled exactly
as shown. Variables appear in all lowercase letters (for example, column-name).
They represent user-supplied names or values.
v If punctuation marks, parentheses, arithmetic operators, or other such symbols
are shown, you must enter them as part of the syntax.
Where it helps to more clearly separate the examples from the explanatory text,
they are presented in a different font style.
COBOL keywords and compiler options appearing in text are generally shown in
SMALL UPPER CASE. Other terms such as program variable names or method names
are sometimes shown in a different font style for clarity.
Summary of changes
This section lists the key changes that have been made to IBM COBOL for OS/390
& VM. Those documented in this publication have an associated page reference for
your convenience.
The latest technical changes are marked by a change bar in the left margin. Many
corrections have been made without comment.
Major changes
v Enhanced support for decimal data, raising the maximum number of decimal
digits from 18 to 31 and providing an extended-precision mode for arithmetic
calculations (“ARITH” on page 262)
v Enhanced production debugging using overlay hooks rather than compiled-in
hooks, with symbolic debugging information optionally in a separate file
(“TEST” on page 295)
v Support for compiling, linking, and executing in the OS/390 UNIX System
Services environment, with COBOL files able to reside in the HFS (hierarchical
file system) (“Chapter 14. Compiling under OS/390 UNIX” on page 235)
v Toleration of fork(), exec(), and spawn(); and the ability to call UNIX/POSIX
functions (“Calling UNIX/POSIX APIs” on page 364)
v Enhanced input-output function, permitting dynamic file allocation by means of
an environment variable named in SELECT . . . ASSIGN, and the accessing of
sequentially organized HFS files including by means of ACCEPT and DISPLAY
(“Allocating files” on page 105)
v Support for line-sequential file organization for accessing HFS files that contain
text data, with records delimited by the new-line character (“Chapter 10.
Processing line-sequential files” on page 163)
v COMP-5 data type, new to host COBOL, allowing values of magnitude up to the
capacity of the native binary representation (“Formats for numeric data” on
page 36)
v Significant performance improvement in processing binary data with the
TRUNC(BIN) compiler option (“TRUNC” on page 297)
For further details, see the OS/390 SOMobjects Programmer’s Guide, and
“Chapter 25. System Object Model” on page 415.
v The INTDATE compiler option is no longer an installation option only—it can now
be specified as an option when invoking the compiler. See “INTDATE” on
page 278.
2 Programming Guide
Parameters for creating QSAM files . . . . 123 Closing VSAM files . . . . . . . . . . 150
Retrieving QSAM files . . . . . . . . . 123 Handling errors in VSAM files . . . . . . . 151
Parameters for retrieving QSAM files . . . 124 Protecting VSAM files with a password . . . . 151
Ensuring file attributes match your program 124 Example: password protection for a VSAM
Processing existing files . . . . . . . . 125 indexed file . . . . . . . . . . . . . 152
Defining variable-length (format-V) records 125 Working with VSAM data sets under OS/390 and
Defining format-U records . . . . . . . 125 OS/390 UNIX . . . . . . . . . . . . . 152
Defining fixed-length records . . . . . . 125 Defining VSAM files under OS/390 . . . . . 153
Processing new files . . . . . . . . . 125 Creating alternate indexes . . . . . . . . 154
Processing files dynamically created by Example: entries for alternate indexes . . . 155
COBOL . . . . . . . . . . . . . 126 Allocating VSAM files . . . . . . . . . 156
Using striped extended-format QSAM data sets 126 Sharing VSAM files through RLS . . . . . . 157
Allocation of buffers for QSAM files. . . . 127 Preventing update problems with VSAM files
Accessing HFS files using QSAM . . . . . . . 127 in RLS mode . . . . . . . . . . . 157
Restrictions and usage . . . . . . . . . 127 Restrictions when using RLS . . . . . . 158
Identifying QSAM files to CMS . . . . . . . 128 Handling errors in VSAM files in RLS mode 158
Using FILEDEF. . . . . . . . . . . . 128 Defining VSAM data sets under CMS . . . . . 158
Using LABELDEF . . . . . . . . . . . 129 Improving VSAM performance . . . . . . . 159
Labels for QSAM files . . . . . . . . . . 129
Using trailer and header labels . . . . . . 130 Chapter 10. Processing line-sequential files . . 163
Getting a user-label track . . . . . . . 130 Defining line-sequential files and records in
Handling user labels . . . . . . . . . 130 COBOL . . . . . . . . . . . . . . . 163
Format of standard labels . . . . . . . . 131 Allowable control characters . . . . . . . 164
Standard user labels . . . . . . . . . 131 Describing the structure of a line-sequential file 164
Processing QSAM ASCII files on tape . . . . . 132 Defining and allocating line-sequential files . . . 165
Requesting the ASCII alphabet . . . . . . 132 Coding input-output statements for line-sequential
Defining the record formats . . . . . . . 132 files . . . . . . . . . . . . . . . . 165
Defining the ddname . . . . . . . . . . 132 Opening line-sequential files . . . . . . . 166
Processing ASCII file labels . . . . . . . . . 133 Reading records from line-sequential files . . . 166
Adding records to line-sequential files . . . . 167
Chapter 9. Processing VSAM files. . . . . . 135 Closing line-sequential files. . . . . . . . 167
VSAM files . . . . . . . . . . . . . . 136 Handling errors in line-sequential files . . . . . 168
Defining VSAM file organization and records . . 137
Specifying sequential organization for VSAM Chapter 11. Sorting and merging files . . . . 169
files . . . . . . . . . . . . . . . 138 Sort and merge process . . . . . . . . . . 170
Specifying indexed organization for VSAM files 138 Describing the sort or merge file . . . . . . . 170
Alternate keys . . . . . . . . . . . 139 Describing the input to sorting or merging . . . 171
Alternate index . . . . . . . . . . . 139 Example: describing sort and input files for
Specifying relative organization for VSAM files 139 SORT . . . . . . . . . . . . . . . 171
Fixed-length and variable-length RRDS . . . 140 Coding the input procedure . . . . . . . . 172
Simulating variable-length RRDS . . . . . 140 Describing the output from sorting or merging . . 173
Specifying access modes for VSAM files . . . 141 Coding the output procedure . . . . . . . . 173
Example: using dynamic access with VSAM Coding considerations when using DFSORT on
files . . . . . . . . . . . . . . 141 OS/390 . . . . . . . . . . . . . . 174
Defining record lengths for VSAM files. . . . 141 Example: coding the output procedure when
Defining fixed-length records . . . . . . 142 using DFSORT . . . . . . . . . . . . 174
Defining variable-length records . . . . . 142 Restrictions on input and output procedures . . . 175
Coding input and output statements for VSAM Defining sort and merge data sets under OS/390 175
files . . . . . . . . . . . . . . . . 143 Defining sort and merge files under CMS . . . . 176
File position indicator . . . . . . . . . 144 Sorting variable-length records . . . . . . . 176
Opening a file (ESDS, KSDS, or RRDS) . . . . 145 Requesting the sort or merge . . . . . . . . 177
Opening an empty file . . . . . . . . 145 Setting sort or merge criteria . . . . . . . 177
Statements to load records into a VSAM file 147 Example: sorting with input and output
Opening a loaded file (a file with records) 147 procedures . . . . . . . . . . . . . 178
Reading records from a VSAM file . . . . . 147 Choosing alternate collating sequences . . . . 179
Updating records in a VSAM file . . . . . . 148 Sorting on windowed date fields . . . . . . 179
Adding records to a VSAM file . . . . . . 149 Preserving the original sequence of records with
Adding records sequentially . . . . . . 149 equal keys . . . . . . . . . . . . . 180
Adding records randomly or dynamically 149 Determining whether the sort or merge was
Replacing records in a VSAM file. . . . . . 149 successful . . . . . . . . . . . . . . 180
Deleting records from a VSAM file . . . . . 150 Stopping a sort or merge operation prematurely 181
4 Programming Guide
Chapter 1. Structuring your program
A COBOL program consists of four divisions, each with a specific logical function:
v IDENTIFICATION DIVISION
v ENVIRONMENT DIVISION
v DATA DIVISION
v PROCEDURE DIVISION
Only the IDENTIFICATION DIVISION is required.
To define a COBOL class or method, you need to define some divisions differently
than you would for a program.
RELATED TASKS
“Identifying a program”
“Describing the computing environment” on page 7
“Describing the data” on page 12
“Processing the data” on page 17
“Defining a class” on page 378
“Defining a class method” on page 381
Identifying a program
Use the IDENTIFICATION DIVISION to name your program and, if you want, give
other identifying information.
You can use the optional AUTHOR, INSTALLATION, DATE-WRITTEN, and DATE-COMPILED
paragraphs for descriptive information about your program. The data you enter on
the DATE-COMPILED paragraph is replaced with the latest compilation date.
IDENTIFICATION DIVISION.
Program-ID. Helloprog.
Author. A. Programmer.
Installation. Computing Laboratories.
Date-Written. 08/18/1997.
Date-Compiled. 03/30/2000.
Use the PROGRAM-ID paragraph to name your program. The program name that you
assign is used in these ways:
v Other programs use the name to call your program.
v The name appears in the header on each page, except the first page, of the
program listing generated when the program is compiled.
v If you use the NAME compiler option, the name is placed on the NAME linkage
editor control statement to identify the object module created by the
compilation.
Tip: Do not use program names that start with prefixes used by IBM products. If
you try to use programs whose names start with any of the following, your CALL
statements might resolve to IBM library or compiler routines rather than to your
intended program:
RELATED TASKS
“Changing the header of a source listing”
“Identifying a program as recursive”
“Marking a program as callable by containing programs”
“Setting a program to an initial state”
RELATED REFERENCES
Compiler limits (IBM COBOL Language Reference)
Conventions for program names (IBM COBOL Language Reference)
You can code RECURSIVE only on the outermost program of a compilation unit.
Neither nested subprograms nor programs containing nested subprograms can be
recursive.
RELATED TASKS
“Making recursive calls” on page 472
RELATED CONCEPTS
“Nested programs” on page 469
PP 5648-A25 IBM COBOL for OS/390 & VM 2.2.0 Date 03/30/2000 Time 15:05:19 Page 1
6 Programming Guide
You can customize the header on succeeding pages of the listing with the
compiler-directing TITLE statement.
RELATED REFERENCES
TITLE statement (IBM COBOL Language Reference)
RELATED TASKS
“Specifying the collating sequence” on page 8
“Defining symbolic characters” on page 9
“Defining a user-defined class” on page 9
“Defining files to the operating system” on page 10
RELATED REFERENCES
Sections and paragraphs (IBM COBOL Language Reference)
1. The SELECT clause chooses a file in the COBOL program to be associated with an external data set.
| 2. The ASSIGN clause associates the program’s name for the file with the external name for the actual data file. You
| can define the external name with a DD statement or an environment variable.
3. The ORGANIZATION clause describes the file’s organization. For QSAM files, the ORGANIZATION clause is optional.
4. The ACCESS MODE clause defines the manner in which the records are made available for processing—sequential,
| random, or dynamic. For QSAM and line-sequential files, the ACCESS MODE clause is optional. These files always
have sequential organization.
5. For VSAM files, you might have additional statements in the FILE-CONTROL paragraph depending on the type of
VSAM file you use.
RELATED TASKS
“Chapter 8. Processing QSAM files” on page 107
“Chapter 9. Processing VSAM files” on page 135
“Chapter 10. Processing line-sequential files” on page 163
“Describing the computing environment” on page 7
The sequence that you use can be based on one of these alphabets:
v EBCDIC (use NATIVE if the native character set is EBCDIC), the default if you
omit the ALPHABET clause
v ASCII (use STANDARD-1)
v ISO 7-bit code, International Reference Version (use STANDARD-2)
v An alteration of the EBCDIC sequence that you define in the SPECIAL-NAMES
paragraph
RELATED TASKS
“Choosing alternate collating sequences” on page 179
8 Programming Guide
in the SPECIAL-NAMES paragraph, the overall collating sequence is affected, not just
the collating sequence of the characters included in the SPECIAL-NAMES paragraph.
IDENTIFICATION DIVISION.
. . .
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
Source-Computer. IBM-390.
Object-Computer. IBM-390.
RELATED TASKS
“Specifying the collating sequence” on page 8
The class name can be referenced only in a class condition. This user-defined class
is not the same as an object-oriented class.
10 Programming Guide
RELATED TASKS
“Optimizing buffer and device space” on page 12
Rules for using different files: The name you use in the assignment-name of the
| ASSIGN clause must be the same as the ddname in the DD statement, the environment
| variable in the export command, or the ddname in the FILEDEF command. You can
| change the actual file by using the DSNAME in the DD statement, the DSNAME or path
| name in the environment variable, or the fn, ft, and fm in the FILEDEF.
The file-name that you use with the SELECT clause (such as SELECT MASTER) must be
the same as in the FD file-name entry.
| Two files should not use the same ddname or environment variable name in their
SELECT clauses; otherwise, results could be unpredictable. For example, if DISPLAY
| is directed to SYSOUT, do not use SYSOUT as the ddname or environment variable
| name on the SELECT clause for a file.
Example: using different input files on OS/390: Consider a COBOL program that
is used in exactly the same way for several different master files. It contains this
SELECT clause:
SELECT MASTER
ASSIGN TO DA-3330-S-MASTERA
Under OS/390, assume the three possible input files are MASTER1, MASTER2, and
MASTER3. Then you must code one of the following DD statements in the job step
| that calls for program execution, or issue one of the following export commands
| from the same shell from which you run the program, prior to running the
| program:
//MASTERA DD DSNAME=MY.MASTER1, . . .
export MASTERA=DSN(MY.MASTER1),...
//MASTERA DD DSNAME=MY.MASTER2, . . .
export MASTERA=DSN(MY.MASTER2),...
//MASTERA DD DSNAME=MY.MASTER3, . . .
export MASTERA=DSN(MY.MASTER3),...
Any reference in the program to MASTERA will therefore be a reference to the file
| currently assigned to ddname or environment variable name MASTERA.
| Notice that in this example, you cannot use the PATH(path) form of the export
| command to reference a line-sequential file in the HFS, because you cannot specify
| an organization field (S- or AS-) with a line-sequential file.
Under VM, assume the three possible input files on your A-disk are MASTER1
INPUT, MASTER2 INPUT, and MASTER3 INPUT. Then you need to issue one of the
following FILEDEF commands before running the program:
FILEDEF MASTERA DISK MASTER1 INPUT A1 . . .
Any reference in the program to MASTERA will therefore be a reference to the file
named in the FILEDEF command.
The APPLY WRITE-ONLY clause has meaning only for sequential files that have
variable-length records and are blocked.
The AWO compiler option applies an implicit APPLY WRITE-ONLY clause to all eligible
files. The NOAWO compiler option has no effect on files that have the APPLY
WRITE-ONLY clause specified. The APPLY WRITE-ONLY clause takes precedence over
the NOAWO compiler option.
The APPLY-WRITE ONLY clause can cause input files to use a record area rather than
process the data in the buffer. This use might affect the processing of both input
files and output files.
RELATED REFERENCES
“AWO” on page 263
The IBM COBOL for OS/390 & VM compiler limits the maximum size of DATA
DIVISION elements.
12 Programming Guide
RELATED CONCEPTS
“Comparison of WORKING-STORAGE and LOCAL-STORAGE” on page 15
RELATED TASKS
“Using data in input and output operations”
“Using data from another program” on page 16
RELATED REFERENCES
Compiler limits (IBM COBOL Language Reference)
Programs in the same run unit can share, or have access to, common files. The
method for doing this depends on whether the programs are part of a nested
(contained) structure or are separately compiled (including programs compiled as
part of a batch sequence).
You can use the EXTERNAL clause for separately compiled programs. A file that is
defined as EXTERNAL can be referenced by any program in the run unit that
describes the file.
RELATED CONCEPTS
“Nested programs” on page 469
RELATED TASKS
“Sharing files between programs (external files)” on page 483
RELATED REFERENCES
“FILE SECTION entries”
14 Programming Guide
Clause To define Notes
CODE-SET ASCII or EBCDIC files QSAM only.
RELATED CONCEPTS
“Labels for QSAM files” on page 129
RELATED CONCEPTS
“Example: storage sections”
RELATED TASKS
“Ending and reentering main programs or subprograms” on page 460
RELATED REFERENCES
Working-Storage section (IBM COBOL Language Reference)
Local-Storage section (IBM COBOL Language Reference)
if numb = 0
move 1 to fact
else
subtract 1 from numb
call 'factorial'
multiply num by fact
end-if.
The following tables show the changing values of the data items in LOCAL-STORAGE
(L-S) and WORKING-STORAGE (W-S) in the successive recursive calls of the program,
and in the ensuing gobacks. During the gobacks, fact progressively accumulates
the value of 5! (five factorial).
Recursive
CALLs: Main 1 2 3 4 5
___________________________________
L-S num 5 4 3 2 1 0
___________________________________
W-S numb 5 4 3 2 1 0
fact 0 0 0 0 0 0
___________________________________
Recursive
GOBACKs: 5 4 3 2 1 Main
____________________________________
L-S num 0 1 2 3 4 5
____________________________________
W-S numb 0 0 0 0 0 0
fact 1 1 2 6 24 120
____________________________________
RELATED CONCEPTS
“Comparison of WORKING-STORAGE and LOCAL-STORAGE” on page 15
RELATED TASKS
“Sharing data in separately compiled programs”
“Sharing data in nested programs” on page 17
RELATED TASKS
“Passing data” on page 475
16 Programming Guide
Sharing data in nested programs
Some applications consist of nested programs—programs that are contained in
other programs. Level-01 LINKAGE SECTION data items can include the GLOBAL
attribute. This attribute allows any nested program that includes the declarations
to access these LINKAGE SECTION data items.
A nested program can also access data items in a sibling program (one at the same
nesting level in the same containing program) that is declared with the COMMON
attribute.
RELATED CONCEPTS
“Nested programs” on page 469
The PROCEDURE DIVISION begins with the division header and a procedure-name
header. The division header for a program can simply be:
PROCEDURE DIVISION.
You can code your division header to receive parameters with the USING phrase or
to return a value with the RETURNING phrase.
Be sure to define the dataname in the LINKAGE SECTION of the DATA DIVISION.
To receive a parameter that was passed by value, code the division header for a
program as follows:
PROCEDURE DIVISION USING BY VALUE dataname
You can also combine USING and RETURNING in a PROCEDURE DIVISION header:
PROCEDURE DIVISION USING dataname RETURNING dataname2
Be sure to define dataname and dataname2 in the LINKAGE SECTION of the DATA
DIVISION.
RELATED CONCEPTS
“How logic is divided in the PROCEDURE DIVISION”
RELATED TASKS
“Eliminating repetitive coding” on page 551
RELATED CONCEPTS
“Compiler-directing statements” on page 20
“Scope terminators” on page 20
“Imperative statements”
“Conditional statements” on page 19
“Declaratives” on page 21
RELATED REFERENCES
PROCEDURE DIVISION structure (IBM COBOL Language Reference)
Imperative statements
An imperative statement indicates an unconditional action to be taken (such as
ADD, MOVE, INVOKE, or CLOSE).
RELATED CONCEPTS
“Conditional statements” on page 19
“Scope terminators” on page 20
18 Programming Guide
Conditional statements
A conditional statement is either a simple conditional statement (IF, EVALUATE,
SEARCH) or a conditional statement made up of an imperative statement that
includes a conditional phrase or option.
You can end a conditional statement with an implicit or explicit scope terminator.
If you end a conditional statement explicitly, it becomes a delimited scope
statement (which is an imperative statement).
An explicit scope terminator is required for the inline PERFORM statement, but it is
not valid for the out-of-line PERFORM statement.
For additional program control, you can use the NOT phrase with conditional
statements. For example, you can provide instructions to be performed when a
particular exception does not occur, such as NOT ON SIZE ERROR. The NOT phrase
cannot be used with the ON OVERFLOW phrase of the CALL statement, but it can be
used with the ON EXCEPTION phrase.
The following statements are examples of conditional statements if they are coded
without scope terminators:
v Arithmetic statement with ON SIZE ERROR
v Data-manipulation statements with ON OVERFLOW
v CALL statements with ON OVERFLOW
v I/O statements with INVALID KEY, AT END, or AT END-OF-PAGE
v RETURN with AT END
RELATED CONCEPTS
“Imperative statements” on page 18
“Scope terminators” on page 20
RELATED REFERENCES
Conditional statements (IBM COBOL Language Reference)
Compiler-directing statements
A compiler-directing statement is not part of the program logic. A
compiler-directing statement causes the compiler to take specific action about the
program structure, COPY processing, listing control, or control flow.
RELATED REFERENCES
“Compiler-directing statements” on page 304
Compiler-directing statements (IBM COBOL Language Reference)
Scope terminators
Scope terminators can be explicit or implicit. Explicit scope terminators end a verb
without ending a sentence. They consist of END followed by a hyphen and the
name of the verb being terminated, such as END-IF. An implicit scope terminator is
a period (.) that ends the scope of all previous statements not yet ended.
Each of the two periods in the following program fragment ends an IF statement,
making the code equivalent to the code after it that instead uses explicit scope
terminators:
IF ITEM = “A”
DISPLAY “THE VALUE OF ITEM IS ” ITEM
ADD 1 TO TOTAL
MOVE “C” TO ITEM
DISPLAY “THE VALUE OF ITEM IS NOW ” ITEM.
IF ITEM = “B”
ADD 2 TO TOTAL.
IF ITEM = “A”
DISPLAY “THE VALUE OF ITEM IS ” ITEM
ADD 1 TO TOTAL
MOVE “C” TO ITEM
DISPLAY “THE VALUE OF ITEM IS NOW ” ITEM
END-IF
IF ITEM = “B”
ADD 2 TO TOTAL
END-IF
If you use implicit terminators, the end of statements can be unclear. As a result,
you might end statements unintentionally, changing your program’s logic. Explicit
scope terminators make a program easier to understand and prevent unintentional
ending of statements. For example, in the program fragment below, changing the
location of the first period in the first implicit scope example changes the meaning
of the code:
IF ITEM = “A”
DISPLAY “VALUE OF ITEM IS ” ITEM
ADD 1 TO TOTAL.
MOVE “C” TO ITEM
DISPLAY “ VALUE OF ITEM IS NOW ” ITEM
IF ITEM = “B”
ADD 2 TO TOTAL.
The MOVE statement and the DISPLAY statement after it are performed regardless of
the value of ITEM, despite what the indentation indicates, because the first period
terminates the IF statement.
20 Programming Guide
For improved program clarity and to avoid unintentional ending of statements, use
explicit scope terminators, especially within paragraphs. Use implicit scope
terminators only at the end of a paragraph or the end of a program.
To ensure that the explicit scope terminator is paired with the intended statement,
the preceding example can be recoded in this way:
READ FILE1
AT END
MOVE A TO B
READ FILE2
END-READ
END-READ
RELATED CONCEPTS
“Conditional statements” on page 19
“Imperative statements” on page 18
Declaratives
Declaratives provide one or more special-purpose sections that are executed when
an exception condition occurs.
Start each declarative section with a USE statement that identifies the function of
the section; in the procedures, specify the actions to be taken when the condition
occurs.
RELATED TASKS
“Finding and handling input-output errors” on page 311
RELATED REFERENCES
Declaratives (IBM COBOL Language Reference)
Variables
A variable is a data item whose value can change during a program. The values
are restricted, however, to the data type that you define when you give the
variable a name and a length. For example, if a customer name is a variable in
your program, you could code:
Data Division.
. . .
01 Customer-Name Pic X(20).
01 Original-Customer-Name Pic X(20).
. . .
Procedure Division.
. . .
Move Customer-Name to Original-Customer-Name
. . .
Literals
A literal is a character string whose value is given by the characters themselves.
When you know the value you want to use for a data item, use a literal
representation of the data value in the PROCEDURE DIVISION. You do not need to
define it or refer to a data-name. For example, you can prepare an error message
for an output file this way:
Move “Name is not valid” To Customer-Name
Constants
A constant is a data item that has only one value. COBOL does not define a
construct specifically for constants. However, most COBOL programmers define a
data item with an initial VALUE (as opposed to initializing a variable using the
INITIALIZE statement). For example:
Data Division.
. . .
01 Report-Header pic x(50) value “Company Sales Report”.
. . .
01 Interest pic 9v9999 value 1.0265.
Figurative constants
A variable is a data item whose value can change during a program. Certain
commonly used constants and literals are provided as reserved words called
figurative constants: ZERO, SPACE, HIGH-VALUE, LOW-VALUE, QUOTE, NULL, and ALL.
Because they represent fixed values, figurative constants do not require a data
definition. For example:
Move Spaces To Report-Header
RELATED REFERENCES
PICTURE clause (IBM COBOL Language Reference)
Literals (IBM COBOL Language Reference)
Figurative constants (IBM COBOL Language Reference)
24 Programming Guide
Assigning values to data items
After you have defined a data item, you can assign a value to it at any time.
Assignment takes many forms in COBOL, depending on what you want to do.
RELATED TASKS
“Initializing a structure (INITIALIZE)” on page 26
“Assigning values to variables or structures (MOVE)” on page 27
“Assigning arithmetic results (MOVE or COMPUTE)” on page 27
“Assigning input from a screen or file (ACCEPT)” on page 28
“Displaying values on a screen or in a file (DISPLAY)” on page 29
RELATED TASKS
“Initializing a structure (INITIALIZE)”
26 Programming Guide
The following example shows how you can reset fields in a transaction record
produced by a program to spaces and zeros. The fields are not identical in each
record produced.
01 TRANSACTION-OUT.
05 TRANSACTION-CODE PIC X.
05 PART-NUMBER PIC 9(6).
05 TRANSACTION-QUANTITY PIC 9(5).
05 PRICE-FIELDS.
10 UNIT-PRICE PIC 9(5)V9(2).
10 DISCOUNT PIC V9(2).
10 SALES-PRICE PIC 9(5)V9(2).
. . .
INITIALIZE TRANSACTION-OUT
For example, the following statement assigns the contents of the variable
Customer-Name to the variable Orig-Customer-Name:
Move Customer-Name to Orig-Customer-Name
When you move a group item to another group item, be sure the subordinate data
descriptions are compatible. The compiler performs all MOVE statements regardless
of whether the items fit, even if a destructive overlap could occur at run time,
For variables containing numbers, moves can be more complicated because there
are several ways numbers are represented. In general, the algebraic values of
numbers are moved if possible (as opposed to the digit-by-digit move performed
with character data):
01 Item-x Pic 999v9.
. . .
Move 3.06 to Item-x
This move would result in Item-x containing the value 3.0, represented by 0030.
When significant left-order digits would be lost in execution, the COMPUTE statement
can detect the condition and allow you to handle it.
When you use the ON SIZE ERROR phrase of the COMPUTE statement, the compiler
generates code to detect a size-overflow condition. If the condition occurs, the code
in the ON SIZE ERROR phrase is performed, and the content of z remains
unchanged. If the ON SIZE ERROR phrase is not specified, the assignment is carried
out with truncation. There is no ON SIZE ERROR support for the MOVE statement.
You can also use the COMPUTE statement to assign the result of an arithmetic
expression (or intrinsic function) to a variable. For example:
Compute z = y + (x ** 3)
Compute x = Function Max(x y z)
As a result of this call, the variable Result is assigned to be the absolute value of
the value that is in the variable Arg; the variable Feedback-code contains the return
code indicating whether the service completed successfully. You have to define all
the variables in the Data Division using the correct descriptions, according to the
requirements of the particular callable service you are using. For the example
above, the variables could be defined like this:
77 Arg Pic s9(9) Binary.
77 Feedback-code Pic x(12) Display.
77 Result Pic s9(9) Binary.
RELATED REFERENCES
“DIAGTRUNC” on page 269
Intrinsic functions (IBM COBOL Language Reference)
Callable services (Language Environment Programming Reference)
For example:
Environment Division.
Configuration Section.
Special-Names.
Console is Names-Input.
. . .
Accept Customer-Name From Names-Input
To read from a file instead of the screen, make the following change:
28 Programming Guide
v Change Console to device, where device is any valid system device (for example,
SYSIN). For example:
SYSIN is Names-Inpu
| Note that device can be a ddname that references a hierarchical file system (HFS)
| path. If this DD is not defined and your program is running in an OS/390 UNIX
| environment, stdin is the input source. If this DD is not defined and your
| program is not running in an OS/390 UNIX environment, the ACCEPT statement
| fails.
RELATED REFERENCES
SPECIAL-NAMES paragraph (IBM COBOL Language Reference)
To write data to a destination other than the system logical output device, use the
UPON clause with a destination other than SYSOUT. For example, the following
statement writes to the file specified in the SYSPUNCH DD statement:
Display “Hello” UPON SYSPUNCH.
| Note that you can specify a file in the hierarchical file system (HFS) with this
| ddname. For example, with the following definition, your DISPLAY output is
| written to the HFS file /u/userid/cobol/demo.lst:
| //SYSPUNCH DD PATH='/u/userid/cobol/demo.lst',
| // PATHOPTS=(OWRONLY,OCREAT,OTRUNC),PATHMODE=SIRWXU,
| // FILEDATA=TEXT
The output is directed to the ddname that you specify in the OUTDD compiler
| option. Note that you can specify a file in the hierarchical file system (HFS) with
| this ddname.
| If the OUTDD ddname is not allocated and you are not running in an OS/390 UNIX
| environment, a default DD of SYSOUT=* is allocated.
| If the OUTDD ddname is not allocated and you are running in an OS/390 UNIX
| environment, the _IGZ_SYSOUT environment variable is used as follows:
| Undefined or set to stdout
| Output is routed to stdout (file descriptor 1).
| When DISPLAY output is routed to stdout or stderr, the output is not subdivided
| into records; rather the output is written as a single stream of characters without
| line breaks.
If OUTDD and the Language Environment run-time option MSGFILE both specify the
same ddname, DISPLAY output and Language Environment run-time diagnostics
are both routed to the Language Environment message file.
| If you specify the WITH NO ADVANCING phrase and the output is going to stdout or
| stderr, a new-line character is not appended to the end of the stream. A subsequent
| DISPLAY statement might add additional characters to the end of the stream.
| If you do not specify WITH NO ADVANCING and the output is going to a ddname, the
printer control character ’ ’ (space) is placed into the first output position from the
next DISPLAY statement, indicating single-spaced output.
For example:
DISPLAY “ABC”
DISPLAY “CDEF” WITH NO ADVANCING
DISPLAY “GHIJK” WITH NO ADVANCING
DISPLAY “LMNOPQ”
DISPLAY “RSTUVWX”
If you use the statements above, the result sent to the output device is:
ABC
CDEF
+GHIJK
+LMNOPQ
RSTUVMX
The output printed depends on how the output device interprets printer control
characters.
| If you do not specify the WITH NO ADVANCING phrase and the output is going to
| stdout or stderr, a new-line character is appended to the end of the stream.
RELATED TASKS
“Setting and accessing environment variables” on page 362
“Coding COBOL programs to run under CICS” on page 347
RELATED REFERENCES
DISPLAY statement (IBM COBOL Language Reference)
“OUTDD” on page 286
30 Programming Guide
Using intrinsic functions (built-in functions)
Some high-level programming languages have built-in functions that you can
reference in your program as if they were variables having defined attributes and a
predetermined value. In COBOL, these are called intrinsic functions. They provide
capabilities for manipulating strings and numbers.
A function-identifier represents both the invocation of the function and the data
value returned by the function. Because it actually represents a data item, you can
use a function-identifier in most places in the PROCEDURE DIVISION where a data
item having the attributes of the returned value can be used.
The COBOL word function is a reserved word, but the function names are not
reserved. You can use them in other contexts, such as for the name of a variable.
For example, you could use Sqrt to invoke an intrinsic function and to name a
variable in your program:
Working-Storage Section.
01 x Pic 99 value 2.
01 y Pic 99 value 4.
01 z Pic 99 value 0.
01 Sqrt Pic 99 value 0.
. . .
Compute Sqrt = 16 ** .5
Compute z = x + Function Sqrt(y)
. . .
The functions MAX, MIN, DATEVAL, and UNDATE can return either type of value
depending on the type of arguments you supply.
The functions DATEVAL, UNDATE, and YEARWINDOW are provided with the millennium
language extensions to assist with manipulating and converting windowed date
fields.
In this case, Function Sqrt(5) returns a numeric value. Thus, the three arguments
to the MAX function are all numeric, which is an allowable argument type for this
function.
RELATED TASKS
“Processing table items using intrinsic functions” on page 67
“Converting data items (intrinsic functions)” on page 94
“Evaluating data items (intrinsic functions)” on page 96
Pointers are data items that contain virtual storage addresses. You define them
explicitly with the USAGE IS POINTER clause in the DATA DIVISION or implicitly as
ADDRESS OF special registers.
RELATED TASKS
“Defining a table (OCCURS)” on page 53
32 Programming Guide
Chapter 3. Working with numbers and arithmetic
In general, you can view COBOL numeric data as a series of decimal digit
positions. However, numeric items can also have special properties such as an
arithmetic sign or a currency sign.
This section describes how to define, display, and store numeric data so that you
can perform arithmetic operations efficiently:
v Use the PICTURE clause and the characters 9, +, -, P, S, and V to define numeric
data.
v Use the PICTURE clause and editing characters (such as Z, comma, and period)
along with MOVE and DISPLAY statements to display numeric data.
v Use the USAGE clause with various formats to control how numeric data is stored.
v Use the numeric class test to validate that data values are appropriate.
v Use ADD, SUBTRACT, MULTIPLY, DIVIDE, and COMPUTE statements to perform
arithmetic.
v Use the CURRENCY SIGN clause and appropriate PICTURE characters to designate
the currency you want.
RELATED TASKS
“Defining numeric data”
“Displaying numeric data” on page 34
“Controlling how numeric data is stored” on page 35
“Checking for incompatible data (numeric class test)” on page 42
“Performing arithmetic” on page 43
“Using currency signs” on page 51
| When you compile using the default compiler option ARITH(COMPAT) (referred to as
| compatibility mode), you can code up to 18 digits in the PICTURE clause. When you
| compile using ARITH(EXTEND) (referred to as extended mode), you can code up to 31
| digits in the PICTURE clause.
The field can therefore hold a positive or a negative value. The v indicates the
position of an implied decimal point, but does not contribute to the size of the
However, if you plan to port your program or data to a different machine, you
might want to code the sign as a separate position in storage. In this case, the sign
takes 1 byte:
05 Price Pic s99V99 Sign Is Leading, Separate.
This coding ensures that the convention your machine uses for storing a
nonseparate sign will not cause unexpected results on a machine that uses a
different convention.
Separate signs are also preferable for data items that will be printed or displayed.
You cannot use the PICTURE clause with internal floating-point data (COMP-1 or
COMP-2). However, you can use the VALUE clause to provide an initial value for a
floating-point literal:
05 Compute-result Usage Comp-2 Value 06.23E-24.
RELATED CONCEPTS
“Appendix A. Intermediate results and arithmetic precision” on page 559
RELATED TASKS
“Displaying numeric data”
“Controlling how numeric data is stored” on page 35
“Performing arithmetic” on page 43
RELATED REFERENCES
“Sign representation and processing” on page 41
“ARITH” on page 262
“NUMPROC” on page 283
If the contents of Price are 0150099 (representing the value 1,500.99), then
$ 1,500.99 is displayed when you run the code. The z in the PICTURE clause of
Edited-price indicates the suppression of leading zeros.
34 Programming Guide
You can move numeric-edited items to numeric or numeric-edited items. In the
following example, the value of the numeric-edited item is moved to the numeric
item:
Move Edited-price to Price
Display Price
RELATED TASKS
“Controlling how numeric data is stored”
“Defining numeric data” on page 33
“Performing arithmetic” on page 43
RELATED REFERENCES
MOVE statement (IBM COBOL Language Reference)
COMP and COMP-4 are synonymous with BINARY, and COMP-3 is synonymous with
PACKED-DECIMAL.
Regardless of which USAGE clause you use to control the internal representation of a
value, you use the same PICTURE clause conventions and decimal value in the
VALUE clause (except for floating-point data, for which you cannot use a PICTURE
clause).
RELATED CONCEPTS
“Formats for numeric data”
“Data format conversions” on page 39
“Appendix A. Intermediate results and arithmetic precision” on page 559
RELATED TASKS
“Defining numeric data” on page 33
“Displaying numeric data” on page 34
“Performing arithmetic” on page 43
RELATED REFERENCES
“Conversions and precision” on page 40
“Sign representation and processing” on page 41
External decimal (also known as zoned decimal) items are primarily intended for
receiving and sending numbers between your program and files, terminals, or
printers. You can also use external decimal items as operands and receivers in
arithmetic processing. However, if your program performs a lot of intensive
arithmetic and efficiency is a high priority, COBOL’s computational numeric types
might be a better choice for the data items used in the arithmetic.
The minus signs (-) do not mean that the mantissa and exponent must necessarily
be negative numbers. Instead, they mean that when the number is displayed, the
sign appears as a blank for positive numbers or a minus sign for negative
numbers. If you instead code a plus sign (+), the sign appears as a plus sign for
positive numbers or a minus sign for negative numbers.
36 Programming Guide
As with external decimal numbers, external floating-point numbers have to be
converted (by the compiler) to an internal representation of their numeric value
| before they can be used in arithmetic operations. If you compile with the default
| option ARITH (COMPAT), external floating-point numbers are converted to long
| (64-bit) floating-point format. If you compile with ARITH (EXTEND), they are instead
| converted to extended-precision (128-bit) floating-point format.
You can use binary items, for example, for indexes, subscripts, switches, and
arithmetic operands or results.
Use the TRUNC(STD|OPT|BIN) compiler option to indicate how binary data (BINARY,
COMP, or COMP-4) is to be truncated.
| Data items that you declare as USAGE COMP-5 are represented in storage as binary
| data. However, unlike USAGE COMP items, they can contain values of magnitude up
| to the capacity of the native binary representation (2, 4, or 8 bytes) rather than
| being limited to the value implied by the number of 9s in the PICTURE clause.
| When you move or store numeric data into a COMP-5 item, truncation occurs at the
| binary field size rather than at the COBOL PICTURE size limit. When you reference
| a COMP-5 item, the full binary field size is used in the operation.
| COMP-5 is thus particularly useful for binary data items originating in non-COBOL
| programs where the data might not conform to a COBOL PICTURE clause.
| The table below shows the ranges of values possible for COMP-5 data items.
| Regardless of the setting of the TRUNC compiler option, COMP-5 data items behave
| like binary data does in programs compiled with TRUNC(BIN).
Packed-decimal items occupy 1 byte of storage for every two decimal digits you
code in the PICTURE description, except that the rightmost byte contains only one
digit and the sign. This format is most efficient when you code an odd number of
digits in the PICTURE description, so that the leftmost byte is fully used.
Packed-decimal items are handled as fixed-point numbers for arithmetic purposes.
On OS/390 & VM, COMP-1 and COMP-2 data items are stored in System/390
hexadecimal format.
RELATED CONCEPTS
“Appendix A. Intermediate results and arithmetic precision” on page 559
RELATED REFERENCE
“TRUNC” on page 297
38 Programming Guide
PICTURE and USAGE and
Numeric type optional SIGN clause Value Internal representation
Binary PIC S9999 BINARY + 1234 04 D2
COMP - 1234 FB 2E
COMP-4
| COMP-5 + 123451 30 39
| - 123451 CF C7
PIC 9999 BINARY 1234 04 D2
COMP
COMP-4
| COMP-5 600001 EA 60
Internal PIC S9999 PACKED-DECIMAL + 1234 01 23 4C
decimal COMP-3 - 1234 01 23 4D
PIC 9999 PACKED-DECIMAL + 1234 01 23 4F
COMP-3 - 1234 01 23 4F
Internal COMP-1 + 1234 43 4D 20 00
floating
point
Internal COMP-2 + 1234 43 4D 20 00 00 00 00 00
floating - 1234 C3 4D 20 00 00 00 00 00
point
External PIC +9(2).9(2)E+99 DISPLAY + 1234 4E F1 F2 4B F3
floating F4 C5 4E F0 F2
point
- 1234 60 F1 F2 4B F3
F4 C5 4E F0 F2
| 1. The example demonstrates that COMP-5 data items can contain values of magnitude up to the capacity of the
| native binary representation (2, 4, or 8 bytes), rather than being limited to the value implied by the number of 9s
| in the PICTURE clause.
Conversion generally requires additional storage and processing time because data
is moved to an internal work area and converted before the operation is
performed. The results might also have to be moved back into a work area and
converted again.
RELATED REFERENCES
“Conversions and precision”
“Sign representation and processing” on page 41
When the compiler converts short form to long form for comparisons, zeros are
used for padding the shorter number.
When a USAGE COMP-1 data item is moved to a fixed-point data item with more
than nine digits, the fixed-point data item will receive only nine significant digits,
and the remaining digits will be zero.
When a USAGE COMP-2 data item is moved to a fixed-point data item with more
than 18 digits, the fixed-point data item will receive only 18 significant digits, and
the remaining digits will be zero.
If a USAGE COMP-1 data item is moved to a fixed-point data item of nine or more
digits and then returned to the USAGE COMP-1 data item, the original value is
recovered.
If a fixed-point data item with 15 or fewer digits is moved to a USAGE COMP-2 data
item and then returned to the fixed-point data item, the original value is recovered.
If a USAGE COMP-2 data item is moved to a USAGE COMP-1 data item, rounding occurs
in the low-order position of the target data item.
If a fixed-point data item is moved to an external floating-point data item and the
PICTURE of the fixed-point data item contains more digit positions than the PICTURE
of the external floating-point data item, rounding occurs in the low-order position
of the target data item.
40 Programming Guide
RELATED CONCEPTS
“Appendix A. Intermediate results and arithmetic precision” on page 559
Given X’sd’, where s is the sign representation and d represents the digit, the valid
sign representations for external decimal (USAGE DISPLAY without the SIGN IS
SEPARATE clause) are:
Positive:
C, A, E, and F
Negative:
D and B
The COBOL NUMPROC compiler option affects sign processing for external decimal
and internal decimal data. NUMPROC has no effect on binary data or floating-point
data.
NUMPROC(PFD)
Given X’sd’, where s is the sign representation and d represents the digit, when
you use NUMPROC(PFD), the compiler assumes that the sign in your data is one of
three preferred signs:
Signed positive or 0:
X’C’
Signed negative:
X’D’
Unsigned or alphanumeric:
X’F’
Based on this assumption, the compiler uses whatever sign it is given to process
data. The preferred sign is generated only where necessary (for example, when
unsigned data is moved to signed data). Using the NUMPROC(PFD) option can save
processing time, but you must use preferred signs with your data for correct
processing.
NUMPROC(NOPFD)
When the NUMPROC(NOPFD) compiler option is in effect, the compiler accepts any
valid sign configuration. The preferred sign is always generated in the receiver.
NUMPROC(NOPFD) is less efficient than NUMPROC(PFD), but you should use it whenever
data that does not use preferred signs might exist.
NUMPROC(MIG)
When NUMPROC(MIG) is in effect, the compiler generates code that is similar to that
produced by OS/VS COBOL. This option can be especially useful if you migrate
OS/VS COBOL programs to COBOL for OS/390 & VM.
RELATED REFERENCES
“NUMPROC” on page 283
It can happen that values are passed into your program and assigned to items that
have incompatible data descriptions for those values. For example, nonnumeric
data might be moved or passed into a field that is defined as numeric. Or a signed
number might be passed into a field that is defined as unsigned. In both cases, the
receiving fields contain invalid data. Ensure that the contents of a data item
conform to its PICTURE and USAGE clauses before using the data item in any further
processing steps.
You can use the numeric class test to perform data validation. For example:
Linkage Section.
01 Count-x Pic 999.
. . .
Procedure Division Using Count-x.
If Count-x is numeric then display “Data is good”
The numeric class test checks the contents of a data item against a set of values
that are valid for the particular PICTURE and USAGE of the data item. For example, a
packed-decimal item is checked for hexadecimal values X’0’ through X’9’ in the
digit positions, and for a valid sign value in the sign position (whether separate or
nonseparate).
If NUMCLS(PRIM) is in effect at your installation, use the following table to find the
values that the compiler considers valid for the sign.
If NUMCLS(ALT) is in effect at your installation, use the following table to find the
values that the compiler considers valid for the sign.
RELATED REFERENCES
“NUMPROC” on page 283
42 Programming Guide
Performing arithmetic
You can use any of several COBOL language features to perform arithmetic:
v COMPUTE, ADD, SUBTRACT, MULTIPLY, and DIVIDE statements
v Arithmetic expressions
v Intrinsic functions
v Language Environment callable services
Some arithmetic might be more intuitive using arithmetic statements other than
COMPUTE. For example:
You might also prefer to use the DIVIDE statement (with its REMAINDER phrase) for
division in which you want to process a remainder. The REM intrinsic function also
provides the ability to process a remainder.
Arithmetic expressions
| You can use arithmetic expressions in many (but not all) places in statements
where numeric data items are allowed. For example, you can use arithmetic
expressions as comparands in relation conditions:
If (a + b) > (c - d + 5) Then. . .
Arithmetic expressions can consist of a single numeric literal, a single numeric data
item, or a single intrinsic function reference. They can also consist of several of
these items connected by arithmetic operators. Arithmetic operators are evaluated
in the following order of precedence:
Operators at the same level of precedence are evaluated from left to right;
however, you can use parentheses to change the order of evaluation. Expressions
in parentheses are evaluated before the individual operators are evaluated.
Parentheses, necessary or not, make your program easier to read.
Numeric intrinsic functions return a signed numeric value. They are treated as
temporary numeric data items.
You can use intrinsic functions to perform several different arithmetic operations,
as outlined in the following table.
44 Programming Guide
Nesting functions and arithmetic expressions
You can reference one function as the argument of another. A nested function is
evaluated independently of the outer function, except when determining whether a
mixed function should be evaluated using fixed-point or floating-point
instructions.
In this example, there are only three function arguments: a, b, and the arithmetic
expression (c / d).
You can use the integer special registers as arguments wherever integer arguments
are allowed.
| So for example (considering the first row of the table), if you compile using
| ARITH(COMPAT), CEESDACS returns the same result as ACOS. If you compile using
| ARITH(EXTEND), CEESQACS returns the same result as ACOS.
| 1. RANDOM returns a long (64-bit) floating-point result even if you pass it a 31-digit
| argument and compile using option ARITH(EXTEND).
Both the RANDOM intrinsic function and CEERAN0 service generate random
numbers between zero and one. However, because each uses its own algorithm,
RANDOM and CEERAN0 produce different random numbers from the same seed.
Even for functions that produce the same results, how you use intrinsic functions
and Language Environment callable services differs. The rules for the data types
required for intrinsic function arguments are less restrictive. For numeric intrinsic
functions, you can use arguments that are of any numeric data type. When you
invoke a Language Environment callable service with a CALL statement, however,
you must ensure that the parameters match the numeric data types required by
that service (generally COMP-1 or COMP-2).
This means that if you use INTDATE(LILIAN), you get equivalent results from
COBOL intrinsic functions and Language Environment callable date services.
46 Programming Guide
RELATED CONCEPTS
“Fixed-point versus floating-point arithmetic” on page 49
“Appendix A. Intermediate results and arithmetic precision” on page 559
RELATED TASKS
“Using Language Environment callable services” on page 553
RELATED REFERENCES
“ARITH” on page 262
Finance
Business investment decisions frequently require computing the present value of
expected future cash inflows to evaluate the profitability of a planned investment.
You can use the ANNUITY function in business problems that require you to
determine the amount of an installment payment (annuity) necessary to repay the
principal and interest of a loan. The series of payments is characterized by an
equal amount each period, periods of equal length, and an equal interest rate each
period. The following example shows how you can calculate the monthly payment
required to repay a $15,000 loan in three years at a 12% annual interest rate (36
monthly payments, interest per month = .12/12):
01 Loan Pic 9(9)V99.
01 Payment Pic 9(9)V99.
01 Interest Pic 9(9)V99.
01 Number-Periods Pic 99.
. . .
Compute Loan = 15000
Compute Interest = .12
Compute Number-Periods = 36
Compute Payment =
Loan * Function Annuity((Interest / 12) Number-Periods)
Mathematics
The following COBOL statement demonstrates that you can nest intrinsic
functions, use arithmetic expressions as arguments, and perform previously
complex calculations simply:
Compute Z = Function Log(Function Sqrt (2 * X + 1)) + Function Rem(X 2)
Here in the addend the intrinsic function REM (instead of a DIVIDE statement with a
REMAINDER clause) returns the remainder of dividing X by 2.
Statistics
Intrinsic functions make calculating statistical information easier. Assume you are
analyzing various city taxes and want to calculate the mean, median, and range
(the difference between the maximum and minimum taxes):
01 Tax-S Pic 99v999 value .045.
01 Tax-T Pic 99v999 value .02.
01 Tax-W Pic 99v999 value .035.
01 Tax-B Pic 99v999 value .03.
01 Ave-Tax Pic 99v999.
01 Median-Tax Pic 99v999.
01 Tax-Range Pic 99v999.
. . .
48 Programming Guide
Compute Ave-Tax = Function Mean (Tax-S Tax-T Tax-W Tax-B)
Compute Median-Tax = Function Median (Tax-S Tax-T Tax-W Tax-B)
Compute Tax-Range = Function Range (Tax-S Tax-T Tax-W Tax-B)
Floating-point evaluations
In general, if your arithmetic coding has either of the characteristics listed below, it
is evaluated in floating-point arithmetic:
v An operand or result field is floating point.
A data item is floating point if you code it as a floating-point literal or if you
define it as USAGE COMP-1, USAGE COMP-2, or external floating point (USAGE
DISPLAY with a floating-point PICTURE).
An operand that is a nested arithmetic expression or a reference to a numeric
intrinsic function results in floating-point arithmetic when any of the following
is true:
– An argument in an arithmetic expression results in floating point.
– The function is a floating-point function.
– The function is a mixed function with one or more floating-point arguments.
v An exponent contains decimal places.
An exponent contains decimal places if you use a literal that contains decimal
places, give the item a PICTURE containing decimal places, or use an arithmetic
expression or function whose result has decimal places.
An arithmetic expression or numeric function yields a result with decimal places if
any operand or argument (excluding divisors and exponents) has decimal places.
Fixed-point evaluations
In general, if an arithmetic operation contains neither of the characteristics listed
above for floating point, the compiler will cause it to be evaluated in fixed-point
arithmetic. In other words, arithmetic evaluations are handled as fixed point only if
all the operands are fixed point, the result field is defined to be fixed point, and
none of the exponents represent values with decimal places. Nested arithmetic
expressions and function references must also represent fixed-point values.
Implicit comparisons (no relational operator used) are not handled as a unit,
however; the two comparands are treated separately as to their evaluation in
floating-point or fixed-point arithmetic. In the following example, five arithmetic
expressions are evaluated independently of one another’s attributes, and then are
compared to each other.
evaluate (a + d)
when (b + e) thru c
when (f / g) thru (h * i)
. . .
end-evaluate
RELATED REFERENCES
“Arithmetic expressions in nonarithmetic statements” on page 568
50 Programming Guide
compute report-matrix-col = (emp-count ** .5) + 1
compute report-matrix-col = function sqrt(emp-count) + 1
if report-matrix-tot < function sqrt(emp-count) + 1
To specify the symbols for displaying financial information, use the CURRENCY SIGN
clause (in the SPECIAL-NAMES paragraph in the CONFIGURATION SECTION) with the
PICTURE characters that relate to the symbols. In the following example, the
PICTURE character $ indicates that the currency sign $US is to be used:
Currency Sign is “$US” with Picture Symbol “$”.
. . .
77 Invoice-Amount Pic $$,$$9.99.
. . .
Display “Invoice amount is ” Invoice-Amount.
In this example, if Invoice-Amount contained 1500.00, the display output would be:
Invoice amount is $US1,500.00
By using more than one CURRENCY SIGN clause in your program, you can allow for
multiple currency signs to be displayed.
You can use a hexadecimal literal to indicate the currency sign value. This could be
useful if the data-entry method for the source program does not allow the entry of
the intended characters easily. The following example shows the hex value X’9F’
used as the currency sign:
Currency Sign X'9F' with Picture Symbol 'U'.
. . .
01 Deposit-Amount Pic UUUUU9.99.
If there is no corresponding character for the euro sign on your keyboard, you
need to specify it as a hexadecimal value in the CURRENCY SIGN clause. The
hexadecimal value for the euro sign is either X’9F’ or X’5A’ depending on the code
page in use, as shown in the following table.
Modified
Code page Applicable countries from Euro sign
IBM-1140 USA, Canada, Netherlands, Portugal, IBM-037 X’9F’
Australia, New Zealand
IBM-1141 Austria, Germany IBM-273 X’9F’
IBM-1142 Denmark, Norway IBM-277 X’5A’
The exchange rate used in this example is for illustrative purposes only.
52 Programming Guide
Chapter 4. Handling tables
A table is a collection of data items that have the same description, such as account
totals or monthly averages. A table is the COBOL equivalent of an array of
elements. It consists of a table name and subordinate items called table elements.
In the example above, SAMPLE-TABLE-ONE is the group item that contains the table.
TABLE-COLUMN names the table element of a one-dimensional table that occurs three
times.
Rather than define repetitious items as separate, consecutive entries in the DATA
DIVISION, you can use the OCCURS clause in the DATA DIVISION entry to define a
table. This practice has these advantages:
v The code clearly shows the unity of the items (the table elements).
v You can use subscripts and indexes to refer to the table elements.
v You can easily repeat data items.
Tables are important for increasing the speed of a program, especially one that
looks up records.
RELATED TASKS
“Defining a table (OCCURS)”
“Referring to an item in a table” on page 55
“Putting values into a table” on page 58
“Nesting tables” on page 54
“Creating variable-length tables (DEPENDING ON)” on page 62
“Searching a table” on page 65
“Processing table items using intrinsic functions” on page 67
“Handling tables efficiently” on page 539
The table element definition (which includes the OCCURS clause) is subordinate to
the group item that contains the table. The OCCURS clause cannot appear in a
level-01 description.
RELATED REFERENCES
OCCURS clause (IBM COBOL Language Reference)
Nesting tables
To create a two-dimensional table, define a one-dimensional table in each
occurrence of another one-dimensional table. For example:
Subscripting
In a two-dimensional table, the two subscripts correspond to the row and column
numbers. In a three-dimensional table, the three subscripts correspond to the
depth, row, and column numbers.
54 Programming Guide
TABLE-COLUMN (2, 2, 1)
TABLE-COLUMN (2 2 1)
In either table reference, the first value (2) refers to the second occurrence within
TABLE-DEPTH, the second value (2) refers to the second occurrence within TABLE-ROW,
and the third value (1) refers to the first occurrence within TABLE-COLUMN.
Indexing
Consider the following three-dimensional table, SAMPLE-TABLE-FOUR:
01 SAMPLE-TABLE-FOUR
05 TABLE-DEPTH OCCURS 3 TIMES INDEXED BY INX-A.
10 TABLE-ROW OCCURS 4 TIMES INDEXED BY INX-B.
15 TABLE-COLUMN OCCURS 8 TIMES INDEXED BY INX-C PIC X(8).
RELATED REFERENCES
OCCURS clause (IBM COBOL Language Reference)
Subscripting
The lowest possible subscript value is 1, which points to the first occurrence of the
table element. In a one-dimensional table, the subscript corresponds to the row
number.
If a data item with a literal subscript is of fixed length, the compiler resolves the
location of the data item.
When you use a data name as a variable subscript, you must describe the data
name as an elementary numeric integer. The most efficient format is COMPUTATIONAL
(COMP) with a PICTURE size smaller than five digits. You cannot use a subscript with
a data name that is used as a subscript.
The code generated for the application resolves the location of a variable subscript
at run time.
You can change part of a table element rather than the whole element. Simply refer
to the character position and length of the substring to be changed within the
subscripted element. For example:
01 ANY-TABLE.
05 TABLE-ELEMENT PIC X(10)
OCCURS 3 TIMES
VALUE “ABCDEFGHIJ”.
. . .
MOVE “??” TO TABLE-ELEMENT (1) (3 : 2).
The MOVE statement moves the value ?? into table element number 1, beginning at
character position 3, for a length of 2:
RELATED TASKS
“Indexing” on page 57
56 Programming Guide
“Putting values into a table” on page 58
“Searching a table” on page 65
“Handling tables efficiently” on page 539
Indexing
You can create an index either with a particular table (using OCCURS INDEXED BY) or
separately (using USAGE IS INDEX).
For example:
05 TABLE-ITEM PIC X(8)
OCCURS 10 INDEXED BY INX-A.
The compiler calculates the value contained in the index as the occurrence number
(subscript) minus 1, multiplied by the length of the table element. Therefore, for
the fifth occurrence of TABLE-ITEM, the binary value contained in INX-A is (5 - 1) * 8,
or 32.
You can use this index to index another table only if both table descriptions have
the same number of table elements, and the table elements are the same length.
If you use USAGE IS INDEX to create an index, you can use the index data item with
any table. For example:
77 INX-B USAGE IS INDEX.
. . .
PERFORM VARYING INX-B FROM 1 BY 1 UNTIL INX-B > 10
DISPLAY TABLE-ITEM (INX-B)
. . .
END-PERFORM.
INX-B is used to traverse table TABLE-ITEM above, but could be used to traverse
other tables also.
Initialize the index name with a SET, PERFORM VARYING, or SEARCH ALL statement.
You can then also use it in SEARCH or relational condition statements. To change the
value, use a PERFORM, SEARCH, or SET statement.
Use the SET statement to assign to an index the value that you stored in the index
data item defined by USAGE IS INDEX. For example, when you load records into a
variable-length table, you can store the index value of the last record read in a data
item defined as USAGE IS INDEX. Then you can test for the end of the table by
comparing the current index value with the index value of the last record. This
technique is useful when you look through or process the table.
Because you are comparing a physical displacement, you can use index data items
only in SEARCH and SET statements or for comparisons with indexes or other index
data items. You cannot use index data items as subscripts or indexes.
RELATED TASKS
“Subscripting” on page 56
“Putting values into a table” on page 58
RELATED REFERENCES
INDEXED BY phrase (IBM COBOL Language Reference)
INDEX phrase (IBM COBOL Language Reference)
To load a table, use the PERFORM statement and either subscripting or indexing.
When reading data to load your table, test to make sure that the data does not
exceed the space allocated for the table. Use a named value (rather than a literal)
for the item count. Then, if you make the table bigger, you need to change only
one value, instead of all references to a literal.
RELATED REFERENCES
PERFORM with VARYING phrase (IBM COBOL Language Reference)
The INITIALIZE statement cannot load a variable-length table (one that was defined
using OCCURS DEPENDING ON).
RELATED REFERENCES
INITIALIZE statement (IBM COBOL Language Reference)
58 Programming Guide
Define static values in WORKING-STORAGE in one of these ways:
v Initialize each table item individually.
v Initialize an entire table at the 01 level.
v Initialize all occurrences of a given table element to the same value.
(In this example, the items could all be initialized with one VALUE clause at the 01
level, because each item was being initialized to the same value.)
For example:
01 TABLE-ONE VALUE “1234”.
05 TABLE-TWO OCCURS 4 TIMES PIC X.
The above code causes all the X elements (1 through 5) to be initialized to AA, all
the Y elements (1 through 5) to be initialized to 19, and all the Z elements (1
through 5) to be initialized to BB. T-OBJ is then set to 3.
60 Programming Guide
Example: PERFORM and indexing
This example traverses an error flag table using indexing until an error code that
has been set is found. If an error code is found, the corresponding error message is
moved to a print report field.
. . .
***********************************************************
*** E R R O R F L A G T A B L E ***
***********************************************************
01 Error-Flag-Table Value Spaces.
88 No-Errors Value Spaces.
05 Type-Error Pic X.
05 Shift-Error Pic X.
05 Home-Code-Error Pic X.
05 Work-Code-Error Pic X.
05 Name-Error Pic X.
05 Initials-Error Pic X.
05 Duplicate-Error Pic X.
05 Not-Found-Error Pic X.
01 Filler Redefines Error-Flag-Table.
05 Error-Flag Occurs 8 Times
Indexed By Flag-Index Pic X.
***********************************************************
*** E R R O R M E S S A G E T A B L E ***
***********************************************************
01 Error-Message-Table.
05 Filler Pic X(25) Value
“Transaction Type Invalid”.
05 Filler Pic X(25) Value
“Shift Code Invalid”.
05 Filler Pic X(25) Value
“Home Location Code Inval.”.
05 Filler Pic X(25) Value
“Work Location Code Inval.”.
05 Filler Pic X(25) Value
“Last Name - Blanks”.
05 Filler Pic X(25) Value
“Initials - Blanks”.
05 Filler Pic X(25) Value
“Duplicate Record Found”.
05 Filler Pic X(25) Value
“Commuter Record Not Found”.
01 Filler Redefines Error-Message-Table.
05 Error-Message Occurs 8 Times
Indexed By Message-Index Pic X(25).
. . .
PROCEDURE DIVISION.
. . .
Set Flag-Index To 1
Perform Until No-Errors
Search Error-Flag
When Error-Flag (Flag-Index) = Error-On
Move Space To Error-Flag (Flag-Index)
Set Message-Index To Flag-Index
Move Error-Message (Message-Index) To
Print-Message
Perform 260-Print-Report
End-Search
End-Perform
. . .
In this example, X is called the ODO subject, and Y is the ODO object.
If you want to move REC-1 (the sending item in this case) to REC-2, the length of
REC-1 is determined immediately before the move, using the current value in
FIELD-1. If the content of FIELD-1 conforms to its PICTURE (that is, if FIELD-1
contains an external decimal item), the move can proceed based on the actual
length of REC-1. Otherwise, the result is unpredictable. You must ensure that the
ODO object has the correct value before you initiate the move.
When you do a move to REC-1 (the receiving item in this case), the length of REC-1
is determined using the maximum number of occurrences. In this example, that
would be five occurrences of FIELD-2, plus FIELD-1, for a length of 26 bytes.
In this case, you need not set the ODO object (FIELD-1) before referencing REC-1 as
a receiving item. However, the sending field’s ODO object (not shown) must be set
to a valid numeric value between 1 and 5 for the ODO object of the receiving field
to be validly set by the move.
However, if you do a move to REC-1 (again the receiving item) where REC-1 is
followed by a variably located group (a type of complex ODO), the actual length of
REC-1 is calculated immediately before the move. In the following example, REC-1
and REC-2 are in the same record, but REC-2 is not subordinate to REC-1 and is
therefore variably located:
62 Programming Guide
01 MAIN-AREA
03 REC-1.
05 FIELD-1 PIC 9.
05 FIELD-3 PIC 9.
05 FIELD-2 OCCURS 1 TO 5 TIMES
DEPENDING ON FIELD-1 PIC X(05).
03 REC-2.
05 FIELD-4 OCCURS 1 TO 5 TIMES
DEPENDING ON FIELD-3 PIC X(05).
When you do a MOVE to REC-1 in this case, the actual length of REC-1 is calculated
immediately before the move using the current value of the ODO object (FIELD-1).
The compiler issues a message letting you know that the actual length was used.
This case requires that you set the value of the ODO object before using the group
item as a receiving field.
The following example shows how to define a variable-length table when the ODO
object (here LOCATION-TABLE-LENGTH) is outside the group.
DATA DIVISION.
FILE SECTION.
FD LOCATION-FILE
RECORDING MODE F
BLOCK 0 RECORDS
RECORD 80 CHARACTERS
LABEL RECORD STANDARD.
01 LOCATION-RECORD.
05 LOC-CODE PIC XX.
05 LOC-DESCRIPTION PIC X(20).
05 FILLER PIC X(58).
. . .
WORKING-STORAGE SECTION.
01 FLAGS.
05 LOCATION-EOF-FLAG PIC X(5) VALUE SPACE.
88 LOCATION-EOF VALUE “FALSE”.
01 MISC-VALUES.
05 LOCATION-TABLE-LENGTH PIC 9(3) VALUE ZERO.
05 LOCATION-TABLE-MAX PIC 9(3) VALUE 100.
*****************************************************************
*** L O C A T I O N T A B L E ***
*** FILE CONTAINS LOCATION CODES. ***
*****************************************************************
01 LOCATION-TABLE.
05 LOCATION-CODE OCCURS 1 TO 100 TIMES
DEPENDING ON LOCATION-TABLE-LENGTH PIC X(80).
RELATED CONCEPTS
“Appendix B. Complex OCCURS DEPENDING ON” on page 569
RELATED TASKS
“Assigning values to a variable-length table” on page 64
“Loading a variable-length table”
COBOL for OS/390 & VM Compiler and Run-Time Migration Guide
RELATED REFERENCES
OCCURS DEPENDING ON clause (IBM COBOL Language Reference)
“CMPR2” on page 264
If the ODO object has a VALUE clause, it is logically initialized after the ODO subject
has been initialized. For example, in the following code
01 TABLE-THREE VALUE “3ABCDE”.
05 X PIC 9.
05 Y OCCURS 5 TIMES
DEPENDING ON X PIC X.
the ODO subject Y(1) is initialized to A, Y(2) to B, . . ., Y(5) to E, and finally the
ODO object X is initialized to 3. Any subsequent reference to TABLE-THREE (such as
in a DISPLAY statement) refers to the first three elements, Y(1) through Y(3).
RELATED TASKS
COBOL for OS/390 & VM Compiler and Run-Time Migration Guide
64 Programming Guide
RELATED REFERENCES
OCCURS DEPENDING ON clause (IBM COBOL Language Reference)
“CMPR2” on page 264
Searching a table
COBOL provides two search techniques for tables: serial and binary.
To do serial searches, use SEARCH and indexing. For variable-length tables, you can
use PERFORM with subscripting or indexing.
A binary search can be considerably more efficient than a serial search. For a serial
search, the number of comparisons is of the order of n, the number of entries in
the table. For a binary search, the number of comparisons is only of the order of
the logarithm (base 2) of n. A binary search, however, requires that the table items
already be sorted.
RELATED TASKS
“Doing a serial search (SEARCH)”
“Doing a binary search (SEARCH ALL)” on page 66
The conditions in the WHEN option are evaluated in the order in which they appear:
v If none of the conditions is satisfied, the index is increased to correspond to the
next table element, and the WHEN conditions are evaluated again.
v If one of the WHEN conditions is satisfied, the search ends. The index remains
pointing to the table element that satisfied the condition.
v If the entire table has been searched and no conditions were met, the AT END
imperative statement is executed if there is one. If you do not use AT END,
control passes to the next statement in your program.
You can reference only one level of a table (a table element) with each SEARCH
statement. To search multiple levels of a table, use nested SEARCH statements.
Delimit each nested SEARCH statement with END-SEARCH.
If the found condition comes after some intermediate point in the table, you can
speed up the search. Use the SET statement to set the index to begin the search
after that point.
Arranging the table so that the data used most often is at the beginning also
enables more efficient serial searching. If the table is large and is presorted, a
binary search is more efficient.
RELATED REFERENCES
SEARCH statement (IBM COBOL Language Reference)
To use the SEARCH ALL statement, your table must already be ordered on the key or
keys coded in the OCCURS clause. You can use any key in the WHEN condition, but
you must test all preceding data names in the KEY option, if any. The test must be
an equal-to condition, and the KEY data-name must be either the subject of the
condition or the name of a conditional variable with which the tested
condition-name is associated. The WHEN condition can also be a compound
condition, formed from simple conditions with AND as the only logical connective.
The key and its object of comparison must be compatible.
RELATED REFERENCES
SEARCH statement (IBM COBOL Language Reference)
66 Programming Guide
Example: binary search
Suppose you define a table that contains 90 elements of 40 bytes each, with three
keys. The primary and secondary keys (KEY-1 and KEY-2) are in ascending order,
but the least significant key (KEY-3) is in descending order:
01 TABLE-A.
05 TABLE-ENTRY OCCURS 90 TIMES
ASCENDING KEY-1, KEY-2
DESCENDING KEY-3
INDEXED BY INDX-1.
10 PART-1 PIC 99.
10 KEY-1 PIC 9(5).
10 PART-2 PIC 9(6).
10 KEY-2 PIC 9(4).
10 PART-3 PIC 9(18).
10 KEY-3 PIC 9(5).
If an entry is found in which the three keys are equal to the given values (VALUE-1,
VALUE-2, and VALUE-3), PART-1 of that entry will be moved to OUTPUT-AREA. If
matching keys are not found in any of the entries in TABLE-A, the NOENTRY routine
is performed.
You might often need to process the data in tables iteratively. For intrinsic
functions that accept multiple arguments, you can use the ALL subscript to
reference all the items in the table or a single dimension of the table. The iteration
is handled automatically, making your code shorter and simpler.
You can mix scalars and array arguments for functions that accept multiple
arguments:
Compute Table-Median = Function Median(Arg1 Table-One(ALL))
RELATED TASKS
“Using intrinsic functions (built-in functions)” on page 31
RELATED REFERENCES
Intrinsic functions (IBM COBOL Language Reference)
Assuming that Table-Two is a 2x3x2 array, the statement above causes the
following elements to be summed:
Table-Two(1,3,1)
Table-Two(1,3,2)
Table-Two(2,3,1)
Table-Two(2,3,2)
68 Programming Guide
Chapter 5. Selecting and repeating program actions
Use COBOL control language to choose program actions based on the outcome of
logical tests, to iterate over selected parts of your program and data, and to
identify statements to be performed as a group. These controls include:
v IF statement
v EVALUATE statement
v Switches and flags
v PERFORM statement
RELATED TASKS
“Selecting program actions”
“Repeating program actions” on page 76
The IF and EVALUATE statements in COBOL test one or more data items by means
of a conditional expression.
RELATED TASKS
“Coding a choice of actions”
“Coding conditional expressions” on page 73
RELATED REFERENCES
IF statement (IBM COBOL Language Reference)
EVALUATE statement (IBM COBOL Language Reference)
When one of the processing choices is no action, code the IF statement with or
without ELSE. Because the ELSE clause is optional, you can code the following:
IF condition-q
statement-1
END-IF
This coding is suitable for simple programming cases. For complex logic, you
probably need to use the ELSE clause. For example, suppose you have nested IF
statements with an action for only one of the processing choices; you could use the
ELSE clause and code the null branch of the IF statement with the CONTINUE
statement:
Use the EVALUATE statement to code a choice among three or more possible
conditions instead of just two. The EVALUATE statement is an expanded form of the
IF statement that allows you to avoid nesting IF statements for such coding, a
common source of logic errors and debugging problems.
With the EVALUATE statement, you can test any number of conditions in a single
statement and have separate actions for each. In structured programming terms,
this is a case structure. It can also be thought of as a decision table.
RELATED TASKS
“Coding conditional expressions” on page 73
“Using the EVALUATE statement” on page 71
“Using nested IF statements”
Use nested IF statements sparingly. The logic can be difficult to follow, although
explicit scope terminators and proper indentation help.
The following figure shows the logic structure for nested IF statements.
70 Programming Guide
RELATED TASKS
“Coding a choice of actions” on page 69
RELATED REFERENCES
Explicit scope terminators (IBM COBOL Language Reference)
You can code the EVALUATE statement to handle the case where multiple conditions
lead to the same processing by using the THRU phrase and by using multiple WHEN
statements.
When evaluated, each pair of selection subjects and selection objects must belong
to the same class (numeric, character, CONDITION TRUE or FALSE).
RELATED TASKS
“Coding a choice of actions” on page 69
Example: EVALUATE using multiple WHEN statements: You can use multiple
WHEN statements when several conditions lead to the same processing action. This
gives you more flexibility than using the THRU phrase, because the conditions do
not have to evaluate to values that fall in a range or evaluate to alphanumeric
values.
EVALUATE MARITAL-CODE
WHEN “M”
ADD 2 TO PEOPLE-COUNT
WHEN “S”
WHEN “D”
WHEN “W”
ADD 1 TO PEOPLE-COUNT
END-EVALUATE
72 Programming Guide
Configuration Section.
Source-Computer. IBM-390.
Data Division.
Working-Storage Section.
01 Age Pic 999.
01 Sex Pic X.
01 Description Pic X(15).
01 A Pic 999.
01 B Pic 9999.
01 C Pic 9999.
01 D Pic 9999.
01 E Pic 99999.
01 F Pic 999999.
Procedure Division.
PN01.
Evaluate True Also True
When Age < 13 Also Sex = “M”
Move “Young Boy” To Description
When Age < 13 Also Sex = “F”
Move “Young Girl” To Description
When Age > 12 And Age < 20 Also Sex = “M”
Move “Teenage Boy” To Description
When Age > 12 And Age < 20 Also Sex = “F”
Move “Teenage Girl” To Description
When Age > 19 Also Sex = “M”
Move “Adult Man” To Description
When Age > 19 Also Sex = “F”
Move “Adult Woman” To Description
When Other
Move “Invalid Data” To Description
End-Evaluate
Evaluate True Also True
When A + B < 10 Also C = 10
Move “Case 1” To Description
When A + B > 50 Also C = ( D + E ) / F
Move “Case 2” To Description
When Other
Move “Case Other” To Description
End-Evaluate
Stop Run.
RELATED TASKS
“Defining switches and flags” on page 74
“Resetting switches and flags” on page 75
“Checking for incompatible data (numeric class test)” on page 42
Flags and switches make your code easier to change. If you need to change the
values for a condition, you have to change only the value of that level-88
condition-name.
For example, suppose a program uses a condition-name to test a field for a given
salary range. If the program must be changed to check for a different salary range,
you need to change only the value of the condition-name in the DATA DIVISION.
You do not need to make changes in the PROCEDURE DIVISION.
RELATED TASKS
“Defining switches and flags”
“Resetting switches and flags” on page 75
To test for more than two values, as flags, assign more than one condition name to
a field by using multiple level-88 items.
The reader can easily follow your code if you choose meaningful condition names
and if the values assigned have some association with logical values.
“Example: switches”
“Example: flags” on page 75
Example: switches
To test for an end-of-file condition for an input file named Transaction-File, you
could use the following data definitions:
WORKING-STORAGE Section.
01 Switches.
05 Transaction-EOF-Switch Pic X value space.
88 Transaction-EOF value “y”.
74 Programming Guide
If Transaction-EOF Then
Perform Print-Report-Summary-Lines
Example: flags
Consider a program that updates a master file. The updates are read from a
transaction file. The transaction file’s records contain a field for the function to be
performed: add, change, or delete. In the record description of the input file code a
field for the function code using level-88 items:
01 Transaction-Input Record
05 Transaction-Type Pic X.
88 Add-Transaction Value “A”.
88 Change-Transaction Value “C”.
88 Delete-Transaction Value “D”.
The code in the PROCEDURE DIVISION for testing these condition-names might look
like this:
Evaluate True
When Add-Transaction
Perform Add-Master-Record-Paragraph
When Change-Transaction
Perform Update-Exisitng-Record-Paragraph
When Delete-Transaction
Perform Delete-Master-Record-Paragraph
End-Evaluate
When you use the SET condition-name TO TRUE statement, the switch or flag is set
back to the original value that was assigned in its data description.
For a level-88 item with multiple values, SET condition-name TO TRUE assigns the
first value (here, A):
88 Record-is-Active Value “A” “O” “S”
Using the SET statement and meaningful condition-names makes it easy for the
reader to follow your code.
The following example shows how to assign a value for a field in an output record
based on the transaction code of an input record.
This code resets the switch to indicate that the end of the file has not been reached.
Use the PERFORM statement to loop (repeat the same code) a set number of times or
to loop based on the outcome of a decision.
RELATED TASKS
“Choosing inline or out-of-line PERFORM”
“Coding a loop” on page 77
“Coding a loop through a table” on page 78
“Executing multiple paragraphs or sections” on page 79
RELATED REFERENCES
PERFORM statement (IBM COBOL Language Reference)
76 Programming Guide
To determine whether to code an inline or out-of-line PERFORM statement, consider
the following questions:
v Is the PERFORM statement used from several places?
Use out-of-line PERFORM when you use the same piece of code from several
places in your program.
v Which placement of the statement will be easier to read?
Use an out-of-line PERFORM if the logical flow of the program will be less clear
because the PERFORM extends over several screens. If, however, the PERFORM
paragraph is short, an inline PERFORM can save the trouble of skipping around in
the code.
v What are the efficiency tradeoffs?
Avoid the overhead of branching around an out-of-line PERFORM if performance is
an issue. But remember, even out-of-line PERFORM coding can improve code
optimization, so efficiency gains should not be overemphasized.
In the 1974 COBOL standard, the PERFORM statement is out-of-line and thus requires
an explicit branch to a separate paragraph and has an implicit return. If the
performed paragraph is in the subsequent sequential flow of your program, it is
also executed in that flow of the logic. To avoid this additional execution, you
must place the paragraph outside the normal sequential flow (for example, after
the GOBACK) or code a branch around it.
Coding a loop
Use the PERFORM . . . TIMES statement to execute a paragraph a certain number of
times:
PERFORM 010-PROCESS-ONE-MONTH 12 TIMES
INSPECT . . .
Use the PERFORM . . . WITH TEST AFTER . . . UNTIL if you want to execute the
paragraph at least once and then test before any subsequent execution. This
statement is equivalent to the do-until structure:
In the following example, the implicit WITH TEST BEFORE phrase provides a
do-while structure:
PERFORM 010-PROCESS-ONE-MONTH
UNTIL MONTH GREATER THAN 12
INSPECT . . .
When control reaches the PERFORM statement, the condition (MONTH EQUAL DECEMBER)
is tested. If the condition is satisfied, control is transferred to the INSPECT
statement. If the condition is not satisfied, 010-PROCESS-ONE-MONTH is executed, and
the condition is tested again. This cycle continues until the condition tests as true.
(To make your program easier to read, you might want to code the WITH TEST
BEFORE clause.)
Thus you use the PERFORM statement to control a loop through a table. You can use
either of the following forms:
PERFORM . . . WITH TEST AFTER . . . VARYING . . . UNTIL . . .
PERFORM . . . [WITH TEST BEFORE] . . . VARYING . . . UNTIL .
The following code shows an example of looping through a table to check for
invalid data:
78 Programming Guide
PERFORM TEST AFTER VARYING WS-DATA-IX
FROM 1 BY 1
UNTIL WS-DATA-IX = 12
IF WS-DATA (WS-DATA-IX) EQUALS SPACES
SET SERIOUS-ERROR TO TRUE
DISPLAY ELEMENT-NUM-MSG5
END-IF
END-PERFORM
INSPECT . . .
In the code above, when control reaches the PERFORM statement, WS-DATA-IX is set
equal to 1 and the PERFORM statement is executed. Then the condition
(WS-DATA-IX = 12) is tested. If the condition is true, control drops through to the
INSPECT statement. If it is false, WS-DATA-IX is increased by 1, the PERFORM statement
is executed, and the condition is tested again. This cycle of execution and testing
continues until WS-DATA-IX is equal to 12.
In terms of the application, this loop controls input-checking for the 12 fields of
item WS-DATA. Empty fields are not allowed, and this section of code loops through
and issues error messages as appropriate.
Intrinsic functions can make the coding of the iterative processing of tables simpler
and easier.
RELATED TASKS
“Processing table items using intrinsic functions” on page 67
The STRING statement transfers data items into the receiving item in the order you
indicate. In the STRING statement you can also specify the following:
v Delimiters that cause a sending field to be ended and another to be started
v Actions to be taken when the single receiving field is filled before all of the
sending characters have been processed (ON OVERFLOW condition)
“Example: STRING statement”
RELATED TASKS
“Handling errors in joining and splitting strings” on page 190
RELATED REFERENCES
STRING statement (IBM COBOL Language Reference)
The record RCD-01 contains the following information (the symbol º indicates a
blank space):
J.B.ºSMITHººººº
444ºSPRINGºST.,ºCHICAGO,ºILL.ºººººº
A14275
$4,736.85
$2,400.00
09/22/76
$2,336.85
10/22/76
In the PROCEDURE DIVISION, the programmer initializes RPT-LINE to SPACES and sets
LINE-POS, the data item to be used as the POINTER field, to 4. (By coding the
POINTER phrase of the STRING statement, you can use the explicit pointer field to
control placement of data in the receiving field.) Then, the programmer codes this
STRING statement:
STRING
LINE-NO SPACE CUST-INFO INV-NO SPACE DATE-DUE SPACE
DELIMITED BY SIZE
BAL-DUE
DELIMITED BY DEC-POINT
INTO RPT-LINE
WITH POINTER LINE-POS.
Item Positions
LINE-NO 4-8
Space 9
CUST-INFO 10 - 59
INV-NO 60 - 65
Space 66
DATE-DUE 67 - 74
Space 75
Portion of BAL-DUE that precedes the decimal point 76 - 81
After the STRING statement is performed, the value of LINE-POS is 82, and RPT-LINE
appears as shown below.
82 Programming Guide
Splitting data items (UNSTRING)
Use the UNSTRING statement to split one sending field into several receiving fields.
One UNSTRING statement can save you several MOVE statements.
RELATED TASKS
“Handling errors in joining and splitting strings” on page 190
COBOL for OS/390 & VM Compiler and Run-Time Migration Guide
RELATED REFERENCES
“CMPR2” on page 264
UNSTRING statement (IBM COBOL Language Reference)
Before issuing the UNSTRING statement, the programmer places the value 3 in
CHAR-CT (the POINTER field) to avoid working with the two control characters in
INV-RCD. A period (.) is placed in DBY-1 for use as a delimiter, and the value 0
(zero) is placed in FLDS-FILLED (the TALLYING field). The data is then read into
INV-RCD, as shown below.
84 Programming Guide
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
in position 34 is bypassed.
5. Positions 35 through 40 (475120) are examined and placed in M-UNITS. The
value 6 is placed in CTR-3. The delimiter is a SPACE, but because no field has
been defined as a receiving area for delimiters, the SPACE in position 41 is
bypassed.
6. Positions 42 through 46 (00122) are placed in FIELD-A and right-justified in 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 delimiters,
the SPACE in position 47 is bypassed.
7. Positions 48 through 53 (000379) are placed in DISPLAY-DOLS. The period (.)
delimiter character in DBY-1 is placed in DLTR-2, and the value 6 is placed in
CTR-4.
8. Because all receiving fields have been acted on and two characters of data in
INV-RCD have not been examined, the ON OVERFLOW exit is taken, and execution
of the UNSTRING statement is completed.
After the UNSTRING statement is performed, the fields contain the values shown
below.
Field Value
DISPLAY-REC 707890 FOUR-PENNY-NAILS 000379
WORK-REC 475120000122BBA
CHAR-CT (the POINTER field) 55
FLDS-FILLED (the TALLYING field) 6
RELATED REFERENCES
Nonnumeric literals (IBM COBOL Language Reference)
As this example shows, in parentheses immediately following the data item you
code two values separated by a colon:
v Ordinal position (from the left) of the character you want the substring to start
with
v Length of the desired substring
86 Programming Guide
The length is optional. If you omit the length, the substring extends to the end of
the item. Omit the length when possible as a simpler and less error-prone coding
technique.
You can code either of the two values as a variable or as an arithmetic expression.
You can also refer to substrings of table entries, including variable-length entries.
Both numbers in the reference modifier must have a value of at least 1. Their sum
should not exceed the total length of the data item by more than 1 so that you do
not reference beyond the end of the desired substring.
The following options detect out-of-range reference modifiers, and flag violations
with a run-time message:
v SSRANGE compiler option
v CHECK run-time option
RELATED CONCEPTS
“Reference modifiers”
RELATED TASKS
“Referring to an item in a table” on page 55
RELATED REFERENCES
“SSRANGE” on page 294
Reference modification (IBM COBOL Language Reference)
Function definitions (IBM COBOL Language Reference)
Reference modifiers
Assume that you want to retrieve the current time from the system and display its
value in an expanded format. You can retrieve the current time with the ACCEPT
statement, which returns the hours, minutes, seconds, and hundredths of seconds
in this format:
HHMMSSss
However, you might prefer to view the current time in this format:
HH:MM:SS
Without reference modifiers, you would have to define data items for both formats.
You would also have to write code to convert from one format to the other.
With reference modifiers, you do not need to provide names for the subfields that
describe the TIME elements. The only data definition you need is for the time as
returned by the system. For example:
01 REFMOD-TIME-ITEM PIC X(8).
RELATED TASKS
“Referring to substrings of data items” on page 86
The program counts the number of leading spaces and, using arithmetic
expressions in a reference modifier, moves the right-justified characters into
another field, justified to the left:
MOVE SPACES TO LEFTY
MOVE ZERO TO I
INSPECT RIGHTY
TALLYING I FOR LEADING SPACE.
IF I IS LESS THAN LENGTH OF RIGHTY THEN
MOVE RIGHTY ( I + 1 : LENGTH OF RIGHTY - I ) TO LEFTY
END-IF
The MOVE statement transfers characters from RIGHTY, beginning at the position
computed as I + 1 for a length that is computed as LENGTH OF RIGHTY - I, into the
field LEFTY.
88 Programming Guide
RELATED REFERENCES
INTEGER-PART (IBM COBOL Language Reference)
INTEGER (IBM COBOL Language Reference)
RELATED REFERENCES
INSPECT statement (IBM COBOL Language Reference)
In the following example, the INSPECT statement is used to examine and replace
characters in data item DATA-2. The number of times a leading 0 occurs in the data
item is accumulated in COUNTR. Every instance of the character A following the first
instance of the character C is replaced by the character 2.
77 COUNTR PIC 9 VALUE ZERO.
01 DATA-2 PIC X(11).
. . .
INSPECT DATA-2
TALLYING COUNTR FOR LEADING “0”
REPLACING FIRST “A” BY “2” AFTER INITIAL “C”
In the following example, the INSPECT statement is used to examine and replace
characters in data item DATA-3. Every character in the data item preceding the first
instance of a quote (“) is replaced by the character 0.
77 COUNTR PIC 9 VALUE ZERO.
01 DATA-3 PIC X(8).
. . .
INSPECT DATA-3
REPLACING CHARACTERS BY ZEROS BEFORE INITIAL QUOTE
The following example shows the use of INSPECT CONVERTING with AFTER and
BEFORE phrases to examine and replace characters in data item DATA-4. All
After you have processed the DBCS data, use the Language Environment
IGZCD2A service routine to convert the DBCS data items back to nonnumeric data
items containing double-byte characters.
The DBCS compiler option does not affect the operation of these service routines.
RELATED REFERENCES
“DBCS notation”
“Nonnumeric to DBCS data conversion (IGZCA2D)”
“DBCS to nonnumeric data conversion (IGZCD2A)” on page 92
“DBCS” on page 269
DBCS notation
These symbols describe DBCS items:
Symbols Meaning
< and > Shift-out (SO) and Shift-in (SI), respectively
D0, D1, D2, . . ., Dn Any DBCS character except for double-byte EBCDIC
characters
.A, .B, .C, . . . Any double-byte EBCDIC character; the period (.)
represents the value X’42’
A single letter, such as A, B, or s Any single-byte EBCDIC character
90 Programming Guide
IGZCA2D syntax
To use the IGZCA2D service routine, pass the following four parameters to the
routine using the CALL statement:
parameter-1
The sending field for the conversion, handled as a nonnumeric data item.
parameter-2
The receiving field for the conversion, handled as a DBCS data item.
You cannot use reference modification with parameter-2.
parameter-3
The number of bytes in parameter-1 to be converted.
It can be the LENGTH OF special register of parameter-1, or a 4-byte USAGE IS
BINARY data item containing the number of bytes of parameter-1 to be
converted. Shift codes count as 1 byte each.
parameter-4
The number of bytes in parameter-2 that will receive the converted data.
It can be the LENGTH OF special register of parameter-2, or a 4-byte USAGE IS
BINARY data item containing the number of bytes of parameter-2 to receive
the converted data.
Usage notes
v You can pass parameter-1, parameter-3, and parameter-4 to the routine BY
REFERENCE or BY CONTENT, but you must pass parameter-2 BY REFERENCE.
v The compiler does not perform syntax checking on these parameters. Ensure that
the parameters are correctly set and passed to the conversion routine using the
CALL statement. Otherwise, results are unpredictable.
v When creating parameter-2 from parameter-1, IGZCA2D makes these changes:
– Removes the shift codes, leaving the DBCS data unchanged
– Converts the single-byte EBCDIC data to double-byte EBCDIC characters
– Converts EBCDIC space (X’40’) to DBCS space (X’4040’), instead of X’4240’
v IGZCA2D does not change the contents of parameter-1, parameter-3, or
parameter-4.
| v The valid range for the contents of parameter-3 and parameter-4 is 1 to 16,777,215.
“Example: IGZCA2D” on page 92
RELATED REFERENCES
“IGZCA2D return codes”
Example: IGZCA2D
The following CALL statement converts the nonnumeric data in alpha-item to DBCS
data. The results of the conversion are placed in dbcs-item.
CALL “IGZCA2D” USING BY REFERENCE alpha-item dbcs-item
BY CONTENT LENGTH OF alpha-item LENGTH OF dbcs-item
Suppose the contents of alpha-item and dbcs-item and the lengths before the
conversion are:
alpha-item = AB<D1D2D3>CD
dbcs-item = D4D5D6D7D8D9D0
LENGTH OF alpha-item = 12
LENGTH OF dbcs-item = 14
RELATED REFERENCES
“DBCS notation” on page 90
92 Programming Guide
IGZCD2A syntax
To use the IGZCD2A service routine, pass the following four parameters to the
routine using the CALL statement:
parameter-1
The sending field for the conversion, handled as a DBCS data item.
parameter-2
The receiving field for the conversion, handled as a nonnumeric data item.
parameter-3
The number of bytes in parameter-1 to be converted.
It can be the LENGTH OF special register of parameter-1, or a 4-byte USAGE IS
BINARY data item containing the number of bytes of parameter-1 to be
converted.
parameter-4
The number of bytes in parameter-2 that will receive the converted data.
It can be the LENGTH OF special register of parameter-2, or a 4-byte USAGE IS
BINARY data item containing the number of bytes of parameter-2 to receive
the converted data. Shift codes count as 1 byte each.
Usage notes
v You can pass parameter-1, parameter-3, and parameter-4 to the routine BY
REFERENCE or BY CONTENT, but you must pass parameter-2 BY REFERENCE.
v The compiler does not perform syntax checking on these parameters. Ensure that
the parameters are correctly set and passed to the conversion routine. Otherwise,
results are unpredictable.
v When creating parameter-2 from parameter-1, IGZCD2A makes these changes:
– Inserts shift codes around DBCS characters that are not double-byte EBCDIC
characters
– Converts double-byte EBCDIC characters to single-byte EBCDIC characters
– Converts the DBCS space (X’4040’) to an EBCDIC space (X’40’)
v IGZCD2A does not change the contents of parameter-1, parameter-3, or
parameter-4.
v If the converted data contains double-byte characters, shift codes are counted in
the length of parameter-2.
| v The valid range for the contents of parameter-3 and parameter-4 is 1 to 16,777,215.
“Example: IGZCD2A” on page 94
RELATED REFERENCES
“IGZCD2A return codes”
Example: IGZCD2A
The following CALL statement converts the DBCS data in dbcs-item to nonnumeric
data with double-byte characters. The results of the conversion are placed in
alpha-item.
CALL “IGZCD2A” USING BY REFERENCE dbcs-item alpha-item
BY CONTENT LENGTH OF dbcs-item LENGTH OF alpha-item
Suppose the contents of dbcs-item and alpha-item and the lengths before the
conversion are:
dbcs-item = .A.BD1D2D3.C.D
alpha-item = ssssssssssss
LENGTH OF dbcs-item = 14
LENGTH OF alpha-item = 12
RELATED REFERENCES
“DBCS notation” on page 90
94 Programming Guide
| The code above displays the following messages on the system logical output
| device:
Hello World!
HELLO WORLD!
hello world!
HELLO WORLD!
The DISPLAY statements do not change the actual contents of Item-1, but affect only
how the letters are displayed. However, the MOVE statement causes uppercase
letters to be moved to the actual contents of Item-2.
For example, if the starting value is JOHNSONººº, the value after the statement is
performed is ºººNOSNHOJ, where º represents a blank space.
Use NUMVAL-C when the argument includes a currency symbol or comma, or both,
as shown in the example. You can also place an algebraic sign before or after the
character string, and the sign will be processed. The arguments must not exceed 18
| digits when you compile with the default option ARITH(COMPAT) (compatibility mode)
| nor 31 digits when you compile with ARITH(EXTEND) (extended mode), not including
the editing symbols.
When you use NUMVAL or NUMVAL-C, you do not need to statically declare numeric
data in a fixed format, nor input data in a precise manner. For example, suppose
you define numbers to be entered as follows:
01 X Pic S999V99 leading sign is separate.
. . .
Accept X from Console
The user of the application must enter the numbers exactly as defined by the
PICTURE clause. For example:
+001.23
-300.00
RELATED CONCEPTS
“Formats for numeric data” on page 36
RELATED TASKS
“Assigning input from a screen or file (ACCEPT)” on page 28
“Displaying values on a screen or in a file (DISPLAY)” on page 29
RELATED REFERENCES
NUMVAL (IBM COBOL Language Reference)
NUMVAL-C (IBM COBOL Language Reference)
“ARITH” on page 262
If you know the ordinal position in the collating sequence of a character, and want
to know the character that it corresponds to, use the CHAR function with the integer
ordinal position as the argument. CHAR returns the desired character:
INITIALIZE Customer-Name REPLACING ALPHABETIC BY Function Char(65)
RELATED REFERENCES
CHAR (IBM COBOL Language Reference)
ORD (IBM COBOL Language Reference)
96 Programming Guide
Finding the largest or smallest data item
If you want to know which of two or more alphanumeric data items has the
largest value, use the MAX or ORD-MAX function. Supply the data items in question as
arguments. If you want to know which item contains the smallest value, use the
MIN or ORD-MIN function. These functions evaluate the values according to the
collating sequence. You can also use MAX, ORD-MAX, MIN, or ORD-MIN for numbers. In
that case, the algebraic values of the arguments are compared.
If you used the ORD-MAX function in the example above, you would receive a syntax
error message at compile time; the reference to a numeric function is in an invalid
place. The following is a valid use of the ORD-MAX function:
Compute x = Function Ord-max(Arg1 Arg2 Arg3)
This code assigns the integer 3 to x if the same arguments are used as in the
previous example. If you use ORD-MIN instead, the integer 2 is returned.
The above examples would probably be more realistic if Arg1, Arg2, and Arg3 were
instead successive elements of an array (table).
In the following example, the amount of data moved to R3 and the results of the
COMPUTE statement depend on the values and sizes of R1 and R2:
01 R1 Pic x(10) value “e”.
01 R2 Pic x(05) value “f”.
01 R3 Pic x(20) value spaces.
01 L Pic 99.
. . .
Move Function Max(R1 R2) to R3
Compute L = Function Length(Function Max(R1 R2))
RELATED TASKS
“Performing arithmetic” on page 43
“Processing table items using intrinsic functions” on page 67
RELATED REFERENCES
ORD-MAX (IBM COBOL Language Reference)
ORD-MIN (IBM COBOL Language Reference)
The following COBOL statement demonstrates moving a data item into that field
in a record that holds customer names:
Move Customer-name To Customer-record(1:Function Length(Customer-name))
You could also use the LENGTH OF special register. Coding either Function
Length(Customer-Name) or LENGTH OF Customer-Name returns the same result: the
length of Customer-Name in bytes.
You can use the LENGTH function only where arithmetic expressions are allowed.
However, you can use the LENGTH OF special register in a greater variety of
contexts. For example, you can use the LENGTH OF special register as an argument
to an intrinsic function that allows integer arguments. (You cannot use an intrinsic
function as an operand to the LENGTH OF special register.) You can also use the
LENGTH OF special register as a parameter in a CALL statement.
RELATED TASKS
“Performing arithmetic” on page 43
“Processing table items using intrinsic functions” on page 67
RELATED REFERENCES
LENGTH (IBM COBOL Language Reference)
98 Programming Guide
Finding the date of compilation
If you want to know the date and time when a program was compiled, you can
use the WHEN-COMPILED function. The result returned has 21 character positions,
with the first 16 positions in the following format:
YYYYMMDDhhmmsshh
These characters show the four-digit year, month, day, and time (in hours, minutes,
seconds, and hundredths of seconds) of compilation.
The WHEN-COMPILED special register is another means you can use to find the date
and time of compilation. It has the following format:
MM/DD/YYhh.mm.ss
The WHEN-COMPILED special register supports only a two-digit year, and carries the
time out only to seconds. This special register be used only as the sending field in
a MOVE statement.
RELATED REFERENCES
WHEN-COMPILED (IBM COBOL Language Reference)
The source of the information and the target for the results can be one or more of
the following:
v Another program
v Direct-access storage device
v Magnetic tape
v Printer
v Terminal
v Card reader or punch
Your COBOL program does not directly handle physical records. It processes
logical records. A logical record can correspond to a complete physical record, part
of a physical record, or to parts or all of one or more physical records. Your
COBOL program handles logical records exactly as you have defined them.
RELATED CONCEPTS
“File organization and input-output devices”
RELATED TASKS
“Choosing file organization and access mode” on page 103
“Allocating files” on page 105
“Checking for input or output errors” on page 106
| With COBOL for OS/390 & VM, requests to the operating system for the storage
| and retrieval of records from input-output devices are handled by the two access
| methods QSAM and VSAM, and the OS/390 UNIX file system.
The device type upon which you elect to store your data could affect the choices of
file organization available to you. Direct-access storage devices provide greater
flexibility in the file organization options. Sequential-only devices limit
organization options but have other characteristics, such as the portability of tapes,
that might be useful.
Sequential-only devices
Terminals, printers, card readers, and punches are called unit-record devices
because they process one line at a time. Therefore, you must also process
records one at a time sequentially in your program when it reads from or
writes to unit-record devices.
On tape, records are ordered sequentially, so your program must process
them sequentially. Use QSAM physical sequential files when processing
tape files. The records on tape can be fixed length or variable length. The
rate of data transfer is faster than it is for cards.
Direct-access storage devices
Direct-access storage devices hold many records. The record arrangement
of files stored on these devices determines the ways that your program can
process the data. When using direct-access devices, you have greater
flexibility within your program, because your can use several types of file
organization:
v Sequential (VSAM or QSAM)
RELATED TASKS
“Allocating files” on page 105
“Chapter 8. Processing QSAM files” on page 107
“Chapter 9. Processing VSAM files” on page 135
“Chapter 10. Processing line-sequential files” on page 163
“Choosing file organization and access mode”
The following table shows the possible file organizations, access modes, and record
formats for COBOL files.
| 1. The data itself is in variable format but can be read into and written from COBOL
| fixed-length records.
RELATED REFERENCES
“Format for coding input and output”
“Allowable control characters” on page 164
RELATED TASKS
“Chapter 8. Processing QSAM files” on page 107
“Chapter 9. Processing VSAM files” on page 135
“Chapter 10. Processing line-sequential files” on page 163
Allocating files
| For any type of file (sequential, line sequential, indexed, or relative) in your
| OS/390 or OS/390 UNIX applications, you can define the external name with
| either a ddname or an environment variable name. The external name is the name
| in the assignment-name of the ASSIGN clause.
| If the file is in the HFS, you can use either a DD definition or an environment
| variable to define the file by specifying its path name with the PATH keyword.
| The environment variable name must be uppercase. The allowable attributes for its
| value depend on the organization of the file being defined.
| Because you can define the external name in either of two ways, the COBOL run
| time goes through the following steps to find the definition of the file:
| 1. If the ddname is explicitly allocated, it is used. The definition can be from a DD
| statement in JCL, an ALLOCATE command from TSO/E, or a user-initiated
| dynamic allocation.
| 2. If the ddname is not explicitly allocated and an environment variable of the
| same name is set, the value of the environment variable is used.
| The file is dynamically allocated using the attributes specified by the
| environment variable. At a minimum, you must specify either the PATH() or
| DSN() option. All options and attributes must be in uppercase, except for the
| path-name suboption of the PATH option, which is case sensitive. You cannot
| specify a temporary data set name in the DSN() option.
| File status code 98 results from any of the following:
| v The contents (including a value of null or all blanks) of the environment
| variable are not valid.
| v The dynamic allocation of the file fails.
| v The dynamic deallocation of the file fails.
| The COBOL run time checks the contents of the environment variable at each
| OPEN statement. If a file with the same external name was dynamically allocated
| by a previous OPEN statement and the contents of the environment variable
| have changed since that OPEN, the run time dynamically deallocates the
| previous allocation and reallocates the file using the options currently set in the
| environment variable. If the contents of the environment variable have not
| changed, the run time uses the current allocation.
| The COBOL run time follows these steps for both OS/390 and OS/390 UNIX
| applications that were compiled with the NOCMPR2 compiler option. Dynamic
| allocation of files using an environment variable is not available to programs
| compiled with the CMPR2 compiler option or programs run under CMS.
| The COBOL run time deallocates all dynamic allocations at run-unit termination,
| except “implicit” CBLQDA allocations.
RELATED TASKS
“Setting and accessing environment variables” on page 362
“Defining and allocating QSAM files” on page 121
“Dynamically creating QSAM files with CBLQDA” on page 118
“Allocating VSAM files” on page 156
RELATED REFERENCES
“CMPR2” on page 264
With VSAM files, you can use a second data-name in the FILE STATUS clause to get
additional VSAM return code information.
Another way of handling errors in input and output operations is to code ERROR
(synonymous with EXCEPTION) declaratives, as explained in the references below.
RELATED TASKS
“Handling errors in input and output operations” on page 191
“Coding ERROR declaratives” on page 194
“Using file status keys” on page 194
To process QSAM files in your program, use COBOL language statements that:
v Identify and describe the QSAM files in the ENVIRONMENT DIVISION and the DATA
DIVISION.
v Process the records in these files in the PROCEDURE DIVISION.
After you have created a record, you cannot change its length or its position in the
file, and you cannot delete it. You can, however, update QSAM files on
| direct-access storage devices (using REWRITE), though not in the HFS.
| You can also access byte-stream files in the HFS using QSAM. These files are
| binary byte-oriented sequential files with no record structure. The record
| definitions that you code in your COBOL program and the length of the variables
| that you read into and write from determine the amount of data transferred.
RELATED CONCEPTS
“Labels for QSAM files” on page 129
OS/390 DFSMS: Using Data Sets (how QSAM files are organized, and how the
system processes them)
RELATED TASKS
“Defining QSAM files and records in COBOL”
“Coding input and output statements for QSAM files” on page 117
“Handling errors in QSAM files” on page 120
“Working with QSAM files under OS/390” on page 121
“Identifying QSAM files to CMS” on page 128
“Processing QSAM ASCII files on tape” on page 132
“Processing ASCII file labels” on page 133
| Your ASSIGN clause name can include an S- before the external name (ddname or
| environment variable name) to document that the file is a QSAM file.
RELATED TASKS
“Establishing record formats”
“Setting block sizes” on page 115
You can code a record format of F, V, S, or U in the RECORDING MODE clause. COBOL
determines the record format from the RECORD clause or from the record
descriptions associated with your FD entry for the file. If you want the records to
be blocked, code the BLOCK CONTAINS clause in your FD entry.
The following example shows how the FD entry might look for a file with
fixed-length records:
FILE SECTION.
FD COMMUTER-FILE-MST
RECORDING MODE IS F
BLOCK CONTAINS 0 RECORDS
RECORD CONTAINS 80 CHARACTERS.
01 COMMUTER-RECORD-MST.
05 COMMUTER-NUMBER PIC X(16).
05 COMMUTER-DESCRIPTION PIC X(64).
| A recording mode of S is not supported for files in the HFS. The above example is
| appropriate for such a file.
RELATED CONCEPTS
“Logical records”
RELATED TASKS
“Requesting fixed-length format” on page 109
“Requesting variable-length format” on page 110
“Requesting spanned format” on page 112
“Requesting undefined format” on page 114
“Defining QSAM files and records in COBOL” on page 107
Logical records
The term logical record is used in a slightly different way in the COBOL language
and in OS/390 QSAM. For format-V and format-S files, the QSAM logical record
includes a 4-byte prefix in front of the user data portion of the record that is not
included in the definition of a COBOL logical record. For format-F and format-U
| files, and for HFS byte-stream files, the definitions of QSAM logical record and
COBOL logical record are identical.
RELATED REFERENCES
“Layout of format-F records”
“Layout of format-V records” on page 111
“Layout of format-S records” on page 113
“Layout of format-U records” on page 114
You can omit the RECORDING MODE clause. The compiler determines the recording
mode to be F if the length of the largest level-01 record associated with the file is
not greater than the block size coded in the BLOCK CONTAINS clause, and you take
one of the following actions:
v Use the RECORD CONTAINS integer clause (RECORD clause format 1).
When you use this clause, the file is always fixed format with record length
integer, even if there are multiple level-01 record description entries with
different lengths associated with the file.
v Omit the RECORD CONTAINS integer clause, but code the same fixed size and no
OCCURS DEPENDING ON clause for all level-01 record description entries associated
with the file. This fixed size is the record length.
In an unblocked format-F file, the logical record is the same as the block.
In a blocked format-F file, the number of logical records in a block (the blocking
factor) is constant for every block in the file, except the last block, which might be
| shorter. Files in the HFS are never blocked.
RELATED CONCEPTS
“Logical records” on page 108
RELATED TASKS
“Requesting variable-length format” on page 110
“Requesting spanned format” on page 112
“Requesting undefined format” on page 114
“Establishing record formats” on page 108
RELATED REFERENCES
“Layout of format-F records”
RELATED TASKS
“Requesting fixed-length format” on page 109
Fixed-length record formats (OS/390 DFSMS: Using Data Sets)
RELATED REFERENCES
“Layout of format-V records” on page 111
“Layout of format-S records” on page 113
“Layout of format-U records” on page 114
You can omit the RECORDING MODE clause. The compiler determines the recording
mode to be V if the largest level-01 record associated with the file is not greater
than the block size set in the BLOCK CONTAINS clause, and you take one of the
following actions:
v Use the RECORD IS VARYING clause (RECORD clause format 3).
If you provide values for integer-1 and integer-2 (RECORD IS VARYING FROM
integer-1 TO integer-2), the maximum record length is the value coded for
integer-2, regardless of the lengths coded in the level-01 record description
entries associated with the file.
If you omit integer-1 and integer-2, the maximum record length is determined to
be the size of the largest level-01 record description entry associated with the
file.
v Use the RECORD CONTAINS integer-1 TO integer-2 clause (RECORD clause format 2).
Make integer-1 and integer-2 match the minimum length and the maximum
length of the level-01 record description entries associated with the file. The
maximum record length is the integer-2 value.
v Omit the RECORD clause, but code multiple level-01 records (associated with the
file) that are of different sizes or contain an OCCURS DEPENDING ON clause.
The maximum record length is determined to be the size of the largest level-01
record description entry associated with the file.
When you specify a READ INTO statement for a format-V file, the record size read
for that file is used in the MOVE statement generated by the compiler. Consequently,
you might not get the result you expect if the record just read does not correspond
to the level-01 record description. All other rules of the MOVE statement apply. For
example, when you specify a MOVE statement for a format-V record read in by the
READ statement, the size of the record moved corresponds to its level-01 record
description.
When you specify a READ statement for a format-V file followed by a MOVE of the
level-01 record, the actual record length is not used. The program will attempt to
move the number of bytes described by the level-01 record description. If this
number exceeds the actual record length and extends outside the area addressable
by the program, results are unpredictable. If the number of bytes described by the
level-01 record description is shorter than the physical record read, truncation of
bytes beyond the 01-level description occurs. To find the actual length of a
variable-length record, specify data-name-1 in format 3 of the RECORD clause of the
File Definition (FD).
RELATED TASKS
“Requesting fixed-length format” on page 109
“Requesting spanned format” on page 112
“Requesting undefined format” on page 114
“Establishing record formats” on page 108
RELATED REFERENCES
“Layout of format-V records”
“CMPR2” on page 264
COBOL for OS/390 & VM Compiler and Run-Time Migration Guide (VS COBOL II
Release 2 compatibility and migration)
| Layout of format-V records: Format-V QSAM records have control fields (shown
below) preceding the data. The QSAM logical record length is determined by
adding 4 bytes (for the control fields) to the record length defined in your
program, but you must not include these 4 bytes in the description of the record
and record length.
RELATED CONCEPTS
“Logical records” on page 108
RELATED TASKS
“Requesting variable-length format” on page 110
RELATED REFERENCES
“Layout of format-F records” on page 109
“Layout of format-S records” on page 113
“Layout of format-U records” on page 114
You can omit the RECORDING MODE clause. The compiler determines the recording
mode to be S if the maximum record length plus 4 is greater than the block size set
in the BLOCK CONTAINS clause.
For files with format S in your program, the compiler determines the maximum
record length with the same rules used for format V. The length is based on your
usage of the RECORD clause.
When creating files containing format-S records, and a record is larger than the
remaining space in a block, COBOL writes a segment of the record to fill the block.
The rest of the record is stored in the next block or blocks, depending on its length.
COBOL supports QSAM Spanned records up to 32760 bytes long.
When retrieving files with format-S records, your program can retrieve only
complete records.
Benefits of format-S files: You can efficiently use external storage and still
organize your files with logical record lengths by defining files with format-S
records:
v You can set block lengths to efficiently use track capacities on direct access
devices.
v You are not required to adjust the logical record lengths to device-dependent
physical block lengths. One logical record can span two or more physical blocks.
v You have greater flexibility when you want to transfer logical records between
direct access storage types.
You will, however, have additional overhead in processing format-S files.
Format-S files and READ INTO: By specifying a READ INTO statement for a
format-S file, the record size just read for that file is used in the MOVE statement
generated by the compiler. Consequently, you might not get the result you expect
if the record just read does not correspond to the level-01 record description. All
other rules of the MOVE statement apply.
RELATED CONCEPTS
“Logical records” on page 108
“Spanned blocked and unblocked files” on page 113
RELATED REFERENCES
“Layout of format-S records”
| Spanned blocked and unblocked files: A spanned blocked QSAM file is made
up of blocks, each containing one or more logical records or segments of logical
records. The logical records can be either fixed or variable in length and their size
can be smaller than, equal to, or larger than the physical block size. There are no
required relationships between logical records and physical block sizes.
RELATED CONCEPTS
“Logical records” on page 108
RELATED TASKS
“Requesting spanned format” on page 112
Each block is preceded by a block descriptor field. There is only one block
descriptor field at the beginning of each physical block.
Each segment of a record in a block, even if the segment is the entire record, is
preceded by a segment descriptor field. There is one segment descriptor field for
each record segment in the block. The segment descriptor field also indicates
whether the segment is the first, the last, or an intermediate segment.
You do not describe these fields in the DATA DIVISION of your COBOL program,
and the fields are not available for you to use in your program.
RELATED TASKS
“Requesting spanned format” on page 112
RELATED REFERENCES
“Layout of format-F records” on page 109
“Layout of format-V records” on page 111
“Layout of format-U records” on page 114
The compiler determines the recording mode to be U only if you code RECORDING
MODE U.
The record length is determined in your program based on how you use the
RECORD clause:
v If you use the RECORD CONTAINS integer clause (RECORD clause format 1), the record
length is the integer value, regardless of the lengths of the level-01 record
description entries associated with the file.
v If you use the RECORD IS VARYING clause (RECORD clause format 3), the record
length is determined based on whether you code integer-1 and integer-2.
If you code integer-1 and integer-2 (RECORD IS VARYING FROM integer-1 TO
integer-2), the maximum record length is the integer-2 value, regardless of the
lengths of the level-01 record description entries associated with the file.
If you omit integer-1 and integer-2, the maximum record length is determined to
be the size of the largest level-01 record description entry associated with the
file.
v If you use the RECORD CONTAINS integer-1 TO integer-2 clause (RECORD clause
format 2), with integer-1 and integer-2 matching the minimum length and the
maximum length of the level-01 record description entries associated with the
file, the maximum record length is the integer-2 value.
v If you omit the RECORD clause, the maximum record length is determined to be
the size of the largest level-01 record description entry associated with the file.
Format-U files and READ INTO: When you specify a READ INTO statement for a
format-U file, the size of the record just read for that file is used in the MOVE
statement generated by the compiler. Consequently, you might not get the result
you expect if the record just read does not correspond to the level-01 record
description. All other rules of the MOVE statement apply.
RELATED TASKS
“Requesting fixed-length format” on page 109
“Requesting variable-length format” on page 110
“Requesting spanned format” on page 112
“Establishing record formats” on page 108
RELATED REFERENCES
“Layout of format-U records”
RELATED CONCEPTS
“Logical records” on page 108
RELATED TASKS
“Requesting undefined format”
If you set the block size explicitly in the BLOCK CONTAINS clause, it must not be
greater than the maximum block size for the device. The block size set for a
format-F file must be an integral multiple of the record length.
If your program uses QSAM files on tape, use a physical block size of at least 12 to
18 bytes. Otherwise, the block will be skipped over when a parity check occurs
while doing one of the following:
v Reading a block of records of fewer than 12 bytes
v Writing a block of records of fewer than 18 bytes
| If you specify a block size larger than 32760 directly on your BLOCK CONTAINS
| clause or indirectly with the use of BLOCK CONTAINS n RECORDS, and you do not
| meet both the following conditions, the OPEN of the data set fails with file status
| code 90:
| v You use OS/390 V2R10.0 DFSMS or later.
| v You define the data set to be tape.
For existing blocked data sets, it is simplest to:
| The LBI is not used in all cases. An attempt to use a block size greater than 32760
| in the following cases is diagnosed at compile time or results in a failure at OPEN:
| v Spanned records
| v OPEN I-O
| Using a block size that exceeds 32760 might result in your not being able to read
| the tape on another system. A tape that you create with a block size greater than
| 32760 can be read only on an MVS system that uses OS/390 V2R10.0 DFSMS or
| later and has a tape device that supports block sizes greater than 32760. If you
| specify a block size that is too large for the file, the device, or the operating system
| level, a run-time message is issued.
RELATED TASKS
“Opening QSAM files”
“Adding records to QSAM files” on page 119
“Updating QSAM files” on page 119
“Writing QSAM files to a printer or spooled data set” on page 119
“Closing QSAM files” on page 120
RELATED REFERENCES
OPEN statement (IBM COBOL Language Reference)
READ statement (IBM COBOL Language Reference)
WRITE statement (IBM COBOL Language Reference)
REWRITE statement (IBM COBOL Language Reference)
CLOSE statement (IBM COBOL Language Reference)
Code CLOSE WITH LOCK so that the file cannot be opened again while the program
is running.
Use the REVERSED option of the OPEN statement to process tape files in reverse order.
Execution of the OPEN statement will then position the file at its end. Subsequent
READ statements read the data records in reverse order, starting with the last record.
The REVERSED option is supported only for files with fixed-length records.
RELATED TASKS
“Dynamically creating QSAM files with CBLQDA”
RELATED REFERENCES
OPEN statement (IBM COBOL Language Reference)
A file is available on CMS when it has been identified using a CMS FILEDEF
command or if the file FILE ddname exists on your minidisk.
| Do not confuse this implicit allocation mechanism with the dynamic allocation of
| files through the use of environment variables. That explicit dynamic allocation
| requires a valid environment variable to be set. This CBLQDA support is used only
| when the QSAM file is unavailable as defined above, which includes no valid
| environment variable being set.
Under OS/390, files created using the CBLQDA option are temporary data sets and
do not exist after the program has run. Under CMS, they are named FILE ddname
A4 and do exist after the program has run.
RELATED TASKS
“Opening QSAM files” on page 117
To add records to a file opened as I-O, you must first close the file and open it as
EXTEND.
RELATED REFERENCES
READ statement (IBM COBOL Language Reference)
WRITE statement (IBM COBOL Language Reference)
Replace an existing record with another record of the same length by doing the
following:
1. Open the file as I-O.
2. Use REWRITE to update an existing record in the file. (The last file processing
statement before REWRITE must have been a successful READ statement.)
RELATED REFERENCES
REWRITE statement (IBM COBOL Language Reference)
If you use the LINAGE clause in combination with WRITE BEFORE/AFTER ADVANCING
nn LINES, be careful about the values you set. With the ADVANCING nn LINES clause,
COBOL first calculates the sum of LINAGE-COUNTER plus nn. Subsequent actions
depend on the size of nn. The END-OF-PAGE imperative statement is performed after
the LINAGE-COUNTER is increased. Consequently, the LINAGE-COUNTER could be
pointing to the next logical page instead of to the current footing area when the
END-OF-PAGE statement is performed.
RELATED REFERENCES
WRITE statement (IBM COBOL Language Reference)
If you do not close a QSAM file, the file is automatically closed for you under the
following conditions:
v When the run unit ends normally, the run time closes all open files that are
defined in any of the following types of programs in the run unit: COBOL for
OS/390 & VM, COBOL for MVS & VM, and VS COBOL II.
v If the run unit ends abnormally and you have set the TRAP(ON) run-time option,
the run time closes all open files that are defined in any of the following types
of programs in the run unit: COBOL for OS/390 & VM, COBOL for MVS & VM,
and VS COBOL II.
v When Language Environment condition handling is completed and the
application resumes in a routine other than where the condition occurred, the
run time closes all open files that are defined in any of the following types of
programs in the run unit that might be called again and reentered: COBOL for
OS/390 & VM, COBOL for MVS & VM, and VS COBOL II.
You can change the location of where the program resumes running (after a
condition is handled) by moving the resume cursor with the Language
Environment CEEMRCR callable service or by using HLL language constructs
such as a C longjmp.
v When you use CANCEL for a COBOL for OS/390 & VM, COBOL for MVS & VM,
or VS COBOL II subprogram, the run time closes any open nonexternal files that
are defined in that program.
v When a COBOL for OS/390 & VM, COBOL for MVS & VM, or VS COBOL II
subprogram with the INITIAL attribute returns control, the run time closes any
open nonexternal files that are defined in that program.
File status codes are set when these implicit CLOSE operations are performed, but
EXCEPTION/ERROR and LABEL declaratives are not invoked.
RELATED REFERENCES
CLOSE statement (IBM COBOL Language Reference)
COBOL provides these ways for you to intercept and handle certain QSAM input
and output errors:
v End of file phrase (AT END)
v EXCEPTION/ERROR declarative
If you use the FILE STATUS clause or the EXCEPTION/ERROR declarative, code
EROPT=ACC in the DCB of the DD statement for that file. Otherwise, your COBOL
program will not be able to continue processing after some error conditions.
If you use the FILE STATUS clause, be sure to check the key and take appropriate
action based on its value. If you do not check the key, your program might
continue, but the results will probably not be what you expected.
RELATED TASKS
“Handling errors in input and output operations” on page 191
| You can optionally specify the following attributes in any order following the DSN:
| v A disposition value, one of: NEW, OLD, SHR, or MOD
| v TRACKS or CYL
| v SPACE(nnn,mmm)
| v VOL(volume-serial)
| v UNIT(type)
| v KEEP, DELETE, CATALOG, or UNCATALOG
| v STORCLAS(storage-class)
| v MGMTCLAS(management-class)
| v DATACLAS(data-class)
| When you define a QSAM file, use the specified parameters to do the following:
Some of the information about the QSAM file must always be coded in the
FILE-CONTROL entry, the FD entry, and other COBOL clauses. Other information
| must be coded in the DD statement or environment variable for output files. For
input files, the system can obtain information from the file label (for standard label
files). If DCB information is provided in the DD statement for input files, it overrides
information on the data set label. For example, the amount of space allocated for a
new direct-access device file can be set in the DD statement by the SPACE parameter.
You cannot express certain characteristics of QSAM files in the COBOL language,
but you can code them in the DD statement for the file using the DCB parameter. Use
the subparameters of the DCB parameter to provide information that the system
needs for completing the data set definition, including the following:
v Block size (BLKSIZE=), if BLOCK CONTAINS 0 RECORDS was coded at compile time
(which is recommended)
v Options to be executed if an error occurs in reading or writing a record
v TRACK OVERFLOW or standard blocks
RELATED TASKS
“Setting block sizes” on page 115
“Defining QSAM files and records in COBOL” on page 107
“Allocating files” on page 105
RELATED REFERENCES
“Parameters for creating QSAM files”
OS/390 MVS JCL Reference
RELATED TASKS
“Defining and allocating QSAM files” on page 121
| If you are using JCL, and you created the file in the current job step or in a
previous job step in the current job, you can refer to the previous DD statement for
most of the data set information. You do, however, need to code DSNAME and DISP.
RELATED REFERENCES
“Parameters for retrieving QSAM files”
RELATED TASKS
“Retrieving QSAM files” on page 123
To prevent common file status 39 problems, follow the guidelines listed below for
processing files that are existing, new, or dynamically created by COBOL.
If the existing file is an ASCII data set (DCB=(OPTCD=Q)), you must use the CODE-SET
clause in the program’s FD entry for the file.
RELATED TASKS
“Requesting fixed-length format” on page 109
“Requesting variable-length format” on page 110
“Requesting undefined format” on page 114
“Dynamically creating QSAM files with CBLQDA” on page 118
Striped extended-format QSAM data sets can benefit an application with these
characteristics:
v The application processes files that contain large volumes of data.
v The time for the input and output operations to the files significantly affects
overall performance.
For you to gain the maximum benefit from using QSAM striped data sets, DFSMS
needs to be able to allocate the required number of buffers above the 16-MB line.
When you develop applications that contain files allocated to QSAM striped data
sets, follow these guidelines:
v Avoid using a QSAM striped data set for a file that cannot have buffers
allocated above the 16-MB line.
RELATED REFERENCES
“Allocation of buffers for QSAM files”
RELATED TASKS
“Allocating files” on page 105
“Defining and allocating QSAM files” on page 121
Accessing HFS files via BSAM and QSAM (OS/390 DFSMS: Using Data Sets)
For certain files, you also need to use the LABELDEF command.
Using FILEDEF
The FILEDEF command relates a ddname (file name) in your program with an
input or output device. If the FILEDEF command is issued for a program input or
output file, the ddname must be the same as the ddname or file name coded for
the file in the source program. Code the ddname in the ASSIGN clause of the SELECT
statement in the FILE CONTROL paragraph.
Although you can read data sets from operating system (OS) disks when you run
COBOL programs in CMS, you cannot write files on the disks unless they are
VSAM files. You can, however, write OS simulated data sets on CMS disks, which
retain file characteristics of OS sequential data sets. To do this, use file-mode 4
when creating the files. You should use OS simulated data sets for files defined in
the COBOL program as blocked and with variable-length records.
Using LABELDEF
The LABELDEF command is required in addition to FILEDEF for certain files.
CMS multivolume tape files must be standard labeled tape files (SL or AL). Also,
the LABELDEF command must be used to sequentially identify the tape volumes that
compose the logical file.
If you are using OPEN EXTEND and standard labeled tapes, issue the LABELDEF
command with the FID option. For example:
FILEDEF OUTFILE TAP3 SL
LABELDEF OUTFILE FID EXTR4C
RELATED REFERENCES
The FILEDEF command (VM/ESA CMS Command Reference)
There are two kinds of labels: standard and nonstandard. COBOL for OS/390 &
VM does not support nonstandard user labels. In addition, standard user labels
contain user-specified information about the associated data set.
Standard labels consist of volume labels and groups of data set labels. Volume
labels precede or follow data on the volume, and identify and describe the volume.
The data set labels precede or follow each data set on the volume, and identify and
describe the data set.
v The data set labels that precede the data set are called header labels.
v The data set labels that follow the data set are called trailer labels.
They are similar to the header labels, except that they also contain a count of
blocks in the data set.
v The data set label groups can optionally include standard user labels.
v The volume label groups can optionally include standard user labels.
RELATED TASKS
“Using trailer and header labels” on page 130
You can create, examine, or update up to eight header labels and eight trailer
labels on each volume of the data set. (QSAM EXTEND works in a manner identical
to OUTPUT except that the beginning-of-file label is not processed.) Labels reside on
the initial volume of a multivolume data set. This volume must be mounted as
CLOSE if trailer labels are to be created, examined, or updated. Trailer labels for files
opened as INPUT or I-O are processed when a CLOSE statement is performed for the
file that has reached an AT END condition.
If you code a header or trailer with the wrong position number, the result is
unpredictable. (Data management might force the label to the correct relative
position.)
When you use standard label processing, code the label type of the standard and
user labels (SUL) on the DD statement that describes the data set.
List the labels as data-names in the LABEL RECORDS clause in the FD entry for the file.
You can specify a special exit by using the statement GO TO MORE-LABELS. When
this statement results in an exit from a label DECLARATIVE SECTION, the system does
one of the following:
v Writes the current beginning or ending label and then reenters the USE section at
its beginning to create more labels. After creating the last label, the system exits
by performing the last statement of the section.
RELATED CONCEPTS
“Labels for QSAM files” on page 129
Identifier Description
VOL1 Volume label
HDR1 or HDR2 Data set header labels
EOV1 or EOV2 Data set trailer labels (end-of-volume)
EOF1 or EOF2 Data set trailer labels (end-of-data-set)
UHL1 to UHL8 User header labels
UTL1 to UTL8 User trailer labels
The format of the label for a direct-access volume is the almost the same as the
format of the label group for a tape volume label group. The difference is that a
data set label of the initial DASTO volume label consists of the data set control
block (DSCB). The DSCB appears in the volume table of contents (VTOC) and
contains the equivalent of the tape data set header and trailer, in addition to
control information such as space allocation.
The format used for user header labels (UHL1-8) and user trailer labels (UTL1-8)
consists of a label 80 characters in length recorded in either:
v EBCDIC on DASD or on IBM standard labeled tapes, or
v ASCII on ANSI/ISO/FIPS labeled tapes
The first 3 bytes consist of the characters that identify the label as either:
v UHL for a user header label (at the beginning of a data set), or
v UTL for a user trailer label (at the end-of-volume or end-of-data set)
The next byte contains the relative position of this label within a set of labels of the
same type. One through eight labels are permitted.
Standard user labels are not supported for QSAM striped data sets.
RELATED CONCEPTS
“Labels for QSAM files” on page 129
If you are using variable-length records, you cannot explicitly code format D;
instead, code RECORDING MODE V. The format information is internally converted to
D mode. D-mode records have a 4-byte record descriptor for each record.
BLKSIZE=n
n The size of the block, including the length of the block prefix.
LABEL=[AL|AUL|NL]
AL American National Standard (ANS) labels.
AUL ANS and user labels.
NL No labels.
RELATED TASKS
“Processing ASCII file labels”
All ANS user labels are optional. ASCII files can have user header labels (UHLn)
and user trailer labels (UTLn). There is no limit to the number of user labels at the
beginning and the end of a file; you can write as many labels as you need. All user
labels must be 80 bytes in length.
To create or verify user labels (user label exit), code a USE AFTER STANDARD LABEL
procedure. You cannot use USE BEFORE STANDARD LABEL procedures. Under CMS,
code the OPTCD=Q option on the FILEDEF command for ASCII files.
RELATED TASKS
“Processing QSAM ASCII files on tape” on page 132
The lists below show how VSAM terms differ from COBOL terms and other terms
that you might be familiar with.
The term file in this VSAM information refers to either a COBOL file or a VSAM
data set.
If you have complex requirements or frequently use VSAM, review the VSAM
publications for your operating system.
RELATED TASKS
“Defining VSAM file organization and records” on page 137
“Coding input and output statements for VSAM files” on page 143
“Protecting VSAM files with a password” on page 151
“Handling errors in VSAM files” on page 151
“Working with VSAM data sets under OS/390 and OS/390 UNIX” on page 152
“Defining VSAM data sets under CMS” on page 158
“Improving VSAM performance” on page 159
VSAM files
The physical organization of VSAM data sets differs considerably from those used
by other access methods. VSAM data sets are held in control intervals and control
areas (CA). The size of these is normally determined by the access method, and the
way in which they are used is not visible to you.
The following table compares the different types of VSAM data sets in terms of
several characteristics.
RELATED TASKS
“Specifying sequential organization for VSAM files” on page 138
“Specifying indexed organization for VSAM files” on page 138
“Specifying relative organization for VSAM files” on page 139
“Defining VSAM files under OS/390” on page 153
“Defining VSAM data sets under CMS” on page 158
In the FILE SECTION of the DATA DIVISION, code a file description (FD) entry for the
file. In the associated record description entry or entries, define the record-name and
record length. Code the logical size of the records with the RECORD clause.
Important: You can process VSAM data sets in COBOL for OS/390 & VM
programs only after you define them with access method services.
The following table summarizes VSAM file organization, access modes, and record
formats (fixed or variable length).
RELATED TASKS
“Specifying sequential organization for VSAM files”
“Specifying indexed organization for VSAM files”
“Specifying relative organization for VSAM files” on page 139
“Using file status keys” on page 194
“Using VSAM return codes (VSAM files only)” on page 196
“Defining VSAM files under OS/390” on page 153
“Defining VSAM data sets under CMS” on page 158
“Specifying access modes for VSAM files” on page 141
You can access (read or write) records in sequential files only sequentially.
After you place a record in the file, you cannot shorten, lengthen, or delete it.
However, you can update (REWRITE) a record if the length does not change. New
records are added at the end of the file.
The following example shows typical FILE-CONTROL entries for a VSAM sequential
file (ESDS):
SELECT S-FILE
ASSIGN TO SEQUENTIAL-AS-FILE
ORGANIZATION IS SEQUENTIAL
ACCESS IS SEQUENTIAL
FILE STATUS IS FSTAT-CODE VSAM-CODE.
RELATED CONCEPTS
“VSAM files” on page 136
where data-name is the name of the key field as you defined it in the record
description entry in the DATA DIVISION.
The following example shows the statements for a VSAM indexed file (KSDS) that
is accessed dynamically. In addition to the primary key, COMMUTER-NO, there is an
alternate key, LOCATION-NO:
Alternate keys
In addition to the primary key, you can also code one or more alternate keys to use
for retrieving records. Using alternate keys, you can access the indexed file to read
records in some sequence other than the prime key sequence. For example, you
could access the file through employee department rather than through employee
number. Alternate keys need not be unique. More than one record will be accessed,
given a department number as a key. This is permitted if alternate keys are coded
to allow duplicates.
You define the alternate key in your COBOL program with the ALTERNATE RECORD
KEY clause:
ALTERNATE RECORD KEY IS data-name
Here data-name is the name of the key field as you defined it in the record
description entry in the DATA DIVISION.
Alternate index
To use an alternate index, you need to define a data set (using access method
services) called the alternate index (AIX). The AIX contains one record for each
value of a given alternate key; the records are in sequential order by alternate key
value. Each record contains the corresponding primary keys of all records in the
associated indexed files that contain the alternate key value.
RELATED CONCEPTS
“VSAM files” on page 136
RELATED TASKS
“Creating alternate indexes” on page 154
Use the RELATIVE KEY IS clause to associate each logical record with its relative
record number.
The following example shows a relative-record data set (RRDS) that is accessed
randomly by the value in the relative key ITEM-NO:
SELECT R-FILE
ASSIGN TO RELATIVE-FILE
ORGANIZATION IS RELATIVE
ACCESS IS RANDOM
RELATIVE KEY IS RFILE-RELATIVE-KEY
FILE STATUS IS FSTAT-CODE VSAM-CODE.
You can use a randomizing routine to associate a key value in each record with the
relative record number for that record. Although there are many techniques to
convert a record key to a relative record number, the most commonly used
randomizing algorithm is the division/remainder technique. With this technique,
When you load an RRDS with variable-length records, you can skip over relative
record numbers. Unlike fixed-length RRDS, a variable-length RRDS does not have
slots. Instead, the free space that you define allows for more efficient record
insertions.
The coding you use in your COBOL program to identify and describe VSAM
variable-length RRDS and COBOL simulated variable-length RRDS is similar. How
you use the SIMVRD run-time option and whether you define the VSAM file as a
RRDS or KSDS differs, however.
RELATED CONCEPTS
“VSAM files” on page 136
RELATED TASKS
“Defining VSAM files under OS/390” on page 153
For random access, code ACCESS IS RANDOM in the FILE-CONTROL entry. Records in
indexed files are then accessed according to the value you place in a key field.
Records in relative files are accessed according to the value you place in the
relative key.
For dynamic access, code ACCESS IS DYNAMIC in the FILE-CONTROL entry. Dynamic
access is a mixed sequential-random access in the same program. Using dynamic
access, you can write one program to perform both sequential and random
processing, accessing some records in sequential order and others by their keys.
RELATED TASKS
“Reading records from a VSAM file” on page 147
Because the concept of blocking has no meaning for VSAM files, you can omit the
BLOCK CONTAINS clause. The clause is syntax-checked, but it has no effect on how
the program runs.
Clause
RECORD clause format Record length Comments
Code RECORD CONTAINS 1 Fixed in size with a The lengths of the
integer length of integer-2 level-01 record
description entries
associated with the file
do not matter.
Omit the RECORD clause, The fixed size that you
but code all level-01 coded
records (associated with
the file) as the same size
and none with an OCCURS
DEPENDING ON clause.
Clause
RECORD clause format Maximum record length Comments
Code RECORD IS VARYING 3 integer-2 value The lengths of the
FROM integer-1 TO level-01 record
integer-2 description entries
associated with the file
do not matter.
Code RECORD IS VARYING 3 Size of the largest level-01 The compiler determines
record description entry the maximum record
associated with the file length.
Code RECORD CONTAINS 2 integer-2 value The minimum record
integer-1 TO integer-2 length is the integer-2
value.
Omit the RECORD clause, Size of the largest level-01 The compiler determines
but code multiple level-01 record description entry the maximum record
records (associated with associated with the file length.
the file) that are of
different sizes or that
contain an OCCURS
DEPENDING ON clause.
When you specify a READ INTO statement for a format-V file, the record size read
for that file is used in the MOVE statement generated by the compiler. Consequently,
you might not get the result you expect if the record read in does not correspond
to the level-01 record description. All other rules of the MOVE statement apply. For
example, when you specify a MOVE statement for a format-V record read in by the
READ statement, the size of the record corresponds to its level-01 record description.
RELATED TASKS
COBOL for OS/390 & VM Compiler and Run-Time Migration Guide
All of the following factors determine which input and output statements you can
use for a given VSAM data set:
v Access mode (sequential, random, or dynamic)
v File organization (ESDS, KSDS, or RRDS)
v Mode of OPEN statement (INPUT, OUTPUT, I-O, or EXTEND)
The following table shows the possible combinations with sequential files (ESDS).
The X indicates that you can use the statement with the open mode at the top of
the column.
The following table shows the possible combinations you can use with indexed
(KSDS) files and relative (RRDS) files. The X indicates that you can use the
statement with the open mode at the top of the column.
The fields you code in the FILE STATUS clause are updated by VSAM after each
input-output statement to indicate the success or failure of the operation.
RELATED CONCEPTS
“File position indicator”
RELATED TASKS
“Opening a file (ESDS, KSDS, or RRDS)” on page 145
“Reading records from a VSAM file” on page 147
“Updating records in a VSAM file” on page 148
“Adding records to a VSAM file” on page 149
“Replacing records in a VSAM file” on page 149
“Deleting records from a VSAM file” on page 150
“Closing VSAM files” on page 150
RELATED TASKS
“Reading records from a VSAM file” on page 147
For example, if you OPEN EXTEND, OPEN I-O, or OPEN INPUT a file that is neither
optional nor available, you get file status 35 and the OPEN statement fails. If the file
is OPTIONAL, the OPEN EXTEND, OPEN I-O, or OPEN INPUT creates the file and returns
file status 05.
An OPEN operation works successfully only when you set fixed file attributes in the
DD statement or data set label for a file and specify consistent attributes for that file
in the SELECT and FD statements of your COBOL program. Mismatches in the
following items result in a file status code 39, and the OPEN statement fails:
v Attributes for file organization (sequential, relative, or indexed)
v Prime record key
v Alternate record keys
v Maximum record size
v Record type (fixed or variable)
How you code the OPEN statement in your COBOL program for a VSAM file
depends on whether the file is empty (a file that has never contained records) or
loaded. For either type of file, your program should check the file status key after
each OPEN statement.
RELATED TASKS
“Opening an empty file”
“Opening a loaded file (a file with records)” on page 147
RELATED REFERENCES
“Statements to load records into a VSAM file” on page 147
When you load VSAM indexed files sequentially, you optimize both loading
performance and subsequent processing performance, because sequential
processing maintains user-defined free space. Future insertions will be more
efficient.
With ACCESS IS SEQUENTIAL, you must write the records in ascending RECORD KEY
order.
When you load VSAM relative files sequentially, the records are placed in the file
in the ascending order of relative record numbers.
In addition to extra overhead for preparing files for use, random processing does
not consider any user-defined free space. As a result, any future insertions might
be inefficient. Sequential processing maintains user-defined free space.
Loading a VSAM data set with access method services: You can load or update
a VSAM data set with the access method services REPRO command. Use REPRO
whenever possible.
RELATED TASKS
“Opening a loaded file (a file with records)” on page 147
RELATED REFERENCES
“Statements to load records into a VSAM file” on page 147
REPRO (OS/390 DFSMS: Access Method Services for Catalogs)
RELATED TASKS
“Opening an empty file” on page 145
“Updating records in a VSAM file” on page 148
If you open a VSAM key-sequenced file as EXTEND, each record you add must have
a record key higher than the highest record in the file.
RELATED TASKS
“Opening an empty file” on page 145
“Working with VSAM data sets under OS/390 and OS/390 UNIX” on page 152
“Defining VSAM data sets under CMS” on page 158
RELATED REFERENCES
“Statements to load records into a VSAM file”
Access Method Services Reference
You can retrieve records in VSAM sequential files only in the sequence in which
they were written.
You can retrieve records in VSAM indexed and relative record files in any of the
following ways:
Sequentially
According to the ascending order of the key you are using, the RECORD KEY
With dynamic access, you can switch between reading a specific record directly
and reading records sequentially, by using READ NEXT for sequential retrieval and
READ for random retrieval (by key).
When you want to read sequentially, beginning at a specific record, use START
before the READ NEXT statement to set the file position indicator to point to a
particular record. When you code START followed by READ NEXT, the next record is
read and the file position indicator is reset to the next record. You can move the
file position indicator randomly by using START, but all reading is done
sequentially from that point.
START file-name KEY IS EQUAL TO ALTERNATE-RECORD-KEY
When a direct READ is performed for a VSAM indexed file, based on an alternate
index for which duplicates exist, only the first record in the data set (base cluster)
with that alternate key value is retrieved. You need a series of READ NEXT
statements to retrieve each of the data set records with the same alternate key. A
file status code of 02 is returned if there are more records with the same alternate
key value to be read; a code of 00 is returned when the last record with that key
value has been read.
RELATED CONCEPTS
“File position indicator” on page 144
RELATED TASKS
“Specifying access modes for VSAM files” on page 141
Access
method ESDS KSDS RRDS
ACCESS IS OPEN EXTEND OPEN EXTEND OPEN EXTEND
SEQUENTIAL WRITE WRITE WRITE
CLOSE CLOSE CLOSE
or or or
OPEN I-O OPEN I-O OPEN I-O
READ READ READ
REWRITE REWRITE REWRITE
CLOSE DELETE DELETE
CLOSE CLOSE
RELATED REFERENCES
“Statements to load records into a VSAM file” on page 147
For indexed files, you must write new records in ascending key sequence. If you
open the file EXTEND, the record keys of the records to be added must be higher
than the highest primary record key on the file when you opened the file.
For relative files, the records must be in sequence. If you include a RELATIVE KEY
data-item in the SELECT clause, the relative record number of the record to be
written is placed in that data item.
When you use ACCESS IS SEQUENTIAL or the file contains spanned records, your
program must first read the record to be deleted. The DELETE then removes the
record that was read. If the DELETE is not preceded by a successful READ, the
deletion is not done and the status key value is set to 92.
When you use ACCESS IS RANDOM or ACCESS IS DYNAMIC, your program need not
first read the record to be deleted. To delete a record, move the key of the record to
be deleted to the RECORD KEY data item and then issue the DELETE. Your program
should check the file status key after each DELETE statement.
If you do not close a VSAM file, the file is automatically closed for you under the
following conditions:
v When the run unit ends normally, all open files defined in any COBOL for
OS/390 & VM, COBOL for MVS & VM, or VS COBOL II programs in the run
unit are closed.
v When the run unit ends abnormally, if the TRAP(ON) run-time option has been
set, all open files defined in any COBOL for OS/390 & VM, COBOL for MVS &
VM, or VS COBOL II programs in the run unit are closed.
v When Language Environment condition handling is completed and the
application resumes in a routine other than where the condition occurred, open
files defined in any COBOL for OS/390 & VM, COBOL for MVS & VM, or VS
COBOL II programs in the run unit that might be called again and reentered are
closed.
You can change the location where a program resumes after a condition is
handled. To make this change, you can, for example, move the resume cursor
with the CEEMRCR callable service or use HLL language constructs such as a C
longjmp statement.
v When you issue CANCEL for a COBOL for OS/390 & VM, COBOL for MVS &
VM, or VS COBOL II subprogram, any open nonexternal files defined in that
program are closed.
All OPEN and CLOSE errors with a VSAM file, whether logical errors in your
program or input/output errors on the external storage media, return control to
your COBOL program, even when you have coded no DECLARATIVE and no FILE
STATUS clause.
If any other input or output statement operation fails, you choose whether your
program will continue running after a less-than-severe input/output error occurs.
COBOL provides these ways for you to intercept and handle certain VSAM input
and output errors:
v End-of-file phrase (AT END)
v EXCEPTION/ERROR declarative
v FILE STATUS clause (file status key and VSAM return code)
v INVALID KEY phrase
You should define a status key for each VSAM file that you define in your
program. Check the status key value after every input or output request, especially
OPEN and CLOSE.
If you do not code a FILE STATUS key or a declarative, serious VSAM processing
errors will cause a message to be issued and a Language Environment condition to
be signaled, which will cause an abend if you specify the run-time option
ABTERMENC(ABEND).
RELATED TASKS
“Handling errors in input and output operations” on page 191
“Using VSAM return codes (VSAM files only)” on page 196
RELATED REFERENCES
OS/390 DFSMS: Macro Instructions for Data Sets
To use explicit passwords, code the PASSWORD clause in the SELECT statement of
your program. Use this clause only if the catalog entry for the files includes a read
or an update password.
v If the catalog entry includes a read password, you cannot open and access the
file in a COBOL program unless you use the password clause in the
FILE-CONTROL paragraph and describe it in the DATA DIVISION. The data-name
referred to must contain a valid password when the file is opened.
For indexed files, the PASSWORD data item for the RECORD KEY must contain the valid
password before the file can be successfully opened.
Working with VSAM data sets under OS/390 and OS/390 UNIX
| There are some special considerations for VSAM files under OS/390 and OS/390
| UNIX in terms of coding access method services (IDCAMS) commands,
| environment variables, and JCL.
You always get a return code of zero on completion of the OPEN statement for a
VSAM sequential file.
RELATED TASKS
“Defining files to the operating system” on page 10
“Defining VSAM files under OS/390”
“Creating alternate indexes” on page 154
“Allocating VSAM files” on page 156
“Sharing VSAM files through RLS” on page 157
A VSAM cluster is a logical definition for a VSAM data set and has one or two
components:
v The data component of a VSAM cluster contains the data records.
v The index component of a VSAM key-sequenced cluster consists of the index
records.
Use the access method services DEFINE CLUSTER command to define your VSAM
data sets (clusters). This process includes creating an entry in an integrated catalog
without any data transfer.
When you define a data set in this way, all records will be padded to the fixed
slot size n. If you use the RECORD IS VARYING ON data-name form of the RECORD
clause, a WRITE or REWRITE will use the length specified in the DEPENDING ON
data-name as the length of the record to be transferred by VSAM. This data is
then padded to the fixed slot size. READ statements always return the fixed slot
size in the DEPENDING ON data-name.
v For VSAM variable-length relative-record data sets (RRDS), specify the average
size COBOL record expected and the maximum size COBOL record expected:
The average size COBOL record expected must be less than the maximum size
COBOL record expected.
v For COBOL simulated variable-length relative-record data sets, specify the
average size of the COBOL records and a size that is greater than or equal to the
maximum size COBOL record plus 4:
DEFINE CLUSTER INDEXED
KEYS(4,0)
RECORDSIZE(avg,m)
The average size COBOL record expected must be less than the maximum size
COBOL record expected.
RELATED TASKS
“Creating alternate indexes”
“Allocating VSAM files” on page 156
“Specifying relative organization for VSAM files” on page 139
RELATED REFERENCES
OS/390 DFSMS: Access Method Services for Catalogs
Access Method Services Reference
Because an alternate index is, in practice, a VSAM data set that contains pointers to
the keys of a VSAM data set, you must define the alternate index and the alternate
index path (the entity that establishes the relationship between the alternate index
and the prime index). After you define an alternate index, make a catalog entry to
establish the relationship (or path) between the alternate index and its base cluster.
This path allows you to access the records of the base cluster through the alternate
keys.
The base cluster and alternate index are described by entries in the same
catalog.
3. Load the VSAM indexed data set.
4. Build the alternate index by using (typically) the BLDINDEX command. Identify
the input file as the indexed data set (base cluster) and the output file as the
alternate index or its path. This command BLDINDEX reads all the records in
your VSAM indexed data set (or base cluster) and extracts the data needed to
build the alternate index.
Alternatively, you can use the run-time option AIXBLD to build the alternate
index at run time. However, this option might adversely affect run-time
performance.
“Example: entries for alternate indexes”
RELATED REFERENCES
AIXBLD (Language Environment Programming Reference)
Using JCL:
//MASTERA DD DSNAME=clustername,DISP=OLD (1)
//MASTERA1 DD DSNAME=path1,DISP=OLD (2)
//MASTERA2 DD DSNAME=path2,DISP=OLD (3)
RELATED TASKS
“Creating alternate indexes” on page 154
| Allocation of VSAM files (indexed, relative, and sequential) follows the general
| rules for the allocation of COBOL files. If you use an environment variable to
| allocate a VSAM file, you must specify these options in the order shown, but no
| others:
| v DSN(dsname), where dsname is the name of the base cluster
| v OLD or SHR
The basic DD statement that you need for your VSAM files is:
//ddname DD DSN=dsname,DISP=SHR,AMP=AMORG
In either case, dsname must be the same as the name used in the access method
services DEFINE CLUSTER or DEFINE PATH command. DISP must be OLD or SHR
because the data set is already cataloged. If you specify MOD when using JCL, the
data set is treated as OLD.
AMP is a VSAM JCL parameter used to supplement the information that the
program supplies about the data set. AMP takes effect when your program opens
the VSAM file. Any information that you set through the AMP parameter takes
precedence over the information that is in the catalog or that the program supplies.
The AMP parameter is not required except under the following circumstances:
v You use a dummy VSAM data set. For example,
//ddname DD DUMMY,AMP=AMORG
v You request additional index or data buffers. For example,
//ddname DD DSN=VSAM.dsname,DISP=SHR,
// AMP=('BUFNI=4,BUFND=8')
| You cannot specify AMP if you allocate your VSAM data set with an environment
| variable.
| For a VSAM base cluster, specify the same system name (ddname or or
| environment variable name) that you specify in the ASSIGN clause of the SELECT
statement in your COBOL program.
| If the length of the base cluster system name and sequence number exceeds eight
| characters, the base cluster portion of the system name is truncated on the right to
| reduce the concatenated result to eight characters. For example, if the system name
| of a base cluster is ABCDEFGH, the system name of the first alternate index path is
ABCDEFG1, the tenth is ABCDEF10, and so on.
RELATED TASKS
“Allocating files” on page 105
RELATED REFERENCES
OS/390 MVS JCL Reference
| You cannot specify RLS if you allocate your VSAM data set with an environment
| variable.
Specifying RLS=CR locks a record and prevents an update to it until another READ is
requested for another record. While a lock on the record being read is in effect,
other users can request a READ for the same record, but they cannot update the
record until the read lock is released. When you specify RLS=NRI, no lock will be in
effect when a READ for input is issued and another user might update the record.
The locking rules for RLS=CR can cause the application to wait for availability of a
record lock, and this wait might slow down the READ for input.
When you open a VSAM data set in RLS mode for INPUT or I-O processing, it is a
good idea to issue an OPEN or START immediately before a READ. If there is a delay
between the OPEN or START and the actual READ, another user might add records
before the record on which the application is positioned after the OPEN or START.
The COBOL run time points explicitly to the beginning of the VSAM data set at
the time when OPEN was requested, but another user might add records that would
alter the true beginning of the VSAM data set if the READ is delayed.
The COBOL run time generates message IGZ0205W and automatically closes the
file if the error occurs during OPEN processing.
All other RLS mode errors return a VSAM return code of 4, 8, or 12.
COBOL coding requirements are the same whether OS/390 or VSE VSAM is used.
However, instead of using the FILEDEF command to identify the VSAM files, you
must use the DLBL command. It has the same basic format as the FILEDEF
command. For example:
If you are running a program that uses a VSAM file and a non-VSAM file, use the
DLBL command to identify the VSAM file and the FILEDEF command to identify
your non-VSAM file. You can set additional options if the VSAM data set is a
multivolume file or if it is cataloged in a user catalog. If you use any of these
special options, you do not need to use the VSAM option.
A special ddname is provided for you to identify the catalog that you use during a
terminal session:
DLBL IJSYSCT F DSN MASTCAT (PERM
Entering this command makes the catalog available to you for the remainder of
your terminal session.
You must use access method services (CMS command AMSERV) to define catalogs,
data spaces, and clusters, and to perform functions such as REPRO, EXPORT, IMPORT,
and LISTCAT. Notice that the commands for these functions under CMS are
VSE/VSAM commands.
If a file with alternate indexes is open for input or output, you must define it with
SHAREOPTIONS(4).
RELATED REFERENCES
DLBL command (VM/ESA CMS User’s Guide)
AMSERV command (CMS Command Reference)
VSE/VSAM Commands and Macros
RELATED TASKS
“Specifying access modes for VSAM files” on page 141
Deciding how big a virtual resource pool to provide (OS/390 DFSMS: Using Data
Sets)
Selecting the optimal percentage of free space (OS/390 DFSMS: Using Data Sets)
RELATED REFERENCES
AMSERV command (CMS Command Reference)
Access Method Services Reference
RELATED CONCEPTS
OS/390 UNIX System Services User’s Guide
RELATED TASKS
“Defining line-sequential files and records in COBOL”
“Describing the structure of a line-sequential file” on page 164
“Coding input-output statements for line-sequential files” on page 165
“Handling errors in line-sequential files” on page 168
“Defining and allocating line-sequential files” on page 165
RELATED REFERENCES
“Allowable control characters” on page 164
| Your ASSIGN assignment-name clause must not include an organization field (S- or
| AS-) before the external name. The ACCESS phrase and the FILE STATUS phrase are
| optional.
RELATED REFERENCES
“Allowable control characters”
| The new-line character is treated as a record delimiter. The other control characters
| are treated as data and are part of the record.
RELATED TASKS
“Defining line-sequential files and records in COBOL” on page 163
| Code the logical size of the records with the RECORD clause. Line-sequential files are
| stream files. Because of their character-oriented nature, the physical records are of
| variable length.
| The following examples show how the FD entry might look for a line-sequential
| file:
| If you code the same fixed size and no OCCURS DEPENDING ON clause for any level-01
| record description entries associated with the file, that fixed size is the logical
| record length. However, because blanks at the end of a record are not written to
| the file, the physical records might be of varying lengths.
RELATED TASKS
“Defining line-sequential files and records in COBOL” on page 163
“Coding input-output statements for line-sequential files”
“Defining and allocating line-sequential files”
RELATED REFERENCES
Data Division—file description entries (IBM COBOL Language Reference)
To define a line-sequential file, define one of the following with a name that
matches the external name on your ASSIGN clause:
| v A DD allocation:
| – A DD statement that specifies PATH=’absolute-path-name’
| – A TSO allocation that specifies PATH(’absolute-path-name’)
RELATED REFERENCES
OS/390 MVS JCL Reference
RELATED TASKS
“Defining line-sequential files and records in COBOL” on page 163
“Describing the structure of a line-sequential file” on page 164
“Opening line-sequential files”
“Reading records from line-sequential files”
“Adding records to line-sequential files” on page 167
“Closing line-sequential files” on page 167
“Handling errors in line-sequential files” on page 168
RELATED REFERENCES
OPEN statement (IBM COBOL Language Reference)
READ statement (IBM COBOL Language Reference)
WRITE statement (IBM COBOL Language Reference)
CLOSE statement (IBM COBOL Language Reference)
| An OPEN statement works if the file is available or has been dynamically allocated.
| Code CLOSE WITH LOCK so that the file cannot be opened again while the program
| is running.
RELATED TASKS
“Reading records from line-sequential files”
“Adding records to line-sequential files” on page 167
“Closing line-sequential files” on page 167
“Defining and allocating line-sequential files” on page 165
RELATED REFERENCES
OPEN statement (IBM COBOL Language Reference)
CLOSE statement (IBM COBOL Language Reference)
| With sequential processing, your program reads one record after another in the
| same order in which the records were entered when the file was created.
| Characters in the file record are read one at a time into the record area until one of
| the following conditions occurs:
| v The record delimiter (the EBCDIC new-line character) is encountered.
| The delimiter is discarded and the remainder of the record area is filled with
| spaces. (Record area is longer than the file record.)
RELATED REFERENCES
OPEN statement (IBM COBOL Language Reference)
WRITE statement (IBM COBOL Language Reference)
| Blanks at the end of the record area are removed and the record delimiter is
| added. The characters in the record area from the first character up to and
| including the added record delimiter are written to the file as one record.
| Records written to line-sequential files must contain only USAGE DISPLAY and
| DISPLAY-1 items. External decimal data items must be unsigned or declared with
| the SEPARATE CHARACTER phrase if signed.
RELATED TASKS
“Opening line-sequential files” on page 166
“Reading records from line-sequential files” on page 166
“Closing line-sequential files”
“Defining and allocating line-sequential files” on page 165
RELATED REFERENCES
OPEN statement (IBM COBOL Language Reference)
WRITE statement (IBM COBOL Language Reference)
| If you do not close a line-sequential file, the file is automatically closed for you
| under the following conditions:
| v When the run unit ends normally.
| v When the run unit ends abnormally, if the TRAP(ON) run-time option is set.
| v When Language Environment condition handling is completed and the
| application resumes in a routine other than where the condition occurred, open
| files defined in any COBOL programs in the run unit that might be called again
| and reentered are closed.
RELATED TASKS
“Opening line-sequential files” on page 166
“Reading records from line-sequential files” on page 166
“Adding records to line-sequential files” on page 167
“Defining and allocating line-sequential files” on page 165
RELATED REFERENCES
CLOSE statement (IBM COBOL Language Reference)
| If you use the FILE STATUS clause, be sure to check the key and take appropriate
| action based on its value. If you do not check the key, it is possible that your
| program could continue; but the results will probably not be what you expected.
RELATED TASKS
“Coding input-output statements for line-sequential files” on page 165
“Handling errors in input and output operations” on page 191
You can mix SORT and MERGE statements in the same COBOL program. A program
can contain any number of sort and merge operations. They can be the same
operation performed many times or different operations. However, one operation
must finish before another begins.
With COBOL for OS/390 & VM, your IBM licensed program for sorting and
merging must be DFSORT or an equivalent. Where DFSORT is mentioned, you can
use any equivalent sort or merge product.
COBOL programs containing SORT or MERGE statements can reside above or below
the 16M line.
| OS/390 UNIX: You cannot run a COBOL program containing SORT or MERGE
| statements under OS/390 UNIX. This restriction includes BPXBATCH. The USING
| or GIVING files on a SORT or MERGE statement can be sequential files residing in the
| HFS.
RELATED CONCEPTS
Sort and merge process
RELATED TASKS
“Describing the sort or merge file” on page 170
“Describing the input to sorting or merging” on page 171
“Describing the output from sorting or merging” on page 173
“Requesting the sort or merge” on page 177
“Determining whether the sort or merge was successful” on page 180
“Improving sort performance with FASTSRT” on page 181
“Controlling sort behavior” on page 184
DFSORT Application Programming Guide
During the merging of two or more files (which must already be sorted), the
records are combined and ordered according to the contents of one or more keys in
each record. As with sorting, the records are first ordered according to the content
of the primary key, then according to the content of the second key, and so on. You
can order the records in either ascending or descending order of each key.
Use MERGE . . . USING to name the files that you want to combine into one
sequenced file. . The merge operation compares keys in the records of the input
files, and passes the sequenced records one by one to the RETURN statement of an
output procedure or to the file that you name in the GIVING phrase.
RELATED REFERENCES
SORT statement (IBM COBOL Language Reference)
MERGE statement (IBM COBOL Language Reference)
Sort-Work-1 is the name of the file in your program. Use this name to refer to
the file.
2. Describe the sort file in an SD entry in the FILE SECTION of the DATA DIVISION.
Every SD entry must contain a record description. For example:
DATA DIVISION.
FILE SECTION.
SD Sort-Work-1
RECORD CONTAINS 100 CHARACTERS.
01 SORT-WORK-1-AREA.
05 SORT-KEY-1 PIC X(10).
05 SORT-KEY-2 PIC X(10).
05 FILLER PIC X(80).
You need SELECT statements and SD entries for sorting or merging, even if you are
sorting or merging data items from WORKING-STORAGE only.
RELATED REFERENCES
“FILE SECTION entries” on page 14
Input-File is the name of the file in your program. Use this name to refer to
the file.
2. Describe the input file (or files when merging) in an FD entry in the FILE
SECTION of the DATA DIVISION. For example:
DATA DIVISION.
FILE SECTION.
FD Input-File
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 CHARACTERS
RECORDING MODE IS F
RECORD CONTAINS 100 CHARACTERS.
01 Input-Record PIC X(100).
RELATED TASKS
“Coding the input procedure” on page 172
“Requesting the sort or merge” on page 177
RELATED REFERENCES
“FILE SECTION entries” on page 14
RELATED TASKS
“Requesting the sort or merge” on page 177
To transfer records to the sort program, all input procedures must contain at least
one RELEASE or RELEASE FROM statement. To release A from X, for example, you can
code:
MOVE X TO A.
RELEASE A.
RELATED REFERENCES
“Restrictions on input and output procedures” on page 175
RELEASE statement (IBM COBOL Language Reference)
Output-File is the name of the file in your program. Use this name to refer to
the file.
2. Describe the output file (or files when merging) in an FD entry in the FILE
SECTION of the DATA DIVISION. For example:
DATA DIVISION.
FILE SECTION.
FD Output-File
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 CHARACTERS
RECORDING MODE IS F
RECORD CONTAINS 100 CHARACTERS.
01 Output-Record PIC X(100).
RELATED TASKS
“Coding the output procedure”
“Requesting the sort or merge” on page 177
RELATED REFERENCES
“FILE SECTION entries” on page 14
You can use the AT END and END-RETURN phrases with the RETURN statement. The
imperative statements on the AT END phrase are performed after all the records
have been returned from the sort file. The END-RETURN explicit scope terminator
delimits the scope of the RETURN statement.
If you use the RETURN INTO statement instead of RETURN, your records will be
returned to WORKING-STORAGE or to an output area.
RELATED REFERENCES
“Restrictions on input and output procedures” on page 175
RETURN statement (IBM COBOL Language Reference)
RELATED TASKS
“Controlling sort behavior” on page 184
“Using checkpoint/restart with DFSORT under OS/390” on page 186
RELATED TASKS
“Controlling sort behavior” on page 184
“Identifying QSAM files to CMS” on page 128 (FILEDEF command)
Using DFSORT/CMS (DFSORT/CMS User’s Guide)
Using the GLOBAL command (Language Environment Programming Guide)
The compiler will determine that the sort work file is variable length if you code
one of the following in its SD entry:
v A RECORD IS VARYING clause
v Two or more record descriptions that define records with different sizes, or
records that contain an OCCURS DEPENDING ON clause
You cannot code RECORDING MODE V for the sort work file because the SD entry does
not allow the RECORDING MODE clause.
RELATED TASKS
“Changing DFSORT defaults with control statements” on page 185
“Controlling sort behavior” on page 184
To transfer sorted or merged records from the sort or merge program directly to
another file without any further processing, use SORT . . . GIVING or MERGE . . .
GIVING and the name of the output file that you have declared in a SELECT
statement. The compiler generates an output procedure to open the output file,
return the records, write the records, and close the file. The output file must not be
open when the SORT or MERGE statement begins execution. For example:
SORT Sort-Work-1
ON ASCENDING KEY Sort-Key-1
USING Input-File
GIVING Output-File.
“Example: describing sort and input files for SORT” on page 171
If you want an input procedure to be performed on the sort records before they are
sorted, use SORT . . . INPUT PROCEDURE. If you want an output procedure to be
performed on the sorted records, use SORT . . . OUTPUT PROCEDURE. For example:
SORT Sort-Work-1
ON ASCENDING KEY Sort-Key-1
INPUT PROCEDURE EditInputRecords
OUTPUT PROCEDURE FormatData.
Restriction: You cannot use an input procedure with the MERGE statement. The
source of input to the merge operation must be a collection of already sorted files.
However, if you want an output procedure to be performed on the merged
records, use MERGE . . . OUTPUT PROCEDURE. For example:
MERGE Merge-Work
ON ASCENDING KEY Merge-Key
USING Input-File-1 Input-File-2 Input-File-3
OUTPUT PROCEDURE ProcessOutput.
You must define Merge-Work in an SD statement in the FILE SECTION of the DATA
DIVISION, and the input files in FD statements in the FILE SECTION.
RELATED CONCEPTS
“Appendix B. Complex OCCURS DEPENDING ON” on page 569 (variably located
items)
RELATED TASKS
“Defining sort and merge data sets under OS/390” on page 175
“Defining sort and merge files under CMS” on page 176
RELATED REFERENCES
SORT control statement (DFSORT Application Programming Guide)
SORT statement (IBM COBOL Language Reference)
MERGE statement (IBM COBOL Language Reference)
RELATED TASKS
“Requesting the sort or merge” on page 177
When you sort or merge an ASCII file, you have to request the ASCII collating
sequence. To do so, code the COLLATING SEQUENCE phrase of the SORT or MERGE
statement, where you define the alphabet-name as STANDARD-1 in the SPECIAL-NAMES
paragraph.
RELATED TASKS
“Specifying the collating sequence” on page 8
RELATED REFERENCES
SORT statement (IBM COBOL Language Reference)
To sort on a windowed date field, use the DATE FORMAT clause to define a
windowed date field; then use the field as the sort key. DFSORT will use the same
century window as that used by the compilation unit. Specify the century window
with the YEARWINDOW compiler option.
DFSORT supports year-last windowed date fields, although the compiler itself
does not provide automatic windowing for year-last windowed date fields in
statements other than MERGE or SORT.
RELATED REFERENCES
“YEARWINDOW” on page 303
The completion code is stored in the SORT-RETURN special register. The contents of
this register change after each SORT or MERGE statement is performed.
You should test for successful completion after each SORT or MERGE statement. For
example:
SORT SORT-WORK-2
ON ASCENDING KEY SORT-KEY
INPUT PROCEDURE IS 600-SORT3-INPUT-PROC
OUTPUT PROCEDURE IS 700-SORT3-OUTPUT-PROC.
IF SORT-RETURN NOT=0
DISPLAY “SORT ENDED ABNORMALLY. SORT-RETURN = ” SORT-RETURN.
. . .
600-SORT3-INPUT-PROC SECTION.
. . .
700-SORT3-OUTPUT-PROC SECTION.
. . .
If you do not reference SORT-RETURN anywhere in your program, the COBOL run
time tests the return code. If the return code is 16, COBOL issues a run-time
diagnostic message.
If you test SORT-RETURN for one or more (but not necessarily all) SORT or MERGE
statements, the COBOL run time does not check the return code.
By default, DFSORT diagnostic messages are sent to the SYSOUT data set. If you
want to change this default, use the MSGDDN parameter of the DFSORT OPTION
control card or use the SORT-MESSAGE special register.
RELATED TASKS
“Checking for sort errors with NOFASTSRT” on page 183
“Controlling sort behavior” on page 184
Restrictions: You cannot use the DFSORT options SORTIN or SORTOUT if you use
| FASTSRT. The FASTSRT compiler option does not apply to line-sequential files you
| use as USING or GIVING files.
If you specify file status and use FASTSRT, file status is ignored during the sort.
RELATED REFERENCES
“FASTSRT” on page 273
“FASTSRT requirements for JCL (OS/390 only)”
“FASTSRT requirements for sort input and output files”
For the input and output files, the DCB parameter of the DD statement in the JCL
must match the FD description.
Many DFSORT functions perform the same operations that are common in input
or output procedures. Code the appropriate DFSORT control statements instead,
and place them either in the IGZSRTCD data set or the SORTCNTL data set.
v Do not code the LINAGE clause for the output FD entry.
v Do not code any INPUT declarative (for input files), OUTPUT declarative (for
output files), or file-specific declaratives (for either input or output files) to
apply to any FDs used in the sort.
v Do not use a variable relative file as the input or output file.
| v Do not use a line-sequential file as the input or output file.
v For either an input or an output file, the record descriptions of the SD and FD
entry must define the same format (fixed or variable), and the largest records of
the SD and FD entry must define the same record length.
Note that if you code a RELATIVE KEY clause for an output file, it will not be set by
the sort.
Tip: If you block your input and output records, the sort performance could be
significantly improved.
QSAM requirements
v QSAM files must have a record format of fixed, variable, or spanned.
v A QSAM input file can be empty.
v To use the same QSAM file for both input and output, you must describe the file
using two different DD statements. For example, in the FILE-CONTROL SECTION
you might code the following:
SELECT FILE-IN ASSIGN INPUTF.
SELECT FILE-OUT ASSIGN OUTPUTF.
In the DATA DIVISION, you would have an FD entry for both FILE-IN and
FILE-OUT, where FILE-IN and FILE-OUT are identical except for their names.
In the PROCEDURE DIVISION, your SORT statement could look like this:
SORT file-name
ASCENDING KEY data-name-1
USING FILE-IN GIVING FILE-OUT
On the other hand, if you code the same file name in the USING and GIVING
phrases, or assign the input and output files the same ddname, then the file can
be accepted for FASTSRT either for input or output, but not both. If no other
conditions disqualify the file from being eligible for FASTSRT on input, then the
file will be accepted for FASTSRT on input, but not on output. If the file was
found to be ineligible for FASTSRT on input, it might be eligible for FASTSRT on
output.
A QSAM file that qualifies for FASTSRT can be accessed by the COBOL program
while the SORT statement is being performed. For example, if the file is used for
FASTSRT on input, you can access it in an output procedure; if it is used for FASTSRT
on output, you can access it in an input procedure.
VSAM requirements
v A VSAM input file must not be empty.
v VSAM files cannot be password protected.
v You cannot name the same VSAM file in both the USING and GIVING phrases.
v A VSAM file that qualifies for FASTSRT cannot be accessed by the COBOL
program until the SORT statement processing is completed. For example, if the
file qualifies for FASTSRT on input, you cannot access it in an output procedure
and vice versa. (If you do so, OPEN will fail.)
RELATED TASKS
DFSORT Application Programming Guide
The code required depends on whether you code a FILE STATUS clause or an ERROR
declarative for the files referenced in the USING and GIVING phrases, as shown in
the table below.
The table below lists those aspects of sort behavior that you can affect using
special registers or compiler options, and the equivalent sort control statement
keywords if any. For a full list of sort keywords, see the reference below.
| You can use the SORT-RETURN special register to determine whether the sort or
| merge was successful and to stop a sort or merge operation prematurely, as
| discussed in the cross-references below.
A compiler warning message (W-level) is issued for each sort special register that
you set in a program.
RELATED TASKS
“Determining whether the sort or merge was successful” on page 180
“Stopping a sort or merge operation prematurely” on page 181
“Changing DFSORT defaults with control statements”
Using DFSORT program control statements (DFSORT Application Programming
Guide)
RELATED REFERENCES
“Default characteristics of the IGZSRTCD data set”
The control statements you can include in the IGZSRTCD data set (in the order
listed) are:
1. SMS=nnnnn, where nnnnn is the length in bytes of the most frequently occurring
record size. (Use only if the SD file is variable length.)
2. OPTION (except keywords SORTIN or SORTOUT).
3. Other DFSORT control statements (except SORT, MERGE, RECORD, or END).
Code control statements between columns 2 and 71. You can continue a control
statement record by ending the line with a comma and starting the next line with a
new keyword. No labels or comments are allowed on a record, and a record itself
cannot be a DFSORT comment statement.
RELATED TASKS
“Controlling sort behavior” on page 184
Using DFSORT program control statements (DFSORT Application Programming
Guide)
RELATED REFERENCES
“Default characteristics of the IGZSRTCD data set”
DFSORT installation should not allocate all the free space in the region for its
COBOL operation, however. When your program is running, storage must be
available for the following:
v COBOL programs that are dynamically called from an input or output procedure
v Language Environment run-time library modules
v Data management modules that can be loaded into the region for use by an
input or output procedure
v Any storage obtained by these modules
For a specific sort or merge operation, you can override the DFSORT storage
values set at installation. To do so, code the MAINSIZE and RESINV keywords on the
OPTION control statement in the sort control statement data set, or use the
SORT-CORE-SIZE special register.
Be careful not to override the storage allocation to the extent that all the free space
in the region is used for sort operations in your COBOL program.
RELATED TASKS
“Controlling sort behavior” on page 184
DFSORT Installation and Customization
RELATED REFERENCES
OPTION control statement (DFSORT Application Programming Guide)
RELATED TASKS
“Changing DFSORT defaults with control statements” on page 185
“Setting checkpoints” on page 501
You must have both an input and an output procedure for the SORT statement. In
the input procedure, use the RELEASE statement to transfer records from the
COBOL program to the sort program before the sort is performed. In the output
procedure, use the RETURN statement to transfer records from the sort program to
the COBOL program after the sort is performed.
RELATED TASKS
“Coding the input procedure” on page 172
“Coding the output procedure” on page 173
RELATED REFERENCES
“CICS SORT application restrictions”
Your error-handling code can take actions such as handling the situation, issuing a
message, or halting the program. In any event, coding a warning message is a
good idea.
You might create error-detection routines for data-entry errors or for errors as your
installation defines them.
COBOL contains special elements to help you anticipate and correct error
conditions:
v User-requested dumps
v ON OVERFLOW in STRING and UNSTRING operations
v ON SIZE ERROR in arithmetic operations
v Technique handling for input or output errors
v ON EXCEPTION or ON OVERFLOW in CALL statements
v User-written routines for handling errors
RELATED TASKS
“Handling errors in joining and splitting strings” on page 190
“Handling errors in arithmetic operations” on page 191
“Handling errors in input and output operations” on page 191
“Handling errors when calling programs” on page 199
“Writing routines for handling errors” on page 199
Requesting dumps
You can obtain a formatted dump of the run-time environment by calling the
Language Environment service CEE3DMP. To obtain a system dump, you can
request an abend without cleanup by calling the Language Environment service
CEE3ABD with a cleanup value of zero.
This callable service stops the run unit immediately, and a system dump is
requested when the abend is issued.
RELATED REFERENCES
Language Environment Debugging Guide and Run-Time Messages
Language Environment Programming Reference
These are the data values before and after the statement is performed:
Because String-ptr has a value of zero that falls short of the receiving field, an
overflow condition occurs and the STRING operation is not completed. (A
String-ptr greater than nine would have the same result.) If ON OVERFLOW had not
been specified, you would not be notified that the contents of Item-4 remain
unchanged.
For ON SIZE ERROR to work correctly for fixed-point overflow and decimal
overflow, you must specify the TRAP(ON) run-time option.
The imperative statement of the ON SIZE ERROR clause will be performed and the
result field will not change in these cases:
v Fixed-point overflow
v Division by zero
v Zero raised to the zero power
v Zero raised to a negative number
v Negative number raised to a fractional power
Floating-point exponent overflow occurs when the value of a floating-point
computation cannot be represented in the System/390 floating-point operand
format. This type of overflow does not cause SIZE ERROR; an abend occurs instead.
You could code a user-written condition handler to intercept the abend and
provide your own error recovery logic.
RELATED REFERENCES
“ON SIZE ERROR and intermediate results” on page 567
| You can use any of the following techniques for intercepting and handling certain
| input or output errors:
| v Imperative-statement phrases on your READ or WRITE statement
If you do not handle an input or output error in any of these ways, a severity-3
| Language Environment condition is signaled, which causes the run unit to end if
the condition is not handled.
The following figures show the flow of logic after the indicated errors:
v VSAM input or output error
| v QSAM and line-sequential input or output error
The following figure shows the flow of logic after a VSAM input or output error:
Applicable*
Yes Execute
imperative
imperative
phrase?
statement
No
Associated Execute
Yes
ERROR ERROR
declarative? declarative
No
File-status
Yes Test file**
clause
status key
specified ?
No
| *Possible phrases for QSAM are AT END, AT END-OF-PAGE, and INVALID KEY; for line
| sequential, AT END.
| **You need to write the code to test the file status key.
RELATED TASKS
“Using the end-of-file condition (AT END)”
“Coding ERROR declaratives” on page 194
“Using file status keys” on page 194
“Handling errors in QSAM files” on page 120
“Using VSAM return codes (VSAM files only)” on page 196
“Coding INVALID KEY phrases” on page 198
Any NOT AT END phrase you code is performed only if the READ statement
completes successfully. If the READ operation fails because of a condition other than
end-of-file, neither the AT END nor the NOT AT END phrase is performed. Instead,
control passes to the end of the READ statement after performing any associated
declarative procedure.
You might choose to code neither an AT END phrase nor an EXCEPTION declarative
procedure, but a status key clause for the file. In that case, control passes to the
next sequential instruction after the input or output statement that detected the
end-of-file conditions. Here presumably you have some code to take appropriate
action.
RELATED REFERENCES
AT END phrases (IBM COBOL Language Reference)
In your procedure, you can choose to try corrective action, retry the operation,
continue, or end execution. You can use the ERROR declaratives procedure in
combination with the file status key if you want a further analysis of the error.
If you continue processing a blocked file, you might lose the remaining records in
a block after the record that caused the error.
Write an ERROR declarative procedure if you want the system to return control to
your program after an error occurs. If you do not write an ERROR declarative
procedure, your job could be canceled or abnormally terminated after an error
occurs.
RELATED REFERENCES
EXCEPTION/ERROR declarative (IBM COBOL Language Reference)
The variable data-name-1 specifies the two-character COBOL file status key that
should be defined in the WORKING-STORAGE SECTION. This data-name cannot be
variably located.
Your program can check the COBOL file status key to discover whether an error
has been made and, if so, what type of error it is. For example, suppose a FILE
STATUS clause is coded like this:
FILE STATUS IS FS-CODE
You can use the status key alone, or in conjunction with the INVALID KEY option, or
to supplement the EXCEPTION or ERROR declarative. Using the status key in this way
gives you precise information about the results of each input or output operation.
The variable data-name-1 specifies the two-character COBOL file status key. The
variable data-name-8 specifies a 6-byte data item that contains the VSAM return
code when the COBOL file status key is not 0.
You can define the second status area, data-name-8, in the WORKING-STORAGE SECTION
as in VSAM-CODE here:
01 RETURN-STATUS.
05 FS-CODE PIC X(2).
05 VSAM-CODE.
10 VSAM-R15-RETURN PIC S9(4) Usage Binary.
10 VSAM-FUNCTION PIC S9(4) Usage Binary.
10 VSAM-FEEDBACK PIC S9(4) Usage Binary.
IF FS-CODE = “00”
PERFORM READ-NEXT UNTIL FS-CODE NOT = “00”
END-IF.
CLOSE VSAMFILE.
STOP RUN.
READ-NEXT.
READ VSAMFILE NEXT.
DISPLAY “READ NEXT VSAMFILE FS-CODE: ” FS-CODE.
IF FS-CODE NOT = “00”
PERFORM VSAM-CODE-DISPLAY
END-IF.
DISPLAY VSAMFILE-REC.
VSAM-CODE-DISPLAY.
DISPLAY “VSAM-CODE ==>”
“ RETURN: ” VSAM-RETURN-CODE,
“ COMPONENT: ” VSAM-COMPONENT-CODE,
“ REASON: ” VSAM-REASON-CODE.
Below is a sample of the output from the example program that checks VSAM
code information:
Use the FILE STATUS clause with INVALID KEY to evaluate the status key and
determine the specific INVALID KEY condition.
You can also include INVALID KEY on WRITE requests for QSAM files, but the
INVALID KEY phrase has limited meaning here. It is used only if you try to write to
a disk that is full.
The FILE-CONTROL entry for the master file of customer records includes statements
defining indexed organization, random access, MASTER-CUSTOMER-NUMBER as the
prime record key, and CUSTOMER-FILE-STATUS as the file status key. The following
example shows how you can use FILE STATUS with the INVALID KEY to more
specifically determine why an input or output statement failed.
Use the ON EXCEPTION clause to perform a series of statements and to perform your
own error handling. For example:
MOVE “REPORTA” TO REPORT-PROG
CALL REPORT-PROG
ON EXCEPTION
DISPLAY “Program REPORTA not available, using REPORTB.'
MOVE ”REPORTB“ TO REPORT-PROG
CALL REPORT-PROG
END-CALL
END-CALL
The ON EXCEPTION clause applies only to the availability of the called program. If
an error occurs while the called program is running, the ON EXCEPTION clause will
not be performed.
RELATED TASKS
COBOL for OS/390 & VM Compiler and Run-Time Migration Guide
RELATED REFERENCES
“CMPR2” on page 264
However, COBOL for OS/390 & VM and Language Environment provide a way
for a user-written program to gain control when such conditions occur. Using
RELATED TASKS
“Using procedure pointers” on page 472
Whether you are compiling using JCL or under TSO, as part of the compilation
step, you need to define the data sets needed for the compilation and specify any
compiler options necessary for your program and the desired output.
The compiler translates your COBOL program into language that the computer can
process (object code). The compiler also lists errors in your source statements and
provides supplementary information to help you debug and tune your program.
Use compiler-directing statements and compiler options to control your
compilation.
After compiling your program, you need to review the results of the compilation
and correct any compiler-detected errors.
RELATED TASKS
“Compiling with JCL”
“Compiling under TSO” on page 215
“Starting the compiler from an assembler program” on page 216
“Defining compiler input and output” on page 218
“Specifying compiler options under OS/390” on page 223
“Compiling multiple programs (batch compilation)” on page 226
“Correcting errors in your source program” on page 230
RELATED REFERENCES
“Compiler-directing statements” on page 304
“Data sets used by the compiler under OS/390” on page 218
“Compiler options and compiler output under OS/390” on page 224
The following JCL shows the general format for a cataloged procedure.
//jobname JOB parameters
//stepname EXEC [PROC=]procname[,{PARM=│PARM.stepname=}'options']
//SYSIN DD data set parameters
. . . (source program to be compiled)
/*
//
RELATED TASKS
“Using a cataloged procedure”
“Writing JCL to compile programs” on page 213
“Specifying compiler options under OS/390” on page 223
“Specifying compiler options in a batch compilation” on page 227
“Compiling programs to create DLLs” on page 490
RELATED REFERENCES
“Data sets used by the compiler under OS/390” on page 218
The following JCL calls the IBM-supplied cataloged procedure (IGYWC) for
compiling a COBOL for OS/390 & VM program and defining the required data
sets:
You can use these procedures with any of the job schedulers that are part of
OS/390. When a scheduler encounters parameters that it does not require, the
scheduler either ignores them or substitutes alternative parameters.
If the compiler options are not explicitly supplied with the procedure, default
options established at the installation apply. You can override these default options
by using an EXEC statement that includes the desired options.
| You can specify data sets to be in the hierarchical file system by overriding the
| corresponding DD statement. However, the compiler utility files (SYSUTx) and copy
| libraries (SYSLIB) you specify must be MVS data sets.
RELATED TASKS
Language Environment Programming Guide
RELATED REFERENCES
“Compile procedure (IGYWC)”
“Compile and link-edit procedure (IGYWCL)” on page 206
“Compile, link-edit, and run procedure (IGYWCLG)” on page 207
“Compile, load, and run procedure (IGYWCG)” on page 208
“Compile, prelink, and link-edit procedure (IGYWCPL)” on page 209
“Compile, prelink, link-edit, and run procedure (IGYWCPLG)” on page 210
“Prelink and link-edit procedure (IGYWPL)” on page 211
“Compile, prelink, load, and run procedure (IGYWCPG)” on page 212
You must supply the following DD statement, indicating the location of the source
program, in the input stream.
//COBOL.SYSIN DD * (or appropriate parameters)
| Example: JCL for compiling using HFS: The following job uses procedure
| IGYWC to compile a COBOL program demo.cbl that is located in the hierarchical
| You can use a mixture of HFS (PATH=’hfs-directory-path’) and MVS data sets
| (DSN=traditional-data-set-name) on the compilation DD statements shown in this
| example as overrides. However, the compiler utility files (DD statements SYSUTx)
| and COPY libraries (DD statements SYSLIB) must be MVS data sets.
RELATED REFERENCES
OS/390 UNIX System Services Command Reference
OS/390 MVS JCL Reference
“Data sets used by the compiler under OS/390” on page 218
You must supply the following DD statement, indicating the location of the source
program, in the input stream.
//COBOL.SYSIN DD * (or appropriate parameters)
The COBOL job step produces an object module that is input to the linkage editor.
Other object modules can be added. If the COBOL program refers to any data sets,
DD statements that define these data sets must also be supplied.
You must supply the following DD statement, indicating the location of the source
program, in the input stream.
//COBOL.SYSIN DD * (or appropriate parameters)
The following shows the statements that make up the IGYWCLG cataloged
procedure.
//IGYWCLG PROC LNGPRFX='IGY.V2R2M0',SYSLBLK=3200,
// LIBPRFX='CEE',GOPGM=GO
//*
//* COMPILE, LINK EDIT AND RUN A COBOL PROGRAM
//*
//* PARAMETER DEFAULT VALUE USAGE
//* LNGPRFX IGY.V2R2M0 PREFIX FOR LANGUAGE DATA SET NAMES
//* SYSLBLK 3200 BLKSIZE FOR OBJECT DATA SET
//* LIBPRFX CEE PREFIX FOR LIBRARY DATA SET NAMES
//* GOPGM GO MEMBER NAME FOR LOAD MODULE
You must supply the following DD statement, indicating the location of the source
program, in the input stream.
//COBOL.SYSIN DD * (or appropriate parameters)
The following shows the statements that make up the IGYWCG cataloged
procedure.
//IGYWCG PROC LNGPRFX='IGY.V2R2M0',SYSLBLK=3200,
// LIBPRFX='CEE'
//*
//* COMPILE, LOAD AND RUN A COBOL PROGRAM
//*
//* PARAMETER DEFAULT VALUE USAGE
//* LNGPRFX IGY.V2R2M0 PREFIX FOR LANGUAGE DATA SET NAMES
//* SYSLBLK 3200 BLKSIZE FOR OBJECT DATA SET
//* LIBPRFX CEE PREFIX FOR LIBRARY DATA SET NAMES
//*
//* CALLER MUST SUPPLY //COBOL.SYSIN DD . . .
//*
//COBOL EXEC PGM=IGYCRCTL,REGION=2048K
You must supply the following DD statement, indicating the location of the source
program, in the input stream.
SYSIN DD * (or appropriate parameters)
The following shows the statements that make up the IGYWCPL cataloged
procedure.
//IGYWCPL PROC LNGPRFX='IGY.V2R2M0',SYSLBLK=3200,
// LIBPRFX='CEE',PLANG=EDCPMSGE,
// PGMLIB='&&GOSET',GOPGM=GO
//*
//* COMPILE, PRELINK AND LINK EDIT A COBOL PROGRAM
//*
//* PARAMETER DEFAULT VALUE USAGE
//* LNGPRFX IGY.V2R2M0 PREFIX FOR LANGUAGE DATA SET NAMES
//* SYSLBLK 3200 BLOCK SIZE FOR OBJECT DATA SET
//* LIBPRFX CEE PREFIX FOR LIBRARY DATA SET NAMES
//* PLANG EDCPMSGE PRELINKER MESSAGES MODULE
//* PGMLIB &&GOSET DATA SET NAME FOR LOAD MODULE
//* GOPGM GO MEMBER NAME FOR LOAD MODULE
//*
//* CALLER MUST SUPPLY //COBOL.SYSIN DD . . .
//*
//COBOL EXEC PGM=IGYCRCTL,REGION=2048K
//STEPLIB DD DSNAME=&LNGPRFX..SIGYCOMP, (1)
// DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSLIN DD DSNAME=&&LOADSET,UNIT=SYSDA,
// DISP=(MOD,PASS),SPACE=(TRK,(3,3)),
// DCB=(BLKSIZE=&SYSLBLK)
//SYSUT1 DD UNIT=SYSDA,SPACE=(CYL,(1,1))
//SYSUT2 DD UNIT=SYSDA,SPACE=(CYL,(1,1))
You must supply the following DD statement, indicating the location of the source
program, in the input stream.
SYSIN DD * (or appropriate parameters)
The following shows the statements that make up the IGYWCPLG cataloged
procedure.
//IGYWCPLG PROC LNGPRFX='IGY.V2R2M0',SYSLBLK=3200,
// PLANG=EDCPMSGE,
// LIBPRFX='CEE',GOPGM=GO
//*
//* COMPILE, PRELINK, LINK EDIT, AND RUN A COBOL PROGRAM
//*
//* PARAMETER DEFAULT VALUE USAGE
//* LNGPRFX IGY.V2R2M0 PREFIX FOR LANGUAGE DATA SET NAMES
//* SYSLBLK 3200 BLKSIZE FOR OBJECT DATA SET
//* PLANG EDCPMSGE PRELINKER MESSAGES MODULE
//* LIBPRFX CEE PREFIX FOR LIBRARY DATA SET NAMES
//* GOPGM GO MEMBER NAME FOR LOAD MODULE
//*
//* CALLER MUST SUPPLY //COBOL.SYSIN DD . . .
//*
//COBOL EXEC PGM=IGYCRCTL,REGION=2048K
//STEPLIB DD DSNAME=&LNGPRFX..SIGYCOMP, (1)
// DISP=SHR
//SYSPRINT DD SYSOUT=*
You must supply the following DD statement, indicating the location of the source
program, in the input stream.
//COBOL.SYSIN DD * (or appropriate parameters)
| You can use a mixture of HFS (PATH=’hfs-directory-path’) and MVS data sets
| (DSN=traditional-data-set-name) on the compilation DD statements for the
| following data sets:
| v Sources files
| v Object files
| v Listings
| v Interface Definition Language files
| v ADATA files
| v Debug files
| v Executable modules
| However, the compiler utility files (DD statements SYSUTx) and COPY files (DD
| statement SYSLIB) must be MVS data sets.
RELATED REFERENCES
OS/390 MVS JCL Reference
You can allocate data sets in any order. However, you must allocate all needed
data sets before you start to compile.
2. Use the CALL command to request compilation:
READY
CALL 'IGY.V2R2M0.SIGYCOMP(IGYCRCTL)'
| You can specify the ALLOCATE and CALL commands on the TSO command line, or, if
| you are not using HFS files, include them in a CLIST.
| You can allocate HFS files for all the compiler data sets except the SYSUTx utility
| data sets and the SYSLIB libraries. Your ALLOCATE statements have the following
| form:
| Allocate File(SYSIN) Path('/u/myu/myap/std/prog2.cbl')
| Pathopts(ORDONLY) Filedata(TEXT)
Format
symbol {LINK|ATTACH} EP=IGYCRCTL,
PARAM=(optionlist[,ddnamelist]),VL=1
VL Specifies that the sign bit is to be set to 1 in the last fullword of the
address parameter list.
When the COBOL for OS/390 & VM compiler completes processing, it puts a
return code in register 15.
RELATED TASKS
“Defining the source code data set (SYSIN)” on page 220
“Specifying source libraries (SYSLIB)” on page 220
“Defining the output data set (SYSPRINT)” on page 221
“Directing compiler messages to your terminal (SYSTERM)” on page 221
“Creating object code (SYSLIN or SYSPUNCH)” on page 221
“Creating an associated data file (SYSADATA)” on page 222
“Defining the output IDL data set (SYSIDL)” on page 222
“Defining the debug data set (SYSDEBUG)” on page 222
RELATED REFERENCES
“Data sets used by the compiler under OS/390”
| Allowable Reside
| Device device on
| Type ddname Function Required? requirements classes HFS?
| Input SYSIN1
Reads source Yes Card reader; Any Yes
program intermediate
storage
| SYSLIB or Reads user source If program has COPY or BASIS Direct access SYSDA No
other copy libraries (PDSs) statements (LIB is required)
libraries1
SOMENV Reads SOM profile If TYPECHK or IDLGEN is in
when OO COBOL effect
programs are
compiled
1. You can use the EXIT option to provide user exits from these data sets.
2. These data sets must be single volume.
RELATED REFERENCES
“Logical record length and block size”
“EXIT” on page 272
1. n = blocking factor
| 2. If you specify BLKSIZE=0, the system will determine the block size.
For variable-length records (RECFM=V), LRECL is the logical record length, and
BLKSIZE equals LRECL plus 4.
You can place your source code or BASIS statement directly in the input stream. If
you do, use this SYSIN DD statement:
//SYSIN DD *
When you use the DD * convention, the source code or BASIS statement must
follow the statement. If another job step follows the compilation, the EXEC
statement for that step follows the /* statement or the last source statement.
You do not need the SYSLIB DD statement if the NOLIB option is in effect.
You can direct the output to a SYSOUT data set, a printer, a direct-access storage
device, or a magnetic-tape device. The listing includes the results of the default or
requested options of the PARM parameter (that is, diagnostic messages, the object
code listing).
| Specify the following for the data set that you define:
| v The name of a sequential data set, the name of a PDS or PDSE member, or an
| HFS path.
| v A data set LRECL of 133.
| v A data set RECFM of F or B.
| v A block size, using the BLKSIZE subparameter of the DCB parameter, or let the
| system set the system-determined default block size.
You can define SYSTERM in various ways, including as a SYSOUT data set, a data
| set on disk, a file in the HFS, or to another print class.
Use the DISP parameter of the SYSLIN DD statement to indicate whether the object
code data set is to be:
v Passed to the linkage editor
v Cataloged
v Kept
v Added to an existing cataloged library
In the example above, the data is created and passed to another job step, the
linkage editor job step.
Your installation might use the DECK option and the SYSPUNCH DD statement.
You do not need the SYSLIN DD statement if the NOOBJECT option is in effect. You do
not need the SYSPUNCH DD statement if the NODECK option is in effect.
RELATED REFERENCES
“OBJECT” on page 284
“DECK” on page 269
The file defined in the SYSADATA DD statement will be a sequential file containing
specific record types that have information about the program collected during
| compilation. The file can be a traditional MVS data set or an HFS file.
RELATED REFERENCES
“ADATA” on page 261
| The file can be a traditional MVS data set as shown, or an HFS file.
| Specify the following for the data set that you define:
| v The name of a sequential data set, the name of a PDS or PDSE member, or an
| HFS path.
| v A data set LRECL greater than or equal to 80, and less than or equal to 1024. The
| default LRECL for SYSDEBUG is 1024.
| v A data set RECFM of F or FB.
| v A block size, using the BLKSIZE subparameter of the DCB parameter, or let the
| system set the system-determined default block size.
RELATED REFERENCES
“TEST” on page 295
The compiler recognizes the options in the following order of precedence from
highest to lowest:
1. Installation defaults that are fixed by your site
| 2. Values of the BUFSIZE, LIB, OUTDD, SIZE, and SQL compiler options in effect for
the first program in a batch
3. Options specified on PROCESS (or CBL) statements, preceding the Identification
Division
4. Options specified on the compiler invocation (JCL PARM parameter or the TSO
CALL command)
5. Installation defaults that are not fixed
This order of precedence also determines which options are in effect when
conflicting or mutually exclusive options are specified.
Most of the options come in pairs; you select one or the other. For example, the
option pair for a cross-reference listing is XREF|NOXREF. If you want a
cross-reference listing, specify XREF. If you do not want one, specify NOXREF.
Some options have subparameters. For example, if you want 44 lines per page on
your listings, specify LINECOUNT(44).
RELATED TASKS
“Specifying compiler options with the PROCESS (CBL) statement”
“Specifying compiler options in a batch compilation” on page 227
RELATED REFERENCES
“Conflicting compiler options” on page 259
“Chapter 16. Compiler options” on page 257
You can start PROCESS in columns 1 through 66. A sequence field is allowed in
columns 1 through 6. When used with a sequence field, PROCESS can start in
columns 8 through 66. If used, the sequence field must contain six characters, and
the first character must be numeric.
You can use CBL as a synonym for PROCESS. CBL can start in columns 1 through 70.
When used with a sequence field, CBL can start in columns 8 through 70.
Use one or more blanks to separate PROCESS from the first option in options-list.
Separate options with a comma or a blank. Do not insert spaces between
individual options and their suboptions.
You can use more than one PROCESS statement. If multiple PROCESS statements are
used, they must follow one another with no intervening statement of any other
type. You cannot continue options across multiple PROCESS statements.
Your programming organization can inhibit the use of PROCESS statements with the
default options module of the COBOL compiler. When PROCESS statements are
found in a COBOL program where not allowed by the organization, the COBOL
compiler generates error diagnostics.
READY
Listing output from compilation will be in the data set defined by SYSPRINT; object
output will be in SYSLIN or SYSPUNCH. Progress and diagnostic messages can be
directed to the SYSTERM data set as well as included in the SYSPRINT data set.
Associated data file records will be in the data set defined by SYSADATA. The
database request module (DBRM) will be the data set defined in DBRMLIB. The
debug information side file will be the data set defined in SYSDEBUG.
Save the listings you produced during compilation. You can use them during the
testing of your work if you need to debug or tune.
After compilation, your next step will be to fix any errors that the compiler found
in your program.
If no errors are detected, you can go to the next step in the process: link-editing, or
binding, your program. (If you used compiler options to suppress object code
generation, you must recompile to obtain it.)
RELATED REFERENCES
“Messages and listings for compiler-detected errors” on page 231
“Chapter 16. Compiler options” on page 257
You can also use a single invocation of the compiler to compile a sequence of class
definitions or a sequence that mixes class definitions and program definitions.
When you compile several programs as part of a batch job, you need to:
v Determine whether you want to create one or more load modules.
v Terminate each program in the sequence.
v Specify compiler options, with an awareness of the effect of compiler options
specified in programs within the batch job.
To create separate load modules, precede each set of modules with the NAME option.
When the compiler encounters a NAME compiler option, the first program in the
sequence and all subsequent programs are link-edited into a single load module,
until the next NAME compiler option is encountered. Then, each successive program
that is compiled with the NAME option is included in a separate load module.
Use the END PROGRAM header to terminate each program in the sequence (except the
last program in the batch for which the END PROGRAM header is optional).
Alternatively, you can precede each program in the sequence with a CBL or PROCESS
statement. (If the CMPR2 compiler option is in effect, separate each program with
the CBL form of the PROCESS or CBL statement.)
If you omit the END PROGRAM header from a program (other than the last program
in a sequence of separate programs), the next program in the sequence will be
nested in the preceding program. An error can occur in either of the following
situations:
v A PROCESS statement is in a program that is now nested.
v A CBL statement is not coded entirely in the sequence number area (columns 1
through 6).
If a CBL statement is coded entirely in the sequence number area (columns 1
through 6), no error message is issued for the CBL statement because it is
considered a label for the source statement line.
“Example: batch compilation”
RELATED TASKS
“Specifying compiler options in a batch compilation” on page 227
RELATED REFERENCES
“NAME” on page 282
“CMPR2” on page 264
RELATED REFERENCES
Cataloged procedures for link-editing COBOL programs (Language Environment
Programming Guide)
If you specify the LIB option for the batch, you cannot change the NUMBER and
SEQUENCE options during the batch compilation. The compiler treats all programs in
the batch as a single input file during NUMBER and SEQUENCE processing under the
LIB option; therefore, the sequence numbers of the entire input file must be in
ascending order.
If the compiler diagnoses the LANGUAGE option on the CBL or PROCESS statement as
an error, the language selection reverts to what was in effect before the compiler
encountered the first CBL or PROCESS statement. The language in effect during a
batch compilation conforms to the rules of processing CBL or PROCESS statements in
that environment.
INVOCATION PARAMETERS:
NOTERM
PROCESS(CBL) statements:
CBL CMPR2,FLAG(I,I)
Options in effect: All options are installation defaults unless otherwise noted:
NOADATA
ADV
QUOTE
NOAWO
BUFSIZE(4096)
CMPR2 Process option PROGRAM 1
.
.
FLAG(I,I) Process option PROGRAM 1
.
.
NOTERM INVOCATION option
.
.
End of compilation for program 1
.
.
PP 5648-A25 IBM COBOL for OS/390 & VM 2.2.0 Date 03/30/2000 Time 10:34:14 Page 4
PROCESS(CBL) statements:
Source Language in
effect
------------------------------------------------------------------------
CBL LANG(JP),FLAG(I,I),APOST,SIZE(MAX) |EN| Installation default -- EN
IDENTIFICATION DIVISION. |JP| Invocation -- XX
PROGRAM-ID. COMPILE1. |: |
. . . |: |
END PROGRAM COMPILE1. |: |
CBL LANGUAGE(YY) |EN| CBL resets language
CBL SIZE(2048K),LANGUAGE(JP),LANG(!!) |: | to EN. LANGUAGE(YY)
IDENTIFICATION DIVISION. |JP| is ignored because it
PROGRAM-ID. COMPILE2. |: | is superseded by (JP).
. . . |: | (!!) is not alpha-
END PROGRAM COMPILE2. |: | numeric and is
IDENTIFICATION DIVISION. |: | discarded.
PROGRAM-ID. COMPILE3. |: |
. . . |: |
END PROGRAM COMPILE3. |: |
CBL LANGUAGE(JP),LANGUAGE(YY) |EN| CBL resets language
. . . |: | to EN. LANGUAGE(YY)
. . . |: | supersedes (JP) but
. . . |: | is nonexistent.
For the program COMPILE1, the default language English (EN) is in effect when
the compiler scans the invocation options. A diagnostic message is issued in
mixed-case English because XX is a nonexistent language identifier. The default EN
remains in effect when the compiler scans the CBL statement. The unrecognized
option APOST in the CBL statement is diagnosed in mixed-case English because the
CBL statement has not completed processing and EN was the last valid language
option. After the compiler processes the CBL options, the language in effect
becomes Japanese (JP).
The program COMPILE3 has no CBL statement, and so it inherits the language in
effect, Japanese (JP), from the previous compilation.
After compiling COMPILE3, the compiler resets the language in effect to English
(EN) because of the CBL statement. The language option in the CBL statement
resolves the last-specified two-character alphanumeric language identifier, which is
YY. Because YY is nonexistent, the language in effect remains English.
Although you should try to correct errors, it is not necessary to fix all of them. A
warning-level or informational-level message can be left in a program without
much risk, and you might decide that the recoding and compilation needed to
remove the error are not worth the effort. Severe-level and error-level errors,
however, indicate probable program failure and should be corrected.
After correcting the errors in your source program, recompile the program. If this
second compilation is successful, go on to the link-editing step. If the compiler still
finds problems, repeat the above procedure until only informational messages are
returned.
RELATED TASKS
“Generating a list of compiler error messages”
RELATED REFERENCES
“Messages and listings for compiler-detected errors” on page 231
The messages for errors found during processing of compiler options, CBL and
PROCESS statements, or BASIS, COPY, and REPLACE statements are displayed near the
top of your listing.
The messages for compilation errors found in your program (ordered by line
number) are displayed near the end of the listing for each program.
A summary of all errors found during compilation is displayed near the bottom of
your listing.
RELATED TASKS
“Correcting errors in your source program” on page 230
“Generating a list of compiler error messages” on page 230
RELATED REFERENCES
“Format of compiler error messages”
“Severity codes for compiler error messages” on page 232
“FLAG” on page 274
RELATED REFERENCES
“Severity codes for compiler error messages”
“FLAG” on page 274
In the following example, the part of the statement that caused the message to be
issued is enclosed in quotes.
Line
ID Message code Message text
2 IGYDS0009-E “PROGRAM” should not begin in area “A.” It was processed as if
found in area “B.”
2 IGYDS1089-S “PROGRAM” was invalid. Scanning was resumed at the next area
“A” item, level-number, or the start of the next clause.
2 IGYDS0017-E “ID” should begin in area “A.” It was processed as if found in
area “A.”
2 IGYDS1003-E A “PROGRAM-ID” paragraph was not found. Program name
“CBLPGM01” was assumed.
2 IGYSC1082-E A period was required. A period was assumed before “ID.”
2 IGYDS1102-E Expected “DIVISION,” but found “ALONGPRO.” “DIVISION”
was assumed before “ALONGPRO.”
2 IGYDS1082-E A period was required. A period was assumed before
“ALONGPRO.”
2 IGYDS1089-S “ALONGPRO” was not valid. Scanning was resumed at the next
area “A” item, level-number, or the start of the next clause.
2 IGYDS1003-E A “PROGRAM-ID” paragraph was not found. Program name
“CBLPGM02” was assumed.
3 IGYPS0017-E “PROCEDURE” should begin in area “A.” It was processed as if
found in area “A.”
| As part of the compilation step, you need to define the files needed for the
| compilation and specify any compiler options necessary for your program and for
| the output that you want.
| The main job of the compiler is to translate your COBOL program into language
| that the computer can process (object code). The compiler also lists errors in your
| source statements and provides supplementary information to help you debug and
| tune your program. Use compiler-directing statements and compiler options to
| control your compilation.
RELATED TASKS
“Setting environment variables under OS/390 UNIX”
“Specifying compiler options under OS/390 UNIX” on page 236
“Compiling and linking with the cob2 command” on page 237
“Compiling using scripts” on page 241
RELATED REFERENCES
“Run-time restrictions under CMS” on page 369
“Data sets used by the compiler under OS/390” on page 218
“Compiler options and compiler output under OS/390” on page 224
| The value that you assign to an environment variable can include other
| environment variables or the variable itself. The values of these variables apply
| only when you compile from the shell where you issue the export command. If
| you do not set an environment variable, either a default value is applied or the
| variable is not defined. The environment variable names must be uppercase.
| The environment variables that you can set for use by the compiler are as follows:
| COBOPT
| Specify compiler options separated by blanks or commas. Separate
| suboptions with commas. Blanks at the beginning or the end of the
| variable value are ignored. Delimit the list of options with quotation marks
| if it contains blanks or characters significant to the OS/390 UNIX shell. For
| example:
| export COBOPT=“TRUNC(OPT) XREF”
RELATED TASKS
“Specifying compiler options under OS/390 UNIX”
“Compiling and linking with the cob2 command” on page 237
RELATED REFERENCES
“Compiler-directing statements” on page 304
“Chapter 16. Compiler options” on page 257
COPY statement (IBM COBOL Language Reference)
| The order of precedence also determines which options are in effect when
| conflicting or mutually exclusive options are specified. When you compile using
| the cob2 command, compiler options are recognized in the following order of
| precedence from highest to lowest:
| 1. Installation defaults fixed as nonoverridable
| 2. The values of BUFSIZE, LIB, SQL, OUTDD, and SIZE options in effect for the first
| program in a batch compilation
RELATED REFERENCES
“Conflicting compiler options” on page 259
“Chapter 16. Compiler options” on page 257
| To compile multiple files (batch compilation), specify multiple source file names.
| When you compile COBOL programs for OS/390 UNIX, the RENT option is
| required. The cob2 command automatically includes the COBOL compiler options
| RENT and TERM.
| The cob2 command invokes the COBOL compiler that is found through the
| standard MVS search order. If the COBOL compiler is not installed in the linklist
| or if more than one level of IBM COBOL compiler is installed on your system, you
| can specify the compiler PDS that you want to use in the STEPLIB environment
| variable. For example:
| export STEPLIB=IGY.V2R2M0.SIGYCOMP
| The cob2 command implicitly uses the OS/390 UNIX shell command c89 for the
| link step. c89 is the shell interface to the linkage editor (the DFSMS program
| management binder).
| Only files with the .cbl extension are passed to the compiler; cob2 passes all other
| files to the linker.
| Listing output that you request from the compilation of a COBOL source program
| file.cbl is written to file.lst. Listing output that you request from the linker is
| written to stdout.
| When you specify cob2 -bdll, the link step produces a DLL definition side file.
| This file contains IMPORT control statements for each of the names exported by the
| DLL. The name of the DLL definition side file is based on the output file name. If
| the output name has an extension, that extension is replaced with “x” to form the
| side file name. For example, if the output file name is foo.dll, the side file name is
| foo.x.
| To use the DLL definition side files later when you create a module that calls the
| DLL, specify the side files with any other object files (file.o) that you specify for the
| linking. For example:
| cob2 -o myappl -qdll myappl.cbl mydll.x
RELATED TASKS
“Compiling programs to create DLLs” on page 490
Language Environment Programming Guide
OS/390 UNIX System Services User’s Guide
RELATED REFERENCES
“cob2” on page 239
“cob2 input and output files” on page 240
“Data sets used by the compiler under OS/390” on page 218
“Compiler options and compiler output under OS/390” on page 224
OS/390 UNIX System Services Command Reference
| This command creates alpha.o and beta.o, then links alpha.o, beta.o, and the
| COBOL libraries. If the link step is successful, it produces an executable program
| named gamma.
| v To compile alpha.cbl with the LIST and NODATA options, enter:
| cob2 -qlist,noadata alpha.cbl
| One special value is when xxx is dll, which specifies that the executable
| module is to be a DLL. It is not passed to the linker.
| -c Compiles programs but does not link them.
| -comprc_ok=n
| Controls cob2 behavior on the return code from the compiler. If the return
| code is less than or equal to n, cob2 continues to the link step or, in the
| compile-only case, exits with a zero return code. If the return code
| returned by the compiler is greater than n, cob2 exits with the same return
| code. When the c89 command is implicitly invoked by cob2 for the link
| step, the exit value from the c89 command is used as the return code from
| the cob2 command.
| The default is -comprc_ok=4.
| -e xxx Specifies the name of a program to be used as the entry point of the
| module. If you do not specify -e, the default entry point is the first
| program (file.cbl) or object file (file.o) that you specify as a file name on the
| cob2 command invocation.
| -g Prepares the program for debugging. Equivalent to specifying the TEST
| option with no suboptions.
| -Ixxx Adds a path xxx to the directories to be searched for COPY files for which
| you do not specify a library-name.
| To specify multiple paths, either use multiple -I options, or use a colon to
| separate multiple path names within a single -I option value.
| For COPY statements where you have not coded an explicit library name,
| the compiler searches for your COPY book in this order:
| 1. In the current directory
| 2. In the paths you specify with the -I cob2 option
| 3. In the paths you specify in the SYSLIB environment variable
RELATED TASKS
“Compiling and linking with the cob2 command” on page 237
“Setting environment variables under OS/390 UNIX” on page 235
| File
| name Description Comments
| file.cbl COBOL source file to be compiled and Will not be linked if you specify the
| linked cob2 option -c
| file.a Archive file Produced by the ar command, to be
| used during the link-edit phase
| file.o Object file to be link-edited Can be produced by the COBOL
| compiler, the C/C++ compiler, or the
| assembler
| file.x DLL definition side file Used during the link-edit phase of an
| application that references the dynamic
| link library (DLL)
| When you use the cob2 command, the following files are created in the current
| directory:
RELATED TASKS
“Compiling and linking with the cob2 command” on page 237
RELATED REFERENCES
“ADATA” on page 261
“TEST” on page 295
“IDLGEN” on page 277
OS/390 UNIX System Services Command Reference
RELATED TASKS
“Accessing the compiler (CP LINK and ACCESS)”
“Specifying a source program to compile” on page 244
“Using compiler-directing statements” on page 245
“Specifying compiler options under CMS” on page 246
“Naming generated files under CMS” on page 251
“Correcting errors” on page 252
“Chapter 22. Running COBOL programs under CMS” on page 369
RELATED REFERENCES
“Run-time restrictions under CMS” on page 369
“COBOL2” on page 244
“Differences in compiler options under CMS” on page 248
“Files used by the compiler under CMS” on page 248
This example links to disk 194 of the virtual machine that contains the IBM
COBOL for OS/390 & VM product and for which the user ID is PRODUCT. It defines
disk 194 as 198 to the VM session. It asks for read access to the disk (RR) and
enters the read-share password for the 194 disk (PASSWORD). After linking to the 194
disk as 198, this code accesses the 198 disk as disk B.
This command compiles the COBOL source program named PROG1 using the
compiler options SOURCE, VBREF, XREF, and MAP. The source program must have a
file type of COBOL.
v Issue a FILEDEF for SYSIN before compiling. For example:
FILEDEF SYSIN DISK PROG2 COBOL A
COBOL2 (SOURCE,VBREF,XREF,MAP)
This code compiles the COBOL program named PROG2 using the options
entered with the COBOL2 command.
The compiler uses the source program that you enter with the FILEDEF, even if
you provided an optional file name on the command line. The compiler uses the
optional file name for the name of listing, text, SYSADATA, and work files. With
FILEDEF, the file type need not be COBOL.
v Supply source statements from a user-supplied module by using the EXIT
compiler option.
Neither a FILEDEF for SYSIN nor a file name in the COBOL2 command is required.
For example:
COBOL2 (EXIT(INEXIT('ABCD',INMOD1)),VBREF,XREF)
This command compiles the source statements provided by the input user
module named INMOD1 using the character string ABCD and the options VBREF
and XREF.
The compiler ignores FILEDEF for SYSIN when the INEXIT suboption of the EXIT
option is specified. However, you can provide an optional file name with the
COBOL2 command that will be used as the name for listing, text, and work files.
RELATED REFERENCES
“COBOL2”
COBOL2
You can compile programs under CMS by using the COBOL2 command.
Your installation might have created a synonym for COBOL2 when the compiler was
installed. See your system programmer for the command name.
RELATED TASKS
“Specifying a source program to compile” on page 244
“Specifying compiler options under CMS” on page 246
“Naming generated files under CMS” on page 251
RELATED REFERENCES
“Additional compiler options under CMS” on page 247
If you have files that contain frequently used COBOL code, you can place them in
a CMS file called a MACLIB. You can then use the compiler-directing COPY
statement in your COBOL program and identify the MACLIB to be searched
during compilation.
If you are using the compiler-directing BASIS statement, you also place the BASIS
program in a CMS MACLIB file.
To make the MACLIB available, you must issue the CMS GLOBAL command:
GLOBAL MACLIB mylib
If the GLOBAL command is issued, the FILEDEF command for SYSLIB will be issued
by IBM COBOL for OS/390 & VM.
To use the COPY statement to copy from libraries other than SYSLIB, you must issue
a FILEDEF command for each library. The ddname field of the FILEDEF command is
identical to the library-name in your program. For these additional libraries, do not
issue a GLOBAL command.
RELATED REFERENCES
“Compiler-directing statements” on page 304
You can enter more than one compiler option on the COBOL2 command line, using a
blank character or a comma as a separator. Do not mix commas and blanks within
the command. If you choose blanks, use all blanks; if you choose commas, use all
commas.
The COBOL2 command can diagnose some errors in compiler options from the
command line by issuing a message to the terminal and then stopping the
compilation. If the compilation is not ended, you should check the compiler listing
for other compiler-detected errors. The listing shows subparameter values that are
not valid. If a subparameter is optional, you can omit it and the separator
character.
The format for specifying options in the COBOL2 command is the same as for
specifying options on the PROCESS statement.
Option lists for existing applications that use only spaces and no parentheses will
continue to work, and the compiler will issue a warning indicating that
parentheses were added to the option list. If you change an existing options list by
adding an option that requires parentheses, by adding commas, or by adding an
option greater than eight characters, then parentheses must also be added to all the
existing options that require them.
For example, the VM/ESA default setting for the logical escape character is the
quotation mark (“). Suppose the compiler option CURRENCY(”$“) was entered with
the COBOL2 command:
COBOL2 progname (CURRENCY(”$“)
VM/ESA removes the character ” from the input stream and passes the following
code:
CURRENCY($)
The COBOL for OS/390 & VM compiler then diagnoses the option CURRENCY($) as
not valid because of the missing delimiters in the value.
RELATED REFERENCES
“Additional compiler options under CMS”
“Files used by the compiler under CMS” on page 248
“Error messages from COBOL2” on page 252
Use DISK to request that a program listing be produced containing any of the
following information:
v Page headings
v Line numbers of the statements in error
v Message identification numbers
v Severity levels
v Message texts
v Any other output requested by OFFSET, MAP, LIST, XREF, SOURCE, or VBREF
This listing will be written to the appropriate read/write disk with a file type of
LISTING.
If you have issued a FILEDEF for SYSPRINT to redirect the listing file produced by
the compiler, the DISK, PRINT, and NOPRINT options are ignored.
DISK, PRINT, and NOPRINT are opposing options. If you enter more than one of these
options with the COBOL2 command, the last one takes precedence.
RELATED REFERENCES
“Conflicting compiler options” on page 259
“Chapter 16. Compiler options” on page 257
When the compiler is running, it uses and creates both work and default files, as
shown below.
Default
FILEDEF File type Function Required? device Comments
SYSIN COBOL Reads the source file Yes Disk
SYSLIB MACLIB Reads user source libraries If program has COPY or Disk
BASIS statements (LIB
option is required)
1. These files are written to the minidisk with the most available read-write space; they are erased at the end of
compilation.
2. LISTING, TEXT, and SYSADATA files are written to the minidisk where the source COBOL program resides, if
that disk is accessed as read-write. If that disk is not accessed in read-write mode, the LISTING, TEXT, and
SYSADATA files are written to the first read-write disk found using the search order.
The following table lists the types of output you will get if you use various
compiler options.
If you start the compiler using COBOL2 and the file name of the source program, the
compiler will assign file names that are the same as the source program file name:
COBOL2 filename (SOURCE,VBREF,XREF,MAP)
You can override the name of a compiler-created file (such as listing, text, or work
files) by issuing a CMS FILEDEF command. When you issue a FILEDEF with a
different file name or file type, the file is not erased when the compilation ends.
Indicate the file name to be assigned by the compiler for these files with any of the
following methods when you start the compiler:
FILEDEF SYSIN DISK PROG2 COBOL A
COBOL2 PROG1 (SOURCE,VBREF,XREF,MAP)
or
COBOL2 PROG1 (EXIT(INEXIT('ABCD',INMOD1)),VBREF,XREF)
or
FILEDEF SYSIN DISK PROG2 COBOL A
COBOL2 PROG1 (EXIT(INEXIT('ABCD',INMOD1)),VBREF,XREF)
In all the above cases, the compiler assigns the file name PROG1.
Overriding FILEDEF
By using the PRTEXIT suboption of the EXIT option, you can override two
specifications for file names:
v The listing output from the FILEDEF command for SYSPRINT
v Any optional file name that you specify in the COBOL2 command
For example:
FILEDEF SYSPRINT DISK PROG4 COBOL A
COBOL2 PROG2 (EXIT(PRTEXIT('WXYZ',OUTMOD)),VBREF,XREF)
This code causes the SYSPRINT output to be transmitted to the user-supplied exit
module named OUTMOD.
RELATED REFERENCES
“Files used by the compiler under CMS” on page 248
Correcting errors
You can usually identify a problem from the diagnostic message you see displayed
at the terminal, so that you do not have to examine a printed listing file. When
you have an error, you can correct the source file immediately and recompile it.
Under CMS, the TERM option is in effect unless the default value for your site has
been changed to TERM=NO or you have specified the NOTERM option. TERM specifies
that all diagnostic messages issued by the compiler are displayed at your terminal,
in addition to being written to a LISTING file.
RELATED REFERENCES
“Error messages from COBOL2”
The error was issued because the specified input file was not found on any of the
accessed disks. You should reissue the command using the correct file name.
The messages issued by the COBOL2 command will be in the language specified by
your installation’s default setting for the LANGUAGE compiler option.
The error messages issued by the COBOL2 command are listed below.
Be sure to check your listing for any errors not detected by the COBOL2 command.
DMSIGY000E
Explanation: An error was detected that will terminate the COBOL2 command. This
message will be issued only once for invalid COBOL2 commands.
System action: Execution of the COBOL2 command ends. The system status is the
same as before the command executed, except that all user FILEDEFs issued
without the PERM option will be cleared.
DMSIGY002E
Explanation: The specified input file was not found on any of the accessed disks.
Programmer response: Reissue the command, specifying the correct input file.
System action: RC=40. Execution of the COBOL2 command ends. The system has the
same status as before the command executed.
DMSIGY003E
System action: RC=40. Execution of the COBOL2 command ends. The system has the
same status as before the command executed.
DMSIGY004E
DMSIGY005W
System action: The compiler adds any required parentheses to the list.
DMSIGY011E
Explanation: No read/write disk is available for compiler output and work files.
System action: RC=40. Execution of the COBOL2 command ends. The system has the
same status as before the command executed.
DMSIGY012E
Explanation: A user FILEDEF specifying a device invalid for SYSIN has been issued.
Programmer response: Reissue the COBOL2 command specifying a valid device for
SYSIN, or clear the SYSIN FILEDEF.
System action: RC=40. Execution of the COBOL2 command ends. The user-issued
FILEDEF is cleared unless the PERM option was specified. Otherwise, the system has
the same status as before the command executed.
SOURCE FILE “filename filetype” DID NOT HAVE “FIXED” RECORD FORMAT.
Programmer response: Change the record format of the source file to FIXED and
reissue the command.
System action: RC=40. Execution of the COBOL2 command ends. The system has the
same status as before the command executed.
DMSIGY030E
Explanation: At least one invalid option is specified in the command line. The
invalid options are listed under message DMSIGY031I that follows.
System action: RC=40. Execution of the COBOL2 command ends. The system has the
same status as before the command executed.
DMSIGY031I
“option-1 option-2...option-n”.
DMSIGY032E
Programmer response: Reissue the COBOL2 command, specifying a value for the
option.
System action: RC=40. Execution of the COBOL2 command ends. The system has the
same status as before the command executed.
DMSIGY033E
Explanation: User specified too many characters for options in the COBOL2
command line.
System action: RC=40. Execution of the COBOL2 command ends. The system has the
same status as before the command executed. for the options.
DMSIGY034E
A LEFT PARENTHESIS “(” DID NOT PRECEDE THE OPTION LIST IN THE COBOL2
COMMAND.
Explanation: Options following the file name in the COBOL2 command must be
preceded by a left parenthesis.
Programmer response: Reissue the COBOL2 command with the correct syntax.
System action: RC=40. Execution of the COBOL2 command ends. The system has the
same status as before the command executed.
DMSIGY036W
Explanation: A right parenthesis has prematurely ended the option list in the
COBOL2 command.
System action: RC=0. Any options following a right parenthesis are ignored. The
COBOL2 command will be executed unless other terminating errors are detected.
DMSIGY037E
Explanation: The user specified GRAPHIC as an option of the COBOL2 command. This
option is not supported in Release 2.0 or later.
Programmer response: Reissue the COBOL2 command without the GRAPHIC option.
System action: RC=40. Execution of the COBOL2 command ends. The system has the
same status as before the command executed.
RELATED TASKS
“Correcting errors” on page 252
Compiler options affect the aspects of your program that are listed in the table
below. The linked-to information for each option provides the syntax for specifying
the option and describes the option, its parameters, and its interaction with other
parameters.
Aspect of your
program Compiler option Default Abbreviations
| Source language “ARITH” on page 262 ARITH(COMPAT) AR(C), AR(E)
“QUOTE/APOST” on page 289 QUOTE Q|APOST
“CMPR2” on page 264 NOCMPR2 None
“CURRENCY” on page 265 NOCURRENCY CURR|NOCURR
“DBCS” on page 269 NODBCS None
“LIB” on page 280 LIB None
“NUMBER” on page 283 NONUMBER NUM|NONUM
“SEQUENCE” on page 291 SEQUENCE SEQ|NOSEQ
| “SQL” on page 293 NOSQL None
“WORD” on page 301 NOWORD WD|NOWD
Date processing “DATEPROC” on page 267 NODATEPROC, or DP|NODP
DATEPROC(FLAG,NOTRIG) if only
DATEPROC is specified
“INTDATE” on page 278 INTDATE(ANSI) None
“YEARWINDOW” on page 303 YEARWINDOW(1900) YW
Maps and listings “LANGUAGE” on page 279 LANGUAGE(ENGLISH) LANG(EN|UE|JA|JP)
“LINECOUNT” on page 280 LINECOUNT(60) LC
“LIST” on page 281 NOLIST None
“MAP” on page 281 NOMAP None
“OFFSET” on page 285 NOOFFSET OFF|NOOFF
“SOURCE” on page 292 SOURCE S|NOS
“SPACE” on page 293 SPACE(1) None
“TERMINAL” on page 295 NOTERMINAL TERM|NOTERM
“VBREF” on page 301 NOVBREF None
“XREF” on page 302 NOXREF X|NOX
Installation defaults: The default options that were set up when your compiler
was installed are in effect for your program unless you override them with other
options. (In some installations, certain compiler options are set up as fixed so that
you cannot override them. If you have problems, see your system administrator.)
To find out the default compiler options in effect, run a test compilation without
specifying any options; the output listing lists the default options specified by your
installation.
CMS only: The compiler options DISK, PRINT, and NOPRINT, which are not listed in
the following table, are unique to COBOL under CMS. For a description, see the
related information below.
RELATED REFERENCES
“Conflicting compiler options”
“Compiler-directing statements” on page 304
“Option settings for COBOL 85 Standard conformance”
RELATED TASKS
“Chapter 13. Compiling under OS/390” on page 203
“Compiling under TSO” on page 215
“Chapter 15. Compiling under CMS” on page 243
“Chapter 14. Compiling under OS/390 UNIX” on page 235
“Chapter 33. Tuning your program” on page 535
RELATED TASKS
“Specifying compiler options under OS/390” on page 223
“Specifying compiler options in a batch compilation” on page 227
“Specifying compiler options under OS/390 UNIX” on page 236
“Specifying compiler options under CMS” on page 246
ADATA
Use ADATA when you want the compiler to create a SYSADATA file, which contains
records of additional compilation information. It is required for remote compile
using IBM VisualAge COBOL. On OS/390, this file is written to DDNAME SYSADATA.
On CMS, a file with file type SYSADATA is created. The size of this file generally
grows with the size of the associated program.
You cannot specify ADATA in a PROCESS (CBL) statement; it can be specified only in
one of the following ways:
v On invocation of the compiler using an option list
v On the PARM field of JCL
v As a command option
v As an installation default
RELATED REFERENCES
“Appendix C. EXIT compiler option” on page 575
“Conflicting compiler options” on page 259
ANALYZE
Use ANALYZE when you want the compiler to check the syntax of embedded SQL
and CICS statements in addition to native COBOL statements.
This option can be set as the installation default option or as a compiler invocation
option, but cannot be set on a CBL or PROCESS statement.
The specification of the ANALYZE option forces the handling of the following
character strings as reserved words:
v CICS
v EXEC
v END-EXEC
v SQL
RELATED REFERENCES
“Conflicting compiler options” on page 259
ADV
ADV has meaning only if you use WRITE . . . ADVANCING in your source code.
With ADV in effect, the compiler adds 1 byte to the record length to account for the
printer control character.
Use NOADV if you have already adjusted your record length to include 1 byte for the
printer control character.
ARITH
RELATED REFERENCES
“Conflicting compiler options” on page 259
AWO
With AWO specified, an implicit APPLY WRITE-ONLY clause is activated for all files in
the program that are eligible for this clause. To be eligible, a file must have
physical sequential organization and blocked variable-length records.
RELATED TASKS
“Optimizing buffer and device space” on page 12
BUFSIZE
If you use both BUFSIZE and SIZE, the amount allocated to buffers is included in
the amount of main storage available for compilation via the SIZE option.
BUFSIZE cannot exceed the track capacity for the device used, nor can it exceed the
maximum allowed by data management services.
CMPR2
Use CMPR2 when you want the compiler to generate code that is compatible with
code generated by VS COBOL II Release 2. Valid COBOL source programs that
compiled successfully under VS COBOL II Release 2 also compile successfully
under COBOL for OS/390 & VM with CMPR2 in effect and will provide compatible
results.
The only valid VS COBOL II Release 2 programs that do not compile successfully
under CMPR2 are programs comparing an internal decimal item, a binary item, or
an arithmetic expression to a group item.
| Limited support: In general, new language elements added to IBM COBOL since
| VS COBOL II Release 2 are not supported under CMPR2. CMPR2 is intended only as a
| migration aid to enable continued use of programs that are written at the VS
| COBOL II Release 2 language level.
RELATED REFERENCES
“FLAGMIG” on page 275
“Conflicting compiler options” on page 259
Differences between CMPR2 and NOCMPR2 (COBOL for OS/390 & VM Compiler
and Run-Time Migration Guide)
Use the COMPILE option only if you want to force full compilation even in the
presence of serious errors. All diagnostics and object code will be generated. Do
not try to run the object code generated if the compilation resulted in serious
errors—the results could be unpredictable or an abnormal termination could occur.
Use NOCOMPILE without any suboption to request a syntax check (only diagnostics
produced, no object code).
CURRENCY
The default currency symbol is the dollar sign ($). You can use the CURRENCY option
to provide an alternate default currency symbol to be used for the COBOL
program.
To change the default currency symbol, use the CURRENCY(literal) option where
literal is a valid COBOL nonnumeric literal (including a hex literal) representing a
single character that must not be any of the following:
v Digits zero (0) through nine (9)
If you use both the CURRENCY option and the CURRENCY SIGN clause in a program,
the CURRENCY option is ignored. Currency symbols specified in the CURRENCY SIGN
clause or clauses can be used in PICTURE clauses.
When the NOCURRENCY option is in effect and you omit the CURRENCY SIGN clause,
the dollar sign ($) is used as the PICTURE symbol for the currency sign.
Delimiter note: The CURRENCY option literal can be delimited by either the quote or
the apostrophe, regardless of the QUOTE|APOST compiler option setting.
If you plan to specify the CURRENCY compiler option in the COBOL2 command under
CMS, see the special usage notes under Specifying compiler options using the
COBOL2 command in the related information below.
RELATED TASKS
“Specifying compiler options under CMS” on page 246
“Conflicting compiler options” on page 259
DATA
Language Environment provides services that control the storage used at run time.
IBM COBOL for OS/390 & VM uses these services for all storage requests
For reentrant programs, the DATA(24|31) compiler option and the HEAP run-time
option control whether storage for dynamic data areas (such as WORKING-STORAGE
section and FD record areas) is obtained from below the 16-MB line or from
unrestricted storage. (The DATA option does not affect the location of LOCAL-STORAGE
section variables; the STACK run-time option controls that location instead.)
When you specify the run-time option HEAP(BELOW), the DATA(24|31) compiler
option has no effect; the storage for all dynamic data areas is allocated from below
the 16-MB line. However, with HEAP(ANYWHERE) as the run-time option, storage for
Specify the DATA(24) compiler option for programs running in 31-bit addressing
mode that are passing data parameters to programs in 24-bit addressing mode.
This ensures that the data will be addressable by the called program.
External data
In addition to affecting how storage is obtained for dynamic data areas, the
DATA(24|31) compiler option can also influence where storage for external data is
obtained. Storage required for external data will be obtained from unrestricted
storage if the following conditions are met:
v The program is compiled with the DATA(31) compiler option.
v The HEAP(ANYWHERE) run-time option is in effect.
v The ALL31(ON) run-time option is in effect.
In all other cases, the storage for external data will be obtained from below the
16-MB line. To specify the ALL31(ON) run-time option, all the programs in the run
unit must be capable of running in 31-bit addressing mode.
RELATED TASKS
Using run-time options (Language Environment Programming Guide)
RELATED REFERENCES
“Allocation of buffers for QSAM files” on page 127
DATEPROC
Notes:
1. NODATEPROC conforms to the COBOL 85 Standard.
2. You can specify the FLAG|NOFLAG and TRIG|NOTRIG suboptions in any order. If
you omit either suboption, it defaults to the current setting.
RELATED REFERENCES
“FLAG” on page 274
“Conflicting compiler options” on page 259
Using DBCS causes the compiler to recognize X’0E’ (SO) and X’0F’ (SI) as shift
codes for the double-byte portion of a nonnumeric literal.
With DBCS selected, the double-byte portion of the literal is syntax-checked and the
literal remains category alphanumeric.
RELATED REFERENCES
“Conflicting compiler options” on page 259
DECK
Use DECK to produce object code in the form of 80-column card images. If you use
the DECK option, be certain that SYSPUNCH is defined in your JCL for compilation.
DIAGTRUNC
| The diagnostic message is also issued for implicit moves associated with
| statements such as these:
| v INITIALIZE
| There is no diagnostic for COMP-5 receivers, nor for binary receivers when you
| specify the TRUNC(BIN) option.
RELATED CONCEPTS
“Formats for numeric data” on page 36
“Reference modifiers” on page 87
RELATED REFERENCES
“TRUNC” on page 297
“Conflicting compiler options” on page 259
DISK/PRINT
The DISK and PRINT|NOPRINT compiler options are unique to COBOL under CMS.
RELATED REFERENCES
“Additional compiler options under CMS” on page 247
DLL
| Execution of programs compiled with the DLL option is allowed only under
| OS/390. You can specify the DLL option when compiling under VM/CMS, but the
| resulting application object modules must be moved to OS/390 for linking and for
| execution.
Use DLL to instruct the compiler to generate an object module that is enabled for
dynamic link library (DLL) support. DLL enablement is required if the program
will be part of a DLL, will reference DLLs, or if the program contains
object-oriented COBOL syntax such as INVOKE statements, class definitions, or calls
to SOMobjects API functions.
Specification of the DLL option requires that the RENT linkage editor option also be
used.
NODLL instructs the compiler to generate an object module that is not enabled for
DLL usage.
DUMP
Use DUMP to produce a system dump at compile time for an internal compiler error.
Under CMS, this option specifies that there is to be an abend at the point of
failure, but no output is produced. The DUMP option should only be used at the
request of an IBM representative.
The dump, which consists of a listing of the compiler’s registers and a storage
dump, is intended primarily for diagnostic personnel for determining errors in the
compiler.
If you use the DUMP option, include a DD statement at compile time to define
SYSABEND, SYSUDUMP, or SYSMDUMP.
With DUMP, the compiler will not issue a diagnostic message before abnormal
termination processing. Instead, a user abend will be issued with an IGYppnnnn
message. In general, a message IGYppnnnn corresponds to a compile-time user
abend nnnn. However, both IGYpp5nnn and IGYpp1nnn messages produce a user
abend of 1nnn. You can usually distinguish whether the message is really a 5nnn or
a 1nnn by recompiling with the NODUMP option.
This situation is not a compiler error. Using the NODUMP option will allow the
compiler to issue message IGYOP3124-W and continue processing.
RELATED TASKS
Understanding abend codes (Language Environment Debugging Guide and Run-Time
Messages)
DYNAM
Use DYNAM to cause nonnested, separately compiled programs invoked through the
CALL literal statement to be loaded (for CALL) and deleted (for CANCEL) dynamically
at run time. Any CALL identifier statements that cannot be resolved in your program
are also handled as dynamic calls. The DYNAM compiler option must not be used by
programs that are translated by the CICS translator.
If your COBOL program calls programs that have been linked as dynamic link
libraries (DLLs), then you must not use the DYNAM option. You must instead
compile the program with the NODYNAM and DLL options. In particular, if your
program calls SOMobjects API functions, then you must compile it with NODYNAM
and DLL.
RELATED REFERENCES
“Making both static and dynamic calls” on page 465
“Conflicting compiler options” on page 259
EXIT
For information on the EXIT compiler option, see the first reference below.
RELATED REFERENCES
“Appendix C. EXIT compiler option” on page 575
“Conflicting compiler options” on page 259
EXPORTALL
| Execution of programs compiled with the EXPORTALL option is only allowed under
| OS/390. You can specify the EXPORTALL option when compiling under VM/CMS,
| but you must move the resulting application object modules to OS/390 for linking
| and for execution.
NOEXPORTALL instructs the compiler to not export any symbols. In this case the
programs and class definitions are only accessible from other routines that are
link-edited into the same load module together with this COBOL class or program
definition.
RELATED REFERENCES
“Conflicting compiler options” on page 259
FASTSRT
FASTSRT allows IBM DFSORT, or its equivalent, to perform the input and output
instead of COBOL.
RELATED TASKS
“Improving sort performance with FASTSRT” on page 181
Use FLAG(x) to produce diagnostic messages for errors of a severity level x or above
at the end of the source listing.
Use FLAG(x,y) to produce diagnostic messages for errors of severity level x or above
at the end of the source listing, with error messages of severity y and above to be
embedded directly in the source listing. The severity coded for y must not be
lower than the severity coded for x. To use FLAG(x,y), you must also specify the
SOURCE compiler option.
Error messages in the source listing are set off by embedding the statement
number in an arrow that points to the message code. The message code is then
followed by the message text. For example:
With FLAG(x,y) selected, messages of severity y and above will be embedded in the
listing following the line that caused the message. (Refer to the notes below for
exceptions.)
Use NOFLAG to suppress error flagging. NOFLAG will not suppress error messages for
compiler options.
Embedded messages:
1. Specifying embedded level-U messages is accepted, but will not produce any
messages in the source. Embedding a level-U message is not recommended.
2. The FLAG option does not affect diagnostic messages produced before the
compiler options are processed.
3. Diagnostic messages produced during processing of compiler options, CBL and
PROCESS statements, or BASIS, COPY, and REPLACE statements, are never
embedded in the source listing. All such messages appear at the beginning of
the compiler output.
4. Messages produced during processing of the *CONTROL (*CBL) statement are not
embedded in the source listing.
RELATED REFERENCES
“Messages and listings for compiler-detected errors” on page 231
RELATED REFERENCES
“Conflicting compiler options” on page 259
CMPR2, FLAGMIG, and NOCOMPILE compiler options (COBOL for OS/390 & VM
Compiler and Run-Time Migration Guide)
FLAGSTD
Use FLAGSTD to get informational messages about the COBOL 85 Standard elements
included in your program. You can specify any of the following items for flagging:
v A selected Federal Information Processing Standard (FIPS) COBOL subset
v Any of the optional modules
v Obsolete language elements
v Any combination of subset and optional modules
v Any combination of subset and obsolete elements
v IBM extensions (these are flagged any time FLAGSTD is specified and are
identified as “nonconforming nonstandard”)
The informational messages appear in the source program listing and contain the
following information:
v Identify the element as “obsolete,” “nonconforming standard,” or
“nonconforming nonstandard” (a language element that is both obsolete and
nonconforming is flagged as obsolete only).
v Identify the clause, statement, or header that contains the element.
v Identify the source program line and beginning location of the clause, statement,
or header that contains the element.
v Identify the subset or optional module to which the element belongs.
FLAGSTD requires the standard set of reserved words.
In the following example, the line number and column where a flagged clause,
statement, or header occurred are shown, as well as the message code and text. At
the bottom is a summary of the total of the flagged items and their type.
3 1 1 1
RELATED REFERENCES
“Conflicting compiler options” on page 259
Use the IDLGEN option to indicate whether SOM Interface Definition Language
(IDL) should be generated for COBOL class definitions contained in the COBOL
source file.
Use IDLGEN to request that in addition to the compile of the COBOL source file,
IDL definitions for classes defined in the file be generated.
The IDL is written to the data set specified on the SYSIDL DD statement, which
must be included in the JCL for the compilation. The data set name on the SYSIDL
DD statement must specify a member of a partitioned data set (PDS) that has fixed
or fixed-blocked records (RECFM=F or RECFM=FB) and a record length (LRECL) of
between 80 and 255 characters. The default record length is 255 characters. IDL
does not support continuation characters, so if a line output by the compiler is
longer than the LRECL of the IDL output data set, the line is truncated. This could
occur if the class uses very long names for methods or the external class-name, and
the LRECL of the IDL output data set is too short. A record length of 255 is
recommended, since IDL created by COBOL compiler will always fit in
255-character lines.
When a COBOL source file contains more than one class definition (batch compile)
and you use the IDLGEN option, the COBOL class definitions must be sequenced in
an appropriate order within the source file. The generated IDL for such a batch
compile contains multiple class interfaces with the IDL interfaces in the same order
as the COBOL classes were defined in the COBOL source file. The SOM IDL
compiler requires that interfaces be defined before they are referenced. So if there
are references between the classes in the COBOL batch compile, the referenced
classes must precede the referencing classes in the COBOL source file.
Do not use SIZE(MAX) when you are compiling large object-oriented applications
with the IDLGEN option. You must leave storage space in the user region for
Interface Repository data.
RELATED TASKS
“Chapter 24. Writing object-oriented programs” on page 375
“Chapter 26. Using SOM IDL-based class libraries” on page 425
OS/390 SOMobjects Programmer’s Guide
RELATED REFERENCES
“Conflicting compiler options” on page 259
INTDATE
INTDATE(ANSI) instructs the compiler to use the ANSI COBOL Standard starting
date for integer dates used with date intrinsic functions. Day 1 is Jan 1, 1601.
With INTDATE(ANSI), the date intrinsic functions return the same results as in
COBOL/370 Release 1.
With INTDATE(LILIAN), the date intrinsic functions return results compatible with
the Language Environment date callable services. These results will be different
than in COBOL/370 Release 1.
Usage notes:
1. When INTDATE(LILIAN) is in effect, CEECBLDY is not usable since you have no
way to turn an ANSI integer into a meaningful date using either intrinsic
functions or callable services. If you code a CALL literal statement with
CEECBLDY as the target of the call with INTDATE(LILIAN) in effect, the
compiler diagnoses this and converts the call target to CEEDAYS.
2. If your installation default is INTDATE(LILIAN), you should recompile all of your
COBOL/370 Release 1 programs that use intrinsic functions to ensure that all of
your code uses the Lilian integer date standard. This method is the safest,
because you can store integer dates and pass them between programs, even
between PL/I, COBOL, and C programs, and know that the date processing
will be consistent.
RELATED REFERENCES
“Conflicting compiler options” on page 259
LANGUAGE
Use the LANGUAGE option to select the language in which compiler output will be
printed. The information that will be printed in the selected language includes
diagnostic messages, source listing page and scale headers, FIPS message headers,
message summary headers, compilation summary, and headers and notations that
result from the selection of certain compiler options (MAP, XREF, VBREF, and
FLAGSTD).
name specifies the language for compiler output messages. Possible values for the
LANGUAGE option are shown in the table.
1. If your installation’s system programmer has provided a language other than those
described, you must specify at least the first two characters of this other language’s
name.
2. To specify a language other than UENGLISH, the appropriate language feature must be
installed.
NATLANG: The NATLANG run-time option allows you to control the national language
to be used for the run-time environment, including error messages, month names,
and day-of-the-week names. The LANGUAGE compiler option and the NATLANG
run-time option act independently of each other. You can use them together with
neither taking precedence over the other.
LIB
If your program uses COPY, BASIS, or REPLACE statements, you need to specify the
| LIB compiler option. In addition, for COPY and BASIS statements, you need to define
| the library or libraries from which the compiler can take the copied code. Define
| the libraries with DD statements, ALLOCATE commands, environment variables, or
| FILEDEF commands as appropriate for your environment. When using JCL, also
include a DD statement to allocate SYSUT5.
RELATED REFERENCES
“Compiler-directing statements” on page 304
“Conflicting compiler options” on page 259
LINECOUNT
Abbreviations are: LC
If you specify LINECOUNT(0), no page ejects are generated in the compilation listing.
The compiler uses three lines of nnn for titles. For example, if you specify
LINECOUNT(60), 57 lines of source code are printed on each page of the output
listing.
RELATED TASKS
“Getting listings” on page 319
RELATED REFERENCES
“Conflicting compiler options” on page 259
*CONTROL (*CBL) statement (IBM COBOL Language Reference)
MAP
Use the MAP compiler option to produce a listing of the items you defined in the
DATA DIVISION. The output includes the following:
v DATA DIVISION map
v Global tables
v Literal pools
v Nested program structure map, and program attributes
By selecting the MAP option, you can also print an embedded MAP report in the
source code listing. The condensed MAP information is printed to the right of
data-name definitions in the FILE SECTION, WORKING-STORAGE SECTION, and LINKAGE
SECTION of the DATA DIVISION. When both XREF data and an embedded MAP
summary are on the same line, the embedded summary is printed first.
RELATED CONCEPTS
“Chapter 17. Debugging” on page 309
RELATED TASKS
“Getting listings” on page 319
RELATED REFERENCES
*CONTROL (*CBL) statement (IBM COBOL Language Reference)
NAME
Use NAME to generate a link-edit NAME card for each object module. NAME is also used
to generate names for each load module when doing batch compilations. When
NAME is specified, a NAME card is appended to each object module that is created.
Load module names are formed using the rules for forming module names from
PROGRAM-ID statements.
The NAME or NAME(ALIAS) options cannot be used when compiling programs that
will be prelinked with the Language Environment prelinker.
RELATED REFERENCES
PROGRAM-ID paragraph (IBM COBOL Language Reference)
Use the NUMBER compiler option if you have line numbers in your source code and
want those numbers to be used in error messages and SOURCE, MAP, LIST, and XREF
listings.
If you request NUMBER, the compiler checks columns 1 through 6 to make sure that
they contain only numbers and that the numbers are in numeric collating
sequence. (In contrast, SEQUENCE checks the characters in these columns according
to EBCDIC collating sequence.) When a line number is found to be out of
sequence, the compiler assigns to it a line number with a value one higher than the
line number of the preceding statement. The compiler flags the new value with
two asterisks and includes in the listing a message indicating an out-of-sequence
error. Sequence-checking continues with the next statement, based on the newly
assigned value of the previous line.
If you use COPY statements and NUMBER is in effect, be sure that your source
program line numbers and the COPY member line numbers are coordinated.
If you are doing a batch compilation and LIB and NUMBER are in effect, all programs
in the batch compile will be treated as a single input file. The sequence numbers of
the entire input file must be in ascending order.
Use NONUMBER if you do not have line numbers in your source code, or if you want
the compiler to ignore the line numbers you do have in your source code. With
NONUMBER in effect, the compiler generates line numbers for your source statements
and uses those numbers as references in listings.
NUMPROC
Use NUMPROC(NOPFD) if you want the compiler to perform invalid sign processing.
This option is not as efficient as NUMPROC(PFD); object code size will be increased,
and there could be an increase in run-time overhead to validate all signed data.
External decimal, unsigned: High-order 4 bits of the sign byte contain X’F’.
External decimal, signed overpunch: High-order 4 bits of the sign byte contain
X’C’ if the number is positive or 0, X’D’ if it is not.
External decimal, separate sign: Separate sign contains the character ’+’ if the
number is positive or 0, ’-’ if it is not.
Internal decimal, unsigned: Low-order 4 bits of the low-order byte contain X’F’.
Internal decimal, signed: Low-order 4 bits of the low-order byte contain X’C’ if the
number is positive or 0, X’D’ if it is not.
Using NUMPROC(PFD) can affect class tests for numeric data. You should use
NUMPROC(NOPFD) or NUMPROC(MIG) if a COBOL program calls programs written in
PL/I or FORTRAN.
Sign representation is not only affected by the NUMPROC option, but also by the
installation time option NUMCLS.
Use NUMPROC(MIG) to aid in migrating OS/VS COBOL programs to IBM COBOL for
OS/390 & VM. When NUMPROC(MIG) is in effect, the following processing occurs:
v Preferred signs are created only on the output of MOVE statements and arithmetic
operations.
v No explicit sign repair is done on input.
v Some implicit sign repair might occur during conversion.
v Numeric comparisons are performed by a decimal compare, not a logical
compare.
RELATED TASKS
“Checking for incompatible data (numeric class test)” on page 42
RELATED REFERENCES
“Sign representation and processing” on page 41
OBJECT
If you specify OBJECT, include a SYSLIN DD statement in your JCL for compilation.
The only difference between DECK and OBJECT is in the routing of the data sets:
v DECK output goes to the data set associated with ddname SYSPUNCH.
v OBJECT output goes to the data set associated with ddname SYSLIN.
Use the option your installation guidelines recommend.
RELATED REFERENCES
“Conflicting compiler options” on page 259
OFFSET
Use OFFSET to produce a condensed PROCEDURE DIVISION listing. With OFFSET, the
condensed PROCEDURE DIVISION listing will contain line numbers, statement
references, and the location of the first instruction generated for each statement. In
addition, the following are produced:
v Global tables.
v Literal pools.
v Size of the program’s WORKING-STORAGE, and its location in the object code if the
program is compiled with the NORENT option.
RELATED REFERENCES
“Conflicting compiler options” on page 259
OPTIMIZE
Use OPTIMIZE to reduce the run time of your object program; optimization might
also reduce the amount of storage your object program uses. Because OPTIMIZE
increases compile time, and can change the order of statements in your program, it
should not be used when debugging.
RELATED CONCEPTS
“Optimization” on page 542
RELATED REFERENCES
“Conflicting compiler options” on page 259
OUTDD
Use OUTDD to specify that you want DISPLAY output that is directed to the system
| logical output device to go to a specific ddname. Note that you can specify a file in
| the hierarchical file system (HFS) with the ddname named in OUTDD. See the
| discussion of the DISPLAY statement for defaults and for behavior when this
| ddname is not allocated.
The MSGFILE run-time option allows you to specify the ddname of the file to which
all run-time diagnostics and reports generated by the RPTOPTS and RPTSTG run-time
options are written. The IBM-supplied default is MSGFILE(SYSOUT). If the OUTDD
compiler option and the MSGFILE run-time option both specify the same ddname,
RELATED TASKS
“Displaying values on a screen or in a file (DISPLAY)” on page 29
RELATED REFERENCES
MSGFILE (Language Environment Programming Reference)
PGMNAME
The PGMNAME option controls the handling of names used in the following contexts:
v Program names defined in the PROGRAM-ID paragraph
v Program entry point names on the ENTRY statement
v Program name references in:
– Calls to nested programs
– Static calls to separately compiled programs
– Static SET procedure-pointer TO ENTRY literal statement
– CANCEL of a nested program
PGMNAME(COMPAT)
With PGMNAME(COMPAT), program names are handled in a manner compatible with
COBOL/370 Release 1, namely:
v The program name can be up to 30 characters in length.
v All the characters used in the name must be alphabetic, digits, or the hyphen,
except that if the program name is entered in the literal format and is in the
outermost program, then the literal can also contain the extension characters @,
#, and $.
v At least one character must be alphabetic.
v The hyphen cannot be used as the first or last character.
External program names are processed by the compiler as follows:
v They are folded to uppercase.
v They are truncated to eight characters.
v Hyphens are translated to zero (0).
v If the first character is not alphabetic, it is converted as follows:
– 1-9 are translated to A-J.
– Anything else is translated to J.
PGMNAME(LONGMIXED)
With PGMNAME(LONGMIXED), program names are processed as is, without truncation,
translation, or folding to uppercase.
The literal used for a program name (in any of the contexts listed above as affected
by the PGMNAME option) can contain any character in the range X’41’-X’FE’.
QUOTE/APOST
Use QUOTE if you want the figurative constant [ALL] QUOTE or [ALL] QUOTES to
represent one or more quotation mark (“) characters. QUOTE conforms to the
COBOL 85 Standard.
Use APOST if you want the figurative constant [ALL] QUOTE or [ALL] QUOTES to
represent one or more apostrophe (’) characters.
RENT
| OS/390 UNIX: You must use RENT for programs to be run in the OS/390 UNIX
| environment.
When a reentrant program is to be run with extended addressing, you can use the
DATA(24|31) option to control whether dynamic data areas are allocated in
unrestricted storage or in storage obtained from below 16 MB. Compile programs
with RENT or RMODE(ANY) if they will be run with extended addressing in virtual
storage addresses above 16 MB.
RENT|NORENT also affects the RMODE (residency mode) that your program will run
under. All IBM COBOL for OS/390 & VM programs are AMODE(ANY).
Link-edit considerations: If all programs in a load module are compiled with RENT,
then it is recommended that the load module be link-edited with the RENT link-edit
attribute. (Use the REUS link-edit attribute instead if the load module will also
contain any non-COBOL programs that are serially reusable.)
If any program in a load module is compiled with NORENT, the load module must
not be link-edited with the RENT or REUS link-edit attributes. The NOREUS
linkage-editor option is needed to ensure that the CANCEL statement will guarantee
a fresh copy of the program on a subsequent CALL.
RELATED REFERENCES
“Conflicting compiler options” on page 259
RMODE
A program compiled with the RMODE(AUTO) option will have RMODE(24) if NORENT is
specified, and RMODE(ANY) if RENT is specified. This is the same behavior as
COBOL/370 Release 1 and VS COBOL II.
A program compiled with the RMODE(24) option will have RMODE(24) whether
NORENT or RENT is specified.
A program compiled with the RMODE(ANY) option will have RMODE(ANY) whether
NORENT or RENT is specified.
Passing data: IBM COBOL for OS/390 & VM NORENT programs compiled with
RMODE(ANY) that are required to pass data to programs running in AMODE(24) must
be link-edited with RMODE(24). The data areas for NORENT programs will be above
the line or below the line depending on the RMODE of the program, even if DATA(24)
has been specified.
RELATED REFERENCES
“QSAM input/output buffers” on page 267
“Conflicting compiler options” on page 259
SEQUENCE
When you use SEQUENCE, the compiler examines columns 1 through 6 of your
source statements to check that the statements are arranged in ascending order
according to their EBCDIC collating sequence. The compiler issues a diagnostic
message if any statements are not in ascending sequence (source statements with
blanks in columns 1 through 6 do not participate in this sequence check and do
not result in messages).
If you use COPY statements and SEQUENCE is in effect, be sure that your source
program sequence fields and the copy member sequence fields are coordinated.
If you use NUMBER and SEQUENCE, the sequence is checked according to numeric,
rather than EBCDIC, collating sequence.
If you are doing a batch compilation and LIB and SEQUENCE are in effect, all
programs in the batch compile will be treated as a single input file. The sequence
numbers of the entire input file must be in ascending order.
SIZE
Abbreviations are: SZ
Use SIZE to indicate the amount of main storage available for compilation (where
1K = 1024 bytes decimal).
Do not use SIZE(MAX) if, when you invoke the compiler, you require it to leave a
specific amount of unused storage available in the user region. If you specify
SIZE(MAX) in an extended addressing environment, the compiler uses:
v Above the 16-MB line—all the storage in the user region
v Below the 16-MB line—storage for:
– Work file buffers
– Compiler modules that must be loaded below the line
Do not use SIZE(MAX) when you are compiling large object-oriented applications
with either the IDLGEN or TYPECHK options. Storage space must be left in the user
region for Interface Repository data.
SOURCE
Use SOURCE to get a listing of your source program. This listing will include any
statements embedded by PROCESS or COPY statements.
You must specify SOURCE if you want embedded messages in the source listing.
Use NOSOURCE to suppress the source code from the compiler output listing.
If you want to limit the SOURCE output, use *CONTROL SOURCE or NOSOURCE
statements in your PROCEDURE DIVISION. Your source statements following a
*CONTROL NOSOURCE are not included in the listing at all, unless a *CONTROL SOURCE
statement switches the output back to normal SOURCE format.
RELATED REFERENCES
*CONTROL (*CBL) statement (IBM COBOL Language Reference)
Use SPACE to select single-, double-, or triple-spacing in your source code listing.
SPACE has meaning only when the SOURCE compiler option is in effect.
RELATED REFERENCES
“SOURCE” on page 292
SQL
| Use the SQL compiler option to enable the DB2 coprocessor capability and to
| specify DB2 suboptions. You must specify the SQL option if your COBOL source
| program contains SQL statements and it has not been processed by the DB2
| precompiler.
| When you use the SQL option, the compiler writes the database request module
| (DBRM) to ddname DBRMLIB. Note that the compiler needs access to DB2 Version 7
| or later.
| If you specify the NOSQL option, any SQL statements found in the source program
| are diagnosed and discarded.
| You can partition a long suboption string into multiple suboption strings on
| multiple CBL statements. The DB2 suboptions are concatenated in the order of their
| appearance. For example:
| //STEP1 EXEC IGYWC, . . .
| // PARM.COBOL='SQL(“string1”)'
| //COBOL.SYSIN DD *
| CBL SQL(“string2”)
| CBL SQL(“string3”)
| IDENTIFICATION DIVISION.
| PROGRAM-ID. DRIVER1.
| . . .
| The concatenated strings are delimited with single spaces as shown. If multiple
| instances of the same DB2 option are found, the last specification of each option
| prevails. The compiler limits the length of the concatenated DB2 suboptions string
| to 4K bytes.
RELATED TASKS
“Compiling with the SQL option” on page 356
RELATED REFERENCES
“Conflicting compiler options” on page 259
SSRANGE
Use SSRANGE to generate code that checks if subscripts (including ALL subscripts) or
indexes try to reference an area outside the region of the table. Each subscript or
index is not individually checked for validity; rather, the effective address is
checked to ensure that it does not cause a reference outside the region of the table.
Variable-length items will also be checked to ensure that the reference is within
their maximum defined length.
Remember: You will get range checking only if you compile your program with
the SSRANGE option and run it with the CHECK(ON) run-time option.
RELATED CONCEPTS
“Reference modifiers” on page 87
Use TERMINAL to send progress and diagnostic messages to the SYSTERM data set.
TEST
Use TEST to produce object code that enables Debug Tool to perform batch and
interactive debugging. The amount of debugging support available depends on
which TEST suboptions you use. The TEST option also allows you to request that
symbolic variables be included in the formatted dump produced by Language
Environment.
Use NOTEST if you do not want to generate object code with debugging information
and do not want the formatted dump to include symbolic variables.
| When you set the SYM suboption, you can specify the optional suboption SEPARATE,
| indicating that the symbolic information tables for the Debug Tool are generated in
| a data set separate from the object module. When you do not specify the SEPARATE
| suboption, the symbolic information is included in the object module.
| When you invoke the COBOL compiler from JCL or from TSO and you specify the
| TEST(. . .,SYM,SEPARATE) option, the symbolic debug information tables are
| written to the data set specified in the SYSDEBUG DD statement. The SYSDEBUG DD
| statement must specify the name of a sequential data set, the name of a PDS or
| PDSE member, or an HFS path. The data set LRECL must be greater than or equal
| to 80, and less than or equal 1024. The default LRECL for SYSDEBUG is 1024. The
| data set RECFM can be F or FB. You can set the block size by either using the
| BLKSIZE subparameter of the DCB parameter, or leave it to the system to set it to the
| system-determined default block size.
| When you invoke the COBOL compiler from the OS/390 UNIX shell and you
| specify the TEST(. . .,SYM,SEPARATE) option, the symbolic debug information
| tables are written to file file.dbg in the current directory, where file is the name of
| the COBOL source file.
| Production debugging: With the latest levels of Debug Tool you can step through
| your program, even if there are no compiled-in hooks, using new Debug Tool
| function called overlay hooks. To take advantage of this function, compile with
| NOOPTIMIZE and TEST(NONE). This is sometimes referred to as production debugging
| or production-level debugging, because you avoid the performance overhead of
| compiled-in hooks yet most Debug Tool function is still available. Production
| debugging also refers to using the SEPARATE suboption to keep the load module
| size smaller and yet maintain Debug Tool and Language Environment formatted
| dump functionality.
| When you use production debugging with overlay hooks, there are some
| restrictions on debugging function, such as:
| v The GO TO Debug Tool command is not supported.
There are two ways that the TEST option can improve your formatted dumps from
Language Environment:
v Use the NOSYM suboption of TEST to have line numbers in the dump that indicate
the failing statement, rather than just an offset.
v Use the SYM suboption of TEST to have the values of the program variables listed
in the dump.
With NOTEST, the dump will not have program variables and will not have a line
number for the failing statement.
RELATED CONCEPTS
Considerations for setting TERMTHDACT options (Language Environment
Debugging Guide and Run-Time Messages)
RELATED TASKS
“Defining the debug data set (SYSDEBUG)” on page 222
Generating a dump (Language Environment Debugging Guide and Run-Time Messages)
Invoking Debug Tool using the run-time TEST option (Debug Tool User’s Guide and
Reference)
RELATED REFERENCES
“Conflicting compiler options” on page 259
TEST | NOTEST (Language Environment Programming Reference)
TRUNC
| TRUNC has no effect on COMP-5 data items; COMP-5 items are handled as if
| TRUNC(BIN) were in effect regardless of the TRUNC suboption specified.
TRUNC(STD)
Use TRUNC(STD) to control the way arithmetic fields are truncated during
MOVE and arithmetic operations. TRUNC(STD) applies only to USAGE BINARY
receiving fields in MOVE statements and arithmetic expressions. When
TRUNC(STD) is in effect, the final result of an arithmetic expression, or the
sending field in the MOVE statement, is truncated to the number of digits in
the PICTURE clause of the BINARY receiving field.
TRUNC(OPT)
TRUNC(OPT) is a performance option. When TRUNC(OPT) is in effect, the
compiler assumes that data conforms to PICTURE specifications in USAGE
BINARY receiving fields in MOVE statements and arithmetic expressions. The
results are manipulated in the most optimal way, either truncating to the
number of digits in the PICTURE clause, or to the size of the binary field in
storage (halfword, fullword, or doubleword).
Tips:
TRUNC example 1
01 BIN-VAR PIC 99 USAGE BINARY.
. . .
MOVE 123451 to BIN-VAR
The following table shows values of the data items after the MOVE:
A halfword of storage is allocated for BIN-VAR. The result of this MOVE statement if
the program is compiled with the TRUNC(STD) option is 51; the field is truncated to
conform to the PICTURE clause.
If you compile the program with the TRUNC(BIN), the result of the MOVE statement is
-7621. The reason for the unusual result is that nonzero high-order digits are
truncated. Here, the generated code sequence would merely move the lower
halfword quantity X’E23B’ to the receiver. Because the new truncated value
overflows into the sign bit of the binary halfword, the value becomes a negative
number.
It is better not to compile this MOVE statement with TRUNC(OPT), because 123451 has
greater precision than the PICTURE clause for BIN-VAR. With TRUNC(OPT), the results
are again -7621. This is because the best performance was gained by not doing a
decimal truncation.
TRUNC example 2
01 BIN-VAR PIC 9(6) USAGE BINARY
. . .
MOVE 1234567891 to BIN-VAR
The following table shows values of the data items after the MOVE:
When you specify TRUNC(STD), the sending data is truncated to six integer digits to
conform to the PICTURE clause of the BINARY receiver.
When you specify TRUNC(OPT), the compiler assumes the sending data is not larger
than the PICTURE clause precision of the BINARY receiver. The most efficient code
sequence in this case is ttruncation as if TRUNC(STD) were in effect.
When you specify TRUNC(BIN), no truncation occurs because all of the sending data
fits into the binary fullword allocated for BIN-VAR.
RELATED CONCEPTS
“Formats for numeric data” on page 36
RELATED TASKS
“Preparing COBOL programs to run under CICS” on page 350
Use TYPECHK to have the compiler enforce the rules for object-oriented type
checking, and generate diagnostics for any violations.
The type conformance requirements are covered in the IBM COBOL Language
Reference under the appropriate language elements. Type-checking requirements
include:
v The method being invoked on an INVOKE statement must be supported by the
class of the referenced object.
v Method parameters on an INVOKE and the corresponding method PROCEDURE
DIVISION USING must conform.
v The SET object-reference-1 TO object-reference-2 statement requires that the classes of
the objects be of appropriate derivation relationships.
v A method override must have a conforming interface to the corresponding
method in the parent class.
When you specify TYPECHK, there must be entries in the SOM Interface Repository
(IR) for each class that is referenced in the COBOL source being compiled.
For COBOL classes, you can create the IR entries by using the COBOL IDLGEN
option when compiling the class definitions. Doing so creates an IDL file that
describes the interface of the COBOL class. Compile the IDL using the SOM
Compiler with its “ir” emitter.
Note that if the COBOL program references classes that are provided by the SOM
product itself (such as the SOMObject class), then you can use the pregenerated IR
for these classes (provided as part of the OS/390 SOMobjects product) to verify
that the COBOL usage conforms to the class interfaces.
Do not use SIZE(MAX) when you are compiling large object-oriented applications
with the TYPECHK option. Storage space must be left in the user region for Interface
Repository data.
RELATED CONCEPTS
“Chapter 25. System Object Model” on page 415
RELATED REFERENCES
“IDLGEN” on page 277
“Conflicting compiler options” on page 259
Use VBREF to get a cross-reference among all verb types used in the source program
and the line numbers in which they are used. VBREF also produces a summary of
how many times each verb was used in the program.
WORD
xxxx specifies the ending characters of the name of the reserved-word table
(IGYCxxxx) to be used in your compilation. IGYC are the first four standard
characters of the name, and xxxx can be one to four characters in length.
RELATED TASKS
“Preparing COBOL programs to run under CICS” on page 350
RELATED REFERENCES
“Conflicting compiler options” on page 259
XREF
Use XREF to get a sorted cross-reference listing. EBCDIC data names and procedure
names are listed in alphanumeric order. DBCS data names and procedure names
are listed based on their physical order in the program, and appear before the
EBCDIC data names and procedure names, unless the DBCSXREF installation option
is selected with a DBCS ordering program. In this case, DBCS data names and
procedure names are ordered as specified by the DBCS ordering program.
Also included is a section listing all the program names that are referenced in your
program, and the line number where they are defined. External program names are
identified as such.
If you use XREF and SOURCE, cross-reference information will also be printed on the
same line as the original source in the listing. Line number references or other
information, will appear on the right-hand side of the listing page. On the right of
source lines that reference intrinsic functions, the letters ’IFN’ appear with the line
numbers of the location where the function’s arguments are defined. Information
included in the embedded references lets you know if an identifier is undefined or
defined more than once (UND or DUP will be printed); if an item is implicitly defined
(IMP), such as special registers or figurative constants; and if a program name is
external (EXT).
If you use XREF and NOSOURCE, you’ll get only the sorted cross-reference listing.
XREF(SHORT) will print only the explicitly referenced variables in the cross-reference
listing. XREF(SHORT) applies to DBCS data names and procedure-names as well as
EBCDIC names.
Observe:
RELATED TASKS
“Getting listings” on page 319
RELATED REFERENCES
COBOL compiler options (Language Environment Debugging Guide and Run-Time
Messages)
YEARWINDOW
Abbreviation is: YW
Use the YEARWINDOW option to specify the first year of the 100-year window (the
century window) to be applied to windowed date field processing by the COBOL
compiler.
base-year represents the first year of the 100-year window, and must be specified as
one of the following:
v An unsigned decimal number between 1900 and 1999.
This specifies the starting year of a fixed window. For example,
YEARWINDOW(1930) indicates a century window of 1930-2029.
v A negative integer from -1 through -99.
This indicates a sliding window, where the first year of the window is calculated
from the current run-time date. The number is subtracted from the current year
to give the starting year of the century window. For example, YEARWINDOW(-80)
indicates that the first year of the century window is 80 years before the current
year at the time the program is run.
Notes:
1. The YEARWINDOW option has no effect unless the DATEPROC option is also in effect.
2. At run time, two conditions must be true:
v The century window must have its beginning year in the 1900s.
v The current year must lie within the century window for the compilation
unit.
For example, if the current year is 2001, the DATEPROC option is in effect, and
you use the YEARWINDOW(1900) option, the program will terminate with an error
message.
RELATED REFERENCES
“Conflicting compiler options” on page 259
With ZWB, the compiler removes the sign from a signed external decimal (DISPLAY)
field when comparing this field to an alphanumeric elementary field during
execution.
If the external decimal item is a scaled item (contains the symbol P in its PICTURE
character string), its use in comparisons is not affected by ZWB. Such items always
have their sign removed before the comparison is made to the alphanumeric field.
ZWB affects how the program runs; the same COBOL source program can give
different results, depending on the option setting.
Use NOZWB if you want to test input numeric fields for SPACES.
Compiler-directing statements
Several statements help you to direct the compilation of your program.
BASIS statement
This extended source program library statement provides a complete
| COBOL program as the source for a compilation. For rules of formation
| and processing, see the description under text-name of the COPY statement.
*CONTROL (*CBL) statement
This compiler-directing statement selectively suppresses or allows output
to be produced. The names *CONTROL and *CBL are synonymous.
COPY statement
For example:
COPY INVOICES1Q
COPY “Company-#Employees” IN Personellib
| In the IN/OF phrase, library-name is the ddname that identifies the
| partitioned data set to be copied from. Use a DD statement such as in the
| following example to define library-name:
| //COPYLIB DD DSNAME=ABC.COB,VOLUME=SER=111111,
| // DISP=SHR,UNIT=3380
| To specify more than one copy library, use either JCL or a combination of
| JCL and the IN/OF phrase. Using just JCL, concatenate data sets on your DD
| statement for SYSLIB. Alternatively, define multiple DD statements and
| include the IN/OF phrase on your COPY statements.
The maximum block size for the copy library depends on the device on
which your data set resides.
| When you compile with the cob2 command, COPY text is included from the
| HFS. Text-name, library-name, and literal are processed as follows:
| v User-defined words are folded to uppercase. Literals are not. Because
| OS/390 UNIX is case sensitive, if your file name is lowercase or mixed
| case, you must specify it as a literal.
| v When text-name is a literal and library-name is omitted, text-name is used
| directly: as a file name, a relative path name, or an absolute path name
| (if the first character is /). For example:
| COPY “MyInc”
| COPY “x/MyInc”
| COPY “/u/user1/MyInc”
| v When text-name is a user-defined word and an environment variable of
| that name is defined, the value of the environment variable is used as
| the name of the file containing the copy text.
| If an environment variable of that name is not defined, the copy text is
| searched for as the following names, in the order given:
| 1. text-name.cpy
| 2. text-name.CPY
| 3. text-name.cbl
| 4. text-name.CBL
| 5. text-name.cob
| 6. text-name.COB
| 7. text-name
| v When library-name is a literal, it is treated as the actual path, relative or
| absolute, from which to copy file text-name.
RELATED TASKS
“Changing the header of a source listing” on page 6
“Eliminating repetitive coding” on page 551
“Using compiler-directing statements” on page 245
“Specifying compiler options under OS/390” on page 223
“Specifying compiler options under OS/390 UNIX” on page 236
“Setting environment variables under OS/390 UNIX” on page 235
“Specifying compiler options under CMS” on page 246
RELATED REFERENCES
“cob2” on page 239
IBM COBOL Language Reference
If the problem with your program is not easily detected and you do not have a
debugger available, you might need to analyze a storage dump of your program.
Besides using the features inherent in COBOL, you can also use the Debug Tool,
which is available in the Full Function offering of this compiler.
RELATED REFERENCE
Debug Tool User’s Guide and Reference
Formatting and analyzing system dumps on OS/390 (Language Environment
Debugging Guide and Run-Time Messages)
Debugging example COBOL programs (Language Environment Debugging Guide and
Run-Time Messages)
RELATED REFERENCES
Source language debugging (IBM COBOL Language Reference)
If you have used explicit scope terminators to end statements in your program, the
logic of your program is more apparent and therefore easier to trace.
To determine whether a particular routine started and finished, you might insert
code like this into your program:
DISPLAY “ENTER CHECK PROCEDURE”
.
. (checking procedure routine)
.
DISPLAY “FINISHED CHECK PROCEDURE”
After you are sure that the routine works correctly, disable the DISPLAY statements
one of two ways:
v Put an asterisk in column 7 of each DISPLAY statement line to convert it to a
comment line.
v Put a D in column 7 of each DISPLAY statement to convert it to a comment line.
When you want to reactivate these statements, include a WITH DEBUGGING MODE
clause in the ENVIRONMENT DIVISION; the D in column 7 is ignored and the
DISPLAY statements are implemented.
Before you put the program into production, delete or disable the debugging aids
you used and recompile the program. The program will run more efficiently and
use less storage.
RELATED REFERENCES
DISPLAY statement (IBM COBOL Language Reference)
To use file status keys in debugging, include a test after each input-output
statement to check for a nonzero value in the status key. If the value is nonzero (as
reported in an error message), you should look at the coding of the input-output
procedures in the program. You can also include procedures to correct the error
based on the value of the status key.
Code each USE AFTER STANDARD ERROR statement in a section immediately after the
DECLARATIVE SECTION keyword of the PROCEDURE DIVISION.
RELATED REFERENCES
Status key values and meanings (IBM COBOL Language Reference)
Status key (IBM COBOL Language Reference)
Validating data
If you suspect that your program is trying to perform arithmetic on nonnumeric
data or is somehow receiving the wrong type of data on an input record, use the
class test to validate the type of data. The class test checks whether data is
alphabetic, alphabetic-lower, alphabetic-upper, DBCS, KANJI, or numeric.
RELATED REFERENCES
Class condition (IBM COBOL Language Reference)
If the problem you are having happens intermittently and not always with the
same data, the problem could be that a switch is not initialized but generally is set
to the right value (0 or 1) by accident. By including a SET statement to ensure that
the switch is initialized, you can either determine that the uninitialized switch is
the problem or remove that as a possible cause.
RELATED REFERENCES
INITIALIZE statement (IBM COBOL Language Reference)
SET statement (IBM COBOL Language Reference)
For example, to check how many times a procedure is run, you could include a
debugging procedure in the USE FOR DEBUGGING declarative and use a counter to
keep track of the number of times control passes to that procedure. You can use
the counter technique to check items such as these:
v How many times a PERFORM runs and thus whether a particular routine is being
used and whether the control structure is correct
v How many times a loop routine runs and thus whether the loop is executing
and whether the number for the loop is accurate
You can have debugging lines or debugging statements or both in your program.
Debugging lines
Debugging lines are statements that are identified by a D in column 7. To make
debugging lines in your program active, include the WITH DEBUGGING MODE clause
on the SOURCE-COMPUTER line in the ENVIRONMENT DIVISION. Otherwise debugging
lines are treated as comments.
Debugging statements
Debugging statements are the statements coded in the DECLARATIVES SECTION of the
PROCEDURE DIVISION. Code each USE FOR DEBUGGING declarative in a separate
section. Code the debugging statements as follows:
v Only in a DECLARATIVES SECTION.
v Following the header USE FOR DEBUGGING.
v Only in the outermost program; they are not valid in nested programs.
Debugging statements are also never triggered by procedures contained in
nested programs.
To use debugging statements in your program, you must include both the WITH
DEBUGGING MODE clause and the DEBUG run-time option.
The WITH DEBUGGING MODE clause and the TEST compiler option (with any suboption
value other than NONE) are mutually exclusive. If both are present, the WITH
DEBUGGING MODE clause takes precedence.
RELATED REFERENCES
Debugging line (IBM COBOL Language Reference)
Coding debugging sections (IBM COBOL Language Reference)
DEBUGGING declarative (IBM COBOL Language Reference)
The number at the end of the message, 22, is the value accumulated in the
data-item Total; it shows the number of times Some-Routine has run. The
statements in the debugging declarative are performed before the named
procedure runs.
You can also use the DISPLAY statement to trace program execution and show the
flow through the program. You do this by dropping Total from the DISPLAY
statement and changing the USE FOR DEBUGGING declarative in the DECLARATIVES
SECTION to:
USE FOR DEBUGGING ON ALL PROCEDURES.
There is also a compiler option (TEST) that you need to use to prepare your
program for debugging.
RELATED TASKS
“Selecting the level of error to be diagnosed” on page 316
“Finding coding errors”
“Finding line sequence problems” on page 315
“Checking for valid ranges” on page 315
“Finding program entity definitions and references” on page 317
“Listing data items” on page 318
“Getting listings” on page 319
“Preparing to use the debugger” on page 343
RELATED REFERENCES
“COMPILE” on page 265
“SEQUENCE” on page 291
“SSRANGE” on page 294
“FLAG” on page 274
“XREF” on page 302
“MAP” on page 281
“VBREF” on page 301
“LIST” on page 281
“TEST” on page 295
If you are compiling in the TSO foreground, you can send the messages to your
screen by defining your data set as the SYSTERM data set and using the TERM option
when you compile your program.
The following compiler options are suppressed when you use NOCOMPILE without
parameters: DECK, OFFSET, LIST, OBJECT, OPTIMIZE, SSRANGE, and TEST.
Compiling conditionally
When you use NOCOMPILE(x), where x is one of the severity levels for errors, your
program is compiled if all the errors are of a lower severity than the x level. The
severity levels (from highest to lowest) that you can use are S (severe), E (error),
and W (warning).
RELATED REFERENCES
“COMPILE” on page 265
When you use SEQUENCE, the compiler checks the source statement numbers you
have supplied to see whether they are in ascending sequence. Two asterisks are
placed beside statement numbers that are out of sequence. Also, the total number
of these statements is printed as the first line of the diagnostics after the source
listing.
RELATED REFERENCES
“SEQUENCE” on page 291
If all subscripts, indices, or reference modifiers are literals in a given data reference
and they result in a reference outside the data item, the error is diagnosed at
compile time, regardless of the setting of the SSRANGE compiler option.
Specify as the first parameter the lowest severity level of the syntax-error messages
to be issued. Optionally, specify the second parameter as the lowest level of the
syntax-error messages to be embedded in the source listing. This severity level
must be the same or higher than the level for the first parameter. If you specify
both parameters, you must also specify the SOURCE compiler option.
Severity level What you get when you specify the corresponding level
U (unrecoverable) U messages only
S (severe) All S and U messages
E (error) All E, S, and U messages
W (warning) All W, E, S, and U messages
I (informational) All messages
When you specify the second parameter, each syntax-error message (except a
U-level message) is embedded in the source listing at the point where the compiler
had enough information to detect the error. All embedded messages (except those
issued by the library compiler phase) directly follow the statement to which they
refer. The number of the statement containing the error is also included with the
message. Embedded messages are repeated with the rest of the diagnostic
messages at the end of the source listing.
When you specify the NOSOURCE compiler option, the syntax-error messages are
included only at the end of the listing. Messages for unrecoverable errors are not
embedded in the source listing, because an error of this severity terminates the
compilation.
RELATED CONCEPTS
“Severity codes for compiler error messages” on page 232
RELATED TASKS
“Generating a list of compiler error messages” on page 230
RELATED REFERENCES
“FLAG” on page 274
“Messages and listings for compiler-detected errors” on page 231
To include only the explicitly referenced variables, use the XREF(SHORT) option.
If your program contains DBCS user-defined words, these user-defined words are
listed before the alphabetic list of EBCDIC user-defined words.
In the CMS environment, the DBCS user-defined words are listed in physical order
according to their appearance in the source program.
Group names in a MOVE CORRESPONDING statement are listed in the XREF listing. The
cross-reference listing includes the group names and all the elementary names
involved in the move.
RELATED TASKS
“Getting listings” on page 319
RELATED REFERENCES
“XREF” on page 302
In addition, when you use the MAP option, an embedded MAP summary (which
contains condensed data MAP information) is generated to the right of the COBOL
source data declaration. When both XREF data and an embedded MAP summary are
on the same line, the embedded summary is printed first.
You can select or inhibit parts of the MAP listing and embedded MAP summary by
using *CONTROL MAP or *CONTROL NOMAP statements (*CBL MAP or *CBL NOMAP
statements) throughout the source. For example:
*CONTROL NOMAP *CBL NOMAP
01 A 01 A
02 B 02 B
*CONTROL MAP *CBL MAP
RELATED TASKS
“Getting listings” on page 319
RELATED REFERENCES
“MAP” on page 281
Attention: The listings produced by the compiler are not a programming interface
and are subject to change.
1. To eliminate messages, turn off the options (such as FLAG) that govern the level of compile diagnostic
information. To use your line numbers in the compiled program, use the NUMBER compiler option. The compiler
checks the sequence of your source statement line numbers in columns 1 through 6 as the statements are read in.
When it finds a line number out of sequence, the compiler assigns to it a number with a value one higher than
the line number of the preceding statement. The new value is flagged with two asterisks. A diagnostic message
indicating an out-of-sequence error is included in the compilation listing.
2. The context of the procedure reference is indicated by the characters preceding the line number.
3. You can control the selective listing of generated object code by placing *CONTROL LIST and *CONTROL NOLIST
statements (*CBL LIST and *CBL NOLIST) in your source. Note that the *CONTROL statement is different from the
PROCESS (or CBL) statement.
The output is generated if:
v You specify the COMPILE option (or the NOCOMPILE(x) option is in effect and an error level x or higher does not
occur).
v You do not specify the OFFSET option. OFFSET and LIST are mutually exclusive options with OFFSET taking
precedence.
RELATED TASKS
“Generating a list of compiler error messages” on page 230
“Reading LIST output” on page 328
Determining the source of error (Language Environment Debugging Guide and
Run-Time Messages)
RELATED REFERENCES
“Messages and listings for compiler-detected errors” on page 231
(4) Deliberate option conflicts were forced by specifying the OPTIMIZE option
on the compiler input parameter list. OPTIMIZE and the TEST(ALL) option
specified on the CBL statement are mutually exclusive. As a result, the
OPTIMIZE option is ignored.
(5) Status of options at the start of this compilation.
(6) Customized page header resulting from the COBOL program TITLE
statement.
(7) Program diagnostics. The first message refers you to any library phase
diagnostics. Diagnostics for the library phase are presented at the
beginning of the listing.
(8) Count of diagnostic messages in this program, grouped by severity level.
(9) Program statistics for the program IGYTCARA.
(10) Program statistics for the compilation unit. When you perform a batch
compilation, the return code is the highest message severity level for the
entire compilation.
(1) Customized page header resulting from the COBOL program TITLE
statement
(2) Scale line labels Area A, Area B, and source code column numbers
(3) Source code line number assigned by the compiler
(4) Program (PL) and statement (SL) nesting level
(5) Columns 1 through 6 of program (the sequence number area)
RELATED REFERENCES
“Terms used in MAP output” on page 326
“Symbols used in LIST and MAP output” on page 326
1. n is the size in bytes for fixed-length groups and the maximum size in bytes for variable-length groups.
2. If the SYNCHRONIZED clause appears, these fields are used.
Symbol Definition
APBdisp=n1 ALL subscript parameter block displacement
AVN=n1 Variable name cell for ALTER statement
RELATED TASKS
Interpret a particular instruction (System/390 Reference Summary)
RELATED REFERENCE
The stack frame section (Language Environment Debugging Guide and Run-Time
Messages)
RELATED REFERENCES
“Signature information bytes: compiler options”
“Signature information bytes: DATA DIVISION” on page 333
“Signature information bytes: ENVIRONMENT DIVISION” on page 333
“Signature information bytes: PROCEDURE DIVISION verbs” on page 333
“Signature information bytes: more PROCEDURE DIVISION items” on page 335
RELATED REFERENCES
“LIST” on page 281
Check return code: A return code greater than 4 from the compiler could mean
that some of the verbs shown as being in the program in information bytes might
have been discarded because of an error.
RELATED REFERENCES
“LIST” on page 281
(1) Source line number and COBOL verb, paragraph name, or section name
In line 000436, SET is the COBOL verb. An asterisk (*) before a name
indicates that the name is a paragraph name or a section name.
(2) Relative location of the object code instruction in the module, in
hexadecimal notation
(3) Object code instruction, in hexadecimal notation
The first two or four hexadecimal digits are the instruction, and the
remaining digits are the instruction operands. Some instructions have two
operands.
(4) Compiler-generated names (GN) for code sequences
(5) Object code instruction in a form that closely resembles assembler
language
(6) Comments about the object code instruction:
v One or two operands participating in the machine instructions are
displayed on the right. An asterisk immediately follows the data names
that are defined in more than one structure (in that way made unique by
qualification in the source program).
v The relative location of any generated label appearing as an operand is
displayed in parentheses.
RELATED REFERENCES
“Symbols used in LIST and MAP output” on page 326
DATA VALIDATION AND UPDATE PROGRAM IGYTCARA Date 03/30/2000 Time 12:26:53 Page 139
*** DSA MEMORY MAP ***
(1) (2)
DSALOC
(1) Hexadecimal offset of the dynamic save area (DSA) field from the start of
the DSA
(2) Explanation of the contents of the DSA field
(1) Line number where the program name was defined. If the program is
external, the word EXTERNAL is displayed instead of a definition line
number.
(2) Program name.
(3) Line numbers where the program is referenced.
(1) Line number of the definition of the data name or procedure name in the
program
(2) Special definition symbols:
UND The user name is undefined.
DATA VALIDATION AND UPDATE PROGRAM IGYTCARA Date 03/30/2000 Time 12:26:53 Page 54
. . .
(1) (2) (3)
LINE # HEXLOC VERB LINE # HEXLOC VERB LINE # HEXLOC VERB
000880 0026F0 DISPLAY 000881 002702 PERFORM 000933 002702 OPEN
000934 002722 IF 000935 00272C DISPLAY 000936 002736 PERFORM
001389 002736 DISPLAY 001390 002740 DISPLAY 001391 00274A DISPLAY
001392 002754 DISPLAY 001393 00275E DISPLAY 001394 002768 DISPLAY
001395 002772 DISPLAY 000937 00277C PERFORM 001434 00277C DISPLAY
001435 002786 STOP 000939 0027A2 MOVE 000940 0027AC WRITE
000941 0027D6 IF 000942 0027E0 DISPLAY 000943 0027EA PERFORM
001389 0027EA DISPLAY 001390 0027F4 DISPLAY 001391 0027FE DISPLAY
001392 002808 DISPLAY 001393 002812 DISPLAY 001394 00281C DISPLAY
001395 002826 DISPLAY 000944 002830 DISPLAY 000945 00283A PERFORM
001403 00283A DISPLAY 001404 002844 DISPLAY 001405 00284E DISPLAY
001406 002858 DISPLAY 001407 002862 CALL 000947 002888 CLOSE
(1) Line number. Your line numbers or compiler-generated line numbers are
listed.
(2) Offset, from the start of the program, of the code generated for this verb
(in hexadecimal notation).
The verbs are listed in the order in which they occur and once for each
time they are used.
(3) Verb used.
RELATED REFERENCES
“OFFSET” on page 285
The Debug Tool debugger is provided with the Full Function feature of the
COBOL for OS/390 & VM compiler. To use Debug Tool to step through a run of
your program, specify the TEST compiler option. For remote debugging, the
Distributed Debugger provides the client graphical user interface to the debug
| information provided by the Debug Tool engine running on OS/390 or OS/390
| UNIX.
| You can specify the TEST suboption SEPARATE to have the symbolic information
| tables for the Debug Tool generated in a data set separate from your object
| module. And you can enable your COBOL program for debugging using overlay
| hooks (production debugging), rather than compiled-in hooks, which have some
| performance degradation even when the run-time TEST option is off.
RELATED TASKS
Debug Tool User’s Guide and Reference
The CICS translator converts the EXEC CICS commands in your source program to
COBOL code. The translator replaces each EXEC CICS command with one or more
COBOL statements, one of which is a CALL statement.
After compiling and link-editing your program, you need to do some other steps
such as updating CICS tables before you can run the COBOL program under CICS.
However, these CICS topics are beyond the focus of this COBOL information.
RELATED TASKS
“Coding COBOL programs to run under CICS”
“Preparing COBOL programs to run under CICS” on page 350
“Handling errors by using CICS HANDLE” on page 352
Observe these guidelines when coding your COBOL programs to run under CICS:
v Do not use EXEC, CICS, or END-EXEC for variable names.
v Do not use the FILE-CONTROL entry in the ENVIRONMENT DIVISION, unless the
FILE-CONTROL entry is being used for a SORT statement.
v Do not use the FILE SECTION of the DATA DIVISION, unless the FILE SECTION is
being used for a SORT statement.
v Do not use user-specified parameters to the main program.
v Do not use USE declaratives (except USE FOR DEBUGGING).
v Do not use these COBOL language statements:
| ACCEPT format 1: data transfer (you can use format-2 ACCEPT to retrieve the
| system date and time)
CLOSE
DELETE
| DISPLAY UPON SYSPUNCH
| DISPLAY UPON CONSOLE
MERGE
OPEN
READ
RERUN
REWRITE
START
STOP literal
WRITE
| You can use these format-2 ACCEPT statements in the CICS environment to get the
| system date:
| v ACCEPT identifier-2 FROM DATE
| v ACCEPT identifier-2 FROM DATE YYYYMMDD
| v ACCEPT identifier-2 FROM DAY
| v ACCEPT identifier-2 FROM DAY YYYYDDD
| v ACCEPT identifier-2 FROM DAY-OF-WEEK
| You can use this format-2 ACCEPT statement in the CICS environment to get the
| system time:
| v ACCEPT identifier-2 FROM TIME
The recommended way of retrieving system date and time information is using the
ACCEPT statement, because it works in all environments (CICS and non-CICS).
You can use CALL identifier with the NODYNAM compiler option to dynamically call a
program. Called programs can contain any function supported by CICS for the
language. You must define dynamically called programs in the CICS program
processing table (PPT), if you are not using CICS autoinstall.
The ON OVERFLOW phrase and ON EXCEPTION phrase of the CALL statement are
supported under CICS unless the program has been compiled with the CMPR2
compiler option. In that case, no conditions under CICS will cause the statement
specified by the ON OVERFLOW to be performed.
Language Non-Language
Calls between COBOL and Environment-conforming Environment-conforming
assembler programs assembler program assembler program
From a COBOL for OS/390 Yes Yes
& VM program to the
assembler program?
From the assembler program Yes No
to a COBOL for OS/390 &
VM program?
To ensure that a meaningful return code is given at termination, set the job step
return code before terminating your program. Keep the COBOL convention of
storing its RETURN-CODE special register into register 15 by saving the response code
from the last call to the external CICS interface and moving it to special register
RETURN-CODE before terminating.
RELATED TASKS
Writing ILC applications (Language Environment Writing ILC Applications)
RELATED REFERENCES
CICS/ESA V4R1 External CICS Interface, SC33-1390
When you use the COBOL3 translator option, it causes the following line to be
inserted:
CBL RENT,NODYNAM,LIB
You can suppress the insertion of a CBL statement by using the CICS translator
option NOCBLCARD.
CICS features the translator option ANSI85, which supports these language features
(introduced by the COBOL 85 Standard):
v Blank lines intervening in literals
v Sequence numbers containing any character
v Lowercase characters supported in all COBOL words
v REPLACE statement
v Batch compilation
v Nested programs
v Reference modification
v GLOBAL variables
v Interchangeability of comma, semicolon, and space
v Symbolic character definition
In addition, you might want to use the following recommended options under
certain circumstances:
For example, if you have a data item defined as PIC S9(8) BINARY that might
receive a value greater than eight digits, use TRUNC(BIN) or change the PICTURE
clause.
You might also want to avoid using an option that has no effect:
ADV
FASTSRT
OUTDD
The input data set for the compiler is the data set that you received as result of
translation, which is SYSPUNCH by default.
If you intend to use the SORT statement under CICS (COBOL supports an interface
for the SORT statement under CICS), you must change the CICS reserved-word
table before using it. You must remove the words italicized above from the list of
words marked as restricted, because they are required for the SORT function.
RELATED TASKS
“Preparing COBOL programs to run under CICS” on page 350
Run with CBLPSHPOP(ON) if any of your called COBOL subprograms uses one or
more of the following CICS commands:
CICS HANDLE CONDITION
CICS HANDLE AID
CICS HANDLE ABEND
CICS IGNORE CONDITION
CICS PUSH HANDLE
CICS POP HANDLE
If you use the CICS HANDLE CONDITION or HANDLE AID commands, the LABEL
specified for the CICS HANDLE command must be in the same PROCEDURE DIVISION
as the CICS command that causes branching to the CICS HANDLE label. You cannot
use the CICS HANDLE commands with the LABEL option to handle conditions, aids,
and abends that were caused by another program invoked using the COBOL CALL
statement. Attempts to perform cross-program branching by using the CICS HANDLE
command with the LABEL option result in a transaction abend.
If a condition, aid, or abend occurs in a nested program, the LABEL for the
condition, aid, or abend must be in the same nested program; otherwise
unpredictable results will occur.
RELATED TASKS
“Coding SQL statements”
“Compiling with the SQL option” on page 356
Coding SQL statements in a COBOL application (IBM DB2 Application Programming
and SQL Guide)
RELATED REFERENCES
IBM DB2 SQL Reference
| The name in an SQL INCLUDE statement follows the same rules as those for COPY
| text-name and is processed identically to a COPY text-name without a REPLACING
| clause.
| The library search order for SQL INCLUDE statements is the same SYSLIB
| concatenation as the compiler uses to resolve COBOL COPY statements that do not
| specify a library name.
The exception on OS/390 occurs when a program runs under DSN from one of the
alternate entry points of the TSO batch mode module IKJEFT01 (IKJEFT1A or
IKJEFT1B). In this case, the return code is passed in register 15.
Because DB2 usually does not pass the return code in register 15, the COBOL
RETURN-CODE special register might contain a value that is not valid. Your COBOL
program should set the RETURN-CODE special register to a meaningful value before
returning to its caller, to keep the COBOL convention of storing its RETURN-CODE
special register into register 15.
RELATED CONCEPTS
“Formats for numeric data” on page 36
| You can specify the SQL option in any of the compiler option sources: compiler
| invocation, PROCESS or CBL statements, or installation default. You cannot specify
| DB2 suboptions when the SQL option is the COBOL installation default, but you
| can specify default DB2 suboptions by customizing the DB2 product installation
| defaults.
| The DB2 suboption string that you provide on the SQL compiler option is made
| available to the DB2 coprocessor. Only the DB2 coprocessor views the contents of
| the string.
| When you use the DB2 coprocessor, you must compile with these options:
Compiling in batch
| When you use the SQL option to compile a source file that contains a sequence of
| COBOL programs (a batch compile sequence), the option must be in effect for the
| first program of the batch sequence. If the SQL option is specified on CBL or PROCESS
| cards, the CBL or PROCESS cards must precede the first program in the batch
| compile sequence.
| The DB2 suboptions that you include in the suboption string are cumulative. The
| compiler concatenates these suboptions from multiple sources in the order that
| they are specified. For example, suppose that your source file has the following
| code:
| //STEP1 EXEC IGYWC, . . .
| // PARM.COBOL='SQL(“DATABASE xxxx”)'
| //COBOL.SYSIN DD *
| CBL SQL(“PACKAGE USER xxxx”)
| CBL SQL(“USING xxxx”)
| IDENTIFICATION DIVISION.
| PROGRAM-ID. DRIVER1.
| During compilation, the compiler passes the following suboption string to the DB2
| coprocessor:
| “DATABASE xxxx PACKAGE USER xxxx USING xxxx”
| The concatenated strings are delimited with single spaces. When the compiler finds
| multiple instances of the same DB2 suboption, the last specification of the
| suboption in the concatenated string will be in effect. The compiler limits the
| length of the concatenated DB2 suboption string to 4K bytes.
RELATED CONCEPTS
“DB2 coprocessor” on page 358
RELATED REFERENCES
“SQL” on page 293
IBM DB2 Command Reference
| Compiling with the DB2 coprocessor generates a DB2 database request module
| (DBRM) along with the usual COBOL compiler outputs such as object module and
| listing. The DBRM writes to the data set that you specified on the DBRMLIBB DD
| statement in the JCL for the COBOL compile step. As input to the DB2 bind
| process, the DBRM data set contains information about the SQL statements and
| host variables in the program.
| The COBOL compiler listing includes the error diagnostics (such as syntax errors
| in the SQL statements) that the DB2 coprocessor generates.
| Certain restrictions on the use of COBOL language that apply when you use the
| precompile step do not apply when you use the DB2 coprocessor:
| v You can use SQL statements in any nested program. (With the precompiler, SQL
| statements are restricted to the outermost program.)
| v You can use SQL statements in copy books.
| v REPLACE statements work on SQL statements.
RELATED TASKS
“Compiling with the SQL option” on page 356
In COBOL, IMS message processing programs (MPPs) do not use non-IMS input or
output statements such as READ, WRITE, REWRITE, OPEN, and CLOSE.
With COBOL for OS/390 & VM you can invoke IMS facilities using the following
interfaces:
v CBLTDLI call
v Language Environment callable service CEETDLI
You code calls to CEETDLI the same way as calls to CBLTDLI. CEETDLI behaves
essentially the same way as CBLTDLI.
You must use the RENT compiler option to compile a program that is to be used
only preloaded or in both a preloaded and a nonpreloaded way. When you preload
a load module that contains COBOL programs, all of the COBOL programs in that
load module must be compiled with the RENT option.
In an application with any mixture of COBOL for OS/390 & VM, COBOL for MVS
& VM, VS COBOL II, and OS/VS COBOL programs, the following compiler
options are recommended:
You can place programs compiled with the RENT option in the OS/390 link pack
area. There they can be shared among the IMS dependent regions.
To run above the 16-MB line, your application program must be compiled with
either of the following compiler options, depending on your IMS environment:
With IMS, the data for IMS application programs can reside above the 16-MB line,
and you can use DATA(31) RENT, or RMODE(ANY) NORENT, for programs that use IMS
services.
RELATED REFERENCES
“DATA” on page 266
“RENT” on page 289
Appendix M. IMS considerations (COBOL for OS/390 & VM Compiler and Run-Time
Migration Guide)
RELATED REFERENCE
“RENT” on page 289
| The program must be in the current directory or in your search path. When
| running your UNIX programs, you can specify run-time options only by setting
| the environment variable _CEE_RUNOPTS before starting your program.
| You can run your MVS executable program that resides in a cataloged MVS data
| set from a shell by using the tso utility. For example:
| tso “call 'my.loadlib(myprog)'”
| To call your OS/390 UNIX COBOL program that resides in an HFS file from the
| TSO/E ready prompt, use the BPXBATCH utility or a spawn() syscall in a REXX
| exec.
| To call your OS/390 UNIX COBOL program that resides in an HFS file with the
| JCL EXEC statement, use the BPXBATCH utility.
RELATED TASKS
“Setting and accessing environment variables”
“Calling UNIX/POSIX APIs” on page 364
“Accessing main program parameters” on page 365
Running POSIX-enabled programs using an OS/390 UNIX shell (Language
Environment Programming Guide)
Running POSIX-enabled programs outside the OS/390 UNIX shells (Language
Environment Programming Guide)
“Defining and allocating QSAM files” on page 121
“Defining and allocating line-sequential files” on page 165
“Allocating VSAM files” on page 156
“Displaying values on a screen or in a file (DISPLAY)” on page 29
RELATED REFERENCES
“TEST” on page 295
BPXBATCH utility (OS/390 UNIX System Services User’s Guide)
Language Environment Programming Reference
| If you are running your program with BPXBATCH, you can set environment
| variables by using an STDENV DD statement.
| Call POSIX functions setenv() and putenv() to set environment variables from your
| program.
| To access the value of an environment variable from your COBOL program, call
| the getenv() function.
RELATED TASKS
“Running in OS/390 UNIX environments” on page 361
“Calling UNIX/POSIX APIs” on page 364
“Accessing main program parameters” on page 365
“Displaying values on a screen or in a file (DISPLAY)” on page 29
RELATED REFERENCES
Language Environment Programming Reference
OS/390 MVS JCL Reference
| Because these are C functions, you must pass arguments BY VALUE. Pass character
| strings as BY VALUE pointers that point to null-terminated strings.
| CBL pgmname(longmixed)
| Identification division.
| Program-id. “envdemo”.
| Data division.
| Working-storage section.
| 01 P pointer.
| 01 PATH pic x(5) value Z“PATH”.
| 01 var-ptr pointer.
| 01 var-len pic 9(4) binary.
| 01 putenv-arg pic x(14) value Z“MYVAR=ABCDEFG”.
| 01 rc pic 9(9) binary.
| Because these are C functions, you must pass arguments BY VALUE. Pass character
| strings as BY VALUE pointers that point to null-terminated strings. You must use the
| compiler options NODYNAM and PGMNAME(LONGMIXED) when you compile programs
| that call these functions.
Samples
| Sample code is provided with the product for calling some of the POSIX routines.
| The sample source code is in the SIGYSAMP data set.
RELATED TASKS
“Running in OS/390 UNIX environments” on page 361
“Setting and accessing environment variables” on page 362
“Accessing main program parameters”
Language Environment Programming Guide
RELATED REFERENCES
OS/390 C/C++ Run-Time Library Reference
OS/390 UNIX System Services Programming: Assembler Callable Services Reference
RELATED TASKS
“Running in OS/390 UNIX environments” on page 361
“Setting and accessing environment variables” on page 362
“Calling UNIX/POSIX APIs” on page 364
QSAM unblocked files or files with a small block size can slow performance under
CMS. To improve performance, use files with a block size 50 to 100 times larger
than the logical record length.
Also, CMS does not diagnose as errors any conflicts in fixed file attributes when
opening an existing QSAM file for output (not update). These attributes refer to:
v Record format (RECFM)
v Logical record length (LRECL)
v Data set organization (DSORG)
v Attribute indicating that ASCII or EBCDIC translation is requested (OPTCD=Q)
Conflicts in these attributes can occur on an OPEN of an existing QSAM file when
the COBOL program (DCB) and the data set label for the file or the CMS FILEDEF
command specify different values for any of them. However, because CMS does
Certain VM/ESA rules govern the precedence of sources for CMS file attributes
(sources include the DCB for the program, CMS FILEDEF command, and existing
data set label). These rules affect the behavior of the file status code 39.
where
120S Is the CMS message number for SYNAD errors
INPUT Indicates an input operation was tried
OUTPUT Indicates an output operation was tried
nnn Is the associated error code
ddname
Is the ddname of the related file
A CMS SYNAD error also occurs when there is not enough minidisk space
available for a CMS output file. When this SYNAD error occurs on QSAM files
used by COBOL programs, and no invalid key clause, file status key, or user error
declarative was specified in the COBOL program for the output operation tried,
Language Environment issues COBOL run-time message IGZ0002S as follows:
IGZ0002S '120S OUTPUT ERROR 013 ON ddname'
RELATED REFERENCES
Precedence rules for CMS file attributes (VM/ESA CMS Application Development
Guide)
Under CMS, you must specify the CMS option when you use the ISPF command
ISPEXEC SELECT PGM to invoke a COBOL program in order to pass user arguments
or run-time options specified and have them take effect. Under OS/390, you
cannot pass any user arguments or run-time options when you use the ISPEXEC
SELECT PGM command to invoke a COBOL program.
You can run COBOL programs concurrently in both screens of the ISPF split-screen
mode.
One of the sample programs that is shipped with COBOL for OS/390 & VM,
IGYTCARB, runs under ISPF.
RELATED CONCEPTS
“IGYTCARB: interactive program” on page 592
RELATED TASKS
“Defining a class” on page 378
“Defining a class method” on page 381
Once classes are determined, the next step is to determine the methods the classes
need to do their work. The Orders class must provide the following services:
v Add items to the order
v Delete items from the order
v Compute the cost of the order
v Provide the order number to the service representative
v Write the final order for later processing
The following methods for the Orders class meet the above need:
AddItem
Add an item to the order
DeleteItem
Delete an item from the order
ComputeCost
Compute the cost of the order
getOrderNumber
Provide the order number
WriteOrder
Write the final order
As you design your class and its methods, you discover the need for the class to
keep some instance data. Typically, an orders class needs the following instance
data:
v Order number
The words in parentheses are instance data and the words after the number and
colon are methods.
The class structure of this object-oriented system is a tree structure. This structure
shows how classes are related to each other and is known as the inheritance
hierarchy. Orders and UserInterface are basic classes, so they inherit directly from
the System Object Model (SOM) base class, SOMObject.
All classes in COBOL inherit directly or indirectly from SOMObject. When multiple
inheritance is used, the class structure might not be a tree; it could be a graph.
However, the SOMObject class will always be at the root of the tree or graph.
The complete class structure for the mail-order catalog system is shown below:
A number and colon with nothing after them represent a method inherited from a
superclass.
RELATED TASKS
“Defining a class” on page 378
“Defining a class method” on page 381
“Defining a subclass” on page 393
“Defining a metaclass” on page 405
RELATED TASKS
“Defining a subclass” on page 393
“Defining a metaclass” on page 405
“Changing the definition of a class or subclass” on page 407
“Describing the computing environment” on page 7
You must specify, in the REPOSITORY paragraph, any class name that you explicitly
reference in your class definition. For example:
v SOM base classes.
In the example above, CLASS SOMObject IS ’SOMObject’ indicates that what you
are calling SOMObject in your COBOL program is also called SOMObject in the
SOM interface repository. All SOM names are mixed case, so SOMObject spelled
in mixed case is required to properly handle SOM case sensitivity.
v The classes from which your class is inheriting.
v The metaclass to which your class belongs.
v Any class referenced in methods introduced by the class.
You can optionally include the name of the class that you are defining. If you do
not include the name of your class, it is treated as all uppercase regardless of how
you typed it in the CLASS-ID paragraph. In the above example, Orders is stored in
the SOM interface repository in mixed case.
The class definition (except the method definitions) for the UserInterface class:
IDENTIFICATION DIVISION.
*
* UserInterface is the name of the class
* UserInterface inherits from SOMObject (SOM base class)
*
CLASS-ID. UserInterface INHERITS SOMObject.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
*
* SOMObject is known as SOMObject in SOM repository
CLASS SOMObject IS 'SOMObject'
*
* UserInterface is known as UserInterface in SOM repository
CLASS UserInterface IS 'UserInterface'.
DATA DIVISION.
WORKING-STORAGE SECTION.
*
* Instance data for UserInterface class
*
01 uif-action PIC X(10).
88 uif-add VALUE 'AddItem'.
88 uif-delete VALUE 'DeleteItem'.
88 uif-quit VALUE 'Quit'.
01 uif-item PIC X(5).
RELATED TASKS
“Defining a subclass method” on page 395
“Defining a metaclass method” on page 406
“Overriding a method”
“Invoking methods” on page 391
“Coding special methods” on page 383
In this example, WriteOrder is the method name. Other methods or programs use
this name to invoke the method.
Overriding a method
Occasionally, a class defines a method whose name exists in a superclass. In this
case, you need to override the superclass method with the OVERRIDE clause on the
METHOD-ID. System Object Model (SOM) provides two methods designed to be
overridden. These SOM methods allow you to customize the creation and disposal
The INPUT-OUTPUT SECTION relates your method files to the external file names
known by the operating system. The syntax for a method INPUT-OUTPUT SECTION is
the same as for a program INPUT-OUTPUT SECTION.
RELATED TASKS
“Describing the computing environment” on page 7
RELATED TASKS
“Describing the data” on page 12
“Sharing data by using the EXTERNAL clause” on page 483
The EXIT METHOD statement returns control to the invoking program or method.
GOBACK has the same effect as EXIT METHOD. If you specify the RETURNING clause
when the method is invoked, the EXIT METHOD or GOBACK returns the value of the
data item to the invoking program or method. You may specify STOP RUN in a
method; however, it terminates the run unit.
You can code any COBOL statements in a method except the following:
v ENTRY
v EXIT PROGRAM
v The following obsolete elements of ANSI COBOL-85:
– ALTER
– GOTO without a specified procedure name
– SEGMENTATION
– USE FOR DEBUGGING
You must properly terminate a method definition with an END METHOD statement.
For example, the following statement marks the end of the WriteOrder method:
End Method WriteOrder.
Attribute methods
Instance variables in COBOL are all private in the sense that the class fully
encapsulates them, and only the methods that are introduced by the class that
defines the instance variables can access them directly. Normally, a well-designed
object-oriented application does not need to access instance variables from outside
the class.
COBOL does not directly support the concept of a public instance variable, as
defined in other object-oriented languages, nor the concept of a class attribute, as
defined by SOM and CORBA. (A CORBA attribute behaves like an instance
variable that has get and set methods to access and modify the value of the
instance variable from outside the class definition.) You can provide this capability
by coding getX and setX methods for any instance variables X for which direct
access from outside the class is required.
For example, the following method passes the order number to any program that
invokes getOrderNumber.
Identification Division.
Method-Id. 'getOrderNumber'.
Data Division.
Linkage Section.
01 ord-num PIC 9(5).
Procedure Division returning ord-num.
Move order-number To ord-num.
Exit Method.
End Method 'getOrderNumber'.
RELATED CONCEPTS
“How logic is divided in the PROCEDURE DIVISION” on page 17
RELATED TASKS
“Processing the data” on page 17
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
* Declare classes used in class definition
REPOSITORY.
CLASS SOMObject IS 'SOMObject'
CLASS Orders IS 'Orders'.
DATA DIVISION.
* Define instance data
WORKING-STORAGE SECTION.
01 order-number PIC 9(5).
01 order-date PIC X(8).
01 order-count PIC 99.
01 order-table.
02 order-entry OCCURS 10 TIMES.
03 order-item PIC X(5).
PROCEDURE DIVISION.
PROCEDURE DIVISION.
MOVE FUNCTION CURRENT-DATE(1:8) TO order-date.
COMPUTE order-number = FUNCTION RANDOM ( 99999 ).
MOVE 0 TO order-count.
INITIALIZE order-table.
EXIT METHOD.
END METHOD 'somInit'.
DATA DIVISION.
* Use LOCAL-STORAGE for items that should be allocated
* and initialized for each invocation of the method
LOCAL-STORAGE SECTION.
77 sub PIC 99.
01 found-flag PIC 9 VALUE 1.
88 found VALUE 0.
LINKAGE SECTION.
01 in-item PIC X(5).
01 add-flag PIC 9.
DATA DIVISION.
* Use LOCAL-STORAGE for items that should be allocated
* and initialized for each invocation of the method
LOCAL-STORAGE SECTION.
77 sub PIC 99.
77 cost PIC 9(5)V99.
LINKAGE SECTION.
01 total-cost PIC 9(7)V99.
DATA DIVISION.
LINKAGE SECTION.
01 ord-num PIC 9(5).
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT order-file ASSIGN OrdrFile.
DATA DIVISION.
FILE SECTION.
* Methods support only EXTERNAL files
FD order-file EXTERNAL.
01 order-record PIC X(80).
* Use LOCAL-STORAGE for items that should be allocated
* and initialized for each invocation of the method
LOCAL-STORAGE SECTION.
01 print-line.
02 print-order-number PIC 9(5).
02 print-order-date PIC X(8).
02 print-order-count PIC 99.
02 print-order-table.
03 print-order-entry OCCURS 10 TIMES.
04 print-order-item PIC X(5).
PROCEDURE DIVISION.
OPEN OUTPUT order-file.
MOVE order-number TO print-order-number.
MOVE order-date TO print-order-date.
MOVE order-table TO print-order-table.
MOVE order-count TO print-order-count.
WRITE order-record FROM print-line.
CLOSE order-file.
EXIT METHOD.
END METHOD WriteOrder.
The class definition for the UserInterface class, including the method definitions:
IDENTIFICATION DIVISION.
CLASS-ID. UserInterface INHERITS SOMObject.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
* Declare classes used in class definition
REPOSITORY.
CLASS SOMObject IS 'SOMObject'
CLASS UserInterface IS 'UserInterface'.
DATA DIVISION.
* Define instance data
WORKING-STORAGE SECTION.
01 uif-action PIC X(10).
88 uif-add VALUE 'AddItem'.
88 uif-delete VALUE 'DeleteItem'.
88 uif-quit VALUE 'Quit'.
01 uif-item PIC X(5).
PROCEDURE DIVISION.
DATA DIVISION.
LINKAGE SECTION.
Get-Item.
DISPLAY 'Enter the item'.
ACCEPT item FROM SYSIN.
MOVE item TO uif-item.
DATA DIVISION.
LINKAGE SECTION.
01 flag PIC 9.
DATA DIVISION.
LOCAL-STORAGE SECTION.
77 formated-cost PIC $Z,ZZZ,ZZ9.99.
LINKAGE SECTION.
01 total-cost PIC 9(7)V99.
01 order-number PIC 9(5).
A method can request services from another method. Therefore a method can be a
client and use the statements discussed in this section.
RELATED TASKS
“Creating and freeing instances of classes” on page 390
“Manipulating object references” on page 391
“Invoking methods” on page 391
“Changing a client program” on page 407
Source-Computer. IBM-370.
Object-Computer. IBM-370.
Repository. Required
Client UserInterface is 'UserInterface'
Client Orders is 'Orders'.
Because the client is using classes, it needs one or more special data items called
object references. Object references are handles to instances of classes that the
program creates. All requests to a method are handled through object references to
instances of the class that defined the method.
In the above example, the phrase USAGE OBJECT REFERENCE indicates that the data
item is used as a handle for an object instance. The example defines three object
references. The first two, orderObj and userObj, are typed object references because
a class name appears after the OBJECT REFERENCE phrase. Therefore, orderObj can
be used to reference only instances of the Orders class or one of its subclasses.
Likewise, userObj can be used to reference only instances of the UserInterface
class or one of its subclasses. The other object reference, univObj, does not have a
class name after its OBJECT REFERENCE phrase. It is a universal object reference and
can reference instances of any class.
Remember: You must define the class name, in this case Orders, in the REPOSITORY
paragraph of the CONFIGURATION SECTION. You must define the object reference, in
this case orderObj, as USAGE OBJECT REFERENCE in the DATA DIVISION.
When you finish with an instance of a class, you should free it. Again, SOM
provides a method, somFree, to free the instance. The following example frees the
instance of orderObj, after which orderObj has an undefined value.
Invoke orderObj 'somFree'.
The first and second IF statements check whether orderObj is a null object
reference (refers to no instance). The third IF statement checks whether orderObj
and univObj refer to the same instance.
This IF statement checks whether the instance on which the method was invoked,
SELF, refers to the same instance as orderObj.
You may need to make an object reference null or to make one object reference
refer to the same instance as another object reference. The SET statement takes care
of these situations:
Set orderObj To Null.
Set univObj To orderObj.
In the second SET statement, univObj is made to refer to the instance to which
orderObj refers. In this syntax, if the receiver (univObj) is a universal object
reference, the sender (orderObj) can be either a universal or typed object reference.
However, if the receiver is a typed object reference, the sender must also be a
typed object reference and typed to the same class or a subclass.
This SET statement makes the receiver (orderObj) refer to the same instance as that
on which the method was invoked, SELF.
Invoking methods
To use the service defined by a method, you must invoke the method with the
INVOKE statement. For example:
Invoke Orders 'somNew' Returning orderObj.
Invoke orderObj 'AddItem' Using item Returning flag.
In the first INVOKE statement, a class name is used to create a new instance whose
handle is returned in the object reference orderObj. You must define the class
name, Orders, in the REPOSITORY paragraph of the CONFIGURATION SECTION. You
must define the object reference, orderObj, as either a universal object reference or
as an object reference of type class Orders.
In the second INVOKE statement, an object reference, orderObj, is used to invoke the
method AddItem. The general syntax of this form of INVOKE is one of the following:
Invoke objref 'literal-name'.
Invoke objref identifier-name.
Conformance between the invoked method and the object reference is checked at
compile time if the following three items are all true:
1. objref is a typed object reference.
2. The literal form of the method name is used in the INVOKE statement.
3. The TYPECHK compile option is specified.
Otherwise, conformance requirements are checked at run time. Run-time checking,
however, is not as thorough as compile-time checking.
INVOKE has the optional scope terminator END-INVOKE. The USING and RETURNING
phrases on the INVOKE work the same as they do on the CALL statement. Also,
INVOKE has the optional ON EXCEPTION and NOT ON EXCEPTION phrases like the CALL
statement.
RELATED REFERENCES
INVOKE statement (IBM COBOL Language Reference)
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
*
* Declare the classes used in the program
REPOSITORY.
CLASS Orders IS 'Orders'
CLASS UserInterface IS 'UserInterface'.
DATA DIVISION.
WORKING-STORAGE SECTION.
*
* Declare the object references used in the program
77 orderObj USAGE OBJECT REFERENCE Orders.
77 userObj USAGE OBJECT REFERENCE UserInterface.
*
* Declare other data items used in the program
77 order-number PIC 9(5).
77 total-cost PIC 9(7)V99.
77 item PIC X(5).
77 action PIC X(10).
77 flag PIC 9.
PROCEDURE DIVISION.
*
* Create an instance of the UserInterface class - userObj
INVOKE UserInterface 'somNew' RETURNING userObj.
*
* Create an instance of the Orders class - orderObj
INVOKE Orders 'somNew' RETURNING orderObj.
*
* Read customer input - action and item
INVOKE userObj 'ReadUserInput' USING item action.
*
* Calculate the total cost of the order
INVOKE orderObj 'ComputeCost' USING total-cost.
*
* Determine the order number
INVOKE orderObj 'getOrderNumber'
RETURNING order-number.
*
* Display information about the order
INVOKE userObj 'WriteUserOutput'
USING total-cost order-number.
*
* Write the order to a file
INVOKE orderObj 'WriteOrder'.
*
* Free the object instances - orderObj and userObj
INVOKE orderObj 'somFree'.
INVOKE userObj 'somFree'.
STOP RUN.
END PROGRAM 'PhoneOrders'.
Defining a subclass
You can make a class (called a subclass or child class) a specialization of another
class (called a superclass or parent class). The subclass is related to its superclass
by an is-a relationship. For example, “Subclass S is a type of superclass P.”
You must properly terminate a subclass definition with an END CLASS statement.
Use the CLASS-ID paragraph to name the subclass and indicate from what
superclass (or superclasses) the subclass inherits.
In the above example, BackOrders is the class name. It inherits all the methods
from Orders. Also, it can access Orders instance data if Orders provides methods to
get and set its instance data.
You must specify the names of the superclasses in the REPOSITORY paragraph in the
CONFIGURATION SECTION of the ENVIRONMENT DIVISION. Optionally, you can specify
BackOrders in the REPOSITORY paragraph.
In COBOL, instance data is private, and so the superclass must provide methods to
allow the subclass to access superclass instance data, if necessary. Using the
methods that the superclass provides, a subclass can retrieve values from, or store
values in, the superclass instance data.
COBOL allows multiple inheritance, inheriting from more than one superclass. If a
conflict in method names occurs between two superclasses due to multiple
inheritance, the conflict is resolved according to the System Object Model (SOM)
rules discussed in the related reference below.
You must properly terminate a subclass method definition with an END METHOD
statement.
RELATED REFERENCES
Multiple inheritance (OS/390 SOMobjects Programmer’s Guide)
This example invokes the method AddItem that is defined in the superclass rather
than the method AddItem that is defined in the subclass.
In the case of multiple inheritance, a subclass may inherit several methods with the
same name from different parents. To specify precisely which method from which
parent is invoked, use the following form of the INVOKE statement:
Invoke Class-A of Super 'AddItem'.
This example invokes the method AddItem that is defined in the superclass Class-A
rather than the method AddItem that is defined in any other superclass or in the
subclass.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
* Declare classes used in class definition
REPOSITORY.
CLASS SOMObject IS 'SOMObject'
CLASS UserInterface IS 'UserInterface'.
DATA DIVISION.
* Define instance data
WORKING-STORAGE SECTION.
01 uif-action PIC X(10).
88 uif-add VALUE 'AddItem'.
88 uif-delete VALUE 'DeleteItem'.
88 uif-quit VALUE 'Quit'.
01 uif-item PIC X(5).
PROCEDURE DIVISION.
DATA DIVISION.
LINKAGE SECTION.
01 request PIC X(6).
DATA DIVISION.
LINKAGE SECTION.
01 action PIC X(10).
01 item PIC X(5).
Get-Item.
DISPLAY 'Enter the item'.
ACCEPT item FROM SYSIN.
MOVE item TO uif-item.
END METHOD ReadUserInput1.
DATA DIVISION.
LINKAGE SECTION.
| 01 order-numb PIC 9(5).
DATA DIVISION.
LINKAGE SECTION.
01 flag PIC 9.
DATA DIVISION.
LOCAL-STORAGE SECTION.
77 sub PIC 99.
LINKAGE SECTION.
01 out-table.
02 out-entry OCCURS 10 TIMES.
03 out-item PIC X(5).
01 out-count PIC 99.
The new class and method definitions for the Orders class:
IDENTIFICATION DIVISION.
CLASS-ID. Orders INHERITS SOMObject.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
* Declare classes used in program
REPOSITORY.
CLASS SOMObject IS 'SOMObject'
CLASS Orders IS 'Orders'.
DATA DIVISION.
* Define instance data
WORKING-STORAGE SECTION.
01 order-number PIC 9(5).
01 order-date PIC X(8).
01 order-count PIC 99.
01 order-table.
02 order-entry OCCURS 10 TIMES.
03 order-item PIC X(5).
PROCEDURE DIVISION.
PROCEDURE DIVISION.
MOVE FUNCTION CURRENT-DATE(1:8) TO order-date.
COMPUTE order-number = FUNCTION RANDOM ( 99999 ).
MOVE 0 TO order-count.
INITIALIZE order-table.
EXIT METHOD.
END METHOD 'somInit'.
DATA DIVISION.
LINKAGE SECTION.
01 in-order.
02 in-order-number PIC 9(5).
02 in-order-date PIC X(8).
02 in-order-count PIC 99.
02 in-order-table.
03 in-order-entry OCCURS 10 TIMES.
04 in-order-item PIC X(5).
DATA DIVISION.
LINKAGE SECTION.
01 out-order.
02 out-order-number PIC 9(5).
02 out-order-date PIC X(8).
02 out-order-count PIC 99.
02 out-order-table.
03 out-order-entry OCCURS 10 TIMES.
04 out-order-item PIC X(5).
LOCAL-STORAGE SECTION.
77 sub PIC 99.
01 found-flag PIC 9 VALUE 1.
88 found VALUE 0.
LINKAGE SECTION.
01 in-item PIC X(5).
01 add-flag PIC 9.
DATA DIVISION.
LOCAL-STORAGE SECTION.
77 sub PIC 99.
01 found-flag PIC 9 VALUE 1.
88 found VALUE 0.
LINKAGE SECTION.
01 out-item PIC X(5).
01 delete-flag PIC 9.
DATA DIVISION.
LOCAL-STORAGE SECTION.
77 sub PIC 99.
77 cost PIC 9(5)V99.
LINKAGE SECTION.
01 total-cost PIC 9(7)V99.
DATA DIVISION.
LINKAGE SECTION.
01 ord-num PIC 9(5).
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT order-file ASSIGN OrdrFile.
DATA DIVISION.
FILE SECTION.
FD order-file EXTERNAL.
01 order-record PIC X(80).
LOCAL-STORAGE SECTION.
01 print-line.
02 print-order-number PIC 9(5).
02 print-order-date PIC X(8).
02 print-order-count PIC 99.
02 print-order-table.
03 print-order-entry OCCURS 10 TIMES.
04 print-order-item PIC X(5).
PROCEDURE DIVISION.
OPEN OUTPUT order-file.
MOVE order-number TO print-order-number.
MOVE order-date TO print-order-date.
MOVE order-count TO print-order-count.
MOVE order-table TO print-order-table.
WRITE order-record FROM print-line.
CLOSE order-file.
EXIT METHOD.
END METHOD WriteOrder.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
* Declare classes used in subclass definition
REPOSITORY.
CLASS NewOrders IS 'NewOrders'
CLASS Orders IS 'Orders'.
DATA DIVISION.
PROCEDURE DIVISION.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
* Declare classes used in subclass definition
REPOSITORY.
CLASS BackOrders IS 'BackOrders'
CLASS Orders IS 'Orders'.
DATA DIVISION.
PROCEDURE DIVISION.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT backorder-file ASSIGN BackFile.
DATA DIVISION.
FILE SECTION.
FD backorder-file EXTERNAL.
01 backorder-record PIC X(80).
LOCAL-STORAGE SECTION.
01 backorder.
02 backorder-number PIC 9(5).
02 backorder-date PIC X(8).
02 backorder-count PIC 99.
02 backorder-table.
03 backorder-entry OCCURS 10 TIMES.
04 backorder-item PIC X(5).
77 eof-flag PIC 9 VALUE 1.
88 eof VALUE 0.
LINKAGE SECTION.
01 order-number PIC 9(5).
DATA DIVISION.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
*
* Declare the classes used in the program
REPOSITORY.
CLASS NewOrders IS 'NewOrders'
CLASS BackOrders IS 'BackOrders'
CLASS UserInterface IS 'UserInterface'.
DATA DIVISION.
WORKING-STORAGE SECTION.
*
* Declare the object references used in the program
* Note: univObj is a universal object reference
77 univObj USAGE OBJECT REFERENCE.
77 userObj USAGE OBJECT REFERENCE UserInterface.
*
* Declare other data items used in the program
77 order-number PIC 9(5).
77 total-cost PIC 9(7)V99.
77 out-count PIC 9(2).
77 request PIC X(6).
77 action PIC X(10).
77 flag PIC 9.
PROCEDURE DIVISION.
*
* Create an instance of the UserInterface class - userObj
INVOKE UserInterface 'somNew' RETURNING userObj.
*
* Read customer input - request
INVOKE userObj 'ReadUserRequest' USING request.
*
* What is the customer's request?
IF request = 'STATUS'
PERFORM CheckBackOrder
ELSE
PERFORM CreateNewOrder
END-IF.
*
* Free the instance of the UserInterface class - userObj
INVOKE userObj 'somFree'.
STOP RUN.
CreateNewOrder.
*
* Create an instance of the NewOrders class - univObj
INVOKE NewOrders 'somNew' RETURNING univObj.
*
* Read customer input - action and item
INVOKE userObj 'ReadUserInput1' USING item action.
*
* Begin customer driven loop based on action
PERFORM UNTIL action = 'Quit'
*
* Do appropriate action
IF action (1:3) = 'Add'
INVOKE univObj 'AddItem' USING item
RETURNING flag
ELSE
INVOKE univObj 'DeleteItem' USING item
RETURNING flag
END-IF
*
* Display result of action
INVOKE userObj 'WriteUserMessage' USING flag
*
* Read customer input - action and item
INVOKE userObj 'ReadUserInput1' USING item action
END-PERFORM.
* End customer driven loop based on action
*
*
* Calculate the total cost of the order
INVOKE univObj 'ComputeCost' USING total-cost.
*
* Determine the order number
INVOKE univObj 'getOrderNumber'
RETURNING order-number.
*
* Display information about the order
INVOKE userObj 'WriteUserOutput'
USING total-cost order-number.
*
* Free the NewOrders instance - univObj
INVOKE univObj 'somFree'.
CheckBackOrder.
*
* Create an instance of the BackOrders class - univObj
INVOKE BackOrders 'somNew' RETURNING univObj.
*
* Read customer input - order number
INVOKE userObj 'ReadUserInput2' USING order-number.
*
* Read the back-ordered information from a file
INVOKE univObj 'ReadOrder' USING order-number.
*
* Check whether the back-ordered items are now in stock
INVOKE univObj 'CheckItem' USING item-table out-count.
*
* Display the status of the back-ordered items
INVOKE userObj 'WriteUserStatus' USING item-table out-count.
*
* Free the BackOrders instance - univObj
INVOKE univObj 'somFree'.
Defining a metaclass
A metaclass is a special type of class whose instances are called class objects. Class
objects are the run-time objects that represent SOM classes. You can provide
explicit metaclass definitions for specialized purposes. Otherwise, object-oriented
COBOL applications use the default metaclasses provided automatically by the
SOM environment.
Metaclasses have their own methods and can have their own instance data. The
most common use of a metaclass is to control how an instance of a class is created.
Metaclasses are also useful when multiple instances of a class are created and data
must be gathered from all the instances.
You must properly terminate a metaclass definition with an END CLASS statement.
In the above example, MetaBackOrders is the class name. It inherits from the base
SOM class SOMClass.
By default, the data is global to all the methods that the metaclass introduces.
Instance data in a COBOL metaclass is private. No other class or metaclass can
reference it.
You must properly terminate a metaclass method definition with an END METHOD
statement.
RELATED TASKS
“Invoking a metaclass constructor method”
“Defining a class method” on page 381
“Defining a subclass method” on page 395
This example creates an instance of the class on which the method was invoked,
Self, and returns the handle to that instance in the object reference anObj.
Also, you must specify the name of the metaclass in the REPOSITORY paragraph of
the CONFIGURATION SECTION. For example:
Environment Division.
Configuration Section.
Repository.
Class MetaBackOrders Is 'MetaBackOrders'
Class BackOrders Is 'BackOrders'
Class Orders Is 'Orders'.
You can invoke any method in a metaclass with the class name. For example:
| Invoke BackOrders 'CountBackOrders' Returning out-count.
Or you can define a metaclass object reference as a handle to the metaclass. For
example:
Working-Storage Section.
01 metaObj Usage Object Reference Metaclass BackOrders.
The object reference metaObj is a handle to the metaclass for BackOrders, not a
handle to BackOrders itself.
The first INVOKE statement invokes a SOM method somGetClass which takes an
object reference, backObj, to an instance and returns an object reference, metaObj, to
the metaclass to which backObj belongs.
The second INVOKE statement uses the object reference to the metaclass, metaObj to
invoke the method CountBackOrders which is defined in the metaclass.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
* Declare classes used in metaclass definition
REPOSITORY.
CLASS MetaBackOrders IS 'MetaBackOrders'
CLASS BackOrders IS 'BackOrders'
CLASS SOMClass IS 'SOMClass'.
DATA DIVISION.
* Define instance data
WORKING-STORAGE SECTION.
01 status-count PIC 99.
PROCEDURE DIVISION.
PROCEDURE DIVISION.
DATA DIVISION.
LINKAGE SECTION.
01 order-number PIC 9(5).
01 anObj USAGE OBJECT REFERENCE.
DATA DIVISION.
LINKAGE SECTION.
01 out-count PIC 9(2).
The new subclass and method definitions for the BackOrders subclass:
IDENTIFICATION DIVISION.
CLASS-ID. BackOrders INHERITS Orders
METACLASS MetaBackOrders.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
* Declare classes used in subclass definition
REPOSITORY.
CLASS MetaBackOrders IS 'MetaBackOrders'
CLASS BackOrders IS 'BackOrders'
CLASS Orders IS 'Orders'.
DATA DIVISION.
PROCEDURE DIVISION.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT backorder-file ASSIGN BackFile.
DATA DIVISION.
FILE SECTION.
FD backorder-file EXTERNAL.
01 backorder-record PIC X(80).
LOCAL-STORAGE SECTION.
DATA DIVISION.
LOCAL-STORAGE SECTION.
01 backorder.
02 backorder-number PIC 9(5).
02 backorder-date PIC X(8).
02 backorder-count PIC 99.
02 backorder-table.
03 backorder-entry OCCURS 10 TIMES.
04 backorder-item PIC X(5).
77 sub PIC 99 VALUE 0.
77 status-flag PIC 9.
88 in-stock VALUE 0.
88 out-stock VALUE 1.
LINKAGE SECTION.
01 out-table.
02 out-entry OCCURS 10 TIMES.
03 out-item PIC X(5).
01 out-count PIC 99.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
*
* Declare the classes used in the program
REPOSITORY.
CLASS NewOrders IS 'NewOrders'
CLASS BackOrders IS 'BackOrders'
CLASS UserInterface IS 'UserInterface'.
DATA DIVISION.
WORKING-STORAGE SECTION.
*
* Declare the object references used in the program
77 univObj USAGE OBJECT REFERENCE.
* Note: metaObj is an object reference to a metaclass
77 metaObj USAGE OBJECT REFERENCE METACLASS BackOrders.
77 userObj USAGE OBJECT REFERENCE UserInterface.
*
* Declare other data items used in the program
77 order-number PIC 9(5).
77 total-cost PIC 9(7)V99.
77 out-count PIC 9(2).
77 request PIC X(6).
77 action PIC X(10).
77 flag PIC 9.
77 item PIC X(5).
01 item-table.
02 item-entry OCCURS 10 TIMES.
03 item-element PIC X(5).
PROCEDURE DIVISION.
*
* Create an instance of the UserInterface class - userObj
INVOKE UserInterface 'somNew' RETURNING userObj.
*
* Read customer input - request
INVOKE userObj 'ReadUserRequest' USING request.
*
* What is the customer's request?
IF request = 'STATUS'
PERFORM CheckBackOrder
ELSE
PERFORM CreateNewOrder
END-IF.
*
* Free the instance of the UserInterface class - userObj
INVOKE userObj 'somFree'.
STOP RUN.
CreateNewOrder.
*
* Create an instance of the NewOrders class - univObj
INVOKE NewOrders 'somNew' RETURNING univObj.
*
* Read customer input - action and item
INVOKE userObj 'ReadUserInput1' USING item action.
*
* Calculate the total cost of the order
INVOKE univObj 'ComputeCost' USING total-cost.
*
* Determine the order number
INVOKE univObj 'getOrderNumber'
RETURNING order-number.
*
* Display information about the order
INVOKE userObj 'WriteUserOutput'
USING total-cost order-number.
*
* Write the order to a file
INVOKE univObj 'WriteOrder'.
*
* Free the NewOrders instance - univObj
INVOKE univObj 'somFree'.
CheckBackOrder.
*
* Read customer input - order number
INVOKE userObj 'ReadUserInput2' USING order-number.
*
* Begin customer driven loop based order number
| PERFORM UNTIL order-number = 0
*
* Create an instance of the BackOrders class (univObj) and
* read the back order from a file using a metaclass method
INVOKE BackOrders 'CreateBackOrders'
USING order-number RETURNING univObj
*
* Check whether the back-ordered items are now in stock
INVOKE univObj 'CheckItem'
USING item-table out-count
*
* Display the status of the back-ordered items
INVOKE userObj 'WriteUserStatus'
USING item-table out-count
*
* Read customer input - order number
INVOKE userObj 'ReadUserInput2'
RELATED CONCEPTS
“SOM Interface Repository”
“SOM services” on page 420
RELATED TASKS
“Defining a class” on page 378
“Chapter 26. Using SOM IDL-based class libraries” on page 425
OS/390 SOMobjects Programmer’s Guide
RELATED REFERENCES
“SOM methods and functions” on page 420
RELATED TASKS
“Accessing the SOM Interface Repository”
“Compiling and linking programs that call SOM functions” on page 421
“Populating the SOM Interface Repository” on page 416
SOMIR=//’prefix.class.SOMIR’;
prefix.class.SOMIR is the data set name (DSN) of the IR file. Substitute your OS/390
user ID for prefix, and a meaningful name for class.
You set this and other SOM environment variables in a SOM configuration file. See
the cross-references below for further information on setting up configuration files
and on SOM environment variables.
In this case, somhlq.SGOSIR and prefix.app.SOMIR are the SOM and application IR
files, respectively, and are not changed. prefix.user.IR is the working IR file, which
is updated.
When you compile an application with the IDLGEN or TYPECHK compiler options,
you must:
1. Define an IR file.
2. Create a SOM configuration file whose SOMIR setting specifies the IR as the
rightmost in the list of IR files.
3. Provide a SOMENV DD statement (or equivalent TSO ALLOCATE command) that
refers to the configuration file.
RELATED CONCEPTS
“SOM Interface Repository” on page 415
“SOM services” on page 420
RELATED TASKS
Setting up configuration files (OS/390 SOMobjects Programmer’s Guide)
RELATED REFERENCES
“SOM environment variables” on page 417
“SOM methods and functions” on page 420
RELATED CONCEPTS
“SOM Interface Repository” on page 415
RELATED REFERENCES
“Class initialization” on page 421
| The configuration file is organized into stanzas that contain specific environment
| variables. Each stanza is headed by the name of the stanza in brackets. For
| example, [somc] introduces the stanza for the SOM compiler.
| Set the following environment variables, within the proper stanza, as shown:
| SOM kernel stanza:
SMLANG
Specifies the language for SOM messages.
For example:
| [somk]
| SMLANG=EnUs
For example:
| [somc]
| SMEMIT=ir:h
| SMINCLUDE=//'somhlq.SGOSIDL';//'prefix.MYCLASS.IDL';
For example:
| [somir]
| SOMIR=//'somhlq.SGOSIR';//'prefix.LOCAL.SOMIR';
See a complete sample SOM configuration file in note (6) to the JCL in the example
below (“Example: sample JCL for an object-oriented application”).
RELATED TASKS
Setting up configuration files (OS/390 SOMobjects Programmer’s Guide)
RELATED TASKS
“Chapter 13. Compiling under OS/390” on page 203
“Populating the SOM Interface Repository” on page 416
SOM services
IBM COBOL implements a subset of the ANSI Object-Oriented COBOL syntax,
based on the SOM object-oriented engine. Not all essential object-oriented
capabilities are implemented in native COBOL syntax. Instead, IBM COBOL uses
SOM application programming interfaces, methods, and functions. For example,
native COBOL syntax is available for class definitions, object-reference data type,
and method invocation. However, you accomplish object creation, destruction,
initialization, and termination by invoking SOM methods provided by the
SOMObject and SOMClass classes. Many other SOM facilities are available to you
either for direct use or for overriding and customizing.
RELATED TASKS
OS/390 SOMobjects Programmer’s Guide
RELATED REFERENCES
“SOM methods and functions”
“Class initialization” on page 421
Your invocations of SOM methods do not require any special considerations. The
correct linkage conventions are used automatically for method invocations.
RELATED TASKS
“Chapter 30. Creating a DLL or a DLL application” on page 489
Class initialization
Every SOM class provides an initialization function <classname>NewClass.
Normally COBOL programmers do not use this function directly, but the function
is available in all COBOL classes. The COBOL run-time system automatically
initializes all classes referenced within a COBOL program by calling their class
initialization functions before the first user-written COBOL statement in the
PROCEDURE DIVISION is executed.
RELATED REFERENCES
“SOM methods and functions” on page 420
You can invoke methods defined in COBOL classes from other languages (such as
C code built with the SOM C emitter) that use offset resolution. In this case, the
standard SOM requirements apply. COBOL does not provide language comparable
to the SOM “release-order” mechanism, which is used to ensure methods can be
added to a class definition without requiring recompilation of code that invokes
the methods using offset resolution. When you add methods to an existing COBOL
class, add them at the end of the PROCEDURE DIVISION of the class definition, after
existing methods. This placement ensures that any existing client code invoking the
original methods does not require recompilation.
RELATED REFERENCES
Method resolution (OS/390 SOMobjects Programmer’s Guide)
There are several forms of Interface Definition Language (IDL), such as those for
the Distributed Computing Environment (DCE) or the Object Management Group’s
Common Object Request Broker Architecture (OMG CORBA). This information
concerns only IBM’s System Object Model Interface Definition Language (SOM
IDL). SOM IDL is consistent with CORBA but allows some additional data types
such as pointers.
You need to understand the System Object Model (SOM), at least conceptually, and
know where to find more detailed documentation about SOM when you need it.
You also need access to the documentation for the class library that you are
intending to use.
To get started, you need one of the object-enabled IBM COBOL products, together
with the executables for the class library and its documentation.
RELATED CONCEPTS
“SOM objects”
“SOM IDL” on page 426
RELATED TASKS
Understanding Somobjects programming (OS/390 SOMobjects Programmer’s Guide)
“Mapping IDL to COBOL” on page 427
“Handling errors and exceptions” on page 442
“Creating and initializing object instances” on page 445
“Avoiding memory leaks” on page 447
RELATED REFERENCES
“Common IDL types” on page 429
SOM objects
A SOM class library consists of:
v Executable code
v Interface information that defines the operations that the library supports,
including the parameters for invoking the operations (known as the operation
signatures)
When the library is being used at run time, the components that are present in
memory are shown below:
SOM IDL
The interface information for a SOM class library can be in various forms:
v IDL files
v An Interface Repository (IR), a machine-readable form of IDL used during
compilation
v Documentation defining the method interfaces in IDL, and describing the
semantics and rules for using the methods
IDL expresses the contract between the provider of object services (in this case the
class library) and the user of these services (COBOL program, method, or
subclass). The interface description is formally independent of the language in
which either the user of the service or the service itself is implemented. This
property is known as language neutrality. The separation of the interface from the
implementation also allows flexibility in the deployment of the objects on the
nodes of a network.
IDL data types have their origins in the C and C++ data model. Because many of
them do not have an exact counterpart in the COBOL language, there needs to be
a translation (or mapping) between IDL and COBOL. The mapping recommended
here assumes that the data structures can be passed directly between the COBOL
and C/C++ mappings to SOM IDL.
The standard CORBA model presumes a stub routine between the invoking and
invoked object to do argument translation, marshalling, and so on. Passing the
structures directly yields very significant gains in efficiency, but some of the
mappings might not seem as natural to the COBOL programmer as they would if
the transfer were mediated by a stub routine. Passing directly also means that you
must have the correct alignment and padding of structures that are passed across
an interface. In general the recommended way to achieve this for IDL-based
interfaces is to specify the SYNCHRONIZED clause for COBOL mappings to any IDL
structs or arrays that directly contain structs.
RELATED TASKS
“Mapping IDL to COBOL” on page 427
RELATED REFERENCES
“Common IDL types” on page 429
“Complex IDL types” on page 432
You need to map IDL identifiers, operations, and attributes to their COBOL
counterparts. Some of the IDL types (such as boolean, long, and string) occur very
commonly in interfaces, while complex IDL types (such as array and struct) are
quite rare. You might be able to avoid knowing about the complex IDL types. Refer
to the related references below for each category of IDL types. You do need to
know the conventions for passing arguments and return values.
The only IDL names that must be identical in COBOL are the class (IDL interface)
and method (IDL operation) names. You specify these names exactly with literals:
v For a class, in the CLASS IS clause of the REPOSITORY paragraph.
v For a method, by using the literal form of the method name in the METHOD-ID
paragraph. When you invoke a method, you use either the literal form of the
name or a data name initialized with the exact method name.
The other identifiers, such as parameter, constant, and exception names, are
internal to your program or class, and do not have to be identical to the IDL.
However, it is a good practice to keep these names close to the IDL originals to
enhance the readability and maintainability of your programs.
RELATED TASKS
“Using IDL operations”
“Expressing IDL attributes” on page 428
“Passing COBOL arguments and return values” on page 435
RELATED REFERENCES
“Common IDL types” on page 429
“Complex IDL types” on page 432
To use an operation, you code an INVOKE statement with the appropriate USING and
RETURNING phrases that correspond to the parameters and the return value of the
operation. If these parameters are simple scalar types, the operation definition is
self-contained. But if an operation uses a “constructed” type, you might need the
definition of the parameter type to specify your INVOKE statement completely.
The single input argument is of type color, which is not a basic scalar IDL type.
Suppose that color is an IDL enum (enumerated item) with the following definition
(typically found in a different section of the library documentation):
typedef enum color{red, white, blue};
The evp argument is the environment pointer, which precedes the explicit operation
arguments. It is used for communicating to the caller any exceptions that the
operation encounters.
RELATED TASKS
“Passing COBOL arguments and return values” on page 435
“Handling errors and exceptions” on page 442
RELATED REFERENCES
“Common IDL types” on page 429
SOM models attributes as a pair of operations, one to set and one to get the
attribute value. Attribute operations return errors by means of standard exceptions.
float _get_radius();
void _set_radius(in float r);
position_t _get_position();
};
(You pass the instance of the class according to the rules for
passing arguments.)
long long that; 1 that comp-5 pic s9(9).
octet octet that; 1 that displays pic x.
pointer pointer that; 1 that pointer.
short short that; 1 that comp-5 pic s9(4).
| string (bounded) string<100> that; 1 that-l-max comp-5 pic 9(9) value 101.
| 1 that-l comp-5 pic 9(9).
1 that.
2 that-v pic x occurs 1 to 101 depending that-l.
| string (unbounded) string that; 1 that-l-max comp-5 pic 9(9) value 4096.
| 1 that-l comp-5 pic 9(9).
1 that.
2 that-v pic x occurs 1 to 4096 depending that-l.
unsigned long unsigned long that; 1 that comp-5 pic 9(9).
unsigned short unsigned short that; 1 that comp-5 pic 9(4).
enum
The closest COBOL equivalent to a SOM IDL enum is an unsigned binary fullword,
together with condition-name entries for each of the enumeration members.
RELATED TASKS
“Passing enumerated arguments” on page 437
interface
The use of an IDL interface as an argument to, or result of, an operation denotes
an object reference to an instance of the class to which the interface has been
mapped. Therefore, if a method has an interface type as one of its parameters,
specify an OBJECT REFERENCE to an instance of a class that supports that interface.
Also be aware that there are significant performance effects associated with the use
| of COMP-5 data items or the TRUNC(BIN) compiler option (primarily, though, for
| doubleword binary data items, that is for items declared USAGE BINARY with a
| PICTURE clause containing 10 or more 9s).
The unsigned form of binary data is mapped as for the SOM IDL short type,
except that the PICTURE clause does not specify the character S.
string
The SOM IDL type string is one of the most important types, because it is widely
used in operations and interfaces. It is also one of the most difficult to match in
COBOL, because SOM IDL strings are modeled on those of C and C++. These have
a null terminator to determine the length of the string, and are passed by a typed
pointer. IBM COBOL does not support such null-terminated strings as a native
data type. However, the null-terminated literal Z’string-value’ alleviates some of
the problems and, when it can be passed BY CONTENT, is an exact match to a SOM
IDL in string. (For inout and out strings, you must pass a pointer to the string
data or buffer BY REFERENCE.) You can also use a null-terminated literal to set the
initial VALUE of a data item to be used as a string argument.
In general, IDL strings are mapped to pointers to the appropriate character string
data or buffer. With the exception of in strings, however, just the pointer is actually
passed in a method invocation. But, for this to work operationally, the pointer
must be set to the address of the underlying character string data or buffer in
PICTURE X format. There are several styles of data definition, depending on
whether the parameter is an in, inout, or out argument, or a return value. The
declarations described below can be used to represent both the COBOL and SOM
IDL view of a variable-length string simultaneously.
The main cases to distinguish are bounded and unbounded strings. Bounded
strings have a fixed upper limit on their size. The following IDL declaration
represents a SOM IDL string of no more than 100 characters in length:
string<100> that;
The -l suffix denotes the length of the string, the -v its value. The extra position
allows for the null terminator. The data item that, in addition to being a valid
SOM IDL string, is also variable length in COBOL, because of the OCCURS
DEPENDING clause.
You might, for example, know that the strings that are passed across the interface
do not in practice exceed 4095 characters. Then the following COBOL declarations
would be appropriate:
1 that-l-max binary pic 9(9) value 4096.
1 that-l binary pic 9(9).
1 that.
2 that-v pic x occurs 1 to 4096 depending that-l.
You can use a pair of helper routines (see the related references below) to
synchronize the two representations, for example, either the bounded or
unbounded that, above:
’IDLStringToCOBOL’ using that that-l
This routine sets the COBOL OCCURS object that-l from the position of the
mandatory null terminator.
If you prefer, you can achieve the same result in COBOL:
Move that-l-max to that-l
Move zero to tally
Inspect that tallying tally for characters before x'00'
Move tally to that-l
’IDLStringFromCOBOL’ using that that-l
This routine inserts the null terminator at the string position indicated by
the COBOL OCCURS object.
If you prefer, you can do this quite easily yourself in COBOL:
Move x'00' to that-v(that-l)
RELATED TASKS
“Passing string arguments” on page 437
RELATED REFERENCES
“Source code for helper routines” on page 450
any
The IDL any type is a self-describing representation of any of the IDL types,
including another IDL any. The descriptor is mapped to COBOL as a group item,
which includes a pointer to the actual data item of the particular type. Suppose
you want to map the following IDL declaration:
The that-value field points to the start of the data for the item that the any
represents.
array
IDL arrays map to COBOL tables—groups whose subordinate items contain the
OCCURS clause. The underlying IDL type can be any of the IDL types, including
array itself, and is mapped according to the rules for the individual IDL type.
The -v suffix denotes the individual element values. The unsuffixed name is used
to pass the entire array as an argument to a method; the suffixed name is used to
refer to individual elements of the array.
If any level of the array contains a struct or union, then you must specify the
SYNCHRONIZED clause on the group item. This is to ensure that the subordinate items
are aligned on their natural boundaries, in conformance with the default alignment
of SOM IDL structures.
sequence
An IDL sequence is a one-dimensional array with a descriptor that specifies a
maximum and current size for the sequence. If the maximum size is explicitly
declared, the sequence is said to be bounded. Otherwise, the sequence is unbounded,
and the maximum size is determined at run time (in an application-specific way)
and is set prior to passing the sequence to an operation.
The descriptor for the maximum and current size and address of this sequence is
represented in COBOL as a group item:
1 that.
2 that-maximum binary pic 9(9).
2 that-length binary pic 9(9).
2 that-buffer pointer.
struct
An IDL struct type corresponds to a COBOL group item containing the
individually mapped components of the struct as subordinate data items.
The SYNCHRONIZED clause is required so that the alignment of the subordinate items
approximates the default alignment of SOM IDL structures. In most practical cases,
the alignment would be correct either way, but specifying SYNCHRONIZED is a
sensible precaution.
union
A SOM IDL union has a discriminator that indicates which format variant to use.
In COBOL, this type is mapped to a group item containing the discriminator, plus
the union itself represented by using the REDEFINES clause. Then, in the procedure
division, use an EVALUATE statement to determine which format is currently in
effect.
The data declaration part of the COBOL mapping could be written as follows:
1 that sync.
2 that-d binary pic s9(9).
2 that-u display pic x(4).
2 that-x redefines that-u display pic x.
2 that-y redefines that-u binary pic s9(9).
2 that-z redefines that-u comp-1.
The SYNCHRONIZED clause makes sure that COBOL mimics the default SOM IDL
alignment rules. Thus, in the unlikely event that any IDL structures have “holes,”
COBOL would insert slack bytes in the record as appropriate.
The size of the extra member of the union, that-u, is the maximum of the sizes of
the explicit union members. This extra data item is needed because of the COBOL
restriction that a data item being redefined must be at least as large as the item
redefining it. Alternatively, you could declare the union members in order of
decreasing size, but that might lose the correspondence between the COBOL
declaration and the original IDL.
Literal arguments are not supported for the enum type because of the risk of the
source getting out of sync with the enumeration list.
RELATED TASKS
“Passing enumerated arguments” on page 437
“Passing string arguments” on page 437
RELATED REFERENCES
“Conventions for passing arguments and return values”
“Source code for helper routines” on page 450
OS/390 SOMobjects Programmer’s Guide (rules for passing arguments of complex
types)
1. For IBM COBOL for OS/390 & VM you can use BY CONTENT or BY REFERENCE only if the
argument is not the last. This limitation is due to the System/390 linkage conventions
of the high-order bit of the last argument address being set on to indicate the end of
the argument list. This convention confuses C and C++ programs that attempt to
manipulate the address as a pointer. An alternative to BY REFERENCE (for this situation
and in general) is to pass BY VALUE a pointer that has previously been set to the address
of the data item.
2. For inout and out strings, you must pass a pointer to the string data or buffer BY
REFERENCE.
3. The term type here means the COBOL equivalent of the IDL type, specified directly in
the RETURNING phrase of the INVOKE statement.
4. The term pointer here means a COBOL POINTER that has been set to the address of the
equivalent data item or output buffer.
For in string types: You pass in string types in several ways. Where you know
the content, you can specify it as a null-terminated literal, either directly or as the
value of a data item:
1 that pic x(101) value z'initial value'.
. . .
Invoke anObject 'method'
For variable-content strings, you might find it convenient to use a plain (PICTURE
X) alphanumeric data declaration for the string buffer. You can use reference
modification if you want to see the valid part of the string:
1 that-l binary pic 9(9).
1 that pic x(101).
. . .
Display 'Content of “that” = “' that(1:that-l) '”'
You can synchronize either the reference-modified or the OCCURS DEPENDING form of
the COBOL string representation with the IDL representation by using the
IDLStringToCOBOL and IDLStringFromCOBOL helper routines.
For inout and out strings: You must pass the string buffer with an extra level of
indirection. The way that you express the extra level of indirection in COBOL is to
pass a pointer that for inout strings has previously been set to the address of the
string data. As usual, you have a choice of passing this pointer BY REFERENCE, or
declaring a second pointer that you have set to the address of the first and passing
this second pointer BY VALUE:
1 ptr1 pointer.
1 ptr2 pointer.
1 that-l binary pic 9(9).
. . .
Linkage section.
1 that.
2 that-v pic x occurs 1 to 101 depending that-l.
. . .
Set ptr1 to address of that
Invoke anObject 'method' using by value evp by reference ptr1 . . .
. . .
Set ptr2 to address of ptr1
Invoke anObject 'method' using by value evp ptr2
The extra level of indirection is needed for out strings, because they are allocated
by the method and can be arbitrarily long. But the output size of an inout string is
limited by the input size: the upper bound for a bounded string; or the actual
input size for an unbounded string.
For a return value: Specify a pointer, which the method sets to the address of the
output string before it returns.
For all the output modes of string, including inout: Declare the string buffer
itself in the LINKAGE SECTION to allow the method to allocate, or reallocate, the
storage for the string. You should acquire storage for an inout string calling
OMMAllocate, so that (in future) methods can resize the string if necessary.
You can look at the storage by declaring appropriate LINKAGE SECTION data items
as usual, but do not attempt to modify it. The storage might be protected, and you
cannot assume that you have appropriate write privileges. Instead, make a copy
RELATED REFERENCES
“Source code for helper routines” on page 450
Let us begin by looking at the documentation for our class library, which provides
a bucket class. A bucket is a container that lets you add or remove objects, and
that can report the number of objects it contains. Buckets have no special initializer
methods, and can thus be created and initialized correctly just by invoking the
somNew method on the class. Normally, the documentation would define and
describe each operation separately, but for this simple example, we will give the
complete interface definition of a bucket:
interface Bucket {
readonly attribute unsigned long count;
void add(in SOMObject element) raises(BucketFull);
SOMObject remove() raises(BucketEmpty);
};
The raises clause specifies the exceptions that the operation can incur.
The things that we put into our buckets have no external behavior beyond their
existence. That is, they can be created and destroyed, and are identifiable by their
object references, but they have no methods or attributes.
The COBOL program in this example shows how you might use this class library.
The COBOL coding is very simplistic. For example, it does not check for errors
realistically or free all the objects that it creates. But it does cover most of the
things that you have to do to start using a class library. It performs the following
steps:
1. Create an instance of a bucket.
2. Create and add some things to the bucket.
3. Print the number of things in the bucket.
4. Remove a thing from the bucket.
5. Print the number of things in the bucket.
(1) Process pgmname(longmixed),dll
******************************************************************
* Client program for Bucket. *
******************************************************************
Identification division.
Program-id. 'TryBucket'.
Environment division.
Configuration section.
Repository.
class thing 'Thing'
chkxcp.
if any-exception
display 'An exception occurred; quitting the program!'
stop run
end-if.
Notes:
(1) Regardless of what you call your program, you need to specify the
PGMNAME(LONGMIXED) and the DLL compiler options to be able to call SOM
APIs such as somGetGlobalEnvironment. The options do not affect INVOKE
statements, but they do apply to program names in CALL statements.
(2), (3), and (4)
If not stated otherwise, SOM IDL class libraries use callstyle idl. With this
convention, every operation has an implicit environment pointer preceding
the explicit IDL arguments for the operation. Although this argument is
implicit in the IDL, you code it explicitly on your INVOKE statements.
You must, at a minimum, define the environment pointer in the
WORKING-STORAGE or LOCAL-STORAGE SECTION. If you want to examine any
exceptions that are returned, you must also define the exception type in the
SOMError is used for internal errors in the kernel classes, and is not relevant to the
average user. Methods of the kernel classes create an object (somNew and
somNewNoInit) or destroy it (somFree). The main implication of SOMError for these
methods is that you do not need to provide an environment argument when you
invoke them, and you do not need to check for exceptions after they return.
However you do need to know how to use the SOM exception mechanism, which
is used for most other methods. Exceptions are not necessarily errors, but errors do
use the SOM exception mechanism.
SOM exceptions are not the same as C++ exceptions, but instead set the value of
an exception structure, which you can think of as a special kind of return code,
accessed through the environment variable.
Handling exceptions
When a callstyle idl method that you have invoked detects a condition that is to
be expressed as an exception, it uses the somSetException function to supply the
exception name and an exception structure.
RELATED REFERENCES
CORBA standard exceptions (OS/390 SOMobjects Programmer’s Guide)
******************************************************************
* Subroutine to strip leading zeroes *
******************************************************************
Identification division.
Program-id.
'SLZ'.
Data division.
Linkage section.
1 uint binary pic 9(9).
1 str pic x(9).
1 pos binary pic 9(9).
Procedure division using uint str pos.
Move uint to str
Move 0 to pos
Inspect str(1 : length str - 1)
tallying pos for leading '0'
Add 1 to pos
Goback
. . .
End program 'SLZ'.
You can execute the nondefault initializer methods (as a client) of a class by
invoking first somNewNoInit and then the appropriate initializer method. This is the
recommended way to create an instance of one of the SOM-enabled collections, for
example.
You do need to specify the somInitCtrl structure that is used to control the
progress of the initializer as it traverses the class hierarchy. For a client of a class
initializer method (as opposed to a subclass that provides its own initializer
methods), this structure is initially null, represented in COBOL as an OMITTED
argument. Suppose that the IDL for the initialization method is:
void ISHeap_withNumber(inout somInitCtrl ctrl, in long number);
For COBOL subclasses of classes that use explicit initializers, use metaclass
methods to instantiate and initialize the COBOL object. After creating the instance,
the metaclass method invokes the initializer for each parent (with multiple
inheritance, there could be several). It then initializes any instance data that the
subclass introduced. You could create and initialize these objects directly in the
client code. However, encapsulating the logic in a metaclass method is more
reliable and convenient, especially when the subclass inherits from multiple
parents.
Using a metaclass method is also a good way to create and initialize your own
pure COBOL objects in a single step, particularly where each object has a unique
initial value.
Consider the sample IDL file spred from the collection class library.
#ifndef _ISPRED_IDL (1)
#define _ISPRED_IDL
somDefaultInit: override,init;
somDestruct: override;
callstyle = idl;
majorversion = 1;
minorversion = 0;
You can also use these routines to manage dynamic storage (as opposed to instance
data) for your own classes.
RELATED TASKS
“Passing COBOL arguments and return values” on page 435
RELATED REFERENCES
“Source code for helper routines” on page 450
******************************************************************
* Variable-length string class instance data. *
******************************************************************
Data division.
Working-storage section.
1 vstlen binary pic 9(9).
1 vstptr pointer.
******************************************************************
* Variable-length string class method: default initialization; *
* set the instance to a predictable state. *
******************************************************************
Identification division.
Method-id.
'somInit' override.
Procedure division.
(1) Set vstptr to null
Move 0 to vstlen
Goback
. . .
End method 'somInit'.
******************************************************************
* Variable-length string class method: assignment from a literal*
******************************************************************
Identification division.
Method-id.
'SetVarstring'.
Data division.
Local-Storage section.
1 strsze pic 9(9) binary.
Linkage section.
1 valptr pointer.
1 setval pic x(100).
1 vstval pic x(100).
Procedure division using by value valptr.
(2) If vstptr not = null then
Call 'OMMFree' using vstptr
End-if
Move 0 to vstlen
Set address of setval to valptr
Inspect setval tallying vstlen
for characters before initial x'00'
Add 1 to vstlen giving strsze
Call 'OMMAllocate' using strsze returning vstptr
Set address of vstval to vstptr
******************************************************************
* Variable-length string class method: return string (pointer). *
******************************************************************
Identification division.
Method-id.
'GetVarstring'.
Data division.
Linkage section.
1 valptr pointer.
Procedure division returning valptr.
Set valptr to vstptr
Goback
. . .
End method 'GetVarstring'.
******************************************************************
* Variable-length string class method: assign from another string*
******************************************************************
Identification division.
Method-id.
'AssignVarstring'.
Data division.
Local-Storage section.
1 strsze binary pic 9(9).
1 valptr pointer.
Linkage section.
1 str object reference varstring.
Procedure division using by value str.
(3) If self not = str then
Invoke str 'GetVarstring' returning valptr
Invoke self 'SetVarstring' using by value valptr
End-if
Goback
. . .
End method 'AssignVarstring'.
******************************************************************
* Variable-length string class method: free associated storage. *
******************************************************************
Identification division.
Method-id.
'somUninit' override.
Procedure division.
(4) If vstptr not = null then
Call 'OMMFree' using vstptr
Set vstptr to null
Move 0 to vstlen
End-if
Goback
. . .
End method 'somUninit'.
/* Set IDL string length (null byte) from COBOL (ODO) representation */
void IDLStringFromCOBOL(char *str, long *len) {
char *s;
long *l;
Clean(s,str);
Clean(l,len);
s[*l]=0;
return;
}
Only if your existing code no longer meets your needs or its maintenance cost is
too high should you consider converting the entire procedure-oriented system to
an object-oriented system. Then the conversion entails identifying objects,
analyzing the data flow and usage, reallocating code to objects, and writing the
object-oriented code.
RELATED CONCEPTS
“OO view of COBOL programs”
RELATED TASKS
“Wrapping procedure-oriented programs” on page 452
“Converting from procedure-oriented to OO programs” on page 453
Online programs are built around the transactions which they process, and which
are reflected in user interface maps and panels. Online transactions can access
several files or databases from one panel. There is a one-to-many relationship
between the source of the action and the targets of the action, all of which can be
viewed as objects.
Suppose you have a stable set of procedural code for updating a database, but you
want to include the database as part of a graphical user interface. You want users
to be able to drop a list object representing an update to the database on the
database object and have the update performed. To achieve this, you need to write
a wrapper class to accept messages from the list object; that is, the list object
invokes methods in the wrapper. The methods in the wrapper class interpret the
information from the list object and use the CALL statement to call the appropriate
subprogram in the old procedural code, as shown in the figure:
By using wrappers, you can phase in new object-oriented code and continue to use
your existing procedure-oriented code. You can, for example, write a wrapper for
each subprogram in the procedural code. Or if several subprograms are working
with the same object, processing the same file, or producing the same report, you
can write a single wrapper for all the related subprograms. A true object invokes
RELATED TASKS
“Converting from procedure-oriented to OO programs”
RELATED TASKS
“Defining a class” on page 378
“Defining a class method” on page 381
“Defining a client program” on page 389
2. Now you have many potential objects, some of which are redundant. Study the
potential objects and decide whether two or more are slight variations of the
same object.
3. Where possible, combine two potential objects into one object. Maybe you have
two detail lines as potential objects that differ in only one or two of their fields.
If possible, use REDEFINES or some other technique to combine the two detail
lines into one.
As a result of identifying objects, you have an object list with the name of each
object and its instance data.
For example:
The first MOVE statement is associated with an input object and the second with an
output object.
Now couple the procedural statements from the PROCEDURE DIVISION with the
objects to form methods. Take the code you pulled from the program and organize
it into task-oriented methods.
Refer to the object relationship table from step two (analyzing data flow and
usage) and determine if you must write any new methods to facilitate passing data
between objects.
RELATED TASKS
“Identifying objects” on page 454
“Analyzing data flow and usage” on page 454
“Defining a class method” on page 381
Also, write the client program to create instances of the classes and invoke
methods.
RELATED TASKS
“Identifying objects” on page 454
“Reallocating code to objects” on page 454
“Defining a class” on page 378
“Defining a client program” on page 389
Attention: Do not use program names that start with prefixes used by IBM
products. If you try to use programs whose names start with any of the following,
your CALL statements might resolve to IBM library or compiler routines rather than
to your intended program:
RELATED CONCEPTS
“Main programs, subprograms, and calls”
RELATED TASKS
“Ending and reentering main programs or subprograms” on page 460
“Transferring control to another program” on page 461
“Making recursive calls” on page 472
“Calling to and from object-oriented programs” on page 472
“Using procedure pointers” on page 472
“Making programs reentrant” on page 474
Language Environment Writing ILC Applications
RELATED REFERENCES
Register conventions (Language Environment Programming Guide)
In the PROCEDURE DIVISION, a program can call another program (generally called a
subprogram in COBOL terms), and this called program can itself call other
programs. The program that calls another program is referred to as the calling
program, and the program it calls is referred to as the called program. When the
The called COBOL program starts running at the top of the PROCEDURE DIVISION.
RELATED TASKS
“Ending and reentering main programs or subprograms”
“Making recursive calls” on page 472
“Transferring control to another program” on page 461
RELATED REFERENCES
Language Environment Programming Guide
Termination
statement Main program Subprogram
EXIT PROGRAM No action taken. Return to calling program without
ending the run unit. An implicit
EXIT PROGRAM statement is
generated if the called program
has no next executable statement.
STOP RUN Return to calling program.1 (Might Return directly to the program that
be the operating system, and job called the main program.1 (Might
will end.) be the operating system, and job
will end.)
STOP RUN terminates the run unit,
and deletes all dynamically called
programs in the run unit and all
programs link-edited with them. (It
does not delete the main program.)
GOBACK Return to calling program.1 (Might Return to calling program.
be the operating system, and job
will end.)
1. If the main program is called by a program written in another language that does not
follow Language Environment linkage conventions, return will be to this calling
program.
A subprogram is usually left in its last-used state when it terminates with EXIT
PROGRAM or GOBACK. The next time it is called in the run unit, its internal values will
be as they were left, except that return values for PERFORM statements will be reset
to their initial values. (In contrast, a main program is initialized each time it is
called.)
There are some cases where programs will be in their initial state:
v A subprogram that is dynamically called and then canceled will be in the initial
state the next time it is called.
v A program with the INITIAL attribute will be in the initial state each time it is
called.
RELATED TASKS
“Calling nested COBOL programs” on page 468
“Making recursive calls” on page 472
When you want to use OS/VS COBOL with COBOL for OS/390 & VM, there are
differences in support between non-CICS and CICS:
In a non-CICS environment
You can make static and dynamic calls between COBOL for OS/390 & VM,
COBOL for MVS & VM, and OS/VS COBOL programs.
| Exception: You cannot call OS/VS COBOL in the OS/390 UNIX
| environment.
In a CICS environment
You must use EXEC CICS LINK to transfer control between OS/VS COBOL
programs and COBOL for OS/390 & VM, COBOL for MVS & VM, and
OS/VS COBOL programs.
Calls to dynamic link libraries (DLLs) are an alternative to COBOL dynamic CALL,
| and are well suited to object-oriented COBOL applications, OS/390 UNIX
| programs, and applications that interoperate with C/C++
Under OS/390, linking two load modules together results logically in a single
program with a primary entry point and an alternate entry point, each with its
own name. Each name by which a subprogram is to be dynamically called must be
known to the system. You must specify each such name in linkage editor control
statements as either a NAME or an ALIAS of the load module that contains the
subprogram.
RELATED TASKS
“Making static calls”
“Making dynamic calls”
“Making both static and dynamic calls” on page 465
“Calling nested COBOL programs” on page 468
In the static CALL statement, the COBOL program and all called programs are part
of the same load module. When control is transferred, the called program already
resides in storage, and a branch to it takes place. Subsequent executions of the CALL
statement make the called program available in its last-used state, unless the called
program has the INITIAL attribute. In that case, the called program and each
program directly or indirectly contained within it are placed into its initial state
every time the called program is called within a run unit.
If you specify alternate entry points, a static CALL statement can use any alternate
entry point to enter the called subprogram.
RELATED CONCEPTS
“Performance considerations of static and dynamic calls” on page 464
RELATED TASKS
“Calling to and from object-oriented programs” on page 472
“Making dynamic calls”
“Making both static and dynamic calls” on page 465
RELATED REFERENCES
“NODYNAM restriction (CMS only)” on page 467
“DYNAM” on page 272
“DLL” on page 270
CALL statement (IBM COBOL Language Reference)
In this form of the CALL statement, the called COBOL subprogram is not link-edited
with the main program, but is instead link-edited into a separate load module,
and, at run time, is loaded only when it is required (that is, when called).
Each subprogram that is called with a dynamic CALL statement can be part of a
different load module that is a member of either the system link library or a
The first dynamic call to a subprogram within a run unit obtains a fresh copy of
the subprogram. Subsequent calls to the same subprogram (by either the original
caller or any other subprogram within the same run unit) result in a branch to the
same copy of the subprogram in its last-used state, provided the subprogram does
not possess the INITIAL attribute. Therefore, the reinitialization of either of the
following items is your responsibility:
v GO TO statements that have been altered
v Data items
If the same COBOL program is called under different run units, a separate copy of
working storage is allocated for each run unit.
Canceling a subprogram
When a CANCEL statement is issued for a subprogram, the storage occupied by the
subprogram is freed, and a subsequent call to the subprogram functions as though
it were the first call. You can cancel a subprogram from a program other than the
original caller.
If the called subprogram has more than one entry point, ensure an intervening
CANCEL statement is issued before you specify different entry points in the dynamic
CALL statement.
RELATED CONCEPTS
“Performance considerations of static and dynamic calls”
RELATED TASKS
“Making both static and dynamic calls” on page 465
RELATED REFERENCES
“NODYNAM restriction (CMS only)” on page 467
“DYNAM” on page 272
CALL statement (IBM COBOL Language Reference)
ENTRY statement (IBM COBOL Language Reference)
Language Environment Programming Reference
When a dynamic CALL statement and a static CALL statement to the same
subprogram are issued within one program, a second copy of the subprogram is
loaded into storage. Because this arrangement does not guarantee that the
subprogram will be left in its last-used state, results can be unpredictable.
RELATED REFERENCES
“NODYNAM restriction (CMS only)” on page 467
“DYNAM” on page 272
The following example shows how you would code a dynamic call:
The following example shows a called subprogram that is called by each of the
two preceding calling programs:
IDENTIFICATION DIVISION.
PROGRAM-ID. SUBPROG.
DATA DIVISION.
LINKAGE SECTION.
01 PAYREC. (2)
10 PAY PICTURE S9(5)V99.
10 HOURLY-RATE PICTURE S9V99.
10 HOURS PICTURE S99V9.
77 PAY-CODE PICTURE 9. (6)
PROCEDURE DIVISION USING PAYREC. (1)
. . .
EXIT PROGRAM. (3)
ENTRY “PAYMASTR” USING PAYREC PAY-CODE. (5)
. . .
GOBACK. (7)
(1) Processing begins in the calling program. When the first CALL statement is
executed, control is transferred to the first statement of the PROCEDURE
DIVISION in SUBPROG, which is the called program.
In each of the CALL statements, the operand of the first USING option is
identified as RECORD-1.
(2) When SUBPROG receives control, the values within RECORD-1 are made
available to SUBPROG; however, in SUBPROG they are referred to as PAYREC.
The PICTURE character-strings within PAYREC and PAY-CODE contain the same
number of characters as RECORD-1 and RECORD-2, although the descriptions
are not identical.
(3) When processing within SUBPROG reaches the EXIT PROGRAM statement,
control is returned to the calling program. Processing continues in that
program until the second CALL statement is issued.
(4) In the example of a dynamically called program, because the second CALL
statement refers to another entry point within SUBPROG, a CANCEL statement
is issued before the second CALL statement.
(5) With the second CALL statement in the calling program, control is again
transferred to SUBPROG, but this time processing begins at the statement
following the ENTRY statement in SUBPROG.
(6) The values within RECORD-1 are again made available to PAYREC. In
addition, the value in RECORD-2 is now made available to SUBPROG through
the corresponding USING operand PAY-CODE.
In any given execution of the called program and either of the two calling
programs, if the values within RECORD-1 are changed between the time of the first
CALL and the second, the values passed at the time of the second CALL statement
will be the changed, not the original, values. If you want to use the original values,
they must be saved.
When you use the NODYNAM option, do not mix a dynamic CALL identifier and a static
CALL literal for the same subprogram. Under CMS, certain combinations can cause
unpredictable results; some of these combinations are illustrated below.
Use either the CALL literal or CALL identifier statement to make calls to nested
programs.
You can call a contained program only from its directly containing program, unless
you identify the contained program as COMMON in its PROGRAM-ID clause. In that case,
you can call the common program from any program that is contained (directly or
indirectly) in the same program as the common program. Only contained
programs can be identified as COMMON. Recursive calls are not allowed.
RELATED REFERENCES
“Scope of names” on page 471
CALL statement (IBM COBOL Language Reference)
Nested programs
A COBOL program can “nest,” or contain, other COBOL programs. The nested
programs can themselves contain yet other programs. A nested program can be
directly or indirectly contained in a program.
RELATED TASKS
“Calling nested COBOL programs” on page 468
RELATED REFERENCES
“Scope of names” on page 471
This program Can call these programs And can be called by these programs
A A1, A2, A3 None
A1 A11, A12, A2, A3 A
A11 A111, A12, A2, A3 A1
A111 A12, A2, A3 A11
A12 A2, A3 A1, A11, A111
A2 A3 A, A1, A11, A111, A12, A3
A3 A2 A, A1, A11, A111, A12, A2
Note that:
v A2 cannot call A1 because A1 is not common and is not contained in A2.
v A1 can call A2 because A2 is common.
Scope of names
Names in nested structures are divided into two classes: local and global. The class
determines whether a name is known beyond the scope of the program that
declares it. A specific search sequence locates the declaration of a name after it is
referenced in a program.
Local names: Names (except the program name) are local unless declared to be
otherwise. Local names are visible or accessible only within the program in which
they were declared. They are not visible or accessible to contained and containing
programs.
Global names: A name that is global (indicated using the GLOBAL clause) is visible
and accessible to the program in which it is declared, and to all the programs that
are directly and indirectly contained in that program. Therefore, the contained
programs can share common data and files from the containing program, simply
by referencing the name of the item.
You can declare the same name with the GLOBAL clause more than one time,
providing that each declaration occurs in a different program. Be aware that you
can mask, or hide, a name in a nested structure by having the same name occur in
different programs of the same containing structure. However, this masking could
cause problems during a search for a name declaration.
To make a recursive call, you must code the RECURSIVE clause on the PROGRAM-ID
paragraph of the recursively called program. If you try to recursively call a
COBOL program that does not have the RECURSIVE clause coded on its PROGRAM-ID
paragraph, a condition is signaled. If the condition remains unhanded, the run unit
will end.
RELATED TASKS
“Identifying a program as recursive” on page 6
RELATED REFERENCES
RECURSIVE attribute (IBM COBOL Language Reference)
If you must call a COBOL DLL program from a COBOL non-DLL program, other
methods, which ensure the DLL linkage mechanism is followed, are available.
You can set a procedure-pointer data item only by using format-6 of the SET
statement. The SET statement sets the procedure pointer to refer either to an entry
point in the same load module as your program, to a separate load module, or to
Calling a C function-pointer
Many callable services written in C return function-pointers. Your COBOL program
can call such a C function-pointer by the following technique:
IDENTIFICATION DIVISION.
PROGRAM-ID. DEMO.
ENVIRONMENT DIVISION.
DATA DIVISION.
******
WORKING-STORAGE SECTION.
01 FP USAGE POINTER
01 PP USAGE PROCEDURE-POINTER
******
PROCEDURE DIVISION.
CALL “c-function” RETURNING FP.
SET PP TO FP.
CALL PP.
. . .
RELATED TASKS
“Using procedure-pointers with DLLs” on page 495
RELATED REFERENCES
“DYNAM” on page 272
“NAME” on page 282
CANCEL statement (IBM COBOL Language Reference)
Procedure pointer (IBM COBOL Language Reference)
ENTRY statement (IBM COBOL Language Reference)
RELATED REFERENCES
“RENT” on page 289
“DATA” on page 266
ALL31 run-time option (Language Environment Programming Reference)
HEAP run-time option (Language Environment Programming Reference)
This material describes how you can write programs that can share data with other
programs. For the purposes of this discussion, a subprogram is any program called
by another program.
RELATED TASKS
“Passing data”
“Coding the LINKAGE SECTION” on page 477
“Coding the PROCEDURE DIVISION for passing arguments” on page 478
“Passing return code information” on page 482
“Specifying CALL . . . RETURNING” on page 483
“Sharing data by using the EXTERNAL clause” on page 483
“Sharing files between programs (external files)” on page 483
Passing data
You can choose among three ways of passing data between programs:
BY REFERENCE
The subprogram refers to and processes the data items in storage of the
calling program rather than working on a copy of the data.
BY CONTENT
The calling program passes only the contents of the literal, or identifier.
With a CALL . . . BY CONTENT, the called program cannot change the value
of the literal or identifier in the calling program, even if it modifies the
variable in which it received the literal or identifier.
BY VALUE
The calling program or method passes the value of the literal, or identifier,
not a reference to the sending data item.
The called program or invoked method can change the parameter in the
called program or invoked method. However, because the subprogram or
method has access only to a temporary copy of the sending data item,
these changes do not affect the argument in the calling program.
Determine which of these three data-passing methods to use based on what you
want your program to do with the data:
1. File-names as CALL operands are allowed as an IBM extension to COBOL. Any use of the extension generally
depends on the specific internal implementation of the compiler. Control block field settings might change in
future releases. Any changes made to the control block are the user’s responsibility and not supported by IBM.
Storage for arguments is allocated only in the highest outermost program. For
example, program A calls program B, which calls program C. Data items are
allocated in program A and are described in the LINKAGE sections of programs B
and C, making the one set of data available to all three programs.
If you reference data in a file, the file must be open when the data is referenced.
Code the USING clause of the CALL statement to pass the arguments.
Code the USING clause after the PROCEDURE-DIVISION header to receive the
parameters.
RELATED TASKS
“Specifying CALL . . . RETURNING” on page 483
“Sharing data by using the EXTERNAL clause” on page 483
“Sharing files between programs (external files)” on page 483
RELATED REFERENCES
CALL statement (IBM COBOL Language Reference)
INVOKE statement (IBM COBOL Language Reference)
You will introduce errors if the number of data-names in the identifier list of a called
program is greater than the number of data-names in the identifier list of the calling
program. The compiler does not try to match arguments and parameters.
The following figure shows a data item being passed from one program to another.
RELATED REFERENCES
The procedure division header (IBM COBOL Language Reference)
To make the possibility of mismatched records even smaller, put the level-01 record
into a copy library and copy it in both programs. That is, copy it in the
WORKING-STORAGE SECTION of the calling program and in the LINKAGE SECTION of the
called program.
RELATED TASKS
“Coding the LINKAGE SECTION” on page 477
RELATED TASKS
“Manipulating null-terminated strings” on page 85
RELATED REFERENCES
Null-terminated nonnumeric literals (IBM COBOL Language Reference)
When you pass addresses between programs in a chained list, you can use NULL to
assign the value of an address that is not valid (nonnumeric 0) to pointer items.
You can assign the value NULL to a pointer data item in two ways:
v Use a VALUE IS NULL clause in its data definition.
v Use NULL as the sending field in a SET statement.
In the case of a chained list in which the pointer data item in the last record
contains a null value, the code to check for the end of the list is as follows:
IF PTR-NEXT-REC = NULL
. . .
(logic for end of chain)
If the program has not reached the end of the list, the program can process the
record and move on to the next record.
RELATED TASKS
“Coding the LINKAGE SECTION” on page 477
“Coding the PROCEDURE DIVISION for passing arguments” on page 478
RELATED REFERENCES
SET statement (IBM COBOL Language Reference)
The first item in each record points to the next record, except for the last record.
The first item in the last record contains a null value instead of an address, to
indicate that it is the last record.
The high-level logic of an application that processes these records might look as
follows:
OBTAIN ADDRESS OF FIRST RECORD IN CHAINED LIST FROM ROUTINE
CHECK FOR END OF THE CHAINED LIST
DO UNTIL END OF THE CHAINED LIST
PROCESS RECORD
GO ON TO THE NEXT RECORD
END
The following code contains an outline of the calling program, LISTS, used in this
example of processing a chained list.
IDENTIFICATION DIVISION.
PROGRAM-ID. LISTS.
ENVIRONMENT DIVISION.
DATA DIVISION.
******
WORKING-STORAGE SECTION.
77 PTR-FIRST POINTER VALUE IS NULL. (1)
77 DEPT-TOTAL PIC 9(4) VALUE IS 0.
******
LINKAGE SECTION.
01 SALARY-REC.
02 PTR-NEXT-REC POINTER. (2)
02 NAME PIC X(20).
02 DEPT PIC 9(4).
02 SALARY PIC 9(6).
01 DEPT-X PIC 9(4).
IF DEPT = DEPT-X
THEN ADD SALARY TO DEPT-TOTAL
ELSE CONTINUE
END-IF
SET ADDRESS OF SALARY-REC TO PTR-NEXT-REC (6)
END-PERFORM
******
DISPLAY DEPT-TOTAL
GOBACK.
(1) PTR-FIRST is defined as a pointer data item with an initial value of NULL.
On a successful return from the call to CHAIN-ANCH, PTR-FIRST contains the
address of the first record in the chained list. If something goes amiss with
the call, however, and PTR-FIRST never receives the value of the address of
the first record in the chain, a null value remains in PTR-FIRST and,
according to the logic of the program, the records will not be processed.
(2) The LINKAGE SECTION of the calling program contains the description of the
records in the chained list. It also contains the description of the
department code that is passed, using the USING clause of the CALL
statement.
(3) To obtain the address of the first SALARY-REC record area, the LISTS
program calls the program CHAIN-ANCH:
(4) The SET statement bases the record description SALARY-REC on the address
contained in PTR-FIRST.
(5) The chained list in this example is set up so that the last record contains an
address that is not valid. This check for the end of the chained list is
accomplished with a DO WHILE structure where the value NULL is assigned
to the pointer data item in the last record.
(6) The address of the record in the LINKAGE-SECTION is set equal to the
address of the next record by means of the pointer data item sent as the
first field in SALARY-REC. The record-processing routine repeats, processing
the next record in the chained list.
To increment addresses received from another program, you could set up the
LINKAGE SECTION and PROCEDURE DIVISION like this:
LINKAGE SECTION.
01 RECORD-A.
02 HEADER PIC X(12).
02 REAL-SALARY-REC PIC X(30).
. . .
01 SALARY-REC.
02 PTR-NEXT-REC POINTER.
RELATED TASKS
“Using pointers to process a chained list” on page 479
You can also use the RETURNING phrase on the PROCEDURE DIVISION header in your
method to return information to an invoking program or method. If you use
PROCEDURE DIVISION . . . RETURNING with CALL . . . RETURNING, the RETURN-CODE
register will not be set.
You might need to think about this handling of the RETURN-CODE when control is
returned to a COBOL program from a non-COBOL program. If the non-COBOL
program does not use register 15 to pass back the return code, then the
RETURN-CODE special register of the COBOL program might be updated with a
value that is not valid. Unless you set this special register to a meaningful value
before your COBOL for OS/390 & VM program returns to the operating system, a
return code that is not valid will be passed back to the system.
For equivalent function between COBOL and C programs, have your COBOL
program call the C program with the RETURNING option. If the C program (function)
correctly declares a function value, the RETURNING value of the calling COBOL
program will be set.
You cannot set the RETURN-CODE special register by using the INVOKE statement.
When the called program successfully returns to its caller, the value in dataname2 is
stored into the identifier that you specified in the RETURNING phrase of the CALL
statement:
You must define dataname2 in the DATA DIVISION of the calling COBOL program.
The data type of the return value that is declared in the target function must be
identical to the data type of dataname2.
Program B could access that data item by having the identical data description in
its WORKING-STORAGE SECTION.
Remember, any program that has access to an EXTERNAL data item can change its
value. Do not use this clause for data items that you need to protect.
RELATED REFERENCES
EXTERNAL clause (IBM COBOL Language Reference)
Name Function
ef1 The main program, which calls all the subprograms and then verifies the
contents of a record area
ef1openo Opens the external file for output and checks the file status code
ef1write Writes a record to the external file and checks the file status code
ef1openi Opens the external file for input and checks the file status code
ef1read Reads a record from the external file and checks the file status code
ef1close Closes the external file and checks the file status code
Each program in the example declares a data item with the EXTERNAL clause in its
WORKING-STORAGE SECTION. This item is used for checking file status codes and is
also placed using the COPY statement.
RELATED CONCEPTS
Dynamic link libraries (DLLs)
RELATED TASKS
“Using CALL identifier with DLLs” on page 493
“Using DLL linkage and dynamic calls together” on page 494
“Using COBOL DLLs with C/C++ programs” on page 498
“Using DLLs in OO COBOL applications” on page 498
“Compiling programs to create DLLs” on page 490
“Linking DLLs” on page 491
“Using procedure pointers” on page 472
RELATED TASKS
Building class libraries (OS/390 SOMobjects Programmer’s Guide)
RELATED REFERENCES
“PGMNAME” on page 287
Binder support for DLLs (OS/390 DFSMS: Program Management)
In an application with DLL support, use the following compiler options depending
on where the programs or classes are:
If a DLL load module includes some programs or classes that are used only from
within the DLL module, you can hide these routines inside the DLL by compiling
them with NOEXPORTALL.
RELATED TASKS
“Linking DLLs” on page 491
RELATED REFERENCES
“DLL” on page 270
“EXPORTALL” on page 272
“RENT” on page 289
Linking DLLs
You can link your DLL-enabled object modules into separate DLL load modules, or
you can link them together statically. You can decide whether to package the
application as one module or as several DLL modules at link time.
| Use of the DLL support in the DFSMS binder is recommended for linking DLL
| applications. The DFSMS binder can now directly receive the output of the COBOL
| compilers, thus eliminating the prelink step. However, you must use the prelinker
| if your DLL must reside in a PDS load library or you will deploy the DLL on a
| CICS system at a level lower than CICS Transaction Server 1.3.
| A binder-based DLL must reside in a PDSE or in an HFS file, rather than in a PDS.
| When linking a DLL application by using the DFSMS binder, use the following
| binder options:
You must specify a SYSDEFSD DD statement to indicate the data set where the binder
should create a DLL definition side file. This side file contains IMPORT control
statements for each symbol exported by a DLL. The binder SYSLIN input (the
binding code that references the DLL code) must include the DLL definition side
files for the DLLs that are to be referenced from the module being linked.
If there are programs in the module that you do not want to make available with
DLL linkage, you can edit the definition side file to remove these programs.
| If a DLL must reside in a PDS load library or if the output will be deployed on a
| CICS system at a level lower than CICS Transaction Server 1.3, you must prelink
| the application by using the Language Environment prelinker before standard
| linkage editing.
RELATED TASKS
“Chapter 30. Creating a DLL or a DLL application” on page 489
“Compiling programs to create DLLs” on page 490
“Prelinking certain DLLs” on page 492
OS/390 DFSMS: Program Management
RELATED TASKS
“Compiling programs to create DLLs” on page 490
“Linking DLLs” on page 491
| For the contents of the identifier or for the literal in the CALL statement, use the
| name of either of the following programs:
| v A nested program in the same compilation unit as is eligible to be called from
| the program containing the CALL identifier statement.
| v A program in a separately bound DLL module. The target program name must
| be exported from the DLL, and the DLL module name must match the exported
| name of the target program.
| In the nonnested case, the run-time environment interprets the program name in
| the identifier according to the setting of the PGMNAME compiler option of the program
| containing the CALL statement, and interprets the program name that is exported
| from the target DLL according to the setting of the PGMNAME option used when the
| target program was compiled.
| The search for the target DLL in the hierarchical file system (HFS) is case sensitive.
| If the target DLL is a PDS or PDSE member, then the DLL member name must be
| eight characters or less. For the purpose of the search for the DLL as a PDS or
| PDSE member, the run time automatically converts the name to uppercase.
| If the run-time environment cannot resolve the CALL statement in either of these
| cases, control is transferred to the ON EXCEPTION or ON OVERFLOW phrase of the CALL
| statement. If the CALL statement does not specify one of these phrases in this
| situation, Language Environment raises a severity-3 condition.
RELATED REFERENCES
“DLL” on page 270
“PGMNAME” on page 287
CALL statement (IBM COBOL Language Reference)
“Search order for DLLs in HFS”
| If the POSIX run-time option is set to ON, the search order is as follows:
| 1. The run-time environment looks for the DLL in the HFS. If the LIBPATH
| environment variable is set, the run time searches each directory listed.
| Otherwise, it searches just the current directory. The search for the DLL in the
| HFS is case sensitive.
| 2. If the run-time environment does not find the DLL in the HFS, it tries to load
| the DLL from the MVS load library search order of the caller. In this case, the
| DLL name must be eight characters or less. The run time automatically
| converts the DLL name to uppercase for this search.
| If the POSIX run-time option is set to OFF, the search order is reversed:
| 1. The run-time environment tries to load the DLL from the search order for the
| load library of the caller.
| 2. If the run-time environment cannot load the DLL from this load library, it tries
| to load the DLL from the HFS.
RELATED TASKS
“Using CALL identifier with DLLs” on page 493
RELATED REFERENCES
POSIX (Language Environment Programming Reference)
| However, some applications require more flexibility. In these cases, you can use
| both DLL linkage and COBOL dynamic call linkage within a Language
| Environment enclave if the programs are compiled as follows:
| If a program contains a CALL statement for a separately compiled program and you
| compile one program with the DLL compiler option and the other program with
| NODLL, then the CALL is supported only if you bind the two programs together in
| the same module.
The following diagram shows several separately bound modules that mix dynamic
calls and DLL linkage:
You cannot cancel programs that are called using DLL linkage.
All components of a DLL application must have the same AMODE. The automatic
AMODE switching normally provided by COBOL dynamic calls is not available for
DLL linkages.
| If you compile with the NODYNAM and DLL options and entryname is an identifier, the
| identifier value must refer to the entry point name that is exported from a DLL
| module. The DLL module name must match the name of the exported entry point.
| The following are further considerations in this case:
| v The program name that is contained in the identifier is interpreted according to
| the setting of the PGMNAME(COMPAT|LONGUPPER|LONGMIXED) compiler option of the
| program containing the CALL statement.
| v The program name that is exported from the target DLL is interpreted according
| to the setting of the PGMNAME option used when compiling the target program.
| v The search for the target DLL in the HFS is case sensitive.
RELATED CONCEPTS
“Dynamic link libraries (DLLs)” on page 489
RELATED TASKS
“Using CALL identifier with DLLs” on page 493
“Using procedure pointers” on page 472
“Compiling programs to create DLLs” on page 490
“Linking DLLs” on page 491
RELATED REFERENCES
“DLL” on page 270
“EXPORTALL” on page 272
IF DLL-NOT-LOADED
THEN
* Move the names in. They must be null terminated.
MOVE Z'OOC05R' TO DLL-LOADMOD-NAME
MOVE Z'ooc05r' TO DLL-PROGRAM-NAME
GOBACK.
#include <stdio.h>
#include <dll.h>
#pragma linkage (A1CCDLGT,COBOL)
You can pass a C/C++ DLL function-pointer to COBOL and use it within COBOL.
However, the COBOL application must receive the C/C++ function pointer as a
pointer data item rather than as a COBOL procedure pointer, because C/C++
function pointers are 4 bytes long and COBOL procedure pointers are 8 bytes long.
RELATED TASKS
“Compiling programs to create DLLs” on page 490
“Linking DLLs” on page 491
RELATED REFERENCES
“DLL” on page 270
“EXPORTALL” on page 272
“RENT” on page 289
EXTERNAL (IBM COBOL Language Reference)
With OS/390 Release 3 SOMobjects (or later releases), access to the SOMobjects
facilities must use the SOMobjects DLLs. You cannot link the SOM object modules
into the application load module.
RELATED TASKS
“Compiling programs to create DLLs” on page 490
“Linking DLLs” on page 491
RELATED REFERENCES
“DLL” on page 270
“EXPORTALL” on page 272
“RENT” on page 289
Because the checkpoint/restart functions cause a lot of extra processing, use them
only when you anticipate interruptions caused by machine malfunctions, input or
output errors, or intentional operator intervention.
OS/390 only: The checkpoint/restart functions are not available under VM/CMS.
The checkpoint routine starts from the COBOL load module containing your
program. While your program is running, the checkpoint routine creates records at
points you have designated using the COBOL RERUN clause. A checkpoint record
contains a snapshot of the information in the registers and main storage when the
program reached the checkpoint.
The restart routine restarts an interrupted program. You can perform a restart at
any time after the program was interrupted: either immediately (automatic restart),
or later (deferred restart).
RELATED TASKS
“Setting checkpoints”
“Restarting programs” on page 504
“Resubmitting jobs for restart” on page 507
OS/390 DFSMS: Checkpoint/Restart
RELATED REFERENCES
“DD statements for defining checkpoint data sets” on page 503
“Messages generated during checkpoint” on page 504
“Formats for requesting deferred restart” on page 506
Setting checkpoints
To set checkpoints, use job control statements, and use the RERUN clause in the
ENVIRONMENT DIVISION. Associate each RERUN clause with a particular COBOL file.
You can write checkpoint records from several COBOL files onto one checkpoint
data set, but you must use a separate data set exclusively for checkpoint records.
You cannot embed checkpoint records in one of your program data sets.
A checkpoint data set must have sequential organization. You cannot write
checkpoints on VSAM data sets or on data sets allocated to extended-format
QSAM data sets. Also, a checkpoint cannot be taken if any program in the run unit
has an extended-format QSAM data set open.
You must use the multiple checkpoint method for complete compliance to the
COBOL 85 Standard.
Designing checkpoints
Design your checkpoints at critical points in your program so that data can be
easily reconstructed. Do not change the contents of files between the time of a
checkpoint and the time of the restart.
In a program using disk files, design the program so that you can identify
previously processed records. For example, consider a disk file containing loan
records that are periodically updated for interest due. If a checkpoint is taken,
records are updated, and then the program is interrupted, you would want to test
that the records updated after the last checkpoint are not updated again when the
program is restarted. To do this, set up a date field in each record, and update the
field each time the record is processed. Then, after the restart, test the field to
determine whether the record was already processed.
For efficient repositioning of a print file, take checkpoints on the file only after
printing the last line of a page.
RELATED TASKS
“Using checkpoint/restart with DFSORT under OS/390” on page 186
For tape:
//ddname DD DSNAME=data-set-name,
// [VOLUME=SER=volser,]UNIT=device-type,
// DISP=({NEW|MOD},PASS)
checkid is the identification name of the checkpoint taken. The control program
assigns checkid as an eight-character string. The first character is the letter C,
followed by a decimal number indicating the checkpoint. For example, the
following message indicates the fourth checkpoint taken in the job step:
checkid C0000004
Restarting programs
The system restart routine does the following:
v Retrieves the information recorded in a checkpoint record
v Restores the contents of main storage and all registers
v Restarts the program
You can begin the restart routine in one of two ways:
v Automatically, at the time an interruption stopped the program
v At a later time, as a deferred restart
The RD parameter of the job control language determines the type of restart. You
can use the RD parameter on either the JOB or the EXEC statement. If coded on the
JOB statement, the parameter overrides any RD parameters on the EXEC statement.
Data sets that have the SYSOUT parameter coded on their DD statements are handled
in various ways depending on the type of restart.
Whenever automatic restart is to occur, the system repositions all devices except
unit-record devices.
When a deferred restart has been successfully completed, the system displays a
message on the console stating that the job has been restarted. Control is then
given to your program.
If you want deferred restart, code the RD parameter as RD=NR. This form of the
parameter suppresses automatic restart, but allows a checkpoint record to be
written provided that a RERUN clause has been coded.
Request a deferred restart by using the RESTART parameter on the JOB card and a
SYSCHK DD statement to identify the checkpoint data set. If a SYSCHK DD statement is
present in a job and the JOB statement does not contain the RESTART parameter, the
SYSCHK DD statement is ignored. If a RESTART parameter without the CHECKID
subparameter is included in a job, a SYSCHK DD statement must not appear before
the first EXEC statement for the job.
RELATED REFERENCES
“Formats for requesting deferred restart”
checkid
Identifies the checkpoint where restart is to occur.
SYSCHK The ddname used to identify a checkpoint data set to the control program.
The SYSCHK DD statement must immediately precede the first EXEC
statement of the resubmitted job, and must follow any JOBLIB statement.
data-set-name
Identifies the checkpoint data set. It must be the same name that
was used when the checkpoint was taken.
device-type and volser
Identify the device type and the serial number of the volume
containing the checkpoint data set.
RELATED CONCEPTS
“Millennium language extensions (MLE)” on page 510
RELATED TASKS
“Resolving date-related logic problems” on page 511
“Using year-first, year-only, and year-last date fields” on page 516
“Manipulating literals as dates” on page 519
“Setting triggers and limits” on page 521
“Sorting and merging by date” on page 523
“Performing arithmetic on date fields” on page 525
“Controlling date processing explicitly” on page 527
“Analyzing and avoiding date-related diagnostic messages” on page 528
“Avoiding problems in processing dates” on page 530
RELATED REFERENCES
DATE FORMAT clause (IBM COBOL Language Reference)
“DATEPROC” on page 267
“YEARWINDOW” on page 303
RELATED CONCEPTS
“Principles and objectives of these extensions”
RELATED REFERENCES
“DATEPROC” on page 267
“YEARWINDOW” on page 303
You can use the millennium language extensions with each approach to achieve a
solution, but each has advantages and disadvantages, as shown below.
RELATED TASKS
“Using a century window”
“Using internal bridging” on page 513
“Moving to full field expansion” on page 514
To implement this century window, you use the DATE FORMAT clause to identify the
date fields in your program and use the YEARWINDOW compiler option to define the
century window as either a fixed window or a sliding window:
v For a fixed window, specify a four-digit year between 1900 and 1999 as the
YEARWINDOW option value. For example, YEARWINDOW(1950) defines a fixed window
of 1950-2049.
v For a sliding window, specify a negative integer from -1 through -99 as the
YEARWINDOW option value. For example, YEARWINDOW(-48) defines a sliding
window that starts 48 years before the year that the program is running. So if
In this example, there are no changes to the PROCEDURE DIVISION. The addition of
the DATE FORMAT clause on the two date fields means that the compiler recognizes
them as windowed date fields, and therefore applies the century window when
processing the IF statement. For example, if Date-Due-Back contains 000102
(January 2, 2000) and Date-Returned contains 991231 (December 31, 1999),
Date-Returned is less than (earlier than) Date-Due-Back, so the program does not
perform the Fine-Member paragraph.
When you use this technique, your changes to the program logic are minimal. You
simply add statements to expand and contract the dates, and change the
statements that refer to dates to use the four-digit-year date fields in
WORKING-STORAGE instead of the two-digit-year fields in the records.
Because you are converting the dates back to two-digit years for output, you
should allow for the possibility that the year is outside the century window. For
example, if a date field contains the year 2020, but the century window is
1920-2019, then the date is outside the window, and simply moving it to a
two-digit-year field will be incorrect. To protect against this problem, you can use a
RELATED TASKS
“Using a century window” on page 512
“Performing arithmetic on date fields” on page 525
“Moving to full field expansion”
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-FILE
ASSIGN TO INFILE
FILE STATUS IS INPUT-FILE-STATUS.
SELECT OUTPUT-FILE
ASSIGN TO OUTFILE
FILE STATUS IS OUTPUT-FILE-STATUS.
DATA DIVISION.
FILE SECTION.
FD INPUT-FILE
RECORDING MODE IS F.
01 INPUT-RECORD.
03 CUST-NAME.
05 FIRST-NAME PIC X(10).
05 LAST-NAME PIC X(15).
03 ACCOUNT-NUM PIC 9(8).
03 DUE-DATE PIC X(6) DATE FORMAT YYXXXX. (1)
03 REMINDER-DATE PIC X(6) DATE FORMAT YYXXXX.
03 DUE-AMOUNT PIC S9(5)V99 COMP-3.
FD OUTPUT-FILE
RECORDING MODE IS F.
01 OUTPUT-RECORD.
03 CUST-NAME.
05 FIRST-NAME PIC X(10).
05 LAST-NAME PIC X(15).
03 ACCOUNT-NUM PIC 9(8).
03 DUE-DATE PIC X(8) DATE FORMAT YYYYXXXX. (2)
03 REMINDER-DATE PIC X(8) DATE FORMAT YYYYXXXX.
03 DUE-AMOUNT PIC S9(5)V99 COMP-3.
WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
GO TO READ-RECORD.
CLOSE-FILES.
CLOSE INPUT-FILE.
CLOSE OUTPUT-FILE.
EXIT PROGRAM.
Notes:
(1) The fields DUE-DATE and REMINDER-DATE in the input record are both
Gregorian dates with two-digit-year components. They are defined with a
DATE FORMAT clause in this program so that the compiler will recognize
them as windowed date fields.
(2) The output record contains the same two fields in expanded date format.
They are defined with a DATE FORMAT clause so that the compiler will treat
them as four-digit-year date fields.
(3) The MOVE CORRESPONDING statement moves each item in INPUT-RECORD
individually to its matching item in OUTPUT-RECORD. When the two
windowed date fields are moved to the corresponding expanded date
fields, the compiler will expand the year values using the current century
window.
A year-last date field is a date field whose DATE FORMAT clause specifies one or more
Xs preceding the YY or YYYY. Such date formats are commonly used to display
dates, but are less useful computationally, because the year, which is the most
significant part of the date, is in the least significant position of the date
representation.
If you need more general date-processing capability for year-last dates, you should
isolate and operate on the year part of the date.
RELATED CONCEPTS
“Compatible dates”
RELATED TASKS
“Sorting and merging by date” on page 523
“Using other date formats” on page 518
Compatible dates
The meaning of the term compatible dates depends on the COBOL division in which
the usage occurs, as follows:
v The DATA DIVISION usage deals with the declaration of date fields, and the rules
governing COBOL language elements such as subordinate data items and the
REDEFINES clause. In the following example, Review-Date and Review-Year are
compatible because Review-Year can be declared as a subordinate data item to
Review-Date:
01 Review-Record.
03 Review-Date Date Format yyxxxx.
05 Review-Year Pic XX Date Format yy.
05 Review-M-D Pic XXXX.
v The PROCEDURE DIVISION usage deals with how date fields can be used together
in operations such as comparisons, moves, and arithmetic expressions. For
year-first and year-only date fields, to be considered compatible, date fields must
have the same number of nonyear characters. For example, a field with DATE
FORMAT YYXXXX is compatible with another field that has the same date format,
and with a YYYYXXXX field, but not with a YYXXX field.
Year-last date fields must have identical DATE FORMAT clauses. In particular,
operations between windowed date fields and expanded year-last date fields are
not allowed. For example, you can move a date field with a date format of
XXXXYY to another XXXXYY date field, but not to a date field with a format of
XXXXYYYY.
You can perform operations on date fields, or on a combination of date fields and
nondates, provided that the date fields in the operation are compatible. For
example, assume the following definitions:
01 Date-Gregorian-Win Pic 9(6) Packed-Decimal Date Format yyxxxx.
01 Date-Julian-Win Pic 9(5) Packed-Decimal Date Format yyxxx.
01 Date-Gregorian-Exp Pic 9(8) Packed-Decimal Date Format yyyyxxxx.
The following statement is accepted because the number of nonyear digits is the
same for both fields:
If Date-Gregorian-Win Less than Date-Gregorian-Exp . . .
In this case the century window is applied to the windowed date field
(Date-Gregorian-Win) to ensure that the comparison is meaningful.
When a nondate is used in conjunction with a date field, the nondate either is
assumed to be compatible with the date field or is treated as a simple numeric
value.
If there are date fields in your application that do not fit these criteria, you might
have to make some code changes to define just the year part of the date as a date
field with the DATE FORMAT clause. Some examples of these types of date formats
are:
v A seven-character field consisting of a two-digit year, three characters containing
an abbreviation of the month and two digits for the day of the month. This
format is not supported because date fields can have only one through four
nonyear characters.
v A Gregorian date of the form DDMMYY. Automatic windowing is not provided
because the year component is not the first part of the date. Year-last dates such
as these are fully supported as windowed keys in SORT or MERGE statements, and
are also supported in a limited number of other COBOL operations.
If you need to use date windowing in cases like these, you will need to add some
code to isolate the year portion of the date.
Because the year is not the first part of these date fields, the DATE FORMAT clause
cannot be applied without some code to isolate the year component. In the next
The literal 051220 is treated as a nondate, and therefore it is windowed against the
assumed century window of 1900-1999 to represent December 20, 1905. But where
the same literal is specified in the VALUE clause of an 88-level condition-name, the
literal becomes part of the data item to which it is attached. Because this data item
is a windowed date field, the century window is applied whenever it is referenced.
You can also use the DATEVAL intrinsic function in a comparison expression to
convert a literal to a date field, and the output from the intrinsic function will then
be treated as either a windowed date field or an expanded date field to ensure a
consistent comparison. For example, using the above definitions, both of these
conditions evaluate to true:
If Date-Due = Function DATEVAL (051220 “YYXXXX”)
If Date-Due = Function DATEVAL (20051220 “YYYYXXXX”)
With a level-88 condition-name, you can specify the THRU option on the VALUE
clause, but you must specify a fixed century window on the YEARWINDOW compiler
option rather than a sliding window. For example:
05 Year-Field Pic 99 Date Format yy.
88 In-Range Value 98 Thru 06.
With this form, the windowed value of the second item must be greater than the
windowed value of the first item. However, the compiler can verify this difference
only if the YEARWINDOW compiler option specifies a fixed century window (for
example, YEARWINDOW(1940) rather than YEARWINDOW(-60).
The windowed order requirement does not apply to year-last date fields. If you
specify a condition-name VALUE clause with the THROUGH phrase for a year-last date
field, the two literals must follow normal COBOL rules. That is, the first literal
must be less than the second literal.
RELATED TASKS
“Controlling date processing explicitly” on page 527
The assumed century window is 1900-1999, which is typically not the same as the
century window for the compilation unit.
In many cases, particularly for literal nondates, this assumed century window is
the correct choice. In the following construct, the literal should retain its original
meaning of January 1, 1972, and not change to 2072 if the century window is, for
example, 1975-2074:
01 Manufacturing-Record.
03 Makers-Date Pic X(6) Date Format yyxxxx.
. . .
If Makers-Date Greater than “720101” . . .
Even if the assumption is correct, it is better to make the year explicit and
eliminate the warning-level diagnostic message (which results from applying the
assumed century window) by using the DATEVAL intrinsic function:
If Makers-Date Greater than
Function Dateval(“19720101” “YYYYXXXX”) . . .
In some cases, the assumption might not be correct. For the following example,
assume that Project-Controls is in a COPY member that is used by other
applications that have not yet been upgraded for year 2000 processing, and
therefore Date-Target cannot have a DATE FORMAT clause:
01 Project-Controls.
03 Date-Target Pic 9(6).
. . .
01 Progress-Record.
03 Date-Complete Pic 9(6) Date Format yyxxxx.
. . .
If Date-Complete Less than Date-Target . . .
In the example, the following three conditions need to be true to make the
Date-Complete earlier than (less than) Date-Target:
v The century window is 1910-2009.
v Date-Complete is 991202 (Gregorian date: December 2, 1999).
v Date-Target is 000115 (Gregorian date: January 15, 2000).
However, because Date-Target does not have a DATE FORMAT clause, it is a nondate.
Therefore, the century window applied to it is the assumed century window of
1900-1999, and it is processed as January 15, 1900. So Date-Complete will be greater
than Date-Target, which is not the desired result.
RELATED TASKS
“Controlling date processing explicitly” on page 527
Treatment of nondates
The simplest kind of nondate is a literal value. The following items are also
nondates:
v A data item whose data description does not include a DATE FORMAT clause.
v The results (intermediate or final) of some arithmetic expressions. For example,
the difference of two date fields is a nondate, whereas the sum of a date field
and a nondate is a date field.
v The output from the UNDATE intrinsic function.
When you use a nondate in conjunction with a date field, the compiler interprets
the nondate either as a date whose format is compatible with the date field or as a
simple numeric value. This interpretation depends on the context in which the date
field and nondate are used, as follows:
v Comparison
When a date field is compared with a nondate, the nondate is considered to be
compatible with the date field in the number of year and nonyear characters. In
the following example, the nondate literal 971231 is compared with a windowed
date field:
01 Date-1 Pic 9(6) Date Format yyxxxx.
. . .
If Date-1 Greater than 971231 . . .
The nondate literal 971231 is treated as if it had the same DATE FORMAT as Date-1,
but with a base year of 1900.
v Arithmetic operations
In all supported arithmetic operations, nondate fields are treated as simple
numeric values. In the following example, the numeric value 10000 is added to
the Gregorian date in Date-2, effectively adding one year to the date:
01 Date-2 Pic 9(6) Date Format yyxxxx.
. . .
Add 10000 to Date-2.
v MOVE statement
Moving a date field to a nondate is not supported. However, you can use the
UNDATE intrinsic function to do this.
When you move a nondate to a date field, the sending field is assumed to be
compatible with the receiving field in the number of year and nonyear
characters. For example, when you move a nondate to a windowed date field,
the nondate field is assumed to contain a compatible date with a two-digit year.
The difference between a trigger and a limit is not in the particular value, but in
the way it is used. You can use any of the special values as either a trigger or a
limit.
When used as triggers, special values can indicate a specific condition such as
“date not initialized” or “account past due.” When used as limits, special values
are intended to act as dates earlier or later than any valid date. LOW-VALUE, SPACE
and zeros are lower limits; HIGH-VALUE and nines are upper limits.
You activate trigger and limit support by specifying the TRIG suboption of the
DATEPROC compiler option. If the DATEPROC(TRIG) compiler option is in effect,
automatic expansion of windowed date fields (before their use as operands in
comparisons, arithmetic, and so on) is sensitive to these special values.
When an actual or assumed windowed date field contains a trigger, the compiler
expands the trigger as if the trigger value were propagated to the century part of
the expanded date result, rather than inferring 19 or 20 as the century value as in
normal windowing. In this way, your application can test for special values or use
them as upper or lower date limits. Specifying DATEPROC(TRIG) also enables SORT
and MERGE statement support of the DFSORT special indicators, which correspond
to triggers and limits.
RELATED TASKS
“Using sign conditions” on page 523
However, if you are compiling with the NOTRIG suboption of the DATEPROC compiler
option, this comparison is not valid because the literal value Zero is a nondate, and
is therefore windowed against the assumed century window to give a value of
1900000.
With a sign condition, Order-Date is treated as a nondate, and the century window
is not considered.
This approach applies only if the operand in the sign condition is a simple
identifier rather than an arithmetic expression. If an expression is specified, the
expression is evaluated first, with the century window being applied where
appropriate. The sign condition is then compared with the results of the
expression.
You could use the UNDATE intrinsic function instead or the TRIG suboption of the
DATEPROC compiler option to achieve the same result.
RELATED CONCEPTS
“Treatment of nondates” on page 521
RELATED TASKS
“Setting triggers and limits” on page 521
“Controlling date processing explicitly” on page 527
If your sort product also supports the date field identifiers Y2T, Y2U, Y2W, Y2X, and
Y2Y, you can use the TRIG suboption of the DATEPROC compiler option. (Support for
these date fields identifiers was added to DFSORT through APAR PQ19684.)
The special indicators that DFSORT recognizes match exactly those supported by
COBOL: LOW-VALUE, HIGH-VALUE, and SPACE for alphanumeric date or year fields,
and all zeros and all nines for numeric and alphanumeric date fields with at least
one nonyear digit.
RELATED TASKS
DFSORT Application Programming Guide (for information on DFSORT and Y2PAST)
RELATED REFERENCES
“DATEPROC” on page 267
“YEARWINDOW” on page 303
01 Transaction-Record.
05 Trans-Account PIC 9(8).
05 Trans-Type PIC X.
05 Trans-Date PIC 9(5) Date Format yyxxx.
05 Trans-Time PIC 9(6).
05 Trans-Amount PIC 9(7)V99.
. . .
Sort Transaction-File
On Ascending Key Trans-Account
Trans-Date
Trans-Time
Using Input-File
Giving Sorted-File.
COBOL passes the relevant information to DFSORT for it to perform the sort. In
addition to the information COBOL always passes to DFSORT, COBOL also passes
the following information:
v Century window as the Y2PAST sort option
v Windowed year field and date format of Trans-Date.
DFSORT uses this information to perform the sort.
Date semantics are provided for the year parts of date fields but not for the
nonyear parts. For example, adding 1 to a windowed Gregorian date field that
contains the value 980831 gives a result of 980832, not 980901.
If the century window is 1910-2009, and the value of Last-Review-Year is 98, then
the computation proceeds as if Last-Review-Year is first incremented by 1900 to
give 1998. Then the ADD operation is performed, giving a result of 2008. This result
is stored in Next-Review-Year as 08.
This result falls outside the range of the century window. If the result is stored in
Next-Review-Year, it will be incorrect because later references to Next-Review-Year
will interpret it as 1918. In this case, the result of the operation depends on
whether the ON SIZE ERROR phrase is specified on the ADD statement:
v If SIZE ERROR is specified, the receiving field is not changed, and the SIZE ERROR
imperative statement is executed.
v If SIZE ERROR is not specified, the result is stored in the receiving field with the
left-hand digits truncated.
SIZE ERROR processing for windowed date receivers recognizes any year value that
falls outside the century window. That is, a year value less than the starting year of
the century window raises the SIZE ERROR condition, as does a year value greater
than the ending year of the century window.
However, the addition of two date fields is not permitted. To resolve these date
fields, you should use parentheses to isolate the parts of the arithmetic expression
that are allowed. For example:
Compute End-Year-2 = Start-Year-2 + (End-Year-1 - Start-Year-1).
The subtraction of one date field from another is permitted and gives a nondate
result. This nondate result is then added to the date field End-Year-1, giving a date
field result that is stored in End-Year-2.
RELATED TASKS
“Using internal bridging” on page 513
Using DATEVAL
You can use the DATEVAL intrinsic function to convert a nondate to a date field, so
that COBOL will apply the relevant date processing to the field. The first argument
in the function is the nondate to be converted, and the second argument specifies
the date format. The second argument is a literal string with a specification similar
to that of the date pattern in the DATE FORMAT clause.
In most cases, the compiler makes the correct assumption about the interpretation
of a nondate, but accompanies this assumption with a warning-level diagnostic
message. This message typically happens when a windowed date is compared
with a literal:
03 When-Made Pic x(6) Date Format yyxxxx.
. . .
If When-Made = “850701” Perform Warranty-Check.
Using UNDATE
The UNDATE intrinsic function converts a date field to a nondate, so that it can be
referenced without any date processing.
Attention: Avoid using UNDATE except as a last resort, because the compiler will
lose the flow of date fields in your program. This problem could result in date
comparisons not being windowed properly. Use more DATE FORMAT clauses instead
of function UNDATE for MOVE and COMPUTE.
Example: DATEVAL
Assume that a program contains a field Date-Copied and that this field is
referenced many times in the program, but that most of these references move it
between records or reformat it for printing. Only one reference relies on it to
contain a date, for comparison with another date.
In this case, it is better to leave the field as a nondate, and use the DATEVAL intrinsic
function in the comparison statement. For example:
03 Date-Distributed Pic 9(6) Date Format yyxxxx.
03 Date-Copied Pic 9(6).
. . .
If FUNCTION DATEVAL(Date-Copied “YYXXXX”) Less than
Date-Distributed . . .
In this example, the DATEVAL intrinsic function converts Date-Copied to a date field
so that the comparison will be meaningful.
RELATED REFERENCES
DATEVAL (IBM COBOL Language Reference)
Example: UNDATE
In the following example, the field Invoice-Date in Invoice-Record is a windowed
Julian date. In some records, it contains a value of 00999 to indicate that this is not
a true invoice record, but a record containing file control information.
Invoice-Date has been given a DATE FORMAT clause because most of its references in
the program are date-specific. However, in the instance where it is checked for the
existence of a control record, the value of 00 in the year component will lead to
some confusion. A year of 00 in Invoice-Date will represent a year of either 1900
or 2000, depending on the century window. This is compared with a nondate (the
literal 00999 in the example), which will always be windowed against the assumed
century window and will therefore always represent the year 1900.
To ensure a consistent comparison, you should use the UNDATE intrinsic function to
convert Invoice-Date to a nondate. Therefore, if the IF statement is not comparing
date fields, it does not need to apply windowing. For example:
01 Invoice-Record.
03 Invoice-Date Pic x(5) Date Format yyxxx.
. . .
If FUNCTION UNDATE(Invoice-Date) Equal “00999” . . .
RELATED REFERENCES
UNDATE (IBM COBOL Language Reference)
To see all MLE messages, specify the FLAG(I,I) and DATEPROC(FLAG) compiler
options. Initially, you might want to see all of the messages to understand how
MLE is processing the date fields in your program. For example, if you want to do
a static analysis of the date usage in a program by using the compile listing, use
FLAG (I,I).
RELATED REFERENCES
Millennium Language Extensions Guide (for details on the MLE messages)
A field that holds a six-digit Gregorian date, for example, can be declared as PIC
S9(6) COMP-3, and this declaration will reserve 4 bytes of storage. But the
programmer might have declared the field as PIC S9(7), knowing that this would
reserve the same 4 bytes, with the high-order digit always containing a zero.
If you add a DATE FORMAT YYXXXX clause to this field, the compiler will give you a
diagnostic message because the number of digits in the PICTURE clause does not
match the size of the date format specification. In this case, you need to check
carefully each use of the field. If the high-order digit is never used, you can simply
change the field definition to PIC S9(6). If it is used (for example, if the same field
can hold a value other than a date), you need to take some other action, such as:
v Using a REDEFINES clause to define the field as both a date and a nondate (this
usage will also produce a warning-level diagnostic message)
v Defining another WORKING-STORAGE field to hold the date, and moving the
numeric field to the new field
v Not adding a DATE FORMAT clause to the data item, and using the DATEVAL
intrinsic function when referring to it as a date field
RELATED TASKS
“Using an optimal programming style”
“Choosing efficient data types” on page 537
“Handling tables efficiently” on page 539
“Optimizing your code” on page 542
“Choosing compiler features to enhance performance” on page 544
Specifying run-time options (Language Environment Programming Guide)
“Running efficiently with CICS, IMS, or VSAM” on page 548
RELATED REFERENCES
“Performance-related compiler options” on page 545
Storage performance considerations (Language Environment Programming Guide)
Factoring expressions
Factoring can save a lot of computation. For example, this code:
MOVE ZERO TO TOTAL
PERFORM VARYING I FROM 1 BY 1 UNTIL I = 10
COMPUTE TOTAL = TOTAL + ITEM(I)
END-PERFORM
COMPUTE TOTAL = TOTAL * DISCOUNT
If you move a literal to a data item, the optimizer recognizes it as a constant, but
only in a limited region of the program after the MOVE statement.
For example, given that V1, V2, and V3 are variables and that C1, C2, and C3 are
constants, the expressions that contain the constant computations are preferable to
those that do not:
The optimizer can eliminate duplicate computations; you do not need to introduce
artificial temporary computations. The program is often more comprehensible
without them.
To produce the most efficient code for a BINARY data item, ensure that it has:
v A sign (an S in its PICTURE clause)
v Eight or fewer digits
For a data item that is larger than eight digits or is used with DISPLAY data items,
use PACKED-DECIMAL. The code generated for PACKED-DECIMAL data items can be as
fast as that for BINARY data items in some cases, especially if the statement is
complicated or specifies rounding.
To produce the most efficient code for a PACKED-DECIMAL data item, ensure that it
has:
v A sign (an S in its PICTURE clause)
v An odd number of digits (9s in the PICTURE clause), so that it occupies an exact
number of bytes without a half byte left over
v 15 or fewer digits in the PICTURE specification to avoid using library routines for
multiplication and division
You largely avoid conversions by using consistent data types, giving both operands
the same usage and also appropriate PICTURE specifications. That is, you should
give two numbers to be compared, added, or subtracted not only have the same
usage but also the same number of decimal places (9s after the V in the PICTURE
clause).
Arithmetic expressions
Computation of arithmetic expressions that are evaluated in floating point is most
efficient when the operands need little or no conversion. Use operands that are
COMP-1 or COMP-2 to produce the most efficient code.
Exponentiations
Use floating point for exponentiations for large exponents to achieve faster
evaluation and more accurate results. For example, the first statement below is
computed more quickly and accurately than the second statement:
COMPUTE fixed-point1 = fixed-point2 ** 100000.E+00
RELATED CONCEPTS
“Formats for numeric data” on page 36
The following two guidelines affect your choice of how to refer to table elements:
v Use indexing rather than subscripting.
Although the compiler can eliminate duplicate indexes and subscripts, the
original reference to a table element is more efficient with indexes than with
subscripts, even if the subscripts are BINARY. The value of an index has the
element size factored into it, whereas the value of a subscript must be multiplied
by the element size when the subscript is used. The index already contains the
displacement from the start of the table, and this value does not have to be
calculated at run time. However, subscripting might be easier to understand and
maintain.
v Use relative indexing.
Relative index references (that is, references in which an unsigned numeric
literal is added to or subtracted from the index name) are executed as fast as
direct index references and sometimes faster. There is no merit in keeping
alternative indexes with the offset factored in.
Whether you use indexes or subscripts, the following guidelines can help you get
better performance in terms of how you code them:
v Put constant and duplicate indexes or subscripts on the left.
You can reduce or eliminate run-time computations by making the constant and
duplicate indexes or subscripts the leftmost ones. Even when all the indexes or
subscripts are variable, try to use your tables so that the rightmost subscript
varies most often for references that occur close to each other in the program.
This practice also improves the pattern of storage references as well as paging. If
all the indexes or subscripts are duplicates, then the entire index or subscript
computation is a common subexpression.
v Specify the element length so that it matches that of related tables.
When you index or subscript tables, it is most efficient if all the tables have the
same element length. With equal element lengths, the stride for the last
dimension of the tables will be equal. The optimizer can then reuse the
rightmost index or subscript computed for one table. If both the element lengths
and the number of occurrences in each dimension are equal, then the strides for
dimensions other than the last are also equal, resulting in greater commonality
between their subscript computations. The optimizer can then reuse indexes or
subscripts other than the rightmost.
v Avoid errors in references by coding index and subscript checks into your
program.
If you need to validate your indexes and subscripts, it might be faster to code
your own checks in your COBOL program than to use the SSRANGE compiler
option.
RELATED TASKS
“Referring to an item in a table” on page 55
“Choosing efficient data types” on page 537
RELATED REFERENCES
“SSRANGE” on page 294
Here comp_s1 is the value of S1 after conversion to binary, comp-s2 is the value of
S2 after conversion to binary, and so on. The strides for each dimension are d1, d2,
and d3. The stride of a given dimension is the distance in bytes between table
elements whose occurrence numbers in that dimension differ by 1 and whose other
occurrence numbers are equal. For example, the stride, d2, of the second dimension
in the above example is the distance in bytes between ELEMENT(S1 1 S3) and
ELEMENT(S1 2 S3).
Because the compiler evaluates expressions from left to right, the optimizer finds
the most opportunities to eliminate computations when the constant or duplicate
subscripts are the leftmost.
However, for the table element reference ELEMENT(C1 C2 V1) the compiler can
eliminate the entire subexpression comp_c1 * d1 + comp_c2 * d2 as constant from
the expression:
comp_c1 * d1 + comp_c2 * d2 + comp_v1 * d3 + base_address
In the table element reference ELEMENT(C1 C2 C3) all the subscripts are constant,
and so no subscript computation is done at run time. The expression is:
comp_c1 * d1 + comp_c2 * d2 + comp_c3 * d3 + base_address
However, for the two table element references ELEMENT(V1 V2 V3) and ELEMENT(V1
V2 V4) the entire subexpression comp_v1 * d1 + comp_v2 * d2 is common between
the two expressions needed to reference the table elements:
comp_v1 * d1 + comp_v2 * d2 + comp_v3 * d3 + base_address
comp_v1 * d1 + comp_v2 * d2 + comp_v4 * d3 + base_address
In the two references ELEMENT(V1 V2 V3) and ELEMENT(V1 V2 V3), the expressions
are the same:
comp_v1 * d1 + comp_v2 * d2 + comp_v3 * d3 + base_address
comp_v1 * d1 + comp_v2 * d2 + comp_v3 * d3 + base_address
With the optimizer, the second (and any subsequent) reference to the same element
can be as efficient as a reference to a scalar (nontable) item.
The direct indexing in ELEMENT (I5, J3, K2) requires this preprocessing:
This processing makes the direct indexing less efficient than the relative indexing
in ELEMENT (I + 5, J - 3, K + 2).
RELATED CONCEPTS
“Optimization”
RELATED TASKS
“Handling tables efficiently” on page 539
You might also want to use this compiler option during development if a program
is used frequently without recompilation. However, the overhead for OPTIMIZE
might outweigh its benefits if you recompile frequently, unless you are using the
assembler language expansion (LIST compiler option) to fine-tune your program.
For unit-testing your program, you will probably find it easier to debug code that
has not been optimized.
To see how the optimizer works on your program, compile it with and without the
OPTIMIZE option and compare the generated code. (Use the LIST compiler option to
request the assembler language listing of the generated code.)
RELATED CONCEPTS
“Optimization”
RELATED REFERENCES
“LIST” on page 281
“OPTIMIZE” on page 285
Optimization
To improve the efficiency of the generated code, you can use the OPTIMIZE compiler
option to cause the COBOL optimizer to do the following:
v Eliminate unnecessary transfers of control and inefficient branches, including
those generated by the compiler that are not evident from looking at the source
program.
v Simplify the compiled code for both a PERFORM statement and a CALL statement to
a contained (nested) program. Where possible, the optimizer places the
statements inline, eliminating the need for linkage code. This optimization is
known as procedure integration. If procedure integration cannot be done, the
optimizer uses the simplest linkage possible (perhaps as few as two instructions)
to get to and from the called program.
v Eliminate duplicate computations (such as subscript computations and repeated
statements) that have no effect on the results of the program.
Program size: If several CALL statements call contained programs and these
programs replace each such statement, the containing program can become large.
The optimizer limits this increase to no more than 50 percent, after which it no
longer integrates the programs. The optimizer then chooses the next best
optimization for the CALL statement; the linkage overhead can be as few as two
instructions.
RELATED REFERENCES
“OPTIMIZE” on page 285
By contrast, in the following program only the first PERFORM statement, PERFORM 12,
will be optimized by procedure integration:
1 SECTION.
11. PERFORM 12
STOP RUN.
12. PERFORM 21
PERFORM 21.
2 SECTION 5.
21. IF A < 5 THEN
ADD 1 TO A
DISPLAY A
END-IF.
RELATED CONCEPTS
“Optimization of table references” on page 540
RELATED TASKS
“Optimizing your code” on page 542
“Chapter 33. Tuning your program” on page 535
Although COBOL allows segmentation language, you will not improve storage
allocation by using it, because COBOL does not perform overlay.
RELATED CONCEPTS
“Optimization” on page 542
RELATED TASKS
“Optimizing your code” on page 542
“Getting listings” on page 319
RELATED REFERENCES
“Performance-related compiler options”
Compiler Performance
option Purpose Performance advantages disadvantages Usage notes
(“AWO” on To get optimum Can result in performance In general, none When you use AWO, the APPLY
page 263) use of buffer savings, because this WRITE-ONLY clause is in effect
and device option results in fewer calls for all files in the program that
space to data management are physical sequential with
services to handle input V-mode records.
and output
DATA(31) To have DFSMS Because extended-format In general, none On an OS/390 system with
allocate QSAM QSAM data sets can DFSMS, if your application
(see (“DATA” buffers in require many buffers, processes striped
on unrestricted allocating the buffers in extended-format QSAM data
page 266)) storage (by unrestricted storage avoids sets, use the RENT and
using the RENT virtual storage constraint DATA(31) compiler options to
and DATA(31) problems. have the input-output buffers
compiler for your QSAM files allocated
options) from unrestricted storage
above the 16-MB line.
RELATED CONCEPTS
“Optimization” on page 542
RELATED TASKS
“Generating a list of compiler error messages” on page 230
“Evaluating performance” on page 548
“Optimizing buffer and device space” on page 12
“Choosing compiler features to enhance performance” on page 544
“Improving sort performance with FASTSRT” on page 181
“Using striped extended-format QSAM data sets” on page 126
“Handling tables efficiently” on page 539
Evaluating performance
Fill in this worksheet to help you evaluate the performance of your program. If
you answer yes to each question, you are probably improving the performance.
In thinking about the performance tradeoff, be sure you understand the function of
each option as well as the performance advantages and disadvantages. You might
prefer function over increased performance in many instances.
RELATED TASKS
“Choosing compiler features to enhance performance” on page 544
RELATED REFERENCES
“Performance-related compiler options” on page 545
CICS
If your application runs under CICS, convert EXEC CICS LINKs to COBOL CALLs to
improve transaction response time.
For better system performance, use the RENT compiler option and preload the
applications and library routines when possible.
You can also use the library routine retention (LRR) function to improve
performance in IMS/TM regions.
VSAM
When you use VSAM files, increase the number of data buffers for sequential
access or index buffers for random access. Also, select a control interval size (CISZ)
appropriate for the application. Smaller CISZ results in faster retrieval for the
random processing at the expense of inserts, and a larger CISZ is more efficient for
sequential processing.
For better performance, access the records sequentially and avoid using multiple
alternate indexes when possible. If you do use alternate indexes, access method
services builds them more efficiently than the AIXBLD run-time option.
RELATED TASKS
“Improving VSAM performance” on page 159
Language Environment for OS/390 Customization
RELATED REFERENCES
Language Environment Programming Guide
COBOL provides various capabilities for manipulating strings and numbers. These
capabilities can help you simplify your coding.
The Language Environment date and time callable services store dates as fullword
binary integers and timestamps as long (64-bit) floating-point values. These
formats let you do arithmetic calculations on date and time values simply and
efficiently. You do not need to write special subroutines that use services outside
the language library for your application in order to perform these calculations.
RELATED CONCEPTS
“Numeric intrinsic functions” on page 44
“Math and date Language Environment services” on page 45
RELATED TASKS
“Eliminating repetitive coding”
“Converting data items (intrinsic functions)” on page 94
“Evaluating data items (intrinsic functions)” on page 96
“Using Language Environment callable services” on page 553
| To specify more than one copy library, use either multiple system definitions or a
combination of multiple definitions and the IN/OF phrase (IN/OF library-name):
OS/390 batch
Use JCL to concatenate data sets on your SYSLIB DD statement.
Alternatively, define multiple DD statements and use the IN/OF phrase of
the COPY statement.
TSO Use the ALLOCATE command to concatenate data sets for SYSLIB.
Alternatively, issue multiple ALLOCATE statements and use the IN/OF phrase
of the COPY statement.
For example:
COPY MEMBER1 OF COPYLIB
COPY and debugging line: In order for the text copied to be treated as debug lines,
for example, as if there were a D inserted in column 7, put the D on the first line of
the COPY statement. A COPY statement itself cannot be a debugging line; if it
contains a D and WITH DEBUGGING mode is not specified, the COPY statement is
nevertheless processed.
RELATED REFERENCES
“Compiler-directing statements” on page 304
You can retrieve the member CFILEA by using the COPY statement in the DATA
DIVISION of your source program code as follows:
FD FILEA
COPY CFILEA.
The library entry is copied into your program, and the resulting program listing
looks as follows:
FD FILEA
COPY CFILEA.
C BLOCK CONTAINS 20 RECORDS
C RECORD CONTAINS 120 CHARACTERS
C LABEL RECORDS ARE STANDARD
C DATA RECORD IS FILE-OUT.
C 01 FILE-OUT PIC X(120).
In the compiler source listing, the COPY statement prints on a separate line, and C
precedes copied lines.
Assume that a member named DOWORK was stored with the following statements:
COMPUTE QTY-ON-HAND = TOTAL-USED-NUMBER-ON-HAND
MOVE QTY-ON-HAND to PRINT-AREA
If you use the EXIT compiler option to provide a LIBEXIT module, your results
might differ from those presented here.
RELATED TASKS
“Eliminating repetitive coding” on page 551
“Using compiler-directing statements” on page 245
RELATED REFERENCES
“Compiler-directing statements” on page 304
RELATED CONCEPTS
“Sample list of Language Environment callable services”
“Numeric intrinsic functions” on page 44
“Math and date Language Environment services” on page 45
RELATED TASKS
“Calling Language Environment services” on page 555
“Using procedure pointers” on page 472
RELATED REFERENCES
Language Environment Programming Reference
Define the variables for the CALL statement in the DATA DIVISION with the
definitions required by the function you are calling:
77 argument comp-1.
77 feedback-code pic x(12) display.
77 result comp-1.
You can choose whether you want to specify the feedback code parameter. If you
specify the feedback code, the value returned in feedback-code indicates whether
the service completed successfully. If you specify OMITTED instead of the feedback
code and the service is not successful, a Language Environment condition is
automatically signaled to the Language Environment condition manager. You can
handle such a condition by recovery logic implemented in a user-written condition
handler, or allow the default Language Environment processing for unhandled
conditions to occur. In any case, this avoids the requirement to write logic to check
the feedback code explicitly after each call.
When you call a Language Environment callable service and specify OMITTED for
the feedback code, the RETURN-CODE special register is set to 0 if the service is
successful. It is not altered if the service is unsuccessful. If you do not specify
OMITTED for the feedback code, the RETURN-CODE special register is always set to 0
regardless of whether the service completed successfully.
RELATED REFERENCES
Language Environment callable services (Language Environment Programming
Reference)
CALL statement (IBM COBOL Language Reference)
| The precision of intermediate results depends on whether you compile using the
| default option ARITH(COMPAT) (referred to as compatibility mode), or using
| ARITH(EXTEND) (referred to as extended mode), explained below.
RELATED REFERENCES
“Fixed-point data and intermediate results” on page 561
“Floating-point data and intermediate results” on page 566
“ON SIZE ERROR and intermediate results” on page 567
“Arithmetic expressions in nonarithmetic statements” on page 568
“ARITH” on page 262
RELATED CONCEPTS
“Arithmetic expressions” on page 43
RELATED REFERENCES
“Terminology used for intermediate results” on page 560
You must define the operands of any arithmetic statements with enough decimal
places to obtain the accuracy you want in the final result.
The following table shows the number of places the compiler carries for
fixed-point intermediate results of arithmetic operations involving addition,
| subtraction, multiplication, or division in compatibility mode (that is, when you
| compile using the default compiler option ARITH(COMPAT)):
Value of i +
Value of i + d Value of d dmax Number of places carried for ir
<30 Any value Any value i integer and d decimal places
=30
| The following table shows the number of places the compiler carries for
| fixed-point intermediate results of arithmetic operations involving addition,
| subtraction, multiplication, or division in extended mode (that is, when you compile
| using option ARITH(EXTEND)):
Value of i +
| Value of i + d Value of d dmax Number of places carried for ir
| <31 Any value Any value i integer and d decimal places
| =31
| >31 <dmax Any value 31-d integer and d decimal places
=dmax
| >dmax <31 i integer and 31-i decimal places
| =31
| >31 31-dmax integer and dmax decimal
| places
Exponentiation
Exponentiation is represented by the expression op1 ** op2. Based on the
characteristics of op2, the compiler handles exponentiation of fixed-point numbers
in one of three ways:
v When op2 is expressed with decimals, floating-point instructions are used.
v When op2 is an integral literal or constant, the value d is computed as
d = d1 * |op2|
| In either mode, if op2 is negative, the value of 1 is then divided by the result
produced by the preliminary computation. The values of i and d that are used
are calculated following the division rules for fixed-point data already shown
above.
| v When op2 is an integral data name or variable, dmax decimal places and 30-dmax
| (compatibility mode) or 31-dmax (extended mode) integer places are used. op1 is
multiplied by itself (|op2| - 1) times for nonzero op2.
If op2 is equal to 0, the result is 1. Division-by-0 and exponentiation SIZE ERROR
conditions apply.
Fixed-point exponents with more than nine significant digits are always truncated
to nine digits. If the exponent is a literal or constant, an E-level compiler diagnostic
message is issued; otherwise, an informational message is issued at run time.
RELATED REFERENCES
“Terminology used for intermediate results” on page 560
“Truncated intermediate results” on page 564
“Binary data and intermediate results” on page 564
“Floating-point data and intermediate results” on page 566
“Intrinsic functions evaluated in fixed-point arithmetic” on page 565
“ARITH” on page 262
SIZE ERROR phrases (IBM COBOL Language Reference)
RELATED REFERENCES
“Terminology used for intermediate results” on page 560
“Fixed-point data and intermediate results” on page 561
If you want to avoid the truncation of intermediate results that can occur in
fixed-point calculations, use floating-point operands (COMP-1 or COMP-2) instead.
RELATED CONCEPTS
“Formats for numeric data” on page 36
RELATED REFERENCES
“Fixed-point data and intermediate results” on page 561
“ARITH” on page 262
You use binary operands most efficiently when the intermediate results will not
exceed nine digits.
RELATED REFERENCES
“Fixed-point data and intermediate results” on page 561
“ARITH” on page 262
Integer functions
Integer intrinsic functions return an integer; thus their outer-dmax is always zero.
For those integer functions whose arguments must all be integers, the inner-dmax is
thus also always zero.
The following table summarizes the inner-dmax and the precision of the function
result.
Mixed functions
A mixed intrinsic function is a function whose result type depends on the type of
its arguments. A mixed function is fixed point if all of its arguments are numeric
and none of its arguments is floating point. (If any argument of a mixed function is
floating point, the function is evaluated with floating-point instructions and returns
a floating-point result.) When a mixed function is evaluated with fixed-point
arithmetic, the result is integer if all of the arguments are integer; otherwise, the
result is fixed point.
For the mixed functions MAX, MIN, RANGE, REM, and SUM, the outer-dmax is always
equal to the inner-dmax (and both are thus zero if all the arguments are integer). To
determine the precision of the result returned for these functions, apply the rules
for fixed-point arithmetic and intermediate results (as referred to below) to each
step in the algorithm.
MAX
RELATED REFERENCES
“Terminology used for intermediate results” on page 560
“Fixed-point data and intermediate results” on page 561
“Floating-point data and intermediate results”
“ARITH” on page 262
Mixed functions with at least one floating-point argument are evaluated using
floating-point arithmetic.
RELATED REFERENCES
“Terminology used for intermediate results” on page 560
“ARITH” on page 262
RELATED REFERENCES
“CMPR2” on page 264
For example:
IF operand-1 = expression-1 THEN . . .
RELATED REFERENCES
“Terminology used for intermediate results” on page 560
“Fixed-point data and intermediate results” on page 561
“Floating-point data and intermediate results” on page 566
IF statement (IBM COBOL Language Reference)
EVALUATE statement (IBM COBOL Language Reference)
Conditional expressions (IBM COBOL Language Reference)
The basic forms of complex ODO permitted by the compiler are as follows:
v Variably located item or group: A data item described by an OCCURS clause with
the DEPENDING ON option is followed by a nonsubordinate data item or group.
v Variably located table: A data item described by an OCCURS clause with the
DEPENDING ON option is followed by a nonsubordinate data item described by an
OCCURS clause.
v Table with variable-length elements: A data item described by an OCCURS clause
contains a subordinate data item described by an OCCURS clause with the
DEPENDING ON option.
v Index name for a table with variable-length elements.
v Element of a table with variable-length elements.
Complex ODO can help you save disk space, but it can be tricky to use and can
make maintaining your code more difficult.
RELATED TASKS
“Preventing index errors when changing ODO object value” on page 571
“Preventing overlay when adding elements to a variable table” on page 571
RELATED REFERENCES
“Effects of change in ODO object value” on page 570
OCCURS DEPENDING ON clause (IBM COBOL Language Reference)
Definition: In the example, COUNTER-1 is an ODO object, that is, it is the object of
the DEPENDING ON clause of RECORD-1. RECORD-1 is said to be an ODO subject.
Similarly, COUNTER-2 is the ODO object of the corresponding ODO subject,
RECORD-2.
RELATED REFERENCES
“Effects of change in ODO object value” on page 570
SET statement (IBM COBOL Language Reference)
Each element of VARY-FIELD-1 has 5 bytes, and each element of VARY-FIELD-2 has 9
bytes. If CONTROL-1 and CONTROL-2 both contain the value 3, you can picture storage
for VARY-FIELD-1 and VARY-FIELD-2 as follows:
You can picture the updated storage for VARY-FIELD-1 and VARY-FIELD-2 as follows:
RELATED REFERENCES
“Effects of change in ODO object value” on page 570
For SYSADATA, the ADEXIT suboption provides a module that will be called for
each SYSADATA record immediately after the record has been written out to the
file. Under CMS, the user-supplied modules must be relocatable MODULE files.
If you specify the EXIT option without providing a least one suboption, NOEXIT will
be in effect. You can specify the suboptions in any order and separate them by
either commas or spaces. If you specify both the positive and negative form of a
suboption (INEXIT|NOINEXT, LIBEXIT|NOLIBEXIT, PRTEXIT|NOPRTEXIT, or
ADEXIT|NOADEXIT), the form specified last takes effect. If you specify the same
suboption more than once, the last one that you specified takes effect.
You can specify the EXIT option only at invocation in the PARM field of JCL (under
TSO, in a command argument) or at installation time. Do not specify the EXIT
option in a PROCESS (CBL) statement.
INEXIT([’str1’,]mod1)
The compiler reads source code from a user-supplied load module (where
mod1 is the module name), instead of SYSIN.
LIBEXIT([’str2’,]mod2)
The compiler obtains copy code from a user-supplied load module (where
mod2 is the module name), instead of library-name or SYSLIB. For use with
either COPY or BASIS statements.
PRTEXIT([’str3’,]mod3)
The compiler passes printer-destined output to the user-supplied load
module (where mod3 is the module name), instead of SYSPRINT.
ADEXIT([’str4’,]mod4)
The compiler passes the SYSADATA output to the user-supplied load
module (where mod4 is the module name).
The module names mod1, mod2, mod3, and mod4 can refer to the same module.
If one of str1, str2, str3, or str4 is specified, the string is passed to the appropriate
user-exit module with the following format:
LL string
RELATED TASKS
“Using the user-exit work area”
“Calling from exit modules”
RELATED REFERENCES
“Processing of INEXIT” on page 577
“Processing of LIBEXIT” on page 578
“Processing of PRTEXIT” on page 580
“Processing of ADEXIT” on page 582
“Error handling for exit modules” on page 583
You need to establish your own conventions for using the work area if more than
one exit is active during the compilation. For example, the INEXIT module uses
the first word in the work area, the LIBEXIT module uses the second word, and
the PRTEXIT module uses the third word.
RELATED REFERENCES
“Appendix C. EXIT compiler option” on page 575
Exit modules must have the RMODE attribute of 24 and the AMODE attribute of ANY.
RELATED REFERENCES
“Appendix C. EXIT compiler option” on page 575
Processing of INEXIT
The exit module is used in place of SYSIN, to read source code from a
user-supplied load module.
RELATED REFERENCES
“Appendix C. EXIT compiler option” on page 575
Processing of LIBEXIT
The exit module is used in place of the SYSLIB, or library-name, data set. Calls are
made to the module by the compiler to obtain copy text whenever COPY or BASIS
statements are encountered.
The following table shows how the processing of LIBEXIT changes when there is
one or more valid COPY statements:
RELATED REFERENCES
“Appendix C. EXIT compiler option” on page 575
Processing of PRTEXIT
The exit module is used in place of the SYSPRINT data set.
Processing of ADEXIT
Use of the ADEXIT module requires:
v Compiler option ADATA to produce SYSADATA output
v DD statement SYSADATA
The processing of ADEXIT is as follows:
RELATED REFERENCES
“Appendix C. EXIT compiler option” on page 575
Message IGYSI5008 is written to the operator, and the compiler terminates with
return code 16 when any of the following happens:
v An exit module cannot be loaded.
v A nonzero return code is received from INEXIT during an OPEN request.
v A nonzero return code is received from PRTEXIT during an OPEN request.
The exit type and operation (OPEN or LOAD) are identified in the message.
Any other error from INEXIT or PRTEXIT causes the compiler to terminate.
RELATED REFERENCES
“Appendix C. EXIT compiler option” on page 575
Identification Division.
Environment Division.
Data Division.
WORKING-STORAGE Section.
* *******************************************************
* * *
* * Local variables. *
* * *
* *******************************************************
Linkage Section.
01 Exit-Type Pic 9(4) Comp.
01 Exit-Operation Pic 9(4) Comp.
01 Exit-ReturnCode Pic 9(5) Comp.
01 Exit-WorkArea.
05 Sysin-Slot Pic 9(5) Comp.
05 Syslib-Slot Pic 9(5) Comp.
05 Sysprint-Slot Pic 9(5) Comp.
05 Reserved-Slot Pic 9(5) Comp.
01 Exit-DataLength Pic 9(5) Comp.
01 Exit-DataArea Pic 9(9) Comp.
01 Exit-Open-Parm Redefines Exit-DataArea.
05 String-Len Pic 9(4) Comp.
05 Open-String Pic X(64).
01 Exit-Print-Line Redefines Exit-DataArea Pic X(133).
01 Exit-Syslibrary Pic X(8).
01 Exit-Systext Pic X(8).
01 Exit-CBLLibrary Pic X(30).
01 Exit-CBLText Pic X(30).
***********************************************************
* *
* Begin PROCEDURE DIVISION *
* *
* Invoke the section to handle the exit. *
* *
***********************************************************
Go To Sysin-Open
Sysin-Close
Sysin-Get
Depending On Operation.
Move 16 To Exit-ReturnCode
Goback.
Sysin-Open.
* ------------------------------------------------------
* Prepare for reading source
* ------------------------------------------------------
Goback.
Sysin-Close.
* ------------------------------------------------------
* Release resources
* ------------------------------------------------------
Goback.
Sysin-Get.
* ------------------------------------------------------
* Retrieve next source record
* ------------------------------------------------------
* ------------------------------------------------------
* The following can be used to return the address of the
* record to the compiler.
* ------------------------------------------------------
Call “GETADDRESS” Using
By Reference Record-Variable
By Reference Exit-DataArea
* ------------------------------------------------------
* Set length of record in User-Exit Parameter List
* ------------------------------------------------------
Move 80 To Exit-DataLength
Goback.
***************************************************
* S Y S L I B E X I T P R O C E S S O R *
***************************************************
Handle-Syslib.
Display “**** This module for SYSIN only”
Move 16 To Exit-ReturnCode
Goback.
*******************************************************
* S Y S P R I N T E X I T P R O C E S S O R *
*******************************************************
Handle-Sysprint.
Display “**** This module for SYSIN only”
Move 16 To Exit-ReturnCode
Goback.
*******************************************************
*******************************************************
** **
** Internal program to obtain the address of an **
** item in the caller's WORKING-STORAGE SECTION **
** **
*******************************************************
*******************************************************
The sample programs in this material demonstrate many language elements and
concepts of COBOL:
v IGYTCARA is an example of using QSAM files and VSAM indexed files and
shows how to use many COBOL intrinsic functions.
v IGYTCARB is an example of using the IBM Interactive System Product Facility
(ISPF).
v IGYTSALE is an example of using several of the Language Environment callable
services features.
RELATED CONCEPTS
“IGYTCARA: batch application”
“IGYTCARB: interactive program” on page 592
“IGYTSALE: nested program application” on page 595
The following diagram shows the parts of the application and how they are
organized:
RELATED REFERENCES
“Input data for IGYTCARA”
“Report produced by IGYTCARA” on page 589
“Language elements and concepts that are illustrated” on page 604
1. Transaction code
2. Shift
All the files required by the IGYTCARA program are supplied on the product
installation tape. These files (IGYTCARA, IGYTCODE, and IGYTRANX) are located
in the IGY.V2R2M0.SIGYSAMP data set.
Data set and procedure names can be changed at installation time. You should
check with your system programmer to verify these names.
Do not change these options on the CBL statement in the source file for
IGYTCARA:
NOADV
NOCMPR2
NODYNAM
NONAME
NONUMBER
QUOTE
SEQUENCE
With these options in effect, the program will not cause any diagnostic messages to
be issued. You can use the sequence number string in the source file to search for
the language elements used.
RELATED CONCEPTS
“IGYTCARA: batch application” on page 587
RELATED TASKS
“Running IGYTCARA under OS/390”
“Running IGYTCARA under CMS” on page 591
RELATED REFERENCES
“Input data for IGYTCARA” on page 588
“Report produced by IGYTCARA” on page 589
“Language elements and concepts that are illustrated” on page 604
To run IGYTCARA under OS/390, use JCL to define a VSAM cluster and compile
the program. Insert the information specific to your system and installation in the
fields that are shown in lowercase letters (accounting information, volume serial
number, unit name, cluster prefix). We have used the name IGYTCAR.MASTFILE in
these examples; you can use another name if you want.
1. Use this JCL to create the required VSAM cluster:
//CREATE JOB (acct-info),'IGYTCAR CREATE VSAM',MSGLEVEL=(1,1),
// TIME=(0,29)
//CREATE EXEC PGM=IDCAMS
//VOL1 DD VOL=SER=your-volume-serial,UNIT=your-unit,DISP=SHR
//SYSPRINT DD SYSOUT=A
//SYSIN DD *
DELETE your-prefix.IGYTCAR.MASTFILE -
FILE(VOL1) -
PURGE
DEFINE CLUSTER -
To remove any existing cluster, a DELETE is issued before the VSAM cluster is
created.
2. Use the following JCL to compile, link-edit, and run the IGYTCARA program:
//IGYTCARA JOB (acct-info),'IGYTCAR',MSGLEVEL=(1,1),TIME=(0,29)
//TEST EXEC IGYWCLG
//COBOL.SYSLIB DD DSN=IGY.V2R2M0.SIGYSAMP,DISP=SHR
//COBOL.SYSIN DD DSN=IGY.V2R2M0.SIGYSAMP(IGYTCARA),DISP=SHR
//GO.SYSOUT DD SYSOUT=A
//GO.COMMUTR DD DSN=your-prefix.IGYTCAR.MASTFILE,DISP=SHR
//GO.LOCCODE DD DSN=IGY.V2R2M0.SIGYSAMP(IGYTCODE),DISP=SHR
//GO.UPDTRANS DD DSN=IGY.V2R2M0.SIGYSAMP(IGYTRANX),DISP=SHR
//GO.UPDPRINT DD SYSOUT=A,DCB=BLKSIZE=133
//
RELATED TASKS
“Chapter 9. Processing VSAM files” on page 135
To run IGYTCARA under CMS, first access the COBOL for OS/390 & VM product
using the CP LINK and ACCESS commands, and then do the following steps:
1. Access the Language Environment library:
GLOBAL TXTLIB SCEELKED
2. Compile program by using the COBOL2 command:
COBOL2 IGYTCARA
At the end of the compilation, LISTING and TEXT files are created and sent to
your disk.
3. Identify the data sets that are used by issuing FILEDEF commands (where “*”
designates a disk):
FILEDEF SYSOUT DISK IGYTCARA SYSOUT A
FILEDEF UPDTRANS DISK IGYTRANX UPDATE A
FILEDEF LOCCODE DISK IGYTCODE INPUT *
FILEDEF UPDPRINT DISK IGYTCARA UPDPRINT A
4. Identify the catalog and your VSAM files by using the DLBL command:
DLBL * CLEAR
QUEUE '30 390'
QUEUE ''
DLBL IJSYSCT E DSN MASTCAT (EXTENT
QUEUE '60 360'
QUEUE ''
DLBL COMMUTR E DSN IGYTCARA (EXTENT
5. Set up a AMSERV file named IGYTCARA AMSERV to contain the following
statements:
The input data for IGYTCARB is the same as that for IGYTCARA. IGYTCARB lets
you append to the information in your input file by using an ISPF panel. An
example of the panel used by IGYTCARB is shown below:
RELATED TASKS
“Running IGYTCARB”
Running IGYTCARB
You can run IGYTCARB using the Interactive System Productivity Facility (ISPF)
under OS/390 or CMS.
Data set and procedure names can be changed at installation time. Check with
your system programmer to verify these names.
Do not change these options on the CBL card in the source file for IGYTCARB:
NOCMPR2
NONUMBER
QUOTE
SEQUENCE
With these options in effect, the program will not cause any diagnostic messages to
be issued. You can use the sequence number string in the source file to search for
language elements.
RELATED CONCEPTS
“IGYTCARB: interactive program” on page 592
RELATED TASKS
“Running IGYTCARB under OS/390”
“Running IGYTCARB under CMS” on page 595
RELATED REFERENCES
“Language elements and concepts that are illustrated” on page 604
As indicated by (1) in this example, you add IGYTCARB to the upper portion
of the panel by entering:
% C +IGYTCARB - Run IGYTCARB UPDATE TRANSACTION PROGRAM
You add the corresponding line on the lower portion of the panel, indicated by
(2), by entering:
C,'PGM(IGYTCARB)'
2. Place ISR@PRIM (or your other modified panel) and IGYTPNL in a library and
make this library the first library in the ISPPLIB concatenation.
3. If necessary, comment sequence line IB2200 and uncomment sequence line
IB2210 in IGYTCARB. The OPEN EXTEND verb is supported under OS/390.
4. Compile and link-edit IGYTCARB and place the resulting load module in your
LOADLIB.
5. Allocate ISPLLIB using the following command:
ALLOCATE FILE(ISPLLIB) DATASET(DSN1, SYS1.COBLIB, DSN2) SHR REUSE
Here DSN1 is the library name of the LOADLIB from step 4. DSN2 is your
installed ISPLLIB.
6. Allocate the input and output data sets using the following command:
ALLOCATE FILE(UPDTRANS) DA('IGY.V2R2M0.SIGYSAMP(IGYTRANB)) SHR REUSE
7. Allocate ISPPLIB using the following command:
ALLOCATE FILE(ISPPLIB) DATASET(DSN3, DSN4) SHR REUSE
Here DSN3 is the library containing the modified panels. DSN4 is the ISPF panel
library.
8. Invoke IGYTCARB using your modified panel.
RELATED REFERENCES
Interactive System Productivity Facility Dialog Manager Guide
The corresponding line on the lower portion of the panel, indicated by (2), is
added by entering:
C,'PGM(IGYTCARB) CMS'
2. Place ISR@PRIM (or your other modified panel) and IGYPANEL in a MACLIB
using the following command:
MACLIB GEN IGYTCAR ISR@PRIM IGYTPNL
Make this MACLIB the first library in the ISPPLIB concatenation by using the
following FILEDEF command (where “*” designates a disk):
FILEDEF ISPPLIB DISK IGYTCAR MACLIB * (PERM CONCAT
3. Comment sequence line IB2210 and uncomment sequence line IB2200 in
IGYTCARB. The OPEN EXTEND statement is not supported under CMS.
4. Concatenate SCEELKED TXTLIB with ISPXLIB by issuing the following
FILEDEF command (where “*” designates a disk):
FILEDEF ISPXLIB DISK SCEELKED TXTLIB * (PERM CONCAT
5. Concatenate SCEERUN LOADLIB with ISPLLIB by issuing the following
FILEDEF command (where “*” designates a disk):
FILEDEF ISPLLIB DISK SCEERUN LOADLIB * (PERM CONCAT
6. Access the COBOL for OS/390 & VM library:
GLOBAL TXTLIB SCEELKED
GLOBAL LOADLIB SCEERUN
7. Compile IGYTCARB and make IGYTCARB TEXT available on your system.
8. Identify the data sets that are used by issuing the following FILEDEF commands
(where “*” designates a disk):
FILEDEF UPDTRANS DISK IGYTRANB OUTPUT * (PERM DISP MOD
9. Invoke IGYTCARB using the modified panel.
RELATED REFERENCES
Interactive System Productivity Facility Dialog Manager Guide
RELATED TASKS
“Running IGYTSALE” on page 602
1. Record type
2. Customer code
3. Customer name
4. Product code
5. Product description
6. Product unit price
7. Salesperson number
8. Salesperson name
9. Date of hire
10. Commission rate
The value of field 1 (C, P, or S) determines the format of the input record. The
following sample shows a section of IGYTABLE:
S1111Edyth Phillips 062484042327
S1122Chuck Morgan 052780084425
S1133Art Tung 022882061728
S1144Billy Jim Bob 010272121150
S1155Chris Preston 122083053377
S1166Al Willie Roz 111276100000
P01Footballs 0000620
P02Football Equipment 0032080
P03Football Uniform 0004910
P04Basketballs 0002220
P05Basketball Rim/Board0008830
P06Basketball Uniform 0004220
C01L. A. Sports
C02Gear Up
C03Play Outdoors
C04Sports 4 You
C05Sports R US
Running IGYTSALE
You can run IGYTSALE under OS/390 or CMS.
All the files required by the IGYTSALE program are supplied on the product
installation tape. These files (IGYTSALE, IGYTCRC, IGYTPRC, IGYTSRC,
IGYTABLE, IGYTRANA) are located in the IGY.V2R2M0.SIGYSAMP data set.
Data set and procedure names can be changed at installation time. Check with
your system programmer to verify these names.
Do not change these options on the CBL card in the source file for IGYTSALE:
LIB
NOCMPR2
NONUMBER
SEQUENCE
NOFLAGMIG
NONUMBER
QUOTE
With these options in effect, the program might not cause any diagnostic messages
to be issued. You can use the sequence number string in the source file to search
for the language elements used.
When you run IGYTSALE, the following messages are printed to the SYSOUT data
set:
Program IGYTSALE Begins
There were 00041 records processed in this program
Program IGYTSALE Normal End
RELATED TASKS
“Running IGYTSALE under OS/390”
“Running IGYTSALE under CMS”
RELATED REFERENCES
“Input data for IGYTSALE” on page 597
“Reports produced by IGYTSALE” on page 598
“Language elements and concepts that are illustrated” on page 604
Use the following JCL to compile, link-edit, and run the IGYTSALE program.
Insert the information for your system or installation in the fields that are shown
in lowercase letters (accounting information).
//IGYTSALE JOB (acct-info),'IGYTSALE',MSGLEVEL=(1,1),TIME=(0,29)
//TEST EXEC IGYWCLG
//COBOL.SYSLIB DD DSN=IGY.V2R2M0.SIGYSAMP,DISP=SHR
//COBOL.SYSIN DD DSN=IGY.V2R2M0.SIGYSAMP(IGYTSALE),DISP=SHR
//GO.SYSOUT DD SYSOUT=A
//GO.IGYTABLE DD DSN=IGY.V2R2M0.SIGYSAMP(IGYTABLE),DISP=SHR
//GO.IGYTRANS DD DSN=IGY.V2R2M0.SIGYSAMP(IGYTRANA),DISP=SHR
//GO.IGYPRINT DD SYSOUT=A,DCB=BLKSIZE=133
//GO.IGYPRT2 DD SYSOUT=A,DCB=BLKSIZE=133
//
To run IGYTSALE under CMS, first access the COBOL for OS/390 & VM product
using the CP LINK and ACCESS commands, and then do the following steps:
1. Issue the following FILEDEF and GLOBAL MACLIB commands:
FILEDEF * CLEAR
FILEDEF SYSLIB DISK SIGYSAMP MACLIB *
GLOBAL MACLIB SIGYSAMP
At the end of the compilation, LISTING and TEXT files are created and sent to
your disk.
4. Identify the data sets that are used by issuing FILEDEF commands (where “*”
designates a disk):
The following table lists the language elements and programming concepts that the
sample programs illustrate. The language element or concept is described, and the
sequence string is shown. The sequence string is the special character string that
appears in the sequence field of the source file. You can use this string as a search
argument for locating the elements in the listing.
IBM may have patents or pending patent applications covering subject matter
described 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:
IBM Corporation
J74/G4
555 Bailey Avenue
P.O. Box 49023
San Jose, CA 95161-9023
U.S.A.
For license inquiries regarding double-byte (DBCS) information, contact the IBM
Intellectual Property Department in your country or send inquiries, in writing, to:
IBM World Trade Asia Corporation
Licensing
2-31 Roppongi 3-chome, Minato-ku
Tokyo 106, Japan
The following paragraph does not apply to the United Kingdom or any other
country where such provisions are inconsistent with local law:
INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS
PUBLICATION “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS
FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of express or
implied warranties in certain transactions, therefore, this statement may not apply
to you.
Any references in this publication to non-IBM Web sites are provided for
convenience only and do not in any manner serve as an endorsement of those Web
sites. The materials at those Web sites are not part of the materials for this IBM
product and use of those Web sites is at your own risk.
AIX MVS
CICS OpenEdition
CICS/ESA OS/390
COBOL/370 RACF
DB2 SOM
DFSMS SOMobjects
DFSORT System Object Model
IBM System/390
IMS VisualAge
IMS/ESA VM/ESA
Language Environment
UNIX is a registered trademark in the United States and other countries licensed
exclusively through X/Open Company Limited.
Other company, product or service names may be the trademarks or service marks
of others.
If you are viewing this information in softcopy, the photographs and color
illustrations may not appear.
This glossary includes terms and definitions from * alphanumeric function. A function whose value is
the following publications: composed of a string of one or more characters from
the character set of the computer.
v American National Standard Programming
Language COBOL, ANSI X3.23-1985 (copyright * alternate record key. A key, other than the prime
1985 American National Standards Institute, record key, whose contents identify a record within an
Inc.) (ISO 1989: 1985), as amended by indexed file.
X3.23a-1989 (ISO 1989/Amendment 1) and
X3.23b-1993 (ISO1989/Amendment 2). ANSI (American National Standards Institute). An
organization that consists of producers, consumers, and
v American National Standard Dictionary for general-interest groups and establishes the procedures
Information Systems ANSI X3.172-1990, by which accredited organizations create and maintain
copyright 1990 by the American National voluntary industry standards in the United States.
Standards Institute (ANSI). Copies may be
purchased from the American National APPC. See advanced program-to-program communication
Standards Institute, 11 West 42nd Street, New (APPC).
York, New York 10036.
* argument. An identifier, a literal, an arithmetic
American National Standard definitions are expression, or a function-identifier that specifies a value
preceded by an asterisk (*). to be used in the evaluation of a function.
* ascending key. A key upon the values of which data * block. A physical unit of data that is normally
is ordered, starting with the lowest value of the key up composed of one or more logical records. For mass
to the highest value of the key, in accordance with the storage files, a block can contain a portion of a logical
rules for comparing data items. record. The size of a block has no direct relationship to
the size of the file within which the block is contained
ASCII. American National Standard Code for or to the size of the logical records that are either
Information Interchange. The standard code uses a contained within the block or that overlap the block.
coded character set that consists of seven-bit coded Synonymous with physical record.
characters (eight bits including parity check). The
standard is used for information interchange between breakpoint. A place in a computer program, usually
data processing systems, data communication systems, specified by an instruction, where external intervention
and associated equipment. The ASCII set consists of or a monitor program can interrupt the program as it
control characters and graphic characters. runs.
Extension:IBM has defined an extension to ASCII code
Btrieve file system. A key-indexed record
(characters 128-255).
management system that allows applications to manage
assignment-name. A name that identifies the records by key value, sequential access method, or
organization of a COBOL file and the name by which it random access method. IBM COBOL supports COBOL
is known to the system. sequential and indexed file input-output language
through Btrieve (available from Btrieve Technologies,
* assumed decimal point. A decimal point position Inc.). You can use the Btrieve file system to access files
that does not involve the existence of an actual created by VisualAge CICS Enterprise Application
character in a data item. The assumed decimal point Development.
has logical meaning but no physical representation.
buffer. A portion of storage that is used to hold input
* AT END condition. A condition that is caused during or output data temporarily.
the execution of a READ, RETURN, or SEARCH statement
under certain conditions: built-in function. See intrinsic function.
v A READ statement runs on a sequentially accessed file byte. A string that consists of a certain number of bits,
when no next logical record exists in the file, or usually eight, treated as a unit, and representing a
when the number of significant digits in the relative character.
record number is larger than the size of the relative
key data item, or when an optional input file is not
present. C
v A RETURN statement runs when no next logical record
callable services. In Language Environment, a set of
exists for the associated sort or merge file.
services that a COBOL program can invoke by using
v A SEARCH statement runs when the search operation the conventional Language Environment-defined call
terminates without satisfying the condition specified interface. All programs that share the Language
in any of the associated WHEN phrases. Environment conventions can use these services.
* class definition. The COBOL source unit that * COBOL word. See word.
defines a class.
code page. An assignment of graphic characters and
class hierarchy. A tree-like structure that shows control function meanings to all code points. For
relationships among object classes. It places one class at example, one code page could assign characters and
the top and one or more layers of classes below it. meanings to 256 code points for eight-bit code, and
Synonymous with inheritance hierarchy. another code page could assign characters and
meanings to 128 code points for seven-bit code. For
* class identification entry. An entry in the CLASS-ID
example, the usual IBM code page for English on the
paragraph of the IDENTIFICATION DIVISION; this entry
workstation is IBM-850 and on the host is IBM-1047.
contains clauses that specify the class-name and assign
selected attributes to the class definition. * collating sequence. The sequence in which the
characters that are acceptable to a computer are
class library. A collection of classes.
ordered for purposes of sorting, merging, comparing,
* class-name. A user-defined word that is defined in and for processing indexed files sequentially.
the SPECIAL-NAMES paragraph of the ENVIRONMENT
* column. A character position within a print line. The
DIVISION; this word assigns a name to the proposition
columns are numbered from 1, by 1, starting at the
Glossary 613
leftmost character position of the print line and date format except for the year part, which can be
extending to the rightmost position of the print line. windowed or expanded. For example, a windowed
date field with DATE FORMAT YYXXX is compatible
* combined condition. A condition that is the result of with:
connecting two or more conditions with the AND or the
– Another windowed date field with DATE FORMAT
OR logical operator. See also condition and negated
YYXXX
combined condition.
– An expanded date field with DATE FORMAT YYYYXXX
* comment-entry. An entry in the IDENTIFICATION
DIVISION that can be any combination of characters * compile. (1) To translate a program expressed in a
from the character set of the computer. high-level language into a program expressed in an
intermediate language, assembly language, or a
* comment line. A source program line represented by computer language. (2) To prepare a machine-language
an asterisk (*) in the indicator area of the line and any program from a computer program written in another
characters from the character set of the computer in programming language by making use of the overall
area A and area B of that line. The comment line serves logic structure of the program, or generating more than
only for documentation in a program. A special form of one computer instruction for each symbolic statement,
comment line represented by a slant (/) in the indicator or both, as well as performing the function of an
area of the line and any characters from the character assembler.
set of the computer in area A and area B of that line
causes page ejection before printing the comment. * compile time. The time at which a COBOL source
program is translated, by a COBOL compiler, to a
* common program. A program that, despite being COBOL object program.
directly contained within another program, can be
called from any program directly or indirectly compiler. A program that translates a program written
contained in that other program. in a higher-level language into a machine-language
object program.
compatible date field. The meaning of the term
compatible, when applied to date fields, depends on the compiler-directing statement. A statement (or
COBOL division in which the usage occurs: directive), beginning with a compiler-directing verb,
that causes the compiler to take a specific action during
v DATA DIVISION
compilation. Compiler directives are contained in the
Two date fields are compatible if they have identical
COBOL source program. Therefore, you can specify
USAGE and meet at least one of the following
different suboptions of a directive within the source
conditions:
program by using multiple compiler-directing
– They have the same date format. statements.
– Both are windowed date fields, where one consists
only of a windowed year, DATE FORMAT YY. * complex condition. A condition in which one or
more logical operators act upon one or more
– Both are expanded date fields, where one consists
conditions. See also condition, negated simple condition,
only of an expanded year, DATE FORMAT YYYY.
and negated combined condition.
– One has DATE FORMAT YYXXXX, and the other has
YYXX. complex ODO. Certain forms of the OCCURS DEPENDING
– One has DATE FORMAT YYYYXXXX, and the other has ON clause:
YYYYXX. v Variably located item or group: A data item
described by an OCCURS clause with the DEPENDING ON
A windowed date field can be subordinate to a data option is followed by a nonsubordinate data item or
item that is an expanded date group. The two date group.
fields are compatible if the subordinate date field has v Variably located table: A data item described by an
USAGE DISPLAY, starts two bytes after the start of the OCCURS clause with the DEPENDING ON option is
group expanded date field, and the two fields meet followed by a nonsubordinate data item described by
at least one of the following conditions: an OCCURS clause.
– The subordinate date field has a DATE FORMAT v Table with variable-length elements: A data item
pattern with the same number of Xs as the DATE described by an OCCURS clause contains a subordinate
FORMAT pattern of the group date field. data item described by an OCCURS clause with the
– The subordinate date field has DATE FORMAT YY. DEPENDING ON option.
– The group date field has DATE FORMAT YYYYXXXX v Index name for a table with variable-length elements.
and the subordinate date field has DATE FORMAT v Element of a table with variable-length elements.
YYXX.
v PROCEDURE DIVISION
Two date fields are compatible if they have the same
condition. An exception that has been enabled, or * contiguous items. Items that are described by
recognized, by Language Environment and thus is consecutive entries in the DATA DIVISION, and that bear
eligible to activate user and language condition a definite hierarchic relationship to each other.
handlers. Any alteration to the normal programmed
flow of an application. Conditions can be detected by copy file. A file or library member containing a
the hardware or the operating system and result in an sequence of code that is included in the source
interrupt. They can also be detected by program at compile time using the COPY statement. The
language-specific generated code or language library file can be created by the user, supplied by COBOL, or
code. supplied by another product. Synonymous with
copybook.
* condition. A status of a program at run time for
which a truth value can be determined. When used in CORBA. The Common Object Request Broker
these language specifications in or in reference to Architecture established by the Object Management
’condition’ (condition-1, condition-2,...) of a general Group. IBM’s Interface Definition Language, which is
format, the term refers to a conditional expression that used to describe the interface for SOM classes, is fully
consists of either a simple condition optionally compliant with CORBA standards. See also Interface
parenthesized or a combined condition (consisting of Definition Language.
the syntactically correct combination of simple
conditions, logical operators, and parentheses) for * counter. A data item used for storing numbers or
which a truth value can be determined. See also simple number representations in a manner that permits these
condition, complex condition, negated simple condition, numbers to be increased or decreased by the value of
combined condition, and negated combined condition. another number, or to be changed or reset to zero or to
an arbitrary positive or negative value.
* conditional expression. A simple condition or a
complex condition specified in an EVALUATE, IF, cross-reference listing. The portion of the compiler
PERFORM, or SEARCH statement. See also simple condition listing that contains information on where files, fields,
and complex condition. and indicators are defined, referenced, and modified in
a program.
* conditional phrase. A phrase that specifies the
action to be taken upon determination of the truth currency-sign value. A character string that identifies
value of a condition that results from the execution of a the monetary units stored in a numeric-edited item.
conditional statement. Typical examples are $, USD, and EUR. A currency-sign
value can be defined by either the CURRENCY
* conditional statement. A statement that specifies compiler option or the CURRENCY SIGN clause in the
that the truth value of a condition is to be determined SPECIAL-NAMES paragraph of the ENVIRONMENT DIVISION.
and that the subsequent action of the object program If the CURRENCY SIGN clause is not specified and the
depends on this truth value. NOCURRENCY compiler option is in effect, the dollar sign
($) is used as the default currency-sign value. See also
* conditional variable. A data item one or more currency symbol.
values of which has a condition-name assigned to it.
currency symbol. A character used in a PICTURE clause
* condition-name. A user-defined word that assigns a to indicate the position of a currency sign value in a
name to a subset of values that a conditional variable numeric-edited item. A currency symbol can be defined
can assume; or a user-defined word assigned to a status by either the CURRENCY compiler option or the
of an implementor-defined switch or device. When CURRENCY SIGN clause in the SPECIAL-NAMES paragraph
condition-name is used in the general formats, it of the ENVIRONMENT DIVISION. If the CURRENCY SIGN
represents a unique data item reference that consists of clause is not specified and the NOCURRENCY
a syntactically correct combination of a condition-name, compiler option is in effect, the dollar sign ($) is used
qualifiers, and subscripts, as required for uniqueness of as the default currency sign value and currency
reference. symbol. Multiple currency symbols and currency sign
values can be defined. See also currency sign value.
* condition-name condition. The proposition (for
which a truth value can be determined) that the value * current record. In file processing, the record that is
of a conditional variable is a member of the set of available in the record area associated with a file.
values attributed to a condition-name associated with
the conditional variable.
Glossary 615
* current volume pointer. A conceptual entity that date format. The date pattern of a date field, specified
points to the current volume of a sequential file. in either of the following ways:
v Explicitly, by the DATE FORMAT clause or DATEVAL
D intrinsic function argument-2
v Implicitly, by statements and intrinsic functions that
* data clause. A clause, appearing in a data return date fields (for details, see Date field in IBM
description entry in the DATA DIVISION of a COBOL COBOL Language Reference)
program, that provides information describing a
particular attribute of a data item. DBCS. See double-byte character set (DBCS).
* data description entry. An entry in the DATA * debugging line. Any line with a D in the indicator
DIVISION of a COBOL program that is composed of a area of the line.
level-number followed by a data-name, if required, and
then followed by a set of data clauses, as required. * debugging section. A section that contains a USE FOR
DEBUGGING statement.
DATA DIVISION. One of the four main components of a
COBOL program, class definition, or method definition. * declarative sentence. A compiler-directing sentence
The DATA DIVISION describes the data to be processed that consists of a single USE statement terminated by
by the object program, class, or method: files to be used the separator period.
and the records contained within them; internal
* declaratives. A set of one or more special-purpose
working-storage records that will be needed; data to be
sections, written at the beginning of the PROCEDURE
made available in more than one program in the
DIVISION, the first of which is preceded by the key
COBOL run unit. (A class DATA DIVISION contains only
word DECLARATIVE and the last of which is followed by
the WORKING-STORAGE SECTION.)
the key words END DECLARATIVES. A declarative is
* data item. A unit of data (excluding literals) defined composed of a section header, followed by a USE
by a COBOL program or by the rules for function compiler-directing sentence, followed by a set of zero,
evaluation. one, or more associated paragraphs.
* data-name. A user-defined word that names a data * de-edit. The logical removal of all editing characters
item described in a data description entry. When used from a numeric-edited data item in order to determine
in the general formats, data-name represents a word the unedited numeric value of the item.
that must not be reference-modified, subscripted, or
* delimited scope statement. Any statement that
qualified unless specifically permitted by the rules for
includes its explicit scope terminator.
the format.
* delimiter. A character or a sequence of contiguous
date field. Any of the following:
characters that identify the end of a string of characters
v A data item whose data description entry includes a and separate that string of characters from the
DATE FORMAT clause. following string of characters. A delimiter is not part of
v A value returned by one of the following intrinsic the string of characters that it delimits.
functions:
* descending key. A key upon the values of which
DATE-OF-INTEGER data is ordered starting with the highest value of key
DATE-TO-YYYYMMDD down to the lowest value of key, in accordance with the
DATEVAL rules for comparing data items.
DAY-OF-INTEGER
digit. Any of the numerals from 0 through 9. In
DAY-TO-YYYYDDD
COBOL, the term is not used to refer to any other
YEAR-TO-YYYY
symbol.
YEARWINDOW
v The conceptual data items DATE, DATE * digit position. The amount of physical storage
YYYYMMDD, DAY, and DAY YYYYDDD of the required to store a single digit. This amount can vary
ACCEPT statement. depending on the usage specified in the data
v The result of certain arithmetic operations (for description entry that defines the data item.
details, see Arithmetic with date fields in IBM
* direct access. The facility to obtain data from storage
COBOL Language Reference).
devices or to enter data into a storage device in such a
way that the process depends only on the location of
The term date field refers to both expanded date field and
that data and not on a reference to data previously
windowed date field. See also nondate.
accessed.
* dynamic access. An access mode in which specific encapsulation. In object-oriented programming, the
logical records can be obtained from or placed into a technique that is used to hide the inherent details of an
mass storage file in a nonsequential manner and object. The object provides an interface that queries and
obtained from a file in a sequential manner during the manipulates the data without exposing its underlying
scope of the same OPEN statement. structure. Synonymous with information hiding.
dynamic link library (DLL). A file containing enclave. When running under the Language
executable code and data that are bound to a program Environment product, an enclave is analogous to a run
at load time or run time, rather than during linking. unit. An enclave can create other enclaves on OS/390
Several applications can share the code and data in a and CMS by a LINK, on CMS by CMSCALL, and the use
DLL simultaneously. Although a DLL is not part of the of the system() function of C.
Glossary 617
*end class header. A combination of words, followed expanded year. A date field that consists only of a
by a separator period, that indicates the end of a four-digit year. Its value includes the century: for
COBOL class definition. The end class header is: example, 1998. Compare with windowed year.
END CLASS class-name.
* explicit scope terminator. A reserved word that
*end method header. A combination of words, terminates the scope of a particular PROCEDURE DIVISION
followed by a separator period, that indicates the end statement.
of a COBOL method definition. The end method header
exponent. A number that indicates the power to
is:
which another number (the base) is to be raised.
END METHOD method-name. Positive exponents denote multiplication; negative
exponents denote division; and fractional exponents
* end of PROCEDURE DIVISION. The physical position of
denote a root of a quantity. In COBOL, an exponential
a COBOL source program after which no further
expression is indicated with the symbol ** followed by
procedures appear.
the exponent.
* end program header. A combination of words,
* expression. An arithmetic or conditional expression.
followed by a separator period, that indicates the end
of a COBOL source program. The end program header * extend mode. The state of a file after execution of an
is: OPEN statement, with the EXTEND phrase specified for
END PROGRAM program-name. that file, and before the execution of a CLOSE statement,
without the REEL or UNIT phrase for that file.
* entry. Any descriptive set of consecutive clauses
terminated by a separator period and written in the extensions. Certain COBOL syntax and semantics
IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, or supported by IBM compilers in addition to those
DATA DIVISION of a COBOL program. described in ANSI Standard.
* environment clause. A clause that appears as part of * external data. The data that is described in a
an ENVIRONMENT DIVISION entry. program as external data items and external file
connectors.
ENVIRONMENT DIVISION. One of the four main
component parts of a COBOL program, class definition, * external data item. A data item that is described as
or method definition. The ENVIRONMENT DIVISION part of an external record in one or more programs of a
describes the computers where the source program is run unit and that can be referenced from any program
compiled and those where the object program is run. It in which it is described.
provides a linkage between the logical concept of files
and their records, and the physical aspects of the * external data record. A logical record that is
devices on which files are stored. described in one or more programs of a run unit and
whose constituent data items can be referenced from
environment-name. A name, specified by IBM, that any program in which they are described.
identifies system logical units, printer and card punch
control characters, report codes, program switches or external decimal item. A format for representing
all of these. When an environment-name is associated numbers in which the digit is contained in bits 4
with a mnemonic-name in the ENVIRONMENT DIVISION, through 7 and the sign is contained in bits 0 through 3
the mnemonic-name can be substituted in any format of the rightmost byte. Bits 0 through 3 of all other bytes
in which such substitution is valid. contain 1 (hex F). For example, the decimal value of
+123 is represented as 1111 0001 1111 0010 1111 0011.
environment variable. Any of a number of variables Synonymous with zoned decimal item.
that describe the way an operating system is going to
run and the devices it is going to recognize. * external file connector. A file connector that is
accessible to one or more object programs in the run
EXE. See executable file (EXE). unit.
executable file (EXE). A file that contains programs or external floating-point item. A format for
commands that perform operations or actions to be representing numbers in which a real number is
taken. represented by a pair of distinct numerals. In a
floating-point representation, the real number is the
execution time. See run time. product of the fixed-point part (the first numeral), and
a value obtained by raising the implicit floating-point
execution-time environment. See run-time environment. base to a power denoted by the exponent (the second
numeral). For example, a floating-point representation
expanded date field. A date field containing an
of the number 0.0001234 is: 0.1234 -3, where 0.1234 is
expanded (four-digit) year. See also date field and
the mantissa and -3 is the exponent.
expanded year.
* file clause. A clause that appears as part of any of * fixed-length record. A record associated with a file
the following DATA DIVISION entries: file description whose file description or sort-merge description entry
entry (FD entry) and sort-merge file description entry requires that all records contain the same number of
(SD entry). character positions.
* file connector. A storage area that contains fixed-point number. A numeric data item defined
information about a file and is used as the linkage with a PICTURE clause that specifies the location of an
between a file-name and a physical file and between a optional sign, the number of digits it contains, and the
file-name and its associated record area. location of an optional decimal point. The format can
be either binary, packed decimal, or external decimal.
FILE-CONTROL. The name of an ENVIRONMENT DIVISION
paragraph in which the data files for a given source floating-point number. A numeric data item that
program are declared. contains a fraction and an exponent. Its value is
obtained by multiplying the fraction by the base of the
* file control entry. A SELECT clause and all its numeric data item raised to the power that the
subordinate clauses that declare the relevant physical exponent specifies.
attributes of a file.
* format. A specific arrangement of a set of data.
* file description entry. An entry in the FILE SECTION
of the DATA DIVISION that is composed of the level * function. A temporary data item whose value is
indicator FD, followed by a file-name, and then determined at the time the function is referenced
followed by a set of file clauses as required. during the execution of a statement.
Glossary 619
G * implicit scope terminator. A separator period that
terminates the scope of any preceding unterminated
statement, or a phrase of a statement that by its
* global name. A name that is declared in only one
occurrence indicates the end of the scope of any
program but that can be referenced from the program
statement contained within the preceding phrase.
and from any program contained within the program.
Condition-names, data-names, file-names, * index. A computer storage area or register, the
record-names, report-names, and some special registers content of which represents the identification of a
can be global names. particular element in a table.
* group item. A data item that is composed of * index data item. A data item in which the values
subordinate data items. associated with an index-name can be stored in a form
specified by the implementor.
H indexed data-name. An identifier that is composed of
header label. (1) A file label or data set label that a data-name, followed by one or more index-names
precedes the data records on a unit of recording media. enclosed in parentheses.
(2) Synonym for beginning-of-file label.
* indexed file. A file with indexed organization.
hierarchical file system (HFS). A collection of files
* indexed organization. The permanent logical file
and directories that are organized in a hierarchical
structure in which each record is identified by the
structure and can be accessed by using OS/390 UNIX
value of one or more keys within that record.
System Services.
indexing. Synonymous with subscripting using
* high-order end. The leftmost character of a string of
index-names.
characters.
* index-name. A user-defined word that names an
I index associated with a specific table.
* imperative statement. A statement that either begins * input-output file. A file that is opened in the I-O
with an imperative verb and specifies an unconditional mode.
action to be taken or is a conditional statement that is
delimited by its explicit scope terminator (delimited * INPUT-OUTPUT SECTION. The section of the
scope statement). An imperative statement can consist ENVIRONMENT DIVISION that names the files and the
of a sequence of imperative statements. external media required by an object program or
method and that provides information required for
* input procedure. A set of statements, to which intermediate result. An intermediate field that
control is given during the execution of a SORT contains the results of a succession of arithmetic
statement, for the purpose of controlling the release of operations.
specified records to be sorted.
* internal data. The data that is described in a
instance data. (1) Data that defines the state of an program and excludes all external data items and
object. The instance data introduced by a class is external file connectors. Items described in the LINKAGE
defined in the WORKING-STORAGE SECTION of the DATA SECTION of a program are treated as internal data.
DIVISION of the class definition. The state of an object
also includes the state of the instance variables * internal data item. A data item that is described in
introduced by base classes that are inherited by the one program in a run unit. An internal data item can
current class. A separate copy of the instance data is have a global name.
created for each object instance. (2) In Visual Builder,
private data that belongs to a given object and is internal decimal item. A format in which each byte in
hidden from direct access by all other objects. Data a field except the rightmost byte represents two
members can be accessed only by the methods of the numeric digits. The rightmost byte contains one digit
defining class and its subclasses. and the sign. For example, the decimal value +123 is
represented as 0001 0010 0011 1111. Synonymous with
* integer. (1) A numeric literal that does not include packed decimal.
any digit positions to the right of the decimal point. (2)
A numeric data item defined in the DATA DIVISION that * internal file connector. A file connector that is
does not include any digit positions to the right of the accessible to only one object program in the run unit.
decimal point. (3) A numeric function whose definition
* intrarecord data structure. The entire collection of
provides that all digits to the right of the decimal point
groups and elementary data items from a logical record
are zero in the returned value for any possible
that a contiguous subset of the data description entries
evaluation of the function.
defines. These data description entries include all
integer function. A function whose category is entries whose level-number is greater than the
numeric and whose definition does not include any level-number of the first data description entry
digit positions to the right of the decimal point. describing the intra-record data structure.
Interactive System Productivity Facility (ISPF). An intrinsic function. A predefined function, such as a
IBM software product that provides a menu-driven commonly used arithmetic function, called by a built-in
interface for the TSO or VM user. ISPF includes library function reference.
utilities, a powerful editor, and dialog management.
* invalid key condition. A condition, at run time,
interface. The information that a client must know to caused when a specific value of the key associated with
use a class—the names of its attributes and the an indexed or relative file is determined to be not valid.
signatures of its methods. With direct-to-SOM
* I-O-CONTROL. The name of an ENVIRONMENT DIVISION
compilers such as COBOL, the native language syntax
paragraph in which object program requirements for
for class definitions can define the interface to a class.
rerun points, sharing of same areas by several data
Classes implemented in other languages might have
files, and multiple file storage on a single input-output
their interfaces defined directly in SOM Interface
device are specified.
Definition Language (IDL). The COBOL compiler has a
compiler option, IDLGEN, to automatically generate * I-O-CONTROL entry. An entry in the I-O-CONTROL
IDL for a COBOL class. paragraph of the ENVIRONMENT DIVISION; this entry
contains clauses that provide information required for
Interface Definition Language (IDL). The formal
the transmission and handling of data on named files
language (independent of any programming language)
during the execution of a program.
by which the interface for a class of objects is defined
in a IDL file, which the SOM compiler then interprets * I-O mode. The state of a file after execution of an
to create an implementation template file and binding OPEN statement, with the I-O phrase specified, for that
files. The Interface Definition Language is fully
Glossary 621
file and before the execution of a CLOSE statement * level indicator. Two alphabetic characters that
without the REEL or UNIT phase for that file. identify a specific type of file or a position in a
hierarchy. The level indicators in the DATA DIVISION are:
* I-O status. A conceptual entity that contains the CD, FD, and SD.
two-character value indicating the resulting status of an
input-output operation. This value is made available to * level-number. A user-defined word (expressed as a
the program through the use of the FILE STATUS clause two-digit number) that indicates the hierarchical
in the file control entry for the file. position of a data item or the special properties of a
data description entry. Level-numbers in the range from
is-a. A relationship that characterizes classes and 1 through 49 indicate the position of a data item in the
subclasses in an inheritance hierarchy. Subclasses that hierarchical structure of a logical record. Level-numbers
have an is-a relationship to a class inherit from that in the range 1 through 9 can be written either as a
class. single digit or as a zero followed by a significant digit.
Level-numbers 66, 77 and 88 identify special properties
ISPF. See Interactive System Productivity Facility (ISPF). of a data description entry.
iteration structure. A program processing logic in * library-name. A user-defined word that names a
which a series of statements is repeated while a COBOL library that the compiler is to use for
condition is true or until a condition is true. compiling a given source program.
* key of reference. The key, either prime or alternate, * linage-counter. A special register whose value points
currently being used to access records within an to the current position within the page body.
indexed file.
link. (1) The combination of the link connection (the
* keyword. A reserved word or function-name whose transmission medium) and two link stations, one at
presence is required when the format in which the each end of the link connection. A link can be shared
word appears is used in a source program. among multiple links in a multipoint or token-ring
configuration. (2) To interconnect items of data or
kilobyte (KB). One kilobyte equals 1024 bytes. portions of one or more computer programs; for
example, linking object programs by a linkage editor to
produce an executable file.
L
LINKAGE SECTION. The section in the DATA DIVISION of
* language-name. A system-name that specifies a the called program that describes data items available
particular programming language. from the calling program. Both the calling program and
the called program can refer to these data items.
Language Environment-conforming. A characteristic
of compiler products (such as COBOL for MVS & VM, literal. A character string whose value is specified
COBOL for OS/390 & VM, C/C++ for MVS and VM, either by the ordered set of characters comprising the
PL/I for MVS and VM) that produce object code string or by the use of a figurative constant.
conforming to the Language Environment format.
little-endian. The default format that the PC uses to
last-used state. A state that a program is in if its store binary data. In this format, the most significant
internal values remain the same as when the program digit is on the highest address. Compare with
was exited (the values are not reset to their initial big-endian.
values).
locale. A set of attributes for a program execution
* letter. A character belonging to one of the following environment indicating culturally sensitive
two sets: considerations, such as character code page, collating
1. Uppercase letters: A, B, C, D, E, F, G, H, I, J, K, L, sequence, date and time format, monetary value
M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z representation, numeric value representation, or
language.
2. Lowercase letters: a, b, c, d, e, f, g, h, i, j, k, l, m, n,
o, p, q, r, s, t, u, v, w, x, y, z
* low-order end. The rightmost character of a string of module definition file. A file that describes the code
characters. segments within a load module.
* megabyte (M). One megabyte equals 1,048,576 bytes. * negated combined condition. The NOT logical
operator immediately followed by a parenthesized
* merge file. A collection of records to be merged by a combined condition. See also condition and combined
MERGE statement. The merge file is created and can be condition.
used only by the merge function.
* negated simple condition. The NOT logical operator
metaclass. A SOM class whose instances are SOM immediately followed by a simple condition. See also
class-objects. The methods defined in metaclasses are condition and simple condition.
executed without requiring any object instances of the
class to exist, and are frequently used to create nested program. A program that is directly contained
instances of the class. within another program.
method. Procedural code that defines an operation * next executable sentence. The next sentence to
supported by an object and that is executed by an which control will be transferred after execution of the
INVOKE statement on that object. current statement is complete.
* method definition. The COBOL source unit that * next executable statement. The next statement to
defines a method. which control will be transferred after execution of the
current statement is complete.
* method identification entry. An entry in the
METHOD-ID paragraph of the IDENTIFICATION DIVISION; * next record. The record that logically follows the
this entry contains clauses that specify the current record of a file.
method-name and assign selected attributes to the
method definition.
Glossary 623
* noncontiguous items. Elementary data items in the Builder, a computer representation of something that a
WORKING-STORAGE SECTION and LINKAGE SECTION that user can work with to perform a task. An object can
bear no hierarchic relationship to other data items. appear as text or as an icon.
nondate. Any of the following: object code. Output from a compiler or assembler that
v A data item whose date description entry does not is itself executable machine code or is suitable for
include the DATE FORMAT clause processing to produce executable machine code.
v A literal * OBJECT-COMPUTER. The name of an ENVIRONMENT
v A date field that has been converted using the UNDATE DIVISION paragraph in which the computer
function environment, where the object program is run, is
v A reference-modified date field described.
v The result of certain arithmetic operations that can * object computer entry. An entry in the
include date field operands; for example, the OBJECT-COMPUTER paragraph of the ENVIRONMENT
difference between two compatible date fields DIVISION; this entry contains clauses that describe the
computer environment in which the object program is
* nonnumeric item. A data item whose description
to be executed.
permits its content to be composed of any combination
of characters from the character set of the computer. object deck. A portion of an object program suitable
Certain categories of nonnumeric items can be formed as input to a linkage editor. Synonymous with object
from more restricted character sets. module and text deck.
* nonnumeric literal. A literal that is bounded by object instance. See object.
quotation marks. The string of characters can include
any character in the character set of the computer. object module. Synonym for object deck or text deck.
null. A figurative constant that is used to assign, to * object of entry. A set of operands and reserved
pointer data items, the value of an address that is not words, within a DATA DIVISION entry of a COBOL
valid. NULLS can be used wherever NULL can be used. program, that immediately follows the subject of the
entry.
* numeric character. A character that belongs to the
following set of digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. object-oriented programming. A programming
approach based on the concepts of encapsulation and
numeric-edited item. A numeric item that is in a form inheritance. Unlike procedural programming
appropriate for use in printed output. It can consist of techniques, object-oriented programming concentrates
external decimal digits from 0 through 9, the decimal on the data objects that comprise the problem and how
point, commas, the dollar sign, editing sign control they are manipulated, not on how something is
symbols, plus other editing symbols. accomplished.
* numeric function. A function whose class and * object program. A set or group of executable
category are numeric but that for some possible machine-language instructions and other material
evaluation does not satisfy the requirements of integer designed to interact with data to provide problem
functions. solutions. In this context, an object program is generally
the machine language result of the operation of a
* numeric item. A data item whose description
COBOL compiler on a source program. Where there is
restricts its content to a value represented by characters
no danger of ambiguity, the word program can be used
chosen from the digits 0 through 9. If signed, the item
in place of object program.
can also contain a +, -, or other representation of an
operational sign. object reference. A value that identifies an instance of
a class. If the class is not specified, the object reference
* numeric literal. A literal composed of one or more
is universal and applies to instances of any class.
numeric characters that can contain a decimal point or
an algebraic sign, or both. The decimal point must not * object time. The time at which an object program is
be the rightmost character. The algebraic sign, if executed. Synonymous with run time.
present, must be the leftmost character.
* obsolete element. A COBOL language element in
O Standard COBOL that is to be deleted from the next
revision of Standard COBOL.
object. (1) An entity that has state (its data values) ODBC. See Open Database Connectivity (ODBC).
and operations (its methods). An object is a way to
encapsulate state and behavior. Each object in the class ODO object. In the example below, X is the object of
is said to be an instance of the class. (2) In Visual the OCCURS DEPENDING ON clause (ODO object).
* open mode. The state of a file after execution of an page. A vertical division of output data that represents
OPEN statement for that file and before the execution of a physical separation of the data. The separation is
a CLOSE statement without the REEL or UNIT phrase for based on internal logical requirements or external
that file. The particular open mode is specified in the characteristics of the output medium or both.
OPEN statement as either INPUT, OUTPUT, I-O, or EXTEND.
* page body. That part of the logical page in which
* operand. (1) The general definition of operand is lines can be written or spaced or both.
”the component that is operated upon.“ (2) For the
* paragraph. In the PROCEDURE DIVISION, a
purposes of this document, any lowercase word (or
paragraph-name followed by a separator period and by
words) that appears in a statement or entry format can
zero, one, or more sentences. In the IDENTIFICATION
be considered to be an operand and, as such, is an
DIVISION and ENVIRONMENT DIVISION, a paragraph
implied reference to the data indicated by the operand.
header followed by zero, one, or more entries.
operation. A service that can be requested of an
* paragraph header. A reserved word, followed by the
object.
separator period, that indicates the beginning of a
* operational sign. An algebraic sign that is associated paragraph in the IDENTIFICATION DIVISION and
with a numeric data item or a numeric literal, to ENVIRONMENT DIVISION. The permissible paragraph
indicate whether its value is positive or negative. headers in the IDENTIFICATION DIVISION are:
PROGRAM-ID. (Program IDENTIFICATION DIVISION)
* optional file. A file that is declared as being not CLASS-ID. (Class IDENTIFICATION DIVISION)
necessarily present each time the object program is run. METHOD-ID. (Method IDENTIFICATION DIVISION)
The object program causes an interrogation for the AUTHOR.
presence or absence of the file. INSTALLATION.
DATE-WRITTEN.
* optional word. A reserved word that is included in DATE-COMPILED.
a specific format only to improve the readability of the SECURITY.
language. Its presence is optional to the user when the
format in which the word appears is used in a source The permissible paragraph headers in the ENVIRONMENT
program. DIVISION are:
SOURCE-COMPUTER.
* output file. A file that is opened in either output OBJECT-COMPUTER.
mode or extend mode. SPECIAL-NAMES.
REPOSITORY. (Program or Class CONFIGURATION SECTION)
* output mode. The state of a file after execution of an FILE-CONTROL.
OPEN statement, with the OUTPUT or EXTEND phrase I-O-CONTROL.
specified, for that file and before the execution of a
CLOSE statement without the REEL or UNIT phrase for * paragraph-name. A user-defined word that identifies
that file. and begins a paragraph in the PROCEDURE DIVISION.
* output procedure. A set of statements to which parameter. (1) Data passed between a calling program
control is given during execution of a SORT statement and a called program. (2) A data element in the USING
after the sort function is completed, or during clause of a method call. Arguments provide additional
execution of a MERGE statement after the merge function information that the invoked method can use to
perform the requested operation.
Glossary 625
* phrase. A phrase is an ordered set of one or more compiler-directing statements, paragraphs, procedures,
consecutive COBOL character strings that form a and sections. The PROCEDURE DIVISION for a class
portion of a COBOL procedural statement or of a contains only method definitions.
COBOL clause.
procedure integration. One of the functions of the
* physical record. See block. COBOL optimizer is to simplify calls to performed
procedures or contained programs.
pointer data item. A data item in which address
PERFORM procedure integration is the process whereby a
values can be stored. Data items are explicitly defined
PERFORM statement is replaced by its performed
as pointers with the USAGE IS POINTER clause. ADDRESS
procedures. Contained program procedure integration
OF special registers are implicitly defined as pointer
is the process where a call to a contained program is
data items. Pointer data items can be compared for
replaced by the program code.
equality or moved to other pointer data items.
* procedure-name. A user-defined word that is used
port. (1) To modify a computer program to enable it to
to name a paragraph or section in the PROCEDURE
run on a different platform. (2) In the Internet suite of
DIVISION. It consists of a paragraph-name (which can
protocols, a specific logical connector between the
be qualified) or a section-name.
Transmission Control Protocol (TCP) or the User
Datagram Protocol (UDP) and a higher-level protocol procedure-pointer data item. A data item in which a
or application. A port is identified by a port number. pointer to an entry point can be stored. A data item
defined with the USAGE IS PROCEDURE-POINTER clause
portability. The ability to transfer an application
contains the address of a procedure entry point.
program from one application platform to another with
relatively few changes to the source program. process. The course of events that occurs during the
execution of all or part of a program. Multiple
preinitialization. The initialization of the COBOL
processes can run concurrently, and programs that run
run-time environment in preparation for multiple calls
within a process can share resources.
from programs, especially non-COBOL programs. The
environment is not terminated until an explicit program. (1) A sequence of instructions suitable for
termination. processing by a computer. Processing may include the
use of a compiler to prepare the program for execution,
* prime record key. A key whose contents uniquely
as well as a run-time environment to execute it. (2) A
identify a record within an indexed file.
logical assembly of one or more interrelated modules.
* priority-number. A user-defined word that classifies Multiple copies of the same program can be run in
sections in the PROCEDURE DIVISION for purposes of different processes.
segmentation. Segment-numbers can contain only the
* program identification entry. In the PROGRAM-ID
characters 0 through 9. A segment-number can be
paragraph of the IDENTIFICATION DIVISION, an entry
expressed as either one or two digits.
that contains clauses that specify the program-name
private. Accessible only by methods of the class that and assign selected program attributes to the program.
defines the instance data.
* program-name. In the IDENTIFICATION DIVISION and
* procedure. A paragraph or group of logically the end program header, a user-defined word that
successive paragraphs, or a section or group of identifies a COBOL source program.
logically successive sections, within the PROCEDURE
project environment. The central location where you
DIVISION.
launch your COBOL tools such as the editor and job
* procedure branching statement. A statement that monitor and work with COBOL files or data sets.
causes the explicit transfer of control to a statement
* pseudotext. A sequence of text words, comment
other than the next executable statement in the
lines, or the separator space in a source program or
sequence in which the statements are written in the
COBOL library bounded by, but not including,
source program. The procedure branching statements
pseudotext delimiters.
are: ALTER, CALL, EXIT, EXIT PROGRAM, GO TO, MERGE, (with
the OUTPUT PROCEDURE phrase), PERFORM and SORT (with * pseudotext delimiter. Two contiguous equal sign
the INPUT PROCEDURE or OUTPUT PROCEDURE phrase). characters (==) used to delimit pseudotext.
PROCEDURE DIVISION. One of the four main component public. Accessible by getX and setX methods from
parts of a COBOL program, class definition, or method outside the class that defines the instance data X.
definition. The PROCEDURE DIVISION contains
instructions for solving a problem. The PROCEDURE * punctuation character. A character that belongs to
DIVISION for a program or method can contain the following set:
imperative statements, conditional statements,
Glossary 627
Character Meaning the main program by using either ILBOSTP0 programs,
IS NOT LESS THAN Not less than IGZERRE programs, or the RTEREUS run-time option.
IS NOT < Not less than ring. In the COBOL editor, a set of files that are
available for editing so that you can easily more
IS EQUAL TO Equal to between them.
IS = Equal to
IS NOT EQUAL TO Not equal to routine. A set of statements in a COBOL program that
IS NOT = Not equal to causes the computer to perform an operation or series
of related operations. In Language Environment, refers
to either a procedure, function, or subroutine.
IS GREATER THAN OR EQUAL Greater than or equal to
TO * routine-name. A user-defined word that identifies a
IS >= Greater than or equal to procedure written in a language other than COBOL.
IS LESS THAN OR EQUAL TO Less than or equal to * run time. The time at which an object program is
IS <= Less than or equal to executed. Synonymous with object time.
* resultant identifier. A user-defined data item that is In the PROCEDURE DIVISION, a section header is
to contain the result of an arithmetic operation. composed of a section-name, followed by the reserved
word SECTION, followed by a separator period.
reusable environment. A reusable environment is
created when you establish an assembler program as * section-name. A user-defined word that names a
section in the PROCEDURE DIVISION.
* separately compiled program. A program that, slack bytes. Bytes inserted between data items or
together with its contained programs, is compiled records to ensure correct alignment of some numeric
separately from all other programs. items. Slack bytes contain no meaningful data. In some
cases, they are inserted by the compiler; in others, it is
* separator. A character or two contiguous characters the responsibility of the programmer to insert them.
used to delimit character strings. The SYNCHRONIZED clause instructs the compiler to insert
slack bytes when they are needed for proper alignment.
* separator comma. A comma (,) followed by a space Slack bytes between records are inserted by the
used to delimit character strings. programmer.
* separator period. A period (.) followed by a space SOM. See System Object Model (SOM).
used to delimit character strings.
* sort file. A collection of records to be sorted by a
* separator semicolon. A semicolon (;) followed by a SORT statement. The sort file is created and can be used
space used to delimit character strings. by the sort function only.
sequence structure. A program processing logic in * sort-merge file description entry. An entry in the
which a series of statements is executed in sequential FILE SECTION of the DATA DIVISION that is composed of
order. the level indicator SD, followed by a file-name, and
then followed by a set of file clauses as required.
* sequential access. An access mode in which logical
records are obtained from or placed into a file in a * SOURCE-COMPUTER. The name of an ENVIRONMENT
consecutive predecessor-to-successor logical record DIVISION paragraph in which the computer
sequence determined by the order of records in the file. environment, where the source program is compiled, is
described.
* sequential file. A file with sequential organization.
* source computer entry. An entry in the
* sequential organization. The permanent logical file
SOURCE-COMPUTER paragraph of the ENVIRONMENT
structure in which a record is identified by a
DIVISION; this entry contains clauses that describe the
predecessor-successor relationship established when the
computer environment in which the source program is
record is placed into the file.
to be compiled.
serial search. A search in which the members of a set
* source item. An identifier designated by a SOURCE
are consecutively examined, beginning with the first
clause that provides the value of a printable item.
member and ending with the last.
source program. Although a source program can be
* 77-level-description-entry. A data description entry
represented by other forms and symbols, in this
that describes a noncontiguous data item with the
document the term always refers to a syntactically
level-number 77.
correct set of COBOL statements. A COBOL source
* sign condition. The proposition (for which a truth program commences with the IDENTIFICATION DIVISION
value can be determined) that the algebraic value of a or a COPY statement and terminates with the end
data item or an arithmetic expression is either less than, program header, if specified, or with the absence of
greater than, or equal to zero. additional source program lines.
signature. The name of an operation and its * special character. A character that belongs to the
parameters. following set:
Glossary 629
Character Meaning * subclass. A class that inherits from another class.
; Semicolon When two classes in an inheritance relationship are
considered together, the subclass is the inheritor or
. Period (decimal point, full stop)
inheriting class; the superclass is the inheritee or
″ Quotation mark
inherited class.
( Left parenthesis
) Right parenthesis * subject of entry. An operand or reserved word that
> Greater than symbol appears immediately following the level indicator or
< Less than symbol the level-number in a DATA DIVISION entry.
: Colon
* subprogram. See called program.
* special-character word. A reserved word that is an * subscript. An occurrence number that is represented
arithmetic operator or a relation character. by either an integer, a data-name optionally followed
by an integer with the operator + or -, or an
SPECIAL-NAMES. The name of an ENVIRONMENT DIVISION index-name optionally followed by an integer with the
paragraph in which environment-names are related to operator + or -, that identifies a particular element in a
user-specified mnemonic-names. table. A subscript can be the word ALL when the
subscripted identifier is used as a function argument
* special names entry. An entry in the SPECIAL-NAMES for a function allowing a variable number of
paragraph of the ENVIRONMENT DIVISION; this entry arguments.
provides means for specifying the currency sign;
choosing the decimal point; specifying symbolic * subscripted data-name. An identifier that is
characters; relating implementor-names to composed of a data-name followed by one or more
user-specified mnemonic-names; relating subscripts enclosed in parentheses.
alphabet-names to character sets or collating sequences;
and relating class-names to sets of characters. * superclass. A class that is inherited by another class.
See also subclass.
* special registers. Certain compiler-generated storage
areas whose primary use is to store information switch-status condition. The proposition (for which a
produced in conjunction with the use of a specific truth value can be determined) that an UPSI switch,
COBOL feature. capable of being set to an on or off status, has been set
to a specific status.
* standard data format. The concept used in
describing the characteristics of data in a COBOL DATA * symbolic-character. A user-defined word that
DIVISION under which the characteristics or properties specifies a user-defined figurative constant.
of the data are expressed in a form oriented to the
syntax. (1) The relationship among characters or
appearance of the data on a printed page of infinite
groups of characters, independent of their meanings or
length and breadth, rather than a form oriented to the
the manner of their interpretation and use. (2) The
manner in which the data is stored internally in the
structure of expressions in a language. (3) The rules
computer, or on a particular external medium.
governing the structure of a language. (4) The
* statement. A syntactically valid combination of relationship among symbols. (5) The rules for the
words, literals, and separators, beginning with a verb, construction of a statement.
written in a COBOL source program.
* system-name. A COBOL word that is used to
STL file system. The Standard language file system is communicate with the operating environment.
the native workstation file system for COBOL and
System Object Model (SOM). IBM’s object-oriented
PL/I. This system supports sequential, relative, and
programming technology for building, packaging, and
indexed files, including the full ANSI 85 COBOL
manipulating class libraries. SOM conforms to the
standard input and output language and all of the
Object Management Group’s (OMG) Common Object
extensions described in IBM COBOL Language Reference,
Request Broker Architecture (CORBA) standards.
unless exceptions are explicitly noted.
Glossary 631
VSAM file system. A file system that supports
COBOL sequential, relative, and indexed organizations.
Z
This file system is available as part of IBM VisualAge
zoned decimal item. See external decimal item.
COBOL and enables you to read and write files on
remote systems such as OS/390.
W
windowed date field. A date field containing a
windowed (two-digit) year. See also date field and
windowed year.
X
x. The symbol in a PICTURE clause that can hold any
character in the character set of the computer.
Y
year field expansion. Explicitly expanding date fields
that contain two-digit years to contain four-digit years
in files and databases and then using these fields in
expanded form in programs. This is the only method
for assuring reliable date processing for applications
that have used two-digit years.
Messages, Codes, and Diagnosis, SC28-1996 The following collection kits contain IBM COBOL
and related product publications.
Object Services, SC28-1995
OS/390 Collection, SK2T-6700
Programmer’s Guide, GC28-1859
VM Collection, SK2T-2067
Programmer’s Reference Volume 1, SC28-1997
Index 637
compiler options (continued) compiling (continued) converting data items
NODYNAM 467 from an assembler program 216 characters to numbers 95
NOFASTSRT 183 invoking with COBOL2 command INSPECT statement 89
NOSOURCE 321 under CMS 244 reversing order of characters 95
NUMBER 320 under OS/390 203 to integers 88
NUMPROC 283 under OS/390 UNIX 235 to uppercase or lowercase 95
NUMPROC(PFD) 545 under TSO 215 with intrinsic functions 94
NUMPROC(PFD|NOPFD|MIG) 41 using shell script 241 converting files to expanded date form,
OBJECT 284 using the cob2 command 237 example 515
on compiler invocation 321 with cataloged procedures 204 copy
OPTIMIZE 545 with JCL (job control language) 203 libraries 552
OUTDD 286 compiling and linking in the OS/390 OS/390 UNIX search order 239
PGMNAME 287 UNIX shell 237 search order 305
precedence of 248 completion code, sort 180 SYSLIB 220
PRINT 247 complex OCCURS DEPENDING ON copy code, obtaining from user-supplied
QUOTE 289 basic forms of 569 module 575
RENT 545 complex ODO item 569 COPY statement
RMODE 290 variably located data item 570 CMS considerations 245
SEQUENCE 315 variably located group 570 example 552
settings for standard compilation 259 computation nested 552
signature bytes 331 constant data items 536 OS/390 considerations 220
SIZE 291 duplicate 537 OS/390 UNIX considerations 305
SOURCE 319 subscript 540 copybook 304
SPACE 293 COMPUTATIONAL (COMP) 37 copying, code 551
specifying 223 COMPUTATIONAL-1 (COMP-1) 38 counting data items 89
PROCESS (CBL) statement 223 COMPUTATIONAL-2 (COMP-2) 38 creating
specifying under CMS 246 COMPUTATIONAL-3 (COMP-3) 38 Associated Data File 222
specifying under OS/390 224 COMPUTATIONAL-3 date fields, IDL data set 222
specifying under OS/390 UNIX 236 potential problems 530 line-sequential files, OS/390 165
specifying under TSO 224 COMPUTATIONAL-4 (COMP-4) 37 object code 221
SQL 356 COMPUTATIONAL-5 (COMP-5) 37 QSAM files, CMS 128
SSRANGE 545 computer, describing 7 QSAM files, OS/390 123
status 321 concatenating data items 81 cross-reference
TERMINAL 248 condition handling 175 data and procedure names 317
TEST 545 condition-name 519 embedded 319
TRUNC 297 condition testing 74 program-name 341
TRUNC(STD|OPT|BIN) 545 conditional expression special definition symbols 341
TYPECHK 300 IF statement 69 verbs 319
under CICS 350 PERFORM statement 78 cross-reference list 301
under IMS 349 conditional statement CRP (file position indicator) 144
VBREF 319 in EVALUATE statement 70 CURRENCY compiler option 265
when coding for CICS 350 list of 19 currency signs
WORD 301 overview 19 euro 51
XREF 317 with NOT phrase 19 hex literals 51
YEARWINDOW 303 CONFIGURATION SECTION 7 multiple-character 51
ZWB 304 conflicting compiler options 259 using 51
compiler output, CMS 249 constant CURRENT-DATE intrinsic function 47
computations 536
compiling
accessing compiler under CMS 243
data items 536
figurative 24
D
batch 226 D format record 111
constructor method 407
CMS 243 DASD (direct-access storage device) 159
contained program integration 543
CMS work files 248 data
continuation
compile, link-edit, run cataloged concatenating 81
entry 185
procedure 207 conversion, DBCS to nonnumeric 90
compile, load, run cataloged continuation, syntax checking 265
conversion, nonnumeric to DBCS 90
procedure 208 CONTINUE statement 70 efficient execution 535
compile, prelink, link-edit, run contracting alphanumeric dates 530 format, numeric types 35
cataloged procedure 210 control format conversion 39
compile, prelink, link-edit cataloged in nested programs 468 grouping 478
procedure 209 program flow 69 incompatible 42
compile, prelink, load, run cataloged transfer 459 joining 81
procedure 212 control interval size (CISZ), performance naming 14
compile and link-edit cataloged considerations 549 numeric 33
procedure 206 CONTROL statement 304 passing 475
compile cataloged procedure 205 controlling program compilation under record size 14
control of 223 CMS 243 splitting 83
data sets for 218 conversion of data formats 39 validation 42
Index 639
diagnostic messages entry point (continued) euro currency sign 51
from millennium language passing entry addresses of 472 EVALUATE statement
extensions 528 procedure-pointer data item 472 case structure 71
diagnostics, program 321 ENTRY statement structured programming 535
DIAGTRUNC compiler option 269 handling of programs name in 287 evaluating data item contents
direct-access ENVIRONMENT DIVISION class test 42
direct indexing 57 class 379 INSPECT statement 89
file organization 102 client 389 intrinsic functions 96
storage device (DASD) 159 collating sequence coding 8 exception condition 199
directories CONFIGURATION SECTION 7 EXCEPTION/ERROR declarative
adding a path to 239 description 7 description 194
where error listing file is written 231 entries for line-sequential files 163 file status key 195
DISK compiler option 247 entries for QSAM files 107 line-sequential error processing 168
DISPLAY (USAGE IS) 36 entries for VSAM files 137 QSAM error processing 120
DISPLAY statement INPUT-OUTPUT SECTION 7 VSAM error processing 151
directing output 286 items present in, program EXEC control statement 504
displaying data values 29 initialization code 333 EXIT compiler option 575
interaction with OUTDD 29 method 382 with the COBOL2 command 244
using in debugging 310 signature bytes 333 exit modules
writing to stdout/stderr 29 subclass 394 called for SYSADATA data set 582
DLBL command 158 environment variable error messages generated 583
DLL compiler option 270 defining line-sequential files 165 loading and invoking 577
mutually exclusive with 259 defining QSAM files 121 when used in place of
DLLs (see dynamic link libraries) 489 example of defining files 10 library-name 578
do loop 77 environment variables when used in place of SYSLIB 578
do-until 77 _CEE_RUNOPTS 362 when used in place of
do-while 77 and COPY files 305 SYSPRINT 580
documentation of program 7 COBOPT 235 EXIT PROGRAM statement
Double-Byte Character Data (DBCS) 90 example of setting and accessing 363 in subprogram 460
dump LIBPATH 362 expanded IF statement 69
with DUMP compiler option 224 library-name 304 explicit scope terminator 20
DUMP compiler option 248 setting 235 exponentiation
duplicate computations 537 setting and accessing 362 evaluated in fixed-point
DYNAM compiler option 272 SYSLIB 235 arithmetic 562
description 272 System Object Model (SOM) 417 evaluated in floating-point
performance considerations 545 using to allocate files 105 arithmetic 567
dynamic calls ERRMSG, for generating list of error performance tips 538
using with DLL linkage 494 messages 230 EXPORTALL compiler option 272
dynamic data areas, allocating error extended mode 559
storage 266 arithmetic 191 EXTERNAL clause
dynamic file allocation 118 compiler options, conflicting 259 example for files 484
dynamic link libraries example of message table 60 for data items 483
about 489 handling 189 for files 13
compiling 490 handling for input-output 106 used for input/output 483
creating 489 listing 224 external data
in OO COBOL applicaitons 498 messages, compiler obtaining storage for 267
linking 491 embedding in source listing 316 sharing 483
prelinking 492 sending to terminal 221 storage location of 266
search order for in HFS 494 under CMS 252 external decimal data item 36
using CALL indentifer with 493 messages, from COBOL2 command external file 13
using with C/C++ programs 498 identified by DMSIGY 252 external floating-point data item 36
using with dynamic calls 494 list of 256
processing, line-sequential files 168
processing, QSAM files 120
F
F format record 109
E processing, VSAM files 151 factoring expressions 536
E-level error message 232 error messages FASTSRT compiler option 273
EJECT statement 304 compiler-directed 231 improves sort performance 545
embedded cross-reference 319 determining what severity level to information message 181
example 341 produce 274 requirements 181
embedded error messages 316 format 231 FD (file description) entry 14
embedded MAP summary 318 from exit modules 583 figurative constant 24
empty VSAM file, opening 145 generating a list of 230 file access mode
enclave 459 severity levels 232 dynamic 141
end-of-file phrase (AT END) 193 errors example 141
entry point compiler-directed 231 for indexed files (KSDS) 141
alternate 473 ESDS (entry-sequenced data sets) for relative files (RRDS) 141
ENTRY label 460 file access mode 141 for sequential files (ESDS) 141
Index 641
IDL 425 (continued) inline PERFORM 76 intrinsic functions (continued)
access intent specifiers 435 input example of (continued)
attributes 428 coding for line-sequential files 165 INTEGER-OF-DATE 47
common types 429 coding for QSAM files 117 LENGTH 47
complex types 432 coding for VSAM files 143 LOG 48
files 446 coding in CICS 348 LOWER-CASE 95
identifiers 427 overview 101 MAX 47
literal arguments 435 to compiler, under CMS 244 MEAN 48
mapping to COBOL 427 to compiler, under OS/390 218 MEDIAN 48
operations 427 input/output MIN 88
parameter-passing conventions 435 checking for errors 194 NUMVAL 95
passing complex types 435 coding overview 103 NUMVAL-C 47
IDL data set logic flow after error 191 ORD 96
creating 222 overview 101 ORD-MAX 97
idl extension with cob2 240 processing errors for line-sequential PRESENT-VALUE 48
IDL type files 168 RANGE 48
any 432 processing errors for QSAM files 191 REM 48
array 433 processing errors for VSAM files 191 REVERSE 95
enum 430 input/output coding SQRT 48
interface 430 AT END (end-of-file) phrase 193 SUM 68
long 430 checking for successful operation 194 UPPER-CASE 95
sequence 433 checking VSAM return codes 196 WHEN-COMPILED 99
short 431 detecting faulty index key 198 intermediate results 565
string 431 error handling techniques 191 introduction to 31
struct 434 EXCEPTION/ERROR nesting 32
union 434 declaratives 194 numeric functions
IDLGEN compiler option 277 INPUT-OUTPUT SECTION 7 differences from Language
IDLStringFromCOBOL 450 input procedure Environment callable
IDLStringToCOBOL 450 FASTSRT option not effective 182 services 46
IF statement requires RELEASE or RELEASE equivalent Language Environment
coding 69 FROM 172 callable services 45
nested 70 restrictions 175 examples of 44
with null branch 69 using 172 nested 45
IGZCA2D service routine 90 INSERT statement 304 special registers as arguments 45
IGZCD2A service routine 92 INSPECT statement 89 table elements as arguments 45
IGZSRTCD data set 185 inspecting data 89 type of—integer, floating-point,
ILC (interlanguage communication) 459 INTDATE compiler option 278 mixed 44
imperative statement, list 18 INTEGER intrinsic function 88 uses for 44
implicit scope terminator 20 INTEGER-OF-DATE intrinsic processing table elements 67
IMS function 47 simplifying coding 551
coding programs under 359 interactive program, example 592 UNDATE 527
coding restrictions 359 Interactive System Productivity Facility INVALID KEY phrase 198
mixed COBOL for OS/390 & VM, (ISPF) 592 INVOKE statement
COBOL for MVS & VM, VS COBOL Interface Repository (IR) use with PROCEDURE DIVISION
II, and OS/VS COBOL accessing 415 RETURNING 482
applications 359 definition 415 invoking
performance considerations 549 populating 416 COBOL UNIX programs 361
recommended compiler options 359 interlanguage communication (ILC) 349 Language Environment callable
incrementing addresses 480 intermediate results 559 services 555
index, table 56 internal bridges the compiler under CMS 243
index data item 57 ISAM data set 135
advantages 512
index key, detecting faulty 198 ISPF (Interactive System Productivity
example 514
index-name subscripting 57 Facility) 592
for date processing 513
index range checking 315
indexed file organization 101
internal floating-point data J
bytes required 38 JCL (job control language)
indexing defining 38 ASCII tape files 132
example 61 uses for 38 cataloged procedures 204
preferred to subscripting 539 intrinsic functions for compiling 203
tables 57 as reference modifier 88 for compiling with HFS 205
INEXIT suboption of EXIT option 575 converting character data items 94 for line-sequential files 165
INITIAL attribute 6 DATEVAL 527 for QSAM files 122
INITIALIZE statement evaluating data items 96 for VSAM data sets 156
examples 25 example of SOM 418
loading table values 58 ANNUITY 48 JCL (Job Control Language)
using for debugging 311 CHAR 96 FASTSRT requirement 181
initializing CURRENT-DATE 47 job control statement
a table 58 INTEGER 88 checkpoint/restart sample 507
Index 643
memory map, TGT 328
example 338
N numeric data (continued)
external floating-point
merge NAME compiler option 5 USAGE IS DISPLAY 36
concepts 170 name declaration format conversions between fixed-
description 169 searching for 471 and floating-point 39
files, describing 171 naming internal floating-point
line-sequential files 169 files 10 USAGE IS COMPUTATIONAL-1
pass control statements to 185 programs 5 (COMP-1) 38
storage use 186 National Language Support 279 USAGE IS COMPUTATIONAL-2
successful 180 nested COPY statement 578 (COMP-2) 38
MERGE statement nested delimited scope statements 21 overview 33
description 170 nested IF statement packed-decimal
message handling, Language CONTINUE statement 70 USAGE IS COMPUTATIONAL-3
Environment callable services 553 description 70 (COMP-3) 38
messages EVALUATE statement preferred 70 USAGE IS PACKED-
COBOL2 command error 252 with null branches 70 DECIMAL 38
compile-time error nested intrinsic functions 45 PICTURE clause 33
embedding in source listing 316 nested program integration 543 storage formats 35
compiler-directed 231 nested program map zoned decimal
compiler error about 319 USAGE IS DISPLAY 36
sending to terminal 221 example 328 numeric-edited data item 34
under CMS 252 nested programs numeric editing symbol 34
determining what severity level to calling 468 numeric intrinsic functions
produce 274 conventions for using 468 differences from Language
from exit modules 583 description 469 Environment callable services 46
severity levels 232 map 319 equivalent Language Environment
messages, error scope of names 471 callable services 45
generating a list of 230 transfer of control 468 example of
metaclass definition 405 nesting level ANNUITY 48
method definition 381 program 323 CURRENT-DATE 47
METHOD-ID paragraph 381 statement 323 INTEGER 88
methods 391 NOCOMPILE compiler option INTEGER-OF-DATE 47
PROCEDURE DIVISION use of to find syntax errors 314 LENGTH 47
RETURNING 482 NODYNAM compiler option LOG 48
migration mixing static and dynamic calls 467 MAX 47
FLAGMIG compiler option 275 NODYNAM parameter option 349 MEAN 48
millennium language extensions 510 NOFASTSRT compiler option 183 MEDIAN 48
assumed century window 520 nondates MIN 88
compatible dates 517 with MLE 521 NUMVAL 95
date windowing 509 nonnumeric literal NUMVAL-C 47
DATEPROC compiler option 267 alphanumeric to DBCS conversion 90 ORD 96
nondates 521 conversion of mixed ORD-MAX 68
objectives 511 DBCS/EBCDIC 90 PRESENT-VALUE 48
principles 510 DBCS to alphanumeric conversion 92 RANGE 48
YEARWINDOW compiler option 303 with double-byte characters 90 REM 48
MIN intrinsic function 88 NOPRINT compiler option 247 SQRT 48
mixed COBOL for OS/390 & VM, Notices 609 SUM 68
COBOL for MVS & VM, VS COBOL II, null branch 70 nested 45
and OS/VS COBOL applications null-terminated strings 85 special registers as arguments 45
coding under IMS 359 NUMBER compiler option 320 table elements as arguments 45
syntax and description 283 types of—integer, floating-point,
mixed DBCS/EBCDIC literal 90
NUMCLS installation option 42 mixed 44
alphanumeric to DBCS conversion 90
numeric class test 42 uses for 44
conversion 90
numeric condition 73 NUMPROC compiler option 283
mixed literal
numeric data NUMPROC(PFD) compiler option
alphanumeric to DBCS data
binary performance considerations 545
conversion 90
USAGE IS BINARY 37 NUMPROC(PFD|NOPFD|MIG) compiler
conversion 90
USAGE IS COMPUTATIONAL option
DBCS to alphanumeric conversion 92
(COMP) 37 affected by NUMCLS 42
MLE 510 USAGE IS COMPUTATIONAL-4
mnemonic-name effect on sign processing 41
(COMP-4) 37 NUMVAL-C intrinsic function 95
SPECIAL-NAMES paragraph 7 USAGE IS COMPUTATIONAL-5 example 47
MOVE statement 27 (COMP-5) 37 NUMVAL intrinsic function 95
MSGFILE run-time option 286 conversions between fixed- and
multiple-character currency signs 51 floating-point data 40 O
multiple currency signs 52 editing symbols 34 o extension with cob2 240
multivolume tape files, identifying to external decimal object code
CMS 129 USAGE IS DISPLAY 36 compilation and listing 224
Index 645
performance (continued) PROCEDURE DIVISION (continued) program termination
in a CICS environment 548 in subprograms 478 statements 460
in IMS environment 549 method 383 programs
mixed-level COBOL applications 359 RETURNING 17 developing for OS/390 UNIX 361
NUMPROC compiler option 41 signature bytes 333 protecting VSAM files 151
NUMPROC(PFD) compiler statements PRTEXIT suboption of EXIT option 575
option 545 compiler-directing 20
OCCURS DEPENDING ON 540 conditional 19
of calls 464 delimited scope 19 Q
of tape data sets 116 imperative 18 QSAM (queued sequential access
OPTIMIZE compiler option 545 terminology 17 method) 107
optimizer 542 USING 17 QSAM files
planning arithmetic evaluations 537 verbs present in 333 adding records to 119
programming style 535 PROCEDURE DIVISION RETURNING ASCII tape file 132
RENT compiler option 545 methods, use of 482 ASSIGN clause 108
RMODE compiler option 545 procedure integration 543 BLOCK CONTAINS clause 115
run-time considerations 535 procedure-pointer data item block size 115
SSRANGE compiler option 545 entry address for entry point 472 blocking records 127
table handling 540 SET procedure-pointer 472 closing 120
TEST compiler option 545 with DLLs 495 closing to prevent reopening 118
TRUNC compiler option 297 PROCESS (CBL) statement DATA DIVISION entries 108
TRUNC(STD|OPT|BIN) compiler batch compiling 227 ENVIRONMENT DIVISION
option 545 conflicting options in 259 entries 107
use of arithmetic expressions 538 precedence 248 input/output error processing 191
variable subscript data format 56 specifying compiler options 246 input/output statements for 117
VSAM file considerations 159 PROCESS statement 223 label processing 129
worksheet 548 processing obtaining buffers for 267
performance considerations chained list 479 opening 117
compiler options labels for QSAM files 129 processing files 107
AWO 545 tables 60 processing files in reverse order 118
RMODE 545 using indexing 61 processing HFS files 127
period, as scope terminator 20 using subscripting 60 replacing records 119
PGMNAME compiler option 287 production debugging 296 retrieving 123
physical program striped extended-format 126
block 101 attribute codes 328 tape performance 116
record 14 compiling under CMS 243 under CMS
PICTURE clause compiling under OS/390 203 defining 128
determining symbol used 265 compiling under OS/390 UNIX 235 dynamic allocation 118
numeric data 33 controlling compilation under file availability 118
pointer data item CMS 243 FILEDEF command for 128
incrementing addresses with 480 decisions identifying files, FILEDEF
NULL value 479 EVALUATE statement 70 command 128
used to pass addresses 479 IF statement 69 LABELDEF command 129
used to process chained list 479 loops 77 tape file identification 129
porting your program 34 PERFORM statement 77 under OS/390
POSIX APIs switches and flags 74 creating files 123
calling 364 diagnostics 321 DD statement for 123
potential problems with date fields 530 initialization code 329 defining 123
precedence limitations 535 environment variable for 121
arithmetic operators 561 main 459 file availability 118
compiler options under CMS 248 nesting level 323 job control language (JCL) 122
compiler options under OS/390 223 reentrant 474 updating files 119
preferred sign 41 restarting 504 writing to a printer 119
prelinking signature information bytes 331 QSAM unblocked files 369
compile, prelink, link-edit, run statistics 321 queued sequential access method
cataloged procedure 210 structure 5 (QSAM) 107
prelink and link-edit cataloged sub 459 QUOTE compiler option 289
procedure 211 PROGRAM COLLATING SEQUENCE
PRESENT-VALUE intrinsic function 48 clause 8
preserving original sequence in a Program-ID paragraph R
sort 180 COMMON attribute 6 random numbers, generating 46
PRINT compiler option 247 description 5 RANGE intrinsic function 48
priority numbers, segmentation 545 INITIAL attribute 6 RD parameter 504
PROCEDURE DIVISION program-name cross-reference 341 read a block of records 115
additional information 335 program names 5 READ INTO. . . 142
client 389 handling of case 287 READ NEXT statement 143
description 17 program processing table 349 READ statement 117
Index 647
SIZE compiler option 291 source code (continued) storage (continued)
skip a block of records 115 listing, description 319 management, Language Environment
sliding century window 512 SOURCE compiler option 319 callable services 553
SOM 425 SOURCE-COMPUTER paragraph 7 mapping 319
CORBA-style exceptions 442 SPACE compiler option 293 use during sort 186
environment arguments 442 spanned record format 113 STRING statement
errors and exceptions 442 spanned records 113 description 81
COBOL example 443 special feature specification 7 example of 81
initializers 445 SPECIAL-NAMES paragraph overflow condition 190
JCL for 418 QSAM files 132 with DBCS data 90
memory management with 447 special register strings
SOMerror-style exceptions 442 ADDRESS 476 null-terminated 478
somFree 390 arguments in intrinsic functions 45 striped extended-format QSAM file 126
somNew 390 LENGTH OF 476 structured programming 536
SOMENV data set 218 SORT-RETURN 180 subclass definition 393
sort WHEN-COMPILED 99 subprogram
alternate collating sequence 179 specifying the source program under and main program 459
checkpoint/restart 186 CMS definition of 459
concepts 170 by file name 244 linkage 459
criteria 177 splitting data items 83 common data items 477
data sets needed, OS/390 175 SQL compiler option 356 Procedure Division in 478
DD statements, defining OS/390 data mutually exclusive with 259 termination
sets 175 SQL INCLUDE statement 355 effects 460
description 169 SQL statements 355 subscript
FASTSRT compiler option 181 SQLCA 355 computations 540
files, describing 171 SQLCODE 356 range checking 315
files needed, CMS 176 SQLSTATE 356 subscripting
line-sequential files 169 SQRT intrinsic function 48 example of processing a table 60
more than one 170 SSRANGE compiler option 294 index-names 57
NOFASTSRT compiler option 183 CHECK(OFF) run-time option 545 literal 54
pass control statements to 185 description 315 reference modification 56
performance 181 performance considerations 545 relative 56
preserving original sequence 180 STANDARD clause, FD entry 14 variable 55
restrictions on input/output standard label, QSAM 133 substrings
procedures 175 standard label format 131 of data 86
special registers 184 START statement 143 referencing table items 87
storage use 186 statement SUM intrinsic function 68
successful 180 compiler-directing 20 switch-status condition 73
terminating 181 conditional 19 switches 74
under CICS 187 definition 18 switches and flags
under CMS 176 delimited scope 19 about 74
under OS/390 175 explicit scope terminator 20 defining 74
using input procedures 172 imperative 18 resetting 75
using output procedures 173 implicit scope terminator 20 SYMBOLIC CHARACTER clause 9
variable-length records 176 statement nesting level 323 symbolic constant 536
windowed date fields 179 static call symbols used in LIST and MAP
SORT-CONTROL special register 184 statement 462 output 326
SORT-CORE-SIZE special register 184 statistics SYNAD error 370
Sort File Description (SD) entry intrinsic functions 48 syntax errors
example 171 status key finding with NOCOMPILE compiler
SORT-FILE-SIZE special register 184 importance of in VSAM 151 option 314
SORT-MESSAGE special register 184 stderr SYSADATA
SORT-MODE-SIZE special register 184 directing DISPLAY 29 SYSADATA data set 222
SORT-RETURN special register 181 setting DISPLAY to 363 SYSADATA file 248
SORT statement stdin SYSADATA file 261
description 177 reading with ACCEPT 29 SYSADATA records
restrictions for CICS applications 187 stdout exit module called 582
under CICS 187 directing DISPLAY 29 SYSIDL data set 218
SORTCKPT DD statement 186 setting DISPLAY to 363 SYSIN
source STEPLIB environment variable user exit error message 583
program listing 224 setting 363 SYSLIB
SOURCE and NUMBER output, STOP RUN statement when not used 578
example 323 in main program 460 SYSLIB data set 218
source code storage SYSLIN data set 221
compiler data set (CMS) 244 device SYSPRINT
compiler data set (OS/390) 220 direct-access 102 when not used 580
line number 324 sequential 102 SYSPRINT data set 218
Index 649
VSAM terminology (continued)
ESDS for QSAM 135
KSDS for ISAM 135
RRDS for BDAM 135
W
W-level error message 232
WHEN-COMPILED intrinsic function
example 99
versus WHEN-COMPILED special
register 99
WHEN-COMPILED special register 99
WHEN phrase
EVALUATE statement 71
SEARCH statement 65
windowed date fields 179
wlist file 281
WORD compiler option 301
work data sets 218
work files 248
WORKING-STORAGE
finding location and size of in
storage 339
storage location for data 266
WORKING-STORAGE SECTION
class 379
description 15
method 382
write a block of records 115
WRITE ADVANCING statement 119
WRITE statement 117
line-sequential files 165
X
x extension with cob2 240
XREF compiler option 317
XREF output
data-name cross-references 340
program-name cross-references 341
Y
year field expansion 514
year-last date fields 516
year windowing
advantages 512
how to control 527
MLE approach 512
when not supported 518
YEARWINDOW compiler option 303
effect on sort/merge 184
Z
zero comparison 523
zoned decimal 36
ZWB compiler option 304
Overall, how satisfied are you with the information in this book?
How satisfied are you that the information in this book is:
When you send comments to IBM, you grant IBM a nonexclusive right to use or distribute your comments in any
way it believes appropriate without incurring any obligation to you.
Name Address
Company or Organization
Phone No.
___________________________________________________________________________________________________
Readers’ Comments — We’d Like to Hear from You Cut or Fold
SC26-9049-05 Along Line
_ _ _ _ _ _ _Fold
_ _ _and
_ _ _Tape
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _Please
_ _ _ _ _do
_ _not
_ _ staple
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _Fold
_ _ _and
_ _ Tape
______
NO POSTAGE
NECESSARY
IF MAILED IN THE
UNITED STATES
IBM Corporation
Department HHX/H3
P.O. Box 49023
San Jose, CA
United States of America
95161-9023
_________________________________________________________________________________________
Fold and Tape Please do not staple Fold and Tape
Cut or Fold
SC26-9049-05 Along Line
SC26-9049-05