Compaq AAQ2G1FTK User Manual

CompaqCOBOL UserManual

Order Number: AA–Q2G1F–TK
October 2000
This manual provides information to help you develop Compaq COBOL programs for the OpenVMS Alpha and Compaq Tru64 UNIX platforms.
Revision/Update Information: This manual supersedes the
DIGITAL COBOL User Manual, Version 2.5.
Operating System and Version: OpenVMS Alpha Version 6.2 or higher;
Tru64 UNIX Version 4.0F or higher
Software Version: Compaq COBOL Version 2.7
Compaq Computer Corporation Houston, Texas
© 2000 Compaq Computer Corporation COMPAQ, VAX, VMS, the Compaq logo, and the DIGITAL logo Registered in U.S. Patent and
Trademark Office. OpenVMS and Tru64 are trademarks of Compaq Information Technologies Group, L.P. Microsoft, MS-DOS, Win32, Windows, and Windows NT are trademarks of Microsoft Corporation. Motif, OSF/1, UNIX, and X/Open are trademarks of The Open Group. All other product names mentioned herein may be trademarks of their respective companies. Confidential computer software. Valid license from Compaq required for possession, use, or copying.
Consistent with FAR 12.211 and 12.212, Commercial Computer Software, Computer Software Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under vendor’s standard commercial license.
Compaq shall not be liable for technical or editorial errors or omissions contained herein. The information in this document is subject to change without notice.
THE INFORMATION IN THIS PUBLICATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK ARISING OUT OF THE USE OF THIS INFORMATION REMAINS WITH RECIPIENT. IN NO EVENT SHALL COMPAQ BE LIABLE FOR ANY DIRECT, CONSEQUENTIAL, INCIDENTAL, SPECIAL, PUNITIVE, OR OTHER DAMAGES WHATSOEVER (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION OR LOSS OF BUSINESS INFORMATION), EVEN IF COMPAQ HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND WHETHER IN AN ACTION OF CONTRACT OR TORT, INCLUDING NEGLIGENCE.
The limited warranties for Compaq products are exclusively set forth in the documentation accompanying such products. Nothing herein should be construed as constituting a further or additional warranty.
This document was prepared using DECdocument, Version 3.3-1b.
ZK6297

Contents

