Enterprise Cobol Programming Guide For Zos And Os390 32 Ibm instant download
Enterprise Cobol Programming Guide For Zos And Os390 32 Ibm instant download
https://ebookbell.com/product/enterprise-cobol-programming-guide-
for-zos-and-os390-32-ibm-23632996
https://ebookbell.com/product/enterprisegrade-it-security-for-small-
and-medium-businesses-denny-cherry-46152490
https://ebookbell.com/product/enterprise-systems-architecture-
aligning-business-operating-models-to-technology-landscapes-1st-
edition-daljit-roy-banger-46346492
https://ebookbell.com/product/enterprise-design-operations-and-
computing-26th-international-conference-edoc-2022-bozenbolzano-italy-
october-37-2022-proceedings-1st-ed-2022-joo-paulo-a-almeida-46470046
https://ebookbell.com/product/enterprise-architecture-for-digital-
business-transforming-it-geng-lin-46503372
Enterprise Api Management Design And Deliver Valuable Business Apis
Luis Weir
https://ebookbell.com/product/enterprise-api-management-design-and-
deliver-valuable-business-apis-luis-weir-46651782
https://ebookbell.com/product/enterprise-architecture-and-cartography-
from-practice-to-theory-from-representation-to-design-pedro-
sousa-47214946
https://ebookbell.com/product/enterprise-react-development-with-umijs-
learn-efficient-techniques-and-best-practices-douglas-alves-
venancio-47666172
https://ebookbell.com/product/enterprise-information-systems-and-the-
digitalization-of-business-functions-tavana-48075008
https://ebookbell.com/product/enterprise-interoperability-ix-
interoperability-in-the-era-of-artificial-intelligence-bernard-
archimde-49158402
Enterprise COBOL for z/OS and OS/390
Programming Guide
Version 3 Release 2
SC27-1412-01
Enterprise COBOL for z/OS and OS/390
Programming Guide
Version 3 Release 2
SC27-1412-01
Note!
Before using this information and the product it supports, be sure to read the general information under “Notices” on
page 699.
iv Programming Guide
Chapter 10. Processing VSAM files 147 Sorting variable-length records . . . . . . . 186
VSAM files . . . . . . . . . . . . . . 148 Requesting the sort or merge . . . . . . . . 186
Defining VSAM file organization and records . . 149 Setting sort or merge criteria . . . . . . . 187
Specifying sequential organization for VSAM Example: sorting with input and output
files . . . . . . . . . . . . . . . 150 procedures . . . . . . . . . . . . . 188
Specifying indexed organization for VSAM files 150 Choosing alternate collating sequences . . . . 188
Specifying relative organization for VSAM files 151 Sorting on windowed date fields . . . . . . 189
Specifying access modes for VSAM files . . . 153 Preserving the original sequence of records with
Defining record lengths for VSAM files. . . . 154 equal keys . . . . . . . . . . . . . 189
Coding input and output statements for VSAM Determining whether the sort or merge was
files . . . . . . . . . . . . . . . . 155 successful . . . . . . . . . . . . . . 190
File position indicator . . . . . . . . . 157 Stopping a sort or merge operation prematurely 190
Opening a file (ESDS, KSDS, or RRDS) . . . . 157 Improving sort performance with FASTSRT . . . 191
Reading records from a VSAM file . . . . . 159 FASTSRT requirements for JCL . . . . . . 191
Updating records in a VSAM file . . . . . . 160 FASTSRT requirements for sort input and
Adding records to a VSAM file . . . . . . 161 output files . . . . . . . . . . . . . 191
Replacing records in a VSAM file. . . . . . 162 Checking for sort errors with NOFASTSRT . . . 193
Deleting records from a VSAM file . . . . . 162 Controlling sort behavior . . . . . . . . . 193
Closing VSAM files . . . . . . . . . . 162 Sort special registers . . . . . . . . . . 194
Handling errors in VSAM files . . . . . . . 163 Changing DFSORT defaults with control
Protecting VSAM files with a password . . . . 164 statements . . . . . . . . . . . . . 195
Example: password protection for a VSAM Allocating storage for sort or merge operations 195
indexed file . . . . . . . . . . . . . 164 Allocating space for sort files . . . . . . . 196
Working with VSAM data sets under z/OS and Using checkpoint/restart with DFSORT . . . . 196
UNIX . . . . . . . . . . . . . . . . 165 Sorting under CICS . . . . . . . . . . . 197
Defining VSAM files . . . . . . . . . . 165 CICS SORT application restrictions . . . . . 197
Creating alternate indexes . . . . . . . . 166
Allocating VSAM files . . . . . . . . . 168 Chapter 13. Processing XML
Sharing VSAM files through RLS . . . . . . 170 documents . . . . . . . . . . . . 199
Improving VSAM performance . . . . . . . 171 XML parser in COBOL . . . . . . . . . . 199
Accessing XML documents . . . . . . . . . 201
Chapter 11. Processing line-sequential Parsing XML documents . . . . . . . . . 201
files . . . . . . . . . . . . . . . 173 Processing XML events . . . . . . . . . 202
Defining line-sequential files and records in Writing procedures to process XML . . . . . 208
COBOL . . . . . . . . . . . . . . . 173 Understanding XML document encoding . . . . 213
Allowable control characters . . . . . . . 174 Specifying the code page . . . . . . . . 214
Describing the structure of a line-sequential file 174 Parsing documents in other code pages. . . . 214
Defining and allocating line-sequential files . . . 175 Handling errors in XML documents . . . . . . 215
Coding input-output statements for line-sequential Unhandled exceptions . . . . . . . . . 216
files . . . . . . . . . . . . . . . . 175 Handling exceptions . . . . . . . . . . 216
Opening line-sequential files . . . . . . . 176 Terminating the parse . . . . . . . . . 217
Reading records from line-sequential files . . . 176 CCSID conflict exception . . . . . . . . 217
Adding records to line-sequential files . . . . 177
Closing line-sequential files. . . . . . . . 177 Chapter 14. Handling errors . . . . . 221
Handling errors in line-sequential files . . . . . 178 Requesting dumps . . . . . . . . . . . 221
Creating a formatted dump. . . . . . . . 221
Chapter 12. Sorting and merging files 179 Creating a system dump . . . . . . . . 222
Sort and merge process . . . . . . . . . . 180 Handling errors in joining and splitting strings . . 222
Describing the sort or merge file . . . . . . . 180 Handling errors in arithmetic operations . . . . 223
Describing the input to sorting or merging . . . 181 Example: checking for division by zero . . . . 223
Example: describing sort and input files for Handling errors in input and output operations 223
SORT . . . . . . . . . . . . . . . 181 Using the end-of-file condition (AT END) . . . 226
Coding the input procedure . . . . . . . . 182 Coding ERROR declaratives . . . . . . . 227
Describing the output from sorting or merging . . 183 Using file status keys . . . . . . . . . . 228
Coding the output procedure . . . . . . . . 183 Example: file status key . . . . . . . . . 229
Coding considerations when using DFSORT . . 184 Using VSAM return codes (VSAM files only) 229
Example: coding the output procedure when Example: checking VSAM status codes . . . . 230
using DFSORT . . . . . . . . . . . . 184 Coding INVALID KEY phrases . . . . . . 231
Restrictions on input and output procedures . . . 185 Example: FILE STATUS and INVALID KEY . . 232
Defining sort and merge data sets . . . . . . 185 Handling errors when calling programs . . . . 233
Contents v
Writing routines for handling errors . . . . . . 233 Chapter 17. Compiling, linking, and
running OO applications . . . . . . 277
Part 2. Compiling and debugging Compiling, linking, and running OO applications
your program . . . . . . . . . . 235 under UNIX . . . . . . . . . . . . . . 277
Compiling OO applications under UNIX . . . 277
Preparing OO applications under UNIX . . . 278
Chapter 15. Compiling under z/OS 237 Example: compiling and linking a COBOL class
Compiling with JCL . . . . . . . . . . . 237 definition under UNIX . . . . . . . . . 279
Using a cataloged procedure . . . . . . . 238 Running OO applications under UNIX . . . . 279
Writing JCL to compile programs. . . . . . 248 Compiling, linking, and running OO applications
Compiling under TSO . . . . . . . . . . 249 using JCL or TSO/E . . . . . . . . . . . 281
Example: ALLOCATE and CALL for compiling Compiling OO applications using JCL or TSO/E 281
under TSO . . . . . . . . . . . . . 250 Preparing and running OO applications using
Example: CLIST for compiling under TSO . . . 250 JCL or TSO/E . . . . . . . . . . . . 282
Starting the compiler from an assembler program 251 Example: compiling, linking, and running an
Defining compiler input and output . . . . . . 252 OO application using JCL . . . . . . . . 283
Data sets used by the compiler under z/OS . . 253
Defining the source code data set (SYSIN) . . . 255
Chapter 18. Compiler options . . . . 287
Specifying source libraries (SYSLIB) . . . . . 255
Option settings for COBOL 85 Standard
Defining the output data set (SYSPRINT) . . . 256
conformance. . . . . . . . . . . . . . 289
Directing compiler messages to your terminal
Conflicting compiler options . . . . . . . . 289
(SYSTERM) . . . . . . . . . . . . . 256
ADATA . . . . . . . . . . . . . . . 290
Creating object code (SYSLIN or SYSPUNCH) 256
ADV . . . . . . . . . . . . . . . . 291
Creating an associated data file (SYSADATA) 257
ARITH . . . . . . . . . . . . . . . 291
Defining the output Java data set (SYSJAVA) 257
AWO . . . . . . . . . . . . . . . . 292
Defining the debug data set (SYSDEBUG) . . . 257
BUFSIZE . . . . . . . . . . . . . . . 292
Specifying compiler options under z/OS . . . . 258
CICS . . . . . . . . . . . . . . . . 293
Specifying compiler options with the PROCESS
CODEPAGE . . . . . . . . . . . . . . 294
(CBL) statement . . . . . . . . . . . 258
COMPILE . . . . . . . . . . . . . . 294
Example: specifying compiler options using JCL 259
CURRENCY . . . . . . . . . . . . . . 295
Example: specifying compiler options under
DATA . . . . . . . . . . . . . . . . 296
TSO . . . . . . . . . . . . . . . 259
DATEPROC . . . . . . . . . . . . . . 297
Compiler options and compiler output under
DBCS . . . . . . . . . . . . . . . . 298
z/OS . . . . . . . . . . . . . . . 259
DECK . . . . . . . . . . . . . . . . 298
Compiling multiple programs (batch compilation) 261
DIAGTRUNC . . . . . . . . . . . . . 298
Example: batch compilation . . . . . . . 261
DLL . . . . . . . . . . . . . . . . 299
Specifying compiler options in a batch
DUMP . . . . . . . . . . . . . . . 300
compilation . . . . . . . . . . . . . 262
DYNAM . . . . . . . . . . . . . . . 301
Example: precedence of options in a batch
EXIT . . . . . . . . . . . . . . . . 301
compilation . . . . . . . . . . . . . 263
EXPORTALL . . . . . . . . . . . . . 301
Example: LANGUAGE option in a batch
FASTSRT . . . . . . . . . . . . . . . 302
compilation . . . . . . . . . . . . . 264
FLAG . . . . . . . . . . . . . . . . 302
Correcting errors in your source program . . . . 265
FLAGSTD . . . . . . . . . . . . . . 303
Generating a list of compiler error messages . . 265
INTDATE . . . . . . . . . . . . . . 304
Messages and listings for compiler-detected
LANGUAGE . . . . . . . . . . . . . 305
errors . . . . . . . . . . . . . . . 266
LIB . . . . . . . . . . . . . . . . . 306
Format of compiler error messages . . . . . 266
LINECOUNT . . . . . . . . . . . . . 306
Severity codes for compiler error messages . . 267
LIST . . . . . . . . . . . . . . . . 306
MAP . . . . . . . . . . . . . . . . 307
Chapter 16. Compiling under UNIX 269 NAME . . . . . . . . . . . . . . . 308
Setting environment variables under UNIX . . . 269 NSYMBOL . . . . . . . . . . . . . . 309
Specifying compiler options under UNIX . . . . 270 NUMBER . . . . . . . . . . . . . . 309
Compiling and linking with the cob2 command 271 NUMPROC . . . . . . . . . . . . . . 310
Defining input and output . . . . . . . . 271 OBJECT . . . . . . . . . . . . . . . 311
Creating a DLL . . . . . . . . . . . . 272 OFFSET . . . . . . . . . . . . . . . 312
Example: using cob2 to compile under UNIX 272 OPTIMIZE . . . . . . . . . . . . . . 312
cob2 . . . . . . . . . . . . . . . 273 Unused data items . . . . . . . . . . 312
cob2 input and output files . . . . . . . . 274 OUTDD . . . . . . . . . . . . . . . 313
Compiling using scripts . . . . . . . . . . 275 PGMNAME . . . . . . . . . . . . . . 314
PGMNAME(COMPAT) . . . . . . . . . 314
vi Programming Guide
PGMNAME(LONGUPPER). . . . . . . . 314 Chapter 20. Developing COBOL
PGMNAME(LONGMIXED) . . . . . . . 315 programs for CICS . . . . . . . . . 375
QUOTE/APOST . . . . . . . . . . . . 316 Coding COBOL programs to run under CICS . . 375
RENT . . . . . . . . . . . . . . . . 316 Coding file input and output . . . . . . . 376
RMODE . . . . . . . . . . . . . . . 317 Retrieving the system date and time. . . . . 376
SEQUENCE . . . . . . . . . . . . . . 318 Displaying the contents of data items . . . . 377
SIZE . . . . . . . . . . . . . . . . 318 Calling to or from COBOL programs . . . . 377
SOURCE . . . . . . . . . . . . . . . 319 Coding nested programs . . . . . . . . 377
SPACE . . . . . . . . . . . . . . . 319 Coding a COBOL program to run above the
SQL . . . . . . . . . . . . . . . . 320 16-MB line . . . . . . . . . . . . . 378
SSRANGE . . . . . . . . . . . . . . 321 Determining the success of ECI calls. . . . . 378
TERMINAL . . . . . . . . . . . . . . 321 Compiling with the CICS option . . . . . . . 378
TEST . . . . . . . . . . . . . . . . 322 Compiling a sequence of programs . . . . . 379
THREAD . . . . . . . . . . . . . . . 325 Separating CICS suboptions . . . . . . . 379
TRUNC . . . . . . . . . . . . . . . 326 Integrated CICS translator . . . . . . . . 380
TRUNC example 1 . . . . . . . . . . 327 Using the separate CICS translator . . . . . . 381
TRUNC example 2 . . . . . . . . . . 328 CICS reserved-word table . . . . . . . . . 382
VBREF . . . . . . . . . . . . . . . 329 Handling errors by using CICS HANDLE . . . . 383
WORD . . . . . . . . . . . . . . . 329 Example: handling errors by using CICS
XREF . . . . . . . . . . . . . . . . 330 HANDLE . . . . . . . . . . . . . 383
YEARWINDOW . . . . . . . . . . . . 331
ZWB . . . . . . . . . . . . . . . . 331
Compiler-directing statements . . . . . . . . 332
Chapter 21. Programming for a DB2
environment . . . . . . . . . . . . 385
Chapter 19. Debugging . . . . . . . 337 Coding SQL statements . . . . . . . . . . 385
Using SQL INCLUDE with the DB2 coprocessor 385
Debugging with source language . . . . . . . 338
Using character data . . . . . . . . . . 385
Tracing program logic . . . . . . . . . 338
Using binary items . . . . . . . . . . 386
Finding and handling input-output errors . . . 339
Determining the success of SQL statements . . 387
Validating data . . . . . . . . . . . . 339
Compiling with the SQL option . . . . . . . 387
Finding uninitialized data . . . . . . . . 339
Compiling in batch . . . . . . . . . . 388
Generating information about procedures . . . 340
Separating DB2 suboptions . . . . . . . . 388
Debugging using compiler options . . . . . . 341
DB2 coprocessor . . . . . . . . . . . 388
Finding coding errors . . . . . . . . . 342
Finding line sequence problems . . . . . . 343
Checking for valid ranges . . . . . . . . 343 Chapter 22. Developing COBOL
Selecting the level of error to be diagnosed . . 344 programs for IMS. . . . . . . . . . 391
Finding program entity definitions and Compiling and linking COBOL programs for
references . . . . . . . . . . . . . 345 running under IMS . . . . . . . . . . . 391
Listing data items . . . . . . . . . . . 346 Using object-oriented COBOL and Java under IMS 392
Getting listings . . . . . . . . . . . . . 347 Calling a COBOL method from an IMS Java
Example: short listing . . . . . . . . . 348 application . . . . . . . . . . . . . 392
Example: SOURCE and NUMBER output . . . 351 Building a mixed COBOL and Java application
Example: embedded map summary . . . . . 353 that starts with COBOL . . . . . . . . . 393
Terms used in MAP output. . . . . . . . 354 Writing mixed-language applications . . . . 394
Symbols used in LIST and MAP output . . . 354
Example: nested program map . . . . . . 356 Chapter 23. Running COBOL
Reading LIST output . . . . . . . . . . 356 programs under UNIX . . . . . . . . 397
Example: XREF output - data-name
Running in UNIX environments . . . . . . . 397
cross-references. . . . . . . . . . . . 368
Setting and accessing environment variables . . . 398
Example: XREF output - program-name
Setting environment variables that affect
cross-references. . . . . . . . . . . . 369
execution . . . . . . . . . . . . . . 398
Example: embedded cross-reference . . . . . 369
Resetting environment variables . . . . . . 399
Example: OFFSET compiler output . . . . . 370
Accessing environment variables . . . . . . 399
Example: VBREF compiler output . . . . . 371
Example: accessing environment variables . . . 400
Preparing to use the debugger. . . . . . . . 371
Calling UNIX/POSIX APIs . . . . . . . . . 400
fork(), exec(), and spawn() . . . . . . . . 400
Part 3. Targeting COBOL programs Samples . . . . . . . . . . . . . . 401
for certain environments . . . . . 373 Accessing main program parameters . . . . . 402
Example: accessing main program parameters 402
Contents vii
Part 4. Structuring complex Using DLLs in OO COBOL applications . . . . 446
applications . . . . . . . . . . . 405
Chapter 27. Preparing COBOL
programs for multithreading . . . . . 449
Chapter 24. Using subprograms . . . 407
Multithreading . . . . . . . . . . . . . 449
Main programs, subprograms, and calls . . . . 408
Choosing THREAD to support multithreading . . 451
Ending and reentering main programs or
Transferring control with multithreading . . . . 451
subprograms . . . . . . . . . . . . . 408
Using cancel with threaded programs . . . . 451
Transferring control to another program . . . . 410
Ending a program . . . . . . . . . . . 451
Making static calls. . . . . . . . . . . 410
Preinitializing the COBOL environment . . . 452
Making dynamic calls . . . . . . . . . 411
Processing files with multithreading . . . . . . 452
Performance considerations of static and
File definition storage . . . . . . . . . 452
dynamic calls . . . . . . . . . . . . 413
Recommended usage for file access . . . . . 453
Making both static and dynamic calls . . . . 414
Example: usage patterns of file input and
Examples: static and dynamic CALL statements 414
output with multithreading. . . . . . . . 453
Calling nested COBOL programs . . . . . . 416
Handling COBOL limitations with multithreading 454
Making recursive calls . . . . . . . . . . 419
Calling to and from object-oriented programs . . 419
Using procedure and function pointers . . . . . 420 Part 5. Developing object-oriented
Deciding which type of pointer to use . . . . 421 programs . . . . . . . . . . . . 457
Calling a C function pointer . . . . . . . 421
Calling to alternate entry points . . . . . . 421
Chapter 28. Writing object-oriented
Making programs reentrant . . . . . . . . 422
programs . . . . . . . . . . . . . 459
Example: accounts. . . . . . . . . . . . 460
Chapter 25. Sharing data . . . . . . 423
Subclasses . . . . . . . . . . . . . 461
Passing data . . . . . . . . . . . . . . 423
Defining a class . . . . . . . . . . . . 462
Describing arguments in the calling program 424
CLASS-ID paragraph for defining a class . . . 464
Describing parameters in the called program 425
REPOSITORY paragraph for defining a class 464
Testing for OMITTED arguments . . . . . . 425
WORKING-STORAGE SECTION for defining
Coding the LINKAGE SECTION . . . . . . . 425
class instance data . . . . . . . . . . . 466
Coding the PROCEDURE DIVISION for passing
Example: defining a class . . . . . . . . 467
arguments . . . . . . . . . . . . . . 426
Defining a class instance method . . . . . . . 467
Grouping data to be passed . . . . . . . 426
METHOD-ID paragraph for defining a class
Handling null-terminated strings . . . . . . 426
instance method . . . . . . . . . . . 468
Using pointers to process a chained list . . . 427
INPUT-OUTPUT SECTION for defining a class
Passing return code information . . . . . . . 430
instance method . . . . . . . . . . . 469
Understanding the RETURN-CODE special
DATA DIVISION for defining a class instance
register . . . . . . . . . . . . . . 430
method . . . . . . . . . . . . . . 469
Using PROCEDURE DIVISION RETURNING . .
PROCEDURE DIVISION for defining a class
.. . . . . . . . . . . . . . . . . 431
instance method . . . . . . . . . . . 470
Specifying CALL . . . RETURNING . . . . . 431
Overriding an instance method . . . . . . 471
Sharing data by using the EXTERNAL clause. . . 431
Overloading an instance method . . . . . . 472
Sharing files between programs (external files) . . 432
Coding attribute (get and set) methods . . . . 473
Example: using external files . . . . . . . 432
Example: defining a method . . . . . . . 474
Defining a client . . . . . . . . . . . . 475
Chapter 26. Creating a DLL or a DLL REPOSITORY paragraph for defining a client 477
application . . . . . . . . . . . . 437 DATA DIVISION for defining a client . . . . 478
Dynamic link libraries (DLLs) . . . . . . . . 437 Comparing and setting object references . . . 479
Compiling programs to create DLLs . . . . . . 438 Invoking methods (INVOKE) . . . . . . . 480
Linking DLLs . . . . . . . . . . . . . 439 Creating and initializing instances of classes . . 482
Example: sample JCL for a procedural DLL Freeing instances of classes . . . . . . . . 483
application . . . . . . . . . . . . . . 440 Example: defining a client . . . . . . . . 484
Prelinking certain DLLs . . . . . . . . . . 441 Defining a subclass . . . . . . . . . . . 484
Using CALL identifier with DLLs . . . . . . 441 CLASS-ID paragraph for defining a subclass 485
Search order for DLLs in HFS . . . . . . . 442 REPOSITORY paragraph for defining a subclass 486
Using DLL linkage and dynamic calls together . . 442 WORKING-STORAGE SECTION for defining
Using procedure or function pointers with DLLs 443 subclass instance data . . . . . . . . . 486
Calling DLLs from non-DLLs . . . . . . . 444 Defining a subclass instance method . . . . 487
Example: calling DLLs from non-DLLs . . . . 444 Example: defining a subclass (with methods) 487
Using COBOL DLLs with C/C++ programs . . . 446 Defining a factory section . . . . . . . . . 488
Contents ix
Example: Language Environment callable Calling from exit modules . . . . . . . . . 613
services . . . . . . . . . . . . . . 573 Processing of INEXIT. . . . . . . . . . . 613
Parameter list for INEXIT . . . . . . . . 613
Processing of LIBEXIT . . . . . . . . . . 614
Part 8. Appendixes . . . . . . . . 575
Processing of LIBEXIT with nested COPY
statements . . . . . . . . . . . . . 615
Appendix A. Intermediate results and Parameter list for LIBEXIT . . . . . . . . 616
arithmetic precision . . . . . . . . 577 Processing of PRTEXIT . . . . . . . . . . 617
Terminology used for intermediate results . . . . 578 Parameter list for PRTEXIT . . . . . . . . 617
Example: calculation of intermediate results . . . 579 Processing of ADEXIT . . . . . . . . . . 618
Fixed-point data and intermediate results . . . . 579 Parameter list for ADEXIT . . . . . . . . 619
Addition, subtraction, multiplication, and Error handling for exit modules . . . . . . . 619
division . . . . . . . . . . . . . . 579 Using the EXIT compiler option with CICS and
Exponentiation . . . . . . . . . . . . 580 SQL statements . . . . . . . . . . . . . 620
Example: exponentiation in fixed-point INEXIT . . . . . . . . . . . . . . 620
arithmetic . . . . . . . . . . . . . 581 LIBEXIT . . . . . . . . . . . . . . 620
Truncated intermediate results. . . . . . . 582 PRTEXIT . . . . . . . . . . . . . . 620
Binary data and intermediate results . . . . 582 ADEXIT . . . . . . . . . . . . . . 621
Intrinsic functions evaluated in fixed-point Example: INEXIT user exit . . . . . . . . . 621
arithmetic . . . . . . . . . . . . . . 583
Integer functions . . . . . . . . . . . 583 Appendix F. JNI.cpy . . . . . . . . 625
Mixed functions . . . . . . . . . . . 583
Floating-point data and intermediate results . . . 584
Appendix G. COBOL SYSADATA file
Exponentiations evaluated in floating-point
arithmetic . . . . . . . . . . . . . 585 contents . . . . . . . . . . . . . 631
Intrinsic functions evaluated in floating-point Existing compiler options affecting the SYSADATA
arithmetic . . . . . . . . . . . . . 585 file . . . . . . . . . . . . . . . . . 631
Arithmetic expressions in nonarithmetic statements 586 Record types . . . . . . . . . . . . . 632
Example: SYSADATA . . . . . . . . . . 633
SYSADATA record descriptions . . . . . . . 634
Appendix B. Complex OCCURS
Common header section . . . . . . . . . . 635
DEPENDING ON . . . . . . . . . . 587 Job identification record - X’0000’. . . . . . . 636
Example: complex ODO . . . . . . . . . . 587 ADATA identification record - X’0001’ . . . . . 637
How length is calculated . . . . . . . . 588 Compilation unit start/end record - X’0002’ . . . 637
Setting values of ODO objects . . . . . . . 588 Options record - X’0010’ . . . . . . . . . . 638
Effects of change in ODO object value . . . . . 588 External symbol record - X’0020’ . . . . . . . 647
Preventing index errors when changing ODO Parse tree record - X’0024’ . . . . . . . . . 648
object value . . . . . . . . . . . . . 589 Token record - X’0030’ . . . . . . . . . . 661
Preventing overlay when adding elements to a Source error record - X’0032’ . . . . . . . . 662
variable table . . . . . . . . . . . . 589 Source record - X’0038’ . . . . . . . . . . 662
COPY REPLACING record - X’0039’. . . . . . 663
Appendix C. Converting double-byte Symbol record - X’0042’ . . . . . . . . . . 664
character set (DBCS) data . . . . . . 593 Symbol cross-reference record - X’0044’ . . . . . 675
DBCS notation . . . . . . . . . . . . . 593 Nested program record - X’0046’ . . . . . . . 676
Alphanumeric to DBCS data conversion Library record - X’0060’ . . . . . . . . . . 677
(IGZCA2D) . . . . . . . . . . . . . . 593 Statistics record - X’0090’ . . . . . . . . . 678
IGZCA2D syntax . . . . . . . . . . . 593 EVENTS record - X’0120’ . . . . . . . . . 678
IGZCA2D return codes . . . . . . . . . 594
Example: IGZCA2D . . . . . . . . . . 595 Appendix H. Sample programs . . . . 679
DBCS to alphanumeric data conversion (IGZCD2A) 595 IGYTCARA: batch application . . . . . . . . 679
IGZCD2A syntax . . . . . . . . . . . 595 Input data for IGYTCARA . . . . . . . . 680
IGZCD2A return codes . . . . . . . . . 596 Report produced by IGYTCARA . . . . . . 681
Example: IGZCD2A . . . . . . . . . . 597 Preparing to run IGYTCARA . . . . . . . 682
IGYTCARB: interactive program . . . . . . . 683
Appendix D. XML reference material 599 Preparing to run IGYTCARB . . . . . . . 684
XML exceptions that allow continuation . . . . 599 IGYTSALE: nested program application . . . . 686
XML exceptions that do not allow continuation . . 603 Input data for IGYTSALE . . . . . . . . 687
XML conformance . . . . . . . . . . . . 606 Reports produced by IGYTSALE . . . . . . 689
Preparing to run IGYTSALE . . . . . . . 693
Appendix E. EXIT compiler option . . 611 Language elements and concepts that are
illustrated . . . . . . . . . . . . . . 694
Using the user-exit work area . . . . . . . . 612
x Programming Guide
Notices . . . . . . . . . . . . . . 699 Enterprise COBOL for z/OS and OS/390 . . . . 725
Trademarks . . . . . . . . . . . . . . 700 Related publications . . . . . . . . . . . 725
Contents xi
xii Programming Guide
About this document
Welcome to IBM Enterprise COBOL for z/OS and OS/390, IBM’s latest host
COBOL compiler!
This version of IBM COBOL adds new COBOL function to help integrate COBOL
business processes and Web-oriented business processes by:
v Simplifying the componentization of COBOL programs and enabling
interoperability with Java components
v Promoting the exchange and usage of data in standardized formats, including
XML and Unicode
For a comparison of commonly used Enterprise COBOL and IBM z/OS Language
Environment terms, see “Comparison of commonly used terms” on page xiv.
Abbreviated terms
Certain terms are used in a shortened form in this document. Abbreviations for the
product names used most frequently are listed alphabetically in the following
table:
Other terms, if not commonly understood, are shown in italics the first time that
they appear, and are listed in the glossary at the back of this document.
v 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 choosing one of the items is optional, the entire stack appears below the main
path:
If one of the items is the default, it appears above the main path and the
remaining choices are shown below:
v 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:
v Keywords appear in uppercase (for example, FROM). They must be spelled exactly
as shown. Variables appear in lowercase italics (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.
To more clearly separate some examples from the explanatory text, they are
presented in a monospace font.
Summary of changes
This section lists the key changes that have been made to Enterprise COBOL for
z/OS and OS/390. The changes that are discussed in this document have an
associated page reference for your convenience. The latest technical changes are
marked by a revision bar in the left margin.
| For further details about these enhancements to debugging support, see Debug
| Tool User’s Guide.
| v Extending Java interoperability to IMS: Object-oriented COBOL programs can
| run in an IMS Java dependent region. The object-oriented COBOL and Java
| languages can be mixed in a single application (“Using object-oriented COBOL
| and Java under IMS” on page 392).
| v Enhanced support for Java interoperability:
| – The OPTIMIZE compiler option is fully supported for programs that contain
| OO syntax for Java interoperability.
| – Object references of type jobjectArray are supported for interoperation
| between COBOL and Java (“Declaring arrays and strings for Java” on
| page 506).
| – OO applications that begin with a COBOL main factory method can be
| invoked with the java command (“Structuring OO applications” on page 498).
| – A new environment variable, COBJVMINITOPTIONS, is provided, enabling
| the user to specify options that will be used when COBOL initializes a Java
| virtual machine (JVM) (“Running OO applications under UNIX” on page 279).
| – OO applications that begin with a COBOL program can, with some
| limitations, be bound as modules in a PDSE and run using batch JCL
| (“Preparing and running OO applications using JCL or TSO/E” on page 282).
| v Unicode enhancement for working with DB2: The code pages for host variables
| are handled implicitly when you use the DB2 integrated coprocessor. SQL
| DECLARE statements are necessary only for variables described with USAGE
| DISPLAY or USAGE DISPLAY-1 when COBOL and DB2 code pages do not match
| (“Coding SQL statements” on page 385).
Be sure to include the name of the document, the publication number of the
document, the version of Enterprise COBOL, and, if applicable, the specific
location (for example, page number) of the text that you are commenting on.
When you send information to IBM, you grant IBM a nonexclusive right to use or
distribute the information in any way it believes appropriate without incurring any
obligation to you.
2 Programming Guide
Establishing record formats. . . . . . . . 120 Specifying relative organization for VSAM files 151
Logical records . . . . . . . . . . . 120 Fixed-length and variable-length RRDS . . . 152
Requesting fixed-length format . . . . . 121 Simulating variable-length RRDS . . . . . 152
Requesting variable-length format . . . . 122 Specifying access modes for VSAM files . . . 153
Requesting spanned format. . . . . . . 124 Example: using dynamic access with VSAM
Requesting undefined format . . . . . . 126 files . . . . . . . . . . . . . . 154
Setting block sizes . . . . . . . . . . . 127 Defining record lengths for VSAM files. . . . 154
Letting z/OS determine block size . . . . 127 Defining fixed-length records . . . . . . 154
Setting block size explicitly . . . . . . . 127 Defining variable-length records . . . . . 154
Taking advantage of LBI. . . . . . . . 128 Coding input and output statements for VSAM
Block size and the DCB RECFM files . . . . . . . . . . . . . . . . 155
subparameter . . . . . . . . . . . 129 File position indicator . . . . . . . . . 157
Coding input and output statements for QSAM Opening a file (ESDS, KSDS, or RRDS) . . . . 157
files . . . . . . . . . . . . . . . . 129 Opening an empty file . . . . . . . . 158
Opening QSAM files . . . . . . . . . . 130 Statements to load records into a VSAM file 159
Dynamically creating QSAM files with Opening a loaded file (a file with records) 159
CBLQDA . . . . . . . . . . . . . . 130 Reading records from a VSAM file . . . . . 159
Adding records to QSAM files. . . . . . . 131 Updating records in a VSAM file . . . . . . 160
Updating QSAM files . . . . . . . . . 131 Adding records to a VSAM file . . . . . . 161
Writing QSAM files to a printer or spooled data Adding records sequentially . . . . . . 161
set . . . . . . . . . . . . . . . . 131 Adding records randomly or dynamically 162
Controlling the page size . . . . . . . 132 Replacing records in a VSAM file. . . . . . 162
Controlling the vertical positioning of records 132 Deleting records from a VSAM file . . . . . 162
Closing QSAM files . . . . . . . . . . 132 Closing VSAM files . . . . . . . . . . 162
Handling errors in QSAM files . . . . . . . 133 Handling errors in VSAM files . . . . . . . 163
Working with QSAM files . . . . . . . . . 133 Protecting VSAM files with a password . . . . 164
Defining and allocating QSAM files . . . . . 134 Example: password protection for a VSAM
Parameters for creating QSAM files . . . . 135 indexed file . . . . . . . . . . . . . 164
Retrieving QSAM files . . . . . . . . . 136 Working with VSAM data sets under z/OS and
Parameters for retrieving QSAM files . . . 136 UNIX . . . . . . . . . . . . . . . . 165
Ensuring file attributes match your program 137 Defining VSAM files . . . . . . . . . . 165
Processing existing files . . . . . . . . 137 Creating alternate indexes . . . . . . . . 166
Defining variable-length (format-V) records 137 Example: entries for alternate indexes . . . 168
Defining format-U records . . . . . . . 138 Allocating VSAM files . . . . . . . . . 168
Defining fixed-length records . . . . . . 138 Sharing VSAM files through RLS . . . . . . 170
Processing new files . . . . . . . . . 138 Preventing update problems with VSAM files
Processing files dynamically created by in RLS mode . . . . . . . . . . . 170
COBOL . . . . . . . . . . . . . 139 Restrictions when using RLS . . . . . . 170
Using striped extended-format QSAM data sets 139 Handling errors in VSAM files in RLS mode 171
Allocation of buffers for QSAM files. . . . 140 Improving VSAM performance . . . . . . . 171
Accessing HFS files using QSAM . . . . . . . 140
Labels for QSAM files . . . . . . . . . . 141 Chapter 11. Processing line-sequential files . . 173
Using trailer and header labels . . . . . . 141 Defining line-sequential files and records in
Getting a user-label track . . . . . . . 142 COBOL . . . . . . . . . . . . . . . 173
Handling user labels . . . . . . . . . 142 Allowable control characters . . . . . . . 174
Format of standard labels . . . . . . . . 143 Describing the structure of a line-sequential file 174
Standard user labels . . . . . . . . . 143 Defining and allocating line-sequential files . . . 175
Processing QSAM ASCII files on tape . . . . . 143 Coding input-output statements for line-sequential
Requesting the ASCII alphabet . . . . . . 144 files . . . . . . . . . . . . . . . . 175
Defining the record formats . . . . . . . 144 Opening line-sequential files . . . . . . . 176
Defining the ddname . . . . . . . . . . 144 Reading records from line-sequential files . . . 176
Processing ASCII file labels . . . . . . . . . 145 Adding records to line-sequential files . . . . 177
Closing line-sequential files. . . . . . . . 177
Chapter 10. Processing VSAM files . . . . . 147 Handling errors in line-sequential files . . . . . 178
VSAM files . . . . . . . . . . . . . . 148
Defining VSAM file organization and records . . 149 Chapter 12. Sorting and merging files . . . . 179
Specifying sequential organization for VSAM Sort and merge process . . . . . . . . . . 180
files . . . . . . . . . . . . . . . 150 Describing the sort or merge file . . . . . . . 180
Specifying indexed organization for VSAM files 150 Describing the input to sorting or merging . . . 181
Alternate keys . . . . . . . . . . . 151 Example: describing sort and input files for
Alternate index . . . . . . . . . . . 151 SORT . . . . . . . . . . . . . . . 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
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 462
“Defining a class instance method” on page 467
“Structuring OO applications” on page 498
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/21/2002.
Date-Compiled. 08/21/2002.
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 or binder 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:
Tip: When the program name is case sensitive, avoid mismatches with the name
the compiler is looking for. Verify that the appropriate setting of the PGMNAME
compiler option is used.
RELATED TASKS
“Changing the header of a source listing” on page 7
“Identifying a program as recursive”
“Marking a program as callable by containing programs”
“Setting a program to an initial state”
RELATED REFERENCES
Compiler limits (Enterprise COBOL Language Reference)
Conventions for program names (Enterprise 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. You must code RECURSIVE for programs that you compile with the THREAD
option.
RELATED TASKS
“Sharing data in recursive or multithreaded programs” on page 17
“Making recursive calls” on page 419
RELATED CONCEPTS
“Nested programs” on page 416
6 Programming Guide
Changing the header of a source listing
The header on the first page of your source statement listing contains the
identification of the compiler and the current release level, plus the date and time
of compilation and the page number. For example:
PP 5655-G53 IBM Enterprise COBOL for z/OS and OS/390 3.2.0 Date 08/21/2002 Time 15:05:19 Page 1
You can customize the header on succeeding pages of the listing with the
compiler-directing TITLE statement.
RELATED REFERENCES
TITLE statement (Enterprise 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 10
“Defining files to the operating system” on page 10
RELATED REFERENCES
Sections and paragraphs (Enterprise 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 9, “Processing QSAM files” on page 119
Chapter 10, “Processing VSAM files” on page 147
Chapter 11, “Processing line-sequential files” on page 173
“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
The PROGRAM COLLATING SEQUENCE clause does not affect comparisons that involve
national operands.
8 Programming Guide
RELATED TASKS
“Choosing alternate collating sequences” on page 188
“Comparing national data items” on page 110
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.
The following shows the relationship of a FILE-CONTROL entry to the system data
definition and to the FD entry in the FILE SECTION.
v JCL DD statement:
(1)
//OUTFILE DD DSNAME=MY.OUT171,UNIT=SYSDA,SPACE=(TRK,(50,5)),
// DCB=(BLKSIZE=400)
/*
. . .
v Environment variable (export command):
(1)
export OUTFILE=DSNAME(MY.OUT171),UNIT(SYSDA),SPACE(TRK,(50,5))
. . .
v COBOL code:
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT CARPOOL
ASSIGN TO OUTFILE (1)
ORGANIZATION IS SEQUENTIAL.
. . .
DATA DIVISION.
FILE SECTION.
FD CARPOOL (2)
LABEL RECORD STANDARD
BLOCK CONTAINS 0 CHARACTERS
RECORD CONTAINS 80 CHARACTERS
(1) The ddname in the DD statement or the environment variable name in the
export command, corresponds to the assignment-name in the ASSIGN clause:
v //OUTFILE DD DSNAME=OUT171 . . ., or
v export OUTFILE= . . .
10 Programming Guide
SELECT CARPOOL
. . .
FD CARPOOL
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 or the
environment variable in the export command. You can change the actual file by
using the DSNAME in the DD statement or the DSNAME or path name in the
environment variable.
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: 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
Assume the three possible input files are MASTER1, MASTER2, and MASTER3. 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.
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 292
The Enterprise COBOL compiler limits the maximum size of DATA DIVISION
elements.
RELATED CONCEPTS
“Comparison of WORKING-STORAGE and LOCAL-STORAGE” on page 14
RELATED TASKS
“Using data in input and output operations”
“Using data from another program” on page 16
RELATED REFERENCES
Compiler limits (Enterprise COBOL Language Reference)
12 Programming Guide
v In the record description following the FD entry, describe the fields of the records
in the file:
– You can code a level-01 description of the entire record, and then in the
WORKING-STORAGE SECTION code a working copy that describes the fields of the
record in more detail. Use the READ INTO statement to bring the records into
WORKING-STORAGE. Processing occurs on the copy of data in WORKING-STORAGE.
A WRITE FROM statement then writes processed data into the record area
defined in the FILE SECTION.
– The record-name established is the object of WRITE and REWRITE statements.
– For QSAM files only, you can set the record format in the RECORDING MODE
clause. If you omit the RECORDING MODE clause, the compiler determines the
record format based on the RECORD clause and on the level-01 record
descriptions.
– For QSAM files, you can set a blocking factor for the file in the BLOCK
CONTAINS clause. If you omit the BLOCK CONTAINS clause, the file defaults to
unblocked. However, you can override this with z/OS data management
facilities (including a DD file job control statement).
– For line-sequential files, you can set a blocking factor for the file in the BLOCK
CONTAINS clause. When you code BLOCK CONTAINS 1 RECORDS, or BLOCK
CONTAINS n CHARACTERS, where n is the length of one logical record, WRITE
statements result in the record being transferred immediately to the file,
rather than being buffered. This technique is useful when you want each
record written immediately, such as to an error log.
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.
You can use the GLOBAL clause for programs in a nested, or contained, structure. If
a program contains another program (directly or indirectly), both programs can
access a common file by referencing a GLOBAL file name.
RELATED CONCEPTS
“Nested programs” on page 416
RELATED TASKS
“Sharing files between programs (external files)” on page 432
RELATED REFERENCES
“FILE SECTION entries”
RELATED CONCEPTS
“Labels for QSAM files” on page 141
14 Programming Guide
In this case, WORKING-STORAGE data items are reinitialized each time that the
program is entered.
v A subprogram that is dynamically called and then canceled
In this case, WORKING-STORAGE data items are reinitialized on the first reentry into
the program following the CANCEL.
| See the related tasks for information about WORKING-STORAGE in COBOL class
| definitions.
RELATED TASKS
“WORKING-STORAGE SECTION for defining class instance data” on page 466
Chapter 27, “Preparing COBOL programs for multithreading” on page 449
“Ending and reentering main programs or subprograms” on page 408
RELATED REFERENCES
Working-Storage section (Enterprise COBOL Language Reference)
Local-Storage section (Enterprise 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 14
RELATED TASKS
“Sharing data in separately compiled programs”
“Sharing data in nested programs”
RELATED TASKS
“Passing data” on page 423
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 416
16 Programming Guide
Sharing data in recursive or multithreaded programs
If you compile your program as RECURSIVE or with the THREAD compiler option,
data that is defined in the LINKAGE SECTION is not accessible on subsequent
invocations of the program.
If you compile your program as RECURSIVE or with the THREAD compiler option, the
address of the record is valid for a particular instance of the program invocation.
The address of the record in another execution instance of the same program must
be reestablished for that execution instance. Unpredictable results will occur if you
refer to a data item for which the address has not been established.
RELATED CONCEPTS
“Multithreading” on page 449
RELATED TASKS
“Making recursive calls” on page 419
“Processing files with multithreading” on page 452
RELATED REFERENCES
SET statement (Enterprise COBOL Language Reference)
“THREAD” on page 325
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.
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:
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 569
RELATED CONCEPTS
“Compiler-directing statements” on page 20
“Scope terminators” on page 20
“Imperative statements” on page 19
“Conditional statements” on page 19
“Declaratives” on page 21
RELATED REFERENCES
PROCEDURE DIVISION structure (Enterprise COBOL Language Reference)
18 Programming Guide
Imperative statements
An imperative statement indicates an unconditional action to be taken (such as
ADD, MOVE, INVOKE, or CLOSE).
RELATED CONCEPTS
“Conditional statements”
“Scope terminators” on page 20
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.
RELATED CONCEPTS
“Imperative statements” on page 19
“Scope terminators”
RELATED TASKS
“Selecting program actions” on page 75
RELATED REFERENCES
Conditional statements (Enterprise 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 332
Compiler-directing statements (Enterprise 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
20 Programming Guide
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.
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 19
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 339
RELATED REFERENCES
Declaratives (Enterprise COBOL Language Reference)
RELATED CONCEPTS
“Storage and its addressability” on page 33
RELATED TASKS
“Using variables, structures, literals, and constants”
“Assigning values to data items” on page 25
“Displaying values on a screen or in a file (DISPLAY)” on page 30
“Using intrinsic functions (built-in functions)” on page 32
“Using tables (arrays) and pointers” on page 33
Chapter 7, “Coding for run-time use of national languages” on page 103
Variables
A variable is a data item; its 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
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:
24 Programming Guide
Move Spaces To Report-Header
RELATED REFERENCES
PICTURE clause (Enterprise COBOL Language Reference)
Literals (Enterprise COBOL Language Reference)
Figurative constants (Enterprise COBOL Language Reference)
RELATED TASKS
“Initializing a structure (INITIALIZE)” on page 27
“Assigning values to variables or structures (MOVE)” on page 27
“Joining data items (STRING)” on page 87
“Splitting data items (UNSTRING)” on page 89
“Assigning arithmetic results (MOVE or COMPUTE)” on page 28
“Tallying and replacing data items (INSPECT)” on page 95
“Assigning input from a screen or file (ACCEPT)” on page 29
“Displaying values on a screen or in a file (DISPLAY)” on page 30
Chapter 7, “Coding for run-time use of national languages” on page 103
26 Programming Guide
RELATED TASKS
“Initializing a structure (INITIALIZE)”
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 that contain 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):
This move would result in Item-x containing the value 3.0, represented by 0030.
You can move an alphanumeric item or an integer item to a national variable; the
item is converted. You can move a national item only to another national variable.
In either case padding or truncation might occur, and you must ensure that
truncation does not occur within a character.
The following example shows a data item in the Greek language that moves into a
national data item:
CBL CODEPAGE(00875)
. . .
01 Data-in-Unicode Pic N(100) usage national.
01 Data-in-Greek Pic X(100).
. . .
Read Greek-file into Data-in-Greek
Move Data-in-Greek to Data-in-Unicode
RELATED CONCEPTS
“Unicode and encoding of language characters” on page 105
RELATED REFERENCES
MOVE statement (Enterprise COBOL Language Reference)
“CODEPAGE” on page 294
“Converting national data” on page 107
The MOVE statement carries out the assignment with truncation. You can, however,
specify the DIAGTRUNC compiler option to request that the compiler issue a warning
diagnostic for MOVE statements that might truncate numeric receivers.
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)
28 Programming Guide
statement, and the values they return are passed in the parameters in the CALL
statement. For example, you can call the Language Environment service CEESIABS
to find the absolute value of a variable with the statement:
Call ’CEESIABS’ Using Arg, Feedback-code, Result.
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 298
Intrinsic functions (Enterprise 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:
v Change Console to device, where device is any valid system device (for example,
SYSIN). For example:
SYSIN is Names-Input
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 a UNIX
environment, stdin is the input source. If this DD is not defined and your
program is not running in a UNIX environment, the ACCEPT statement fails.
When you assign a value to a national data item, input data from the console is
converted from EBCDIC to Unicode representation (UTF-16), based on the value of
the CODEPAGE option. This is the only situation where conversion of national data is
done when you use the ACCEPT statement, because the input is known to be
coming from a screen.
If you want conversion done when the input data is from any other device, use the
NATIONAL-OF intrinsic function.
RELATED CONCEPTS
“Unicode and encoding of language characters” on page 105
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.
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 following statement writes to the job log or console and to the TSO screen if
you are running under TSO:
Display “Hello” upon console.
When you display the value of a national data item to the console, it is converted
from Unicode representation (UTF-16) to EBCDIC, based on the value of the
CODEPAGE option. This is the only situation where conversion of national data is
done when you use the DISPLAY statement, because the output is known to be
directed to a screen.
If you want a national data item to be converted when you direct output to a
different device, use the DISPLAY-OF intrinsic function, such as in this example:
01 Data-in-Unicode pic N(10) usage national.
. . .
Display function Display-of(Data-in-Unicode, 00037)
The output is directed to the ddname that you specify in the OUTDD compiler
option. 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 a UNIX
environment, a default DD of SYSOUT=* is allocated.
30 Programming Guide
Other documents randomly have
different content
THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
ebookbell.com