COBOL for AIX
Programming Guide
Ve r s i o n 4 .1
SC27-3601-00
COBOL for AIX
Programming Guide
Ve r s i o n 4 .1
SC27-3601-00 Note! Before using this information and the product it supports, be sure to read the general information under “Notices” on page 807.
First Edition (September 2010) This edition applies to Version 4.1 of IBM COBOL for AIX (program number 5724-Z87) and to all subsequent releases and modifications until otherwise indicated in new editions. Make sure you are using the correct edition for the level of the product. You can order publications online at www.ibm.com/shop/publications/order/, or order by phone or fax. IBM Software Manufacturing Solutions takes publication orders between 8:30 a.m. and 7:00 p.m. Eastern Standard Time (EST). The phone number is (800)879-2755. The fax number is (800)445-9269. You can also order publications through your IBM representative or the IBM branch office serving your locality. © Copyright IBM Corporation 1995, 2010. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents
Tables ...... xi Assigning values to elementary data items (MOVE) ...... 32 Preface ...... xiii Assigning values to group data items (MOVE) . 33 Assigning arithmetic results (MOVE or About this information ...... xiii COMPUTE) ...... 34 How this information will help you .....xiii Assigning input from a screen or file (ACCEPT) 34 Abbreviated terms ...... xiii Displaying values on a screen or in a file (DISPLAY) 35 How to read syntax diagrams ...... xiv Using intrinsic functions (built-in functions) . . . 36 How examples are shown ...... xv Using tables (arrays) and pointers ...... 37 Related information ...... xvi Summary of changes ...... xvi || Version 4.1 (September 2010) ...... xvi Chapter 3. Working with numbers and How to send your comments ...... xvii arithmetic ...... 39 Accessibility ...... xvii Defining numeric data...... 39 Interface information ...... xviii Displaying numeric data ...... 41 Keyboard navigation ...... xviii Controlling how numeric data is stored .....42 Accessibility of this information ...... xviii Formats for numeric data...... 43 IBM and accessibility ...... xviii External decimal (DISPLAY and NATIONAL) items ...... 43 Part 1. Coding your program ....1 External floating-point (DISPLAY and NATIONAL) items ...... 44 Binary (COMP) items ...... 44 Chapter 1. Structuring your program . . 5 Native binary (COMP-5) items ...... 45 Identifying a program ...... 5 Packed-decimal (COMP-3) items ...... 45 Identifying a program as recursive ...... 6 Internal floating-point (COMP-1 and COMP-2) Marking a program as callable by containing items ...... 46 programs ...... 6 Examples: numeric data and internal Setting a program to an initial state...... 6 representation ...... 46 Changing the header of a source listing ....6 Data format conversions ...... 48 Describing the computing environment .....7 Conversions and precision ...... 49 Example: FILE-CONTROL paragraph .....7 Sign representation of zoned and packed-decimal Specifying the collating sequence ...... 8 data ...... 50 Defining symbolic characters ...... 9 Checking for incompatible data (numeric class test) 51 Defining a user-defined class ...... 10 Performing arithmetic ...... 51 Identifying files to the operating system Using COMPUTE and other arithmetic (ASSIGN) ...... 10 statements ...... 51 Describing the data ...... 11 Using arithmetic expressions ...... 52 Using data in input and output operations . . . 12 Using numeric intrinsic functions ...... 53 Comparison of WORKING-STORAGE and Examples: numeric intrinsic functions ....54 LOCAL-STORAGE ...... 13 Fixed-point contrasted with floating-point arithmetic 56 Using data from another program ...... 15 Floating-point evaluations ...... 56 Processing the data ...... 16 Fixed-point evaluations ...... 57 How logic is divided in the PROCEDURE Arithmetic comparisons (relation conditions) . . 57 DIVISION ...... 17 Examples: fixed-point and floating-point Declaratives ...... 21 evaluations ...... 58 Using currency signs ...... 58 Chapter 2. Using data ...... 23 Example: multiple currency signs ...... 59 Using variables, structures, literals, and constants . 23 Using variables ...... 23 Chapter 4. Handling tables ...... 61 Using data items and group items ...... 24 Defining a table (OCCURS) ...... 61 Using literals ...... 25 Nesting tables ...... 63 Using constants ...... 26 Example: subscripting ...... 64 Using figurative constants ...... 26 Example: indexing ...... 64 Assigning values to data items ...... 27 Referring to an item in a table ...... 64 Examples: initializing data items ...... 28 Subscripting ...... 65 Initializing a structure (INITIALIZE) .....30 Indexing ...... 66
© Copyright IBM Corp. 1995, 2010 iii Putting values into a table ...... 67 || Identifying DB2 files ...... 117 Loading a table dynamically...... 67 Identifying SFS files ...... 117 Initializing a table (INITIALIZE) ...... 68 || Precedence of file-system determination . . . 118 Assigning values when you define a table File systems ...... 119 (VALUE) ...... 69 || DB2 file system...... 120 Example: PERFORM and subscripting ....71 RSD file system ...... 121 Example: PERFORM and indexing...... 72 SdU file system...... 122 Creating variable-length tables (DEPENDING ON) 73 SFS file system ...... 122 Loading a variable-length table ...... 74 STL file system ...... 123 Assigning values to a variable-length table . . . 75 File-system summary ...... 126 Searching a table ...... 75 Specifying a file organization and access mode . . 127 Doing a serial search (SEARCH) ...... 76 File organization and access mode .....127 Doing a binary search (SEARCH ALL) ....77 || Generation data groups ...... 130 Processing table items using intrinsic functions . . 78 || Creating generation data groups ...... 131 Example: processing tables using intrinsic || Using generation data groups ...... 133 functions ...... 79 || Name format of generation files ...... 134 || Insertion and wrapping of generation files . . 135 Chapter 5. Selecting and repeating || Limit processing of generation data groups . . 137 program actions ...... 81 || Concatenating files ...... 138 Opening optional files ...... 139 Selecting program actions ...... 81 Setting up a field for file status ...... 140 Coding a choice of actions ...... 81 Describing the structure of a file in detail ....140 Coding conditional expressions ...... 86 Coding input and output statements for files . . . 141 Repeating program actions ...... 89 Example: COBOL coding for files...... 141 Choosing inline or out-of-line PERFORM . . . 90 File position indicator ...... 143 Coding a loop ...... 91 Opening a file ...... 144 Looping through a table ...... 92 Reading records from a file...... 146 Executing multiple paragraphs or sections . . . 92 Statements used when writing records to a file 147 Adding records to a file ...... 148 Chapter 6. Handling strings ...... 93 Replacing records in a file ...... 149 Joining data items (STRING) ...... 93 Deleting records from a file...... 149 Example: STRING statement...... 94 PROCEDURE DIVISION statements used to Splitting data items (UNSTRING) ...... 95 update files ...... 150 Example: UNSTRING statement ...... 96 || Using DB2 files...... 151 Manipulating null-terminated strings ...... 98 | Using DB2 files and SQL statements in the same Example: null-terminated strings ...... 99 || program ...... 153 Referring to substrings of data items ...... 99 Using SFS files ...... 154 Reference modifiers ...... 101 Example: accessing SFS files ...... 155 Example: arithmetic expressions as reference Improving SFS performance ...... 157 modifiers ...... 102 Example: intrinsic functions as reference Chapter 8. Sorting and merging files 161 modifiers ...... 102 Sort and merge process ...... 161 Tallying and replacing data items (INSPECT). . . 103 Describing the sort or merge file ...... 162 Examples: INSPECT statement ...... 103 Describing the input to sorting or merging . . . 163 Converting data items (intrinsic functions) . . . 104 Example: describing sort and input files for Converting to uppercase or lowercase SORT...... 163 (UPPER-CASE, LOWER-CASE) ...... 105 Coding the input procedure ...... 164 Transforming to reverse order (REVERSE) . . . 105 Describing the output from sorting or merging . . 165 Converting to numbers (NUMVAL, Coding the output procedure ...... 165 NUMVAL-C) ...... 105 Restrictions on input and output procedures . . . 166 Converting from one code page to another . . 107 Requesting the sort or merge ...... 166 Evaluating data items (intrinsic functions) ....107 Setting sort or merge criteria ...... 167 Evaluating single characters for collating Choosing alternate collating sequences ....168 sequence ...... 107 Example: sorting with input and output Finding the largest or smallest data item . . . 108 procedures ...... 168 Finding the length of data items ...... 110 Determining whether the sort or merge was Finding the date of compilation ...... 111 successful ...... 169 Sort and merge error numbers...... 170 Chapter 7. Processing files .....113 Stopping a sort or merge operation prematurely 172 || File concepts and terminology ...... 113 Identifying files...... 115 Chapter 9. Handling errors...... 175
iv COBOL for AIX, V4.1 Programming Guide Handling errors in joining and splitting strings . . 175 Using environment variables to specify a locale 213 Handling errors in arithmetic operations ....176 Determination of the locale from system settings 214 Example: checking for division by zero ....176 Types of messages for which translations are Handling errors in input and output operations 176 available ...... 214 Using the end-of-file condition (AT END) . . . 178 Locales and code pages that are supported . . . 215 Coding ERROR declaratives ...... 178 Controlling the collating sequence with a locale 217 Using file status keys...... 179 Controlling the alphanumeric collating sequence Using file system status codes ...... 180 with a locale...... 218 Coding INVALID KEY phrases ...... 182 Controlling the DBCS collating sequence with a Handling errors when calling programs ....183 locale ...... 219 Controlling the national collating sequence with Part 2. Enabling programs for a locale ...... 220 Intrinsic functions that depend on collating international environments ....185 sequence ...... 220 Accessing the active locale and code-page values 221 Chapter 10. Processing data in an Example: get and convert a code-page ID . . . 222 international environment ...... 187 COBOL statements and national data .....188 Part 3. Compiling, linking, running, Intrinsic functions and national data...... 190 and debugging your program . . . 225 Unicode and the encoding of language characters 191 Using national data (Unicode) in COBOL ....192 Defining national data items ...... 192 Chapter 12. Compiling, linking, and Using national literals ...... 193 running programs ...... 227 Using national-character figurative constants 194 Setting environment variables ...... 227 Defining national numeric data items ....195 Compiler and runtime environment variables 228 National groups ...... 195 Compiler environment variables ...... 231 Using national groups ...... 197 Runtime environment variables ...... 232 Storage of character data ...... 199 Example: setting and accessing environment Converting to or from national (Unicode) variables ...... 236 representation ...... 200 Compiling programs ...... 236 Converting alphanumeric, DBCS, and integer to Compiling from the command line .....237 national (MOVE) ...... 200 Compiling using shell scripts ...... 238 Converting alphanumeric or DBCS to national Specifying compiler options in the PROCESS (NATIONAL-OF) ...... 201 (CBL) statement ...... 239 Converting national to alphanumeric Modifying the default compiler configuration 240 (DISPLAY-OF) ...... 202 Correcting errors in your source program ....242 Overriding the default code page...... 202 Severity codes for compiler diagnostic messages 243 Example: converting to and from national data 202 Generating a list of compiler messages ....244 Processing UTF-8 data ...... 203 cob2, cob2_j, and cob2_r options ...... 245 Processing Chinese GB 18030 data ...... 204 Options that apply to compiling ...... 245 Comparing national (UTF-16) data ...... 204 Options that apply to linking ...... 246 Comparing two class national operands . . . 205 Options that apply to both compiling and Comparing class national and class numeric linking ...... 247 operands ...... 206 Linking programs ...... 247 Comparing national numeric and other numeric Passing options to the linker ...... 248 operands ...... 206 Linker input and output files ...... 250 Comparing national and other character-string Correcting errors in linking...... 252 operands ...... 207 Running programs ...... 252 Comparing national data and Redistributing COBOL for AIX library components 253 alphanumeric-group operands...... 207 Coding for use of DBCS support ...... 207 Chapter 13. Compiling, linking, and Declaring DBCS data ...... 208 running OO applications ...... 255 Using DBCS literals ...... 208 Compiling OO applications...... 255 Testing for valid DBCS characters .....209 Preparing OO applications ...... 256 Processing alphanumeric data items that contain Example: compiling and linking a COBOL class DBCS data ...... 210 definition...... 257 Running OO applications ...... 257 Chapter 11. Setting the locale ....211 Running OO applications that start with a main The active locale ...... 211 method ...... 258 Specifying the code page for character data . . . 212
Contents v Running OO applications that start with a YEARWINDOW ...... 308 COBOL program ...... 258 ZWB...... 309 JDK support...... 259 Chapter 15. Compiler-directing Chapter 14. Compiler options ....261 statements ...... 311 Conflicting compiler options ...... 263 ADATA...... 264 Chapter 16. Runtime options .....317 ADDR...... 264 CHECK ...... 317 || ARCH...... 266 DEBUG ...... 318 ARITH ...... 267 ERRCOUNT...... 318 BINARY ...... 268 FILEMODE ...... 319 CALLINT ...... 268 FILESYS ...... 320 CHAR...... 269 TRAP ...... 321 CICS ...... 271 UPSI ...... 321 COLLSEQ ...... 272 COMPILE ...... 273 CURRENCY...... 274 Chapter 17. Debugging ...... 323 DATEPROC ...... 275 Debugging with source language ...... 323 DIAGTRUNC ...... 276 Tracing program logic ...... 323 DYNAM ...... 277 Finding and handling input-output errors . . . 324 ENTRYINT ...... 278 Validating data ...... 325 EXIT ...... 278 Finding uninitialized data ...... 325 FLAG ...... 278 Generating information about procedures . . . 325 FLAGSTD ...... 279 Debugging using compiler options ...... 327 FLOAT ...... 281 Finding coding errors ...... 328 LIB...... 282 Finding line sequence problems ...... 328 LINECOUNT ...... 282 Checking for valid ranges ...... 328 LIST ...... 283 Selecting the level of error to be diagnosed . . 329 LSTFILE ...... 284 Finding program entity definitions and MAP...... 284 references ...... 331 MAXMEM ...... 285 Listing data items ...... 332 MDECK ...... 286 Using the debugger ...... 332 NCOLLSEQ ...... 287 Getting listings ...... 333 NSYMBOL ...... 288 Example: short listing ...... 334 NUMBER ...... 288 Example: SOURCE and NUMBER output . . . 336 OPTIMIZE ...... 289 Example: MAP output ...... 336 PGMNAME ...... 290 Example: XREF output: data-name PGMNAME(UPPER) ...... 291 cross-references...... 340 PGMNAME(MIXED) ...... 291 Example: VBREF compiler output .....343 PROFILE ...... 292 Debugging with messages that have offset QUOTE/APOST ...... 292 information ...... 343 SEPOBJ ...... 293 Debugging user exits ...... 344 Batch compilation ...... 293 Debugging assembler routines...... 344 SEQUENCE ...... 294 SIZE ...... 295 Part 4. Accessing databases . . . 345 SOSI ...... 295 SOURCE ...... 297 Chapter 18. Programming for a DB2 SPACE...... 297 SPILL ...... 298 environment ...... 347 SQL...... 298 DB2 coprocessor ...... 347 || SRCFORMAT ...... 299 Coding SQL statements ...... 348 SSRANGE ...... 300 Using SQL INCLUDE with the DB2 coprocessor 348 TERMINAL ...... 301 Using binary items in SQL statements ....349 TEST ...... 301 Determining the success of SQL statements . . 349 THREAD ...... 302 Starting DB2 before compiling...... 349 TRUNC ...... 303 Compiling with the SQL option ...... 349 TRUNC example 1 ...... 304 Separating DB2 suboptions ...... 350 TRUNC example 2 ...... 305 Using package and bind file-names .....350 VBREF ...... 306 WSCLEAR ...... 306 Chapter 19. Developing COBOL XREF ...... 307 programs for CICS ...... 353
vi COBOL for AIX, V4.1 Programming Guide Coding COBOL programs to run under CICS . . 353 Example: enhancing XML output ...... 408 Getting the system date under CICS.....355 Example: converting hyphens in element or Making dynamic calls under CICS .....355 attribute names to underscores ...... 411 Accessing SFS data ...... 358 Calling between COBOL and C/C++ under Part 6. Developing object-oriented CICS ...... 358 Compiling and running CICS programs ....358 programs ...... 413 Integrated CICS translator ...... 359 Debugging CICS programs ...... 360 Chapter 23. Writing object-oriented programs ...... 415 Chapter 20. Open Database Example: accounts...... 416 Connectivity (ODBC) ...... 361 Subclasses ...... 417 Comparison of ODBC and embedded SQL . . . 361 Defining a class ...... 418 Background ...... 362 CLASS-ID paragraph for defining a class . . . 420 Installing and configuring software for ODBC . . 362 REPOSITORY paragraph for defining a class 420 Coding ODBC calls from COBOL: overview . . . 362 WORKING-STORAGE SECTION for defining Using data types appropriate for ODBC . . . 362 class instance data...... 422 Passing pointers as arguments in ODBC calls 363 Example: defining a class ...... 423 Accessing function return values in ODBC calls 365 Defining a class instance method ...... 423 Testing bits in ODBC calls ...... 365 METHOD-ID paragraph for defining a class Using COBOL copybooks for ODBC APIs ....366 instance method ...... 424 Example: sample program using ODBC INPUT-OUTPUT SECTION for defining a class copybooks ...... 367 instance method ...... 425 Example: copybook for ODBC procedures . . . 368 DATA DIVISION for defining a class instance Example: copybook for ODBC data definitions 371 method ...... 425 ODBC names truncated or abbreviated for PROCEDURE DIVISION for defining a class COBOL ...... 371 instance method ...... 426 Compiling and linking programs that make ODBC Overriding an instance method ...... 427 calls ...... 373 Overloading an instance method ...... 428 Coding attribute (get and set) methods ....429 Example: defining a method ...... 430 Part 5. Using XML and COBOL Defining a client ...... 432 together ...... 375 REPOSITORY paragraph for defining a client 433 DATA DIVISION for defining a client ....434 Chapter 21. Processing XML input 377 Comparing and setting object references . . . 435 XML parser in COBOL ...... 377 Invoking methods (INVOKE) ...... 436 Accessing XML documents ...... 379 Creating and initializing instances of classes . . 440 Parsing XML documents ...... 379 Freeing instances of classes ...... 442 Writing procedures to process XML .....380 Example: defining a client ...... 442 XML events ...... 381 Defining a subclass ...... 443 Transforming XML text to COBOL data items 384 CLASS-ID paragraph for defining a subclass 444 The encoding of XML documents...... 385 REPOSITORY paragraph for defining a subclass 445 XML input document encoding ...... 385 WORKING-STORAGE SECTION for defining Parsing XML documents encoded in UTF-8 . . 388 subclass instance data ...... 445 Handling XML PARSE exceptions ...... 389 Defining a subclass instance method ....446 How the XML parser handles errors.....390 Example: defining a subclass (with methods) 446 Handling encoding conflicts ...... 391 Defining a factory section ...... 447 Terminating XML parsing ...... 392 WORKING-STORAGE SECTION for defining Example: program for processing XML .....392 factory data ...... 448 Output from parsing ...... 394 Defining a factory method ...... 449 Example: defining a factory (with methods) . . 451 Chapter 22. Producing XML output 397 Wrapping procedure-oriented COBOL programs 456 Structuring OO applications ...... 457 Generating XML output ...... 397 Examples: COBOL applications that run using Controlling the encoding of generated XML output 401 the java command...... 457 Handling XML GENERATE exceptions .....402 Example: generating XML ...... 403 Program XGFX ...... 403 Chapter 24. Communicating with Java Program Pretty ...... 404 methods ...... 461 Output from program XGFX ...... 407 Accessing JNI services ...... 461 Enhancing XML output ...... 407 Handling Java exceptions ...... 463
Contents vii Managing local and global references ....464 Coding the PROCEDURE DIVISION for passing Java access controls ...... 465 arguments ...... 503 Sharing data with Java ...... 466 Grouping data to be passed ...... 503 Coding interoperable data types in COBOL and Handling null-terminated strings ...... 504 Java ...... 466 Using pointers to process a chained list . . . 504 Declaring arrays and strings for Java ....467 Using procedure and function pointers .....507 Manipulating Java arrays ...... 468 Passing return-code information ...... 508 Manipulating Java strings ...... 471 Using the RETURN-CODE special register. . . 508 Using PROCEDURE DIVISION RETURNING . . Part 7. Working with more ...... 508 Specifying CALL . . . RETURNING .....508 complex applications ...... 473 Sharing data by using the EXTERNAL clause. . . 509 Sharing files between programs (external files) . . 509 Chapter 25. Porting applications Example: using external files ...... 510 between platforms ...... 475 Using command-line arguments ...... 513 Getting mainframe applications to compile . . . 475 Example: command-line arguments without Getting mainframe applications to run: overview 476 -host option ...... 513 Fixing differences caused by data Example: command-line arguments with -host representations ...... 476 option ...... 514 Fixing environment differences that affect portability ...... 478 Chapter 28. Using shared libraries 515 Fixing differences caused by language elements 479 Static linking versus using shared libraries . . . 515 Writing code to run on the mainframe .....480 How the linker resolves references to shared Writing applications that are portable between AIX libraries ...... 516 and Windows ...... 481 Example: creating a sample shared library. . . 516 Example: creating a makefile for the sample Chapter 26. Using subprograms . . . 483 shared library ...... 519 Main programs, subprograms, and calls ....483 Ending and reentering main programs or Chapter 29. Preparing COBOL subprograms ...... 483 programs for multithreading .....521 Calling nested COBOL programs ...... 484 Multithreading ...... 521 Nested programs ...... 485 Working with language elements with Example: structure of nested programs ....486 multithreading ...... 522 Scope of names...... 487 Working with elements that have run-unit scope 523 Calling nonnested COBOL programs .....488 Working with elements that have program CALL identifier and CALL literal...... 488 invocation instance scope ...... 523 Example: dynamic call using CALL identifier 489 Scope of COBOL language elements with Calling between COBOL and C/C++ programs . . 490 multithreading ...... 524 Initializing environments ...... 491 Choosing THREAD to support multithreading . . 524 Passing data between COBOL and C/C++ . . 491 Transferring control to multithreaded programs 525 Collapsing stack frames and terminating run Ending multithreaded programs ...... 525 units or processes ...... 492 Handling COBOL limitations with multithreading 526 COBOL and C/C++ data types ...... 493 Example: using COBOL in a multithreaded Example: COBOL program calling C functions 493 environment...... 526 Example: C programs that are called by and call Source code for thrcob.c ...... 527 COBOL ...... 494 Source code for subd.cbl...... 528 Example: COBOL program called by a C Source code for sube.cbl ...... 528 program ...... 495 Example: results of compiling and running Chapter 30. Preinitializing the COBOL examples ...... 496 runtime environment ...... 531 Example: COBOL program calling C++ function 496 Making recursive calls ...... 497 Initializing persistent COBOL environment . . . 531 Passing return codes ...... 497 Terminating preinitialized COBOL environment 532 Example: preinitializing the COBOL environment 533 Chapter 27. Sharing data ...... 499 Chapter 31. Processing two-digit-year Passing data...... 499 Describing arguments in the calling program 501 dates ...... 537 Describing parameters in the called program 501 Millennium language extensions (MLE) ....538 Testing for OMITTED arguments ...... 502 Principles and objectives of these extensions . . 538 Coding the LINKAGE SECTION ...... 502 Resolving date-related logic problems .....539 viii COBOL for AIX, V4.1 Programming Guide Using a century window ...... 540 Example: formatting dates for output ....578 Using internal bridging ...... 541 Feedback token...... 579 Moving to full field expansion...... 543 Picture character terms and strings .....580 Using year-first, year-only, and year-last date fields 545 Example: date-and-time picture strings ....582 Compatible dates ...... 545 Century window ...... 583 Example: comparing year-first date fields . . . 546 Using other date formats ...... 546 Part 9. Appendixes ...... 585 Example: isolating the year ...... 547 Manipulating literals as dates ...... 547 Assumed century window ...... 548 Appendix A. Migration from earlier Treatment of nondates ...... 549 versions, and compatibility .....587 Using sign conditions ...... 550 Object code ...... 587 Performing arithmetic on date fields...... 551 Data size limits...... 587 Allowing for overflow from windowed date || Initialization of EXTERNAL data ...... 587 fields ...... 552 STL and SdU files that are larger than 2 GB . . . 588 Specifying the order of evaluation .....552 SFS files ...... 588 Controlling date processing explicitly .....553 || File identifiers ...... 589 Using DATEVAL ...... 553 Object-oriented syntax, and Java 5 or Java 6 . . . 589 Using UNDATE ...... 554 XML generation ...... 589 Example: DATEVAL ...... 554 Migration of 32-bit applications to 64-bit mode . . 590 Example: UNDATE ...... 555 Analyzing and avoiding date-related diagnostic Appendix B. Summary of differences messages ...... 555 from host COBOL ...... 593 Avoiding problems in processing dates .....557 Compiler options ...... 593 Avoiding problems with packed-decimal fields 557 Data representation ...... 593 Moving from expanded to windowed date fields 557 Zoned decimal data ...... 594 Packed-decimal data ...... 594 Part 8. Improving performance and Display floating-point data ...... 594 productivity ...... 559 National data ...... 594 EBCDIC and ASCII data...... 594 Chapter 32. Tuning your program. . . 561 Code-page determination for data conversion 594 DBCS character strings ...... 595 Using an optimal programming style .....562 Runtime environment variables ...... 595 Using structured programming ...... 562 File specification ...... 596 Factoring expressions...... 562 Interlanguage communication (ILC) ...... 597 Using symbolic constants ...... 563 Input and output ...... 597 Grouping constant computations ...... 563 Runtime options ...... 598 Grouping duplicate computations .....563 Source code line size ...... 598 Choosing efficient data types ...... 564 Language elements ...... 598 Choosing efficient computational data items . . 564 Using consistent data types...... 564 Appendix C. System z host data Making arithmetic expressions efficient....565 Making exponentiations efficient ...... 565 format considerations...... 601 Handling tables efficiently ...... 565 CICS access ...... 601 Optimization of table references ...... 567 Date and time callable services ...... 601 Optimizing your code ...... 568 Floating-point overflow exceptions ...... 601 Optimization ...... 569 DB2...... 602 Choosing compiler features to enhance Object-oriented syntax for Java interoperability . . 602 performance...... 570 Distributed Computing Environment applications 602 Performance-related compiler options ....570 File data ...... 602 Evaluating performance ...... 573 SORT...... 602
Chapter 33. Simplifying coding ....575 Appendix D. Intermediate results and Eliminating repetitive coding ...... 575 arithmetic precision ...... 603 Example: using the COPY statement.....576 Terminology used for intermediate results ....604 Manipulating dates and times ...... 577 Example: calculation of intermediate results . . . 605 Getting feedback from date and time callable Fixed-point data and intermediate results ....605 services ...... 577 Addition, subtraction, multiplication, and Handling conditions from date and time callable division ...... 605 services ...... 578 Exponentiation ...... 606 Example: manipulating dates ...... 578
Contents ix Example: exponentiation in fixed-point Appendix H. EXIT compiler option . . 671 arithmetic ...... 607 User-exit work area and work area extension . . . 673 Truncated intermediate results...... 608 Parameter list for exit modules ...... 673 Binary data and intermediate results ....608 Processing of INEXIT...... 675 Intrinsic functions evaluated in fixed-point Processing of LIBEXIT ...... 675 arithmetic ...... 608 Processing of PRTEXIT ...... 677 Integer functions ...... 608 Processing of ADEXIT ...... 677 Mixed functions ...... 609 || Processing of MSGEXIT ...... 677 Floating-point data and intermediate results . . . 610 || Customizing compiler-message severities . . . 678 Exponentiations evaluated in floating-point || Error handling for exit modules ...... 681 arithmetic ...... 611 Example: MSGEXIT user exit ...... 682 Intrinsic functions evaluated in floating-point arithmetic ...... 611 Appendix I. JNI.cpy ...... 687 Arithmetic expressions in nonarithmetic statements 611 Appendix J. COBOL SYSADATA file Appendix E. Complex OCCURS contents ...... 693 DEPENDING ON ...... 613 Compiler options that affect the SYSADATA file 693 Example: complex ODO ...... 613 SYSADATA record types ...... 694 How length is calculated ...... 614 Example: SYSADATA ...... 695 Setting values of ODO objects ...... 614 SYSADATA record descriptions ...... 696 Effects of change in ODO object value .....614 Common header section ...... 697 Preventing index errors when changing ODO Job identification record: X'0000' ...... 698 object value ...... 615 ADATA identification record: X'0001' .....699 Preventing overlay when adding elements to a Compilation unit start | end record: X'0002' . . . 699 variable table ...... 615 Options record: X'0010' ...... 700 External symbol record: X'0020' ...... 710 Appendix F. Date and time callable Parse tree record: X'0024' ...... 711 services...... 619 Token record: X'0030' ...... 725 CEECBLDY: convert date to COBOL integer format 620 Source error record: X'0032'...... 739 CEEDATE: convert Lilian date to character format 624 Source record: X'0038' ...... 739 CEEDATM: convert seconds to character time COPY REPLACING record: X'0039' ...... 740 stamp ...... 628 Symbol record: X'0042' ...... 740 CEEDAYS: convert date to Lilian format ....632 Symbol cross-reference record: X'0044' .....753 CEEDYWK: calculate day of week from Lilian date 635 Nested program record: X'0046' ...... 754 CEEGMT: get current Greenwich Mean Time . . . 637 Library record: X'0060' ...... 755 CEEGMTO: get offset from Greenwich Mean Time Statistics record: X'0090' ...... 755 to local time ...... 639 EVENTS record: X'0120' ...... 756 CEEISEC: convert integers to seconds .....641 CEELOCT: get current local date or time ....644 Appendix K. Runtime messages . . . 761 CEEQCEN: query the century window .....646 CEESCEN: set the century window ...... 647 Notices ...... 807 CEESECI: convert seconds to integers .....649 Trademarks ...... 809 CEESECS: convert time stamp to seconds ....652 CEEUTC: get coordinated universal time ....656 IGZEDT4: get current date ...... 656 Glossary ...... 811
Appendix G. XML reference material 659 List of resources ...... 845 XML PARSE exceptions ...... 659 COBOL for AIX ...... 845 XML PARSE exceptions that allow continuation 659 Related publications ...... 845 XML PARSE exceptions that do not allow continuation ...... 664 Index ...... 847 XML conformance ...... 667 XML GENERATE exceptions ...... 669
x COBOL for AIX, V4.1 Programming Guide Tables
1. FILE SECTION entries ...... 13 39. Using compiler options to get listings 333 2. Assignment to data items in a program 27 40. Terms and symbols used in MAP output 338 3. Ranges in value of COMP-5 data items 45 41. ODBC C types and corresponding COBOL 4. Internal representation of binary numeric declarations ...... 362 items ...... 46 42. ODBC copybooks ...... 366 5. Internal representation of native numeric 43. ODBC names truncated or abbreviated for items ...... 47 COBOL ...... 371 6. Internal representation of numeric items 44. Special registers used by the XML parser 381 when CHAR(EBCDIC) and FLOAT(HEX) are | 45. Result of processing-procedure changes to in effect ...... 48 || XML-CODE ...... 383 7. Order of evaluation of arithmetic operators 52 | 46. Hexadecimal values of white-space 8. Numeric intrinsic functions ...... 53 || characters...... 386 9. STL file system return codes ...... 124 47. Hexadecimal values of special characters for 10. STL file system adapter open routine return various EBCDIC CCSIDs ...... 388 codes ...... 125 48. Encoding of generated XML if the 11. File-system summary ...... 126 ENCODING phrase is omitted .....401 12. File organization and access mode ....127 49. Structure of class definitions ...... 418 13. Valid COBOL statements for sequential files 145 50. Structure of instance method definitions 424 14. Valid COBOL statements for line-sequential 51. Structure of COBOL clients ...... 432 files ...... 145 52. Conformance of arguments in a COBOL 15. Valid COBOL statements for indexed and client ...... 437 relative files ...... 146 53. Conformance of the returned data item in a 16. Statements used when writing records to a COBOL client ...... 439 file ...... 148 54. Structure of factory definitions .....448 17. PROCEDURE DIVISION statements used to 55. Structure of factory method definitions 449 update files ...... 150 56. JNI services for local and global references 465 18. Sort and merge error numbers .....170 57. Interoperable data types in COBOL and Java 466 19. COBOL statements and national data 188 58. Interoperable arrays and strings in COBOL 20. Intrinsic functions and national character and Java ...... 467 data...... 190 59. Noninteroperable array types in COBOL 21. National group items that are processed and Java ...... 468 with group semantics ...... 199 60. JNI array services ...... 469 22. Encoding and size of alphanumeric, DBCS, 61. Services that convert between jstring and national data ...... 199 references and national data ...... 471 23. Supported locales and code pages ....215 62. Services that convert between jstring 24. Intrinsic functions that depend on collating references and UTF-8 data ...... 471 sequence ...... 220 63. ASCII characters contrasted with EBCDIC 477 25. TZ environment parameter variables 230 64. ASCII comparisons contrasted with EBCDIC 477 26. Output from the cob2 command .....238 65. IEEE contrasted with hexadecimal ....477 27. Examples of compiler-option syntax in a 66. COBOL and C/C++ data types .....493 shell script ...... 239 67. Methods for passing data in the CALL 28. Stanza attributes ...... 241 statement ...... 500 29. Severity codes for compiler diagnostic 68. Scope of COBOL language elements with messages ...... 243 multithreading ...... 524 30. Common linker options ...... 248 69. Advantages and disadvantages of Year 2000 31. Default file-names assumed by the linker 252 solutions ...... 540 32. Commands for compiling and linking a 70. Performance-related compiler options 570 class definition ...... 256 71. Performance-tuning worksheet .....573 33. java command options for customizing the 72. Picture character terms and strings ....581 JVM ...... 258 73. Japanese Eras ...... 582 34. Compiler options ...... 261 74. Examples of date-and-time picture strings 582 35. Mutually exclusive compiler options 263 75. Language differences between Enterprise 36. Effect of comparand data type and collating COBOL for z/OS and COBOL for AIX ...598 sequence on comparisons ...... 273 76. Maximum floating-point values .....601 37. Runtime options ...... 317 77. Date and time callable services .....619 38. Severity levels of compiler messages 329 78. Date and time intrinsic functions ....620
© Copyright IBM Corp. 1995, 2010 xi 79. CEECBLDY symbolic conditions .....622 102. SYSADATA compilation unit start | end 80. CEEDATE symbolic conditions .....625 record ...... 699 81. CEEDATM symbolic conditions .....628 103. SYSADATA options record...... 700 82. CEEDAYS symbolic conditions .....633 104. SYSADATA external symbol record 710 83. CEEDYWK symbolic conditions .....635 105. SYSADATA parse tree record ...... 711 84. CEEGMT symbolic conditions .....638 106. SYSADATA token record ...... 725 85. CEEGMTO symbolic conditions .....640 107. SYSADATA source error record .....739 86. CEEISEC symbolic conditions...... 642 108. SYSADATA source record ...... 739 87. CEELOCT symbolic conditions .....644 109. SYSADATA COPY REPLACING record 740 88. CEEQCEN symbolic conditions .....646 110. SYSADATA symbol record ...... 740 89. CEESCEN symbolic conditions .....648 111. SYSADATA symbol cross-reference record 753 90. CEESECI symbolic conditions...... 650 112. SYSADATA nested program record ....754 91. CEESECS symbolic conditions .....653 113. SYSADATA library record ...... 755 92. XML PARSE exceptions that allow 114. SYSADATA statistics record ...... 755 continuation ...... 660 115. SYSADATA EVENTS TIMESTAMP record 93. XML PARSE exceptions that do not allow layout ...... 756 continuation ...... 664 116. SYSADATA EVENTS PROCESSOR record 94. XML GENERATE exceptions ...... 670 layout ...... 756 95. Parameter list for exit modules .....673 117. SYSADATA EVENTS FILE END record || 96. MSGEXIT processing ...... 678 layout ...... 757 || 97. FIPS (FLAGSTD) message categories ....680 118. SYSADATA EVENTS PROGRAM record 98. SYSADATA record types ...... 694 layout ...... 757 99. SYSADATA common header section 697 119. SYSADATA EVENTS FILE ID record layout 757 100. SYSADATA job identification record 698 120. SYSADATA EVENTS ERROR record layout 758 101. ADATA identification record ...... 699 121. Runtime messages...... 761
xii COBOL for AIX, V4.1 Programming Guide Preface
About this information
Welcome to IBM® COBOL for AIX®, IBM's COBOL compiler and run time for AIX!
There are some differences between host and workstation COBOL. For details about language and system differences between COBOL for AIX and Enterprise COBOL for z/OS®, see Appendix B, “Summary of differences from host COBOL,” on page 593. How this information will help you
This information will help you write, compile, link-edit, and run IBM COBOL for AIX programs. It will also help you define object-oriented classes and methods, invoke methods, and refer to objects in your programs.
This information assumes experience in developing application programs and some knowledge of COBOL. It focuses on using COBOL to meet your programming objectives and not on the definition of the COBOL language. For complete information about COBOL syntax, see the COBOL for AIX Language Reference.
This information also assumes familiarity with AIX. For information about AIX, see your operating system documentation. Abbreviated terms
Certain terms are used in a shortened form in this information. Abbreviations for the product names used most frequently are listed alphabetically in the table below.
Term used Long form CICS® IBM TXSeries COBOL for AIX IBM COBOL for AIX DB2® Database 2
In addition to these abbreviated terms, the term "Standard COBOL 85" is used in this information to refer to the combination of the following standards: v ISO 1989:1985, Programming languages - COBOL v ISO/IEC 1989/AMD1:1992, Programming languages - COBOL: Intrinsic function module v ISO/IEC 1989/AMD2:1994, Programming languages - Correction and clarification amendment for COBOL v ANSI INCITS 23-1985, Programming Languages - COBOL v ANSI INCITS 23a-1989, Programming Languages - Intrinsic Function Module for COBOL v ANSI INCITS 23b-1993, Programming Language - Correction Amendment for COBOL
© Copyright IBM Corp. 1995, 2010 xiii The ISO standards are identical to the American National Standards.
Other terms, if not commonly understood, are shown in italics the first time they appear and are listed in the glossary. How to read syntax diagrams
Use the following description to read the syntax diagrams in this information: v Read the syntax diagrams from left to right, from top to bottom, following the path of the line. The >>--- symbol indicates the beginning of a syntax diagram. The ---> symbol indicates that the syntax diagram is continued on the next line. The >--- symbol indicates that the syntax diagram is continued from the previous line. The --->< symbol indicates the end of a syntax diagram. Diagrams of syntactical units other than complete statements start with the >--- symbol and end with the ---> symbol. v Required items appear on the horizontal line (the main path).