Preface ............................................................ xxiii
1 Developing Compaq COBOL Programs
1.0.1 Files Installed on Your System ............................... 1–1
1.1 Compaq COBOL and Alpha Architecture System Resources ........... 1–2
1.1.1 Compilation Performance . . . ................................ 1–2
1.1.2 Tuning OpenVMS Alpha for Large Compaq COBOL Compiles ...... 1–3
1.1.2.1 Optimizing Virtual Memory Usage . . ....................... 1–3
1.1.2.2 Optimizing Physical Memory Usage. ....................... 1–4
1.1.2.3 Improving Compile Performance with Separate Compilation
(OpenVMS) . . ........................................ 1–6
1.1.3 Choosing a Reference Format ............................... 1–6
1.1.3.1 Terminal Reference Format .............................. 1–6
1.1.3.2 ANSI Reference Format . ................................ 1–7
1.1.3.3 Converting Between Reference Formats .................... 1–7
1.2 Developing Programs on Tru64 UNIX ............................ 1–7
1.2.1 Creating a Compaq COBOL Program on Tru64 UNIX ............. 1–7
1.2.2 Compiling a Compaq COBOL Program on Tru64 UNIX ............ 1–10
1.2.2.1 Format of the COBOL Command on Tru64 UNIX ............. 1–10
1.2.2.2 COBOL Command Flags ................................ 1–11
1.2.2.3 External File Handler Support ........................... 1–15
1.2.2.4 Specifying Multiple Files and Flags . ....................... 1–15
1.2.2.5 Compiling Multiple Files ................................ 1–15
1.2.2.6 Debugging a Program . . ................................ 1–16
1.2.2.7 Output Files: Object, Executable, Listing, and Temporary
Files ................................................ 1–16
1.2.2.8 Naming Output Files . . . ................................ 1–17
1.2.2.9 Temporary Files ....................................... 1–17
1.2.2.10 Examples of the COBOL Command . ....................... 1–17
1.2.2.11 Other Compilers....................................... 1–18
1.2.2.12 Interpreting Messages from the Compiler ................... 1–18
1.2.3 Linking a Compaq COBOL Program on Tru64 UNIX ............. 1–19
1.2.3.1 Specifying Object Libraries for Linking ..................... 1–19
1.2.3.2 Specifying Additional Object Libraries ...................... 1–20
1.2.3.3 Specifying Types of Object Libraries ....................... 1–21
1.2.3.4 Creating Shared Object Libraries . . ....................... 1–21
1.2.3.5 Shared Library Restrictions .............................. 1–22
1.2.3.6 Installing Shared Libraries .............................. 1–22
1.2.3.7 Interpreting Messages from the Linker ..................... 1–22
1.2.4 Running a Compaq COBOL Program on Tru64 UNIX ............. 1–23
1.2.4.1 Accessing Command-Line Arguments ...................... 1–23
1.2.4.2 Accessing Environment Variables . . ....................... 1–24
1.2.4.3 Errors and Switches.................................... 1–25
iii
1.2.5 Program Development Stages and Tools ....................... 1–25
1.3 Developing Programs on OpenVMS Alpha ......................... 1–27
1.3.1 Creating a Compaq COBOL Program on OpenVMS Alpha ......... 1–27
1.3.2 Compiling a Compaq COBOL Program on OpenVMS Alpha ........ 1–29
1.3.2.1 Format of the COBOL Command on OpenVMS Alpha.......... 1–29
1.3.2.2 Compiling Multiple Files ................................ 1–30
1.3.2.3 Debugging a Program .................................. 1–30
1.3.2.4 Separately Compiled Programs ........................... 1–31
1.3.2.5 COBOL Qualifiers . .................................... 1–31
1.3.2.6 Common Command-Line Errors to Avoid . ................... 1–35
1.3.2.7 Compiling Programs with Conditional Compilation . ........... 1–36
1.3.2.8 Interpreting Messages from the Compiler ................... 1–36
1.3.2.9 Using Compiler Listing Files ............................ 1–38
1.3.3 Linking a Compaq COBOL Program .......................... 1–39
1.3.3.1 The LINK Command ................................... 1–39
1.3.3.2 LINK Qualifiers . . .................................... 1–40
1.3.3.3 Specifying Modules Other than Compaq COBOL Modules....... 1–40
1.3.3.4 Specifying Object Module Libraries ........................ 1–41
1.3.3.5 Creating Shareable Images . . ............................ 1–43
1.3.3.6 Interpreting Messages from the Linker . ................... 1–47
1.3.4 Running a Compaq COBOL Program ......................... 1–48
1.3.4.1 Accessing Command-Line Arguments at Run Time . ........... 1–48
1.3.4.2 Accessing System Logicals at Run Time . ................... 1–49
1.3.4.3 Accessing Input and Output Devices at Run Time . . ........... 1–50
1.3.4.4 Debugging Environment ................................ 1–50
1.3.4.5 Interpreting Run-Time Messages ......................... 1–51
1.4 Program Run Messages . . . .................................... 1–52
1.4.1 Data Errors . ............................................ 1–52
1.4.2 Program Logic Errors. . .................................... 1–53
1.4.3 Run-Time Input/Output Errors . . ............................ 1–54
1.4.4 I/O Errors and RMS (OpenVMS) . ............................ 1–55
1.5 Using Program Switches . . .................................... 1–59
1.5.1 Setting and Controlling Switches Internally . ................... 1–60
1.5.2 Setting and Controlling Switches Externally ................... 1–60
1.6 Special Information for Year 2000 Programming . ................... 1–62
2 Handling Numeric Data
2.1 How the Compiler Stores Numeric Data .......................... 2–1
2.2 Specifying Alignment ......................................... 2–1
2.3 Sign Conventions ............................................ 2–2
2.4 Invalid Values in Numeric Items ................................ 2–2
2.5 Evaluating Numeric Items . .................................... 2–3
2.5.1 Numeric Relation Test . .................................... 2–3
2.5.2 Numeric Sign Test ........................................ 2–4
2.5.3 Numeric Class Tests. . . .................................... 2–4
2.5.4 Success/Failure Tests . . .................................... 2–5
2.6 Using the MOVE Statement ................................... 2–6
2.6.1 Elementary Numeric Moves ................................. 2–6
2.6.2 Elementary Numeric-Edited Moves ........................... 2–7
2.6.3 Subscripted Moves ........................................ 2–9
2.6.4 Common Move Errors . .................................... 2–9
2.7 Using the Arithmetic Statements................................ 2–9
2.7.1 Temporary Work Items . .................................... 2–9
iv
2.7.2 Standard and Native Arithmetic ............................. 2–10
2.7.2.1 Using the /MATH_INTERMEDIATE Qualifier . ............... 2–10
2.7.2.2 Using the /ARITHMETIC Qualifier . ....................... 2–12
2.7.3 Specifying a Truncation Qualifier ............................. 2–12
2.7.4 Using the ROUNDED Phrase ............................... 2–12
2.7.4.1 ROUNDED with REMAINDER ........................... 2–13
2.7.5 Using the SIZE ERROR Phrase .............................. 2–13
2.7.6 Using the GIVING Phrase . . ................................ 2–14
2.7.7 Multiple Operands in ADD and SUBTRACT Statements........... 2–14
2.7.8 Common Errors in Arithmetic Statements ...................... 2–15
3 Handling Nonnumeric Data
3.1 Storage of Nonnumeric Data . . . ................................ 3–1
3.2 Data Organization . . . ........................................ 3–2
3.2.1 Group Items ............................................. 3–2
3.2.2 Elementary Items ........................................ 3–2
3.3 Special Characters . . . ........................................ 3–3
3.4 Testing Nonnumeric Items ..................................... 3–3
3.4.1 Relation Tests of Nonnumeric Items . . . ....................... 3–3
3.4.1.1 Classes of Data ....................................... 3–4
3.4.1.2 Comparison Operations . ................................ 3–5
3.4.2 Class Tests for Nonnumeric Items ............................ 3–5
3.5 Data Movement ............................................. 3–6
3.6 Using the MOVE Statement . . . ................................ 3–7
3.6.1 Group Moves ............................................ 3–7
3.6.2 Elementary Moves ........................................ 3–7
3.6.2.1 Edited Moves . ........................................ 3–9
3.6.2.2 Justified Moves ....................................... 3–9
3.6.3 Multiple Receiving Items . . . ................................ 3–10
3.6.4 Subscripted Moves ........................................ 3–10
3.6.5 Common Nonnumeric Item MOVE Statement Errors ............. 3–11
3.6.6 Using the MOVE CORRESPONDING Statement for Nonnumeric
Items . . ................................................ 3–11
3.6.7 Using Reference Modification ................................ 3–12
4 Handling Tables
4.1 Defining Tables ............................................. 4–1
4.1.1 Defining Fixed-Length, One-Dimensional Tables . . ............... 4–1
4.1.2 Defining Fixed-Length, Multidimensional Tables. . ............... 4–4
4.1.3 Defining Variable-Length Tables ............................. 4–5
4.1.4 Storage Allocation for Tables ................................ 4–6
4.1.4.1 Using the SYNCHRONIZED Clause ....................... 4–7
4.2 Initializing Values of Table Elements ............................. 4–10
4.3 Accessing Table Elements ..................................... 4–12
4.3.1 Subscripting ............................................. 4–12
4.3.2 Subscripting with Literals . . ................................ 4–13
4.3.3 Subscripting with Data Names .............................. 4–14
4.3.4 Subscripting with Indexes . . ................................ 4–14
4.3.5 Relative Indexing . ........................................ 4–15
4.3.6 Index Data Items . ........................................ 4–16
v
4.3.7 Assigning Index Values Using the SET Statement................ 4–16
4.3.7.1 Assigning an Integer Index Value with a SET Statement ....... 4–16
4.3.7.2 Incrementing an Index Value with the SET Statement ......... 4–16
4.3.8 Identifying Table Elements Using the SEARCH Statement ......... 4–16
4.3.8.1 Implementing a Sequential Search ........................ 4–17
4.3.8.2 Implementing a Binary Search ........................... 4–18
5 Using the STRING, UNSTRING, and INSPECT Statements
5.1 Concatenating Data Using the STRING Statement .................. 5–1
5.1.1 Multiple Sending Items .................................... 5–1
5.1.2 Using the DELIMITED BY Phrase ........................... 5–2
5.1.3 Using the POINTER Phrase ................................ 5–4
5.1.4 Using the OVERFLOW Phrase . . ............................ 5–4
5.1.5 Common STRING Statement Errors .......................... 5–6
5.2 Separating Data Using the UNSTRING Statement .................. 5–6
5.2.1 Multiple Receiving Items ................................... 5–6
5.2.2 Controlling Moved Data Using the DELIMITED BY Phrase ........ 5–8
5.2.2.1 Multiple Delimiters .................................... 5–12
5.2.3 Using the COUNT Phrase .................................. 5–12
5.2.4 Saving UNSTRING Delimiters Using the DELIMITER Phrase . . . . . . 5–13
5.2.5 Controlling UNSTRING Scanning Using the POINTER Phrase . . . . . 5–14
5.2.6 Counting UNSTRING Receiving Items Using the TALLYING
Phrase ................................................. 5–15
5.2.7 Exiting an UNSTRING Statement Using the OVERFLOW Phrase . . . 5–16
5.2.8 Common UNSTRING Statement Errors ....................... 5–16
5.3 Examining and Replacing Characters Using the INSPECT Statement . . . 5–17
5.3.1 Using the TALLYING and REPLACING Options of the INSPECT
Statement . . ............................................ 5–17
5.3.2 Restricting Data Inspection Using the BEFORE/AFTER Phrase . . . . . 5–18
5.3.3 Implicit Redefinition . . .................................... 5–18
5.3.4 Examining the INSPECT Operation .......................... 5–21
5.3.4.1 Setting the Scanner .................................... 5–22
5.3.4.2 Active/Inactive Arguments . . . ............................ 5–22
5.3.4.3 Finding an Argument Match . ............................ 5–23
5.3.5 The TALLYING Phrase .................................... 5–24
5.3.5.1 The Tally Counter . .................................... 5–24
5.3.5.2 The Tally Argument .................................... 5–24
5.3.5.3 The Tally Argument List ................................ 5–25
5.3.5.4 Interference in Tally Argument Lists ....................... 5–27
5.3.6 Using the REPLACING Phrase . . ............................ 5–30
5.3.6.1 The Search Argument .................................. 5–30
5.3.6.2 The Replacement Value ................................. 5–31
5.3.6.3 The Replacement Argument . . ............................ 5–31
5.3.6.4 The Replacement Argument List .......................... 5–31
5.3.6.5 Interference in Replacement Argument Lists ................. 5–32
5.3.7 Using the CONVERTING Option. ............................ 5–33
5.3.8 Common INSPECT Statement Errors ......................... 5–33
vi
6 Processing Files and Records
6.1 Defining Files and Records .................................... 6–1
6.1.1 File Organization . ........................................ 6–2
6.1.2 Record Format . . . ........................................ 6–8
6.1.3 File Design .............................................. 6–13
6.2 Identifying Files and Records from Within Your Compaq COBOL
Program................................................... 6–14
6.2.1 Defining a File Connector . . ................................ 6–14
6.2.2 Specifying File Organization and Record Access Mode............. 6–20
6.3 Creating and Processing Files . . ................................ 6–24
6.3.1 Opening and Closing Files . . ................................ 6–24
6.3.2 File Handling for Sequential and Line Sequential Files ........... 6–26
6.3.3 File Handling for Relative Files .............................. 6–29
6.3.4 File Handling for Indexed Files .............................. 6–32
6.4 Reading Files ............................................... 6–37
6.4.1 Reading a Sequential or Line Sequential File ................... 6–37
6.4.2 Reading a Relative File .................................... 6–38
6.4.3 Reading an Indexed File . . . ................................ 6–42
6.5 Updating Files .............................................. 6–48
6.5.1 Updating a Sequential or Line Sequential File . . . ............... 6–48
6.5.2 Updating a Relative File . . . ................................ 6–50
6.5.2.1 Rewriting a Relative File ................................ 6–50
6.5.2.2 Deleting Records from a Relative File ...................... 6–53
6.5.3 Updating an Indexed File . . ................................ 6–55
6.6 Backing Up Your Files ........................................ 6–60
7 Handling Input/Output Exception Conditions
7.1 Planning for the AT END Condition ............................. 7–2
7.2 Planning for the Invalid Key Condition ........................... 7–2
7.3 Using File Status Values and OpenVMS RMS Completion Codes ....... 7–3
7.3.1 File Status Values ........................................ 7–4
7.3.2 RMS Completion Codes (OpenVMS) . . . ....................... 7–5
7.4 Using Declarative USE Procedures .............................. 7–8
8 Sharing Files and Locking Records
8.1 Controlling Access to Files and Records ........................... 8–1
8.2 Choosing X/Open Standard or Compaq Standard File Sharing and Record
Locking . . . ................................................ 8–3
8.3 Ensuring Successful File Sharing ............................... 8–4
8.3.1 Providing Disk Residency. . . ................................ 8–4
8.3.2 Using File Protection ..................................... 8–4
8.3.3 Determining the Intended Access Mode to a File . . ............... 8–6
8.3.4 Specifying File Access Using X/Open Standard File Sharing . ....... 8–6
8.3.5 Specifying File Access Using Compaq Standard File Sharing ....... 8–8
8.3.6 Error Handling for File Sharing ............................. 8–12
8.4 Ensuring Successful Record Locking ............................. 8–16
8.4.1 X/Open Standard Record Locking ............................ 8–17
8.4.2 Compaq Standard Record Locking ........................... 8–18
8.4.3 Error Handling for Record Locking ........................... 8–23
vii
9 Using the SORT and MERGE Statements
9.1 Sorting Data with the SORT Statement .......................... 9–1
9.1.1 File Organization Considerations for Sorting . ................... 9–2
9.1.2 Specifying Sort Parameters with the ASCENDING and
DESCENDING KEY Phrases ................................ 9–3
9.1.3 Resequencing Files with the USING and GIVING Phrases ......... 9–3
9.1.4 Manipulating Data Before and After Sorting with the INPUT
PROCEDURE and OUTPUT PROCEDURE Phrases . . . ........... 9–3
9.1.5 Maintaining the Input Order of Records Using the WITH
DUPLICATES IN ORDER Phrase ............................ 9–6
9.1.6 Specifying Non-ASCII Collating Sequences with the COLLATING
SEQUENCE IS Alphabet-Name Phrase ........................ 9–7
9.1.7 Multiple Sorting .......................................... 9–7
9.1.8 Sorting Variable-Length Records . ............................ 9–8
9.1.9 Preventing I/O Aborts . .................................... 9–9
9.1.10 Sorting Tables ........................................... 9–9
9.1.11 Sorting at the Operating System Level ........................ 9–9
9.2 Merging Data with the MERGE Statement ........................ 9–10
9.3 Sample Programs Using the SORT and MERGE Statements .......... 9–10
10 Producing Printed Reports
10.1 Designing a Report .......................................... 10–1
10.2 Components of a Report . . . .................................... 10–1
10.3 Accumulating and Reporting Totals . . ............................ 10–4
10.4 The Logical Page and the Physical Page .......................... 10–5
10.5 Programming a Conventional File Report ......................... 10–6
10.5.1 Defining the Logical Page in a Conventional Report . . . ........... 10–6
10.5.2 Controlling the Spacing in a Conventional Report ................ 10–7
10.5.3 Advancing to the Next Logical Page in a Conventional Report . . . . . . 10–7
10.5.3.1 Programming for the Page-Overflow Condition in a Conventional
Report . . ............................................ 10–7
10.5.3.2 Using a Line Counter................................... 10–8
10.5.4 Printing the Conventional Report ............................ 10–9
10.5.5 A Conventional File Report Example .......................... 10–9
10.6 Programming a Linage-File Compaq COBOL Report ................. 10–12
10.6.1 Defining the Logical Page in a Linage-File Report ................ 10–13
10.6.2 Controlling the Spacing in a Linage-File Report ................. 10–14
10.6.3 Using the LINAGE-COUNTER . . ............................ 10–14
10.6.4 Advancing to the Next Logical Page in a Linage-File Report ........ 10–14
10.6.5 Programming for the End-of-Page and Page-Overflow Condition . . . . . 10–15
10.6.6 Printing a Linage-File Report . . . ............................ 10–19
10.6.7 A Linage-File Report Example . . . ............................ 10–20
10.7 Modes for Printing Reports .................................... 10–23
10.7.1 Directly Allocating a Printer ................................ 10–23
10.7.2 Spooling to a Mass Storage Device ............................ 10–24
10.8 Programming a Report Writer Report ............................ 10–24
10.8.1 Using the REPORT Clause in the File Section .................. 10–25
10.8.2 Defining the Report Section and the Report File ................. 10–25
10.8.3 Defining a Report Writer Logical Page with the PAGE Clause . . . . . . 10–25
10.8.4 Describing Report Group Description Entries ................... 10–26
10.8.5 Vertical Spacing for the Logical Page .......................... 10–29
10.8.6 Horizontal Spacing for the Logical Page ....................... 10–30
10.8.7 Assigning a Value in a Print Line ............................ 10–31
viii
10.8.8 Defining the Source for a Print Field . . . ....................... 10–31
10.8.9 Specifying Multiple Reports . ................................ 10–32
10.8.10 Generating and Controlling Report Headings and Footings . . ....... 10–32
10.8.11 Defining and Incrementing Totals ............................ 10–34
10.8.11.1 Subtotaling . . ........................................ 10–34
10.8.11.2 Crossfooting . . ........................................ 10–35
10.8.11.3 Rolling Forward ....................................... 10–35
10.8.11.4 RESET Option ........................................ 10–36
10.8.11.5 UPON Option . ........................................ 10–36
10.8.12 Restricting Print Items .................................... 10–37
10.8.13 Processing a Report Writer Report ............................ 10–38
10.8.13.1 Initiating the Report . . . ................................ 10–38
10.8.13.2 Generating a Report Writer Report . ....................... 10–39
10.8.13.3 Automatic Operations of the GENERATE Statement . . . ....... 10–39
10.8.13.4 Ending Report Writer Processing . . . ....................... 10–40
10.8.13.5 Applying the USE BEFORE REPORTING Statement . . . ....... 10–41
10.8.13.6 Suppressing a Report Group ............................. 10–42
10.8.14 Selecting a Report Writer Report Type. . ....................... 10–42
10.8.14.1 Detail Reporting....................................... 10–42
10.8.14.2 Summary Reporting .................................... 10–43
10.9 Report Writer Examples ....................................... 10–43
10.9.1 Input Data .............................................. 10–43
10.9.2 EX1006—Detail Report Program ............................. 10–44
10.9.3 EX1007—Detail Report Program ............................. 10–49
10.9.4 EX1008—Detail Report Program ............................. 10–57
10.9.5 EX1009—Detail Report Program ............................. 10–65
10.9.6 EX1010—Summary Report Program . . . ....................... 10–74
10.10 Solving Report Problems ...................................... 10–82
10.10.1 Printing More Than One Logical Line on a Single Physical Line ..... 10–82
10.10.2 Group Indicating . ........................................ 10–87
10.10.3 Fitting Reports on the Page . ................................ 10–88
10.10.4 Printing Totals Before Detail Lines ........................... 10–88
10.10.5 Underlining Items in Your Reports ........................... 10–89
10.10.6 Bolding Items in Your Reports ............................... 10–89
11 Using ACCEPT and DISPLAY Statements for Input/Output and
Video Forms
11.1 Using ACCEPT and DISPLAY for I/O ............................ 11–1
11.2 Designing Video Forms with ACCEPT and DISPLAY Statement
Extensions . ................................................ 11–3
11.2.1 Clearing a Screen Area .................................... 11–4
11.2.2 Horizontal and Vertical Positioning of the Cursor . ............... 11–5
11.2.3 Assigning Character Attributes to Your Format Entries ........... 11–8
11.2.4 Using the CONVERSION Phrase to Display Numeric Data . ....... 11–9
11.2.5 Handling Data with ACCEPT Options . . ....................... 11–12
11.2.5.1 Using CONVERSION with ACCEPT Data................... 11–12
11.2.5.2 Using ON EXCEPTION When Accepting Data with
CONVERSION ........................................ 11–13
11.2.5.3 Protecting the Screen . . . ................................ 11–14
11.2.5.4 Using NO ECHO with ACCEPT Data ...................... 11–16
11.2.5.5 Assigning Default Values to Data Fields .................... 11–16
11.2.6 Using Terminal Keys to Define Special Program Functions . . ....... 11–20
11.2.7 Using the EDITING Phrase . ................................ 11–28
ix
11.3 Designing Video Forms with Screen Section ACCEPT and DISPLAY . . . . 11–31
11.3.1 Using Screen Section Options . . . ............................ 11–32
11.3.1.1 Comparison of Screen Section Extensions with Other Extensions
of ACCEPT and DISPLAY . . . ............................ 11–34
12 Interprogram Communication
12.1 Multiple COBOL Program Run Units ............................ 12–1
12.1.1 Examples of COBOL Run Units . . ............................ 12–1
12.1.2 Calling Procedures ........................................ 12–2
12.2 COBOL Program Attributes .................................... 12–3
12.2.1 The INITIAL Clause . . .................................... 12–4
12.2.2 The EXTERNAL Clause .................................... 12–5
12.3 Transferring Flow of Control ................................... 12–5
12.3.1 The CALL Statement . . .................................... 12–5
12.3.2 Nesting CALL Statements .................................. 12–6
12.3.3 The EXIT PROGRAM Statement . ............................ 12–8
12.4 Accessing Another Program’s Data Division........................ 12–8
12.4.1 The USING Phrase . . . .................................... 12–9
12.4.2 The Linkage Section . . .................................... 12–12
12.5 Communicating with Contained COBOL Programs ................. 12–13
12.5.1 The COMMON Clause . .................................... 12–14
12.5.2 The GLOBAL Clause . . .................................... 12–15
12.5.2.1 Sharing GLOBAL Data ................................. 12–15
12.5.2.2 Sharing GLOBAL Files ................................. 12–15
12.5.2.3 Sharing USE Procedures ................................ 12–16
12.5.2.4 Sharing Other Resources ................................ 12–18
12.6 Calling Compaq COBOL Programs from Other Languages . ........... 12–19
12.6.1 Calling COBOL Programs from C ............................ 12–19
12.7 Calling Non-COBOL Programs from Compaq COBOL ................ 12–25
12.7.1 Calling a Fortran Program .................................. 12–25
12.7.2 Calling a BASIC Program .................................. 12–27
12.7.3 Calling a C Program . . .................................... 12–29
12.8 Special Considerations for Interprogram Communication . . ........... 12–30
12.8.1 CALL and CANCEL Arguments . ............................ 12–30
12.8.2 Calling OpenVMS Alpha Shareable Images (OpenVMS) ........... 12–30
12.8.3 Calling Tru64 UNIX Shareable Objects (Tru64 UNIX) . . ........... 12–30
12.8.4 Case Sensitivity on Tru64 UNIX and Windows NT ............... 12–30
12.8.4.1 Linker Case Sensitivity ................................. 12–30
12.8.4.2 Calling C Programs from Compaq COBOL on Tru64 UNIX and
Windows NT ......................................... 12–31
12.8.4.3 Calling COBOL Programs from C on Tru64 UNIX and Windows
NT ................................................ 12–31
12.8.5 Additional Information . .................................... 12–32
13 Using Compaq COBOL in the Alpha Common Language
Environment
13.1 Routines, Procedures, and Functions . ............................ 13–1
13.2 The OpenVMS Alpha Calling Standard (OpenVMS) ................. 13–2
13.2.1 Register and Stack Usage .................................. 13–2
13.2.2 Return of the Function Value ................................ 13–3
13.2.3 The Argument List ........................................ 13–3
13.3 OpenVMS Alpha System Routines (OpenVMS) . . ................... 13–3
x
13.3.1 OpenVMS Alpha Run-Time Library Routines ................... 13–4
13.3.2 System Services . . ........................................ 13–4
13.4 Calling Routines ............................................ 13–5
13.4.1 Determining the Type of Call (OpenVMS) ...................... 13–5
13.4.2 Defining the Argument (OpenVMS) ........................... 13–6
13.4.3 Calling the External Routine (OpenVMS) ...................... 13–7
13.4.4 Calling System Routines (OpenVMS) . . . ....................... 13–8
13.4.4.1 System Routine Arguments (OpenVMS) .................... 13–8
13.4.4.2 Calling a System Routine in a Function Call (OpenVMS) ....... 13–11
13.4.4.3 Calling a System Routine in a Procedure Call (OpenVMS) ...... 13–13
13.4.5 Checking the Condition Value (OpenVMS) ...................... 13–13
13.4.5.1 Library Return Status and Condition Value Symbols
(OpenVMS) . . ........................................ 13–15
13.4.6 Locating the Result (OpenVMS) .............................. 13–15
13.5 Establishing and Removing User Condition Handlers (OpenVMS) ...... 13–15
13.6 Examples (OpenVMS) ........................................ 13–19
14 Using the REFORMAT Utility
14.1 Running the REFORMAT Utility ................................ 14–1
14.2 ANSI-to-Terminal Format Conversion ............................ 14–2
14.3 Terminal-to-ANSI Format Conversion ............................ 14–3
14.4 REFORMAT Error Messages . . . ................................ 14–4
15 Optimizing Your Compaq COBOL Program
15.1 Specifying Optimization on the Compiler Command Line ............. 15–1
15.2 Specifying Alignment of Data for Optimum Performance ............. 15–5
15.3 Using COMP Data Items for Speed ............................. 15–5
15.4 Other Ways to Improve the Performance of Operations on Numeric
Data ...................................................... 15–7
15.4.1 Mixing Scale Factors and Data Types . . ....................... 15–7
15.4.2 Limiting Significant Digits . . ................................ 15–7
15.4.3 Reducing the Compexity of Arithmetic Expressions ............... 15–7
15.4.4 Selection of Data Types (OpenVMS)........................... 15–8
15.5 Choices in Procedure Division Statements . . ....................... 15–8
15.5.1 Using GO TO DEPENDING ON Instead of IF, GO TO ............ 15–8
15.5.2 Using Indexing Instead of Subscripting . ....................... 15–9
15.5.3 Using SEARCH ALL Instead of SEARCH ...................... 15–9
15.5.4 Selecting Hypersort for Sorting Tasks . . ....................... 15–9
15.5.5 Minimizing USE Procedures with LINKAGE SECTION References
....................................................... 15–10
15.6 I/O Operations ............................................. 15–10
15.6.1 Using the APPLY Clause . . ................................ 15–10
15.6.1.1 Using the PREALLOCATION Phrase of the APPLY Clause ..... 15–10
15.6.1.2 Using the EXTENSION Phrase of the APPLY Clause . . . ....... 15–11
15.6.1.3 Using the DEFERRED-WRITE Phrase of the APPLY Clause .... 15–11
15.6.1.4 Using the FILL-SIZE ON Phrase of the APPLY Clause . . ....... 15–12
15.6.1.5 Using the WINDOW Phrase of the APPLY Clause............. 15–12
15.6.2 Using Multiple Buffers ..................................... 15–12
15.6.3 Sharing Record Areas ..................................... 15–13
15.6.4 Using COMP Unsigned Longword Integers ..................... 15–15
15.7 Optimizing File Design (OpenVMS) .............................. 15–15
15.7.1 Sequential Files . . ........................................ 15–15
xi
15.7.2 Relative Files ............................................ 15–16
15.7.2.1 Maximum Record Number (MRN) ......................... 15–16
15.7.2.2 Cell Size . ............................................ 15–16
15.7.2.3 Bucket Size .......................................... 15–17
15.7.2.4 File Size . ............................................ 15–18
15.7.3 Indexed Files ............................................ 15–19
15.7.3.1 Optimizing Indexed File I/O. . ............................ 15–20
15.7.3.2 Calculating Key Index Levels. ............................ 15–24
15.7.3.3 Caching Index Roots ................................... 15–25
15.8 Image Activation Optimization (Tru64 UNIX) . . . ................... 15–25
16 Managing Memory and Data Access
16.1 Managing Memory Granularity ................................. 16–1
16.2 Using the VOLATILE Compiler Directive ......................... 16–3
16.3 Aligning Data for Performance and Compatibility ................... 16–3
16.3.1 Data Boundaries ......................................... 16–3
16.3.2 Data Field Padding . . . .................................... 16–4
16.3.3 Alignment Directives, Qualifiers, and Flags . ................... 16–4
16.3.4 Specifying Alignment at Compile Time ........................ 16–5
16.4 Using Alignment Directives, Qualifiers, and Flags .................. 16–6
16.4.1 Order of Alignment Operations . . ............................ 16–6
16.4.2 Nesting Alignment Directives . . . ............................ 16–7
16.4.3 Comparing Alignment Directive Effects ........................ 16–8
A Compiler Implementation Specifications
B Compaq COBOL for OpenVMS VAX and Compaq COBOL
Compatibility and Migration
B.1 Compatibility Matrix ......................................... B–1
B.2 Differences in Extensions and Other Features . . . ................... B–3
B.3 Command-Line Qualifiers (Options or Flags) ....................... B–4
B.3.1 Qualifiers and Flags Shared by Compaq COBOL and Compaq COBOL
for OpenVMS VAX . . . .................................... B–5
B.3.2 Compaq COBOL Specific Qualifiers and Flags ................... B–6
B.3.3 Qualifiers Only on Compaq COBOL for OpenVMS VAX ........... B–8
B.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Behavior
Differences ................................................. B–10
B.4.1 Program Structure Messages ................................ B–10
B.4.2 Program Listing Differences ................................ B–11
B.4.2.1 Machine Code ........................................ B–11
B.4.2.2 Module Names ........................................ B–11
B.4.2.3 COPY and REPLACE Statements ......................... B–11
B.4.2.4 Multiple COPY Statements . . ............................ B–12
B.4.2.5 COPY Insert Statement ................................. B–13
B.4.2.6 REPLACE and COPY REPLACING Statements . . . ........... B–14
B.4.2.7 DATE COMPILED Statement ............................ B–15
B.4.2.8 Compiler Listings and Separate Compilations (OpenVMS) . . . . . . B–15
B.4.3 Output Formatting ........................................ B–16
xii
B.4.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Statement
Differences .............................................. B–16
B.4.4.1 ACCEPT and DISPLAY Statements. ....................... B–16
B.4.4.2 LINAGE Clause ....................................... B–17
B.4.4.3 MOVE Statement...................................... B–18
B.4.4.4 SEARCH Statement .................................... B–18
B.4.5 System Return Codes ...................................... B–18
B.4.6 Diagnostic Messages ...................................... B–20
B.4.7 Storage for Double-Precision Data Items ....................... B–21
B.4.8 File Status Values ........................................ B–21
B.4.9 RMS Special Registers (OpenVMS) ........................... B–21
B.4.10 Calling Shareable Images . . ................................ B–22
B.4.11 Sharing Common Blocks (OpenVMS) . . . ....................... B–22
B.4.12 Arithmetic Operations ..................................... B–23
B.5 Compaq COBOL Differences Across Operating Systems .............. B–24
B.5.1 REWRITE .............................................. B–25
B.5.2 File Sharing and Record Locking ............................. B–25
B.5.3 VFC File Format . ........................................ B–26
B.5.4 File Attribute Checking .................................... B–26
B.5.5 Indexed Files ............................................ B–26
B.5.6 RMS Special Register References in Your Code . . . ............... B–27
B.5.7 Time and Fractional Seconds ............................... B–27
B.6 File Compatibility Across Languages and Platforms . . ............... B–27
B.7 LIB$INITIALIZE Interaction Between C and COBOL . ............... B–28
B.8 Reserved Words ............................................. B–28
B.9 Debugger Support Differences . ................................ B–29
B.10 DECset/LSE Support Differences ................................ B–29
B.11 DBMS Support .............................................. B–29
B.11.1 Compiling on Tru64 UNIX and Windows NT .................... B–29
B.11.2 Multistream DBMS DML . . . ................................ B–30
C Programming Productivity Tools
C.1 Compaq FUSE—an Integrated Development Environment (Tru64
UNIX) .................................................... C–1
C.2 Debugging Tools for Compaq COBOL Programs .................... C–2
C.3 Ladebug Debugger (Tru64 UNIX) ............................... C–4
C.4 OpenVMS Debugger (OpenVMS) ................................ C–8
C.4.1 Notes on Compaq COBOL Support ........................... C–8
C.4.2 Notes on Debugging Optimized Programs ...................... C–8
C.4.2.1 Separately Compiled Programs ........................... C–13
C.5 Language-Sensitive Editor (LSE) and the Source Code Analyzer (SCA)
(OpenVMS) ................................................ C–13
C.5.1 Notes on Compaq COBOL Support ........................... C–14
C.5.2 Preparing an SCA Library . . ................................ C–14
C.5.3 Starting and Terminating an LSE or an SCA Session ............. C–15
C.5.4 Compiling from Within LSE . ................................ C–15
C.6 Using Oracle CDD/Repository (OpenVMS) . . ....................... C–16
C.6.1 Creating Record and Field Definitions . . ....................... C–17
C.6.2 Accessing Oracle CDD/Repository Definitions from Compaq COBOL
Programs ............................................... C–18
C.6.3 Recording Dependencies.................................... C–19
C.6.4 Data Types.............................................. C–20
C.6.5 For More Information ..................................... C–22
xiii
D Porting to Compaq COBOL from Other Compilers
D.1 Porting Assistance ........................................... D–1
D.2 Flagged Foreign Extensions.................................... D–3
D.3 Implemented Extensions . . .................................... D–3
Index
Examples
1–1 Accessing Environment Variables and Command-Line Arguments . . . 1–24
1–2 Main Program and Subprograms . ............................ 1–45
1–3 Command Procedure to Link a Program as a Shareable Image . . . . . . 1–45
1–4 Accessing Logicals and Command-Line Arguments ............... 1–49
1–5 Using RMS Special Registers to Detect Errors (OpenVMS) ......... 1–56
1–6 Using RMS-CURRENT Special Registers to Detect Errors
(OpenVMS) . ............................................ 1–58
2–1 Success/Failure Test . . . .................................... 2–5
3–1 Item Concatenation Using Two MOVE Statements ............... 3–6
3–2 Sample Record Description Using the MOVE CORRESPONDING
Statement . . ............................................ 3–11
4–1 One-Dimensional Table .................................... 4–2
4–2 Multiple Data Items in a One-Dimensional Table ................ 4–2
4–3 Defining a Table with an Index and an Ascending Search Key . . . . . . 4–3
4–4 Defining a Two-Dimensional Table ............................ 4–4
4–5 Defining a Three-Dimensional Table .......................... 4–5
4–6 Defining a Variable-Length Table. ............................ 4–6
4–7 Sample Record Description Defining a Table . ................... 4–7
4–8 Record Description Containing a COMP SYNC Item . . . ........... 4–8
4–9 Adding an Item Without Changing the Table Size ................ 4–8
4–10 How Adding 3 Bytes Adds 4 Bytes to the Element Length ......... 4–9
4–11 Initializing Tables with the VALUE Clause . . ................... 4–10
4–12 Initializing a Table with the OCCURS Clause ................... 4–10
4–13 Initializing Mixed Usage Items . . ............................ 4–11
4–14 Initializing Alphanumeric Items . ............................ 4–12
4–15 Using a Literal Subscript to Access a Table . . ................... 4–13
4–16 Subscripting a Multidimensional Table ........................ 4–13
4–17 Subscripting with Index Name Items .......................... 4–15
4–18 Sample Table ............................................ 4–19
4–19 A Serial Search .......................................... 4–20
4–20 Using SEARCH and Varying an Index Other than the First Index . . . 4–21
4–21 Using SEARCH and Varying an Index Data Item ................ 4–21
4–22 Using SEARCH and Varying an Index not Associated with the Target
Table .................................................. 4–22
4–23 Doing a Serial Search Without Using the VARYING Phrase ........ 4–22
4–24 A Multiple-Key, Binary Search . . . ............................ 4–23
5–1 Using the STRING Statement and Literals . . ................... 5–2
5–2 Sample Overflow Condition ................................. 5–5
xiv
6–1 Sample Record Description . ................................ 6–9
6–2 Determining Fixed-Length Record Size . ....................... 6–10
6–3 Determining Fixed-Length Record Size for Files with Multiple Record
Descriptions ............................................. 6–10
6–4 Creating Variable-Length Records with the DEPENDING ON
Phrase . ................................................ 6–11
6–5 Creating Variable-Length Records with the RECORD VARYING
Phrase . ................................................ 6–11
6–6 Creating Variable-Length Records and Using the OCCURS Clause
with the DEPENDING ON Phrase ........................... 6–11
6–7 Defining Fixed-Length Records with Multiple Record Descriptions . . . 6–12
6–8 Defining a Disk File ....................................... 6–15
6–9 Defining a Magnetic Tape File (OpenVMS) ..................... 6–16
6–10 Defining a Magnetic Tape File (Tru64 UNIX) ................... 6–16
6–11 Using Environment Variables for File Specification ............... 6–19
6–12 Using Environment Variables ............................... 6–19
6–13 Specifying Sequential File Organization and Sequential Access Mode
for a Sequential File ...................................... 6–21
6–14 Specifying Relative File Organization and Random Access Mode for a
Relative File............................................. 6–21
6–15 Specifying Indexed File Organization and Dynamic Access Mode for
an Indexed File . . ........................................ 6–21
6–16 Specifying Line Sequential File Organization with Sequential Access
Mode . . ................................................ 6–22
6–17 SELECT Statements for Sequential Files with Sequential Access
Mode . . ................................................ 6–23
6–18 SELECT Statements for Relative Files with Sequential and Dynamic
Access Modes ............................................ 6–23
6–19 SELECT Statements for Indexed Files with Dynamic and Default
Sequential Access Modes . . . ................................ 6–24
6–20 SELECT Statements for Line Sequential Files with Sequential Access
Modes . ................................................ 6–24
6–21 OPEN and CLOSE Statements .............................. 6–25
6–22 Creating a Sequential File . . ................................ 6–26
6–23 Creating a Line Sequential File .............................. 6–27
6–24 Creating a Relative File in Sequential Access Mode .............. 6–30
6–25 Creating a Relative File in Random Access Mode . ............... 6–30
6–26 Creating and Populating an Indexed File ...................... 6–33
6–27 Using Segmented Keys .................................... 6–35
6–28 Reading a Sequential File . . ................................ 6–38
6–29 Reading a Relative File Sequentially . . . ....................... 6–39
6–30 Reading a Relative File Randomly............................ 6–40
6–31 Reading a Relative File Dynamically . . . ....................... 6–41
6–32 Reading an Indexed File Sequentially . . ....................... 6–42
6–33 Reading an Indexed File Randomly ........................... 6–43
6–34 Reading an Indexed File Dynamically . . ....................... 6–45
6–35 Reading an Indexed File Dynamically, with READ PRIOR . . ....... 6–46
6–36 Rewriting a Sequential File . ................................ 6–49
xv
6–37 Extending a Sequential File ................................. 6–50
6–38 Rewriting Relative Records in Sequential Access Mode . ........... 6–51
6–39 Rewriting Relative Records in Random Access Mode . . . ........... 6–52
6–40 Deleting Relative Records in Sequential Access Mode . . ........... 6–53
6–41 Deleting Relative Records in Random Access Mode ............... 6–54
6–42 Updating an Indexed File Sequentially ........................ 6–56
6–43 Updating an Indexed File Randomly .......................... 6–57
7–1 Handling the AT END Condition . ............................ 7–2
7–2 Handling the Invalid Key Condition .......................... 7–3
7–3 Defining a File Status for a File . ............................ 7–4
7–4 Using the File Status Value in an Exception Handling Routine . . . . . 7–4
7–5 Referencing RMS-STS, RMS-STV, RMS-CURRENT-STS, and
RMS-CURRENT-STV Codes (OpenVMS) . . . ................... 7–6
7–6 The Declaratives Skeleton .................................. 7–9
7–7 A Declarative USE Procedure Skeleton ........................ 7–9
7–8 Five Types of Declarative USE Procedures . . ................... 7–10
8–1 X/Open Standard Lock Modes and Opening Files ................ 8–7
8–2 Program Segment for File Status Values ....................... 8–13
8–3 Program Segment for RMS-STS Values (OpenVMS) . . . ........... 8–15
8–4 X/Open Standard Record Locking ............................ 8–18
8–5 Automatic Record Locking (Compaq Standard) .................. 8–19
8–6 Sample Program Using Manual Record Locking (Compaq
Standard) . . . ............................................ 8–21
8–7 Program Segment for Record-Locking Exceptions ................ 8–25
9–1 INPUT and OUTPUT PROCEDURE Phrases ................... 9–4
9–2 USING Phrase Replaces INPUT PROCEDURE Phrase . ........... 9–6
9–3 Overriding the COLLATING SEQUENCE IS Phrase. . . ........... 9–7
9–4 Using Two Sort Files . . .................................... 9–7
9–5 The Declarative USE AFTER STANDARD ERROR PROCEDURE . . 9–9
9–6 Using the MERGE Statement . . . ............................ 9–10
9–7 Sorting a File with the USING and GIVING Phrases . . ........... 9–11
9–8 Using the USING and OUTPUT PROCEDURE Phrases ........... 9–12
9–9 Using the INPUT PROCEDURE and OUTPUT PROCEDURE
Phrases ................................................ 9–14
9–10 Using the COLLATING SEQUENCE IS Phrase ................. 9–16
9–11 Creating a New Sort Key ................................... 9–17
9–12 Merging Files ............................................ 9–19
10–1 Components of a Report .................................... 10–2
10–2 Checking for the Page-Overflow Condition . . . ................... 10–8
10–3 Page Advancing and Line Skipping ........................... 10–9
10–4 Checking for End-of-Page on a 28-Line Logical Page . . . ........... 10–16
10–5 Programming a 20-Line Logical Page Defined by the LINAGE Clause
with Automatic Page Overflow . . . ............................ 10–22
10–6 Sample Program EX1006 ................................... 10–45
10–7 Sample Program EX1007 ................................... 10–49
10–8 Sample Program EX1008 ................................... 10–58
10–9 Sample Program EX1009 ................................... 10–65
xvi
10–10 Sample Program EX1010 . . . ................................ 10–75
10–11 Printing Labels Four-Up . . . ................................ 10–83
10–12 Printing Labels Four-Up in Sort Order . ....................... 10–85
11–1 Erasing a Screen . ........................................ 11–5
11–2 Cursor Positioning ........................................ 11–6
11–3 Using PLUS for Cursor Positioning ........................... 11–8
11–4 Using Character Attributes . ................................ 11–9
11–5 Using the CONVERSION Phrase............................. 11–10
11–6 Using the ON EXCEPTION Phrase ........................... 11–13
11–7 Using the SIZE and PROTECTED Phrases ..................... 11–15
11–8 Using the NO ECHO Phrase ................................ 11–16
11–9 Using the DEFAULT Phrase ................................ 11–18
11–10 Using the CONTROL KEY IN Phrase . . ....................... 11–25
11–11 EDITING Phrase Sample Code .............................. 11–29
11–12 Designing a Video Form for a Daily Calendar ................... 11–36
12–1 Run Unit with Three Separately Compiled Programs ............. 12–2
12–2 Run Unit with a Main Program and Two Contained Programs ...... 12–3
12–3 Run Unit with Three Separately Compiled Programs, One with Two
Contained Programs ...................................... 12–4
12–4 Execution Sequence of Nested CALL Statements . ............... 12–6
12–5 Sequence of Messages Displayed When Example 12–4 Is Run ...... 12–8
12–6 Using the COMMON Clause ................................ 12–14
12–7 Calling a COBOL Program from C............................ 12–20
12–8 C Include File cobfunc.h.................................... 12–20
12–9 COBOL Called Program "CALLEDFROMC" .................... 12–21
12–10 C Program Using cobcall, cobfunc, and cobcancel. . ............... 12–22
12–11 COBOL Called Program "PROGCOB" . . ....................... 12–22
12–12 Calling a Fortran Program from a COBOL Program .............. 12–25
12–13 Fortran Subroutine SQROOT ................................ 12–26
12–14 Calling a BASIC Program from a COBOL Program ............... 12–27
12–15 BASIC Program "APP" and Output Data ....................... 12–28
12–16 C Routine to Be Called from a COBOL Program . . ............... 12–29
12–17 Calling a C Program from a COBOL Program ................... 12–29
13–1 User-Written Condition Handler ............................. 13–17
13–2 Random Number Generator (OpenVMS) ....................... 13–19
13–3 Using the SYS$SETDDIR System Service (OpenVMS) ............ 13–20
13–4 Using $ASCTIM (OpenVMS) ................................ 13–20
13–5 Sample Run of CALLTIME (OpenVMS) . ....................... 13–21
13–6 Using LIB$K_* and LIB$_* Symbols (OpenVMS) . ............... 13–22
16–1 Using *DC SET ALIGNMENT Directives ...................... 16–8
16–2 Using /ALIGNMENT with SYNCHRONIZED ................... 16–9
16–3 Comparing /NOALIGN, /ALIGN and /ALIGN=PADDING . . . ....... 16–10
16–4 Data Map for /NOALIGNMENT ............................. 16–11
16–5 Data Map for /ALIGNMENT, -align ........................... 16–11
16–6 Data Map for /ALIGNMENT=PADDING, -align pad .............. 16–12
B–1 Signed and Unsigned Differences ............................. B–18
B–2 Illegal Return Value Coding . ................................ B–19
xvii
C–1 Source Code Used in the Sample Debug Sessions ................ C–4
Figures
1–1 Commands for Developing Compaq COBOL Programs on Tru64
UNIX .................................................. 1–8
1–2 DCL Commands for Developing Programs . . . ................... 1–28
4–1 Organization of the One-Dimensional Table in Example 4–1 ........ 4–2
4–2 Organization of Multiple Data Items in a One-Dimensional Table. . . . 4–3
4–3 Organization of a Table with an Index and an Ascending Search
Key ................................................... 4–4
4–4 Organization of a Two-Dimensional Table . . . ................... 4–5
4–5 Organization of a Three-Dimensional Table . . ................... 4–5
4–6 Memory Map for Example 4–7 . . . ............................ 4–7
4–7 Memory Map for Example 4–8 . . . ............................ 4–8
4–8 Memory Map for Example 4–9 . . . ............................ 4–9
4–9 Memory Map for Example 4–10 . . ............................ 4–9
4–10 Memory Map for Example 4–11 . . ............................ 4–10
4–11 Memory Map for Example 4–13 . . ............................ 4–11
4–12 Memory Map for Example 4–14 . . ............................ 4–12
5–1 Results of the STRING Operation ............................ 5–3
5–2 Matching Delimiter Characters to Characters in a Field ........... 5–19
5–3 Sample INSPECT Statement ................................ 5–21
5–4 Typical REPLACING Phrase ................................ 5–22
5–5 The Replacement Argument ................................. 5–31
6–1 Sequential File Organization ................................ 6–3
6–2 A Multiple-Volume, Sequential File ........................... 6–4
6–3 Line Sequential File Organization ............................ 6–5
6–4 Relative File Organization .................................. 6–6
6–5 Indexed File Organization .................................. 6–8
8–1 Multiple Access to a File ................................... 8–1
8–2 Relationship of Record Locking to File Sharing .................. 8–2
8–3 Why a Record-Already-Exists Error Occurs . . ................... 8–16
10–1 Sample Layout Worksheet .................................. 10–2
10–2 Subtotals, Crossfoot Totals, and Rolled Forward Totals . ........... 10–5
10–3 Logical Page Area for a Conventional Report . ................... 10–6
10–4 A 20-Line Logical Page .................................... 10–11
10–5 A Double-Spaced Master Listing . ............................ 10–12
10–6 Logical Page Areas for a Linage-File Report . ................... 10–13
10–7 A 28-Line Logical Page .................................... 10–16
10–8 A 20-Line Logical Page .................................... 10–20
10–9 Presentation Order for a Logical Page ......................... 10–27
10–10 Sample Report Using All Seven Report Groups .................. 10–28
10–11 First GENERATE Statement ................................ 10–39
10–12 Subsequent GENERATE Statements .......................... 10–40
10–13 TERMINATE Statement ................................... 10–41
10–14 Sample MASTER.DAT File ................................. 10–44
xviii
10–15 EX1006.LIS Listing ....................................... 10–48
10–16 EX1007.LIS Listing ....................................... 10–56
10–17 EX1008.LIS Listing ....................................... 10–65
10–18 EX1009.LIS Listing ....................................... 10–73
10–19 EX1010.LIS Listing ....................................... 10–81
10–20 Printing Labels Four-Up . . . ................................ 10–83
10–21 Printing Labels Four-Up in Sort Order . ....................... 10–85
11–1 Adding Information to a Master File with a Video Form . . . ....... 11–4
11–2 Screen After the ERASE Statement Executes ................... 11–6
11–3 Positioning the Data on Line 19, Column 5 ..................... 11–7
11–4 Cursor Positioning Using the PLUS Option ..................... 11–8
11–5 Screen Display with Character Attributes ...................... 11–10
11–6 Sample Run of Program CONVERT ........................... 11–12
11–7 Accepting Data with the ON EXCEPTION Option. ............... 11–14
11–8 Screen Display of NUM-DATA Using the PROTECTED Option...... 11–16
11–9 Accepting Data with the DEFAULT Phrase ..................... 11–19
11–10 Compaq COBOL Control Keys on the Standard VT100 Keypad and
Keyboard ............................................... 11–24
11–11 Compaq COBOL Control Keys on a Typical VT200 or Later Keypad
and Keyboard . . . ........................................ 11–24
11–12 Screen Display of Program SPECIAL . . ....................... 11–28
11–13 Form with ACCEPT WITH EDITING Phrase ................... 11–31
11–14 MENU-SCREEN Output . . . ................................ 11–40
11–15 SCHEDULE-SCREEN Output ............................... 11–40
12–1 Nesting CALL Statements . ................................ 12–6
12–2 Transfer of Control Flow from a Main Program to Multiple
Subprograms ............................................ 12–9
12–3 Accessing Another Program’s Data Division..................... 12–10
12–4 Defining Data Names in the Linkage Section ................... 12–13
12–5 Sharing USE Procedures . . . ................................ 12–16
12–6 Executing Declaratives with Contained Programs (Rule 1) . . ....... 12–17
12–7 Executing Declaratives Within Contained Programs (Rule 2) ....... 12–18
15–1 Sharing Record Areas ..................................... 15–14
15–2 Two-Level Primary Index . . . ................................ 15–19
Tables
1–1 Other File Name Suffixes . . . ................................ 1–9
1–2 Compaq COBOL Command Flags on Tru64 UNIX. ............... 1–12
1–3 Main Tools for Program Development and Testing . ............... 1–26
1–4 COBOL Command Qualifiers ................................ 1–32
1–5 Commonly Used LINK Qualifiers ............................ 1–40
2–1 Numeric Relational Operator Descriptions ...................... 2–3
2–2 Sign Tests .............................................. 2–4
2–3 Numeric Editing . ........................................ 2–8
2–4 ROUNDING ............................................. 2–13
3–1 Relational Operator Descriptions ............................. 3–4
xix
3–2 Nonnumeric Elementary Moves . . ............................ 3–8
3–3 Data Movement with Editing Symbols ......................... 3–9
3–4 Data Movement with the JUSTIFIED Clause ................... 3–10
4–1 Subscripting Rules for a Multidimensional Table................. 4–14
4–2 Subscripting with Data Names . . ............................ 4–14
5–1 Results of Sample Overflow Statements ........................ 5–5
5–2 Values Moved into the Receiving Items Based on the Sending Item
Value .................................................. 5–7
5–3 Handling a Short Sending Item . . ............................ 5–8
5–4 Results of Delimiting with an Asterisk ........................ 5–9
5–5 Results of Delimiting Multiple Receiving Items .................. 5–10
5–6 Results of Delimiting with Two Asterisks . . . ................... 5–10
5–7 Results of Delimiting with ALL Asterisks . . . ................... 5–11
5–8 Results of Delimiting with ALL Double Asterisks ................ 5–11
5–9 Results of Multiple Delimiters . . . ............................ 5–12
5–10 Values Resulting from Implicit Redefinition . . ................... 5–20
5–11 Relationship Among INSPECT Argument, Delimiter, Item Value, and
Argument Active Position .................................. 5–23
5–12 LEADING Delimiter of the Inspection Operation ................ 5–25
5–13 Results of the Scan with Separate Tallies . . . ................... 5–26
6–1 Compaq COBOL File Organizations—Advantages and
Disadvantages ........................................... 6–2
6–2 Record Format Availability ................................. 6–8
6–3 Valid I/O Statements for Sequential Files . . . ................... 6–27
6–4 Valid I/O Statements for Line Sequential Files .................. 6–28
6–5 Valid I/O Statements for Relative Files ........................ 6–32
6–6 Valid I/O Statements for Indexed Files ........................ 6–34
6–7 Indexed File—ISAM Mapping . . . ............................ 6–47
8–1 File-Sharing Options (OpenVMS) . ............................ 8–10
8–2 File-Sharing Options (Tru64 UNIX) ........................... 8–11
8–3 File Status Values Used in a File-Sharing Environment ........... 8–12
8–4 RMS-STS Values Used in a File-Sharing Environment (OpenVMS). . . 8–14
8–5 Manual Record Locking Combinations ......................... 8–20
10–1 Report Writer Report Group Types ........................... 10–26
10–2 Results of Group Indicating ................................. 10–87
11–1 Available Character Attributes by Terminal Type ................ 11–9
11–2 Compaq COBOL Characters Returned for Cursor Positioning,
Program Function, Function, Keypad, and Keyboard Keys ......... 11–20
11–3 Key Functions for the EDITING Phrase ....................... 11–28
11–4 Character Attribute Clauses for Screen Description Formats ....... 11–32
11–5 Color Table. . ............................................ 11–34
12–1 Calls to COBOL Programs .................................. 12–19
12–2 C Routine Called by Statement: CALL ‘‘Job1’’ ................... 12–31
12–3 C Invocation to Call COBOL PROGRAM-ID ‘‘Job2’’ ............... 12–31
13–1 OpenVMS Alpha Register Usage (OpenVMS) ................... 13–2
13–2 Run-Time Library Facilities (OpenVMS) ....................... 13–4
13–3 System Services (OpenVMS) ................................ 13–4
xx
13–4 COBOL Implementation of the OpenVMS Alpha Data Types
(OpenVMS) ............................................. 13–8
16–1 Boundaries for Naturally Aligned Binary Data . . . ............... 16–4
16–2 Alignment and Padding Order of Precedence .................... 16–7
B–1 Cross-Platform Compatibility of COBOL Features . ............... B–1
B–2 Qualifiers Shared by Compaq COBOL and Compaq COBOL for
OpenVMS VAX and Equivalent Flags and Options ............... B–5
B–3 Compaq COBOL Options Not Available in Compaq COBOL for
OpenVMS VAX . . . ........................................ B–6
B–4 Compaq COBOL for OpenVMS VAX Specific Qualifiers ............ B–8
C–1 Oracle CDD/Repository Data Types ........................... C–21
D–1 Recognized Foreign Reserved Words . . . ....................... D–2
xxi
This manual provides information to help you develop Compaq COBOL programs for the OpenVMS Alpha and Compaq Tru64 UNIX platforms.
Compaq COBOL is the new name for DEC COBOL and for DIGITAL COBOL. Compaq COBOL, unmodified, refers to the COBOL language on three platforms:
OpenVMS Alpha Tru64 UNIX Windows NT Alpha (described in separate documentation)
Compaq COBOL for OpenVMS VAX is the new name for VAX COBOL and DIGITAL VAX COBOL. It is the COBOL implementation for the OpenVMS VAX platform. (It is described in a separate documentation set.)
Any references to the former names in product documentation or other components should be construed as references to the Compaq COBOL names.
All references in this manual to Windows NT mean Microsoft Windows NT Alpha.
Intended Audience
This manual is intended for experienced applications programmers who have a thorough understanding of the COBOL language. Some familiarity with your operating system is also recommended. This is not a tutorial manual.

