Compaq COBOL User Manual 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.
© 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.
Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii 1 Developing Compaq COBOL Programs 1.0.1 Files Installed on Your System . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.1 Compaq COBOL and Alpha Architecture System Resources . . . . . . . 1.1.1 Compilation Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.1.2 Tuning OpenVMS Alpha for Large Compaq COBOL Compiles . . 1.1.2.
1.2.5 1.3 1.3.1 1.3.2 1.3.2.1 1.3.2.2 1.3.2.3 1.3.2.4 1.3.2.5 1.3.2.6 1.3.2.7 1.3.2.8 1.3.2.9 1.3.3 1.3.3.1 1.3.3.2 1.3.3.3 1.3.3.4 1.3.3.5 1.3.3.6 1.3.4 1.3.4.1 1.3.4.2 1.3.4.3 1.3.4.4 1.3.4.5 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.5 1.5.1 1.5.2 1.6 Program Development Stages and Tools . . . . . . . . . . . . . . . . . Developing Programs on OpenVMS Alpha . . . . . . . . . . . . . . . . . . . Creating a Compaq COBOL Program on OpenVMS Alpha . . . Compiling a Compaq COBOL Program on OpenVMS Alpha . .
2.7.2 2.7.2.1 2.7.2.2 2.7.3 2.7.4 2.7.4.1 2.7.5 2.7.6 2.7.7 2.7.8 Standard and Native Arithmetic . . . . . . . . . . . . . . . . . . . Using the /MATH_INTERMEDIATE Qualifier . . . . . . Using the /ARITHMETIC Qualifier . . . . . . . . . . . . . . Specifying a Truncation Qualifier . . . . . . . . . . . . . . . . . . . Using the ROUNDED Phrase . . . . . . . . . . . . . . . . . . . . . ROUNDED with REMAINDER . . . . . . . . . . . . . . . . . Using the SIZE ERROR Phrase . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . 4–16 4–16 4–16 4–16 4–17 4–18 5.1 Concatenating Data Using the STRING Statement . . . . . . . . . . . . . . . 5.1.1 Multiple Sending Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.2 Using the DELIMITED BY Phrase . . . . . . . . . . . . . . . . . . . . . . . . 5.1.3 Using the POINTER Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.4 Using the OVERFLOW Phrase . . . . . . . . . . . . . . . . . . . . . . . . .
6 Processing Files and Records Defining Files and Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . File Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Record Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . File Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Identifying Files and Records from Within Your Compaq COBOL Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9 Using the SORT and MERGE Statements Sorting Data with the SORT Statement . . . . . . . . . . . . . . . . . . . . . . . File Organization Considerations for Sorting . . . . . . . . . . . . . . . . . Specifying Sort Parameters with the ASCENDING and DESCENDING KEY Phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.1.3 Resequencing Files with the USING and GIVING Phrases . . . . . . 9.1.4 Manipulating Data Before and After Sorting with the INPUT PROCEDURE and OUTPUT PROCEDURE Phrases . . . .
10.8.8 Defining the Source for a Print Field . . . . . . . . . . . . . . . . . . . . . . . . . . 10.8.9 Specifying Multiple Reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.8.10 Generating and Controlling Report Headings and Footings . . . . . . . . . 10.8.11 Defining and Incrementing Totals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.8.11.1 Subtotaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.8.11.2 Crossfooting . . .
11.3 Designing Video Forms with Screen Section ACCEPT and DISPLAY . . . . 11.3.1 Using Screen Section Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3.1.1 Comparison of Screen Section Extensions with Other Extensions of ACCEPT and DISPLAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11–31 11–32 11–34 12 Interprogram Communication 12.1 Multiple COBOL Program Run Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.1.1 Examples of COBOL Run Units . . .
13.3.1 OpenVMS Alpha Run-Time Library Routines . . . . . . . . . . . . . . . . . . . 13.3.2 System Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.4 Calling Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.4.1 Determining the Type of Call (OpenVMS) . . . . . . . . . . . . . . . . . . . . . . 13.4.2 Defining the Argument (OpenVMS) . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.4.
15.7.2 Relative Files . . . . . . . . . . . . . . . . . . . . . . 15.7.2.1 Maximum Record Number (MRN) . . . 15.7.2.2 Cell Size . . . . . . . . . . . . . . . . . . . . . . . 15.7.2.3 Bucket Size . . . . . . . . . . . . . . . . . . . . 15.7.2.4 File Size . . . . . . . . . . . . . . . . . . . . . . . 15.7.3 Indexed Files . . . . . . . . . . . . . . . . . . . . . . 15.7.3.1 Optimizing Indexed File I/O . . . . . . . . 15.7.3.2 Calculating Key Index Levels . . . . . . . 15.7.3.3 Caching Index Roots . . . . . . .
B.4.4 B.4.4.1 B.4.4.2 B.4.4.3 B.4.4.4 B.4.5 B.4.6 B.4.7 B.4.8 B.4.9 B.4.10 B.4.11 B.4.12 B.5 B.5.1 B.5.2 B.5.3 B.5.4 B.5.5 B.5.6 B.5.7 B.6 B.7 B.8 B.9 B.10 B.11 B.11.1 B.11.2 Compaq COBOL and Compaq COBOL for OpenVMS VAX Statement Differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ACCEPT and DISPLAY Statements . . . . . . . . . . . . . . . . . . . . . . . . LINAGE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
D Porting to Compaq COBOL from Other Compilers D.1 D.2 D.3 Porting Assistance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Flagged Foreign Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Implemented Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D–1 D–3 D–3 Accessing Environment Variables and Command-Line Arguments . . . Main Program and Subprograms . . . . . . . . . . . . . . . . . . . . .
6–1 6–2 6–3 6–4 6–5 6–6 6–7 6–8 6–9 6–10 6–11 6–12 6–13 6–14 6–15 6–16 6–17 6–18 6–19 6–20 6–21 6–22 6–23 6–24 6–25 6–26 6–27 6–28 6–29 6–30 6–31 6–32 6–33 6–34 6–35 6–36 Sample Record Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Determining Fixed-Length Record Size . . . . . . . . . . . . . . . . . . . . . . . . Determining Fixed-Length Record Size for Files with Multiple Record Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6–37 6–38 6–39 6–40 6–41 6–42 6–43 7–1 7–2 7–3 7–4 7–5 7–6 7–7 7–8 8–1 8–2 8–3 8–4 8–5 8–6 8–7 9–1 9–2 9–3 9–4 9–5 9–6 9–7 9–8 9–9 9–10 9–11 9–12 10–1 10–2 10–3 10–4 10–5 10–6 10–7 10–8 10–9 xvi Extending a Sequential File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Rewriting Relative Records in Sequential Access Mode . . . . . . . . . . . . Rewriting Relative Records in Random Access Mode . . . . . . . . . . . . . . Deleting Relative Records in Sequential Access Mode . . . . . . . .
10–10 10–11 10–12 11–1 11–2 11–3 11–4 11–5 11–6 11–7 11–8 11–9 11–10 11–11 11–12 12–1 12–2 12–3 12–4 12–5 12–6 12–7 12–8 12–9 12–10 12–11 12–12 12–13 12–14 12–15 12–16 12–17 13–1 13–2 13–3 13–4 13–5 13–6 16–1 16–2 16–3 16–4 16–5 16–6 B–1 B–2 Sample Program EX1010 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Printing Labels Four-Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Printing Labels Four-Up in Sort Order . . . . . . . . . . . . . . . . . . . . . . .
C–1 Source Code Used in the Sample Debug Sessions . . . . . . . . . . . . . . . . C–4 Figures 1–1 1–2 4–1 4–2 4–3 4–4 4–5 4–6 4–7 4–8 4–9 4–10 4–11 4–12 5–1 5–2 5–3 5–4 5–5 6–1 6–2 6–3 6–4 6–5 8–1 8–2 8–3 10–1 10–2 10–3 10–4 10–5 10–6 10–7 10–8 10–9 10–10 10–11 10–12 10–13 10–14 xviii Commands for Developing Compaq COBOL Programs on Tru64 UNIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . DCL Commands for Developing Programs . . . . . . . . . . . . . . .
10–15 10–16 10–17 10–18 10–19 10–20 10–21 11–1 11–2 11–3 11–4 11–5 11–6 11–7 11–8 11–9 11–10 11–11 11–12 11–13 11–14 11–15 12–1 12–2 12–3 12–4 12–5 12–6 12–7 15–1 15–2 EX1006.LIS Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . EX1007.LIS Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . EX1008.LIS Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . EX1009.LIS Listing . . . . . . . . . . . . . . . . . . . .
3–2 3–3 3–4 4–1 4–2 5–1 5–2 5–3 5–4 5–5 5–6 5–7 5–8 5–9 5–10 5–11 5–12 5–13 6–1 6–2 6–3 6–4 6–5 6–6 6–7 8–1 8–2 8–3 8–4 8–5 10–1 10–2 11–1 11–2 11–3 11–4 11–5 12–1 12–2 12–3 13–1 13–2 13–3 xx Nonnumeric Elementary Moves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Data Movement with Editing Symbols . . . . . . . . . . . . . . . . . . . . . . . . . Data Movement with the JUSTIFIED Clause . . . . . . . . . . . . . . . . . . . Subscripting Rules for a Multidimensional Table . . . . . . . . . .
13–4 16–1 16–2 B–1 B–2 B–3 B–4 C–1 D–1 COBOL Implementation of the OpenVMS Alpha Data Types (OpenVMS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Boundaries for Naturally Aligned Binary Data . . . . . . . . . . . . . Alignment and Padding Order of Precedence . . . . . . . . . . . . . . . Cross-Platform Compatibility of COBOL Features . . . . . . . . . . . Qualifiers Shared by Compaq COBOL and Compaq COBOL for OpenVMS VAX and Equivalent Flags and Options . . . . . . . . .
Preface 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.
• 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.
where nnn is the version and release number, for example, 027 for Version 2.7.
Convention 8 9 Meaning Braces used in a general format enclose lists from which you must choose only one item. For example: ( 2 3 Brackets used in a general format enclose optional items from which you can choose none or one. For example: SEQUENTIAL ) RANDOM DYNAMIC 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: 8 < : ...
Convention Meaning extensions Compaq extensions to the 1985 ANSI COBOL Standard are 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.) report file Bold type indicates a new term. full-file-name This syntax term refers to the name of a file and the device and directory, or path, in which it is located.
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.
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.
1 Developing Compaq COBOL Programs Compaq COBOL is a powerful optimizing compiler produced by Compaq Computer Corporation. It operates comfortably in the Compaq common language environment; it is based on GEM, which is the highly advanced code generator and optimizer that Compaq uses in its family of languages, which includes COBOL, C, C++, FORTRAN 77, FORTRAN 90, BASIC, Ada, and PASCAL.
Developing Compaq COBOL Programs 1.1 Compaq COBOL and Alpha Architecture System Resources 1.1 Compaq COBOL and Alpha Architecture System Resources For many user applications, the Compaq COBOL compiler requires significantly more system resources than Compaq COBOL for OpenVMS VAX. In fact, unless you have adjusted your system resource parameters accordingly, the attempt to compile may fail because of insufficient virtual memory.
Developing Compaq COBOL Programs 1.1 Compaq COBOL and Alpha Architecture System Resources • Check program sizes. Larger amounts of system resources are used during compilation for large monolithic source files. It is possible that your application is already composed of several separately compiled program units (different PROGRAM IDs not nested), but all in the same .COB. On Alpha systems with Compaq COBOL, compilation performance improves if you split the program units into separate (smaller) .
Developing Compaq COBOL Programs 1.1 Compaq COBOL and Alpha Architecture System Resources COPY files referenced). Alternatively, multiply 25 times the number of lines in the program (including all COPY files). The resulting figure can then be used as a starting point for the system generation parameter VIRTUALPAGECNT. Put that figure in the parameter file SYS$SYSTEM:MODPARAMS.DAT.
Developing Compaq COBOL Programs 1.1 Compaq COBOL and Alpha Architecture System Resources More physical memory can also be made available to a process (if it is present on the machine) by adjusting the system generation parameter WSMAX and the corresponding WSEXTENT (in AUTHORIZE). Approach such adjustments with great caution, as the system may hang if memory is oversubscribed and you create a situation where OpenVMS Alpha effectively has no options to reclaim memory.
Developing Compaq COBOL Programs 1.1 Compaq COBOL and Alpha Architecture System Resources 1.1.2.3 Improving Compile Performance with Separate Compilation (OpenVMS) The /SEPARATE_COMPILATION qualifier can improve compile-time performance for large source files that are made up of multiple separately compiled programs (SCPs).
Developing Compaq COBOL Programs 1.1 Compaq COBOL and Alpha Architecture System Resources 1.1.3.2 ANSI Reference Format ANSI format is useful on a card-oriented system or in an application where strict ANSI compliance is desired. To select ANSI format, specify the -ansi flag (on Tru64 UNIX systems) or the /ANSI_FORMAT qualifier (on OpenVMS Alpha systems) at compile time. You can choose this format if your COBOL program is written for a compiler that uses ANSI format.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX Figure 1–1 Commands for Developing Compaq COBOL Programs on Tru64 UNIX COMMANDS ACTION % vi prog1.cob Use the file type of cob to indicate the file contains a Compaq COBOL program. INPUT/OUTPUT FILES prog1.cob Create a source program % cobol -c prog1.cob The cobol command assumes no file type. (If you use the -list flag, the compiler creates a listing file; if you use the -c flag, the compiler creates an object file.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX .cob .COB .cbl .CBL Table 1–1 shows other file name suffixes. Table 1–1 Other File Name Suffixes Suffix Description .c Identifies C language files passed to the C compiler driver cc, which performs additional command line parsing before invoking the C language compiler. .s Identifies assembler files passed to files. .o .a Identifies object files passed to cc. Compaq COBOL does not generate .s cc, which are in turn passed to ld.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX Compaq recommends that you not name a Compaq COBOL program ‘‘main.’’ If you have a C routine named ‘‘main,’’ you can work around this problem by having the ‘‘main’’ routine directly call the Compaq COBOL initialization routine, cob_init. The cob_init routine interface (in C) is as follows: void cob_init ( int argc, char **argv, char **envp /* /* /* /* init the RTL */ argument count */ arguments */ environment variable pointers */ ) 1.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX An example cobol command line would be: % cobol -v test.cob pas.o This command specifies the following: • The -v flag displays the compilation and link passes with their arguments and files, including the libraries passed to ld. • The file test.cob is passed to the Compaq COBOL compiler for compilation. The resulting object file is then linked. • The object file pas.o is passed directly to the linker.
Developing Compaq COBOL Programs 1.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX Table 1–2 (Cont.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX Table 1–2 (Cont.) Compaq COBOL Command Flags on Tru64 UNIX Flag Default -T num -taso -tps -trunc -tune -V -v -w -warn -warn all -warn [no]information -warn [no]other -warn none -xref, -xref_stdout off off off off -tune generic off off off -warn other off -warn noinformation -warn other off off Technical Notes: 1.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX 4. Any copy file that contains a PROGRAM-ID or END PROGRAM statement for a program must contain that entire program.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX • Compiles the file mainprog.cob, which contains the main program • Uses ld to link both the main program and object files into an executable program file named calc The files can also be compiled separately, as follows: % cobol -c array_calc.cob % cobol -c calc_aver.cob % cobol -o calc mainprog.cob array_calc.o calc_aver.o In this case, the -c option prevents linking and retains the .o files.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX The object file is in Tru64 UNIX extended coff format. The object file provides the following information: • The name of the entry point. It takes this name from the program name in the first PROGRAM-ID paragraph in the source program. • A list of variables that are declared in the module. The linker uses this information when it binds two or more modules together and must resolve references to the same names in the modules.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX 2. % cobol -V *.cob Compaq COBOL source files with file names that end with .cob are compiled into temporary object files, which are then passed to the ld linker. The ld linker produces the a.out file. When the compilation completes, the cobol driver returns one of the following status values: 0—SUCCESS 1—FAILURE 2—SUBPROCESS_FAILURE (cobol or cc) 3—SIGNAL 1.2.2.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX Any messages issued during the compilation are inserted in the listing file. A listing file is useful for debugging the source code. Use the -V or -list flag to produce a listing; you may also use -cross_reference, -copy_list, -flagger, -machine_code, -map, and/or -warn, all of which affect the contents of the listing file. Diagnostic messages provide information for you to determine the cause of an error and correct it.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX If the symbol is undefined, U appears in the column before the symbol name. Any symbols with a U in their names can also be displayed by this use of grep. 1.2.3.2 Specifying Additional Object Libraries You can control the libraries as follows: • To specify additional object library file names for ld to locate, use the -lstring flag to define an additional object library for ld to search.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX 1.2.3.3 Specifying Types of Object Libraries Certain cobol flags influence whether ld searches for an archive (.a) or shared object (.so) library on the standard list of COBOL libraries and any additional libraries specified using the -lstring or -Ldir flags. These flags are the following: • The -call_shared flag, the default, indicates that .so files are searched before .a files.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX 1.2.3.5 Shared Library Restrictions When creating a shared library using ld, be aware of the following restrictions: • Programs that are installed setuid or setgid will not use any libraries that have been installed using the inlib shell command, but only systemwide shared libraries (for security reasons). • For other restrictions imposed by the operating system, see your operating system documentation.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX The message-text may be on multiple lines and is sometimes accompanied by a cobol error. Some common errors that occur during linking resemble the following: • An object module has compilation errors. This error occurs when you attempt to link a module that had warnings or errors during compilation.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX You provide definitions for the command-line arguments with the SPECIALNAMES paragraph in your program’s Environment Division, and you include ACCEPT and DISPLAY statements in the Procedure Division to parse the command line and access the arguments. Detailed information about commandline argument capability is in the ACCEPT and DISPLAY sections in the Compaq COBOL Reference Manual. 1.2.4.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX Example 1–1 (Cont.) Accessing Environment Variables and Command-Line Arguments DISPLAY "COBOLPATH" UPON NAME-OF-ENVIRONMENT-VARIABLE.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX Table 1–3 lists and describes some of the software tools you can use when developing and testing a program. Table 1–3 Main Tools for Program Development and Testing Task or Activity Tool and Description Manage source files Use RCS or sccs to manage source files. For more information, see the Tru64 UNIX documentation on programming support tools or the appropriate reference page.
Developing Compaq COBOL Programs 1.2 Developing Programs on Tru64 UNIX • The strip command removes symbolic and other debugging information to minimize image size. For additional information, see strip(1). Note The CALL dataname, CANCEL, and the Compaq extensions to the ACCEPT and DISPLAY statements will not work correctly if you use the strip command on your image. In most instances, use the cobol command to invoke both the Compaq COBOL compiler and the ld linker.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha Figure 1–2 DCL Commands for Developing Programs COMMANDS $ EDIT/TPU PROG_1.COB Use the file type of COB to indicate the file contains a Compaq COBOL program. $ COBOL PROG_1 The COBOL Command assumes the file type of an input file is COB . (if you use the /LIST qualifier, the compiler creates a listing file.) $ LINK PROG_1 The LINK command assumes the file type of an input file is OBJ. ACTION INPUT/OUTPUT FILES PROG_1.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha You can use the COPY FROM DICTIONARY statement in your program to access a data dictionary and copy Oracle CDD/Repository record descriptions into your program as COBOL record descriptions. Before you can copy record descriptions from Oracle CDD/Repository, you must create the record descriptions using the Common Data Dictionary Language (CDDL) or Common Dictionary Operator (CDO).
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha /qualifier Specifies an action to be performed by the compiler on all files or specific files listed. When a qualifier appears directly after the COBOL command, it affects all the files listed. By contrast, when a qualifier appears after a file specification, it affects only the file that immediately precedes it. However, when files are concatenated, these rules do not apply.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha 1.3.2.4 Separately Compiled Programs If a compilation unit consists of multiple separately compiled programs (SCPs), by default the Compaq COBOL compiler produces a single object file that consists of a single module with multiple embedded procedures. This object file can be inserted into an object library. If your build procedure requires that the linker extract any part of the module, the linker must extract the entire object.
Developing Compaq COBOL Programs 1.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha Table 1–4 (Cont.) COBOL Command Qualifiers Qualifier Default 2 3 [NO]SYMBOLS /DEBUG= 4 [NO]TRACEBACK 5,...
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha Table 1–4 (Cont.) COBOL Command Qualifiers Qualifier Default /MACHINE_CODE or /NOMACHINE_CODE /NOMACHINE_CODE h i ALPHABETICAL1 DECLARED or /NOMAP ,... /MAP= ( /MATH_INTERMEDIATE= 8 AS_IS > > < /NOMAP CIT3 CIT4 FLOAT ) 9 > > = /MATH_INTERMEDIATE=FLOAT /NAMES=LOWERCASE LOWER /NAMES= LOWERCASE > > > UPPER > : ; UPPERCASE h /NATIONALITY= JAPAN US i /NATIONALITY=US /OBJECT[=filename.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha Table 1–4 (Cont.) COBOL Command Qualifiers Qualifier Default /RESERVED_WORDS= " [NO]200X [NO]XOPEN [NO]FOREIGN_EXTENSIONS # , ... /RESERVED_WORDS=(XOPEN, NO200X, NOFOREIGN_EXTENSIONS) /SEPARATE_COMPILATION or /NOSEPARATE_COMPILATION /NOSEPARATE_COMPILATION /SEQUENCE_CHECK or /NOSEQUENCE_CHECK /NOSEQUENCE_CHECK /SOURCE[=filename.ext] Source is filename.COB 2 3 /STANDARD=851 85 6 [NO]MIA 7 6 [NO]SYNTAX 7,...
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha • Forgetting to use a file suffix in the file specification, or not specifying /SOURCE when your source file suffix is not .COB or .CBL 1.3.2.7 Compiling Programs with Conditional Compilation To debug source code that contains conditional compilation lines, you can use either the /CONDITIONALS qualifier or the WITH DEBUGGING MODE clause. The /CONDITIONALS qualifier is listed in Table 1–4.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha message-text The compiler’s message. In many cases, it consists of no more than one line of output. A message generally provides you with enough information to determine the cause of the error so that you can correct it. At line number n in name The integer n is the number of the line where the diagnostic occurs. The number is relative to the beginning of the file or text library module specified by name.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha 1.3.2.9 Using Compiler Listing Files A compiler listing file provides information that can help you debug or document your Compaq COBOL program. It consists of the following sections: • Program listing The program listing section contains the source code plus line numbers generated by the compiler. Any diagnostics will appear in this section.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha 1.3.3 Linking a Compaq COBOL Program After you compile a Compaq COBOL source program or module, use the LINK command to combine your object modules into one executable image that the OpenVMS Alpha operating system can execute. A source program or module cannot run until it is linked.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha 1.3.3.2 LINK Qualifiers LINK qualifiers allow you to control various aspects of the link operation such as modifying linker input and output and invoking the debugging and traceback facilities. Table 1–5 summarizes some of the more commonly used LINK qualifiers.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha 2. Calls a Compaq COBOL program that contains CALL by data name, extended ACCEPT, or extended DISPLAY statements. Compaq COBOL uses the LIB$INITIALIZE routine, COB_NAME_START, to initialize the run-time environment for the CALL by data name and extended ACCEPT and DISPLAY statements. Therefore, the COB_NAME_START routine must be invoked before any CALL, ACCEPT, or DISPLAY statements are performed.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha Defining Default User Object Module Libraries You can define one or more of your private object module libraries as your default user libraries using the DCL DEFINE command, as in the following example: $ DEFINE LNK$LIBRARY DEFLIB The linker searches default user libraries for unresolved references after it searches modules and libraries specified in the LINK command.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha Defining the Search Order for Libraries When you specify libraries as input for the linker, you can specify as many as you want; there is no practical limit. More than one library can contain a definition for the same module name. The linker uses the following conventions to search libraries specified in the command string: • A library is searched only for definitions that are unresolved in the previously specified input files.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha See the OpenVMS Linker Utility Manual and the Guide to Creating OpenVMS Modular Procedures for more information about shareable images. The following sample programs and command procedure provide an example of how to create, link, and install a subprogram as a shareable image, as described in the preceding steps. Example 1–2 shows the main program CALLER.COB and the two subprograms (SUBSHR1.COB and SUBSHR2.COB).
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha Example 1–2 Main Program and Subprograms * CALLER.COB IDENTIFICATION DIVISION. PROGRAM-ID. CALLER. ****************************************************************** * This program calls a subprogram installed as a shareable image.* ****************************************************************** PROCEDURE DIVISION. 0. CALL "SUBSHR1" ON EXCEPTION DISPLAY "First CALL failed. Program aborted." END-CALL. STOP RUN. END PROGRAM CALLER.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha Example 1–3 (Cont.) Command Procedure to Link a Program as a Shareable Image $! $! $ $ $ $! $! $! $! $ $ Compile the main program and subprograms. COBOL CALLER.COB COBOL SUBSHR1.COB COBOL SUBSHR2.COB Create an options file containing all the universal symbols (entry points and other data symbols) for the subprograms. COPY SYS$INPUT OPTIONS1.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha 1.3.3.6 Interpreting Messages from the Linker If the linker detects any errors while linking object modules, it displays system messages indicating their cause and severity. If any error or fatal error conditions occur, the linker does not produce an image file. See the OpenVMS Linker Utility Manual for complete information about the format of linker options.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha 1.3.4 Running a Compaq COBOL Program After you compile and link your program, use the RUN command to execute it. In its simplest form the RUN command has the following format: $ RUN myprog In the preceding example MYPROG.EXE is the file specification of the image you want to run. If you omit the file type from the file specification, the system automatically provides a default value. The default file type is .EXE.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha You provide definitions for the command-line arguments with the SPECIAL-NAMES paragraph in your program’s Environment Division, and include ACCEPT and DISPLAY statements in the Procedure Division to parse the command line and access the arguments. Detailed information about commandline argument capability is in the ACCEPT and DISPLAY sections in the Compaq COBOL Reference Manual. 1.3.4.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha When you execute the following command line: $ MYPROG 1028 powers.dat The following will result: • howmany–records will contain 1028. • file-path will contain MYDEV:[MYDIR] • file-name will contain powers.dat • file-spec will contain MYDEF:[MYDIR]powers.dat For additional information, see the ACCEPT and DISPLAY statements in the Compaq COBOL Reference Manual. 1.3.4.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha 1.3.4.5 Interpreting Run-Time Messages During execution, an image can generate a fatal error called an exception condition. When an exception condition occurs, the system displays a message. Run-time messages can also be issued by the OpenVMS Alpha operating system or by other utilities such as SORT. Other kinds of errors that can occur at run time include program run errors and run-time input/output errors.
Developing Compaq COBOL Programs 1.3 Developing Programs on OpenVMS Alpha For more information about the OpenVMS Debugger, refer to Appendix C and the OpenVMS Debugger Manual. 1.4 Program Run Messages Incorrect or undesirable program results are usually caused by data errors or program logic errors. You can resolve most of these errors by desk-checking your program and by using a debugger. 1.4.1 Data Errors Faulty or incorrectly defined data often produce incorrect results.
Developing Compaq COBOL Programs 1.4 Program Run Messages 01 PAY-RECORD. 03 P-NUMBER 03 P-WEEKLY-AMT 03 P-YEARLY-AMT 03 P-MONTHLY-AMT . . . PROCEDURE DIVISION. ADD-TOTALS. ADD P-MONTHLY-AMT . . . PIC PIC PIC PIC X(5). S9(5)V99 COMP-3. S9(5)V99 COMP-3. S9(5)V99 COMP-3. TO TOTAL-MONTHLY-AMT. You can minimize record field position errors by writing your file and record descriptions in a library file and then using the COPY statement in your programs.
Developing Compaq COBOL Programs 1.4 Program Run Messages If, during execution, the program increments A-COUNTER by a value other than 1 (2 or 1.5, for example), A-COUNTER may never equal 10, causing a loop in ABC-ROUTINE. You can prevent this type of error by changing the statement to something like this: * This is a test for inequality PERFORM ABC-ROUTINE UNTIL A-COUNTER > 9 • Testing two floating point numbers (for example, COMP-1 and COMP-2 fields) for equality.
Developing Compaq COBOL Programs 1.4 Program Run Messages 050-READ-MASTER. READ INDEXED-MASTER INVALID KEY PERFORM 100-CHECK-STATUS GO TO 200-INVALID-READ. . . . 100-CHECK-STATUS. IF MASTER-STATUS = "23" DISPLAY "RECORD NOT IN FILE". IF MASTER-STATUS = "24" DISPLAY "BOUNDARY VIOLATION OR RELATIVE RECORD NUMBER TOO LARGE". . . .
Developing Compaq COBOL Programs 1.4 Program Run Messages Refer to the Compaq COBOL Reference Manual and the OpenVMS Record Management Services Reference Manual for more information about RMS special registers. Examples 1–5 and 1–6 show how you can use RMS special registers to detect errors. Example 1–5 Using RMS Special Registers to Detect Errors (OpenVMS) IDENTIFICATION DIVISION. PROGRAM-ID. RMS-SPEC-REGISTERS.
Developing Compaq COBOL Programs 1.4 Program Run Messages Example 1–5 (Cont.) Using RMS Special Registers to Detect Errors (OpenVMS) REPORT SECTION. RD RPT PAGE 26 LINES HEADING 1 FIRST DETAIL 5. 01 TYPE IS PAGE HEADING. 02 LINE IS PLUS 1. 03 COLUMN 1 PIC X(16) VALUE "Employee File on". 03 COLUMN 18 PIC Z9/99/99 SOURCE D-DATE. 02 LINE IS PLUS 2. 03 COLUMN 2 PIC X(5) VALUE "emp ". 03 COLUMN 22 PIC X(4) VALUE "name". 03 COLUMN 42 PIC X(7) VALUE "address". 03 COLUMN 70 PIC ZZ9 SOURCE PAGE-COUNTER.
Developing Compaq COBOL Programs 1.4 Program Run Messages Example 1–5 (Cont.) Using RMS Special Registers to Detect Errors (OpenVMS) 100-INITIALIZE. ACCEPT D-DATE FROM DATE. DISPLAY "Enter file spec of employee file: " WITH NO ADVANCING. ACCEPT VAL-OF-ID. PERFORM WITH TEST AFTER UNTIL VALID-OP SET VALID-OP TO TRUE SET OP-OPEN TO TRUE OPEN INPUT EMP-FILE IF OP-FAILED THEN SET OP-CLOSE TO TRUE CLOSE EMP-FILE END-IF END-PERFORM. OPEN OUTPUT REPORT-FILE. INITIATE RPT. SET NOT-E-O-F TO TRUE. SET OP-READ TO TRUE.
Developing Compaq COBOL Programs 1.4 Program Run Messages Example 1–6 (Cont.) Using RMS-CURRENT Special Registers to Detect Errors (OpenVMS) DATA DIVISION. FILE SECTION. FD FILE-1. 01 FILE-1-REC. 02 F1-REC-FIELD PIC 9(9). FD FILE-2. 01 FILE-2-REC. 02 F2-REC-FIELD PIC 9(9). FD FILE-3. 01 FILE-3-REC. 02 F3-REC-FIELD PIC 9(9). PROCEDURE DIVISION. DECLARATIVES. USE-SECT SECTION. USE AFTER STANDARD EXCEPTION PROCEDURE ON INPUT. CHECK-RMS-CURRENT-REGISTERS. DISPLAY "************** ERROR **************".
Developing Compaq COBOL Programs 1.5 Using Program Switches 1.5.1 Setting and Controlling Switches Internally To set switches from within the image, define them in the SPECIAL-NAMES paragraph of the ENVIRONMENT DIVISION and use the SET statement in the PROCEDURE DIVISION to specify switches ON or OFF, as in the following example: ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. SWITCH 10 IS MY-SWITCH ON IS SWITCH-ON OFF IS SWITCH-OFF. . . . PROCEDURE DIVISION. 000-SET-SWITCH. SET MY-SWITCH TO ON.
Developing Compaq COBOL Programs 1.5 Using Program Switches The switch-list can contain up to 16 switches separated by commas. To set a switch ON, specify it in the switch-list. A switch is OFF (the default) if you do not specify it in the switch-list. For example: $ DEFINE COB$SWITCHES "1,5,13" Sets switches 1, 5, and 13 ON. $ DEFINE COB$SWITCHES "9,11,16" Sets switches 9, 11, and 16 ON. $ DEFINE COB$SWITCHES " " Sets all switches OFF.
Developing Compaq COBOL Programs 1.5 Using Program Switches On OpenVMS, to test the previous program on an OpenVMS Alpha system, compile and link it and then type the following: $ DEFINE COB$SWITCHES 12 $ RUN TSW The output is as follows: **TEST SWITCHES** SWITCH 12 IS ON **END** ♦ To test the previous program on a Tru64 UNIX system, compile and link it and then type the following: % setenv COBOL_SWITCHES 12 % tsw The output is as follows: **TEST SWITCHES** SWITCH 12 IS ON **END** 1.
Developing Compaq COBOL Programs 1.6 Special Information for Year 2000 Programming 4-digit ACCEPT FROM DATE YYYYMMDD 4-digit ACCEPT FROM DAY YYYYDDD Compaq COBOL offers date functions that can be used in program logic that makes decisions about year order. The full four-digit year handled by the six functions listed should be used in internal program logic decisions that are based on years. External displays of year information can continue to use two-digit formats when that is appropriate.
2 Handling Numeric Data Numeric data in Compaq COBOL is evaluated with respect to the algebraic value of the operands. This chapter describes the following topics concerning numeric data handling: • How the compiler stores numeric data (Section 2.1) • Specifying alignment (Section 2.2) • Sign conventions (Section 2.3) • Invalid values in numeric items (Section 2.4) • Evaluating numeric items (Section 2.5) • Using the MOVE statement (Section 2.6) • Using the arithmetic statements (Section 2.
Handling Numeric Data 2.2 Specifying Alignment OpenVMS VAX, or flexibility. (See Chapter 16, Managing Memory and Data Access and Chapter 15, Optimizing Your Compaq COBOL Program in this manual, and the SYNCHRONIZED clause in the Compaq COBOL Reference Manual for a complete discussion of alignment.) 2.3 Sign Conventions Compaq COBOL numeric items can be signed or unsigned. Note the following sign conventions: • If you store a signed result in an unsigned item, only the absolute value is stored.
Handling Numeric Data 2.4 Invalid Values in Numeric Items both the /CHECK=DECIMAL and the /CONVERT qualifiers on OpenVMS Alpha, the conversion of blanks will be done prior to the validation of the resulting numeric digits. Note that the use of either or both of these qualifiers increases the execution time of the program. See Compaq COBOL online Help (at the OpenVMS Alpha system prompt), or man cobol (on Tru64 UNIX) for more information. 2.
Handling Numeric Data 2.5 Evaluating Numeric Items The length of the literal or arithmetic expression operands (in terms of the number of digits represented) is not significant. Zero is a unique value, regardless of the sign. Unsigned numeric operands are assumed to be positive for comparison. The results of relation tests involving invalid (nonnumeric) data in a numeric item are undefined. 2.5.
Handling Numeric Data 2.5 Evaluating Numeric Items contains an invalid sign value, the NUMERIC class test rejects the item, and program control takes the false path of the IF statement. The ALPHABETIC class test check is not valid for an operand described as numeric. 2.5.4 Success/Failure Tests The success/failure condition tests the return status codes of COBOL and nonCOBOL procedures for success or failure conditions.
Handling Numeric Data 2.6 Using the MOVE Statement 2.6 Using the MOVE Statement The MOVE statement moves the contents of one item into another item. The following sample MOVE statement moves the contents of item FIELD1 into item FIELD2: MOVE FIELD1 TO FIELD2. This section considers MOVE statements as applied to numeric and numeric edited data items. 2.6.1 Elementary Numeric Moves If both items of a MOVE statement are elementary items and the receiving item is numeric, it is an elementary numeric move.
Handling Numeric Data 2.6 Using the MOVE Statement If the sending item has fewer digit positions than the receiving item, the move operation supplies zeros for all unfilled digit positions. 01 TOTAL-AMT PIC 999V99 VALUE ZEROS. . . . MOVE 1 TO TOTAL-AMT. Before execution: 000^00 After execution: 001^00 The following statements produce the same results: MOVE 001.00 TO TOTAL-AMT. MOVE "1" TO TOTAL-AMT.
Handling Numeric Data 2.6 Using the MOVE Statement For a complete description of these symbols see the Compaq COBOL Reference Manual. The numeric-edited move operation first converts the sending item to DISPLAY usage and aligns both items on their decimal point locations. The sending item is truncated or zero-filled until it has the same number of digit positions on both sides of the decimal point as the receiving item.
Handling Numeric Data 2.6 Using the MOVE Statement Table 2–3 (Cont.) Numeric Editing TOTAL-AMT FLD-B -6543^21 1 The PICTURE String Contents After MOVE $,$$$,$$$.99DB $6,543.21DB1 output includes DB if a negative value is moved. The currency symbol ($ or other currency sign) and the editing sign control symbols (+ and –) are the only floating symbols. To float a symbol, enter a string of two or more occurrences of that symbol, one for each character position over which you want the symbol to float.
Handling Numeric Data 2.7 Using the Arithmetic Statements arithmetic operation being performed. Should the temporary work item exceed the maximum size, truncation occurs. The maximum temporary work item size is 31 digits for standard arithmetic and for native CIT4 arithmetic, and is 38 digits for some operations using native float or native CIT3. Programs should not arbitrarily specify sizes significantly larger than the values actually anticipated for the lifetime of the application.
Handling Numeric Data 2.7 Using the Arithmetic Statements The default is /MATH_INTERMEDIATE=FLOAT (or -math_intermediate float). If you specify /ARITHMETIC=STANDARD (discussed in Section 2.7.2.2), this will force /MATH_INTERMEDIATE=CIT4. Example of Different Arithmetic Results The following example illustrates the different results that you can get with FLOAT, CIT3, and CIT4: IDENTIFICATION DIVISION. PROGRAM-ID. MUL31. DATA DIVISION. WORKING-STORAGE SECTION. 01 XD PIC S9(31) VALUE 3.
Handling Numeric Data 2.7 Using the Arithmetic Statements Arithmetic expressions in nonarithmetic statements are also affected. Nonarithmetic statements, such as the IF statement, allow arithmetic expressions to be used, but do not provide a mechanism like the ON SIZE ERROR phrase to detect errors in evaluation. If such an error occurs, the behavior of the statement is unpredictable; in the case of an IF statement, result of the comparison is undefined.
Handling Numeric Data 2.7 Using the Arithmetic Statements Table 2–4 shows several ROUNDING examples. Table 2–4 ROUNDING PICTURE clause Initial Value 03 ITEMA PIC S9(5)V9999. 12345.2222 03 ITEMB PIC S9(5)V99. 54321.11 03 ITEMC PIC S9999. 1234 03 ITEMD PIC S9999P. 0 03 ITEME PIC S99V99 VALUE 9. 9.00 03 ITEMF PIC S99V99 VALUE 24. 24.00 Arithmetic Statement Intermediate Result ROUNDED Result Value ADD ITEMA TO ITEMB ROUNDED. 066666.3322 66666.33 MULTIPLY ITEMC BY 2 GIVING ITEMD ROUNDED.
Handling Numeric Data 2.7 Using the Arithmetic Statements The SIZE ERROR phrase cannot be used with numeric MOVE statements. Thus, if a program moves a numeric quantity to a smaller numeric item, it can lose high-order digits. For example, consider the following move of an item to a smaller item: 01 AMOUNT-A PIC S9(8)V99. 01 AMOUNT-B PIC S9(4)V99. . . . MOVE AMOUNT-A TO AMOUNT-B. This MOVE operation always loses four of AMOUNT-A’s high-order digits.
Handling Numeric Data 2.7 Using the Arithmetic Statements 2. 3. Equivalent coding: ADD ADD ADD ADD ADD ADD ADD A, B, GIVING TEMP. TEMP, C, GIVING TEMP. TEMP, D, GIVING TEMP. TEMP, E, GIVING E. TEMP, F, GIVING F. TEMP, G, GIVING G. TEMP, H, GIVING H. Statement: SUBTRACT A, B, C, FROM D. Equivalent coding: ADD A, B, GIVING TEMP. ADD TEMP, C, GIVING TEMP. SUBTRACT TEMP FROM D, GIVING D. Statement: ADD A,B,C,D, GIVING E. Equivalent coding: ADD A,B, GIVING TEMP. ADD TEMP, C, GIVING TEMP.
3 Handling Nonnumeric Data Nonnumeric data in Compaq COBOL is evaluated with respect to a specified collating sequence of the operands. Information to be found in this chapter: • How the compiler stores nonnumeric data (Section 3.1) • Data organization (Section 3.2) • Special characters (Section 3.3) • Testing nonnumeric items (Section 3.4) • Data movement (Section 3.5) • Using the MOVE statement (Section 3.6) 3.
Handling Nonnumeric Data 3.1 Storage of Nonnumeric Data Sometimes the text refers to alphabetic, alphanumeric, and alphanumeric edited data items as nonnumeric data items to distinguish them from items that are specifically numeric. Regardless of the class of an item, it is usually possible at run time to store an invalid value in the item. Thus, nonnumeric ASCII characters can be placed in an item described as numeric, and an alphabetic item can be loaded with nonalphabetic characters.
Handling Nonnumeric Data 3.2 Data Organization In Compaq COBOL, all records, and elementary items with level 01 or 77, begin at an address that is a multiple of 8 bytes (a quadword boundary). By default, the Compaq COBOL compiler will locate a subordinate data item at the next unassigned byte location. See Chapter 16, Chapter 15, and the SYNCHRONIZED clause in the Compaq COBOL Reference Manual for a complete discussion of alignment. 3.
Handling Nonnumeric Data 3.4 Testing Nonnumeric Items Table 3–1 Relational Operator Descriptions Operator Description IS [NOT] GREATER THAN IS [NOT] > The first operand is greater than (or not greater than) the second operand. IS [NOT] LESS THAN IS [NOT] < The first operand is less than (or not less than) the second operand. IS [NOT] EQUAL TO IS [NOT] = The first operand is equal to (or not equal to) the second operand.
Handling Nonnumeric Data 3.4 Testing Nonnumeric Items ASCII bytes, take part in the comparison, and zeros are not supplied for P characters in the PICTURE character-string. The compiler does not accept a comparison between a noninteger numeric operand and a nonnumeric operand. If you try to compare these two items, you receive a diagnostic message at compile time. 3.4.1.2 Comparison Operations If the two operands are acceptable, the compiler compares them character by character.
Handling Nonnumeric Data 3.4 Testing Nonnumeric Items If the item being tested is described as a numeric data item, it can only be tested as NUMERIC or NOT NUMERIC. The NUMERIC test cannot examine either of the following: • An item described as alphabetic • A group item containing elementary items whose data descriptions indicate the presence of operational signs For further information on using class conditions with numeric items, refer to the Compaq COBOL Reference Manual. 3.
Handling Nonnumeric Data 3.5 Data Movement receiving item must first be described with the JUSTIFIED clause.) Characters from the middle of the sending item cannot easily be moved to any receiving item without extensive redefinitions of the sending item or a reference modification loop (as with concatenation). The STRING and UNSTRING statements handle concatenation and dispersion more easily than compound moves.
Handling Nonnumeric Data 3.6 Using the MOVE Statement Table 3–2 Nonnumeric Elementary Moves Receiving Item Category Sending Item Category Alphanumeric Alphabetic Alphanumeric Edited ALPHABETIC Valid Valid ALPHANUMERIC Valid Valid ALPHANUMERIC EDITED Valid Valid NUMERIC INTEGER (DISPLAY ONLY) Invalid Valid NUMERIC EDITED Invalid Valid In all valid moves, the compiler treats the sending item as though it had been described as PIC X(n).
Handling Nonnumeric Data 3.6 Using the MOVE Statement 3.6.2.1 Edited Moves This section explains the following insertion editing characters: B Blank insertion position 0 Zero insertion position / Slash insertion position When an item with an insertion editing character in its PICTURE characterstring is the receiving item of a nonnumeric elementary MOVE statement, each receiving character position corresponding to an editing character receives the insertion byte value.
Handling Nonnumeric Data 3.6 Using the MOVE Statement Table 3–4 Data Movement with the JUSTIFIED Clause FIELD2 FIELD1 PICTURE Character-String XXX Contents ABC PICTURE Character-String (and JUST-Clause) Contents After MOVE XX AB XXXXX ABCss XX JUST BC XXXXX JUST ssABC Legend: s = space 3.6.3 Multiple Receiving Items If you write a MOVE statement containing more than one receiving item, the compiler moves the same sending item value to each of the receiving items.
Handling Nonnumeric Data 3.6 Using the MOVE Statement In the following example, the compiler evaluates FIELD3(FIELD2) immediately before moving the data into it, but after moving the data from FIELD1 to FIELD2: MOVE FIELD1 TO FIELD2 FIELD3(FIELD2). Thus, it uses the newly stored value of FIELD2 as the subscript value. It is as if the single MOVE statement were replaced with the following two statements: MOVE FIELD1 TO FIELD2. MOVE FIELD1 TO FIELD3(FIELD2). 3.6.
Handling Nonnumeric Data 3.6 Using the MOVE Statement 3.6.7 Using Reference Modification You can use reference modification to define a subset of a data item by specifying its leftmost character position and length. Reference modification is valid anywhere an alphanumeric identifier is allowed unless specific rules for a general format prohibit it. The following is an example of reference modification: WORKING-STORAGE SECTION. 01 ITEMA PIC X(10) VALUE IS "XYZABCDEFG". . . . MOVE ITEMA(4:3) TO...
4 Handling Tables A table is one or more repetitions of one element, composed of one or more data items, stored in contiguous memory locations. In this chapter you will find: • Defining tables (Section 4.1) • Initializing values of table elements (Section 4.2) • Accessing table elements (Section 4.3) 4.1 Defining Tables You define a table by using an OCCURS clause following a data description entry.
Handling Tables 4.1 Defining Tables Example 4–1 One-Dimensional Table 01 TABLE-A. 05 ITEM-B PIC X OCCURS 2 TIMES. The organization of TABLE-A is shown in Figure 4–1. Figure 4–1 Organization of the One-Dimensional Table in Example 4–1 Longword number Byte number 1 1 Level 01 Level 05 2 3 4 A B B Legend: A = TABLE−A B = ITEM−B ZK−6039−GE Example 4–1 specifies only a single data item. However, you can specify as many data items as you need in the table. Multiple data items are shown in Example 4–2.
Handling Tables 4.1 Defining Tables Figure 4–2 Organization of Multiple Data Items in a One-Dimensional Table Longword number Byte number 1 1 2 Level 01 4 A B Level 05 Level 10 3 C Legend: A = TABLE−A B = GROUP−B B D C D C = ITEMC D = ITEMD ZK−6040−GE Example 4–1 and Example 4–2 both do not use the KEY IS or INDEXED BY optional phrases. The INDEXED BY phrase implicitly defines an index name.
Handling Tables 4.1 Defining Tables The organization of this table is shown in Figure 4–3. Figure 4–3 Organization of a Table with an Index and an Ascending Search Key Longword number Byte number 1 2 3 0 0 0 0 0 0 0 0 0 1 1 2 3 4 5 6 7 8 9 0 Level 01 Level 05 Level 10 TABLE−A B B B B B C D C D C D C D C D Legend: B = ELEMENTB C = ITEMC D = ITEMD ZK−6041−GE 4.1.2 Defining Fixed-Length, Multidimensional Tables Compaq COBOL allows 48 levels of OCCURS nesting.
Handling Tables 4.1 Defining Tables Figure 4–4 Organization of a Two-Dimensional Table Longword number Byte number 1 2 1 2 3 4 5 6 7 8 Level 01 2D−TABLE−X Level 05 LY LZ Level 10 Level 15 LY LZ LZ LZ A B A B A B A B Legend: LY = LAYER−Y LZ = LAYER−Z A = CELLA B = CELLB ZK−6042−GE Example 4–5 Defining a Three-Dimensional Table 01 TABLE-A. 05 LAYER-B OCCURS 2 TIMES. 10 ITEMC PIC X. 10 ITEMD PIC X OCCURS 3 TIMES. 10 ITEME OCCURS 2 TIMES. 15 CELLF PIC X. 15 CELLG PIC X OCCURS 3 TIMES.
Handling Tables 4.1 Defining Tables It uses from two to four occurrences depending on the integer value assigned to NUM-ELEM. You specify the table’s minimum and maximum size with the OCCURS (minimum size) TO (maximum size) clause. The minimum size value must be equal to or greater than zero and the maximum size value must be greater than the minimum size value. The DEPENDING ON clause is also required when you use the TO clause.
Handling Tables 4.1 Defining Tables Figure 4–6 shows how the table defined in Example 4–7 is mapped into memory. Example 4–7 Sample Record Description Defining a Table 01 TABLE-A. 03 GROUP-G PIC X(5) OCCURS 5 TIMES.
Handling Tables 4.1 Defining Tables Example 4–8 describes a table containing a COMP SYNC data item. Figure 4–7 illustrates how it is mapped into memory. Example 4–8 Record Description Containing a COMP SYNC Item 01 A-TABLE. 03 GROUP-G OCCURS 4 TIMES. 05 ITEM1 PIC X. 05 ITEM2 PIC S9(5) COMP SYNC.
Handling Tables 4.
Handling Tables 4.2 Initializing Values of Table Elements 4.2 Initializing Values of Table Elements You can initialize a table that contains only DISPLAY items to any desired value in either of the following ways: • You can specify a VALUE clause in the record level preceding the record description of the item containing the OCCURS clause. • You can specify a VALUE clause in a record subordinate to the OCCURS clause.
Handling Tables 4.2 Initializing Values of Table Elements • SECOND-LEG occurs five times; each occurrence is initialized to 5. Often a table is too long to initialize using a single literal, or it contains numeric, alphanumeric, COMP, COMP-1, COMP-2, or COMP SYNC items that cannot be initialized. In these situations, you can initialize individual items by redefining the group level that precedes the level containing the OCCURS clause.
Handling Tables 4.2 Initializing Values of Table Elements Example 4–14 Initializing Alphanumeric Items 01 A-RECORD-ALT. 03 FILLER PIC X(30) VALUE IS "AAAAAAAAAABBBBBBBBBBCCCCCCCCCC". 03 FILLER PIC X(30) VALUE IS "DDDDDDDDDDEEEEEEEEEEFFFFFFFFFF". . . . 01 A-RECORD REDEFINES A-RECORD-ALT. 03 ITEM1 PIC X(10) OCCURS 26 TIMES.
Handling Tables 4.3 Accessing Table Elements 4.3.2 Subscripting with Literals A literal subscript is an integer value, enclosed in parentheses, that represents the desired table element. In Example 4–15, the literal subscript ( 2 ) in the MOVE instruction moves the contents of the second element of A-TABLE to I-RECORD. Example 4–15 Using a Literal Subscript to Access a Table Table Description: 01 A-TABLE. 03 A-GROUP PIC X(5) OCCURS 10 TIMES. Instruction: MOVE A-GROUP(2) TO I-RECORD.
Handling Tables 4.3 Accessing Table Elements Note Because ITEM5 is not subordinate to ITEM2, an occurrence number for ITEM2 is not permitted in the subscript list (when referencing ITEM3, ITEM4, or ITEM5). The ninth occurrence of ITEM2 in the fifth occurrence of A-GROUP will be selected by ITEM2(5,9). Table 4–1 shows the subscripting rules that apply to Example 4–16.
Handling Tables 4.3 Accessing Table Elements You cannot access index items as normal data items; that is, you cannot use them, redefine them, or write them to a file. However, the SET statement can change their values, and relation tests can examine their values. The index integer you specify in the SET statement must be in the range of one to the integer value in the OCCURS clause. The sample MOVE statement shown in Example 4–17 moves the contents of the third element of A-GROUP to I-FIELD.
Handling Tables 4.3 Accessing Table Elements 4.3.6 Index Data Items Often a program requires that the value of an index be stored outside of that item. Compaq COBOL provides the index data item to fulfill this requirement. Index data items are stored as longword COMP items and must be declared with a USAGE IS INDEX phrase in the item description. Index data items can be explicitly modified only with the SET statement. 4.3.
Handling Tables 4.3 Accessing Table Elements 4.3.8.1 Implementing a Sequential Search The SEARCH statement allows you to perform a sequential search of a table. The OCCURS clause of the table description entry must contain the INDEXED BY phrase. If more than one index is specified in the INDEXED BY phrase, the first index is the controlling index for the table search unless you specify otherwise in the SEARCH statement.
Handling Tables 4.3 Accessing Table Elements When you omit the VARYING phrase, the first index you specify in the INDEXED BY phrase becomes the controlling index. Only this index is incremented during a serial search. Example 4–18 and Example 4–23 show how to perform a serial search without using the VARYING phrase. 4.3.8.2 Implementing a Binary Search You can use the SEARCH statement to perform a nonsequential (binary) table search.
Handling Tables 4.3 Accessing Table Elements A useful variation of the binary search is that of specifying multiple search keys. Multiple search keys allow you to select a specified table element from among several elements that have duplicate low-order keys. An example is a telephone listing where several people have the same last and first names, but different middle initials. All specified keys must be either ascending or descending. Example 4–24 shows how to use multiple search keys.
Handling Tables 4.3 Accessing Table Elements Example 4–18 (Cont.) Sample Table - 02 MARRIED-DEDUCTION-DATA. 03 FILLER PIC X(119) VALUE "04800096000000017 "09600173000081620 "17300264000235617 "26400346000390325 "34600433000595328 "43300500000838932 "50000999991053336". 02 MARRIED-DEDUCTION-TABLE REDEFINES MARRIED-DEDUCTION-DATA. 03 MARRIED-TABLE OCCURS 7 TIMES ASCENDING KEY IS M-MIN-RANGE M-MAX-RANGE INDEXED BY IND-0, IND-3. 04 M-MIN-RANGE PIC 99999. 04 M-MAX-RANGE PIC 99999. 04 M-TAX PIC 99999.
Handling Tables 4.3 Accessing Table Elements Example 4–20 Using SEARCH and Varying an Index Other than the First Index 01 TAXABLE-INCOME PIC 9(6) VALUE 50000. 01 FED-TAX-DEDUCTION PIC 9(6). PROCEDURE DIVISION. BEGIN. PERFORM MARRIED. DISPLAY FED-TAX-DEDUCTION. STOP RUN. MARRIED. IF TAXABLE-INCOME < 04800 MOVE ZEROS TO FED-TAX-DEDUCTION GO TO END-FED-COMP. SET IND-3 TO 1.
Handling Tables 4.3 Accessing Table Elements Example 4–22 Using SEARCH and Varying an Index not Associated with the Target Table 01 TAXABLE-INCOME PIC 9(6) VALUE 50000. 01 FED-TAX-DEDUCTION PIC 9(6). PROCEDURE DIVISION. BEGIN. PERFORM SINGLE. DISPLAY FED-TAX-DEDUCTION. STOP RUN. SINGLE. IF TAXABLE-INCOME < 02500 GO TO END-FED-COMP. SET IND-2 TO 1.
Handling Tables 4.3 Accessing Table Elements Example 4–24 shows how to perform a multiple-key, binary search. Example 4–24 A Multiple-Key, Binary Search IDENTIFICATION DIVISION. PROGRAM-ID. MULTI-KEY-SEARCH. DATA DIVISION. WORKING-STORAGE SECTION. 01 DIRECTORY-TABLE. 05 NAMES-NUMBERS. 10 FILLER PIC X(30) VALUE "SMILEY HAPPY T.213-4332". 10 FILLER PIC X(30) VALUE "SMITH ALAN C.881-4987". 10 FILLER PIC X(30) VALUE "SMITH CHARLES J.345-2398". 10 FILLER PIC X(30) VALUE "SMITH FREDERICK 745-0223".
5 Using the STRING, UNSTRING, and INSPECT Statements The STRING, UNSTRING, and INSPECT statements give your Compaq COBOL programs the following capabilities: • Concatenating data using the STRING statement (Section 5.1) • Separating data using the UNSTRING statement (Section 5.2) • Examining and replacing characters using the INSPECT statement (Section 5.3) 5.
Using the STRING, UNSTRING, and INSPECT Statements 5.1 Concatenating Data Using the STRING Statement If FIELD2 is not large enough to hold all three items, the operation stops when it is full. If the operation stops while moving one of the sending items, the compiler ignores the remaining characters of that item and any other sending items not yet processed. For example, if FIELD2 is filled while it is receiving FIELD1B, the compiler ignores the rest of FIELD1B and all of FIELD1C.
Using the STRING, UNSTRING, and INSPECT Statements 5.1 Concatenating Data Using the STRING Statement Figure 5–1 Results of the STRING Operation AYER MA. 01432 16 spaces ZK−6051−GE A more attractive and readable report can be produced by having the STRING operation produce this line: AYER, MA. 01432 To accomplish this, use the figurative constant SPACE as a delimiter on the sending item: MOVE 1 TO P. STRING CITY DELIMITED BY SPACE INTO ADDRESS-LINE WITH POINTER P. STRING ", " STATE ".
Using the STRING, UNSTRING, and INSPECT Statements 5.1 Concatenating Data Using the STRING Statement Remember, the remainder of the receiving item is not space-filled, as with a MOVE statement. If ADDRESS-LINE is to be printed on a mailing label, for example, the STRING statement should be preceded by the statement: MOVE SPACES TO ADDRESS-LINE. This statement guarantees a space-fill to the right of the concatenated result.
Using the STRING, UNSTRING, and INSPECT Statements 5.1 Concatenating Data Using the STRING Statement The ON OVERFLOW phrase cannot distinguish the overflow caused by a bad initial value in the pointer from the overflow caused by a receiving item that is too short. Only a separate test preceding the STRING statement can distinguish between the two. Additionally, even if an overflow condition does not exist, you can use the NOT ON OVERFLOW phrase to branch to or execute other sections of code.
Using the STRING, UNSTRING, and INSPECT Statements 5.1 Concatenating Data Using the STRING Statement 5.1.
Using the STRING, UNSTRING, and INSPECT Statements 5.2 Separating Data Using the UNSTRING Statement The compiler-generated code performs the UNSTRING operation by scanning across FIELD1, the sending item, from left to right. When the number of characters scanned equals the number of characters in the receiving item, the scanned characters are moved into that item and the next group of characters is scanned for the next receiving item.
Using the STRING, UNSTRING, and INSPECT Statements 5.2 Separating Data Using the UNSTRING Statement Consider the following statement with reference to the corresponding PICTURE character-strings and values in Table 5–3: UNSTRING FIELD1 INTO FIELD2A FIELD2B. FIELD2A is a 3-character alphanumeric item. It receives the first three characters of FIELD1 (ABC) in every operation. FIELD2B, however, runs out of characters every time before filling, as Table 5–3 illustrates.
Using the STRING, UNSTRING, and INSPECT Statements 5.
Using the STRING, UNSTRING, and INSPECT Statements 5.2 Separating Data Using the UNSTRING Statement Table 5–5 Results of Delimiting Multiple Receiving Items Values After UNSTRING Operation FIELD1 PIC X(8) VALUE IS: FIELD2A PIC X(3) FIELD2B PIC X(3) ABC*DEF* ABC DEF ABCDE*FG ABC FG# A*B**** A## B## *AB*CD** ### AB# **ABCDEF ### ### A*BCDEFG A## BCD ABC**DEF ABC ### A******B A## ### Legend: # = space The previous examples illustrate the limitations of a single-character delimiter.
Using the STRING, UNSTRING, and INSPECT Statements 5.2 Separating Data Using the UNSTRING Statement the delimiter item. It considers the ALL delimiter to be one, two, three, or more adjacent repetitions of the delimiter item. Table 5–7 shows the results of the following UNSTRING operation using an ALL delimiter: UNSTRING FIELD1 DELIMITED BY ALL "*" INTO FIELD2A FIELD2B.
Using the STRING, UNSTRING, and INSPECT Statements 5.2 Separating Data Using the UNSTRING Statement 5.2.2.1 Multiple Delimiters The UNSTRING statement scans a sending item, searching for a match from a list of delimiters. This list can contain ALL delimiters and delimiters of various sizes. Delimiters in the list must be connected by the word OR. The following sample statement unstrings a sending item into three receiving items.
Using the STRING, UNSTRING, and INSPECT Statements 5.2 Separating Data Using the UNSTRING Statement The compiler then counts the number of characters between the last contiguous asterisk in the first scan and the next asterisk in the second scan, and places the count in COUNT2B. The data between the delimiters of the second scan is moved into FIELD2B. The third scan begins at the first character after the last contiguous asterisk in the second scan.
Using the STRING, UNSTRING, and INSPECT Statements 5.2 Separating Data Using the UNSTRING Statement When a sending string is delimited by the end of the sending item rather than by a match on a delimiter, the delimiter string is of zero length and the DELIMITER item is space-filled. The phrase should be used only where needed. In this example, the character that delimits the last sending string is not needed, so no DELIMITER phrase follows FIELD2C.
Using the STRING, UNSTRING, and INSPECT Statements 5.2 Separating Data Using the UNSTRING Statement PNTR contains the current position of the scanner in the sending item. The second UNSTRING statement uses PNTR to begin scanning the additional sending strings in FIELD1. Because the compiler considers the leftmost character to be character position 1, the value of PNTR can be used to examine the next character.
Using the STRING, UNSTRING, and INSPECT Statements 5.2 Separating Data Using the UNSTRING Statement If the compiler has moved only three sending strings when it reaches the end of FIELD1, it adds 3 to RCOUNT. The first three receiving items (FIELD2A, FIELD2B, and FIELD2C) contain data from the UNSTRING operation, but the last two (FIELD2D and FIELD2E) do not. The UNSTRING statement does not initialize the TALLYING data item.
Using the STRING, UNSTRING, and INSPECT Statements 5.2 Separating Data Using the UNSTRING Statement • Omitting the word INTO (or writing it as TO) before the receiving item list • Repeating the word INTO in the receiving item list as shown in this example: UNSTRING FIELD1 DELIMITED BY SPACE OR TAB INTO FIELD2A DELIMITER IN DELIMA INTO FIELD2B DELIMITER IN DELIMB INTO FIELD2C DELIMITER IN DELIMC.
Using the STRING, UNSTRING, and INSPECT Statements 5.3 Examining and Replacing Characters Using the INSPECT Statement 5.3.2 Restricting Data Inspection Using the BEFORE/AFTER Phrase The BEFORE/AFTER phrase acts as a delimiter and can restrict the area of the item being inspected. The following sample statement counts only the zeros that precede the percent sign ( % ) in FIELD1: INSPECT FIELD1 TALLYING TLY FOR ALL ZEROS BEFORE "%".
Using the STRING, UNSTRING, and INSPECT Statements 5.3 Examining and Replacing Characters Using the INSPECT Statement Figure 5–2 Matching Delimiter Characters to Characters in a Field Instruction FIELD1 Value INSPECT FIELD1...BEFORE "E". INSPECT FIELD1...AFTER "E". ABCDEFGHI ABCDEFGHI INSPECT FIELD1...BEFORE "K". INSPECT FIELD1...AFTER "K". ABCDEFGHI ABCDEFGHI INSPECT FIELD1...BEFORE "AB". INSPECT FIELD1...AFTER "AB". ABCDEFGHI ABCDEFGHI INSPECT FIELD1...BEFORE "HI". INSPECT FIELD1...AFTER "HI".
Using the STRING, UNSTRING, and INSPECT Statements 5.
Using the STRING, UNSTRING, and INSPECT Statements 5.3 Examining and Replacing Characters Using the INSPECT Statement Table 5–10 (Cont.) Values Resulting from Implicit Redefinition Original Value Altered Value Restored Value 5 (65) 5 (65) E (105) 6 (66) 6 (66) F (106) 7 (67) 7 (67) G (107) 8 (70) 8 (70) H (110) 9 (71) 9 (71) I (111) All other values 0 (60) } (173) 5.3.
Using the STRING, UNSTRING, and INSPECT Statements 5.3 Examining and Replacing Characters Using the INSPECT Statement Figure 5–4 Typical REPLACING Phrase INSPECT FIELD1 REPLACING ALL "0" BY "$" Replacing argument ZK−6053−GE Each argument in an argument list used with either a TALLYING or REPLACING operation can have a delimiter item (BEFORE/AFTER phrase) associated with it. If the delimiter item is not present, the argument is applied to the entire item.
Using the STRING, UNSTRING, and INSPECT Statements 5.
Using the STRING, UNSTRING, and INSPECT Statements 5.3 Examining and Replacing Characters Using the INSPECT Statement When an active argument finds a match, the compiler ignores any remaining arguments in the list and conducts the TALLYING or REPLACING operation on the character. The scanner moves to a new position and the next inspection operation begins with the first argument in the list.
Using the STRING, UNSTRING, and INSPECT Statements 5.3 Examining and Replacing Characters Using the INSPECT Statement • An identifier must be an elementary item of DISPLAY usage. It can be any data class. However, if it is not alphanumeric, the compiler performs an implicit redefinition of the item. This redefinition is identical to the BEFORE/AFTER delimiter redefinition discussed in Section 5.3.2.
Using the STRING, UNSTRING, and INSPECT Statements 5.3 Examining and Replacing Characters Using the INSPECT Statement These three tally arguments have the same tally counter, T, and are active over the entire item being inspected. Thus, the preceding statement adds the total number of commas, periods, and semicolons in FIELD1 to the initial value of T.
Using the STRING, UNSTRING, and INSPECT Statements 5.3 Examining and Replacing Characters Using the INSPECT Statement 5.3.5.4 Interference in Tally Argument Lists When several tally arguments contain one or more identical characters active at the same time, they may interfere with each other, so that when one of the arguments finds a match, the scanner steps past any other matching characters, preventing those characters from being considered for a match.
Using the STRING, UNSTRING, and INSPECT Statements 5.3 Examining and Replacing Characters Using the INSPECT Statement Sometimes you can use the interference characteristics of the INSPECT statement to your advantage. Consider the following sample argument list: MOVE 0 TO T4 T3 T2 T1. INSPECT FIELD1 TALLYING T4 FOR ALL "****" T3 FOR ALL "***" T2 FOR ALL "**" T1 FOR ALL "*". The argument list counts all of the asterisks in FIELD1 in four different tally counters.
Using the STRING, UNSTRING, and INSPECT Statements 5.3 Examining and Replacing Characters Using the INSPECT Statement These statements count the number of words in the English statement in FIELD1, assuming that no more than three spaces separate the words in the sentence, that the sentence ends with a period, and that the period immediately follows the last word. When FIELD1 has been scanned, T2 contains the number of spaces between the words.
Using the STRING, UNSTRING, and INSPECT Statements 5.3 Examining and Replacing Characters Using the INSPECT Statement 5.3.6 Using the REPLACING Phrase When an INSPECT statement contains a REPLACING phrase, that statement selectively replaces characters or groups of characters in the designated item. The REPLACING phrase names a search argument of one or more characters and a condition under which the string can be applied to the item being inspected.
Using the STRING, UNSTRING, and INSPECT Statements 5.3 Examining and Replacing Characters Using the INSPECT Statement • LEADING specifies that only adjacent matches of the search argument at the leftmost position of the delimited character-string be replaced. At the first failure to match the search argument, the compiler terminates the replacement operation and causes the argument to become inactive. • FIRST specifies that only the leftmost character string that matches the search argument be replaced.
Using the STRING, UNSTRING, and INSPECT Statements 5.3 Examining and Replacing Characters Using the INSPECT Statement INSPECT FIELD1 REPLACING ALL "," BY SPACE ALL "." BY SPACE ALL ";" BY SPACE. The previous three replacement arguments all have the same replacement value, SPACE, and are active over the entire item being inspected. The statement replaces all commas, periods, and semicolons with space characters and leaves all other characters unchanged. INSPECT FIELD1 REPLACING ALL "0" BY "1" ALL "1" BY "0".
Using the STRING, UNSTRING, and INSPECT Statements 5.3 Examining and Replacing Characters Using the INSPECT Statement The action of a search argument is never affected by the characters of any replacement value, because the scanner does not inspect the replaced characters again during execution of the INSPECT statement. Interference between search arguments, therefore, depends on the order of the arguments, the values of the arguments, and the active/inactive status of the arguments.
6 Processing Files and Records The Compaq COBOL I/O system offers you a wide range of record management techniques while remaining transparent to you. You can select one of several file organizations and access modes, each of which is suited to a particular application. The file organizations available through Compaq COBOL are sequential, line sequential, relative, and indexed. The access modes are sequential, random, and dynamic.
Processing Files and Records 6.1 Defining Files and Records A record is a group of related data elements. The space a record needs on a physical device depends on the file organization, the record format, and the number of bytes the record contains. File organization is described in Section 6.1.1. Record format is described in Section 6.1.2. 6.1.
Processing Files and Records 6.1 Defining Files and Records Table 6–1 (Cont.
Processing Files and Records 6.1 Defining Files and Records Sequential files always contain an end-of-file (EOF) indication. On magnetic tapes, it is the EOF mark; on disk, it is a counter in the file header that designates the end of the file. Compaq COBOL statements can write over the EOF mark and, thus, extend the length of the file.
Processing Files and Records 6.1 Defining Files and Records Figure 6–3 Line Sequential File Organization Beginning of file RECORD 1 RECORD 2 End of file ... RECORD (n−1) RECORD n Record Terminators ZK−6813A−GE Line Sequential File Organization Line sequential file structure is essentially similar to the structure of sequential files, with the major difference being record length. Figure 6–3 illustrates line sequential file organization.
Processing Files and Records 6.1 Defining Files and Records In relative file organization, not every cell must contain a record. Although each cell occupies one record space, a field preceding the record on the storage medium indicates whether or not that cell contains a valid record. Thus, a file can contain fewer records than it has cells, and the empty cells can be anywhere in the file. The numerical order of the cells remains the same during all operations on a relative file.
Processing Files and Records 6.1 Defining Files and Records Indexed file organization allows you to use a key to uniquely identify a record within the file. The location and length of the key are identical in all records. When creating an indexed file, you must select the data items to be the keys.
Processing Files and Records 6.1 Defining Files and Records Figure 6–5 Indexed File Organization Key Definition Primary key index (employee name) ... ABLE JONES record ABLE ... SMITH record ELM AVE ... JONES record MAIN ST ... SMITH COLT RD ZK−6058−GE For a more detailed explanation of indexed file structure on OpenVMS Alpha systems, see the Guide to OpenVMS File Applications. ♦ For information about specifying file organization in your program, see Section 6.2.2. 6.1.
Processing Files and Records 6.1 Defining Files and Records If a file has more than one record description, the different record descriptions automatically share the same record area in memory. The I/O system does not clear this area before it executes the READ statement. Therefore, if the record read by the latest READ statement does not fill the entire record area, the area not overlaid by the incoming record remains unchanged.
Processing Files and Records 6.1 Defining Files and Records Example 6–2 Determining Fixed-Length Record Size FD FIXED-FILE RECORD CONTAINS 100 CHARACTERS. 01 FIXED-REC PIC X(75). Fixed-length record size is determined by either the largest record description or the record size specified by the RECORD CONTAINS clause, whichever is larger. Example 6–2 shows how fixed-length record size is determined.
Processing Files and Records 6.1 Defining Files and Records Example 6–4 Creating Variable-Length Records with the DEPENDING ON Phrase FILE SECTION. FD INFILE. 01 IN-REC. 03 IN-TYPE PIC X. 03 REST-OF-REC PIC X(499). FD OUTFILE RECORD VARYING FROM 200 TO 500 CHARACTERS DEPENDING ON OUT-LENGTH. 01 OUT-REC PIC X(500). WORKING-STORAGE SECTION. 01 OUT-LENGTH PIC 999 COMP VALUE ZEROES. Example 6–5 Creating Variable-Length Records with the RECORD VARYING Phrase FILE SECTION.
Processing Files and Records 6.1 Defining Files and Records If you describe a record with both the RECORD VARYING...DEPENDING ON phrase on data-name-1 and the OCCURS clause with the DEPENDING ON phrase on data-name-2, Compaq COBOL specifies record length as the value of data-name-1.
Processing Files and Records 6.1 Defining Files and Records Stream Stream files contain records of different length, delimited by a record terminator. The compiler generates a stream record formatted file when you use the ORGANIZATION IS LINE SEQUENTIAL clause in the File-Control Division. This record format is useful for files created by text editors. On OpenVMS, a stream file will also be generated under certain situations if you compiled /NOVFC.
Processing Files and Records 6.
Processing Files and Records 6.2 Identifying Files and Records from Within Your Compaq COBOL Program Defining a File Connector with SELECT and ASSIGN Your program must include a SELECT statement, including an ASSIGN clause, for every file description entry (FD) it contains. The file name you specify in the SELECT statement must match the file name in the file description entry. In the ASSIGN clause, you specify a nonnumeric literal or data name that associates the file name with a file specification.
Processing Files and Records 6.2 Identifying Files and Records from Within Your Compaq COBOL Program Example 6–9 Defining a Magnetic Tape File (OpenVMS) ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT MYFILE-PRO ASSIGN TO "MTA0:MARCH.311" . . . DATA DIVISION. FILE SECTION. FD MYFILE-PRO. 01 DAT-RECORD PIC X(100). . . . PROCEDURE DIVISION. A000-BEGIN. OPEN INPUT MYFILE-PRO. . . . READ MYFILE-PRO AT END DISPLAY "end". . . . CLOSE MYFILE-PRO.
Processing Files and Records 6.2 Identifying Files and Records from Within Your Compaq COBOL Program Example 6–10 (Cont.) Defining a Magnetic Tape File (Tru64 UNIX) A000-BEGIN. OPEN INPUT MYFILE-PRO. . . . READ MYFILE-PRO AT END DISPLAY "end". . . . CLOSE MYFILE-PRO. For each OPEN verb referring to a file assigned to magnetic tape, the user is prompted to assign the file to a magnetic tape device. These device names are in the form /dev/rmt0(a,l,m,h) . . .
Processing Files and Records 6.2 Identifying Files and Records from Within Your Compaq COBOL Program On Tru64 UNIX, with this code OPEN would create a file with the name "/usr/filename.dat". ♦ Establishing Device and File Independence with Logical Names On OpenVMS, logical names let you write programs that are device and file independent and provide a brief way to refer to frequently used files. You can assign logical names with the ASSIGN command.
Processing Files and Records 6.2 Identifying Files and Records from Within Your Compaq COBOL Program On Tru64 UNIX, you can also use the literal or alphanumeric item to specify a run-time environment variable set. See setenv(3) in the reference page. ♦ Example 6–11 and the commands that follow it illustrate how to use the ASSIGN TO clause in conjunction with an environment variable. Example 6–11 Using Environment Variables for File Specification IDENTIFICATION DIVISION. PROGRAM-ID. ENVVAR-EXAMPLE.
Processing Files and Records 6.2 Identifying Files and Records from Within Your Compaq COBOL Program PROCEDURE DIVISION. P0. OPEN OUTPUT F-DISK. CLOSE F-DISK. PE. STOP RUN. END PROGRAM ENVVAR-EXAMPLE2. Example 6–12, on OpenVMS Alpha, would produce a file with the name ‘‘ENVTEST.DAT’’. On Tru64 UNIX, ‘‘SYS$SCRATCH:’’ has no meaning because it is a OpenVMS Alpha logical. OpenVMS Alpha logicals are not defined on Tru64 UNIX.
Processing Files and Records 6.2 Identifying Files and Records from Within Your Compaq COBOL Program Examples 6–13, 6–14, and Example 6–15 illustrate how to specify the file organization and access mode for sequential, relative, and indexed files. Example 6–13 Specifying Sequential File Organization and Sequential Access Mode for a Sequential File IDENTIFICATION DIVISION. PROGRAM-ID. SEQ01. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT MASTER-FILE ASSIGN TO "MASTER.DAT".
Processing Files and Records 6.2 Identifying Files and Records from Within Your Compaq COBOL Program Example 6–15 (Cont.) Specifying Indexed File Organization and Dynamic Access Mode for an Indexed File SELECT FLAVORS ASSIGN TO "DAIRY" ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC RECORD KEY IS ICE-CREAM-MASTER-KEY ALTERNATE RECORD KEY IS ICE-CREAM-STORE-STATE WITH DUPLICATES ALTERNATE RECORD KEY IS ICE-CREAM-STORE-CODE. FILE SECTION. FD FLAVORS. 01 ICE-CREAM-MASTER. 02 ICE-CREAM-MASTER-KEY PIC XXXX.
Processing Files and Records 6.2 Identifying Files and Records from Within Your Compaq COBOL Program Record Access Mode The methods for retrieving and storing records in a file are called record access modes. Compaq COBOL supports the following three types of record access modes: • ACCESS MODE IS SEQUENTIAL With sequential files, sequential access mode retrieves the records in the same sequence established by the WRITE statements that created the file.
Processing Files and Records 6.2 Identifying Files and Records from Within Your Compaq COBOL Program Sample SELECT statements for indexed files with dynamic and sequential access modes are shown in Example 6–19. Example 6–19 SELECT Statements for Indexed Files with Dynamic and Default Sequential Access Modes (1) FILE-CONTROL. SELECT A-GROUP ASSIGN TO "RFCBA.PRO" ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC RECORD KEY IS WRITER ALTERNATE RECORD KEY IS EDITOR. (2) FILE-CONTROL.
Processing Files and Records 6.3 Creating and Processing Files Example 6–21 OPEN and CLOSE Statements . . . OPEN INPUT MASTER-FILE. OPEN OUTPUT REPORT-FILE. OPEN I-O MASTER-FILE2 TRANS-FILE OUTPUT REPORT-FILE2. CLOSE MASTER-FILE. CLOSE TRANS-FILE, MASTER-FILE2 REPORT-FILE, REPORT-FILE2. . . .
Processing Files and Records 6.3 Creating and Processing Files 6. If the file characteristics specified by the program attempting an OPEN operation differ from the characteristics specified when the file was created, the OPEN statement fails. If the file is on magnetic tape, the I/O system rewinds the tape. (To close a file on tape without rewinding the tape, use the NO REWIND phrase.
Processing Files and Records 6.3 Creating and Processing Files Example 6–23 Creating a Line Sequential File IDENTIFICATION DIVISION. PROGRAM-ID. LINESEQ01. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT LINESEQ-FILE ASSIGN TO "LINESEQ.DAT". DATA DIVISION. FILE SECTION. FD LINESEQ-FILE. 01 LINESEQ-RECORD PIC X(25). PROCEDURE DIVISION. A000-BEGIN. OPEN OUTPUT LINESEQ-FILE. CLOSE LINESEQ-FILE. STOP RUN.
Processing Files and Records 6.3 Creating and Processing Files • OUTPUT—Output mode can create the following two kinds of files: Storage files—A storage file remains on tape or disk for future reference or processing. Print-control files—The Data Division LINAGE clause, the Environment Division APPLY PRINT-CONTROL clause, the Procedure Division ADVANCING phrase (in the WRITE statement), or Report Writer statements and phrases designates a file as a print-control file.
Processing Files and Records 6.3 Creating and Processing Files ----------------(1)---------------WRITE STOCK-RECORD FROM STOCK-WORK. --------------(2)--------------MOVE STOCK-WORK TO STOCK-RECORD. WRITE STOCK-RECORD. When you omit the FROM phrase, you process the records directly in the record area or buffer (for example, STOCK-RECORD). The following example writes the record PRINT-LINE to the device assigned to that record’s file, then skips three lines.
Processing Files and Records 6.3 Creating and Processing Files Creating a Relative File in Sequential Access Mode When your program creates a relative file in sequential access mode, the I/O system does not use the relative key. Instead, it writes the first record in the file at relative record number 1, the second record at relative record number 2, and so on, until the program closes the file.
Processing Files and Records 6.3 Creating and Processing Files Example 6–25 (Cont.) Creating a Relative File in Random Access Mode IDENTIFICATION DIVISION. PROGRAM-ID. REL03. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT FLAVORS ASSIGN TO "BRAND" ORGANIZATION IS RELATIVE ACCESS MODE IS RANDOM RELATIVE KEY IS KETCHUP-MASTER-KEY. DATA DIVISION. FILE SECTION. FD FLAVORS. 01 KETCHUP-MASTER. 02 FILLER PIC X(14). 02 REC-NUM PIC 9(05). 02 FILLER PIC X(31). WORKING-STORAGE SECTION.
Processing Files and Records 6.
Processing Files and Records 6.3 Creating and Processing Files Example 6–26 Creating and Populating an Indexed File IDENTIFICATION DIVISION. PROGRAM-ID. INDEX02. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INPUT-FILE ASSIGN TO "DAIRYI". SELECT FLAVORS ASSIGN TO "DAIRY" ORGANIZATION IS INDEXED ACCESS MODE IS SEQUENTIAL RECORD KEY IS ICE-CREAM-MASTER-KEY ALTERNATE RECORD KEY IS ICE-CREAM-STORE-STATE WITH DUPLICATES ALTERNATE RECORD KEY IS ICE-CREAM-STORE-CODE. DATA DIVISION. FILE SECTION.
Processing Files and Records 6.3 Creating and Processing Files Table 6–6 lists the valid I/O statements and illustrates the following relationships: • File organization determines valid access modes. • File organization and access mode determine valid open modes. • All three (organization, access, and open mode) enable or disable I/O statements.
Processing Files and Records 6.3 Creating and Processing Files 01 EMPLOYEE. 02 FORENAME 02 BADGE-NO 02 DEPT 02 SURNAME 02 INITIAL PIC PIC PIC PIC PIC X(10). X(6). X(2). X(20). X(1). Then the following line in your program, which specifies the segmented key name and three of its segments: RECORD KEY IS NAME = SURNAME FORENAME INITIAL causes Compaq COBOL to treat name as if it were an explicitly defined group item consisting of the following: 02 SURNAME PIC X(20). 02 FORENAME PIC X(10).
Processing Files and Records 6.3 Creating and Processing Files Example 6–27 (Cont.) Using Segmented Keys DATA DIVISION. FILE SECTION. FD FLAVORS. 01 ICE-CREAM-MASTER. 02 ICE-CREAM-DATA. 03 ICE-CREAM-STORE-KIND PIC XX. 03 ICE-CREAM-STORE-MANAGER PIC X(40). 03 ICE-CREAM-STORE-SIZE PIC XX. 03 ICE-CREAM-STORE-ADDRESS PIC X(20). 03 ICE-CREAM-STORE-CITY PIC X(20). 03 ICE-CREAM-STORE-STATE PIC XX. 03 ICE-CREAM-STORE-ZIP PIC XXXXX. WORKING-STORAGE SECTION. 01 PROGRAM-STAT PIC X. 88 OPERATOR-STOPS-IT VALUE "1".
Processing Files and Records 6.4 Reading Files 6.4 Reading Files Reading sequential, line sequential, relative, and indexed files includes the following tasks: 1. Opening the file 2. Executing a READ or START statement Sections 6.4.1, 6.4.2, and 6.4.3 describe the specific tasks involved in reading sequential, line sequential, relative, and indexed files. 6.4.1 Reading a Sequential or Line Sequential File Reading a sequential or line sequential file involves the following: 1.
Processing Files and Records 6.4 Reading Files Example 6–28 Reading a Sequential File IDENTIFICATION DIVISION. PROGRAM-ID. SEQ02. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT TRANS-FILE ASSIGN TO "TRANS". DATA DIVISION. FILE SECTION. FD TRANS-FILE. 01 TRANSACTION-RECORD PIC X(25). PROCEDURE DIVISION. A000-BEGIN. OPEN INPUT TRANS-FILE. PERFORM A100-READ-TRANS-FILE UNTIL TRANSACTION-RECORD = "END". CLOSE TRANS-FILE. STOP RUN. A100-READ-TRANS-FILE.
Processing Files and Records 6.4 Reading Files Example 6–29 Reading a Relative File Sequentially IDENTIFICATION DIVISION. PROGRAM-ID. REL04. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT FLAVORS ASSIGN TO "BRAND" ORGANIZATION IS RELATIVE ACCESS MODE IS SEQUENTIAL RELATIVE KEY IS KETCHUP-MASTER-KEY. DATA DIVISION. FILE SECTION. FD FLAVORS. 01 KETCHUP-MASTER PIC X(50). WORKING-STORAGE SECTION. 01 KETCHUP-MASTER-KEY PIC 99. 01 END-OF-FILE PIC X. PROCEDURE DIVISION. A000-BEGIN.
Processing Files and Records 6.4 Reading Files Reading a Relative File Randomly Reading relative records randomly involves the following: 1. Specifying ORGANIZATION IS RELATIVE in the Environment Division SELECT clause 2. Specifying ACCESS MODE IS RANDOM (or DYNAMIC) in the Environment Division SELECT clause 3. Opening the file for INPUT or I-O 4. Moving the relative record number value to the RELATIVE KEY data name 5.
Processing Files and Records 6.4 Reading Files available to the program. In dynamic mode, the program can switch from random access I/O statements to sequential access I/O statements in any order, without closing and reopening files. However, you must use the READ NEXT statement to sequentially read a relative file open in dynamic mode. Sequential processing need not begin at the first record of a relative file. The START statement repositions the file position indicator for subsequent I/O operations.
Processing Files and Records 6.4 Reading Files 6.4.3 Reading an Indexed File Your program can read an indexed file sequentially, randomly, or dynamically. Reading an Indexed File Sequentially Reading indexed records sequentially involves the following: 1. Specifying ORGANIZATION IS INDEXED in the Environment Division SELECT clause 2. Specifying ACCESS MODE IS SEQUENTIAL in the Environment Division SELECT clause 3. Opening the file for INPUT or I-O 4.
Processing Files and Records 6.4 Reading Files Example 6–32 (Cont.) Reading an Indexed File Sequentially PROCEDURE DIVISION. A000-BEGIN. OPEN INPUT FLAVORS. A010-SEQUENTIAL-READ. PERFORM A100-READ-INPUT UNTIL END-OF-FILE = "Y". A020-EOJ. DISPLAY "END OF JOB". STOP RUN. A100-READ-INPUT. READ FLAVORS AT END MOVE "Y" TO END-OF-FILE. IF END-OF-FILE NOT = "Y" DISPLAY ICE-CREAM-MASTER STOP "Type CONTINUE to display next master".
Processing Files and Records 6.4 Reading Files Example 6–33 (Cont.) Reading an Indexed File Randomly DATA DIVISION. FILE SECTION. FD FLAVORS. 01 ICE-CREAM-MASTER. 02 ICE-CREAM-KEY PIC XXXX. 02 ICE-CREAM-DATA. 03 ICE-CREAM-STORE-CODE PIC XXXXX. 03 ICE-CREAM-STORE-ADDRESS PIC X(20). 03 ICE-CREAM-STORE-CITY PIC X(20). 03 ICE-CREAM-STORE-STATE PIC XX. WORKING-STORAGE SECTION. 01 PROGRAM-STAT PIC X. 88 OPERATOR-STOPS-IT VALUE "1". PROCEDURE DIVISION. A000-BEGIN. OPEN I-O FLAVORS. PERFORM A020-INITIAL-PROMPT.
Processing Files and Records 6.4 Reading Files Sequential processing need not begin at the first record of an indexed file. The START statement specifies the next record to be read sequentially, selects which key to use to determine the logical sort order, and repositions the file position indicator for subsequent I/O operations anywhere within the file. A sequential read of a dynamic file is indicated by the NEXT phrase of the READ statement.
Processing Files and Records 6.4 Reading Files A100-GET-RECORDS. READ IND-ALPHA NEXT RECORD AT END MOVE "Y" TO END-OF-FILE. IF END-OF-FILE NOT = "Y" DISPLAY INPUT-RECORD. A100-GET-RECORDS-EXIT. EXIT. READ PRIOR retrieves a record from an Indexed file which logically precedes the one which was made current by the previous file access operation, if such a logically previous record exists. READ PRIOR can only be used with a file whose organization is INDEXED and whose access mode is DYNAMIC.
Processing Files and Records 6.4 Reading Files Example 6–35 (Cont.) Reading an Indexed File Dynamically, with READ PRIOR *+ * READ PREVIOUS after file open for IO, from a middle * record to beginning record on primary key. *+ OPEN I-O F. MOVE "2345678990" TO R. READ F INVALID KEY DISPLAY "?6" GO TO P2 END-READ. IF R NOT = "2345678990" THEN DISPLAY "?7 " R. READ F PREVIOUS AT END DISPLAY "?8" GO TO P2 END-READ. IF R NOT = "1234567890" THEN DISPLAY "?9 " R.
Processing Files and Records 6.4 Reading Files Table 6–7 (Cont.) Indexed File—ISAM Mapping COBOL Data Type Maps To Transformation Method signed quadword PIC S9(18) COMP CHARTYPE Reverse the bytes (integers: most significant byte (msb) last; character strings: msb first). If the data type is not _UNSIGNED, then complement the sign bit. This causes negative values to sort correctly with respect to each other, and precede positive values.
Processing Files and Records 6.5 Updating Files Statements ( 1 ) and ( 2 ) in the following example are logically equivalent: FILE SECTION. FD STOCK-FILE. 01 STOCK-RECORD PIC X(80). WORKING-STORAGE SECTION. 01 STOCK-WORK PIC X(80). ---------------(1)-----------------REWRITE STOCK-RECORD FROM STOCK-WORK. --------------(2)-------------MOVE STOCK-WORK TO STOCK-RECORD. REWRITE STOCK-RECORD.
Processing Files and Records 6.5 Updating Files Example 6–37 shows how to extend a sequential file. Example 6–37 Extending a Sequential File IDENTIFICATION DIVISION. PROGRAM-ID. SEQ04. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT TRANS-FILE ASSIGN TO "TRANS". DATA DIVISION. FILE SECTION. FD TRANS-FILE. 01 TRANSACTION-RECORD PIC X(25). PROCEDURE DIVISION. A000-BEGIN. OPEN EXTEND TRANS-FILE. PERFORM A100-WRITE-RECORD UNTIL TRANSACTION-RECORD = "END". CLOSE TRANS-FILE. STOP RUN.
Processing Files and Records 6.5 Updating Files 4. Using a START statement and then a READ statement to read the target record 5. Updating the record 6. Rewriting the record into its cell Example 6–38 reads a relative record sequentially and displays the record on the terminal. The program then passes the record to an update routine that is not included in the example.
Processing Files and Records 6.5 Updating Files Rewriting Relative Records in Random Access Mode Rewriting relative records in random access mode involves the following: 1. Specifying ORGANIZATION IS RELATIVE in the Environment Division SELECT clause 2. Specifying ACCESS MODE IS RANDOM (or DYNAMIC) in the Environment Division SELECT clause 3. Opening the file for I-O 4. Moving the relative record number value of the record you want to read to the RELATIVE KEY data name 5.
Processing Files and Records 6.5 Updating Files Example 6–39 (Cont.) Rewriting Relative Records in Random Access Mode A100-UPDATE-RECORD. DISPLAY "TO UPDATE A RECORD ENTER ITS RECORD NUMBER". ACCEPT KETCHUP-MASTER-KEY. READ FLAVORS INVALID KEY DISPLAY "BAD READ" GO TO A005-EOJ. DISPLAY "*********BEFORE UPDATE*********". DISPLAY KETCHUP-MASTER.
Processing Files and Records 6.5 Updating Files Example 6–40 (Cont.) Deleting Relative Records in Sequential Access Mode ACCESS MODE IS SEQUENTIAL RELATIVE KEY IS KETCHUP-MASTER-KEY. DATA DIVISION. FILE SECTION. FD FLAVORS. 01 KETCHUP-MASTER PIC X(50). WORKING-STORAGE SECTION. 01 KETCHUP-MASTER-KEY PIC 99 VALUE 1. PROCEDURE DIVISION. A000-BEGIN. OPEN I-O FLAVORS. PERFORM A010-DELETE-RECORDS UNTIL KETCHUP-MASTER-KEY = 00. A005-EOJ. DISPLAY "END OF JOB". CLOSE FLAVORS. STOP RUN. A010-DELETE-RECORDS.
Processing Files and Records 6.5 Updating Files Example 6–41 (Cont.) Deleting Relative Records in Random Access Mode ACCESS MODE IS RANDOM RELATIVE KEY IS KETCHUP-MASTER-KEY. DATA DIVISION. FILE SECTION. FD FLAVORS. 01 KETCHUP-MASTER PIC X(50). WORKING-STORAGE SECTION. 01 KETCHUP-MASTER-KEY PIC 99 VALUE 1. PROCEDURE DIVISION. A000-BEGIN. OPEN I-O FLAVORS. PERFORM A010-DELETE-RECORDS UNTIL KETCHUP-MASTER-KEY = 00. A005-EOJ. DISPLAY "END OF JOB". CLOSE FLAVORS. STOP RUN. A010-DELETE-RECORDS.
Processing Files and Records 6.5 Updating Files Updating an Indexed File Sequentially Updating indexed records in sequential acess mode involves the following: 1. Specifying ORGANIZATION IS INDEXED in the Environment Division SELECT clause 2. Specifying ACCESS MODE IS SEQUENTIAL in Environment Division SELECT clause 3. Opening the file for I-O 4. Reading records as you would a sequential file (use the READ statement with the AT END phrase) 5.
Processing Files and Records 6.5 Updating Files Example 6–42 (Cont.) Updating an Indexed File Sequentially PROCEDURE DIVISION. A000-BEGIN. OPEN I-O FLAVORS. DISPLAY "Which store code do you want to find?". ACCEPT REWRITE-KEY. DISPLAY "What is its new address?". ACCEPT NEW-ADDRESS. DISPLAY "Which state do you want to delete?". ACCEPT DELETE-KEY. PERFORM A100-READ-INPUT UNTIL END-OF-FILE = "Y". A020-EOJ. DISPLAY "END OF JOB". STOP RUN. A100-READ-INPUT. READ FLAVORS AT END MOVE "Y" TO END-OF-FILE.
Processing Files and Records 6.5 Updating Files Example 6–43 (Cont.) Updating an Indexed File Randomly FILE-CONTROL. SELECT FLAVORS ASSIGN TO "DAIRY" ORGANIZATION IS INDEXED ACCESS MODE IS RANDOM RECORD KEY IS ICE-CREAM-MASTER-KEY ALTERNATE RECORD KEY IS ICE-CREAM-STORE-STATE WITH DUPLICATES ALTERNATE RECORD KEY IS ICE-CREAM-STORE-CODE. DATA DIVISION. FILE SECTION. FD FLAVORS. 01 ICE-CREAM-MASTER. 02 ICE-CREAM-MASTER-KEY PIC XXXX. 02 ICE-CREAM-MASTER-DATA. 03 ICE-CREAM-STORE-CODE PIC XXXXX.
Processing Files and Records 6.5 Updating Files Example 6–43 (Cont.) Updating an Indexed File Randomly IF LETS-SEE-NEXT-STORE AND ICE-CREAM-STORE-STATE = "NY" PERFORM A500-DELETE-RANDOM-RECORD. IF LETS-SEE-NEXT-STORE AND ICE-CREAM-STORE-STATE = "NJ" MOVE "Monmouth" TO ICE-CREAM-STORE-CITY PERFORM A400-REWRITE-RANDOM-RECORD.
Processing Files and Records 6.6 Backing Up Your Files 6.6 Backing Up Your Files Files can become unusable if either of the following situations occur: • Your disk file becomes corrupted by a hardware error. • Your disk file becomes corrupted with bad data. Proper backup procedures are the key to successful recovery.
7 Handling Input/Output Exception Conditions Many types of exception conditions can occur when a program processes a file; not all of them are errors. The three categories of exception conditions are as follows: • AT END condition—This is a normal condition when you access a file sequentially.
Handling Input/Output Exception Conditions 7.1 Planning for the AT END Condition 7.1 Planning for the AT END Condition Compaq COBOL provides you the option of testing for this condition with the AT END phrase of the READ statement (for sequential, relative, and indexed files) and the AT END phrase of the ACCEPT statement. Programs often read sequential files from beginning to end. They can produce reports from the information in the file or even update it.
Handling Input/Output Exception Conditions 7.2 Planning for the Invalid Key Condition in the file, or when you receive the AT END condition for a subsequent read operation, indicating that no more records exist in the file. Example 7–2 Handling the Invalid Key Condition . . . MOVE "SMITH" TO LAST-NAME TEST-LAST-NAME. MOVE "Y" TO ANY-MORE-DUPLICATES. PERFORM A500-READ-DUPLICATES UNTIL ANY-MORE-DUPLICATES = "N". . . . STOP RUN. A500-READ-DUPLICATES.
Handling Input/Output Exception Conditions 7.3 Using File Status Values and OpenVMS RMS Completion Codes Example 7–3 Defining a File Status for a File DATA DIVISION. FILE SECTION. FD INDEXED-FILE FILE STATUS IS INDEXED-FILE-STATUS. 01 INDEXED-RECORD PIC X(50). WORKING-STORAGE SECTION. 01 INDEXED-FILE-STATUS PIC XX. 01 ANSWER PIC X. 7.3.
Handling Input/Output Exception Conditions 7.3 Using File Status Values and OpenVMS RMS Completion Codes Example 7–4 (Cont.) Using the File Status Value in an Exception Handling Routine REWRITE INDEXED-RECORD INVALID KEY MOVE "Bad REWRITE" TO BAD-VERB-ID PERFORM A900-EXCEPTION-HANDLING-ROUTINE. . . . START INDEXED-FILE INVALID KEY MOVE "Bad START" TO BAD-VERB-ID PERFORM A900-EXCEPTION-HANDLING-ROUTINE. . . .
Handling Input/Output Exception Conditions 7.3 Using File Status Values and OpenVMS RMS Completion Codes These special registers supplement the file status values already available and allow the Compaq COBOL program to directly access RMS completion codes. For more information on RMS completion codes, refer to the Compaq COBOL Reference Manual and the OpenVMS Record Management Services Reference Manual. You do not define these special registers in your program.
Handling Input/Output Exception Conditions 7.3 Using File Status Values and OpenVMS RMS Completion Codes Example 7–5 (Cont.) Referencing RMS-STS, RMS-STV, RMS-CURRENT-STS, and RMS-CURRENT-STV Codes (OpenVMS) PROCEDURE DIVISION. A000-BEGIN. . . WRITE RECORD-1 INVALID KEY PERFORM A901-REPORT-FILE1-STATUS. * * The following PERFORM statement displays the RMS completion * codes resulting from the above WRITE statement for FILE-1. * PERFORM A903-REPORT-RMS-CURRENT-STATUS. . . .
Handling Input/Output Exception Conditions 7.3 Using File Status Values and OpenVMS RMS Completion Codes Example 7–5 (Cont.) Referencing RMS-STS, RMS-STV, RMS-CURRENT-STS, and RMS-CURRENT-STV Codes (OpenVMS) A903-REPORT-RMS-CURRENT-STATUS. ******************************************* * DISPLAY "RMS-CURRENT-STS = " RMS-CURRENT-STS WITH CONVERSION. DISPLAY "RMS-CURRENT-STV = " RMS-CURRENT-STV WITH CONVERSION. DISPLAY "RMS-CURRENT-FILENAME = " RMS-CURRENT-FILENAME.
Handling Input/Output Exception Conditions 7.4 Using Declarative USE Procedures Example 7–6 The Declaratives Skeleton PROCEDURE DIVISION. DECLARATIVES. . . . END DECLARATIVES. MAIN-BODY SECTION. BEGIN. . . . As shown in Example 7–7, a Declarative procedure consists of a section header, followed, in order, by a USE statement and one or more paragraphs. Example 7–7 A Declarative USE Procedure Skeleton . . . PROCEDURE DIVISION. DECLARATIVES. D0-00-FILE-A-PROBLEM SECTION.
Handling Input/Output Exception Conditions 7.4 Using Declarative USE Procedures • INPUT—You can define only one INPUT Declarative USE procedure for each program. This procedure executes for any unsuccessful exception condition if: ( 1 ) the file is open for INPUT and ( 2 ) a file name Declarative USE procedure does not exist for that file. • OUTPUT—You can define only one OUTPUT Declarative USE procedure for each program.
Handling Input/Output Exception Conditions 7.4 Using Declarative USE Procedures Example 7–8 (Cont.) Five Types of Declarative USE Procedures ******************************************************** D2-00-FILE-INPUT-PROBLEM SECTION. USE AFTER STANDARD EXCEPTION PROCEDURE ON INPUT. * * * If an error occurs for any file open * in the INPUT mode except FILE-A, * D2-00-FILE-INPUT-PROBLEM executes. * * D2-01-FILE-INPUT-PROBLEM. PERFORM D9-00-REPORT-FILE-STATUS. . . .
Handling Input/Output Exception Conditions 7.4 Using Declarative USE Procedures Example 7–8 (Cont.) Five Types of Declarative USE Procedures ******************************************************** D5-00-FILE-EXTEND-PROBLEM SECTION. USE AFTER STANDARD EXCEPTION PROCEDURE ON EXTEND. * * * If an error occurs for any file open * in the EXTEND mode except FILE-A, * D5-00-FILE-EXTEND-PROBLEM executes. * * D5-01-FILE-EXTEND-PROBLEM. PERFORM D9-00-REPORT-FILE-STATUS. . . . D9-00-REPORT-FILE-STATUS. . . .
8 Sharing Files and Locking Records This chapter includes the following information about sharing files and protecting records for sequential, relative, and indexed files: • Controlling access to files and records (Section 8.1) • Choosing X/Open standard or Compaq standard file sharing and record locking (Section 8.2) • Ensuring successful file sharing (Section 8.3) • Using record locking to control access to records (Section 8.4) 8.
Sharing Files and Locking Records 8.1 Controlling Access to Files and Records File sharing and record locking allow you to control file and record operations when more than one access stream (the series of file and record operations being performed by a single user, using a single file connector) is concurrently accessing a file, as in Figure 8–1. A Compaq COBOL program, via the I/O system, can define one or more access streams. You create one access stream with each OPEN file-name statement.
Sharing Files and Locking Records 8.1 Controlling Access to Files and Records WRITE REWRITE DELETE UNLOCK 8.
Sharing Files and Locking Records 8.2 Choosing X/Open Standard or Compaq Standard File Sharing and Record Locking • The /STANDARD=[NO]XOPEN qualifier on the COBOL command for the OpenVMS Alpha operating system If you do not specify the flag or qualifier, the default is noxopen (Compaq standard) file sharing and record locking.
Sharing Files and Locking Records 8.3 Ensuring Successful File Sharing In the OpenVMS Alpha file protection facility, four different categories of users exist with respect to data structures and devices.
Sharing Files and Locking Records 8.3 Ensuring Successful File Sharing 8.3.3 Determining the Intended Access Mode to a File Once you establish disk residency and permission for a file, you can consider how the stream intends to access the file. You specify this intention by using the Compaq COBOL open and access modes. The Compaq COBOL open modes are INPUT, OUTPUT, EXTEND, and I-O. The Compaq COBOL access modes are SEQUENTIAL, RANDOM, and DYNAMIC.
Sharing Files and Locking Records 8.3 Ensuring Successful File Sharing LOCK MODE IS EXCLUSIVE You can also select X/Open file sharing by just specifying WITH LOCK on the OPEN or READ statements. However, it is recommended that you use the LOCK MODE clause to avoid ambiguity and maintain readability. If this is not done and any I-O verbs rely on default behavior that might result in ambiguity, you should compile your program with the X/Open option added to the compile command line.
Sharing Files and Locking Records 8.3 Ensuring Successful File Sharing Example 8–1 (Cont.) X/Open Standard Lock Modes and Opening Files PROCEDURE-DIVISION. BEGIN. * The file is shareable per LOCK MODE specification: OPEN I-O employee-file. * The file is exclusive during this access stream, overriding the * LOCK MODE specification: OPEN I-O master-file WITH LOCK. * The file is exclusive per LOCK MODE; others cannot access it: OPEN INPUT tran-file.
Sharing Files and Locking Records 8.3 Ensuring Successful File Sharing If the mode is INPUT (reader), access to the file is granted instead of denied when a previous updater stream has specified full (ALL/UPDATERS/WRITERS) or partial (READERS) sharing of the file. If the mode is I-O, access is denied as expected. ♦ • OPEN ALLOWING WRITERS or UPDATERS or ALL—Allows access by other streams. Other access streams can open the file in INPUT, EXTEND, and I-O modes.
Sharing Files and Locking Records 8.3 Ensuring Successful File Sharing a file is shared. Note that some streams can be locked out if their intentions are not compatible with those of the streams that have already been allowed entry to the file. On OpenVMS, Table 8–1 shows the valid and invalid OPEN ALLOWING combinations between first and subsequent access streams. (The subsequent table is the equivalent for Tru64 UNIX systems.) The table assumes no file protection violations on the first stream.
Sharing Files and Locking Records 8.3 Ensuring Successful File Sharing Legend 3 Second stream is denied access to the file because the first stream intends to write, while the second stream specifies read-only sharing. 4 Second stream is denied access to the file because the second stream intends to write, while the first stream specifies read-only sharing. 5 No sharing; second will create new file version with OPEN OUTPUT.
Sharing Files and Locking Records 8.3 Ensuring Successful File Sharing Legend 6 For indexed files, when the first stream allows READERS, file lock does not exclude updaters allowing sharing. For files other than indexed, 4 applies. 7 For indexed files, the second stream is granted access but cannot update the file. For files other than indexed, 4 applies.
Sharing Files and Locking Records 8.3 Ensuring Successful File Sharing File Status 91 indicates that a previous access stream has denied access to the file. That previous access stream opened the file with locking attributes which conflict with the OPEN statement of the subsequent stream. You can obtain the values that apply to file-sharing exceptions (or to successful file-sharing operations), as shown in Example 8–2. Example 8–2 Program Segment for File Status Values FILE-CONTROL.
Sharing Files and Locking Records 8.3 Ensuring Successful File Sharing Example 8–2 (Cont.) Program Segment for File Status Values * handle other possible errors here . . . RETRY-OPEN. OPEN I-O FILE-NAME. add 1 to RETRY-COUNT. On OpenVMS, Table 8–4 describes RMS-STS values used in a file-sharing environment.
Sharing Files and Locking Records 8.3 Ensuring Successful File Sharing You can obtain the values that apply to file-sharing exceptions (or to successful file-sharing operations) by using the VALUE IS EXTERNAL clause, as shown in Example 8–3: Example 8–3 Program Segment for RMS-STS Values (OpenVMS) WORKING-STORAGE SECTION. 01 RMS-SUC PIC S9(9) COMP VALUE IS EXTERNAL RMS$_SUC. 01 RMS-FLK PIC S9(9) COMP VALUE IS EXTERNAL RMS$_FLK. . . . PROCEDURE DIVISION. DECLARATIVES. FILE-1-ERR SECTION.
Sharing Files and Locking Records 8.3 Ensuring Successful File Sharing Figure 8–3 Why a Record-Already-Exists Error Occurs FILE A Record 1 Record 2 Record 3 Record 4 Access Stream 1 End−of−File Access Stream 2 Record 5/6 ZK−6060−GE When access stream 2 writes to the file, it also tries to write the fifth record. Record 5 already exists (inserted by the first stream), and the second access stream gets a record-exists error.
Sharing Files and Locking Records 8.4 Ensuring Successful Record Locking 8.4.1 X/Open Standard Record Locking This section describes the X/Open standard method of specifying automatic or manual record locking. Specifying Automatic Record Locking (X/Open Standard) You specify X/Open standard automatic record locking in the Environment Division by using LOCK MODE IS AUTOMATIC [WITH LOCK ON RECORD] on the SELECT statement. (The optional WITH LOCK ON RECORD clause has no effect and is for documentation only.
Sharing Files and Locking Records 8.4 Ensuring Successful Record Locking Example 8–4 X/Open Standard Record Locking User 1 (Automatic Record Locking): --------------------------------FILE-CONTROL. SELECT FILE-1 ORGANIZATION IS RELATIVE ASSIGN TO "SHAREDAT.DAT" LOCK MODE AUTOMATIC. . . . PROCEDURE DIVISION. BEGIN. OPEN I-O FILE-1. READ FILE-1. . . . REWRITE FILE-1-REC. CLOSE FILE-1. STOP RUN.
Sharing Files and Locking Records 8.4 Ensuring Successful Record Locking You deaccess a record by using the next READ operation, a REWRITE or a DELETE operation on the record, or by closing the file. In addition, you can release locks applied by automatic record locking by using the UNLOCK statement. In automatic record-locking mode, you can release the current record lock by using an UNLOCK RECORD statement or an UNLOCK ALL RECORDS statement.
Sharing Files and Locking Records 8.
Sharing Files and Locking Records 8.4 Ensuring Successful Record Locking Table 8–5 (Cont.) Manual Record Locking Combinations Lock Held (for first stream) I-O Attempt (for subsequent stream) WRITE Updaters Readers No Others Allowing Readers Y Y N Allowing no others Y Y N Allowing no others N/A N/A N/A Legend: Y = Subsequent stream executes successful I-O operation N = Subsequent stream I-O operation is unsuccessful (File Status 92) Example 8–6 uses manual record locking.
Sharing Files and Locking Records 8.4 Ensuring Successful Record Locking stream on the file (UNLOCK ALL RECORDS). (On Tru64 UNIX and Windows NT systems for indexed files only, there is no current record lock.
Sharing Files and Locking Records 8.4 Ensuring Successful Record Locking When you close a file, any existing record lock is released automatically. The UNLOCK RECORD statement releases the lock only on the current record on OpenVMS Alpha systems, which is the last record you successfully accessed. On Tru64 UNIX systems for indexed files only, there is no current record lock. 8.4.
Sharing Files and Locking Records 8.4 Ensuring Successful Record Locking Soft Record Locks Soft record locks can occur only with Compaq standard record locking. A soft record lock condition, which causes the file status variable to be set to 90, indicates that the record operation was successful, the record was transferred to the buffer, and a prior access stream holds a lock on that record. A soft record lock can be detected by a USE procedure.
Sharing Files and Locking Records 8.4 Ensuring Successful Record Locking Soft Record Locks and Declarative USE Procedures If a soft record lock occurs, the values of the following variables for the current file are undefined until the execution of any applicable Declarative USE procedure is complete: • Record buffer • RELATIVE KEY • DEPENDING ON These variables remain undefined if the Declarative USE procedure terminates with an EXIT PROGRAM statement.
Sharing Files and Locking Records 8.4 Ensuring Successful Record Locking Example 8–7 (Cont.) Program Segment for Record-Locking Exceptions IF record-locked continue ELSE . . . END-IF. END DECLARATIVES. MAIN-BODY SECTION. BEGIN. DISPLAY "From main-body". . . . GET-RECORD. READ file-name. IF NOT record-ok PERFORM check-read. . . . CHECK-READ.
9 Using the SORT and MERGE Statements This chapter includes the following information about using the SORT and MERGE statements to sort and merge records for sequential, line sequential, relative, and indexed files: • Sorting data with the SORT statement (Section 9.1) • Merging data with the MERGE statement (Section 9.2) • Sample programs using the SORT and MERGE statements (Section 9.3) 9.
Using the SORT and MERGE Statements 9.1 Sorting Data with the SORT Statement Sorting Concepts Records are sorted based on the data values in the sort keys. Sort keys identify the location of a record or the ordering of data. The following example depicts unsorted employee name and address records used for creating mailing labels: Smith, Joe 234 Ash St. New Boston NH 04356 Jones, Bill 12 Birch St. Gardner MA 01430 Baker, Tom 78 Oak St. Ayer MA 01510 Thomas, Pete 555 Maple St.
Using the SORT and MERGE Statements 9.1 Sorting Data with the SORT Statement 9.1.2 Specifying Sort Parameters with the ASCENDING and DESCENDING KEY Phrases Use the Data Division ASCENDING and DESCENDING KEY phrases to specify your sort parameters. The order of data names determines the sort hierarchy; that is, the major sort key is the first data name entered, while the minor sort key is the last data name entered. In the following example, the hierarchy of the sort is SORT-KEY-1, SORT-KEY-2, SORT-KEY-3.
Using the SORT and MERGE Statements 9.1 Sorting Data with the SORT Statement RETURN statement to transfer records from the sort. For example, you can use the RETURN statement to retrieve the sorted records for printing a report. Example 9–1 shows a sample sort using the INPUT and OUTPUT procedures. Example 9–1 INPUT and OUTPUT PROCEDURE Phrases IDENTIFICATION DIVISION. PROGRAM-ID. EX0901. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INPUT-FILE ASSIGN TO "input.dat".
Using the SORT and MERGE Statements 9.1 Sorting Data with the SORT Statement Example 9–1 (Cont.) INPUT and OUTPUT PROCEDURE Phrases *********************************************************** * You can add, change, or delete records before sorting * * using COBOL data manipulation * * techniques. * *********************************************************** RELEASE SORT-RECORD. GO TO 070-READ-INPUT. 100-DONE-INPUT SECTION. 110-EXIT-INPUT. EXIT. 200-WRITE-OUTPUT SECTION. 210-OPEN-OUTPUT.
Using the SORT and MERGE Statements 9.1 Sorting Data with the SORT Statement Example 9–2 USING Phrase Replaces INPUT PROCEDURE Phrase . . . PROCEDURE DIVISION. 000-SORT SECTION. 010-DO-THE-SORT. SORT SORT-FILE ON ASCENDING KEY SORT-KEY-1 ON DESCENDING KEY SORT-KEY-2 USING INPUT-FILE OUTPUT PROCEDURE IS 200-WRITE-OUTPUT THRU 230-DONE-OUTPUT. DISPLAY "END OF SORT". STOP RUN. 200-WRITE-OUTPUT SECTION. 210-OPEN-OUTPUT. OPEN OUTPUT OUTPUT-FILE. 220-GET-SORTED-RECORDS.
Using the SORT and MERGE Statements 9.1 Sorting Data with the SORT Statement In contrast, the WITH DUPLICATES IN ORDER phrase guarantees that records with duplicate sort keys remain in the same sequence as they were in the input file. 9.1.6 Specifying Non-ASCII Collating Sequences with the COLLATING SEQUENCE IS Alphabet-Name Phrase This phrase lets you specify a collating sequence other than the ASCII default. You define collating sequences in the Environment Division SPECIAL-NAMES paragraph.
Using the SORT and MERGE Statements 9.1 Sorting Data with the SORT Statement Example 9–4 (Cont.) Using Two Sort Files 01 SORT-REC-2. 03 FILLER PIC X(20). 03 S2-KEY-1 PIC X(10). 03 FILLER PIC X(10). 03 S2-KEY-2 PIC X(10). 03 FILLER PIC X(50). . . . PROCEDURE DIVISION. 000-SORT SECTION. 010-DO-FIRST-SORT. SORT SORT-FILE1 ON ASCENDING KEY S1-KEY-1 S1-KEY-2 WITH DUPLICATES IN ORDER USING INPUT-FILE OUTPUT PROCEDURE IS 050-CREATE-REPORT-1 THRU 300-DONE-REPORT-1. 020-DO-SECOND-REPORT.
Using the SORT and MERGE Statements 9.1 Sorting Data with the SORT Statement If you specify the GIVING phrase and the output file contains variable-length records, the sort-file record must not be smaller than the smallest record, nor larger than the largest record, described in the output file. 9.1.9 Preventing I/O Aborts All I/O errors detected during a sort can cause abnormal program termination.
Using the SORT and MERGE Statements 9.1 Sorting Data with the SORT Statement If you select Hypersort at DCL level, it will be in effect for a SORT statement within a COBOL program as well. ♦ Hypersort is the sole method available on Tru64 UNIX and Windows NT Alpha. See Appendix A for the record and key size limits with Sort-32 and Hypersort. 9.
Using the SORT and MERGE Statements 9.3 Sample Programs Using the SORT and MERGE Statements Example 9–7 Sorting a File with the USING and GIVING Phrases IDENTIFICATION DIVISION. PROGRAM-ID. SORTA. ************************************************* * This program shows how to sort * * a file with the USING and GIVING phrases * * of the SORT statement. The fields to be * * sorted are S-KEY-1 and S-KEY-2; they * * contain account numbers and amounts. The * * sort sequence is amount within account * * number.
Using the SORT and MERGE Statements 9.3 Sample Programs Using the SORT and MERGE Statements Example 9–8 Using the USING and OUTPUT PROCEDURE Phrases IDENTIFICATION DIVISION. PROGRAM-ID. SORTB. ************************************************************** * This program shows how to sort a file * * with the USING and OUTPUT PROCEDURE phrases * * of the SORT statement. The program eliminates * * duplicate records by adding their amounts to the * * amount in the first record with the same account * * number.
Using the SORT and MERGE Statements 9.3 Sample Programs Using the SORT and MERGE Statements Example 9–8 (Cont.) Using the USING and OUTPUT PROCEDURE Phrases USING INPUT-FILE OUTPUT PROCEDURE IS 300-CREATE-OUTPUT-FILE THRU 600-DONE-CREATE. ************************************************************ * At this point, you could transfer control to another * * section of the program and continue processing. * ************************************************************ DISPLAY "END OF PROGRAM SORTB". STOP RUN.
Using the SORT and MERGE Statements 9.3 Sample Programs Using the SORT and MERGE Statements Example 9–9 Using the INPUT PROCEDURE and OUTPUT PROCEDURE Phrases IDENTIFICATION DIVISION. PROGRAM-ID. SORTC. ********************************************************* * This program shows how to use the INPUT * * PROCEDURE and OUTPUT PROCEDURE phrases of the * * SORT statement. Input to the sort is two files * * containing the same type of data. Records with * * a "D" status-code are not released to the sort.
Using the SORT and MERGE Statements 9.3 Sample Programs Using the SORT and MERGE Statements Example 9–9 (Cont.) Using the INPUT PROCEDURE and OUTPUT PROCEDURE Phrases PROCEDURE DIVISION. 000-START SECTION. 005-DO-THE-SORT. SORT SORT-FILE ON ASCENDING KEY S-KEY-1 S-KEY-2 INPUT PROCEDURE IS 010-GET-INPUT THRU 200-DONE-INPUT-GET OUTPUT PROCEDURE IS 300-CREATE-OUTPUT-FILE THRU 600-DONE-CREATE.
Using the SORT and MERGE Statements 9.3 Sample Programs Using the SORT and MERGE Statements Example 9–9 (Cont.) Using the INPUT PROCEDURE and OUTPUT PROCEDURE Phrases MOVE "N" TO INITIAL-SORT-READ GO TO 400-READ-SORT-FILE. 450-COMPARE-ACCOUNT-NUM. IF S-ACCOUNT-NUM = SR-ACCOUNT-NUM ADD S-AMOUNT TO SR-AMOUNT GO TO 400-READ-SORT-FILE. 500-WRITE-THE-OUTPUT. MOVE SAVE-SORT-REC TO OUT-REC. WRITE OUT-REC. ADD 1 TO OUTPUT-COUNT. 550-GET-A-REC. MOVE SORT-REC TO SAVE-SORT-REC. GO TO 400-READ-SORT-FILE.
Using the SORT and MERGE Statements 9.3 Sample Programs Using the SORT and MERGE Statements Example 9–10 (Cont.) Using the COLLATING SEQUENCE IS Phrase FD INPUT-FILE LABEL RECORDS ARE STANDARD. 01 IN-REC PIC X(30). FD OUTPUT-FILE LABEL RECORDS ARE STANDARD. 01 OUT-REC PIC X(30). PROCEDURE DIVISION. 000-DO-THE-SORT. SORT SORT-FILE ON ASCENDING KEY S-KEY-1 S-KEY-2 COLLATING SEQUENCE IS MYSEQUENCE USING INPUT-FILE GIVING OUTPUT-FILE.
Using the SORT and MERGE Statements 9.3 Sample Programs Using the SORT and MERGE Statements Example 9–11 (Cont.) Creating a New Sort Key 03 INCOME-FOURTH-QUARTER PIC 9(5)V99. 03 ORDER-COUNT PIC 9(2). 03 ORDERS OCCURS 1 TO 7 TIMES DEPENDING ON ORDER-COUNT. 05 ORDER-DATE PIC 9(6). 05 FILLER PIC X(59). SD SORT-FILE RECORD VARYING FROM 106 TO 496 CHARACTERS DEPENDING ON SORT-LENGTH. 01 SORT-REC. 03 SORT-ANNUAL-INCOME PIC 9(6). 03 SORT-REST-OF-RECORD PIC X(490).
Using the SORT and MERGE Statements 9.3 Sample Programs Using the SORT and MERGE Statements Example 9–11 (Cont.) Creating a New Sort Key 120-WRITE. RETURN SORT-FILE AT END CLOSE OUT-FILE GO TO 130-DONE. MOVE SORT-LENGTH TO OUT-LENGTH. WRITE OUT-REC. GO TO 120-WRITE. 130-DONE. EXIT. Example 9–12 merges three identically sequenced files into one file. Example 9–12 Merging Files IDENTIFICATION DIVISION. PROGRAM-ID. MERGE01.
Using the SORT and MERGE Statements 9.3 Sample Programs Using the SORT and MERGE Statements Example 9–12 (Cont.) Merging Files FD TOTAL-SALES LABEL RECORDS ARE STANDARD. 01 TOTAL-RECORD PIC X(100). WORKING-STORAGE SECTION. 01 INITIAL-READ PIC X VALUE "Y". 01 THE-COUNTERS. 03 PRODUCT-AMT PIC S9(7)V99. 03 REGION1-AMT PIC S9(9)V99. 03 REGION2-AMT PIC S9(9)V99. 03 REGION3-AMT PIC S9(9)V99. 03 TOTAL-AMT PIC S9(11)V99. 01 SAVE-MERGE-REC. 03 S-REGION-CODE PIC XX. 03 S-PRODUCT-CODE PIC X(10).
Using the SORT and MERGE Statements 9.3 Sample Programs Using the SORT and MERGE Statements Example 9–12 (Cont.) Merging Files 050-TALLY-AMOUNTS. ADD M-SALES-AMT TO PRODUCT-AMT TOTAL-AMT. IF M-REGION-CODE = "01" ADD M-SALES-AMT TO REGION1-AMT. IF M-REGION-CODE = "02" ADD M-SALES-AMT TO REGION2-AMT. IF M-REGION-CODE = "03" ADD M-SALES-AMT TO REGION3-AMT. 100-DONE-TOTAL-SALES SECTION. 120-DONE. EXIT.
10 Producing Printed Reports There are three Compaq COBOL programming capabilities for producing formatted reports: conventional, linage file, and Report Writer. This chapter presents the following topics to help you format and produce reports: • Designing a report (Section 10.1) • Components of a report (Section 10.2) • Methods of reporting accumulation and control totals (Section 10.3) • The logical page and the physical page (Section 10.4) • Programming a conventional file report (Section 10.
Producing Printed Reports 10.
Producing Printed Reports 10.2 Components of a Report Example 10–1 (Cont.) Components of a Report 2 04-NOVEMBER-96 Year To Date Sales Report Page 1 Salesman Salary/Bonus Client Name Client Address Total Sales 3 ************************ JANUARY REPORT ************************** 4 SMITH $30,000.00 STREN 2742 NORTH ST. $225,000.00 JOHN $10,000.00 TOM MANCHESTER, NH . . . . . . . . . . . . . . . TOTAL JANUARY SALES: $ 2,000,000.
Producing Printed Reports 10.2 Components of a Report 3 Control Heading (CH)—The control heading consists of one or more lines of information identifying the beginning of a new logical area on a page. 4 Detail Lines (DL)—The detail (the lines marked with 4 and all the lines between) consists of one or more lines of the primary data of the report.
Producing Printed Reports 10.4 The Logical Page and the Physical Page Figure 10–2 Subtotals, Crossfoot Totals, and Rolled Forward Totals 04−NOVEMBER−96 Year To Date Sales Report Page 1 Salesman Salary/Bonus Client Name Client Address Total Sales −−−−−−−−− −−−−−−−−−−−− −−−−−−−−−−−−− −−−−−−−−−−−−−− −−−−−−−−−−−−− ************************* JANUARY REPORT *************************** SMITH JOHN $30,000.00 $10,000.00 STREN TOM 2742 NORTH ST. MANCHESTER, NH LEPRO RONALD $25,000.00 $10,000.
Producing Printed Reports 10.4 The Logical Page and the Physical Page page is defined, your program must stay within those bounds; otherwise, the printed report may not contain the correct information. You can program two types of reports: a conventional file report or a linage file report. Section 10.5 and Section 10.5.1 discuss these reports in detail. 10.
Producing Printed Reports 10.5 Programming a Conventional File Report Once you have defined the logical page, you must handle vertical spacing, horizontal spacing, and the number of lines that appear on each page so that you can advance to the next logical page. The following sections discuss these subjects. 10.5.
Producing Printed Reports 10.5 Programming a Conventional File Report Example 10–2 Checking for the Page-Overflow Condition . . . PROCEDURE DIVISION. A000-BEGIN. . . . A100-FIRST-REPORT-ROUTINES. * * A901-HEADER-ROUTINE executes whenever the number of lines written exceeds * the number of lines on the 66-line default logical page. * WRITE A-LINE1 AFTER ADVANCING 2 LINES. ADD 2 TO REPORT1-LINE-COUNT. IF REPORT1-LINE-COUNT > 65 PERFORM A901-HEADER-ROUTINE. . . . A500-SECOND-REPORT-ROUTINES.
Producing Printed Reports 10.5 Programming a Conventional File Report 10.5.4 Printing the Conventional Report When you are ready to print your report, you must ensure that your system’s line printer can accommodate the page size or form of your report. If the printer uses a different page size or form, contact your system manager. The system manager can change the page or form size to accommodate your report. Section 10.7 describes the different modes for printing a report. 10.5.
Producing Printed Reports 10.5 Programming a Conventional File Report Example 10–3 (Cont.) 01 FORM1-LINE-14. 02 02 FORM1-STREET 01 FORM1-LINE-15. 02 02 FORM1-CITY 02 02 FORM1-STATE 02 02 FORM1-ZIP 01 FORM2-HEADER-1. 02 PIC 02 PIC 02 PIC 02 PIC 02 F2H-PAGE PIC 01 FORM2-HEADER-2. 02 PIC 02 PIC Page Advancing and Line Skipping PIC X(4) VALUE SPACES. PIC X(20). PIC PIC PIC PIC PIC PIC X(15) VALUE X(30) VALUE X(10) VALUE XXXXX VALUE ZZZZZ. X(4) VALUE SPACES. X(15). X VALUE SPACE. XX. X VALUE SPACE. 99999.
Producing Printed Reports 10.5 Programming a Conventional File Report Example 10–3 (Cont.) Page Advancing and Line Skipping A900-PRINT-HEADERS-ROUTINE. * * This routine generates a form feed, writes two lines, * skips two lines, then resets the line counter to 4 to * indicate used lines on the current logical page. * Line 5 on this page is the next print line. * ADD 1 TO PAGE-NO. MOVE PAGE-NO TO F2H-PAGE. WRITE FORM2-PRINT-LINE FROM FORM2-HEADER-1 AFTER ADVANCING PAGE.
Producing Printed Reports 10.5 Programming a Conventional File Report The second report, Figure 10–5, is a double-spaced master listing of all input records. While this report’s logical page is identical to the default logical page for the system (in this case, 66 vertical lines and 132 horizontal characters), this report uses only the first 55 lines on the page. Both reports are output to a disk for later printing.
Producing Printed Reports 10.6 Programming a Linage-File Compaq COBOL Report On Tru64 UNIX, the linage file contains variable length records. All advancing information is written to the file as blank lines. ♦ The following sections discuss these topics in detail. Example 10–5 shows an example of a linage-file program. 10.6.1 Defining the Logical Page in a Linage-File Report Your program specifies the format of your report.
Producing Printed Reports 10.6 Programming a Linage-File Compaq COBOL Report For example, to define how many lines you want your program to skip at the top or bottom of the logical page, use the LINAGE clause with either the LINES AT TOP or the LINES AT BOTTOM phrase. To define a footing area within the logical page, use the LINAGE clause with the WITH FOOTING phrase. The LINES AT TOP phrase positions the printer on the first print line in the page body.
Producing Printed Reports 10.6 Programming a Linage-File Compaq COBOL Report ADVANCING PAGE clause or the AFTER ADVANCING PAGE clause. For an example of the WRITE statement, see Section 10.6.7. Section 10.6.5 describes how to handle a page-overflow condition. 10.6.5 Programming for the End-of-Page and Page-Overflow Condition A page-overflow condition occurs when your program writes more lines than the logical page can accommodate.
Producing Printed Reports 10.
Producing Printed Reports 10.6 Programming a Linage-File Compaq COBOL Report Example 10–4 (Cont.) Checking for End-of-Page on a 28-Line Logical Page DATA DIVISION. FILE SECTION. FD INPUT-FILE. 01 INPUT-RECORD. 02 I-NAME. 03 I-FIRST 03 I-MID 03 I-LAST 02 I-ADDRESS. 03 I-STREET 03 I-CITY 03 I-STATE 03 I-ZIP 02 I-ACCOUNT-NUMBER 02 I-PURCHASE-DATE 02 I-PURCHASE-AMOUNT 02 I-PURCHASE-DESCRIP FD REPORT-FILE LINAGE IS 26 LINES WITH FOOTING AT LINES AT BOTTOM 01 PRINT-LINE WORKING-STORAGE SECTION. 01 HEAD-1.
Producing Printed Reports 10.6 Programming a Linage-File Compaq COBOL Report Example 10–4 (Cont.) Checking for End-of-Page on a 28-Line Logical Page 01 HEAD-5. 02 H5-LC PIC 99. 02 FILLER PIC X(4) VALUE "Date". 02 FILLER PIC X(7) VALUE SPACES. 02 FILLER PIC X(6) VALUE "Amount". 02 FILLER PIC X(10) VALUE SPACES. 02 FILLER PIC X(11) VALUE "Description". 01 HEAD-6 PIC X(61) VALUE ALL "-". 01 DETAIL-LINE. 02 DET-LC PIC 99. 02 DL-DATE PIC X(9). 02 FILLER PIC X VALUE SPACE. 02 DL-AMT PIC $ZZZ,ZZZ.99-.
Producing Printed Reports 10.6 Programming a Linage-File Compaq COBOL Report Example 10–4 (Cont.) Checking for End-of-Page on a 28-Line Logical Page A300-PRINT-DETAIL-LINE. MOVE I-PURCHASE-DATE TO DL-DATE. MOVE I-PURCHASE-AMOUNT TO DL-AMT. MOVE I-PURCHASE-DESCRIP TO DL-DESC. * At EOP this last detail line goes in footing area of current page WRITE PRINT-LINE FROM DETAIL-LINE AT END-OF-PAGE PERFORM A500-PRINT-HEADERS. ADD I-PURCHASE-AMOUNT TO TOTAL-PURCHASES. A400-PRINT-TOTALS. MOVE TOTAL-PURCHASES TO TL.
Producing Printed Reports 10.6 Programming a Linage-File Compaq COBOL Report 10.6.7 A Linage-File Report Example Example 10–5 shows a Compaq COBOL program that produces a linage-file report. The LINAGE clause in the following File Description entry defines the logical page areas shown in Figure 10–8: FD MINIF1-REPORT LINAGE IS 13 LINES LINES AT TOP LINES AT BOTTOM 2 5. Figure 10–8 shows a 20-line logical page that includes a top margin ( T ), a page body ( P ), and a bottom margin ( B ).
Producing Printed Reports 10.6 Programming a Linage-File Compaq COBOL Report to exceed 15. The pointer is then positioned on the first print line of the next logical page. LINAGE is the sum of N (where N represents the number of lines of text) plus X (where X represents the number of lines at the top) plus Y (where Y represents the number of lines at the bottom). The sum total should not exceed the length of the physical page, which is usually 66 lines.
Producing Printed Reports 10.6 Programming a Linage-File Compaq COBOL Report Example 10–5 Programming a 20-Line Logical Page Defined by the LINAGE Clause with Automatic Page Overflow IDENTIFICATION DIVISION. PROGRAM-ID. REPLINAG. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INPUT-FILE ASSIGN TO "REPIN.DAT". SELECT MINIF1-REPORT ASSIGN TO "MINIF1.DAT". DATA DIVISION. FILE SECTION. FD INPUT-FILE. 01 INPUT-RECORD. 02 I-NAME. 03 I-FIRST PIC X(10). 03 I-MID PIC X. 03 I-LAST PIC X(15).
Producing Printed Reports 10.6 Programming a Linage-File Compaq COBOL Report Example 10–5 (Cont.) Programming a 20-Line Logical Page Defined by the LINAGE Clause with Automatic Page Overflow A100-READ-INPUT. READ INPUT-FILE AT END MOVE "Y" TO END-OF-FILE. IF END-OF-FILE NOT = "Y" PERFORM A200-PRINT-REPORT. A200-PRINT-REPORT. MOVE I-LAST TO MINIF1-LAST. WRITE MINIF1-PRINT-LINE FROM MINIF1-LINE-3 BEFORE ADVANCING 1 LINE. MOVE SPACES TO MINIF1-PRINT-LINE. WRITE MINIF1-PRINT-LINE AFTER ADVANCING 9 LINES.
Producing Printed Reports 10.7 Modes for Printing Reports • You tie up the printer for as long as your job runs. If your program does computations and runs for a long time, you could significantly reduce your installation’s pages-printed-per-day production schedule. • You do not have a backup report file in the event of power failure or other unforeseen circumstances. Therefore, if your job fails, you must begin again. 10.7.
Producing Printed Reports 10.8 Programming a Report Writer Report Detailed examples using Report Writer are documented in Section 10.9. 10.8.1 Using the REPORT Clause in the File Section To create a report with Report Writer, you must write a report to a specific file.
Producing Printed Reports 10.8 Programming a Report Writer Report The RD entry example in Section 10.8.
Producing Printed Reports 10.8 Programming a Report Writer Report Figure 10–9 Presentation Order for a Logical Page REPORT HEADING PAGE HEADING CONTROL HEADING FINAL CONTROL HEADING 1 CONTROL HEADING 2 . . . DETAIL . . . CONTROL FOOTING 2 CONTROL FOOTING 1 CONTROL FOOTING FINAL PAGE FOOTING REPORT FOOTING (RH) (PH) (CH) (DE) (CF) (PF) (RF) ZK−6087−GE Figure 10–10 shows a report that uses all seven of the report groups listed in the preceding table.
Producing Printed Reports 10.8 Programming a Report Writer Report Figure 10–10 Sample Report Using All Seven Report Groups SALES REPORT Report Heading MONTH WK. SALES JAN. REPORT JAN. 4 10.000 JAN. 11 15.000 JAN. TOTALS 25.000 CONTINUED MONTH WK. SALES FEB. REPORT FEB. 2 9.000 FEB. 4 11.000 FEB. TOTALS 20.
Producing Printed Reports 10.8 Programming a Report Writer Report 01 01 01 01 01 01 01 REPORT-HEADER TYPE IS REPORT HEADING. PAGE-HEADER TYPE IS PAGE HEADING. CONTROL-HEADER TYPE IS CONTROL HEADING CONTROL-NAME-1. DETAIL-LINE TYPE IS DETAIL. CONTROL-FOOTER TYPE IS CONTROL FOOTING CONTROL-NAME-2. PAGE-FOOTER TYPE IS PAGE FOOTING. REPORT-FOOTER TYPE IS REPORT FOOTING. 10.8.
Producing Printed Reports 10.8 Programming a Report Writer Report You can also specify absolute line spacing with the NEXT GROUP clause. An absolute line example—NEXT GROUP IS 10—places the next report group on line 10 of the page. In addition you can use NEXT GROUP NEXT PAGE, which causes a page-eject to occur before the NEXT GROUP report group prints. NEXT GROUP can be coded only for REPORT HEADING, CONTROL HEADING, DETAIL, CONTROL FOOTING, and PAGE FOOTING report groups, and only at the 01 level.
Producing Printed Reports 10.8 Programming a Report Writer Report In the next example, the COLUMN NUMBER clauses are subordinate to a LINE NUMBER clause: 02 LINE 03 03 03 03 03 5 ON NEXT PAGE. COLUMN 1 PIC X(12) COLUMN 14 PIC 9999 COLUMN 18 PIC X COLUMN 20 PIC X(15) COLUMN 36 PIC $$$$,$$$.99 VALUE "(Cust-Number". SOURCE CUST-NUM. VALUE ")". VALUE "TOTAL PURCHASES". SUM TOT-PURCHS.
Producing Printed Reports 10.8 Programming a Report Writer Report You can also code a SOURCE clause with PAGE-COUNTER or LINE-COUNTER as its operand, as the following example shows. PAGE-COUNTER references a special register created by the compiler for each Report Description entry in the Report Section. This counter automatically increments by 1 each time the Report Writer executes a page advance.
Producing Printed Reports 10.8 Programming a Report Writer Report When the value of a control name changes, a control break occurs. The Report Writer acknowledges this break only when you execute a GENERATE or TERMINATE statement for the report, which causes the information related to that CONTROL report group to be printed. In the following example, the report defines two control totals (MONTH-CONTRL and WEEK-CONTRL) in the CONTROL clause.
Producing Printed Reports 10.8 Programming a Report Writer Report This example produces the following output: 1 2 3 4 5 column 1234567890123456789012345678901234567890123456789012345 TOTAL SALES FOR YEAR-TO-DATE WAS 953208.90 10.8.11 Defining and Incrementing Totals In addition to using either the VALUE or SOURCE clause to assign a value to a report item, you can use the SUM clause to accumulate values of report items.
Producing Printed Reports 10.8 Programming a Report Writer Report 10.8.11.2 Crossfooting In crossfooting, the SUM clause adds all the sum counters in the same CONTROL FOOTING report group and automatically creates another sum counter. In the following example, the CONTROL FOOTING group shows both subtotaling (SALES-1) and crossfooting (SALES-2): 01 TYPE DETAIL LINE PLUS 1. 05 COLUMN 15 PIC 999.99 SOURCE BRANCH1-SALES. 05 COLUMN 25 PIC 999.99 SOURCE BRANCH2-SALES.
Producing Printed Reports 10.8 Programming a Report Writer Report 10.8.11.4 RESET Option When a CONTROL FOOTING group is printed, the SUM counter in that group is automatically reset to zero. If you want to specify when a SUM counter is reset to zero, use the RESET phrase. RESET names a data item in a higherlevel CONTROL FOOTING that will cause the SUM counter to be reset to zero. RESET is used only with a SUM clause.
Producing Printed Reports 10.8 Programming a Report Writer Report In the preceding example, the value of ADD-COUNTER is added to the CONTROL FOOTING FINAL counter every time the FIRST-DETAIL-LINE report group is generated. 10.8.12 Restricting Print Items In a Report Writer program, the GROUP INDICATE clause eliminates repeated information from report detail lines by allowing an elementary item in a DETAIL report group to be printed only the first time after a control or page break.
Producing Printed Reports 10.8 Programming a Report Writer Report With the GROUP INDICATE clause, the program produces the following output: 1 2 3 123456789012345678901234567890 Name Registration Number Rolans R. Vencher R. Anders J. 123456 123457 123458 654321 654322 654323 654324 987654 987655 987656 10.8.
Producing Printed Reports 10.8 Programming a Report Writer Report 10.8.13.2 Generating a Report Writer Report The GENERATE statement prints the report. You can produce either detail or summary reports depending on the GENERATE identifier. If you code the name of a DETAIL report group with GENERATE, you create a detail report; if you code a report name with GENERATE, you create a summary report. 10.8.13.
Producing Printed Reports 10.8 Programming a Report Writer Report • CONTROL FOOTING and CONTROL HEADING report groups print after the specified control breaks occur. • In a detail report, the TYPE DETAIL report groups print. • SUM operands are incremented. • Sum counters are reset as specified. Figure 10–12 shows the sequence of operations for all GENERATE statements except the first. See Figure 10–11 for a comparison with the sequence of operations for the first GENERATE statement.
Producing Printed Reports 10.8 Programming a Report Writer Report If no GENERATE statement has been executed for the report, the TERMINATE statement does not produce any report groups. A second TERMINATE statement for the report must not be executed before a second INITIATE statement for the report has been executed. The TERMINATE statement does not close the report file; a CLOSE statement must be executed after the TERMINATE statement. Figure 10–13 shows the sequence of operations for TERMINATE.
Producing Printed Reports 10.8 Programming a Report Writer Report The following example indicates that the phrase BEGINNING-OF-REPORT is to be displayed just before the REPORT HEADING group named REPORTHEADER; the phrase END-OF-REPORT is to be displayed just before the REPORT FOOTING group called REPORT-FOOTER. PROCEDURE DIVISION. DECLARATIVES. BOR SECTION. USE BEFORE REPORTING REPORT-HEADER. BOR-A. DISPLAY "BEGINNING-OF-REPORT". EOR SECTION. USE BEFORE REPORTING REPORT-FOOTER. EOR-A.
Producing Printed Reports 10.8 Programming a Report Writer Report 10.8.14.2 Summary Reporting In summary reporting, the GENERATE statement performs all of the automatic operations of the Report Writer facility, but does not produce any TYPE DETAIL report groups. A report name references the name of an RD entry. If MASTER-LIST is an RD entry, then GENERATE MASTER-LIST produces HEADING and FOOTING report groups (in the order defined), but omits DETAIL report group lines. 10.
Producing Printed Reports 10.9 Report Writer Examples Figure 10–14 Sample MASTER.
Producing Printed Reports 10.9 Report Writer Examples Example 10–6 Sample Program EX1006 IDENTIFICATION DIVISION. PROGRAM-ID. EX1006. ENVIRONMENT DIVISION. CONFIGURATION SECTION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CUSTOMER-FILE ASSIGN TO SELECT SORT-FILE ASSIGN TO SELECT SORTED-FILE ASSIGN TO SELECT PRINTER-FILE ASSIGN TO DATA DIVISION. FILE SECTION. SD SORT-FILE. 01 SORTED-CUSTOMER-MASTER-FILE. 02 SORT-NAME 02 01 CUSTOMER-MASTER-FILE FD SORTED-FILE. 01 FD CUSTOMER-MASTER-FILE. 02 NAME.
Producing Printed Reports 10.9 Report Writer Examples Example 10–6 (Cont.) Sample Program EX1006 REPORT SECTION. RD 01 MASTER-LIST PAGE LIMIT IS 66 HEADING 1 FIRST DETAIL 13 LAST DETAIL 55 CONTROL IS FINAL. TYPE IS PAGE HEADING. 02 LINE 5. 03 COLUMN 1 PIC X(27) VALUE "CUSTOMER MASTER FILE REPORT". 03 COLUMN 105 PIC X(4) VALUE "PAGE". 03 COLUMN 109 PIC ZZZ9 SOURCE PAGE-COUNTER. 03 COLUMN 1 PIC X VALUE "+". 03 COLUMN 2 PIC X(110) VALUE ALL "-". 03 COLUMN 112 PIC X VALUE "+". 02 LINE 8.
Producing Printed Reports 10.9 Report Writer Examples Example 10–6 (Cont.) Sample Program EX1006 PIC X(4) VALUE "CITY". 03 COLUMN 71 PIC X VALUE "|". 03 COLUMN 72 PIC X(2) VALUE "ST". 03 COLUMN 74 PIC X VALUE "|". 03 COLUMN 81 PIC X VALUE "|". 03 COLUMN 83 PIC X(4) VALUE "DATE". 03 COLUMN 90 PIC X VALUE "|". 03 COLUMN 92 PIC X(6) VALUE "NUMBER". 03 COLUMN 98 PIC X VALUE "|". PIC X(6) VALUE "AMOUNT". 03 COLUMN 112 PIC X VALUE "|". 02 LINE 11. 03 COLUMN 1 PIC X VALUE "+". 03 COLUMN 2 PIC X(110) VALUE ALL "-".
Producing Printed Reports 10.9 Report Writer Examples Example 10–6 (Cont.) Sample Program EX1006 000-DO-SORT. DISPLAY "*** EX1006 ***". SORT SORT-FILE ON ASCENDING KEY SORT-NAME WITH DUPLICATES IN ORDER USING CUSTOMER-FILE GIVING SORTED-FILE. DISPLAY "*** Created EX1006.LIS ***". 050-START. OPEN INPUT SORTED-FILE. OPEN OUTPUT PRINTER-FILE. ACCEPT UNEDITED-DATE FROM DATE. INITIATE MASTER-LIST. PERFORM 200-READ-MASTER UNTIL NAME = HIGH-VALUES. TERMINATE MASTER-LIST. CLOSE SORTED-FILE, PRINTER-FILE. STOP RUN.
Producing Printed Reports 10.9 Report Writer Examples 10.9.3 EX1007—Detail Report Program Example 10–7 (EX1007) is a Report Writer program that uses the REPORT HEADING, PAGE HEADING, DETAIL, CONTROL FOOTING, and REPORT FOOTING report groups and produces a detail report—EX1007.LIS (shown in Figure 10–16). The output includes both subtotals and rolling-forward totals. Example 10–7 Sample Program EX1007 IDENTIFICATION DIVISION. PROGRAM-ID. EX1007. ENVIRONMENT DIVISION. CONFIGURATION SECTION.
Producing Printed Reports 10.9 Report Writer Examples Example 10–7 (Cont.) Sample Program EX1007 RD 01 MASTER-LIST PAGE LIMIT IS 66 HEADING 1 FIRST DETAIL 13 LAST DETAIL 55 CONTROLS ARE FINAL NAME. REPORT-HEADER TYPE IS REPORT HEADING NEXT GROUP NEXT PAGE. 02 LINE 24. 03 COLUMN 45 PIC X(31) VALUE ALL "*". 02 LINE 25. 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*". 03 COLUMN 45 PIC X(31) VALUE "* Customer Master File 02 LINE 27. 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*".
Producing Printed Reports 10.9 Report Writer Examples Example 10–7 (Cont.) Sample Program EX1007 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*". 02 LINE 33. 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*". 02 LINE 34. 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*". 02 LINE 35. 03 COLUMN 45 PIC X(31) VALUE ALL "*". 02 LINE 5. 03 COLUMN 1 PIC X(27) VALUE "CUSTOMER MASTER FILE REPORT". 03 COLUMN 105 PIC X(4) VALUE "PAGE". 03 COLUMN 109 PIC ZZZ9 SOURCE PAGE-COUNTER. 02 LINE 7.
Producing Printed Reports 10.9 Report Writer Examples Example 10–7 (Cont.) Sample Program EX1007 03 COLUMN 1 PIC X VALUE "|". 03 COLUMN 2 PIC X(110) VALUE ALL "-". 03 COLUMN 112 PIC X VALUE "|". 02 LINE 10. 03 COLUMN 1 PIC X(6) VALUE "| LAST". 03 COLUMN 16 PIC X(7) VALUE "| FIRST". 03 COLUMN 26 PIC X(4) VALUE "|MI|". 03 COLUMN 35 PIC X(6) VALUE "STREET". 03 COLUMN 48 PIC X VALUE "|". PIC X(4) VALUE "CITY". 03 COLUMN 71 PIC X VALUE "|". 03 COLUMN 72 PIC X(2) VALUE "ST". 03 COLUMN 74 PIC X VALUE "|".
Producing Printed Reports 10.9 Report Writer Examples Example 10–7 (Cont.) Sample Program EX1007 TYPE DETAIL LINE PLUS 2. 02 COLUMN 1 02 COLUMN 17 02 COLUMN 28 02 COLUMN 30 02 COLUMN 51 02 COLUMN 72 02 COLUMN 75 02 COLUMN 81 02 COLUMN 83 02 COLUMN 84 02 COLUMN 86 02 COLUMN 87 02 COLUMN 92 02 COLUMN 99 01 01 PIC PIC PIC PIC PIC PIC PIC PIC PIC PIC PIC PIC PIC PIC X(15) SOURCE LAST-NAME. X(10) SOURCE FIRST-NAME. XX SOURCE MIDDLE-INIT. X(20) SOURCE ADDRESS. X(20) SOURCE CITY. XX SOURCE STATE.
Producing Printed Reports 10.9 Report Writer Examples Example 10–7 (Cont.) Sample Program EX1007 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*". 02 LINE 28. 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 55 PIC Z9 SOURCE UE-DAY. 03 COLUMN 57 PIC X VALUE "-". 03 COLUMN 58 PIC 99 SOURCE UE-MONTH. 03 COLUMN 60 PIC X VALUE "-". PIC 9999 SOURCE UE-YEAR. 03 COLUMN 75 PIC X VALUE "*". 02 LINE 29. 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*". 02 LINE 30.
Producing Printed Reports 10.9 Report Writer Examples Example 10–7 (Cont.) Sample Program EX1007 DISPLAY "*** EX1007 ***". DISPLAY "Enter Current Date (YYYYMMDD) :". ACCEPT UNEDITED-DATE. OPEN INPUT SORTED-FILE. OPEN OUTPUT PRINTER-FILE. INITIATE MASTER-LIST. PERFORM 200-READ-MASTER UNTIL NAME = HIGH-VALUES. 100-END-OF-FILE. TERMINATE MASTER-LIST. CLOSE SORTED-FILE, PRINTER-FILE. STOP RUN. 200-READ-MASTER. READ SORTED-FILE AT END MOVE HIGH-VALUES TO NAME. IF NAME NOT = HIGH-VALUES GENERATE DETAIL-LINE.
Producing Printed Reports 10.9 Report Writer Examples Figure 10–16 EX1007.
Producing Printed Reports 10.9 Report Writer Examples Figure 10–16 (Cont.) EX1007.
Producing Printed Reports 10.9 Report Writer Examples Example 10–8 Sample Program EX1008 IDENTIFICATION DIVISION. PROGRAM-ID. EX1008. ENVIRONMENT DIVISION. CONFIGURATION SECTION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CUSTOMER-FILE SELECT SORT-FILE SELECT SORTED-FILE SELECT PRINTER-FILE ASSIGN ASSIGN ASSIGN ASSIGN TO TO TO TO "MASTER.DAT". "EX1008-SORTIN.TMP". "EX1008-SORTOUT.TMP". "EX1008.LIS". DATA DIVISION. FILE SECTION. SD SORT-FILE. 01 SORTED-CUSTOMER-MASTER-FILE. 02 SORT-NAME 02 PIC X(26).
Producing Printed Reports 10.9 Report Writer Examples Example 10–8 (Cont.) Sample Program EX1008 03 INVOICE-NUMBER 03 INVOICE-SALES 03 INVOICE-DATE. 04 INV-DAY 04 INV-MO 04 INV-YR PIC 999999. PIC S9(5)V99. PIC 99. PIC 99. PIC 9999. REPORT SECTION. RD 01 MASTER-LIST PAGE LIMIT IS 66 HEADING 1 FIRST DETAIL 13 LAST DETAIL 55 CONTROLS ARE FINAL. REPORT-HEADER TYPE IS REPORT HEADING NEXT GROUP NEXT PAGE. 02 LINE 24. 03 COLUMN 45 PIC X(31) VALUE ALL "*". 02 LINE 25. 03 COLUMN 45 PIC X VALUE "*".
Producing Printed Reports 10.9 Report Writer Examples Example 10–8 (Cont.) Sample Program EX1008 02 01 LINE 29. 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*". 02 LINE 30. 03 COLUMN 45 PIC X(31) VALUE "* Report EX1008 *". 02 LINE 31. 03 COLUMN 45 PIC X(31) VALUE "* Detail Report *". 02 LINE 32. 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*". 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*". 02 LINE 34. 03 COLUMN 45 PIC X(31) VALUE ALL "*". TYPE IS PAGE HEADING. 02 LINE 5.
Producing Printed Reports 10.9 Report Writer Examples Example 10–8 (Cont.) Sample Program EX1008 03 COLUMN 1 PIC X VALUE "|". 03 COLUMN 2 PIC X(110) VALUE ALL "-". 03 COLUMN 112 PIC X VALUE "|". 02 LINE 10. 03 COLUMN 1 PIC X(6) VALUE "| LAST". 03 COLUMN 16 PIC X(7) VALUE "| FIRST". 03 COLUMN 26 PIC X(4) VALUE "|MI|". 03 COLUMN 35 PIC X(6) VALUE "STREET". 03 COLUMN 48 PIC X VALUE "|". PIC X(4) VALUE "CITY". 03 COLUMN 71 PIC X VALUE "|". 03 COLUMN 72 PIC X(2) VALUE "ST". 03 COLUMN 74 PIC X VALUE "|".
Producing Printed Reports 10.9 Report Writer Examples Example 10–8 (Cont.) Sample Program EX1008 02 LINE 11. 03 COLUMN 1 PIC X VALUE "+". 03 COLUMN 2 PIC X(110) VALUE ALL "-". 03 COLUMN 112 PIC X VALUE "+". 01 DETAIL-LINE TYPE DETAIL LINE IS PLUS 1. 02 COLUMN 1 PIC X(15) SOURCE LAST-NAME. 02 COLUMN 17 PIC X(10) SOURCE FIRST-NAME. 02 COLUMN 28 PIC XX SOURCE MIDDLE-INIT. 02 COLUMN 30 PIC X(20) SOURCE ADDRESS. 02 COLUMN 51 PIC X(20) SOURCE CITY. 02 COLUMN 72 PIC XX SOURCE STATE.
Producing Printed Reports 10.9 Report Writer Examples Example 10–8 (Cont.) Sample Program EX1008 03 03 03 03 03 03 03 02 LINE 03 03 02 LINE 02 LINE 03 03 02 LINE COLUMN 45 PIC X VALUE "*". COLUMN 55 PIC Z9 SOURCE UE-DAY. COLUMN 57 PIC X VALUE "-". COLUMN 58 PIC 99 SOURCE UE-MONTH. COLUMN 60 PIC X VALUE "-". COLUMN 61 PIC 9999 SOURCE UE-YEAR. COLUMN 75 PIC X VALUE "*". 29. COLUMN 45 PIC X VALUE "*". COLUMN 75 PIC X VALUE "*". 30 COLUMN 45 PIC X(31) VALUE "* End of Report EX1008 31.
Producing Printed Reports 10.9 Report Writer Examples Example 10–8 (Cont.) Sample Program EX1008 MAIN SECTION. 000-DO-SORT. SORT SORT-FILE ON ASCENDING KEY SORT-NAME WITH DUPLICATES IN ORDER USING CUSTOMER-FILE GIVING SORTED-FILE. 000-START. DISPLAY "*** EX1008 ***". DISPLAY "Enter Current Date (YYYYMMDD) :". ACCEPT UNEDITED-DATE. OPEN INPUT SORTED-FILE. OPEN OUTPUT PRINTER-FILE. MOVE SPACES TO NAME. INITIATE MASTER-LIST. PERFORM 200-READ-MASTER UNTIL EOF = "Y". 100-END-OF-FILE. TERMINATE MASTER-LIST.
Producing Printed Reports 10.9 Report Writer Examples Figure 10–17 EX1008.
Producing Printed Reports 10.9 Report Writer Examples Example 10–9 (Cont.) Sample Program EX1009 DATA DIVISION. FILE SECTION. SD SORT-FILE. 01 SORTED-CUSTOMER-MASTER-FILE. 02 SORT-NAME 02 FD CUSTOMER-FILE. 01 CUSTOMER-MASTER-FILE FD 01 SORTED-FILE. CUSTOMER-MASTER-FILE. 02 NAME. 03 LAST-NAME 03 FIRST-NAME 03 MIDDLE-INIT 02 ADDRESS 02 CITY 02 STATE 02 ZIP 02 SALESMAN-NUMBER 03 INVOICE-NUMBER 03 INVOICE-SALES 03 INVOICE-DATE. 04 INV-DAY 04 INV-MO 04 INV-YR PIC X(26). PIC X(73). PIC X(99).
Producing Printed Reports 10.9 Report Writer Examples Example 10–9 (Cont.) Sample Program EX1009 02 02 02 02 02 02 02 LINE 24. 03 COLUMN 45 PIC X(31) VALUE ALL "*". LINE 25. 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*". LINE 26. 03 COLUMN 45 PIC X(31) VALUE "* Customer Master File LINE 27. 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*". 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 55 PIC Z9 SOURCE UE-DAY. 03 COLUMN 57 PIC X VALUE "-". 03 COLUMN 58 PIC 99 SOURCE UE-MONTH.
Producing Printed Reports 10.9 Report Writer Examples Example 10–9 (Cont.) Sample Program EX1009 03 03 02 01 LINE 03 TYPE IS PAGE 02 LINE 03 03 03 03 03 03 02 LINE 03 03 03 03 03 03 02 LINE 03 03 03 02 LINE 03 03 03 COLUMN 45 PIC X VALUE "*". COLUMN 75 PIC X VALUE "*". 34. COLUMN 45 PIC X(31) VALUE ALL "*". HEADING. 5. COLUMN 1 PIC X(27) VALUE "CUSTOMER MASTER FILE REPORT". COLUMN 105 PIC X(4) VALUE "PAGE". COLUMN 109 PIC ZZZ9 SOURCE PAGE-COUNTER. COLUMN 1 PIC X VALUE "+".
Producing Printed Reports 10.9 Report Writer Examples Example 10–9 (Cont.) Sample Program EX1009 PIC X(6) VALUE "STREET". 03 COLUMN 48 PIC X VALUE "|". 03 COLUMN 52 PIC X(4) VALUE "CITY". 03 COLUMN 71 PIC X VALUE "|". 03 COLUMN 72 PIC X(2) VALUE "ST". 03 COLUMN 74 PIC X VALUE "|". 03 COLUMN 76 PIC X(3) VALUE "ZIP". 03 COLUMN 81 PIC X VALUE "|". 03 COLUMN 83 PIC X(4) VALUE "DATE". PIC X VALUE "|". 03 COLUMN 92 PIC X(6) VALUE "NUMBER". 03 COLUMN 98 PIC X VALUE "|". 03 COLUMN 103 PIC X(6) VALUE "AMOUNT".
Producing Printed Reports 10.9 Report Writer Examples Example 10–9 (Cont.) Sample Program EX1009 02 LINE 59. 03 COLUMN 45 PIC X(16) VALUE "C O M P A N Y 03 COLUMN 62 PIC X(25) VALUE "C O N F I D E 02 LINE 60. 03 COLUMN 45 PIC X(16) VALUE "C O M P A N Y 03 COLUMN 62 PIC X(25) VALUE "C O N F I D E 02 02 02 02 02 02 02 02 02 02 NEXT GROUP IS PLUS 2. LINE IS PLUS 2. 03 COLUMN 73 PIC X(39) VALUE LINE IS PLUS 1.
Producing Printed Reports 10.9 Report Writer Examples Example 10–9 (Cont.) Sample Program EX1009 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 55 PIC Z9 SOURCE UE-DAY. 03 COLUMN 57 PIC X VALUE "-". 03 COLUMN 58 PIC 99 SOURCE UE-MONTH. 03 COLUMN 60 PIC X VALUE "-". 03 COLUMN 61 PIC 9999 SOURCE UE-YEAR. 03 COLUMN 75 PIC X VALUE "*". 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*". 02 LINE 30 COLUMN 45 PIC X(31) VALUE "* End of Report EX1009 02 LINE 31. 03 COLUMN 45 PIC X VALUE "*".
Producing Printed Reports 10.9 Report Writer Examples Example 10–9 (Cont.) Sample Program EX1009 100-END-OF-FILE. TERMINATE MASTER-LIST. CLOSE SORTED-FILE, PRINTER-FILE. STOP RUN. 200-READ-MASTER. READ SORTED-FILE AT END MOVE HIGH-VALUES TO NAME. IF NAME NOT = HIGH-VALUES GENERATE DETAIL-LINE.
Producing Printed Reports 10.9 Report Writer Examples Figure 10–18 EX1009.
Producing Printed Reports 10.9 Report Writer Examples Figure 10–18 (Cont.) EX1009.
Producing Printed Reports 10.9 Report Writer Examples Example 10–10 Sample Program EX1010 IDENTIFICATION DIVISION. PROGRAM-ID. EX1010. ENVIRONMENT DIVISION. CONFIGURATION SECTION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CUSTOMER-FILE SELECT SORT-FILE SELECT SORTED-FILE SELECT PRINTER-FILE ASSIGN ASSIGN ASSIGN ASSIGN TO TO TO TO "MASTER.DAT". "EX1010-SORTIN.TMP". "EX1010-SORTOUT.TMP". "EX1010.LIS". DATA DIVISION. FILE SECTION. SD SORT-FILE. 01 SORTED-CUSTOMER-MASTER-FILE. 02 SORT-NAME 02 PIC X(26).
Producing Printed Reports 10.9 Report Writer Examples Example 10–10 (Cont.) Sample Program EX1010 REPORT SECTION. RD MASTER-LIST PAGE LIMIT IS 66 HEADING 1 FIRST DETAIL 13 LAST DETAIL 55 FOOTING 58 CONTROLS ARE FINAL NAME. 01 REPORT-HEADER TYPE IS REPORT HEADING NEXT GROUP NEXT PAGE. 02 LINE 24. 03 COLUMN 45 PIC X(31) VALUE ALL "*". 02 LINE 25. 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*". 03 COLUMN 45 PIC X(31) VALUE "* Customer Master File 02 LINE 27. 03 COLUMN 45 PIC X VALUE "*".
Producing Printed Reports 10.9 Report Writer Examples Example 10–10 (Cont.) Sample Program EX1010 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*". 02 LINE 33. 03 COLUMN 45 PIC X VALUE "*". 03 COLUMN 75 PIC X VALUE "*". 02 LINE 34. 03 COLUMN 45 PIC X(31) VALUE ALL "*". 02 LINE 5. 03 COLUMN 1 PIC X(27) VALUE "CUSTOMER MASTER FILE REPORT". 03 COLUMN 105 PIC X(4) VALUE "PAGE". 03 COLUMN 109 PIC ZZZ9 SOURCE PAGE-COUNTER. 02 LINE 7. 03 COLUMN 1 PIC X VALUE "+". 03 COLUMN 2 PIC X(110) VALUE ALL "-".
Producing Printed Reports 10.9 Report Writer Examples Example 10–10 (Cont.) Sample Program EX1010 PIC X VALUE "|". 03 COLUMN 72 PIC X(2) VALUE "ST". 03 COLUMN 74 PIC X VALUE "|". 03 COLUMN 76 PIC X(3) VALUE "ZIP". 03 COLUMN 81 PIC X VALUE "|". 03 COLUMN 83 PIC X(4) VALUE "DATE". 03 COLUMN 90 PIC X VALUE "|". 03 COLUMN 92 PIC X(6) VALUE "NUMBER". 03 COLUMN 98 PIC X VALUE "|". PIC X(6) VALUE "AMOUNT". 03 COLUMN 112 PIC X VALUE "|". 02 LINE 11. 03 COLUMN 1 PIC X VALUE "+". 03 COLUMN 2 PIC X(110) VALUE ALL "-".
Producing Printed Reports 10.9 Report Writer Examples Example 10–10 (Cont.) Sample Program EX1010 01 FINAL-FOOTING TYPE IS CONTROL FOOTING FINAL NEXT GROUP NEXT PAGE. 02 LINE IS PLUS 2. 03 COLUMN 70 PIC X(42) VALUE ALL "*". 02 LINE IS PLUS 1. 03 COLUMN 14 PIC X(21) VALUE "GRAND TOTAL RECORDS: ". 03 FDC COLUMN 40 PIC ZZZ,ZZZ,ZZ9 SUM IDC. 03 COLUMN 70 PIC X(24) VALUE "* GRAND TOTAL INVOICES:". 03 FIA COLUMN 94 PIC $,$$$,$$$,$$$.99- SUM IIA. 03 COLUMN 111 PIC X VALUE "*". 02 LINE IS PLUS 1.
Producing Printed Reports 10.9 Report Writer Examples Example 10–10 (Cont.) Sample Program EX1010 02 LINE 59. 03 COLUMN 45 PIC X(16) VALUE "C O M P A N Y 03 COLUMN 62 PIC X(25) VALUE "C O N F I D E 02 LINE 60. 03 COLUMN 45 PIC X(16) VALUE "C O M P A N Y 03 COLUMN 62 PIC X(25) VALUE "C O N F I D E PROCEDURE DIVISION. DECLARATIVES. BOR SECTION. USE BEFORE REPORTING REPORT-HEADER. EOR SECTION. USE BEFORE REPORTING REPORT-FOOTER. EOR-A. DISPLAY "*** Created EX1010.LIS ***". END DECLARATIVES. ". N T I A L ". ".
Producing Printed Reports 10.9 Report Writer Examples Figure 10–19 EX1010.
Producing Printed Reports 10.9 Report Writer Examples Figure 10–19 (Cont.) EX1010.
Producing Printed Reports 10.10 Solving Report Problems Figure 10–20 Printing Labels Four-Up 1 2 3 4 5 6 7 8 ZK−6088−GE Example 10–11 Printing Labels Four-Up IDENTIFICATION DIVISION. PROGRAM-ID. REP02. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INPUT-FILE ASSIGN TO "LABELS.DAT". SELECT REPORT-FILE ASSIGN TO "LABELS.REP". DATA DIVISION. FILE SECTION. FD INPUT-FILE. 01 INPUT-RECORD. 02 INPUT-NAME PIC X(20). 02 INPUT-ADDRESS PIC X(15). 02 INPUT-CITY PIC X(10).
Producing Printed Reports 10.10 Solving Report Problems Example 10–11 (Cont.) Printing Labels Four-Up 07 07 07 07 07 07 LABEL-CITY FILLER LABEL-STATE FILLER LABEL-ZIP FILLER PIC PIC PIC PIC PIC PIC PIC X(10). XXXX. XX. XXXX. 99999. XXXXX. X. 01 END-OF-FILE PROCEDURE DIVISION. A000-BEGIN. OPEN INPUT INPUT-FILE OUTPUT REPORT-FILE. MOVE SPACES TO LABELS-TABLE. SET INDEX-1, INDEX-2, INDEX-3 TO 1. PERFORM A100-READ-INPUT UNTIL END-OF-FILE = "Y". A050-WRAP-UP.
Producing Printed Reports 10.10 Solving Report Problems Figure 10–21 Printing Labels Four-Up in Sort Order 1 7 13 19 2 8 14 20 3 9 15 21 4 10 16 22 5 11 17 23 6 12 18 24 1 ZK−1556−GE Example 10–12 Printing Labels Four-Up in Sort Order IDENTIFICATION DIVISION. PROGRAM-ID. REP03. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INPUT-FILE ASSIGN TO "LABELS.DAT". SELECT REPORT-FILE ASSIGN TO "LABELS.REP".
Producing Printed Reports 10.10 Solving Report Problems Example 10–12 (Cont.) Printing Labels Four-Up in Sort Order DATA DIVISION. FILE SECTION. FD INPUT-FILE. 01 INPUT-RECORD. 02 INPUT-NAME PIC X(20). 02 INPUT-ADDRESS PIC X(15). 02 INPUT-CITY PIC X(10). 02 INPUT-STATE PIC XX. 02 INPUT-ZIP PIC 99999. FD REPORT-FILE. 01 REPORT-RECORD PIC X(132). WORKING-STORAGE SECTION. 01 LABELS-TABLE. 03 FOUR-UP OCCURS 6 TIMES INDEXED BY ROW-INDEX. 04 NAME-LINE. 05 LINE-1 OCCURS 4 TIMES INDEXED BY NAME-INDEX.
Producing Printed Reports 10.10 Solving Report Problems Example 10–12 (Cont.) Printing Labels Four-Up in Sort Order A100-READ-INPUT. READ INPUT-FILE AT END MOVE "Y" TO END-OF-FILE. IF END-OF-FILE = "Y" NEXT SENTENCE ELSE PERFORM A200-GENERATE-LABELS. A200-GENERATE-LABELS.
Producing Printed Reports 10.10 Solving Report Problems Table 10–2 (Cont.
Producing Printed Reports 10.10 Solving Report Problems 10.10.5 Underlining Items in Your Reports The examples in this section apply only to printers that support overprinting. Sometimes you must underline a column of numbers to denote a total and also underline the total to highlight it: 1234 1122 ---2356 ==== To print a single underline, use the underscore character and suppress line spacing. For example: WRITE PRINT-LINE FROM SINGLE-UNDERLINE-TOTAL BEFORE ADVANCING 0 LINES.
Producing Printed Reports 10.10 Solving Report Problems For example: WRITE PRINT-LINE FROM TOTAL-LINE BEFORE ADVANCING * * Move spaces over the items in the source print line * that are not to be bolded * MOVE SPACES TO ... WRITE PRINT-LINE FROM TOTAL-LINE BEFORE ADVANCING WRITE PRINT-LINE FROM TOTAL-LINE BEFORE ADVANCING WRITE PRINT-LINE FROM TOTAL-LINE. 10–90 Producing Printed Reports 0 LINES. (TOTAL-LINE) 0 LINES. 0 LINES.
11 Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms ACCEPT and DISPLAY statements are used to make low-volume data available to specified devices. You will find the following information useful: • Section 11.1 describes the use of the ACCEPT and DISPLAY statements for interactive I/O. • Section 11.2 explains how you can design an online video form similar to a printed form by using the Compaq extensions to the ACCEPT and DISPLAY statements . • Section 11.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.1 Using ACCEPT and DISPLAY for I/O On the OpenVMS Alpha operating system, you can assign a logical name to a file specification using the ASSIGN command (or the DEFINE command, with the arguments in reverse order): $ ASSIGN [ALLSTATUS]STATUS.LIS COB$LINEPRINTER ♦ If you use an environment variable or a logical name, you must define it appropriately for the ACCEPT or DISPLAY statement to succeed.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.1 Using ACCEPT and DISPLAY for I/O The following example illustrates the UPON phrase used in conjunction with DISPLAY: SPECIAL-NAMES. LINE-PRINTER IS ERROR-LOG . . . PROCEDURE DIVISION. . . . DISPLAY ERROR-COUNT, " phase 2 errors, ", ERROR-MSG UPON ERROR-LOG. 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions The extended Compaq COBOL options to the ACCEPT and DISPLAY statements provide video forms features.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions • ERASE LINE—Erase the entire specified line before accepting or displaying data at the specified or implied cursor position. • ERASE TO END OF SCREEN—Erase from the specified or implied cursor position to the end of the screen before accepting or displaying data at the specified cursor position.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Figure 11–2 Screen After the ERASE Statement Executes 1 2 3 4 5 6 7 8 12345678901234567890123456789012345678901234567890123456789012345678901234567890 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Employee number: ZK−6091−GE Example 11–2 Cursor Positioning IDENTIFICATION DIVISION. PROGRAM-ID. LOCATE. ENVIRONMENT DIVISION. DATA DIVISION.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Figure 11–3 Positioning the Data on Line 19, Column 5 1 2 3 4 5 6 7 8 12345678901234567890123456789012345678901234567890123456789012345678901234567890 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Employee name: ZK−6092−GE If you use LINE, but not COLUMN, data is accepted or displayed at column 1 of the specified line position.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions In Example 11–3, the PLUS phrase is used twice to show relative positioning, once with an integer, and once without. Figure 11–4 shows the results. Example 11–3 Using PLUS for Cursor Positioning IDENTIFICATION DIVISION. PROGRAM-ID. LINEPLUS. PROCEDURE DIVISION. A00-BEGIN. DISPLAY "Positioning Test" "Changing Test" "Adding Test" DISPLAY " " LINE 23 COLUMN STOP RUN.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Figure 11–5 Screen Display with Character Attributes 1 2 3 4 5 6 7 8 12345678901234567890123456789012345678901234567890123456789012345678901234567890 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Employee No.: Employee wage class: NAME SALARY: $ ZK−6093−GE Example 11–5 Using the CONVERSION Phrase IDENTIFICATION DIVISION. PROGRAM-ID. CONVERT.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Example 11–5 (Cont.) Using the CONVERSION Phrase DISPLAY "X(10) Test" LINE 8 ERASE LINE. ACCEPT DATA1A WITH CONVERSION PROTECTED REVERSED LINE 8 COLUMN 50. DISPLAY DATA1A REVERSED WITH CONVERSION LINE 8 COLUMN 65. DISPLAY "X(10) JUSTIFIED Test" LINE 10 ERASE LINE. ACCEPT DATA1B WITH CONVERSION PROTECTED REVERSED LINE 10 COLUMN 50.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Figure 11–6 Sample Run of Program CONVERT 1 2 3 4 5 6 7 8 12345678901234567890123456789012345678901234567890123456789012345678901234567890 to begin... begin... press press your your carriage carriage return return key key 1 to 2 3 4 5 6 7 8 X(10) Test 9 10 X(10) JUSTIFIED Test 11 12 Num edited Test (+++++9999.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions When you use the CONVERSION phrase with an ACCEPT numeric floatingpoint operand, Compaq COBOL converts input data to floating-point (COMP-1 or COMP-2 as appropriate). The converted result is then moved to the destination as if moving a numeric literal equivalent to the input data with the MOVE statement.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Figure 11–7 Accepting Data with the ON EXCEPTION Option 1 2 3 4 5 6 7 8 12345678901234567890123456789012345678901234567890123456789012345678901234567890 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Enter any number in this range: −999.999 to +999.999 1234.567− Valid range is: −999.999 to +999.999 PLEASE try again...
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions When you use the FILLER phrase with the NO BLANK phrase, the input field is filled with the filler character only after you have entered the first character. The PROTECTED SIZE phrase sets the size of the input field on the screen and allows you to change the size of the input field from the size indicated by the PICTURE phrase of the destination item.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Figure 11–8 Screen Display of NUM-DATA Using the PROTECTED Option 1 2 3 4 5 6 7 8 12345678901234567890123456789012345678901234567890123456789012345678901234567890 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Enter data item (NUM−DATA) but SIZE = 3: 1 999 1.1 .12 .
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions • There is a high probability that the default value is identical in most of the records, as where a constant (such as a state’s abbreviation) is used in a mailing list. When you use the DEFAULT phrase, the program executes as if the default value had been typed in when you press Return. However, the value is not automatically displayed on the screen.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Example 11–9 Using the DEFAULT Phrase IDENTIFICATION DIVISION. PROGRAM-ID. TRYDEF. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 DATA1A PIC 9(12). 01 NAME1A PIC XXXXX. 01 PRICEA PIC S99V99. 01 DATA123. 02 NAME1B PIC XXXXX. 02 PIC XX VALUE SPACES. 02 DATA1B PIC XXXXXXXXXXXX. 02 PIC XXX VALUE SPACES. 02 PRICEB PIC $99.99-.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Example 11–9 (Cont.) Using the DEFAULT Phrase A05-GET-DATA. ACCEPT NAME1A PROTECTED DEFAULT NAME-DEFAULT LINE PLUS COLUMN 15 ERASE TO END OF LINE. ACCEPT DATA1A PROTECTED DEFAULT "***[TBS]****" COLUMN 21. ACCEPT PRICEA PROTECTED WITH CONVERSION DEFAULT ZERO COLUMN 34. MOVE NAME1A TO NAME1B. MOVE DATA1A TO DATA1B. MOVE PRICEA TO PRICEB.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions 11.2.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Table 11–2 (Cont.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Table 11–2 (Cont.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Table 11–2 (Cont.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Example 11–10 Using the CONTROL KEY IN Phrase IDENTIFICATION DIVISION. PROGRAM-ID. SPECIAL. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. SYMBOLIC CHARACTERS CR-VAL CSI-VAL Ctrl-Z-VAL SS3-VAL TAB-VAL ESC ARE 14 156 27 144 10 28. DATA DIVISION. WORKING-STORAGE SECTION. * * The code returned will be the same regardless of * terminal type. * 01 CONTROL-KEY.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Example 11–10 (Cont.) Using the CONTROL KEY IN Phrase IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF CR DISPLAY "RETURN" LINE 10 COLUMN 5 ERASE LINE GO TO P1. TAB DISPLAY "\TAB" LINE 10 COLUMN 5 ERASE LINE GO TO P1. PF1 DISPLAY "PF1" LINE 10 COLUMN 5 ERASE LINE GO TO P1. PF2 DISPLAY "PF2" LINE 10 COLUMN 5 ERASE LINE GO TO P1.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Example 11–10 (Cont.) Using the CONTROL KEY IN Phrase DISPLAY "Not an allowable control key -" "press the Return key to continue" LINE 10 COLUMN 5 WITH BELL ERASE LINE. ACCEPT CONTROL-KEY. GO TO P1. P2. DISPLAY "Press the Return key to end this job" LINE 11 COLUMN 5 ERASE LINE. ACCEPT CONTROL KEY IN CONTROL-KEY LINE 12 COLUMN 5 ERASE LINE.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Figure 11–12 Screen Display of Program SPECIAL 1 2 3 4 5 6 7 8 12345678901234567890123456789012345678901234567890123456789012345678901234567890 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Press a directional arrow, PF, RETURN, TAB, or auxiliary keypad key (CTRL/Z stops loop) RIGHT−ARROW ZK−6100−GE 11.2.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Example 11–11 EDITING Phrase Sample Code . . . PROCEDURE DIVISION. A1000-BEGIN. OPEN I-O EMP-FILE. . . . B1000-MODIFY. DISPLAY "MODIFY EMPLOYEE INFORMATION FORM" ERASE SCREEN AT LINE 2 COLUMN 8. DISPLAY "Enter Employee Number : " AT LINE PLUS 2 COLUMN 8. ACCEPT EMP-KEY FROM LINE 4 COLUMN 32 PROTECTED WITH EDITING REVERSED DEFAULT IS CURRENT AT END STOP RUN. . . .
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.2 Designing Video Forms with ACCEPT and DISPLAY Statement Extensions Example 11–11 (Cont.) EDITING Phrase Sample Code ACCEPT DAY-NUM FROM LINE 6 COLUMN 27 PROTECTED WITH EDITING REVERSED DEFAULT IS CURRENT AT END STOP RUN. DISPLAY DAY-NUM AT LINE 6 COLUMN 57. ACCEPT YR-NUM FROM LINE 6 COLUMN 30 PROTECTED WITH EDITING REVERSED DEFAULT IS CURRENT AT END STOP RUN. DISPLAY YR-NUM AT LINE 6 COLUMN 60.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.3 Designing Video Forms with Screen Section ACCEPT and DISPLAY For example: SCREEN SECTION. 01 MENU-SCREEN BLANK SCREEN FOREGROUND-COLOR 7 BACKGROUND-COLOR 1. 02 MENU-SCREEN-2. 03 TITLE-BAR FOREGROUND-COLOR 7 BACKGROUND-COLOR 4. 04 LINE 1 PIC X(80) FROM EMPTY-LINE. 04 LINE 1 COLUMN 32 VALUE "Daily Calendar". See Section 11.3.1 for a description of the options available in the Screen Section. 3.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.3 Designing Video Forms with Screen Section ACCEPT and DISPLAY Table 11–4 (Cont.) Character Attribute Clauses for Screen Description Formats Clause Formats Function BLANK SCREEN 1, 2, 3 Clears the screen before displaying the screen item. BLANK WHEN ZERO[ES] 3 Replaces zeros with spaces when a screen item’s value is zero. BLINK 2, 3 Causes the displayed item to blink.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.3 Designing Video Forms with Screen Section ACCEPT and DISPLAY Table 11–5 Color Table Color Color Value Color Color Value Black 0 Red 4 Blue 1 Magenta 5 Green 2 Yellow/Brown 6 Cyan 3 White 7 11.3.1.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.3 Designing Video Forms with Screen Section ACCEPT and DISPLAY Screen Section Clause ACCEPT or DISPLAY Clause with Equivalent Effect REVERSE-VIDEO REVERSED SECURE WITH NO ECHO UNDERLINE UNDERLINED Differences There are also significant differences between the Screen Section and the nonScreen Section screen formats. With the Screen Section: • You can define screen items that wrap onto multiple lines.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.3 Designing Video Forms with Screen Section ACCEPT and DISPLAY screen (starting in the 60th column of the first line). Elsewhere, you could display the legend box, using the same screen description entry, at a different position on the screen, by choosing different LINE and COLUMN options with the DISPLAY statement. • The default value for an update screen item is the current value of the FROM or USING data item.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.3 Designing Video Forms with Screen Section ACCEPT and DISPLAY Example 11–12 (Cont.) Designing a Video Form for a Daily Calendar * * * Normal termination of the ACCEPT statement will result in a value of ’0’ in KEY1. When the user presses F10, the value in KEY1 will be ’1’ and FKEY-10 will be true. 01 CRT-STATUS. 03 KEY1 03 KEY2 88 FKEY-10 03 filler * * * 01 01 01 01 01 01 01 01 01 01 * * * * PIC X. PIC X. VALUE FKEY-10-VAL. PIC X.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.3 Designing Video Forms with Screen Section ACCEPT and DISPLAY Example 11–12 (Cont.) Designing a Video Form for a Daily Calendar 01 SCHEDULE-SCREEN BLANK SCREEN. 02 TITLE-BAR FOREGROUND-COLOR 7 BACKGROUND-COLOR 4. 03 LINE 1 PIC X(80) FROM EMPTY-LINE. 03 LINE 1 COLUMN 30 VALUE "Schedule Appointment". 02 FIELDS-TEXT FOREGROUND-COLOR 7 BACKGROUND-COLOR 1. 03 LINE 5 VALUE " Description of Appointment: ".
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.3 Designing Video Forms with Screen Section ACCEPT and DISPLAY Example 11–12 (Cont.) Designing a Video Form for a Daily Calendar * For brevity, the sample program includes complete code * for the "Schedule Appointment" screen only. A complete * program for a calendar would also include code for * displaying, canceling, and printing the day’s appointments. IF CURSOR-LINE = 7 DISPLAY "You selected Show Appointments" LINE 22.
Using ACCEPT and DISPLAY Statements for Input/Output and Video Forms 11.3 Designing Video Forms with Screen Section ACCEPT and DISPLAY Figure 11–14 MENU-SCREEN Output +------------------------------------------------------------------------------+ | Daily Calendar | | | | | | | | | | | | Show appointments for a day | | | | Schedule an appointment | | | | Cancel an appointment | | | | Print your appointments | | | | | | | | | | | | Use the arrow keys to move the cursor among menu items.
12 Interprogram Communication COBOL programs can communicate with each other, as well as with non-COBOL programs. Program-to-program communication is conducted by using one (or combinations) of the following: • The CALL statement • External data • cobcall routine • cobcancel routine • cobfunc routine 12.
Interprogram Communication 12.1 Multiple COBOL Program Run Units Example 12–1 Run Unit with Three Separately Compiled Programs IDENTIFICATION DIVISION. PROGRAM-ID. MAIN-PROGRAM. 1 . . . CALL SUB1. . . . IDENTIFICATION DIVISION. 2 PROGRAM-ID. SUB1. . . . CALL SUB2. . . . STOP RUN. END PROGRAM MAIN-PROGRAM EXIT PROGRAM. END PROGRAM SUB1. IDENTIFICATION DIVISION. 3 PROGRAM-ID. SUB2. . . . EXIT PROGRAM. END PROGRAM SUB2. Note A separately compiled program has a nesting level number of 1.
Interprogram Communication 12.1 Multiple COBOL Program Run Units Example 12–2 Run Unit with a Main Program and Two Contained Programs IDENTIFICATION DIVISION. PROGRAM-ID. MAIN-PROGRAM. 4 . . . CALL SUB1. . . . STOP RUN. IDENTIFICATION DIVISION. 5 PROGRAM-ID. SUB1. . . . CALL SUB2. EXIT PROGRAM. IDENTIFICATION DIVISION. 6 PROGRAM-ID. SUB2. . . . EXIT PROGRAM. END PROGRAM SUB2. END PROGRAM SUB1. END PROGRAM MAIN-PROGRAM.
Interprogram Communication 12.2 COBOL Program Attributes Example 12–3 Run Unit with Three Separately Compiled Programs, One with Two Contained Programs IDENTIFICATION DIVISION. PROGRAM-ID. MAIN-PROGRAM. 7 . . . CALL SUB1. CALL SUB2. . STOP RUN. IDENTIFICATION DIVISION. 8 PROGRAM-ID. SUB1. . . . CALL SUB3. EXIT PROGRAM. END PROGRAM SUB1. IDENTIFICATION DIVISION. 9 PROGRAM-ID. SUB2. . . . EXIT PROGRAM. END PROGRAM SUB2. END PROGRAM MAIN-PROGRAM. IDENTIFICATION DIVISION. PROGRAM-ID. SUB3. . . . CALL SUB4. . .
Interprogram Communication 12.2 COBOL Program Attributes When an INITIAL clause is not present, the status of the files and internal program data are the same as when the called program was exited. The initial attribute is attained by specifying the INITIAL clause in the program’s PROGRAM-ID paragraph. For example: IDENTIFICATION DIVISION. PROGRAM-ID. TEST-PROG INITIAL. 12.2.2 The EXTERNAL Clause Storage of data can be external or internal to the program in which the data is declared.
Interprogram Communication 12.3 Transferring Flow of Control Note A program cannot cancel itself nor can any program cancel the program that called it. In COBOL programs, to call a routine named SPECIALROUTINE from an overlying COBOL program you might use: MOVE "SPECIALROUTINE" TO ROUTINE-NAME. CALL ROUTINE-NAME. If you need to call SPECIALROUTINE from a program in another language, use cobcall or cobfunc. 12.3.
Interprogram Communication 12.3 Transferring Flow of Control Example 12–4 (Cont.) Execution Sequence of Nested CALL Statements BEGIN. DISPLAY " 1. MAINPROG has control first. DISPLAY " 2. MAINPROG transfers control to SUB1 DISPLAY " upon executing the following CALL. CALL "SUB1" DISPLAY "11. MAINPROG has control last. DISPLAY "12. MAINPROG terminates the entire image upon DISPLAY " execution of the STOP RUN statement. STOP RUN. IDENTIFICATION DIVISION.
Interprogram Communication 12.3 Transferring Flow of Control Example 12–5 Sequence of Messages Displayed When Example 12–4 Is Run 1. MAINPROG has control first. 2. MAINPROG transfers control to SUB1 upon executing the following CALL. 3. This is the entry point to SUB1. 4. SUB1 now has control. 5. SUB1 transfers control to SUB2. 6. This is the entry point to SUB2. 7. SUB2 now has control. 8. SUB2 returns control to SUB1 after executing the following EXIT PROGRAM statement. 9. SUB1 regains control 10.
Interprogram Communication 12.4 Accessing Another Program’s Data Division Figure 12–2 Transfer of Control Flow from a Main Program to Multiple Subprograms Sharing Execution Control from a Main Program to Multiple Subprograms IDENTIFICATION DIVISION. IDENTIFICATION DIVISION. IDENTIFICATION DIVISION. IDENTIFICATION DIVISION. PROGRAM−ID. MAINPROG. PROGRAM−ID. SUB. PROGRAM−ID. SUBA. PROGRAM−ID. SUBB. ENVIRONMENT DIVISION. ENVIRONMENT DIVISION. ENVIRONMENT DIVISION. ENVIRONMENT DIVISION. DATA DIVISION.
Interprogram Communication 12.4 Accessing Another Program’s Data Division Figure 12–3 Accessing Another Program’s Data Division IDENTIFICATION DIVISION. IDENTIFICATION DIVISION. PROGRAM−ID. MAINPROG. PROGRAM−ID. SUB. ENVIRONMENT DIVISION. ENVIRONMENT DIVISION. DATA DIVISION. DATA DIVISION. WORKING−STORAGE SECTION. LINKAGE SECTION. 01 01 01 01 01 01 01 01 A B C D PICTURE PICTURE PICTURE PICTURE X. 9. XX. 99. PROCEDURE DIVISION. START−UP. 1 2 . . . CALL "SUB" USING A, B, C, D. . . 4 .
Interprogram Communication 12.4 Accessing Another Program’s Data Division • On OpenVMS, DESCRIPTOR—The address of (pointer to) the data item’s descriptor is passed to the called program. ♦ (Note that BY DESCRIPTOR is not supported by Tru64 UNIX. See Compaq COBOL Reference Manual, the CALL statement.) • OMITTED—A value equivalent to BY VALUE 0 is passed to the called program. Note that OMITTED does not change the default mechanism.
Interprogram Communication 12.4 Accessing Another Program’s Data Division Values can also be returned through the BY REFERENCE parameter in the USING phrase. However, the GIVING phrase uses the return value by immediate value mechanism. Use of this mechanism requires that the GIVING result (ITEMC) be an elementary integer numeric data item with COMP, COMP-1, or COMP-2 usage and no scaling positions.
Interprogram Communication 12.5 Communicating with Contained COBOL Programs Figure 12–4 Defining Data Names in the Linkage Section IDENTIFICATION DIVISION. IDENTIFICATION DIVISION. PROGRAM−ID. MAINPROG. PROGRAM−ID. SUB. ENVIRONMENT DIVISION. ENVIRONMENT DIVISION. DATA DIVISION. DATA DIVISION. FILE SECTION. FILE SECTION. 01 FILE−RECORD PICTURE ... WORKING−STORAGE SECTION. WORKING−STORAGE SECTION. 01 WORK−RECORD PICTURE ... LINKAGE SECTION. 01 F−RECORD PICTURE ... 01 W−RECORD PICTURE ...
Interprogram Communication 12.5 Communicating with Contained COBOL Programs 12.5.1 The COMMON Clause The COMMON clause is a program attribute that can be applied to a directly contained program. The COMMON clause is a means of overriding normal scoping rules for program names, namely that a program that does not possess the common attribute and that is directly contained within another program can be referenced only by statements included in that containing program.
Interprogram Communication 12.5 Communicating with Contained COBOL Programs PROG-MAIN (1 ) can call PROG-NAME-B (2 ) because PROG-MAIN directly contains PROG-NAME-B. PROG-NAME-B (2 ) can call PROG-NAME-D (3 ) because PROG-NAME-B directly contains PROG-NAME-D.
Interprogram Communication 12.5 Communicating with Contained COBOL Programs IDENTIFICATION DIVISION. PROGRAM-ID. MAINPROG. . . . DATA DIVISION. FILE SECTION. FD CUSTOMER-FILE GLOBAL . . . Any special registers associated with a GLOBAL file are also global. 12.5.2.3 Sharing USE Procedures The USE statement specifies declarative procedures to handle input/output errors. It also can specify procedures to be executed before the program processes a specific report group.
Interprogram Communication 12.5 Communicating with Contained COBOL Programs At run time, two special precedence rules apply for the selection of a declarative when programs are contained in other programs. In applying these two rules, only the first qualifying declarative is selected for execution. The order of precedence for the selection of a declarative follows: Rule 1 —The declarative that executes first is the declarative within the program containing the statement that caused the qualifying condition.
Interprogram Communication 12.5 Communicating with Contained COBOL Programs Figure 12–7 Executing Declaratives Within Contained Programs (Rule 2) 1 2 3 IDENTIFICATION DIVISION. PROGRAM−ID. MAIN−PROGRAM. . . . PROCEDURE DIVISION. DECLARATIVES. FILEA−OUTPUT−PROBLEM SECTION. USE GLOBAL AFTER STANDARD FILEB−PROBLEM SECTION. USE GLOBAL AFTER STANDARD . . . IDENTIFICATION DIVISION. PROGRAM−ID. USE−PROGRAM. . . . PROCEDURE DIVISION. DECLARATIVES. FILEA−NAME−PROBLEM SECTION.
Interprogram Communication 12.
Interprogram Communication 12.6 Calling Compaq COBOL Programs from Other Languages Example 12–7 Calling a COBOL Program from C #include #include "cobfunc.
Interprogram Communication 12.6 Calling Compaq COBOL Programs from Other Languages Example 12–9 COBOL Called Program "CALLEDFROMC" IDENTIFICATION DIVISION. PROGRAM-ID. CALLEDFROMC. DATA DIVISION. WORKING-STORAGE SECTION. 01 TEST-RESET PIC X(10) VALUE "OFF". 01 RETVAL PIC 9(5) COMP VALUE 357. LINKAGE SECTION. 01 ARG1 PIC X(10). 01 ARG2 PIC 9(4). 01 ARG3 PIC 9(5) COMP. PROCEDURE DIVISION USING ARG1 ARG2 ARG3 GIVING RETVAL. P0. DISPLAY "In CALLEDFROMC".
Interprogram Communication 12.6 Calling Compaq COBOL Programs from Other Languages Example 12–10 C Program Using cobcall, cobfunc, and cobcancel /* File: #include #include #include void int int progc.c */ "stdlib.h" "stdio.h" "string.
Interprogram Communication 12.6 Calling Compaq COBOL Programs from Other Languages Example 12–11 (Cont.) COBOL Called Program "PROGCOB" data division. working-storage section. 01 retVal pic 9(9) comp value 987654321. 01 myVal pic 9(9) comp value 0. 01 arg1 pic 9(9) comp value 0. 01 arg2 pic 9(9) comp value 0. 01 arg3 pic 9(9) comp value 0. 01 arg4 pic 9(9) comp value 0. arg1 arg2 arg3 arg4 giving retVal. p0. display " +------------------- From COBOL --------------------".
Interprogram Communication 12.6 Calling Compaq COBOL Programs from Other Languages [Windows NT] c:\> c:\> c:\> c:\> cobol -c progmain.cob progcob.cob cl -c progc.c cobol progmain.obj progcob.obj progc.obj (*) progmain The order of listing at (*) is fundamental.
Interprogram Communication 12.
Interprogram Communication 12.7 Calling Non-COBOL Programs from Compaq COBOL Example 12–12 (Cont.) Calling a Fortran Program from a COBOL Program DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT-NUMBER. 03 INTEGER PIC 9(5). 03 DEC-POINT PIC X(1). 03 DECIMAL PIC 9(8). 01 WORK-NUMBER. 03 INTEGER PIC 9(5). 03 DECIMAL PIC 9(8). 01 WORK-NUMBER-A REDEFINES WORK-NUMBER PIC 9(5)V9(8). 01 DISPLAY-NUMBER PIC ZZ,ZZ9.9999. PROCEDURE DIVISION. STARTER SECTION. SBEGIN. MOVE SPACES TO INPUT-NUMBER.
Interprogram Communication 12.7 Calling Non-COBOL Programs from Compaq COBOL Sample Run of GETROOT (OpenVMS) $ RUN GETROOT Return Enter number (with decimal point): 25. Return The square root is: 5.000000 5.0000 Enter number (with decimal point): )HELLO Return ** INVALID ARGUMENT FOR SQUARE ROOT Enter number (with decimal point): 1000000. Return The square root is: 1000.000000 1,000.0000 Enter number (with decimal point): 2. Return The square root is: 1.414214 1.
Interprogram Communication 12.7 Calling Non-COBOL Programs from Compaq COBOL Example 12–14 (Cont.) Calling a BASIC Program from a COBOL Program DISPLAY "Enter 3 digit mortgage/rent". ACCEPT MORTGAGE-RENT. MOVE MORTGAGE-RENT TO C-MORTGAGE-RENT. DISPLAY "Enter 2 digit years employed by current employer". ACCEPT YEARS-EMPLOYED. MOVE YEARS-EMPLOYED TO C-YEARS-EMPLOYED. DISPLAY "Enter 2 digit years at present address". ACCEPT YEARS-AT-ADDRESS. MOVE YEARS-AT-ADDRESS TO C-YEARS-AT-ADDRESS.
Interprogram Communication 12.7 Calling Non-COBOL Programs from Compaq COBOL 12.7.3 Calling a C Program Calling a program or routine that is written in C allows you to take advantage of features of that language. Example 12–16 features a C routine that can be called from a COBOL program. Example 12–16 has two global external variables, _ _Argc and **_ _Argv. Note that **_ _Argv[ ] has an extra level of indirection; it is a pointer to a pointer to an array.
Interprogram Communication 12.8 Special Considerations for Interprogram Communication 12.8 Special Considerations for Interprogram Communication Certain situations require special consideration when your programs will communicate with other programs. 12.8.1 CALL and CANCEL Arguments The CALL verb with a data item and the CANCEL verb with either a literal or a data item are implemented by a Run-Time Library routine that finds the appropriate program.
Interprogram Communication 12.8 Special Considerations for Interprogram Communication • upper—Forces all external data names, PROGRAM-ID names, and CALL literals to be uppercase. • as_is—The case of literals used in CALL literals is taken as is. This is useful when you are calling subroutines with mixed case (for example, GetStatusRoutine). Data items defined with EXTERNAL will be treated as lowercase. PROGRAM-ID names will be treated as uppercase.
Interprogram Communication 12.8 Special Considerations for Interprogram Communication PROGRAM ID JOB1. CALL "Job2." END-PROGRAM JOB1. PROGRAM ID JOB2. END-PROGRAM JOB2. With the lower(case) and upper(case) options on the -names flag and /names= option, the program JOB2 will be called by JOB1. However, with the as_is option, the linker will look to resolve a call to ‘‘Job2’’—which in this case is just as different as if it were named job3, WORLD99, or any other routine name other than JOB2. ♦ 12.8.
13 Using Compaq COBOL in the Alpha Common Language Environment The Compaq COBOL compiler is part of the common language environment. This environment defines certain calling procedures and guidelines that allow you to call programs written in different languages or prewritten system routines from Compaq COBOL.
Using Compaq COBOL in the Alpha Common Language Environment 13.1 Routines, Procedures, and Functions For more information on system routines on OpenVMS Alpha, refer to the OpenVMS RTL Library (LIB$) Manual and the OpenVMS System Services Reference Manual. ♦ 13.
Using Compaq COBOL in the Alpha Common Language Environment 13.2 The OpenVMS Alpha Calling Standard (OpenVMS) Table 13–1 (Cont.
Using Compaq COBOL in the Alpha Common Language Environment 13.3 OpenVMS Alpha System Routines (OpenVMS) 13.3.1 OpenVMS Alpha Run-Time Library Routines The OpenVMS Alpha Run-Time Library provides commonly used routines that perform a wide variety of functions. These routines are grouped according to the types of tasks they perform, and each group has a prefix that identifies those routines as members of a particular OpenVMS Alpha Run-Time Library facility.
Using Compaq COBOL in the Alpha Common Language Environment 13.3 OpenVMS Alpha System Routines (OpenVMS) Table 13–3 (Cont.
Using Compaq COBOL in the Alpha Common Language Environment 13.4 Calling Routines Although you can call most system routines as a procedure call, it is recommended that you do so only when the system routine does not return a value. By checking the condition value, you can avoid errors. The OpenVMS Alpha documentation on system services and Run-Time Library routines contains descriptions of each system routine and a description of the condition values returned.
Using Compaq COBOL in the Alpha Common Language Environment 13.4 Calling Routines Once you have determined which arguments you need, read the argument description for information on how to call that system routine. For example, the system routine LIB$STAT_TIMER provides the following description of the code argument: code OpenVMS Usage: type: access: mechanism: longword_signed longword integer (signed) read only by reference Code that specifies the statistic to be returned.
Using Compaq COBOL in the Alpha Common Language Environment 13.4 Calling Routines Remember, you must specify the name of the routine being called and all parameters required for that routine. Make sure the data types and passing mechanisms for the parameters you are passing coincide with those defined in the routine. 13.4.4 Calling System Routines (OpenVMS) The basic steps for calling system routines are the same as those for calling any routine.
Using Compaq COBOL in the Alpha Common Language Environment 13.4 Calling Routines Table 13–4 (Cont.) COBOL Implementation of the OpenVMS Alpha Data Types (OpenVMS) OpenVMS Alpha Data Type COBOL Definition ast_procedure 01 AST-PROC PIC 9(9) COMP.2 boolean 01 BOOLEAN-VALUE PIC 9(9) COMP.2 byte_signed NA . . . PIC X.1 byte_unsigned NA . . . PIC X.1 channel 01 CHANNEL PIC 9(4) COMP.2 char_string 01 CHAR-STRING PIC X to PIC X(65535). complex_number NA . . . PIC X(n) where n is length.
Using Compaq COBOL in the Alpha Common Language Environment 13.4 Calling Routines Table 13–4 (Cont.) COBOL Implementation of the OpenVMS Alpha Data Types (OpenVMS) OpenVMS Alpha Data Type COBOL Definition item_list_3 01 ITEM-LIST-3. 02 ITEM-LIST OCCURS n TIMES. 04 BUF-LEN PIC S9(4) COMP. 04 ITEM-CODE PIC S9(4) COMP. 04 BUFFER-ADDRESS PIC S9(9) COMP. 04 LENGTH-ADDRESS PIC S9(9) COMP. 02 TERMINATOR PIC S9(9) COMP VALUE 0. item_list_pair 01 ITEM-LIST-PAIR. 02 ITEM-LIST OCCURS n TIMES.
Using Compaq COBOL in the Alpha Common Language Environment 13.4 Calling Routines Table 13–4 (Cont.
Using Compaq COBOL in the Alpha Common Language Environment 13.4 Calling Routines As stated earlier, this example does not pass a value for the optional handleaddress argument. The FORMAT will describe optional arguments in one of two ways: [,optional-argument] or ,[optional-argument] If the comma appears outside of the brackets, you must pass a zero by value or use the OMITTED phrase to indicate the place of the omitted argument.
Using Compaq COBOL in the Alpha Common Language Environment 13.4 Calling Routines Even when you use the default passing mechanism, you can include the passing mechanism that is used. For example, to call LIB$STAT_TIMER, you can use either of the following definitions: CALL "LIB$STAT_TIMER" USING ARG-CODE, ARG-VALUE GIVING RET-STATUS. CALL "LIB$STAT_TIMER" USING BY REFERENCE ARG-CODE, ARG-VALUE GIVING RET-STATUS. 13.4.4.
Using Compaq COBOL in the Alpha Common Language Environment 13.4 Calling Routines For example: 01 SS$_NORMAL PIC S9(5) COMP VALUE EXTERNAL SS$_NORMAL . . . CALL "LIB$STAT_TIMER" USING ARG-CODE, ARG-VALUE GIVING RET-STATUS. IF RET-STATUS NOT EQUAL SS$_NORMAL... Because all success codes have odd values, you can check a return status for any success code.
Using Compaq COBOL in the Alpha Common Language Environment 13.4 Calling Routines 13.4.5.1 Library Return Status and Condition Value Symbols (OpenVMS) Library return status and condition value symbols have the following general form: fac$_abcmnoxyz where: fac is a 2- or 3-letter facility symbol (LIB, MTH, STR, OTS, BAS, COB, FOR, SS). abc are the first 3 letters of the first word of the associated message. mno are the first 3 letters of the next word.
Using Compaq COBOL in the Alpha Common Language Environment 13.5 Establishing and Removing User Condition Handlers (OpenVMS) new-handler Specifies the name of the routine to be set up as a condition handler. old-handler Receives the address of the previously established condition handler. The GIVING phrase is optional. LIB$ESTABLISH moves the address of the condition-handling routine into the appropriate process context and returns the address of a previously established condition handler.
Using Compaq COBOL in the Alpha Common Language Environment 13.5 Establishing and Removing User Condition Handlers (OpenVMS) The condition handler is written as a subprogram that returns a result. The result indicates whether or not the condition handler handled the exception. Note that space must be allocated in the LINKAGE SECTION for the signal and mechanism arrays. The mechanism array always contains five elements, but the signal array varies according to the number of additional arguments.
Using Compaq COBOL in the Alpha Common Language Environment 13.5 Establishing and Removing User Condition Handlers (OpenVMS) Example 13–1 (Cont.) User-Written Condition Handler WORKING-STORAGE SECTION. 01 SS_HAND PIC 01 SS$_SSFAIL PIC 01 SS$_RESIGNAL PIC 01 MSGLEN PIC 01 MSGID PIC 01 ERRMSG PIC 01 STAT PIC S9(9) COMP. S9(9) COMP VALUE EXTERNAL SS$_SSFAIL. S9(9) COMP VALUE EXTERNAL SS$_RESIGNAL. S9(4) COMP. S9(9) COMP. X(80). S9(9) COMP. LINKAGE SECTION. 01 SIGNAL_ARRAY.
Using Compaq COBOL in the Alpha Common Language Environment 13.
Using Compaq COBOL in the Alpha Common Language Environment 13.6 Examples (OpenVMS) Example 13–3 Using the SYS$SETDDIR System Service (OpenVMS) 01 DIRECTORY PIC X(24) VALUE "[MYACCOUNT.SUBDIRECTORY]". 01 STAT PIC S9(9) COMP. . . . CALL "SYS$SETDDIR" USING BY DESCRIPTOR DIRECTORY OMITTED OMITTED GIVING STAT. Example 13–4 Using $ASCTIM (OpenVMS) IDENTIFICATION DIVISION. PROGRAM-ID. CALLTIME.
Using Compaq COBOL in the Alpha Common Language Environment 13.6 Examples (OpenVMS) Example 13–5 Sample Run of CALLTIME (OpenVMS) CALL SYS$ASCTIM DATE/TIME 11-AUG-2000 09:34:33.45 LENGTH OF RETURNED = 0023 The following example shows how to call the procedure that enables and disables detection of floating-point underflow (LIB$FLT_UNDER) from a COBOL program. The format of the LIB$FLT_UNDER procedure is explained in the OpenVMS RTL Library (LIB$) Manual. WORKING-STORAGE SECTION.
Using Compaq COBOL in the Alpha Common Language Environment 13.6 Examples (OpenVMS) Example 13–6 Using LIB$K_* and LIB$_* Symbols (OpenVMS) identification division. program-id. SETSYM. environment division. data division. working-storage section. 01 LOCAL-SYM pic S9(9) comp value external LIB$K_CLI_LOCAL_SYM. 01 GLOBAL-SYM pic S9(9) comp value external LIB$K_CLI_GLOBAL_SYM. 01 COND-VAL pic S9(9) comp. 88 COND-NORMAL value external SS$_NORMAL. 88 COND-AMBSYMDEF value external LIB$_AMBSYMDEF.
14 Using the REFORMAT Utility The REFORMAT Utility converts source programs between terminal format and conventional ANSI format. Consider the two formats and their characteristics: • Terminal format eliminates the line-number and identification fields of ANSI format and allows horizontal tab characters and short lines. It saves disk space and decreases compile time. • Conventional ANSI format produces source programs compatible with the reference format as defined in the ANSI-85 COBOL Standard.
Using the REFORMAT Utility 14.1 Running the REFORMAT Utility REFORMAT REFORMAT REFORMAT REFORMAT REFORMAT REFORMAT REFORMAT REFORMAT REFORMAT REFORMAT REFORMAT REFORMAT REFORMAT REFORMAT REFORMAT REFORMAT - Enter Y for ANSI-to-terminal conversion, or Enter N (default) for terminal-to-ANSI conversion. Enter ^Z to exit. ANSI-to-terminal format conversion mode [ Y / [N] ]? n Terminal-to-ANSI format selected Terminal-format input file spec : myprog.cob ANSI-format output file spec: myprog2.
Using the REFORMAT Utility 14.2 ANSI-to-Terminal Format Conversion • Placing the converted code in positions 1 to the end of the line, thereby creating a terminal format line Note When you convert programs that contain continued nonnumeric literals you should examine those literals to see if they require any changes. (This should occur only when going from ANSI format to terminal format.) 14.
Using the REFORMAT Utility 14.3 Terminal-to-ANSI Format Conversion is a text processor and does not perform the level of checking required by lines such as these. You detect this error during a compile operation. 14.4 REFORMAT Error Messages If any of your responses to the prompts are incorrect, REFORMAT displays error messages. It replaces the parentheses and the parenthetical text with the appropriate format type you specified.
Using the REFORMAT Utility 14.4 REFORMAT Error Messages To process another file, type a new input file specification and continue the prompting message sequence. To end execution, type Ctrl/Z (on OpenVMS systems) or CTRL/D (on Tru64 UNIX systems).
15 Optimizing Your Compaq COBOL Program You can specify optimization and data alignment on the COBOL compiler comnp15l.
Optimizing Your Compaq COBOL Program 15.1 Specifying Optimization on the Compiler Command Line The -tune flag has the following form: -tune keyword ♦ The -tune flag is the equivalent of the /OPTIMIZE=TUNE qualifier. On Windows NT systems, /OPTIMIZE and /TUNE specify optimization. The /OPTIMIZE option has the following form: /OPTIMIZE[=n] ♦ The /TUNE option has the following form: /TUNE[=keyword] On all systems, n is a number ranging from 0 to 4, specifying the level of optimization.
Optimizing Your Compaq COBOL Program 15.1 Specifying Optimization on the Compiler Command Line • EV6—Generates and schedules code for the 21264 chip implementation that uses the following extensions to the base Alpha instruction set: BWX (Byte/Word manipulation) and MAX (Multimedia) instructions, square root and FIX (Floating-point convert) instructions, and CIX (Count) instructions.
Optimizing Your Compaq COBOL Program 15.1 Specifying Optimization on the Compiler Command Line • EV56—Generates code for some 21164 chip implementations that use the byte and word manipulation instruction extensions of the Alpha architecture. Programs compiled with the EV56 option may incur emulation overhead on EV4 and EV5 processors, but will still run correctly on OpenVMS Version 7.1 (or later) systems.
Optimizing Your Compaq COBOL Program 15.1 Specifying Optimization on the Compiler Command Line On OpenVMS Alpha systems, in general, specify /NOOPTIMIZE if you specify /DEBUG when you compile a program.
Optimizing Your Compaq COBOL Program 15.
Optimizing Your Compaq COBOL Program 15.3 Using COMP Data Items for Speed SCA and LSE The Source Code Analyzer (SCA) can help discover program interdependencies as you contemplate changes. For example, if it is proposed that an item declared COMP-3 be changed, SCA can quickly and easily find all the references to that item. If SCA is used in conjunction with the Language-Sensitive Editor (LSE), LSE can bring up buffers in your editing session with each of the references.
Optimizing Your Compaq COBOL Program 15.4 Other Ways to Improve the Performance of Operations on Numeric Data intermediate data items will have very large PICTUREs, which will adversely affect performance. If you can break complex arithmetic expressions into two or more simpler expressions, performance can be greatly improved. Try to break expressions to make any divide or exponentiation operation the last operation in the subexpression.
Optimizing Your Compaq COBOL Program 15.5 Choices in Procedure Division Statements 15.5.2 Using Indexing Instead of Subscripting Using index names for table handling is generally more efficient than using PACKED-DECIMAL or numeric DISPLAY subscripts, since the compiler declares index names as binary data items. Subscript data items described in the Working-Storage Section as binary items are as efficient as index items.
Optimizing Your Compaq COBOL Program 15.5 Choices in Procedure Division Statements 15.5.5 Minimizing USE Procedures with LINKAGE SECTION References Compaq COBOL can perform certain optimizations if a program unit does not contain USE procedures that reference LINKAGE SECTION items.
Optimizing Your Compaq COBOL Program 15.6 I/O Operations Specifying APPLY PREALLOCATION preallocates noncontiguous disk blocks. When you specify the CONTIGUOUS-BEST-TRY phrase, the I/O system makes up to three attempts to allocate as many contiguous disk blocks as it can; it then preallocates remaining blocks noncontiguously. The CONTIGUOUS-BEST-TRY phrase minimizes disk space fragmentation and gives better system throughput than CONTIGUOUS.
Optimizing Your Compaq COBOL Program 15.6 I/O Operations Each WRITE or REWRITE statement can cause an I/O operation. The APPLY DEFERRED-WRITE clause permits writes to a file only when the buffer is full. Reducing the number of WRITE operations reduces file access time. However, the APPLY DEFERRED-WRITE clause can affect file integrity: records in the I/O buffer are not written to the file if the system crashes or the program aborts. DEFERRED-WRITE is very useful on write-shared files. 15.6.1.
Optimizing Your Compaq COBOL Program 15.6 I/O Operations 15.6.3 Sharing Record Areas The compiler allocates unique storage space in the Data Division for each file’s current record area. Transferring records between files requires an intermediate buffer area and adds to a program’s processing requirements. To reduce address space and processing overhead, files can share current record areas. Specify the SAME RECORD AREA clause in the I-O-CONTROL paragraph of the Environment Division.
Optimizing Your Compaq COBOL Program 15.6 I/O Operations Figure 15–1 Sharing Record Areas Program with Shared Record Area Program Without Shared Record Area I−O−CONTROL. SAME RECORD AREA FOR INP−FILE OUT−FILE. PROCEDURE DIVISION. . . . READ INP−FILE ... . . . MOVE INP−REC TO OUT−REC. WRITE OUT−REC ... Process Without Shared Areas . . . PROCEDURE DIVISION. . . . READ INP−FILE ... . . . WRITE OUT−REC ...
Optimizing Your Compaq COBOL Program 15.6 I/O Operations 15.6.4 Using COMP Unsigned Longword Integers The compiler generates the most efficient code to process the following clauses if a COMP unsigned longword integer (that is, PIC 9(9) COMP) is used in those cases where a variable is needed: RELATIVE KEY DEPENDING ON LINAGE IS WITH FOOTING AT LINES AT TOP LINES AT BOTTOM ADVANCING LINES 15.
Optimizing Your Compaq COBOL Program 15.7 Optimizing File Design (OpenVMS) FILE SECTION. FD FILE-A BLOCK CONTAINS 5 RECORDS. 01 FILE-A-REC PIC X(64). . . . By contrast, for magnetic tape, the program code entirely controls blocking. Hence, efficiency of the program and the file depends on the programmer’s care with magnetic-tape blocking. 15.7.2 Relative Files I/O optimization of a relative file depends on four concepts: • Maximum record number—The highest numbered record written to a relative file.
Optimizing Your Compaq COBOL Program 15.7 Optimizing File Design (OpenVMS) 15.7.2.3 Bucket Size A bucket’s size is from 1 to 63 blocks. A large bucket improves sequential access to a relative file. You can prevent wasted space between the last cell and the end of a bucket by specifying a bucket size that is a multiple of cell size.
Optimizing Your Compaq COBOL Program 15.7 Optimizing File Design (OpenVMS) To improve I/O access time: ( 1 ) specify a small bucket size, and ( 2 ) use the BLOCK CONTAINS n RECORDS clause to specify the number of records (cells) in each bucket. This example creates buckets that contain eight records. FD A-FILE RECORD CONTAINS 60 CHARACTERS BLOCK CONTAINS 8 RECORDS. . . . In the preceding example, the bucket size is one 512-byte block.
Optimizing Your Compaq COBOL Program 15.7 Optimizing File Design (OpenVMS) 15.7.3 Indexed Files An indexed file contains data records and pointers to facilitate record access. All data records and record pointers are stored in buckets. A bucket contains an integral number of contiguous, 512-byte blocks. The number of blocks is the bucket size. Every indexed file must have a primary key, a field in the record description that contains a value for each record.
Optimizing Your Compaq COBOL Program 15.7 Optimizing File Design (OpenVMS) A data level bucket may not be large enough to contain a new record. In this case, the I/O system inserts a new bucket in the chain, moving enough records from the old bucket to preserve the key value sequence. This is known as a bucket split. Data bucket splits can cause index bucket splits. 15.7.3.
Optimizing Your Compaq COBOL Program 15.7 Optimizing File Design (OpenVMS) For each record moved, a 7-byte pointer to the new record location remains in the original bucket. Thus, bucket splits can accumulate overhead and possibly reduce usable space so much that the original bucket can no longer receive records. Record deletions can also accumulate storage overhead. However, most of the space is available for reuse. There are several ways to minimize overhead accumulation.
Optimizing Your Compaq COBOL Program 15.7 Optimizing File Design (OpenVMS) Total record space is (100 + 7) * 5 TOTAL = 535 bytes (Record size is 100 bytes, record overhead is 7 bytes for each of 5 records) = 550 bytes Because blocks are 512 bytes long, and buckets are always an integral number of blocks, the smallest bucket size possible (the system default) in this case is two blocks. The system, however, puts in as many records as fit into each bucket.
Optimizing Your Compaq COBOL Program 15.7 Optimizing File Design (OpenVMS) • Index records: Record size = key size +3 If a file has more than 65,536 blocks, the 3-byte index record overhead could increase to 5 bytes. Use these calculations to determine SIDR record length: • No duplicates allowed: Record size • = key size +9 Duplicates allowed: = Record size key size +8+5 3( number of duplicate records) Note Bucket packing efficiency determines how well bucket space is used.
Optimizing Your Compaq COBOL Program 15.7 Optimizing File Design (OpenVMS) Continue calculating index depth until you reach the root level—that is, when the number of buckets needed to address the buckets from the previous level equals 1.
Optimizing Your Compaq COBOL Program 15.7 Optimizing File Design (OpenVMS) 15.7.3.3 Caching Index Roots The system requires at least two buffers to process an indexed file: one for a data bucket, the other for an index bucket. In fact, a data buffer and an index buffer are needed for every level of indexing available in the file (a fact that is not visible to the COBOL program, because the minimum amount of space is always allocated). Each buffer is large enough to contain a single bucket.
Managing Memory and Data Access 16.1 Managing Memory Granularity granularity for best performance if you are sure the processes never make concurrent updates within the same aligned quadword. To successfully use byte/word granularity, you need to consider at least four important restrictions: • An EV56 or higher CPU is necessary for byte/word granularity. • LIBOTS.EXE support for byte/word granularity is necessary if PIC X support is needed. However, LIBOTS.EXE Version 1.3 on OpenVMS Alpha Version 7.
Managing Memory and Data Access 16.1 Managing Memory Granularity 19 20 21 22 23 24 if a1 if a2 if a3(1:1) if a4 if a5(2) stop run. not not not not not = = = = = 1 2 "c" 4 5 display display display display display "?1". "?2". "?3 ". "?4". "?5". 16.2 Using the VOLATILE Compiler Directive VOLATILE directives offer flexibility and selectivity: they alter the current storage of certain data items by specifying new storage information from within the program source.
Managing Memory and Data Access 16.
Managing Memory and Data Access 16.3 Aligning Data for Performance and Compatibility In addition to the primary goal of optimum performance, specifying data alignment offers the following advantages: • Ease of use and conversion—You might need to make a minimal number of changes to existing source files before compiling them with the Compaq COBOL compiler. In some cases, all you need to do is specify the -align flag or the /ALIGNMENT qualifier with or without the padding option when you compile.
Managing Memory and Data Access 16.4 Using Alignment Directives, Qualifiers, and Flags 16.4 Using Alignment Directives, Qualifiers, and Flags Alignment directives offer flexibility and selectivity: they alter the current alignment by specifying new alignment information from within the source program.
Managing Memory and Data Access 16.4 Using Alignment Directives, Qualifiers, and Flags Table 16–2 Alignment and Padding Order of Precedence Compiler Directives Command line Qualifier and Option No Directive in Effect *DC SET ALIGNMENT *DC SET PADALIGN *DC SET NOALIGN (none) None Align elementary data items. Align and pad elementary data items and structures. None /ALIGNMENT Align elementary data items. Align elementary data items. Align and pad elementary data items and structures.
Managing Memory and Data Access 16.4 Using Alignment Directives, Qualifiers, and Flags Example 16–1 Using *DC SET ALIGNMENT Directives . 1 . . *DC SET ALIGNMENT 2 01 comp-group. 02 cg-x1 pic x. 02 cg-c1 pic 9(1) comp. *DC SET NOALIGNMENT 3 01 comp-group-2. 02 cg-x2 pic x. 02 cg-c2 pic 9(1) comp. *DC END-SET ALIGNMENT 4 01 comp-group-3. 02 cg-x3 pic x. 02 cg-c3 pic 9(1) comp. *DC END-SET ALIGNMENT 5 01 comp-group-4. 02 cg-x4 pic x. 02 cg-c4 pic 9(1) comp.
Managing Memory and Data Access 16.4 Using Alignment Directives, Qualifiers, and Flags • The effects of the SYNCHRONIZED clause, the alignment command-line option, and the SET ALIGNMENT directive on elementary data alignment are identical. Example 16–2 through Example 16–6 show a comparison of the use and results of several alignment cases. They are applicable to both Tru64 UNIX and OpenVMS Alpha.
Managing Memory and Data Access 16.4 Using Alignment Directives, Qualifiers, and Flags Example 16–3 shows the differences in the actions of /NOALIGN, /ALIGN and -align, and /ALIGN=PADDING and -align pad on the internal alignments of data fields within COBOL data structures in the OpenVMS Alpha and Tru64 UNIX environments. The program fragment in Example 16–3 was extracted from a COBOL program that was compiled three times on Compaq COBOL, using the following qualifiers for each compilation: 1.
Managing Memory and Data Access 16.
Managing Memory and Data Access 16.4 Using Alignment Directives, Qualifiers, and Flags Byte Layout for Example 16–5: |REC1 | |FLD1 |FLD2 |FLD3 | |FLD1-1 |FLD1-2 | |*| |FLD3-2 |FLD3-3 | | | | | |f f f| | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1 5 12 17 21 25 Begin byte number (starting with 0) Record length is 29 bytes. Notes: The asterisk (*) designates FLD3-1.
Managing Memory and Data Access 16.4 Using Alignment Directives, Qualifiers, and Flags 3. These three pad bytes bring FLD3 up to: 16 = 4*4 bytes 4. The total number of bytes in the record is now: 36 = 12 + 8 + 16 bytes 5. *, p, f apply in the same way as for /ALIGN without PADDING.
A Compiler Implementation Specifications The following list summarizes the specifications and restrictions for the Compaq COBOL compiler. The compiler issues diagnostic messages whenever you exceed its design parameters. • Run-time storage (generated object code and data) for COBOL programs cannot exceed 2,147,483,647 bytes. • The length of an FD’s record cannot exceed 32,767 bytes for a sequential file, 32,234 bytes for an indexed file, or 32,255 bytes for a relative file.
Compiler Implementation Specifications • The value of an integer in the WINDOW option of the APPLY clause must be from 0 to 127, inclusive, or equal to 255. • The value of the integer in the RESERVE AREAS clause must not be greater than 127. • If a data item is allocated more than 65,535 bytes, a COBOL program cannot reference it except with INITIALIZE and CALL BY REFERENCE. • Alphanumeric or numeric edited picture character-strings cannot represent more than 255 standard data format characters.
Compiler Implementation Specifications • The Sort-32 (available on OpenVMS) record size limit is 65,535 bytes. • The Sort-32 key size limit is 65,529 bytes. ♦ • The Hypersort key size limit is 65,535 bytes. • If a file is assigned to magnetic tape media and you use the BLOCK CONTAINS clause in the associated file description, the number of characters in a physical block determined from the BLOCK CONTAINS clause must be an even multiple of 8.
B Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration Compaq COBOL is based on and is highly compatible with Compaq COBOL for OpenVMS VAX, which runs on the OpenVMS VAX system. However, there are differences, which are summarized in this appendix.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.1 Compatibility Matrix Table B–1 (Cont.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.1 Compatibility Matrix Table B–1 (Cont.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.2 Differences in Extensions and Other Features • A qualifier (/FLOAT, on the OpenVMS Alpha operating system) that selects IEEE or VAX floating-point data types for single- and double-precision data items. ♦ On Windows NT and the Tru64 UNIX operating system, only IEEE floating point is supported. ♦ • A flag or qualifier (/INCLUDE or -include) to control where the compiler searches for files for simple COPY statements.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.3 Command-Line Qualifiers (Options or Flags) information about Compaq COBOL for OpenVMS VAX command-line qualifiers, see the VAX COBOL User Manual. B.3.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.3 Command-Line Qualifiers (Options or Flags) Oracle CDD/Repository is not supported by Compaq COBOL on OpenVMS Alpha when /NATIONALITY=JAPAN is used. When /NATIONALITY=US or -nationality us is specified on the compile command line, the dollar sign ($) is the default currency sign and symbol, and Japanese Language Support features are disabled.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.3 Command-Line Qualifiers (Options or Flags) Table B–3 (Cont.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.3 Command-Line Qualifiers (Options or Flags) Table B–3 (Cont.) Compaq COBOL Options Not Available in Compaq COBOL for OpenVMS VAX OpenVMS Alpha Qualifier, Windows NT Option 6 Tru64 UNIX Flag /VERBOSE1 -tune keyword -V -v /VFC7 No equivalent flag No equivalent qualifier -xref,-xref_stdout /TUNE=keyword No equivalent qualifier 1 Not available on OpenVMS Alpha.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.3 Command-Line Qualifiers (Options or Flags) Table B–4 (Cont.) Compaq COBOL for OpenVMS VAX Specific Qualifiers Qualifier Comments /WARNINGS=STANDARD Produces informational messages on language features that are Compaq extensions. The Compaq COBOL equivalent is the /STANDARD=SYNTAX qualifier or the -std syntax flag.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.3 Command-Line Qualifiers (Options or Flags) When you specify /STANDARD=OPENVMS_AXP, the Compaq COBOL for OpenVMS VAX compiler generates informational messages to alert you to language constructs that are not available in Compaq COBOL. (You must also specify /WARNINGS=ALL or /WARNINGS=INFORMATIONAL to receive these messages.) You can use this information to modify your program before using Compaq COBOL.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Behavior Differences On Windows NT systems C:\> cobol/OPTIMIZE=4/WARN=ALL T1.COB T1.COB(7) : Info: code can never be executed at label P2 P2. ^ Compaq COBOL is an optimizing compiler. One use of optimization is to perform analysis for uncalled routines and unreachable paragraphs.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Behavior Differences L L L 12 13 14 15 16 17 18 19 20 21 22 FILE-CONTROL. SELECT FILE-1 ASSIGN TO "FILE1.TMP". DATA DIVISION. FILE SECTION. FD FILE-1. 01 FILE1-REC PIC X. WORKING-STORAGE SECTION. PROCEDURE DIVISION. PE. DISPLAY "***END***" STOP RUN.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Behavior Differences Compaq COBOL Listing File for Multiple COPY Statements 1 2 3 4 5 6 7 8 9 10 11 12 13 14 L L L IDENTIFICATION DIVISION. PROGRAM-ID. DCOP1J. * * Tests copy with three copy statements on 1 line. * ENVIRONMENT DIVISION. DATA DIVISION. PROCEDURE DIVISION. THE. COPY LCOP1J. COPY LCOP1J. COPY LCOP1J. DISPLAY "POIUYTREWQ". DISPLAY "POIUYTREWQ". DISPLAY "POIUYTREWQ".
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Behavior Differences B.4.2.6 REPLACE and COPY REPLACING Statements For the REPLACE and COPY REPLACING statements, the line numbers in compiler listing files differ between Compaq COBOL and Compaq COBOL for OpenVMS VAX. Compaq COBOL arranges the line number for the replacement line to correspond to its line number in the original source text, while subsequent line numbers differ.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Behavior Differences Compaq COBOL for OpenVMS VAX Listing File for REPLACE Statement 18 19 20 21 22LR P0. REPLACE ==xyzpdqnothere== BY ==nothere==. copy "drep3hlib". display nothere. 1 %COBOL-F-ERROR 349, (1) Undefined name B.4.2.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Behavior Differences B.4.3 Output Formatting VFU-CHANNEL Compaq COBOL does not support VFU-CHANNEL and thus provides no direct support for VFU and VFP (Vertical Forms Unit utilities and Vertical Forms Printing). Control byte sequences Compaq COBOL and Compaq COBOL for OpenVMS VAX may use different control byte sequences in VFC files to accomplish similar output file formatting.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Behavior Differences • When your terminal is set to no-wrap mode and you display an item whose characters extend past the edge of the screen, all characters past the rightmost column are truncated. For example, if you specify a display of ‘‘1234’’ at column 79 on an 80-column screen, Compaq COBOL will display 12.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Behavior Differences B.4.4.3 MOVE Statement Unsigned computational fields can hold larger values than signed computational fields. In accordance with the ANSI COBOL Standard, the values for unsigned items should always be treated as positive. Compaq COBOL for OpenVMS VAX, however, treats unsigned items as signed, while Compaq COBOL treats them as positive.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Behavior Differences The bad coding practice exhibited in Example B–2 can impact OpenVMS Alpha, Windows NT, and Tru64 UNIX systems, and any supported Alpha floating-point data type. Example B–2 Illegal Return Value Coding IDENTIFICATION DIVISION. PROGRAM-ID. BADCODING. ENVIRONMENT DIVISION. DATA DIVISION. FILE SECTION. WORKING-STORAGE SECTION. 01 FIELDS-NEEDED.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Behavior Differences The Compaq COBOL compiler has no method for determining what data type an external routine may return. You must specify the correct data type for the GIVING-VALUE item in the CALL statement. On the Alpha architecture, the generated code is testing F0 instead of R0 because of the different set of registers used for floating-point data items.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Behavior Differences • There is a difference between Compaq COBOL for OpenVMS VAX and Compaq COBOL in the enforcement of the general rule that name conflicts should be avoided, including names used for COPY libraries. The Compaq COBOL for OpenVMS VAX compiler does not enforce this rule in some cases, including COPY and PROGRAM-ID.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Behavior Differences For example, in the case of a file that was not successfully opened, any subsequent Compaq COBOL record operation (READ, WRITE, START, DELETE, REWRITE, or UNLOCK) fails without invoking RMS. Thus, the values placed in the RMS special registers for the failed OPEN operation remain unchanged for the subsequent failed record operations on the same file.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Behavior Differences B.4.12 Arithmetic Operations Several arithmetic operations differ in behavior between Compaq COBOL and Compaq COBOL for OpenVMS VAX, depending upon your platform: • Results of numeric and integer Intrinsic Functions may differ from Compaq COBOL for OpenVMS VAX or may be formatted differently by a DISPLAY statement.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.4 Compaq COBOL and Compaq COBOL for OpenVMS VAX Behavior Differences CIT3 gives improved compatibility between Compaq COBOL and Compaq COBOL for OpenVMS VAX. Even with CIT3, however, there are differences: Invalid decimal data In Compaq COBOL, invalid decimal data detection takes place before any possible conversion to CIT3.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.5 Compaq COBOL Differences Across Operating Systems B.5.1 REWRITE A REWRITE operation for an ISAM file is dependent on whether the DUPLICATES clause for the primary key is specified. There is an ambiguity when DUPLICATES is specified in one way at the time a file is created, and another way when it is reopened (a program should use the same declarations).
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.5 Compaq COBOL Differences Across Operating Systems B.5.3 VFC File Format If a VFC file is created on OpenVMS Alpha and then read on Windows NT or Tru64 UNIX, the data record will be returned with the 2-byte control string in the data record when it is read. The workaround is to convert the file to a non-VFC format on OpenVMS Alpha.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.5 Compaq COBOL Differences Across Operating Systems On Windows NT and Tru64 UNIX, this RTL check does not detect some differences that would be detected on an OpenVMS Alpha system, because all but signed 16- and 32-bit integers are mapped onto character strings. For example, if you write an indexed file using a key described as an unsigned 32-bit integer, the character string you will read is the integer with its bytes reversed.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.6 File Compatibility Across Languages and Platforms Data Type Differences Data types vary by programming language and by utilities. For example, Compaq Fortran does not support the packed-decimal data type and, therefore, cannot easily use PACKED-DECIMAL data in COBOL files.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.9 Debugger Support Differences B.
Compaq COBOL for OpenVMS VAX and Compaq COBOL Compatibility and Migration B.11 DBMS Support You may also receive the following general diagnostic message when you attempt to compile a program (on Tru64 UNIX) that contains variables defined in your Oracle DBMS sub-schema: cobol: Severe: . . . Undefined name B.11.2 Multistream DBMS DML With Compaq COBOL, when you use multistream Oracle DBMS DML, you must access different schemas or streams from separate source files.
C Programming Productivity Tools Various programming productivity tools can help you increase your productivity as a Compaq COBOL programmer. These include the following: • On Tru64 UNIX, Compaq FUSE, an integrated development environment ♦ • Debugging tools for Compaq COBOL programs – Ladebug Debugger for the Tru64 UNIX operating system (Section C.3) – OpenVMS Debugger for the OpenVMS Alpha operating system (Section C.4) • Language-Sensitive Editor (LSE) and Source Code Analyzer (SCA) (Section C.
Programming Productivity Tools C.1 Compaq FUSE—an Integrated Development Environment (Tru64 UNIX) • Create and use nested (recursive) makefiles. • Use default configurations to automatically set up tools for a new session. • Customize your best tools configuration. • Create custom language templates for use with the Compaq FUSE editor. • Specify pre- and postprocessing scripts for code management operations.
Programming Productivity Tools C.2 Debugging Tools for Compaq COBOL Programs • Perform other functions, such as executing shell commands, examining core files, examining the call stack, or displaying registers. The debugging examples in Section C.3 and Section C.4 focus on a sample program, shown in Example C–1. One common program has been used, to emphasize the portability of Compaq COBOL. As you read the debugging sections that follow, refer to the code in Example C–1 to identify source lines.
Programming Productivity Tools C.2 Debugging Tools for Compaq COBOL Programs Example C–1 Source Code Used in the Sample Debug Sessions module TESTA 1: IDENTIFICATION DIVISION. 2: PROGRAM-ID. TESTA. 3: DATA DIVISION. 4: WORKING-STORAGE SECTION. 5: 01 TESTA-DATA GLOBAL. 6: 02 LET-CNT PIC 9(2)V9(2). 7: 02 IN-WORD PIC X(20). 8: 02 DISP-COUNT PIC 9(2). 10: BEGINIT. 11: DISPLAY "ENTER WORD:". 12: MOVE SPACES TO IN-WORD. 13: ACCEPT IN-WORD. 14: CALL "TESTB" USING IN-WORD LET-CNT. 15: PERFORM SHOW-IT. 16: STOP RUN.
Programming Productivity Tools C.3 Ladebug Debugger (Tru64 UNIX) this section is available in the man page. For example, you can type man cobol, and page to the appropriate topic to read information about the flags (-g, -o) used at the beginning of the example in this section. 1. To begin this example you compile a Compaq COBOL program consisting of the single compilation unit named TESTA. % cobol -g -o testa testa.
Programming Productivity Tools C.3 Ladebug Debugger (Tru64 UNIX) 8. Use the list command to display the source lines where you set breakpoints. (ladebug) list 43,50 43 PERFORM LOOK-BACK VARYING SUB-1 FROM 20 BY -1 44 UNTIL TEMP-CHAR (SUB-1) NOT = SPACE. 45 MOVE SUB-1 TO CHARCT. 46 PERFORM MOVE-IT VARYING SUB-2 FROM 1 BY 1 UNTIL SUB-1 = 0. 47 MOVE HOLD-WORD TO TEMP-WORD. 48 MOVE-IT. 49 MOVE TEMP-CHAR (SUB-1) TO HOLD-CHAR (SUB-2). 50 SUBTRACT 1 FROM SUB-1. 9. Set a tracepoint at line 15 of TESTA.
Programming Productivity Tools C.3 Ladebug Debugger (Tru64 UNIX) 16. Deposit a new value into CHARCT. (ladebug) assign charct=15.95 17. CHARCT now contains the new value. (ladebug) print charct 15.95 18. You can examine any character of a subscripted data item by specifying the character position. The following EXAMINE command accesses the second character in TEMP-CHAR. (ladebug) print temp-char of temp-word(2) "b" 19. You can qualify data names in debug commands as you can in Compaq COBOL.
Programming Productivity Tools C.3 Ladebug Debugger (Tru64 UNIX) 23. Resume execution with the cont command. TESTA executes its final display. The debugger regains control when STOP RUN executes. (ladebug) cont 03 CHARACTERS Thread has finished executing 24. At this point you end the session with the q command. (ladebug) q ♦ C.4 OpenVMS Debugger (OpenVMS) This section provides an introduction to using the OpenVMS debugger with Compaq COBOL programs.
Programming Productivity Tools C.4 OpenVMS Debugger (OpenVMS) During instruction scheduling, instructions are reordered to minimize waiting time. As a result an instruction resulting from a subsequent COBOL statement can be scheduled in the middle of (or even before) a sequence of instructions from a preceding statement. This reordering NEVER changes the meaning of your program, but it can make your program’s execution in the debugger seem incorrect.
Programming Productivity Tools C.4 OpenVMS Debugger (OpenVMS) $ RUN TESTA OpenVMS Alpha DEBUG Version V7.1-000 %DEBUG-I-INITIAL, Language: COBOL, Module: TESTA %DEBUG-I-NOTATMAIN, type GO to get reach MAIN program DBG> 3. Use the GO command to get to the start of the main program. DBG> GO break at routine TESTA 11: DISPLAY "ENTER WORD" 4. Set a breakpoint. DBG> SET BREAK %LINE 43 5. Begin execution with the GO command.
Programming Productivity Tools C.4 OpenVMS Debugger (OpenVMS) 11. Set a watchpoint on the data item DISP-COUNT. When an instruction tries to change the contents of DISP-COUNT, the debugger returns control to you. DBG> SET WATCH DISP-COUNT DEBUG-I-WPTTRACE, non-static watchpoint, tracing every instruction 12. Execution resumes with the GO command. Before line 50 in TESTB executes, the debugger executes the contents of the DO command entered at step 7.
Programming Productivity Tools C.4 OpenVMS Debugger (OpenVMS) 21. You can examine any character of a subscripted data item by specifying the character position. The following EXAMINE command accesses the second character on TEMP-CHAR. DBG> EXAMINE TEMP-CHAR(2) TEMP-CHAR of TESTA\TESTB\TEMP-WORD(2): "b" 22. You can use the DEPOSIT command to put a value into any element of a table and examine its contents. In this example, "x" is deposited into the second character position of TEMP-CHAR.
Programming Productivity Tools C.4 OpenVMS Debugger (OpenVMS) C.4.2.1 Separately Compiled Programs When you debug a Compaq COBOL program, the default module (which will be brought into the debugger) is the main module name. If your program consists of multiple separately compiled programs (SCPs), and was compiled with the /SEPARATE_COMPILATION qualifier (see Section 1.3.2.4 and Section B.4.2.8), each module that you wish to debug other than the main module must be identified to the debugger.
Programming Productivity Tools C.
Programming Productivity Tools C.5 Language-Sensitive Editor (LSE) and the Source Code Analyzer (SCA) (OpenVMS) This command line compiles the input files PG1.COB, PG2.COB and PG3.COB, and generates corresponding output files for each input file, with the file types OBJ and ANA. The COBOL compiler puts these files in your current default directory. 4. Load the information in the data analysis files into your SCA library with the LOAD command.
Programming Productivity Tools C.5 Language-Sensitive Editor (LSE) and the Source Code Analyzer (SCA) (OpenVMS) LSE provides several commands to help you review errors and examine your source code: Command Key Binding Function COMPILE None Compiles the contents of the source buffer. You can issue this command with the /REVIEW qualifier to put LSE in REVIEW mode immediately after the compilation. REVIEW None Puts LSE into REVIEW mode and displays any errors resulting from the last compilation.
Programming Productivity Tools C.6 Using Oracle CDD/Repository (OpenVMS) Oracle CDD/Repository can also store information about the structure of a program, such as the compiled modules that go into making an object module, or the record and field definitions that are used by COBOL programs. If, for example, a record definition needs to change, you can analyze the impact that change will have on the various programs that use it.
Programming Productivity Tools C.6 Using Oracle CDD/Repository (OpenVMS) C.6.2 Accessing Oracle CDD/Repository Definitions from Compaq COBOL Programs You access repository data definitions from a COBOL program using the COPY FROM DICTIONARY statement. At compile time, the record definition and its attributes are extracted from the designated repository. Then the compiler converts the extracted definition into a COBOL declaration.
Programming Productivity Tools C.6 Using Oracle CDD/Repository (OpenVMS) C.6.3 Recording Dependencies When you compile a program with the /DEPENDENCY_DATA qualifier, the compiler creates the following repository objects to represent the compiled modules, the resulting object module, and the relationships between them: • A compiled module object is created for each separately compiled program. The name of the object is the PROGRAM-ID name with hyphens translated to underscores.
Programming Productivity Tools C.6 Using Oracle CDD/Repository (OpenVMS) • A relationship between the MASTER_FILE object and the EMPLOYEE_ ADDRESS_RECORD definition In addition, the record definitions are included in the compiled module. The COPY FROM DICTIONARY statement is used when you want to create a relationship between a compiled module and a record or field definition.
Programming Productivity Tools C.
Programming Productivity Tools C.6 Using Oracle CDD/Repository (OpenVMS) C.6.5 For More Information For more information about Oracle CDD/Repository, refer to the following manuals: Document Description Oracle CDD/Repository Architecture Manual Describes the concepts and capabilities of the Oracle CDD/Repository object-oriented architecture.
D Porting to Compaq COBOL from Other Compilers Compaq COBOL has built-in porting assistance that recognizes foreign COBOL extensions and helps you migrate programs from other systems. Porting assistance is always enabled for some foreign extensions. However, for those features that use new reserved words, this feature is selectively enabled at compile time by qualifiers and flags on the COBOL command line.
Porting to Compaq COBOL from Other Compilers D.1 Porting Assistance -rsv foreign_extensions ♦ Without full porting assistance enabled, if you compile program source code that was written for a compiler other than Compaq COBOL, extensions that are not directly supported by Compaq COBOL are flagged with terse messages and the compile fails. Porting assistance will provide you with better diagnostics and more information that can assist you in recoding the indicated operations with Compaq COBOL syntax.
Porting to Compaq COBOL from Other Compilers D.1 Porting Assistance produce fatal diagnostic messages for programs that have successfully compiled before. D.
Index A 2000 A.D., xxix date change problem, 1–62 a.
ANSI format source line structure and content of, 1–7 ANSI reference format, 1–7 ANSI-to-terminal format conversion, 14–2 /ANSI_FORMAT, 1–7, 1–32 APPLY clause, 6–20, 15–10 APPLY LOCK-HOLDING, 8–3 APPLY PRINT-CONTROL clause, 6–8, 6–12 -arch, 15–3 -arch flag, 1–12 /ARCHITECTURE qualifier, 1–32, 15–3 Archive library creating and maintaining, 1–26 file name suffix, 1–9 obtaining information about, 1–26 specifying using COBOL, 1–19 ar command, 1–26 Argument list, 13–3 Argument-passing mechanisms BY CONTENT, 12–1
Calling Tru64 UNIX Shareable Objects, 12–30 CALL statement nesting, 12–6 transferring execution control, 12–5 use of, 12–5 -call_shared flag, 1–12, 1–21 Case sensitivity issues on Tru64 UNIX, 12–30 on Windows NT, 12–30 cc command using cobol command instead of, 1–18 CDD See Oracle CDD/Repository CDO data types supported, C–20 source representation, C–17 CDO language, C–16 Cell contents, 6–6 location in the file, 6–6 numbering, 6–6 numerical order of, 6–6 relative record number, 6–6 size, 6–6 Century date ch
cobol flags (cont’d) -display_formatted, 1–12 -D num, 1–12 -feedback file, 1–12 -fips 74, 1–12 -flagger [option], 1–12
COBOL_SWITCHES, 1–59 Code Management System integration with LSE, C–13 Coding based on architectural differences, B–18 COLLATING SEQUENCE IS, 9–7 Phrase, overriding a, example, 9–7 Command line arguments, run time OpenVMS Alpha, 1–48 Tru64 UNIX, 1–23 common Compaq COBOL errors, 1–35 Command-line argument accessing, 1–23 Command-line arguments accessing at run time, 1–48 Command-line qualifiers, B–4 to B–10 Compaq COBOL for OpenVMS VAX only (tab.), B–8 Compaq COBOL only (tab.), B–6 shared, B–5 shared (tab.
Compatibility (cont’d) fixed-length records, B–27 ORGANIZATION INDEXED file, reading, B–27 print-controlled files, B–27 reading COBOL indexed files, 6–47 variable-length records, B–27 VFC files, B–27 COMP data item advantages of, 15–5 to 15–7 Compilation performance, 1–2 and physical memory, 1–4 and separate compilation, 1–6 and virtual memory, 1–3 Compiled module entry, C–19 Compiler and linker, 1–27 diagnostic messages issued by general description, 1–18 driver, 1–10, 1–27 error messages, 1–36 messages, 1
Compiling and linking for debugging, C–9 for debugging, C–5 Compiling programs, 1–29 C language file suffix, 1–9 C language with cobol, 1–18 compile command qualifiers, 1–31 compile command qualifiers (table), 1–31 conditional compilation, 1–36 /DEBUG, C–9 debugging, 1–30 error messages, 1–36 -g -o, C–5 multiple source files on OpenVMS Alpha, 1–6, 1–30, 1–31 multiple source files on Tru64 UNIX, 1–16 on OpenVMS Alpha, 1–29 COMP unsigned longword integers, 15–15 Concatenating items nonnumeric data, 5–1 Condit
Data items exceeding size of (cont’d) compiler implementation specifications, A–2 index, 4–16 intermediate, 15–7 padding, 16–4 Data movement, 3–6, 3–12 Data name, subscript with, 4–14 Data organization, 3–2 Data testing, 3–3, 3–6 Data types, 13–8 Compaq COBOL-to-Oracle CDD/Repository mapping, C–20 to C–21 scaling and mixing, 15–7 selection for performance, 15–8 DATE-COMPILED statement differences, B–15 Compaq COBOL for OpenVMS VAX (ex.), B–15 Compaq COBOL on OpenVMS Alpha (ex.
Directives (cont’d) memory allocation and access, 16–3 SET VOLATILE, 16–3 DISPLAY data items, avoiding for arithmetic, 15–5 DISPLAY statement See also Video forms differences, B–16 output, object of, 11–1 DISPLAY within ACCEPT ON EXCEPTION, terminating, 11–14 /DISPLAY_FORMATTED, 1–33 -display_formatted flag, 1–12 /DISPLAY_FORMATTED qualifier, 11–12 -D num flag, 1–12 Double-precision data storage differences, B–21 Driver definition of, 1–10, 1–27 relationship to software components, 1–10, 1–27 Driver program
External report file number of characters compiler implementation specifications, A–2 F FD record length compiler implementation specifications, A–1 -feedback file flag, 1–12 File See also Access mode See also Record ACCEPT and DISPLAY statements, 11–1 ACCEPT statement, 11–2 backing up, 6–60 recommended intervals, 6–60 changing output file names (cobol), 1–17 closing with lock, 6–26 connector, 6–14 created by cobol, 1–16 creating, 6–24 data type differences, B–28 defining a disk, 6–15 defining a disk file,
File sharing specifying OPEN EXTEND (cont’d) with a shared sequential file, 8–15 successful, 8–4 summarizing related file-sharing criteria, 8–9 using file status values, 8–12 using RMS special registers, 8–12 X/Open standard, 8–3 File specification creating a ‘‘comma list’’, 1–30 creating a ‘‘plus list’’, 1–30 how the I/O system builds a COBOL, 6–25 keeping as a variable, 6–18 overriding at run-time, 6–18 variable, 6–18 File status values, 8–12 Compaq COBOL support for, B–4 differences, B–21 for Compaq COBO
flags (cont’d) -T num, 1–14 -tps, 1–14, 1–15 -trunc, 1–14 -tune, 1–14 -v, 1–14 -V, 1–14 -w, 1–14 -warn, 1–14 -warn all, 1–14 -warn none, 1–14 -warn [no]information, 1–14 -warn [no]other, 1–14 -xref, 1–14 -xref_stdout, 1–14 Flags -align, B–3 -align padding, B–8 with no Compaq COBOL for OpenVMS VAX equivalent qualifiers, B–6 /FLOAT, 1–33 /FLOAT qualifier Compaq COBOL support for, B–3 Footing area, 10–13 Foreign extensions, detecting, D–1 Foreign syntax recognized extensions, D–2 FOREIGN_EXTENSIONS option, 1–3
Image activation optimization, 15–25 /INCLUDE, 1–33 -include flag, 1–12 Index data item, 4–16 declaration, 4–16 modifying with SET, 4–16 where defined, 4–3 Indexed file See also Optimization access modes, 6–34 alternate key, 6–7 and ISAM mapping, 6–47 AT END condition, 7–2 capabilities, 6–6 creating, 6–32 creating and populating, 6–33 defining, 6–22 design considerations, 6–13 I/O statements, 6–33 index, 6–7 invalid key condition, 7–2 INVALID KEY condition, 7–2 key, 6–7 duplicate, 6–7 length, 6–7 location,
INSPECT statement REPLACING phrase (cont’d) search argument, 5–30 sample (fig.), 5–21 TALLYING option, 5–17 TALLYING phrase, 5–24 argument list, 5–25 arguments, 5–24 counter, 5–24 interference in the tally arguemnt list, 5–27 leading delimiter of operation (tab.), 5–25 scan with separate tallies results of (tab.
-Ldir flag, 1–12, 1–20 ld linker creating shared object libraries, 1–21 to 1–22 functions performed, 1–19 locating undefined symbols using nm, 1–19 messages, 1–22, 1–23 relationship to cob command, 1–19 relationship to cobol command, 1–19, 1–27 restrictions creating shared libraries, 1–22 sample use with cobol command, 1–9, 1–15 specifying object libraries, 1–19 to 1–21 specifying shared object libraries, 1–22 -L flag, 1–12, 1–20 LIB$ESTABLISH routine, 13–15 user-written condition handler (ex.
Logical accessing at run time, 1–49 Logical name, 6–18 to 6–20 COB$INPUT, 11–2 COB$OUTPUT, 11–2 for file, 11–1 implementor name, 11–1 SYS$INPUT, 11–2 SYS$OUTPUT, 11–2 Logical page conventional report, 10–5 definition, 10–5 presentation order (fig.
Nested IF statements static nesting depth compiler implementation limitations, A–3 Nested program See Contained program Nesting CALL statements, 12–6 nm command, 1–26 use in locating undefined symbols, 1–19 /NOALIGNMENT syntax of, 16–5 /NOALIGNMENT qualifier default, 16–5 NO ECHO phrase, 11–16 -nolocking flag, 1–13 Non-COBOL programs including in run unit, 12–25 Nonnumeric data, 3–1 to 3–12 classes, 3–4 common nonnumeric item move errors, 3–11 concatenating items, 5–1 data movement, 3–6 two MOVE statements
Numeric items testing (cont’d) relation test, 2–3 sign test, 2–3 Numeric moves elementary, 2–6 Numeric relational operators (tab.
Optimization relative files (cont’d) maximum record number, 15–16 selection of data types, 15–8 sequential files, 15–15 /OPTIMIZE, 1–34 and /DEBUG, 15–4 in programs, B–11 /OPTIMIZE=TUNE, 15–2 /OPTIMIZE qualifier, 15–1 Oracle CDD/Repository, 15–7, C–16 to C–22 accessing data definitions, C–18 creating relationships, C–19 pathname specification number of characters, A–2 records including in source listing, C–16 using, C–16 with RECORD statement, C–19 Other languages calling from, 12–19 Output files created by
Program run messages, 1–52 Program structure differences, B–10 Compaq COBOL (ex.
Relative file creating (cont’d) random access mode, 6–30, 6–31 sequential access mode, 6–30 deleting records, 6–53 randomly, 6–54, 6–55 sequentially, 6–53, 6–54 using the DELETE statement, 6–53 design considerations, 6–13 invalid key condition, 7–2 INVALID KEY condition, 7–2 open modes, 6–31 organization, 6–5, 6–6 advantages, 6–3 disadvantages, 6–3 specifying, 6–21 processing, 6–6, 6–31 reading, 6–38 dynamically, 6–40, 6–41 randomly, 6–40 sequentially, 6–38, 6–39 record cells, 6–6 record numbers, 6–6 rewrit
Report problem solving (cont’d) logical lines, 10–82 physical lines, 10–82 physical page, 10–88 printing, 10–82, 10–88 bold, 10–89 details, 10–88 totals, 10–88 underlining, 10–89 RESET phrase, 10–36 spooling, 10–24 streamlining your, 10–88 top margin, 10–13 total accumulating, 10–4 crossfooting, 10–35 crossfoot totals, 10–4 defining, 10–34 incrementing, 10–34 RESET phrase, 10–36 rolled forward totals, 10–4 rolling-forward, 10–35 subtotals, 10–4, 10–34 UPON phrase, 10–36 total accumulating (fig.
ROUNDED phrase, 2–12 with SIZE ERROR, 2–13 Rounding off arithmetic results, 2–12 Routines, 13–1 Named ‘‘main’’, 1–9 -rsv [no]200x flag, 1–13 -rsv [no]foreign_extensions, 1–13 -rsv [no]xopen flag, 1–13 RUN command, 1–48 on OpenVMS Alpha, 1–48 syntax, on OpenVMS Alpha, 1–50 Running Compaq COBOL programs on OpenVMS Alpha, 1–48 on Tru64 UNIX, 1–23 Run time accessing environment variables, 1–24 accessing environment variables (ex.
Sequential file organization (fig.
SORT statement SELECT statement (cont’d) example, 9–1 sorting variable-length records, 9–8 USING phrase, 9–3 with the OUTPUT PROCEDURE phrase, 9–5 USING phrase replacing INPUT PROCEDURE phrase example, 9–5 WITH DUPLICATES IN ORDER phrase, 9–6 example, 9–6 with tables, 9–9, 15–9 /SOURCE, 1–35 Source Code Analyzer See SCA Source code listing, 1–18 Source files analyzing source code using Tru64 UNIX tools, 1–26 building using Tru64 UNIX tools, 1–26 creating and revising, 1–7 managing using Tru64 UNIX tools, 1–
SWITCH clause value of switch numbers compiler implementation specifications, A–1 Switches checking, 1–60, 1–61 controlling, 1–61 controlling externally, 1–61 controlling internally, 1–60 definition, 1–59 order of evaluation, 1–61 program, 1–59 to 1–62 SET statement, 1–60 setting externally, 1–60 setting for a process, 1–60 setting internally, 1–60 using, 1–59 Symbol library condition values, 13–15 numeric editing, 2–7 record, C–9 SYMBOLIC CHARACTERS clause value of numeric literals compiler implementation
Tables memory map (cont’d) initializing alphanumeric items (fig.), 4–12 initializing mixed usage items (fig.), 4–11 initializing with VALUE clause (fig.), 4–10 multidimensional accessing with subscripts, 4–13 rules for (tab.), 4–14 defining, 4–4 OCCURS clause, 4–1 indexes, 4–1 keys, 4–1 subscripts (ex.), 4–13 one-dimensional, 4–1 multiple data items in (ex.), 4–2 organization of multiple data items (fig.), 4–2 one-dimensional (ex.), 4–2 one-dimensional organization of (fig.
UNSTRING statement DELIMITED BY phrase (cont’d) delimiting with all double asterisks results of (tab.), 5–11 delimiting with an asterisk results of (tab.), 5–8 delimiting with two asterisks results of (tab.), 5–10 multiple delimiters results of (tab.), 5–12 DELIMITER phrase, 5–13 delimiters, 5–10, 5–11 function, 5–6 handling short sending items (tab.), 5–8 multiple delimiters, 5–12 multiple receiving items, 5–6, 5–9 based on sending item value (tab.
Version 2.7—what’s new since V2.