Preface

If you are a new COBOL user, you may need to read introductory COBOL textbooks or take COBOL courses. Additional prerequisites are described at the beginning of each chapter or appendix, if appropriate.
Document Structure
This manual is organized as follows:
Chapter 1 describes how to create, compile, link, and run Compaq COBOL programs and how to develop programs at the command level.
Chapter 2 describes how the Compaq COBOL compiler stores, represents, moves, and manipulates numeric data.
Chapter 3 describes how the Compaq COBOL compiler stores, represents, moves, and manipulates nonnumeric data.
Chapter 4 describes how to define, initialize, and access tables.
Chapter 5 describes how to perform text manipulation using the STRING, UNSTRING, and INSPECT statements.
Chapter 6 describes I/O services provided by the operating systems, including record management services.
Chapter 7 describes how to include exception handling routines in Compaq COBOL programs.
xxiii
Chapter 8 describes file sharing and record locking for sequential, relative, and indexed files.
Chapter 9 describes how to sort and merge files using the SORT and MERGE statements.
Chapter 10 describes how to produce printed reports.
Chapter 11 describes screen handling using the Compaq COBOL ACCEPT and DISPLAY statements.
Chapter 12 describes how Compaq COBOL programs communicate with each other or with non-COBOL programs through the CALL statement and external data.
Chapter 13 describes the use of Compaq COBOL in the OpenVMS Alpha Common Language Environment.
Chapter 14 describes how to use the REFORMAT utility, which converts terminal format source programs to conventional ANSI format and converts conventional ANSI format source programs to terminal format.
Chapter 15 presents guidelines for using the Compaq COBOL compiler optimization features.
Chapter 16 describes how to use compile-time and run-time features to optimize the use of system resources while also maximizing run-time performance.
Appendix A contains a list of Compaq COBOL specificatons and limits on the Tru64 UNIX and OpenVMS Alpha systems.
Appendix B describes compatibility and portability issues between Compaq COBOL for OpenVMS VAX and Compaq COBOL on the Tru64 UNIX and OpenVMS Alpha systems.
Appendix C describes optional programming productivity tools available on OpenVMS Alpha systems and Tru64 UNIX systems.
Appendix D describes porting assistance for migrating applications between other COBOL compilers and Compaq COBOL.
The Index indexes and references terms in this manual.
Associated Documents
The following documents contain additional information directly related to various topics in this manual:
Compaq COBOL Reference Manual
This manual describes the concepts and rules of the Compaq COBOL programming language under the supported operating systems.
Release Notes
Consult the Compaq COBOL release notes for your installed version for late corrections and new features.
xxiv
On the OpenVMS Alpha operating system, the release notes are in:
SYS$HELP:COBOLnnn.RELEASE_NOTES (ASCII text) SYS$HELP:COBOLnnn_RELEASE_NOTES.PS
where nnn is the version and release number, for example, 027 for Version
2.7.
On the Tru64 UNIX operating system, the release notes are in:
/usr/lib/cmplrs/cobol/relnotes
Compaq COBOL Installation Guide for OpenVMS Alpha Systems
This manual provides information on how to install Compaq COBOL on the
Convention Meaning
89
Braces used in a general format enclose lists from which you must choose only one item. For example:
(
SEQUENTIAL RANDOM DYNAMIC
)
23
Brackets used in a general format enclose optional items from which you can choose none or one. For example:
RECORD
ALL RECORDS
. . . A horizontal ellipsis indicates that the item preceding the
. . .
Format Program examples are shown in terminal format, rather than
special-character words The following symbols, when used in a general format,
Choice indicators, vertical lines inside a set of braces, used in a general format enclose lists from which you must choose one or more items, using each item chosen only once. For example:
g
9
=
;
...
8
<
COMMON
INITIAL
:
ellipsis can be repeated. For example:
f
switch-name
A vertical ellipsis indicates that not all of the statements are shown.
in ANSI standard format.
constitute required special-character words:
xxvi
Plus sign (+) Minus sign (-) Single (=) and double ( = = ) equal signs Less than (<) or greater than (>) symbols Less than or equal to (<=) and greater than or equal to (>=) symbols Period (.) Colon ( : ) Single (*) and double ( ** ) asterisks Slash ( / ) Left parenthesis (( ) or right parenthesis ())
quotation mark The term quotation mark is used to refer to the double
apostrophe The term apostrophe is used to refer to the single quotation
user input
quotation mark character (").
mark character (). In examples, user input (what you enter) is shown as
monospaced text
.
Convention Meaning
extensions Compaq extensions to the 1985 ANSI COBOL Standard are
report file Bold type indicates a new term. full-file-name This syntax term refers to the name of a file and the device
color coded in blue or gray. Note that the term extension in this manual means a Compaq extension to the ANSI COBOL Standard. (Some of these extensions are included in the X/Open CAE Standard for the COBOL language.)
and directory, or path, in which it is located. For example:
c:\home\public\filename.txt (Windows NT path) DISK2$:[HOME.PUBLIC]FILENAME.TXT; (OpenVMS file
specification) /disk2/home/public/filename.txt (Tru64 UNIX
file specification)
compiler option This term refers to command-line qualifiers (OpenVMS Alpha
systems), options (Windows NT Alpha systems), or flags (Tru64 UNIX systems). For example:
/LIST (OpenVMS qualifier or NT option)†
-list (Tru64 UNIX flag or NT option)†
COBOL This term refers to language information common to ANSI-85
Return
Tab Ctrl/x
$ The dollar sign ($) represents the OpenVMS system prompt. % The percent sign (%) represents the Tru64 UNIX system
C:\> A letter followed by a colon (: ), a backslash \, and a greater-
Start| Programs | . . . A series of names separated by vertical bars ( | ) means you
COBOL, Compaq COBOL, and Compaq COBOL for OpenVMS VAX.
A boxed symbol indicates that you must press a key on the terminal; for example, Return key.
This symbol indicates a nonprinting tab character. The symbol
CTRL while you press another key, for example,
prompt.
than sign (>) represents the MS-DOS system prompt.
should click on the first named Windows NT object, then the second named object, and so on.
Ctrl/x
Return
indicates that you press the
indicates that you hold down the key labeled
Ctrl CorCtrl O
.
References
†Either the slash or the hyphen is acceptable for Windows NT compiler options. Use the slash for Windows NT linker options.
The following table shows certain references and their respective meanings in this manual:
Reference Meaning
OpenVMS OpenVMS Alpha operating system Tru64 UNIX Compaq Tru64 UNIX operating system Windows NT Microsoft Windows NT Version 4.0, SP4, SP5 for Alpha systems
xxvii
Compaq Tru64 UNIX was formerly known as DEC OSF/1 or as DIGITAL UNIX. Compaq COBOL was formerly known as DIGITAL COBOL or DEC COBOL. Compaq COBOL for OpenVMS VAX was formerly known as VAX COBOL or as DIGITAL VAX COBOL.
Acknowledgment
COBOL is an industry language and is not the property of any company or group of companies, or of any organization or group of organizations.
No warranty, expressed or implied, is made by any contributor or by the CODASYL COBOL Committee as to the accuracy and functioning of the programming system and language. Moreover, no responsibility is assumed by any contributor, or by the committee, in connection therewith.
The authors and copyright holders of the copyrighted material used herein are as follows: FLOW-MATIC (trademark of Unisys Corporation), Programming for the UNIVAC (R) I and II, Data Automation Systems, copyrighted 1958, 1959, by Unisys Corporation; IBM Commercial Translator Form No. F28-8013, copyrighted 1959 by IBM; FACT, DSI 27A5260-2760, copyrighted 1960 by Minneapolis-Honeywell.
They have specifically authorized the use of this material, in whole or in part, in the COBOL specifications. Such authorization extends to the reproduction and use of COBOL specifications in programming manuals or similar publications.
How to Order Additional Documentation
For information on pricing and where to buy documentation and other Compaq products in the United States and Canada, please call toll-free 1-800-282-6672.
Reader’s Comments
Compaq appreciates your comments. If you find errors or want to comment about this manual, please send the manual title, order number, and your comments by one of the following methods:
Electronic Internet mail:
LanguageDocs@compaq.com
Fax:
603–884–0120 Attn: Languages Documentation, ZKO2–3/K35
A letter sent to the following address:
Compaq Computer Corporation Languages Documentation, ZKO2–3/K35 110 Spit Brook Road Nashua, NH 03062–2698 USA
xxviii
User Programs and the Year 2000
Even subsequent to the turn of the century, there still exist potential disruptions in previously problem-free software where there are instances of a two-digit year field that should be a four-digit field. Programmers need to correct all such fields, as Compaq cannot prevent problems that originate in application code.
For more information, see Section 1.6.
New Features
Consult the Index for entries under Version 2.7 – what’s new since V2.5. They will point you to information added since Version 2.5 of Compaq COBOL.
xxix
Loading...
+ 590 hidden pages