Trademark Office.
OpenVMS and Tru64 are trademarks of Compaq Information Technologies Group, L.P.
Microsoft, MS-DOS, Win32, Windows, and Windows NT are trademarks of Microsoft Corporation.
Motif, OSF/1, UNIX, and X/Open are trademarks of The Open Group.
All other product names mentioned herein may be trademarks of their respective companies.
Confidential computer software. Valid license from Compaq required for possession, use, or copying.
Consistent with FAR 12.211 and 12.212, Commercial Computer Software, Computer Software
Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government
under vendor’s standard commercial license.
Compaq shall not be liable for technical or editorial errors or omissions contained herein. The
information in this document is subject to change without notice.
THE INFORMATION IN THIS PUBLICATION IS PROVIDED "AS IS" WITHOUT WARRANTY
OF ANY KIND. THE ENTIRE RISK ARISING OUT OF THE USE OF THIS INFORMATION
REMAINS WITH RECIPIENT. IN NO EVENT SHALL COMPAQ BE LIABLE FOR ANY DIRECT,
CONSEQUENTIAL, INCIDENTAL, SPECIAL, PUNITIVE, OR OTHER DAMAGES WHATSOEVER
(INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
BUSINESS INTERRUPTION OR LOSS OF BUSINESS INFORMATION), EVEN IF COMPAQ
HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND WHETHER IN AN
ACTION OF CONTRACT OR TORT, INCLUDING NEGLIGENCE.
The limited warranties for Compaq products are exclusively set forth in the documentation
accompanying such products. Nothing herein should be construed as constituting a further or
additional warranty.
This document was prepared using DECdocument, Version 3.3-1b.
B–4Compaq COBOL for OpenVMS VAX Specific Qualifiers ............B–8
C–1Oracle CDD/Repository Data Types ...........................C–21
D–1Recognized Foreign Reserved Words . . . .......................D–2
xxi
This manual provides information to help you develop Compaq COBOL programs
for the OpenVMS Alpha and Compaq Tru64 UNIX platforms.
Compaq COBOL is the new name for DEC COBOL and for DIGITAL COBOL.
Compaq COBOL, unmodified, refers to the COBOL language on three platforms:
OpenVMS Alpha
Tru64 UNIX
Windows NT Alpha (described in separate documentation)
Compaq COBOL for OpenVMS VAX is the new name for VAX COBOL and
DIGITAL VAX COBOL. It is the COBOL implementation for the OpenVMS VAX
platform. (It is described in a separate documentation set.)
Any references to the former names in product documentation or other
components should be construed as references to the Compaq COBOL names.
All references in this manual to Windows NT mean Microsoft Windows NT Alpha.
Intended Audience
This manual is intended for experienced applications programmers who have a
thorough understanding of the COBOL language. Some familiarity with your
operating system is also recommended. This is not a tutorial manual.
Preface
If you are a new COBOL user, you may need to read introductory COBOL
textbooks or take COBOL courses. Additional prerequisites are described at the
beginning of each chapter or appendix, if appropriate.
Document Structure
This manual is organized as follows:
•Chapter 1 describes how to create, compile, link, and run Compaq COBOL
programs and how to develop programs at the command level.
•Chapter 2 describes how the Compaq COBOL compiler stores, represents,
moves, and manipulates numeric data.
•Chapter 3 describes how the Compaq COBOL compiler stores, represents,
moves, and manipulates nonnumeric data.
•Chapter 4 describes how to define, initialize, and access tables.
•Chapter 5 describes how to perform text manipulation using the STRING,
UNSTRING, and INSPECT statements.
•Chapter 6 describes I/O services provided by the operating systems, including
record management services.
•Chapter 7 describes how to include exception handling routines in Compaq
COBOL programs.
xxiii
•Chapter 8 describes file sharing and record locking for sequential, relative,
and indexed files.
•Chapter 9 describes how to sort and merge files using the SORT and MERGE
statements.
•Chapter 10 describes how to produce printed reports.
•Chapter 11 describes screen handling using the Compaq COBOL ACCEPT
and DISPLAY statements.
•Chapter 12 describes how Compaq COBOL programs communicate with
each other or with non-COBOL programs through the CALL statement and
external data.
•Chapter 13 describes the use of Compaq COBOL in the OpenVMS Alpha
Common Language Environment.
•Chapter 14 describes how to use the REFORMAT utility, which converts
terminal format source programs to conventional ANSI format and converts
conventional ANSI format source programs to terminal format.
•Chapter 15 presents guidelines for using the Compaq COBOL compiler
optimization features.
•Chapter 16 describes how to use compile-time and run-time features to
optimize the use of system resources while also maximizing run-time
performance.
•Appendix A contains a list of Compaq COBOL specificatons and limits on the
Tru64 UNIX and OpenVMS Alpha systems.
•Appendix B describes compatibility and portability issues between Compaq
COBOL for OpenVMS VAX and Compaq COBOL on the Tru64 UNIX and
OpenVMS Alpha systems.
•Appendix C describes optional programming productivity tools available on
OpenVMS Alpha systems and Tru64 UNIX systems.
•Appendix D describes porting assistance for migrating applications between
other COBOL compilers and Compaq COBOL.
•The Index indexes and references terms in this manual.
Associated Documents
The following documents contain additional information directly related to
various topics in this manual:
Compaq COBOL Reference Manual
This manual describes the concepts and rules of the Compaq COBOL
programming language under the supported operating systems.
Release Notes
Consult the Compaq COBOL release notes for your installed version for late
corrections and new features.
xxiv
On the OpenVMS Alpha operating system, the release notes are in:
where nnn is the version and release number, for example, 027 for Version
2.7.
On the Tru64 UNIX operating system, the release notes are in:
/usr/lib/cmplrs/cobol/relnotes
Compaq COBOL Installation Guide for OpenVMS Alpha Systems
This manual provides information on how to install Compaq COBOL on the
ConventionMeaning
89
Braces used in a general format enclose lists from which you
must choose only one item. For example:
(
SEQUENTIAL
RANDOM
DYNAMIC
)
23
Brackets used in a general format enclose optional items from
which you can choose none or one. For example:
RECORD
ALL RECORDS
. . .A horizontal ellipsis indicates that the item preceding the
.
.
.
FormatProgram examples are shown in terminal format, rather than
special-character wordsThe following symbols, when used in a general format,
Choice indicators, vertical lines inside a set of braces, used in a
general format enclose lists from which you must choose one or
more items, using each item chosen only once. For example:
g
9
=
;
...
8
<
COMMON
INITIAL
:
ellipsis can be repeated. For example:
f
switch-name
A vertical ellipsis indicates that not all of the statements are
shown.
in ANSI standard format.
constitute required special-character words:
xxvi
Plus sign (+)
Minus sign (-)
Single (=) and double ( = = ) equal signs
Less than (<) or greater than (>) symbols
Less than or equal to (<=) and greater than or equal to
(>=) symbols
Period (.)
Colon ( : )
Single (*) and double ( ** ) asterisks
Slash ( / )
Left parenthesis (( ) or right parenthesis ())
quotation markThe term quotation mark is used to refer to the double
apostropheThe term apostrophe is used to refer to the single quotation
user input
quotation mark character (").
mark character (’ ).
In examples, user input (what you enter) is shown as
monospaced text
.
ConventionMeaning
extensionsCompaq extensions to the 1985 ANSI COBOL Standard are
report fileBold type indicates a new term.
full-file-nameThis syntax term refers to the name of a file and the device
color coded in blue or gray. Note that the term extension in
this manual means a Compaq extension to the ANSI COBOL
Standard. (Some of these extensions are included in the
X/Open CAE Standard for the COBOL language.)
and directory, or path, in which it is located. For example:
c:\home\public\filename.txt (Windows NT path)
DISK2$:[HOME.PUBLIC]FILENAME.TXT; (OpenVMS file
compiler optionThis term refers to command-line qualifiers (OpenVMS Alpha
systems), options (Windows NT Alpha systems), or flags (Tru64
UNIX systems). For example:
/LIST(OpenVMS qualifier or NT option)†
-list(Tru64 UNIX flag or NT option)†
COBOLThis term refers to language information common to ANSI-85
Return
Tab
Ctrl/x
$The dollar sign ($) represents the OpenVMS system prompt.
%The percent sign (%) represents the Tru64 UNIX system
C:\>A letter followed by a colon (: ), a backslash \, and a greater-
Start| Programs | . . .A series of names separated by vertical bars ( | ) means you
COBOL, Compaq COBOL, and Compaq COBOL for OpenVMS
VAX.
A boxed symbol indicates that you must press a key on the
terminal; for example,
Return key.
This symbol indicates a nonprinting tab character.
The symbol
CTRL while you press another key, for example,
prompt.
than sign (>) represents the MS-DOS system prompt.
should click on the first named Windows NT object, then the
second named object, and so on.
Ctrl/x
Return
indicates that you press the
indicates that you hold down the key labeled
Ctrl CorCtrl O
.
References
†Either the slash or the hyphen is acceptable for Windows NT compiler options. Use the slash for
Windows NT linker options.
The following table shows certain references and their respective meanings in
this manual:
ReferenceMeaning
OpenVMSOpenVMS Alpha operating system
Tru64 UNIXCompaq Tru64 UNIX operating system
Windows NTMicrosoft Windows NT Version 4.0, SP4, SP5 for Alpha systems
xxvii
Compaq Tru64 UNIX was formerly known as DEC OSF/1 or as DIGITAL UNIX.
Compaq COBOL was formerly known as DIGITAL COBOL or DEC COBOL.
Compaq COBOL for OpenVMS VAX was formerly known as VAX COBOL or as
DIGITAL VAX COBOL.
Acknowledgment
COBOL is an industry language and is not the property of any company or group
of companies, or of any organization or group of organizations.
No warranty, expressed or implied, is made by any contributor or by the
CODASYL COBOL Committee as to the accuracy and functioning of the
programming system and language. Moreover, no responsibility is assumed by
any contributor, or by the committee, in connection therewith.
The authors and copyright holders of the copyrighted material used herein are
as follows: FLOW-MATIC (trademark of Unisys Corporation), Programming
for the UNIVAC (R) I and II, Data Automation Systems, copyrighted 1958,
1959, by Unisys Corporation; IBM Commercial Translator Form No. F28-8013,
copyrighted 1959 by IBM; FACT, DSI 27A5260-2760, copyrighted 1960 by
Minneapolis-Honeywell.
They have specifically authorized the use of this material, in whole or in part, in
the COBOL specifications. Such authorization extends to the reproduction and
use of COBOL specifications in programming manuals or similar publications.
How to Order Additional Documentation
For information on pricing and where to buy documentation and other Compaq
products in the United States and Canada, please call toll-free 1-800-282-6672.
Reader’s Comments
Compaq appreciates your comments. If you find errors or want to comment about
this manual, please send the manual title, order number, and your comments by
one of the following methods:
•Electronic Internet mail:
LanguageDocs@compaq.com
•Fax:
603–884–0120
Attn: Languages Documentation, ZKO2–3/K35
•A letter sent to the following address:
Compaq Computer Corporation
Languages Documentation, ZKO2–3/K35
110 Spit Brook Road
Nashua, NH 03062–2698
USA
xxviii
User Programs and the Year 2000
Even subsequent to the turn of the century, there still exist potential disruptions
in previously problem-free software where there are instances of a two-digit year
field that should be a four-digit field. Programmers need to correct all such fields,
as Compaq cannot prevent problems that originate in application code.
For more information, see Section 1.6.
New Features
Consult the Index for entries under Version 2.7 – what’s new since V2.5. They
will point you to information added since Version 2.5 of Compaq COBOL.
xxix
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. In
addition to standard COBOL features, Compaq COBOL includes extensions that
make new application development efficient and effective, with features helpful in
porting legacy COBOL programs to OpenVMS Alpha and Tru64 UNIX systems.
Developing software applications with Compaq COBOL will be a familiar process.
You set up your development environment, create your source, compile, link, and
run. A few of the specific tasks are:
•Choosing a reference format: terminal or ANSI
•Carefully considering Alpha architecture system resources; for example, you
might invest more system resources at compile time to get faster execution at
run time
•Using various system-independent features for program development
1.0.1 Files Installed on Your System
You will have the following directories and files added to your system after a
typical installation:
(drive letter):\DEC\COBOL\Vnn
where nn shows the version and release numbers. For example, for Version 2.7
nn is 27.
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. Also, for very large
programs (greater than 10,000 lines), you might experience extremely long
compile times. Knowing why Compaq COBOL requires more memory can help
you take actions to avoid resource problems.
1.1.1 Compilation Performance
The Alpha architecture is a RISC (reduced instruction set computer) architecture.
Many other processor architectures, including the VAX, are CISC (complex
instruction set computer) architectures. The main distinguishing characteristic of
a RISC machine is that it has few instructions and each instruction does a small
amount of work. A CISC machine generally has many instructions, most of which
perform many complicated operations in one step.
By reducing the amount of work that is done in each instruction (and by reducing
the number of instructions), the complexity of the hardware is reduced. These
hardware changes, plus others, result in an increase in the number of instructions
per second that can be completed. The result is much faster overall system
performance.
A tradeoff of RISC systems is that compilers for these architectures generally
must do a great deal more work than a corresponding compiler for a CISC
architecture. For example, the compiler must compute the best way to use all of
the functional units of the processor, and it must determine how to make the best
use of registers and on-chip data cache because reads and writes to main memory
are generally slow compared to the speed of the processor.
The code generation portion of the Compaq COBOL for OpenVMS VAX compiler
examines one COBOL statement at a time, determines the VAX instructions to
be constructed to execute that statement, and then moves on to the next one.
This tactic works well for a CISC architecture like the VAX. Compaq COBOL for
OpenVMS VAX does ‘‘peephole’’ optimization.
The Compaq COBOL compiler, in contrast, is a globally optimizing compiler
based on the Alpha RISC architecture as well as mathematical concepts. The
compiler constructs an internal representation of the entire COBOL program,
and repeatedly traverses this structure at compile time, so that it can produce
the most efficient machine code for the program. This results in very high
performance code, to the benefit of your users at run time. Although the Compaq
COBOL compiler requires more resources than some other compilers to do this
additional work at compile time, this cost is offset by better performance during
the many run times that follow.
To reduce this impact on system resources, do the following:
-O0
•Use /NOOPTIMIZE or
developing and testing programs. The optimizer is one of the heaviest users
of system resources in the COBOL compiler and is turned on by default. Also,
the higher the optimization level, the more memory required by the compiler.
on the compile command line when initially
•Check system tuning. Because the Compaq COBOL compiler often needs
a great deal of virtual memory, you may need to increase virtual memory
for developers who use the compiler. This results in decreased paging and
improvements in compile time.
1–2 Developing Compaq COBOL Programs
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) .COB files (possibly one
for each separately compiled program unit).
Note
Large arrays (tables) can have a significant impact on compile time and
resource requirements. In addition to the size of the program source, you
should also examine the amount of space allocated in your Data Division,
particularly for arrays. The number of array elements as well as the
size of the array elements is significant. This impact can be minimized
in two ways: by system tuning (as suggested in this section), which
will optimize system resources for the compile, and by using INITIALIZE
instead of VALUE in your data definitions, which will improve compilation
performance.
1.1.2 Tuning OpenVMS Alpha for Large Compaq COBOL Compiles
The recommendations that follow were determined by compiling one set of very
large Compaq COBOL modules on OpenVMS Alpha. While your results may
vary, the principles are generally applicable. For more detailed information
on OpenVMS Alpha tuning, see the OpenVMS System Manager’s Manual,
particularly the sections on Managing System Parameters and Managing SystemPage, Swap, and Dump Files.
Note that many tuning exercises are more beneficial if you work with a relatively
quiet system, submit batch jobs, and retain the log files for later analysis.
1.1.2.1 Optimizing Virtual Memory Usage
If your system does not have enough virtual memory allocated, the compile may
fail, with the ‘‘%LIB-E-INSVIRMEM, insufficient virtual memory’’ error reported.
OpenVMS has two parameters that control the amount of virtual
memory available to a process. One is the system generation parameter
VIRTUALPAGECNT, which sets an upper bound on the number of pagelets
of virtual memory for any process in the system. The other control is the
AUTHORIZE parameter PGFLQUOTA, which determines the number of pagelets
a process can reserve in the system’s page file(s).
After an ‘‘insufficient virtual memory’’ error, you can issue the DCL command
$SHOW PROCESS/ACCOUNTING to see the ‘‘Peak virtual size’’ used by the
process (or look at the ‘‘Peak page file size’’ at the end of a batch job log file).
If the peak size is at the system generation parameter VIRTUALPAGECNT,
you will need to raise this value. If the peak size is below VIRTUALPAGECNT,
and at or above PGFLQUOTA, run AUTHORIZE to increase PGFLQUOTA for
the COBOL users. (Peak size can exceed PGFLQUOTA because some virtual
memory, such as read-only image code, is not allocated page file space.)
It is difficult to predict precisely how much virtual memory will be required
for a compilation, but a starting point for system tuning may be computed by
multiplying 250 times the size of the largest program in disk blocks (including all
Developing Compaq COBOL Programs 1–3
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. For example, if you estimate 370,000
pages, add the line following line in MODPARAMS, run AUTOGEN and reboot:
MIN_VIRTUALPAGECNT = 400000
If the compilation now completes successfully, use the command $SHOW
PROCESS/ACCOUNTING to determine the Peak Virtual Size; if the actual
peak is significantly less than the value computed above, you can reduce
VIRTUALPAGECNT.
When modifying VIRTUALPAGECNT and PGFLQUOTA, you may also need to
increase the size of the page file.
1.1.2.2 Optimizing Physical Memory Usage
In any evaluation of your system’s physical memory, two of the questions to
consider are:
Is there enough memory on the system?
Is enough available to the process running the compilation?
More specifically:
•If the physical memory on the system is too small, the command
$LOGOUT/FULL (which is automatically issued at the end of a batch job)
will show a high number of faults (>100,000 for a single compilation) and an
elapsed time value that greatly exceeds the Charged CPU time value, as the
system waits for disk I/Os to resolve page faults. In this situation, tuning
attempts may be of limited benefit.
•If the physical memory on the system is adequate, but the physical memory
allotted to the process running the compilation is too small, you may still
observe a large number of faults, but elapsed time may remain closer to CPU
time. This is because OpenVMS Alpha resolves page faults from the page
caches (free list, modified list) whenever possible, avoiding the relatively slow
disk I/Os. In this situation, basic tuning may also be beneficial.
The amount of physical memory required will vary, but it should be a large
percentage of the process peak virtual size—as close to 100% as practical.
The reason is that the compiler makes multiple passes over the internal
representation of the program. A page that falls out of the working set in one
pass is probably going to be needed again on the very next pass.
The physical memory present on the system can be determined by the DCL
command $SHOW MEMORY/PHYSICAL. The physical memory used by the
compilation is reported as ‘‘Peak working set size’’ by the command SHOW
PROCESS/ACCOUNTING or at the end of a batch log file.
More physical memory can be made available to a process by minimizing the
number of competing processes on the system (for example, by compiling one
module at a time or by scheduling large compiles for off-peak time periods; late at
night is a good time in some situations).
1–4 Developing Compaq COBOL Programs
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. The following guidelines can help:
•Set the COBOL user WSEXTENT (in AUTHORIZE or INITIALIZE/QUEUE)
to match WSMAX.
•Keep WSQUOTA (in AUTHORIZE or INITIALIZE/QUEUE) low. Make sure
that no process or batch queue has a WSQUOTA of more than approximately
20% of physical memory. The difference between WSEXTENT and WSQUOTA
allows OpenVMS Alpha to manage memory to meet varying demands.
•Use AUTOGEN. AUTOGEN will attempt to make a consistent set of changes
that do not interfere with each other.
By default, AUTOGEN will set the maximum working set (system generation
parameter WSMAX) to 25% of physical memory. This value is reasonable for
a workstation or multi-user system with many active processes.
WSMAX can be increased to a somewhat larger value by editing
MODPARAMS.DAT. For a system with 64 MB
WSMAX to no more than approximately 40% of physical memory, or 52000
pagelets (1 MB = 2048 pagelets). With 128 MB or more of physical memory, a
setting of 50% of physical memory can be attempted.
1
of physical memory, set
The effects of physical memory on compilation time were studied for a set of
seven large modules. These modules ranged in size from approximately 1600 to
3300 disk blocks. Your results may differ, but to give a rough appreciation for the
effect of physical memory on compilation time, note that:
•When the amount of physical memory available to the processes matched the
amount of virtual memory, the elapsed times were close to the CPU times.
•As the physical memory was reduced, CPU times rose only slightly—
approximately 10%.
•As the physical memory was reduced, elapsed times were elongated, at the
rate of approximately 1 hour for each 100 MB of difference between Peak
Virtual Size and the actual memory available. For example, when compiling
a program that used a Peak Virtual Size of 947760 pagelets, or 463 MB, on
a system where approximately 180 MB of physical memory was available to
user processes, the compile required approximately 3 hours more than on a
512 MB system.
Your results may differ from those shown in this section and will be strongly
affected by the speed of the devices that are used for paging.
Note that the requirements for virtual memory and physical memory can also be
reduced by breaking large modules into smaller modules.
1
MB= megabytes
Developing Compaq COBOL Programs 1–5
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). For programs compiled without this qualifier, the compiler engine parses
the entire compilation unit and uses system resources (sized for the total job) for
the duration of this compilation. When you use the /SEPARATE_COMPILATION
qualifier, the compilation is replaced by a smaller series of operations, and
memory structures that are needed for individual procedures are reclaimed and
recycled. See Section 1.3.2.4 for additional information. ♦
1.1.3 Choosing a Reference Format
You need to choose a reference format before you set out to write a Compaq
COBOL program, and you must be aware of the format at compile time. The
Compaq COBOL compiler accepts source code written in either terminal or ANSI
reference format. You cannot mix reference formats in the same source file.
On OpenVMS, when copying text from Oracle CDD/Repository, the Compaq
COBOL compiler translates the record descriptions into the reference format of
the source program. ♦
1.1.3.1 Terminal Reference Format
Compaq recommends using terminal format, a Compaq optional format, when
you create source files from interactive terminals. The compiler accepts terminal
format as the default reference format.
Terminal format eliminates the line number and identification fields of ANSI
format and allows horizontal tab characters and short lines. Terminal format
saves disk space and decreases compile time. It is easier to edit source code
written in terminal format.
The following table shows the structure and content of a terminal reference
source line:
Character PositionsContents
1 to 4Area A
5 to 256Area B
End of lineMargin R
You can use the Tab key or the space bar to position source entries in a line.
Pressing the Return key signifies the end of a line. Terminal format treats the
end of each line as Margin R. Use a continuation (-) character when you want to
continue a line. (This is useful for a quoted literal that is too long for one line.)
If you wish to use a hyphen or continuation dash (-), a comment asterisk (*), or a
skip-to-top-of-page slash (/) character, it must be placed in column 1. If you wish
to use conditional compilation characters, they must be placed in columns 1 and
2. For more information about using conditional compilation characters and the
Tab key, see the Compaq COBOL Reference Manual.
1–6 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
(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.
For ANSI format, the compiler expects 80-character program lines. The following
table shows the structure and content of an ANSI reference source line:
Character PositionsContents
1 to 6Optional sequence numbers
7Indicators
8 to 11Area A
12 to 72Area B
73 to 80Optional Area
For more information about the two reference formats, see the Compaq COBOLReference Manual.
Developing Compaq COBOL Programs
-ansi
flag
1.1.3.3 Converting Between Reference Formats
The REFORMAT utility allows you to convert a terminal format program to ANSI
format and vice versa. You can also use REFORMAT to match the formats of
Compaq COBOL source files and library files when their formats are not the
same. See Chapter 14 for a description of the REFORMAT utility.
1.2 Developing Programs on Tru64 UNIX
This section briefly describes the Tru64 UNIX commands (commands used at the
operating system prompt) that you use to create, compile, link, and run Compaq
COBOL programs on Tru64 UNIX systems.
1.2.1 Creating a Compaq COBOL Program on Tru64 UNIX
Use a text editor, such asvior
instance, to edit the file
% vi prog1.cob
Figure 1–1 shows the basic steps in Compaq COBOL program development on
Tru64 UNIX systems.
When naming a source file, choose one of the four file name extensions that the
cobol
compiler recognizes as COBOL file suffixes. These suffixes are:
prog1.cob
emacs
, to create and revise your source files. For
using thevieditor, type:
Developing Compaq COBOL Programs 1–7
Developing Compaq COBOL Programs
1.2 Developing Programs on Tru64 UNIX
Figure 1–1 Commands for Developing Compaq COBOL Programs on Tru64
UNIX
COMMANDS
% vi prog1.cob
Use the file type of cob
to indicate the file contains
a Compaq COBOL program.
% cobol -c prog1.cob
The cobol command
assumes 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.)
% cobol prog1.o
The link command
assumes file type.no
% a.out
Type the output file name
to run the image.
no
ACTION
Create a
source program
Compile the
source program
Link the
object module
Run the
executable
image
INPUT/OUTPUT FILES
prog1.cob
(prog1.o,
prog1.lis)
libraries
a.out
Note: case of file names is significant.
VM-0610A-AI
1–8 Developing Compaq COBOL Programs
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
SuffixDescription
.c
.s
.o
.a
.so
The following
automatically uses the linkerldto link the main program into an executable
program file named
% cobol prog1.cob
The
and Compaq COBOL libraries to the
program reside in these standard libraries, additional libraries or object files are
not specified on the
If your path definition includes the directory containing
program by simply typing its name:
Identifies C language files passed to the C compiler drivercc, which performs
additional command line parsing before invoking the C language compiler.
Identifies assembler files passed tocc. Compaq COBOL does not generate .s
files.
Identifies object files passed tocc, which are in turn passed told.
Identifies archive object libraries passed tocc, which are in turn passed told.
All routines in the specified object library will be searched during linking to
resolve external references. This is one method of specifying special libraries
for which the
Identifies shared object libraries passed tocc, which are in turn passed told.
All routines in the specified object library will be searched during linking to
resolve external references. This is one method of specifying special libraries
for which the
cobol
cobol
command automatically passes a standard default list of Tru64 UNIX
cobol
cobol
command compiles the program named
a.out
cobol
command does not automatically search.
command does not automatically search.
(the name used if you do not specify a name):
ld
linker. If all external routines used by a
command line.
a.out
prog1.cob
, you can run the
and
% a.out
If the executable image is not in your current directory path, specify the directory
path in addition to the file name.
The COPY Statement and Libraries
As you write a program, you can use the COPY statement in your source program
to include text from another file. With the COPY statement, separate programs
can share common source text kept in libraries, reducing development and testing
time as well as storage. The Compaq COBOL Reference Manual explains how to
use the COPY statement.
Special Considerations for Routines Named ‘‘main’’
If you have a program or routine named ‘‘main,’’ declared either in a Compaq
COBOL or other module, your application may not work correctly. The Compaq
COBOL library contains a routine named ‘‘main,’’ which initializes the run-time
environment for the CALL by data name statements, extended ACCEPT and
DISPLAY statements, and some error handling. When your application also
declares a ‘‘main,’’ your routine preempts the Compaq COBOL routine, and the
run-time initialization is not performed.
Developing Compaq COBOL Programs 1–9
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:
1.2.2 Compiling a Compaq COBOL Program on Tru64 UNIX
Compilation does the following for you:
•Detects errors in your program syntax
•Displays compiler messages on your terminal screen
•Generates machine language instructions from valid source statements
•Groups the instructions into an object module for the linker
To compile your program, use the
The COBOL Command Driver
The
cobol
the Compaq COBOL compiler. It accepts a list of command flags and file names
and causes one or more processors (compiler, assembler, or linker) to process each
file.
After the Compaq COBOL compiler processes the appropriate files to create
command invokes a compiler driver that is the actual user interface to
cobol
command.
ld
Developing Compaq COBOL Programs
1.2 Developing Programs on Tru64 UNIX
An example
% cobol -v test.cob pas.o
This command specifies the following:
•The-vflag displays the compilation and link passes with their arguments
and files, including the libraries passed told.
•The file
The resulting object file is then linked.
•The object file
As an additional example, you might find that your compiler command lines are
getting rather long, as shown in the following example:
% cobol -rsv foreign_extensions -flagger high_fips -warn information zeroes.cob
To work around this, you may truncate compiler flag options (arguments) to their
shortest unambiguous form, as follows:
% cobol -rsv for -flagger high -warn info zeroes.cob
1.2.2.2 COBOL Command Flags
Flags to the
simplest form of the
If you compile parts of your program (compilation units) using multiple
commands, flags that affect the execution of the program should be used
consistently for all compilations, especially if data will be shared or passed
between procedures.
cobol
test.cob
cobol
command line would be:
is passed to the Compaq COBOL compiler for compilation.
pas.o
is passed directly to the linker.
command affect how the compiler processes a file. The
cobol
command is often sufficient.
cobol
For a complete list of Compaq COBOL flags, see Table 1–2. For more information
about the Compaq COBOL flags, access the reference (man) page for COBOL at
the Tru64 UNIX system prompt. For example:
%man cobol
Developing Compaq COBOL Programs 1–11
Developing Compaq COBOL Programs
1.2 Developing Programs on Tru64 UNIX
Table 1–2 Compaq COBOL Command Flags on Tru64 UNIX
Table 1–2 (Cont.) Compaq COBOL Command Flags on Tru64 UNIX
FlagDefault
-T num
-taso
-tps
-trunc
-tune-tune generic
-V
-v
-w
-warn-warn other
-warn all
-warn [no]information-warn noinformation
-warn [no]other-warn other
-warn none
-xref, -xref_stdout
off
off
off
off
off
off
off
off
off
off
Technical Notes:
1. If your program compile generates Errors (E-level diagnostics on OpenVMS
Alpha), the link phase of the two steps taken by the compiler driver will
be aborted and the object file(s) deleted. You can override this deletion by
specifying the-cflag:
% cobol -c test.cob
% cobol test.o
The Compaq COBOL compiler driver (see Section 1.2.2) controls a sequence of
operations (as required): compiling, assembling, linking. The-cflag signals
the compiler driver to break the sequence.
(For additional information, see The COBOL Command Driver description
(earlier in this chapter), Section 1.2.2.12, and the-cdescription under
.)
cobol
2. The
3. The
-tps
flag causes the Compaq COBOL compiler to use an external file
handler (produced by a third party), providing increased flexibility in cross
platform, transaction processing application development. See Section 1.2.2.3
for more information.
-xref
to generate a data file that the Compaq FUSE Database Manager uses to
create a static analysis database file. This improves the performance of the
Compaq FUSE Call Graph Browser and the Compaq FUSE Cross-Referencer,
which use the database file for their operations. See the Compaq FUSE
documentation for more information on the Compaq FUSE static analysis
database, the Compaq FUSE Cross-Referencer and Compaq FUSE Call Graph
Browser.
Specifying the
file to standard output.
and
-xref_stdout
-xref_stdout
flags direct the Compaq COBOL compiler
option directs the compiler to output the data
man
1–14 Developing Compaq COBOL Programs
4. Any copy file that contains a PROGRAM-ID or END PROGRAM statement for
a program must contain that entire program. When compiled in the Compaq
FUSE environment (using the compiler options
certain Compaq COBOL programs may fail, with this fatal diagnostic result:
cobol: Severe: Fatal error -7 returned from a cross-referencing
library procedure
To avoid this error, programmers should ensure that any subroutine beginning
in a given file ends in the same file.
1.2.2.3 External File Handler Support
The
-tps
flag allows Compaq COBOL applications to make use of ACMSxp, the
Application Control and Management System/Cross-Platform Edition.
-tps
specifies that files are part of a transaction processing system, and enables
Encina Structured File System (SFS) record storage for applicable files. It is
intended to be used in conjunction with the Transarc Encina external file handler
and ACMSxp, allowing access to data in a wide variety of databases, without
the need to write code in the language of the databases. This approach provides
access to transaction processing technology, and incorporates industry standards
for data communications and distributed computing. ACMSxp conforms to the
the Multivendor Integration Architecture (MIA).
Developing Compaq COBOL Programs
1.2 Developing Programs on Tru64 UNIX
-xrefor-xref_stdout
),
COBOL is one of the languages approved by MIA for transaction processing
(TP) client programs, customer-written presentation procedures, and processing
procedures. For database access, Structured Query Language (SQL) is the
MIA-required access language. The SQL is embedded in COBOL and C.
See the ACMSxp documentation for full details. Additional information
can also be found in published Distributed Computing Environment (DCE)
documentation.
1.2.2.4 Specifying Multiple Files and Flags
The
cobol
file names are delimited by spaces. If appropriate, each file name can have a
different suffix. The file name suffix could result in the following actions:
•Calling another language compiler, such as the C compiler
•Passing object files directly to the linker, which the linker combines with
other object files
•Passing an object library to the linker, which the linker uses to search for
unresolved global references
When a file is not in your current working directory, specify the directory path
before the file name.
1.2.2.5 Compiling Multiple Files
An entire set of source files can be compiled and linked together using a single
cobol
command can specify multiple file names and multiple flags. Multiple
The resulting file names are com1.o and com2.o. The OpenVMS Alpha equivalent
to this is:
. The last command compiles the main program and links the object
mainprog.cob
, which contains the main program
calc
array_calc.o
. The second command creates the file
calc
.
calc
, you can run the
$ COBOL proga1+proga2+proga3,progb1+progb2
1.2.2.6 Debugging a Program
To debug a program using the Ladebug Debugger, compile the source files
with the-gflag to request additional symbol table information for source line
debugging in the object and executable program files. The following
command also uses the-oflag to name the executable program file
To debug an executable program named calc_debug, type the following command:
% ladebug calc_debug
For more information on running the program within the debugger, see the
Ladebug Debugger Manual.
1.2.2.7 Output Files: Object, Executable, Listing, and Temporary Files
The output produced by the
•An object file, if you specify the-cflag on the command line
•An executable file, if you omit the-cflag
•A listing file, if you specify the-Vflag
If the environment variable TMPDIR is set, the value is used as the directory for
temporary files.
You control the production of these files by specifying the appropriate flags on
the
cobol
single temporary object file, whether you specify one source file or multiple source
files separated by blanks. Theldlinker is then invoked to link the object file into
one executable image file.
command line. Unless you specify the-cflag, the compiler generates a
cobol
command includes:
cobol
calc_debug
:
1–16 Developing Compaq COBOL Programs
Developing Compaq COBOL Programs
1.2 Developing Programs on Tru64 UNIX
The object file is in Tru64 UNIX extended
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.
•A symbol table and a source line correlation table (if you request them
with the
external and internal variables within a module, with definitions of their
locations. The source line correlation table associates lines in your source file
with lines in your program. These tables are of use in debugging.
If severe errors are encountered during compilation or if you specify certain flags
-c
such as
1.2.2.8 Naming Output Files
To specify a file name (other than
-o
output flag, where output specifies the file name. You can also use the
command to rename the file. The following command requests a file name of
prog1.out
% cobol -o prog1.out test1.cob
Besides specifying the name of the executable image file, you can use the
output flag to rename the object file if you specified the-cflag. If you specify the
-c
flag and omit the-ooutput flag, the name of the first specified file is used with
a.osuffix substituted for the source file suffix.
, linking does not occur.
for the source file
coff
format. The object file provides
-g
flag, for debugging). A symbol table is a list of the names of all
a.out
) for the executable image file, use the
test1.cob
:
mv
-o
1.2.2.9 Temporary Files
Temporary files created by the compiler or a preprocessor reside in the
directory and are deleted (unless the-Kflag is specified). You can set the
environment variable TMPDIR to specify a directory to contain temporary files if
/tmp
is not acceptable.
To view the file name and directory where each temporary file is created, use
the-vflag. To create object files in your current working directory, use the
flag. Any object files (.ofiles) that you specify on the
retained.
1.2.2.10 Examples of the COBOL Command
The following examples show the use of the
followed by a description of the output files that it produces.
% cobol -V aaa.cob bbb.cob ccc.cob
1.
The Compaq COBOL source files
into temporary object files. The temporary object files are passed to the
linker. Theldlinker produces the executable file
the compiler to create the listing files
cobol
cobol
aaa.cob,bbb.cob
command. Each command is
, and
a.out
aaa.lis,bbb.lis
/tmp
-c
command line are
ccc.cob
are compiled
ld
. The-Vflag causes
, and
ccc.lis
.
Developing Compaq COBOL Programs 1–17
Developing Compaq COBOL Programs
1.2 Developing Programs on Tru64 UNIX
% cobol -V *.cob
2.
Compaq COBOL source files with file names that end with .cob are compiled
into temporary object files, which are then passed to theldlinker. The
linker produces the a.out file.
ld
When the compilation completes, the
status values:
You can compile and link multilanguage programs using a single
The
cobol
command recognizes C or Assembler program files by their file
suffix characters and passes them to thecccompiler for compilation. Before
compilation,
applies the
cpp
preprocessor to files that it recognizes, such as
cc
any file with a.csuffix.
Certain flags passed toccare passed to theldlinker.
1.2.2.12 Interpreting Messages from the Compiler
The Compaq COBOL compiler identifies syntax errors and violations of language
rules in the program. If the compiler finds any errors, it writes messages to
the
stderr
output file and any listing file. If you enter the
interactively, the messages are displayed on your terminal.
Compiler messages have the following format:
cobol: severity: filename, line n, message-text
[text-in-error]
--------^
cobol
driver returns one of the following
cobolorcc
)
cobol
cobol
command.
command
The pointer (
--^
) indicates the exact place on the source line where the error was
found. For example, the following error message shows the format and message
text in a listing file when an END DO statement was omitted:
cobol: Severe: disp.cob, line 7: Missing period is assumed
05 VAR-1 PIC X.
--------^
The severity level is one of the following:
SevereThe compiler does not produce an object module. You must correct
ErrorThe compiler makes an assumption about what you intended and
WarningThe compiler attempts to correct the error in the statement,
InformationalThis message usually appears with other messages to inform you
the error before you can compile the program to produce an object
module.
continues. However, the compiler’s assumption may not relate to
your intention. Correct the error.
but you should verify that the compiler’s action is acceptable.
Otherwise, your program may produce unexpected results.
of specific actions taken by the compiler. No action is necessary on
your part.
1–18 Developing Compaq COBOL Programs
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-Vor
produce a listing; you may also use
-machine_code,-map
file.
Diagnostic messages provide information for you to determine the cause of an
error and correct it. If the compiler creates a listing file, it writes the messages to
the listing file.
, and/or
-warn
-cross_reference,-copy_list,-flagger
, all of which affect the contents of the listing
1.2.3 Linking a Compaq COBOL Program on Tru64 UNIX
Once your program has compiled successfully, the system passes the resulting
object file (which has the suffix .o by default) to the linker to create an executable
image file. By default, the executable image file has the name a.out. (To change
-o
this default, specify
on the Tru64 UNIX system.
Theldlinker provides the following primary functions:
•Generates appropriate information in the executable image for virtual
memory allocation
•Resolves symbolic references among object files being linked, including
whether to search in archive or shared object libraries
filename on the
cobol
command line.) This file can be run
-list
flag to
,
•Assigns values to relocatable global symbols
•Performs relocation
The linker produces an executable program image with a default name of a.out.
When you enter a
a compilation error occurs or you specify the
1.2.3.1 Specifying Object Libraries for Linking
You can specify object libraries on the
flags or by providing the file name of the library. These object libraries are also
searched byldfor unresolved external references.
When
library file names told. Theldlinker tries to locate each of these library file
names in a standard list of library directories. That is,ldattempts to locate each
object library file name first in one directory, then in the second, and then in the
third directory on its search list of directories.
To display a list of the compilers invoked, files processed, and libraries accessed
during linking, specify the
In addition to an object file created by the compiler, any linker flags and object
files specified on the
linker loads object files according to the order in which they are specified on the
command line. Because of this, you must specify object libraries after all source
and object files on the
cobol
cobol
specifies certain libraries told, it provides a standard list of COBOL
command, theldlinker is invoked automatically unless
-v
flag.
cobol
command are also passed to theldlinker. The
cobol
command line.
COBOL
-c
flag on the command line.
command line by using certain
To help identify undefined references to routines or other symbols in an object
nm
module, consider using the
the
nm
command filtered by the
% cobol -c ex.cob
% nm -o ex.o | grep U
command. For instance, in the following example
grep
command lists all undefined (U) symbols:
Developing Compaq COBOL Programs 1–19
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 withaUintheir names can also be displayed by this use of
1.2.3.2 Specifying Additional Object Libraries
You can control the libraries as follows:
•To specify additional object library file names forldto locate, use the
-l
string flag to define an additional object library forldto search. Thus, each
occurrence of the-lstring flag specifies an additional file name that is added
to the list of object libraries for
names searched (shown in the form of the appropriate
-lcob
-lcurses
-lFutil
-lots2
-lots
-lisam
-lsort
-lexc
-lm
For instance, the file name of
The following example specifies the additional library
grep
ld
to locate. The standard COBOL library file
-l
string flag) are:
-lcobislibcob
.
libX
:
.
% cobol simtest.cob -lX
•In addition to the standard directories in whichldtries to locate the library
file names, you can use the-Ldir flag to specify another directory. The
-l
string flag and-Ldir flag respectively adds an object library file name
(-lstring) or directory path (-Ldir) thatlduses to locate all specified library
ld
files. The standard
the
-L
dir flag.
The following example specifies the additional object library path
/usr/lib/mytest
% cobolsimtest.cob -L/usr/lib/mytest
•You can indicate thatldshould not search its list of standard directories at
all by specifying the-Lflag. When you do so, you must specify all libraries
on the
standard libraries. To specify all libraries, you might use the-Lflag in
combination with the-Ldir flag on the same
•You can specify the pathname and file name of an object library as you
would specify any file. Specifying each object library that resides in special
directories in this manner is an alternative to specifying the library using the
-l
linker must do to locate all the needed object files.
In certain cases, you may need to specify the pathname and file name instead
of using the-lstring or-Ldir flags for the linker to resolve global symbols
with shared libraries.
cobol
string or-Ldir flag. This method can reduce the amount of searching the
command line in some form, including the directory for
directories are searched before directories specified by
:
cobol
command line.
cobol
When processing a C source file (
need to specify the appropriate C libraries using the
1–20 Developing Compaq COBOL Programs
.c
suffix) using the
cobol
-l
string flag.
command, you may
1.2.3.3 Specifying Types of Object Libraries
Certain
object (
libraries specified using the-lstring or-Ldir flags. These flags are the following:
cobol
.so
flags influence whetherldsearches for an archive (.a) or shared
) library on the standard list of COBOL libraries and any additional
Developing Compaq COBOL Programs
1.2 Developing Programs on Tru64 UNIX
•The
•The
External references found in an archive library result in that routine being
included in the resulting executable program file at link time.
External references found in a shared object library result in a special link to
that library being included in the resulting executable program file, instead of the
actual routine itself. When you run the program, this link gets resolved by either
using the shared library in memory (if it already exists) or loading it into memory
from disk.
1.2.3.4 Creating Shared Object Libraries
To create a shared library, first create the
following example:
-call_shared
before.afiles. Asldattempts to resolve external symbols, it looks at the
shared library first before the corresponding archive library. References
to symbols found in a
run time. References to symbols found in.alibraries are loaded into the
executable image file at link time. For instance,
searched before
-non_shared
module created contains static references to external routines and are loaded
into the executable image at link time, not at run time. Corresponding
files are not searched.
The following example requests that the standard
instead of the corresponding
% cobol -non_shared mainprog.cob rest.o
flag, the default, indicates that
/usr/lib/libc.a
flag indicates that only.afiles are searched, so the object
COBOL command would have otherwise passed told. When you create a
shared library, all symbols must be resolved. For more information about the
standard list of libraries used by Compaq COBOL, see Section 1.2.3.2.
is then used as input to theldcommand to create the shared
octagon.so
flag is required to create a shared library.
and subsequent flags are the standard list of libraries that the
:
flag indicates thatldshould not search archive libraries to
octagon.o
. You can specify multiple.ofiles.
Developing Compaq COBOL Programs 1–21
Developing Compaq COBOL Programs
1.2 Developing Programs on Tru64 UNIX
1.2.3.5 Shared Library Restrictions
When creating a shared library usingld, be aware of the following restrictions:
•Programs that are installed
have been installed using the
shared libraries (for security reasons).
•For other restrictions imposed by the operating system, see your operating
system documentation. If you create a shared library that contains
routines written in C, refer to your operating system documentation for
any restrictions associated with thecccommand.
1.2.3.6 Installing Shared Libraries
Once the shared library is created, it must be installed before you run a program
that refers to it. The following describes how you can install a shared library for
private or systemwide use:
•To install a private shared library, such as for testing, set the environment
variable LD_LIBRARY_PATH, as described in ld(1).
•To install a systemwide shared library, place the shared library file in one of
the standard directory paths used byld(see ld(1).
For complete information on installing shared libraries, see your operating system
documentation.
Specifying Shared Object Libraries
When you link your program with a shared library, all symbols must be
referenced before
libraries at the end of the
you specify the
corresponding archive libraries.
ld
-non_shared
setuidorsetgid
inlib
searches the shared library, so you should always specify
cobol
command line after all file names. Unless
flag, shared libraries will be searched before the
shell command, but only systemwide
will not use any libraries that
For instance, the following command generates an error if the file
references routines in the library
% cobol -call_shared test.cob -lX rest.o
The correct order follows:
% cobol -call_shared test.cob rest.o -lX
Link errors can occur with symbols that are defined twice, as when both an
archive and shared object are specified on the same command line. In general,
specify any archive libraries after the last file name, followed by any shared
libraries at the end of the command line.
Before you reference a shared library at run time, it must be installed.
1.2.3.7 Interpreting Messages from the Linker
If the linker detects any errors while linking object modules, it displays messages
about their cause and severity. If any errors occur, the linker does not produce an
image file.
Linker messages are descriptive, and you do not normally need additional
information to determine the specific error. The general format for
follows:
ld:
message-text
libX
rest.o
:
ld
messages
1–22 Developing Compaq COBOL Programs
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
Some common errors that occur during linking resemble the following:
•An object module has compilation errors. This error occurs when you attempt
•The modules being linked define more than one transfer address. The linker
•A reference to a symbol name remains unresolved. This error occurs when
If an error occurs when you link modules, you may be able to correct it by
retyping the command string and specifying the correct routines or libraries
(
command line.
error.
to link a module that had warnings or errors during compilation. Although
you can usually link compiled modules for which the compiler generated
messages, you should verify that the modules will actually produce the output
you expect.
generates a warning if more than one main program has been defined. This
can occur, for example, when an extra END statement exists in the program.
The image file created by the linker in this case can be run; the entry point to
which control is transferred is the first one that the linker found.
you omit required module or library names from the
and the linker cannot locate the definition for a specified global symbol
reference.
-l
string flag,-Ldir flag), or specify the object library or object modules on the
cobolorld
command
1.2.4 Running a Compaq COBOL Program on Tru64 UNIX
The simplest form of the run command to execute a program is to type its file
name at the operating system prompt, as follows:
% myprog.out
In addition to normal IO accesses, your Compaq COBOL programs can read
command-line arguments and access (read and write) environment variables.
1.2.4.1 Accessing Command-Line Arguments
Command-line arguments allow you to provide information to a program at
run time. Your program provides the logic to parse the command line, identify
command-line options, and act upon them. For example, you might develop a
program that will extract a given amount of data from a specified file, where both
the number of records to read and the file name are highly dynamic, changing
for each activation of your program. In this case your program would contain
code that reads a command-line argument for the number of records to read, and
a second argument for the file specification. Your program execution command
could look like the following:
% myprog 1028 powers.dat
In the preceding example the program
file powers.dat.
Multiple command-line arguments are delimited by spaces, as shown in the
preceding example. If an argument itself contains spaces, enclose that argument
in quotation marks (" ") as follows:
myprog
would read 1028 records from the
% myprog2 "all of this is argument 1" argument2
Developing Compaq COBOL Programs 1–23
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 CompaqCOBOL Reference Manual.
1.2.4.2 Accessing Environment Variables
You can read and write environment variables at run time through your Compaq
COBOL program.
Example 1–1 allows you to specify a file specification by putting the directory
in the value of the environment variable COBOLPATH, and the file name in a
command-line argument:
Example 1–1 Accessing Environment Variables and Command-Line Arguments
•file-spec will contain ‘‘/usr/files/powers.dat’’
For additional information, see the ACCEPT and DISPLAY statements in the
Compaq COBOL Reference Manual.
1.2.4.3 Errors and Switches
See Section 1.4 for a discussion of errors that can cause incorrect or undesirable
results when you run a program.
See Section 1.5 for a discussion of controlling program execution with switches.
1.2.5 Program Development Stages and Tools
This manual primarily addresses the program development activities associated
with development and testing phases. For information about topics usually
considered during application design, specification, and maintenance, see your
operating system documentation, appropriate reference pages, or appropriate
commercially published documentation.
Developing Compaq COBOL Programs 1–25
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 ActivityTool and Description
Manage source filesUse
Create and modify
source files
Analyze source codeUse searching commands such as
Build program (compile
and link)
Debug and test programUse the Ladebug Debugger to debug your program or run it for
Install programUse
RCSorsccs
see the Tru64 UNIX documentation on programming support
tools or the appropriate reference page.
Use a text editor, such as
more information, see your operating system documentation.
more information, see the Tru64 UNIX documentation on
programming support tools or the appropriate reference page.
You can use the
perhaps using shell scripts, or use the
your application in an automated fashion using a makefile.
For more information on
and the Tru64 UNIX documentation on programming support
tools.
general testing. For more information on Ladebug Debugger,
see the Ladebug Debugger Manual.
setld
more information, see the Tru64 UNIX documentation on
programming support tools.
to manage source files. For more information,
vi,emacs
cobol
command to create small programs,
make
and related commands such as
, or another editor. For
grep
and
diff
make
command to build
, see the make(1) reference page
tar
. For
. For
In addition, you might use the following shell commands at various times during
program development:
•To view information about an object file or an object library, use the following
commands:
The
file
command shows the type of a file (such as which programming
language, whether it is an object library, ASCII file, and so forth).
Thenmcommand (perhaps with the-aor-oflag) shows symbol table
information, including the identification field of each object file.
The
The
odump
size
command shows the contents of a file and other information.
command shows the size of the code and data sections.
For more information on these commands, see the appropriate reference page
or the DIGITAL UNIX Programmer’s Guide.
•Use thearcommand to create an archive object library (-rflag), maintain
the modules in the library, list the modules in the library (-t), and perform
-ts
other functions. Use
to add a table of contents to the object library for
linking purposes. For more information, see ar(1) or the DIGITAL UNIXProgrammer’s Guide.
•To create shared libraries on Tru64 UNIX systems, useld, not the
ar
command. For more information, refer to Section 1.2.3.4 and the DIGITAL
UNIX Programmer’s Guide.
1–26 Developing Compaq COBOL Programs
Developing Compaq COBOL Programs
1.2 Developing Programs on Tru64 UNIX
•The
In most instances, use the
compiler and theldlinker. To link one or more object files created by the Compaq
COBOL compiler, you should use the
because the
COBOL Run-Time Libraries when it invokes
your current working directory, specify the directory path in addition to the file
name. ♦
Compilation does the following for you:
•Detects errors in your program syntax
•Displays compiler messages on your terminal screen
•Generates machine language instructions from valid source statements
•Groups the instructions into an object module for the linker
strip
minimize image size. For additional information, see strip(1).
The CALL dataname, CANCEL, and the Compaq extensions to the
ACCEPT and DISPLAY statements will not work correctly if you use the
strip
command removes symbolic and other debugging information to
Note
command on your image.
cobol
cobol
command automatically references the appropriate Compaq
command to invoke both the Compaq COBOL
cobol
command instead of theldcommand,
ld
. If the executable image is not in
•Launches the linker with the compiled file or files
•Creates an executable image
You use the COBOL command to compile and link your program. The COBOL
command invokes the Compaq COBOL compiler driver that is the actual user
interface to the Compaq COBOL compiler. The compiler driver can accept
command options and multiple file names, and normally causes the compiler and
linker to process each file. A variety of qualifiers to the compile command are
available to specify optional processing and to specify the names of output files.
After the Compaq COBOL compiler processes the source files to create one
or more object files, the compiler driver passes a list of object files and other
information to the linker.
1.3 Developing Programs on OpenVMS Alpha
You use DCL commands (commands used at the OpenVMS Alpha system prompt)
to create, compile, link, and run Compaq COBOL programs on OpenVMS Alpha
systems.
1.3.1 Creating a Compaq COBOL Program on OpenVMS Alpha
To create and modify a Compaq COBOL program, you must invoke a text editor.
The default editor for OpenVMS Alpha is the DEC Text Processing Utility
(DECTPU). Other editors, such as EDT or the Language-Sensitive Editor (LSE),
may be available on your system. Check with your system administrator and
refer to the OpenVMS EDT Reference Manual (this manual has been archived
but is available on the OpenVMS Documentation CD-ROM) for more information
about EDT or the Guide to Language-Sensitive Editor for additional information
about LSE.
Developing Compaq COBOL Programs 1–27
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 to
indicate the file contains a
Compaq COBOL program.
COBOL PROG_1$
The Command
COBOL
assumes the file type of an
input file is .
(if you use the
qualifier, the compiler
creates a listing file.)
LINK PROG_1
$
The command assumes
LINK
the file type of an input file
is .
OBJ
(If you use the qualifier,
the linker creates a map file.)
RUN PROG_1
$
RUN
The command assumes
the file type of an image is
EXE
.
COB
COB
/LIST
/MAP
ACTION
Create a
source program
Compile the
source program
Link the
object module
Run the
executable
image
INPUT/OUTPUT FILES
PROG_1.COB
PROG_1.OBJ
(PROG_1.LIS)
libraries
PROG_1.EXE
(PROG_1.MAP)
VM-0611A-AI
Figure 1–2 shows the basic steps in Compaq COBOL program development.
Use the text editor of your preference to create and revise your source files. For
example, the following command line invokes the DECTPU editor and creates the
source file PROG_1.COB:
$ EDIT PROG_1.COB
The file type .COB is used to indicate that you are creating a Compaq COBOL
program. COB is the default file type for all Compaq COBOL programs.
The COPY Statement, Dictionaries and Libraries
Including the COPY statement in your program allows separate programs to
share common source text, reducing development and testing time as well as
storage requirements. You can use the COPY statement to access modules in
libraries. The COPY statement causes the compiler to read the file or module
specified during the compilation of a program. When the compiler reaches the
end of the included text, it resumes reading from the previous input file.
By using the /INCLUDE qualifier on the COBOL command line, you can set up a
search list for files specified by the COPY statement. For more information, see
the Compaq COBOL Reference Manual.
1–28 Developing Compaq COBOL Programs
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).
For more information about using Oracle CDD/Repository and creating and
maintaining text libraries, refer to the Compaq COBOL Reference Manual and
Using Oracle CDD/Repository on OpenVMS Systems.
1.3.2 Compiling a Compaq COBOL Program on OpenVMS Alpha
To compile your program, use the COBOL command. The Compaq COBOL
compiler performs these primary functions:
•Detects errors in your program
•Displays each compiler message on your terminal screen
•Generates machine language instructions from valid source statements
•Groups these language instructions into an object module for the linker
•Creates an analysis file if you request it with the /ANALYSIS_DATA qualifier.
SCA uses this file to display information about program symbols and source
files.
The compiler outputs an object module that 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 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.
•Traceback information. This information is used by the system default
condition handler when an error occurs that is not handled by the program.
The traceback information permits the default handler to display a list of the
active blocks in the order of activation; this is an aid in program debugging.
•A symbol table and a source line correlation table, only if you request them
with the /DEBUG qualifier. A symbol table is a list of the names of all
external and internal variables within a module, with definitions of their
locations. The source line correlation table associates lines in your source file
with lines in your program. These tables are of primary help when you use
the OpenVMS Debugger.
To invoke the Compaq COBOL compiler, use the COBOL command (explained
in Section 1.3.2.1). You can specify qualifiers with the COBOL command. The
following sections discuss the COBOL command and its qualifiers.
1.3.2.1 Format of the COBOL Command on OpenVMS Alpha
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.
file-spec
Specifies an input source file that contains the program or module to be compiled.
You are not required to specify a file type; the Compaq COBOL compiler assumes
the default file type COB. If you do not provide a file specification with the
COBOL command, the system prompts you for one.
1.3.2.2 Compiling Multiple Files
You can include more than one file specification on the same command line by
separating the file specifications with either a comma (,) or a plus sign (+). If
you separate the file specifications with commas, you can control which source
files are affected by each qualifier. In the following example, the Compaq COBOL
compiler creates an object file for each source file but creates only a listing file for
the source files entitled PROG_1 and PROG_3:
$ COBOL/LIST PROG_1, PROG_2/NOLIST, PROG_3
If you separate file specifications with plus signs, the Compaq COBOL compiler
concatenates each of the specified source files and creates one object file and one
listing file. In the following example, only one object file, PROG_1.OBJ, and one
listing file, PROG_1.LIS, are created. Both of these files are named after the first
source file in the list, but contain all three modules.
$ COBOL PROG_1 + PROG_2/LIST + PROG_3
Any qualifiers specified for a single file within a list of files separated with plus
signs affect all files in the list.
1.3.2.3 Debugging a Program
To effectively debug a Compaq COBOL program, you must first make symbol
and traceback information available by adding the DEBUG option to the compile
command line. You specify the /DEBUG option as follows:
This enables you to examine and modify variables, monitor flow of control,
and perform various other debugging techniques. See HELP COBOL/DEBUG,
HELP DEBUG, and Section C.4, OpenVMS Debugger (OpenVMS) for additional
information.
When you compile a program with /DEBUG, you should also specify
/NOOPTIMIZE (-O0) to expedite your debugging session. (The default is
/OPTIMIZE (-O).) Optimization often changes the order of execution of the object
code generated for statements in a program, and it might keep values in registers
and deallocate user variables. These effects can be confusing when you use the
debugger. (A diagnostic message warns you if you compile a Compaq COBOL
program with /DEBUG without specifying anything about optimization on the
command line.)
1–30 Developing Compaq COBOL Programs
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.
If you use /SEPARATE_COMPILATION on the compile command line Compaq
COBOL will compile multiple SCPs into a single object file that consists of a
concatenation of modules, each containing a single procedure. This object may
then be inserted into an object library from which the linker can extract just the
procedures that are specifically needed.
1.3.2.5 COBOL Qualifiers
COBOL options (also known as qualifiers or flags) control the way in which the
compiler processes a file. You can process your file with the COBOL command
alone or you can select options that offer you alternatives for developing,
debugging, and documenting programs.
If you compile parts of your program (compilation units) using multiple COBOL
commands, options that affect the execution of the program should be used
consistently for all compilations, especially if data will be shared or passed
between procedures.
Developing Compaq COBOL Programs
1.3 Developing Programs on OpenVMS Alpha
Table 1–4 lists the COBOL command options and their defaults. For more
information about COBOL options, invoke online help for COBOL at the system
prompt.
Note
Brackets ([]) indicate that the enclosed item is optional. If you specify
more than one option for a single qualifier, you must separate each option
with a comma and enclose the list of options in parentheses.
Developing Compaq COBOL Programs 1–31
Developing Compaq COBOL Programs
1.3 Developing Programs on OpenVMS Alpha
Table 1–4 COBOL Command Qualifiers
QualifierDefault
/ALIGNMENT[=[NO]PADDING] or
/NOALIGNMENT
/ANALYSIS_DATA[=file-spec] or
/NOANALYSIS_DATA
/ANSI_FORMAT or /NOANSI_FORMAT/NOANSI_FORMAT
/ARCHITECTURE=
n
/ARITHMETIC=
2
[NO]PERFORM
[NO]BOUNDS
66
/CHECK=
or /NOCHECK
[NO]DECIMAL
6
[NO]DUPLICATES
4
1
ALL
NONE
8
GENERIC
>
>
HOST
>
>
>
>
EV4
<
EV5
EV56
>
>
>
>
EV6
>
>
:
EV67
PCA56
STANDARD
NATIVE
9>
>
>
>
>
>
=>
>
>
>
>
>
;
o
37
7
,...
75
/NOALIGNMENT
/NOANALYSIS_DATA
/ARCHITECTURE=GENERIC
/ARITHMETIC=NATIVE
/NOCHECK or /CHECK=NONE
/CONDITIONALS=(character,...) or
/NOCONDITIONALS
/CONVERT=[NO]LEADING_BLANKS or
/NOCONVERT
/COPY_LIST or /NOCOPY_LIST/NOCOPY_LIST
/CROSS_REFERENCE=
h
ALPHABETICAL
DECLARED
or /NOCROSS_REFERENCE
1
This is the default keyword when using the named option with no keywords.
This is the default keyword when using the named option with no keywords.
1.3.2.6 Common Command-Line Errors to Avoid
The following are some common errors to avoid when entering COBOL command
lines:
•Omitting /ANSI_FORMAT for programs that are in ANSI format (AREA A,
AREA B, and so forth)
•Including contradictory options
•Omitting a necessary qualifier, such as /LIST if you specify /MAP
•Omitting version numbers from file specifications when you want to compile a
program that is not the latest version of a source file
Developing Compaq COBOL Programs 1–35
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. For more information
about the /CONDITIONALS qualifier, invoke the online Help facility for
Compaq COBOL at the system prompt. For more information about the WITH
DEBUGGING MODE clause, refer to the Compaq COBOL Reference Manual.
Using the WITH DEBUGGING MODE clause as part of the SOURCECOMPUTER paragraph causes the compiler to process all conditional compilation
lines in your program as COBOL text. If you do not specify the WITH
DEBUGGING MODE clause, and if the /CONDITIONALS qualifier is not in
effect, all conditional compilation lines in your program are treated as comments.
The WITH DEBUGGING MODE clause applies to: ( 1 ) the program that specifies
it, and (2) any contained program within a program that specifies the clause.
1.3.2.8 Interpreting Messages from the Compiler
If there are errors in your source file when you compile your program, the
Compaq COBOL compiler flags these errors and displays helpful messages.
You can reference the message, locate the error, and, if necessary, correct the
error in your program.
The general format of compiler messages shown on your screen is shown in the
following example:
..........................^
%COBOL-s-ident, message-text
At line number n in name
%COBOL
The facility or program name of the Compaq COBOL compiler. This prefix
indicates that the Compaq COBOL compiler issued the message.
s
The severity of the error, represented in the following way:
FFatal error. The compiler does not produce an object module. You must correct the
EError. The compiler makes an assumption about what you intended and continues.
WWarning. The compiler attempts to correct the error in the statement, but you
IInformational. This message usually appears with other messages to inform you of
error before you can compile the program to produce an object module.
However, the compiler’s assumption may not relate to your intention. Correct the
error.
should verify that the compiler’s action is acceptable. Otherwise, your program
may produce unexpected results.
specific actions taken by the compiler. No action is necessary on your part. Note
that these messages are suppressed by default. You must invoke /WARN=ALL or
/WARN=INFO to enable them.
ident
The message identification. This is a descriptive abbreviation of the message text.
1–36 Developing Compaq COBOL Programs
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.
A sample compiler message with two diagnostics looks like this in the listing file:
12PROCEDURE DIVISION.
13P-NAME
14MOVE ABC TO XYZ.
................^
%COBOL-E-NODOT, Missing period is assumed
14MOVE ABC TO XYZ.
............................^
%COBOL-F-UNDEFSYM, Undefined name
In the sample, the first diagnostic pointer (^) points to the MOVE statement
in source line number 14, which is the closest approximation to where the error
(P-NAME is not followed by a period) occurred. The second diagnostic pointer
points to XYZ, an undefined name in source line number 14. Each diagnostic
pointer is followed by a message line that identifies, in this order:
•The Compaq COBOL compiler generated the message
•The severity code of the message
•The message identification (a mnemonic of the message text)
•The text of the message
Although most compiler messages are self-explanatory, some require additional
explanation. The online HELP facility for Compaq COBOL contains a list and
descriptions of these Compaq COBOL compiler messages. Use the HELP COBOL
Compiler Messages command to access this list.
To examine messages that occurred during compilation, you can search for each
occurrence of %COBOL in the compiler listing file. Section 1.3.2.9 describes
listing files.
The severity levels, and what you should do next, are as follows:
SevereThe compiler does not produce an object module. You must correct the
ErrorThe compiler makes an assumption about what you intended and
WarningThe compiler attempts to correct the error in the statement, but you
InformationalThis message usually appears with other messages to inform you of
error before you can compile the program to produce an object module.
continues. However, the compiler’s assumption may not relate to your
intention. Correct the error.
should verify that the compiler’s action is acceptable. Otherwise, your
program may produce unexpected results.
specific actions taken by the compiler. No action is necessary on your
part.
Developing Compaq COBOL Programs 1–37
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.
•Storage map
The storage map section is optional (produced by the /MAP qualifier); it
contains summary information on program sections, variables, and arrays.
•Compilation summary
The compilation summary section lists the qualifiers used with the COBOL
command and the compilation statistics.
•Machine code
The machine code section is optional; it displays compiler-generated object
code.
To generate a listing file, specify the /LIST qualifier when you compile
your Compaq COBOL program interactively as in the following example for
PROG_1.COB:
$COBOL/LIST PROG_1.COB
If you compile your program as a batch job, the compiler creates a listing file by
default. You can specify the /NOLIST qualifier to suppress creation of the listing
file, if that suits your purposes. (In either case, however, the listing file is not
automatically printed.) By default, the name of the listing file is the name of your
source file followed by the file type .LIS. You can include a file specification with
the /LIST qualifier to override this default.
When used with the /LIST qualifier, the following COBOL command qualifiers
supply additional information in the compiler listing file:
•/COPY_LIST—Includes source statements specified by the COPY command.
•/CROSS_REFERENCE—Creates a cross-reference listing of user-defined
names and references.
•/MACHINE_CODE—Includes a list of compiler-generated machine code.
•/MAP—Produces maps, data names, procedure names, file names, and
external references.
For a description of each qualifier’s function, invoke the online HELP facility for
COBOL at the system prompt as follows:
$ HELP COBOL
Compiler Listing File for a Contained Program
A contained COBOL program listing file includes two additional program
elements that provide nesting level information about the main program and
the contained program. For additional information about contained programs, see
Chapter 12, Interprogram Communication.
1–38 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.
When you execute the LINK command, the OpenVMS Alpha Linker performs the
following functions:
•Resolves local and global symbolic references in the object code
•Assigns values to the global symbolic references
•Signals an error message for any unresolved symbolic reference
•Allocates virtual memory space for the executable image
The LINK command produces an executable image by default. However, you
can specify qualifiers and qualifier options with the LINK command to obtain
shareable images and system images.
See Table 1–5 for a list of commonly used LINK command qualifiers. For a
complete list and for more information about the LINK qualifiers, invoke the
online HELP facility for the LINK command at the system prompt.
Developing Compaq COBOL Programs
For a complete discussion of linker capabilities and for detailed descriptions of
LINK qualifiers and qualifier options, see the OpenVMS Linker Utility Manual.
1.3.3.1 The LINK Command
The format of the LINK command is as follows:
LINK[/qualifier] ... {file-spec[/qualifier] ...} ...
/qualifier...
Specifies output file options when it is positioned after the LINK command.
Specifies input file options when it is positioned after file-spec.
file-spec...
Specifies the input files to be linked.
If you specify more than one input file, you must separate the input file
specifications with a plus sign (+) or a comma (,).
By default, the linker creates an output file with the name of the first input
file specified and the file type EXE. If you link multiple files, specify the file
containing the main program first. Then the name of your output file will have
the same name as your main program module.
The following command line links the object files MAINPROG.OBJ,
SUBPROG1.OBJ, and SUBPROG2.OBJ to produce one executable image called
MAINPROG.EXE:
$ LINK MAINPROG, SUBPROG1, SUBPROG2
Developing Compaq COBOL Programs 1–39
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. Refer to
the OpenVMS Linker Utility Manual for a complete list and explanations of the
LINK qualifiers or invoke the online HELP facility for the LINK command at the
OpenVMS Alpha prompt.
Note
Brackets ([]) indicate that the enclosed item is optional. If you specify
more than one option for a single qualifier, you must separate each option
with a comma and enclose the list of options in parentheses.
Table 1–5 Commonly Used LINK Qualifiers
FunctionQualifierDefault
Indicate that an input file
is a library file.
Indicate that an input file
is a linker options file.
Request output file,
define a file specification,
and specify whether the
image is shareable.
Request and specify the
contents of an image map
(memory allocation) listing.
Specify the amount of
debugging information.
/LIBRARYNot applicable.
/OPTIONSNot applicable.
/EXECUTABLE[=file-spec]
/SHAREABLE[=file-spec]
/BRIEF
/[NO]CROSS_REFERENCE
/FULL
/MAP[=file-spec] or /NOMAP
/DEBUG[=file-spec] or /NODEBUG
/[NO]TRACEBACK
/EXECUTABLE=
name.EXE
where name is the name of
the first input file.
/NOSHAREABLE
1.3.3.3 Specifying Modules Other than Compaq COBOL Modules
When you link Compaq COBOL modules with other modules, your application
will not work correctly if a non Compaq COBOL module contains a
LIB$INITIALIZE routine that:
1. Is invoked before the Compaq COBOL LIB$INITIALIZE routine (COB_
NAME_START) and
1–40 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.
The order in which LIB$INITIALIZE routines are invoked is determined during
the link and is shown in the image map. To ensure that the Compaq COBOL
LIB$INITIALIZE routine is invoked first, change your link command to the
following:
See Appendix B for information on a problem with LIB$INITIALIZE when you
call a C program.
1.3.3.4 Specifying Object Module Libraries
Linking against object modules allows your program to access data and routines
outside of your compilation units. You can create your own object module libraries
or they can be supplied by the system.
Developing Compaq COBOL Programs
User-Created Object Module Libraries
You can make program modules accessible to other programmers by storing them
in object module libraries. To link modules contained in an object module
2
library, use the /INCLUDE qualifier with the LINK command
and specify
the modules you want to link. The following example links the subprogram
modules EGGPLANT, TOMATO, BROCCOLI, and ONION (contained in the
VEGETABLES library) with the main program module GARDEN:
$ LINK GARDEN, VEGETABLES/INCLUDE=(EGGPLANT,TOMATO,BROCCOLI,ONION)
An object module library also contains a symbol table with the names of the
global symbols in the library, and the names of the modules in which the symbols
are defined. You specify the name of the object module library containing these
symbol definitions with the /LIBRARY qualifier. When you use the /LIBRARY
qualifier during a linking operation, the linker searches the specified library for
all unresolved references found in the included modules during compilation.
The following example uses the library RACQUETS to resolve undefined symbols
in the BADMINTON, TENNIS, and RACQUETBALL libraries:
$ LINK BADMINTON, TENNIS, RACQUETBALL, RACQUETS/LIBRARY
For more information about the /INCLUDE and /LIBRARY qualifiers, invoke the
online HELP facility for the LINK command at the DCL prompt or refer to the
OpenVMS Linker Utility Manual.
You can define one or more of your private object module libraries as default
user libraries. The following section describes how to accomplish this using the
DEFINE command.
2
The /INCLUDE qualifier on the LINK command is not to be confused with the /INCLUDE
qualifier on the COBOL compile command, which specifies a search list for COPY files.
Developing Compaq COBOL Programs 1–41
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.
In this example, LNK$LIBRARY is a logical name and DEFLIB is the name of
an object module library (having the file type OLB) that you want the linker to
search automatically in all subsequent link operations.
You can establish any object module library as a default user library by creating a
logical name for the library. The logical names you must use are LNK$LIBRARY
(as in the preceding example), LNK$LIBRARY_1, LNK$LIBRARY_2, and so on,
to LNK$LIBRARY_999. When more than one of these logical names exists when
a LINK command executes, the linker searches them in numeric order beginning
with LNK$LIBRARY.
When one or more logical names exist for default user libraries, the linker uses
the following search order to resolve references:
•The process, group, and system logical name tables (in that order) are
searched for the name LNK$LIBRARY. If the logical name exists in any
of these tables and if it contains the desired reference, the search is ended.
•The process, group, and system logical name tables (in that order) are
searched for the name LNK$LIBRARY_1. If the logical name exists in any of
these tables, and if it contains the desired reference, the search is ended.
This search sequence occurs for each reference that remains unresolved.
System-Supplied Object Module Libraries
All Compaq COBOL programs reference system-supplied object module
libraries when they are linked. These libraries contain routines that provide
I/O and other system functions. Additionally, you can use your own libraries to
provide application-specific object modules.
To use the contents of an object module library, you must do the following:
•Refer to a symbol in the object module by name in your program in a CALL
statement or VALUE EXTERNAL reference.
•Make sure that the linker can locate the library that contains the object
module by ensuring that required software is correctly installed.
•Make sure that your default directory (or LINK/EXE directory) is valid and
that you have write privileges to it.
To specify that a linker input file is a library file, use the /LIBRARY qualifier.
This qualifier causes the linker to search for a file with the name you specify and
the default file type .OLB. If you specify a file that the linker cannot locate, a
fatal error occurs and linking terminates.
The sections that follow describe the order in which the linker searches libraries
that you specify explicitly, default user libraries, and system libraries.
For more information about object module libraries, see the OpenVMS LinkerUtility Manual.
1–42 Developing Compaq COBOL Programs
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.
•If you specified more than one object module library, the libraries are searched
in the order in which they are specified.
For example:
$ LINK METRIC,DEFLIB/LIBRARY,APPLIC
The library DEFLIB will be searched only for unresolved references in the object
module METRIC. It is not searched to resolve references in the object module
APPLIC. However, this command can also be entered as follows:
$ LINK METRIC,APPLIC,DEFLIB/LIBRARY
In this case, DEFLIB.OLB is searched for all references that are not resolved
between METRIC and APPLIC. After the linker has searched all libraries
specified in the command, it searches default user libraries, if any, and then
the default system libraries.
1.3.3.5 Creating Shareable Images
You can create Compaq COBOL programs as shareable images by using the
LINK qualifier /SHARE. A shareable image is a single copy of a program that
can be shared by many users or applications. Using shareable images provides
the following benefits:
•Saves system resources, since one physical copy of a set of procedures can be
shared by more than one application or user
•Facilitates the linking of very large applications by allowing you to break
down the whole application into manageable segments
•Allows you to modify one or more sections of a large application without
having to relink the entire program
The following list describes one way to create and install a Compaq COBOL
program as a shareable image:
1. Create the main program used to call the subprogram (as a shareable image).
2. Create the subprogram.
3. Link the shareable image program using the /SHARE qualifier and including
the options file containing the symbol vector in the LINK command as an
input file. (Refer to Using Symbol Vectors with Shareable Images in this
section for information about declaring universal symbols using a symbol
vector.)
4. Define a logical name to point to your shareable image.
5. Link the main program with the shareable image.
Once you have completed these steps, you can run the main program to access
the subprogram installed as a shareable image.
Developing Compaq COBOL Programs 1–43
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). Only the subprograms are installed as
shareable images.
1–44 Developing Compaq COBOL Programs
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
END-CALL.
STOP RUN.
END PROGRAM CALLER.
* SUBSHR1.COB
IDENTIFICATION DIVISION.
PROGRAM-ID. SUBSHR1.
******************************************************************
* This program is linked as a shareable image. When it is called,*
* it calls another program installed as a shareable image.*
******************************************************************
PROCEDURE DIVISION.
0.
DISPLAY "Call to SUBSHR1 successful. Calling SUBSHR2.".
CALL "SUBSHR2"
END-CALL.
END PROGRAM SUBSHR1.
DISPLAY "First CALL failed. Program aborted."
ON EXCEPTION
DISPLAY "Second call failed. Control returned to CALLER."
* SUBSHR2.COB
IDENTIFICATION DIVISION.
PROGRAM-ID. SUBSHR2.
****************************************************************
* This program is linked as a shareable image and is called by *
* another shareable image.*
****************************************************************
PROCEDURE DIVISION.
0.
DISPLAY "Call to SUBSHR2 successful!".
END PROGRAM SUBSHR2.
Example 1–3 shows a command procedure that compiles, links, and installs the
sample programs in Example 1–2.
Example 1–3 Command Procedure to Link a Program as a Shareable Image
$! Create the main program and subprograms to be installed as
$! shareable images. In this example CALLER.COB is the main program.
$! SUBSHR1.COB and SUBSHR2.COB are the subprograms to be installed
$! as shareable images.
$!
(continued on next page)
Developing Compaq COBOL Programs 1–45
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.OPT
$DECK
SYMBOL_VECTOR=(SUBSHR1=PROCEDURE,SUBSHR2=PROCEDURE)
$EOD
$!
$! Link the subprograms using the /SHARE qualifier to the
$! shareable library and the options file.For more information
$! on options files, refer to the OpenVMS Linker Utility Manual.
$!
$LINK/SHARE=MYSHRLIB SUBSHR1,SUBSHR2,OPTIONS1/OPT
$!
$! Assign a logical name for the shareable images.
$!
$ASSIGN DEVICE:[DIRECTORY]MYSHRLIB.EXE MYSHRLIB
$!
$! Create a second options file to map the main program to the
$! shareable image library.
$!
$COPY SYS$INPUT OPTIONS2.OPT
$DECK
MYSHRLIB/SHAREABLE
$EOD
$!
$! Link the main program with the shareable image subprograms
$! through the options file.
$!
$LINK CALLER,OPTIONS2/OPT
$!
$! Now you can run the main program.
Using Symbol Vectors with Shareable Images
To make symbols in the shareable image available for other modules to link
against, you must declare the symbols as universal. You declare universal
symbols by creating a symbol vector. You create a symbol vector by specifying
the SYMBOL_VECTOR=option clause in a linker options file. List all of the
symbols you want to be universal in the order in which you want them to appear
in the symbol vector.
If you use symbol vectors, you can modify the contents of shareable images and
avoid relinking user programs bound to the shareable image when you modify the
image. Once you have created the symbol vector, you can install the subprograms
and link the main program to the shareable library. Symbol vectors, if used
according to the coding conventions, can also provide upward compatibility.
For more information about symbol vectors, refer to the OpenVMS Linker UtilityManual.
1–46 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 UtilityManual for complete information about the format of linker options.
Linker messages are self-explanatory; you do not usually need additional
information to determine the specific error.
Common Linking Errors to Avoid
The following are some common errors to avoid when linking COBOL programs:
•Trying to link a module that produced warning or error messages during
compilation. Although you can usually link compiled modules for which the
compiler generated system messages, you should verify that the modules
actually produce the expected output during program execution.
•Forgetting to specify a file type for an input file that has a file type other than
the default on the command line. The linker searches for a file that has a file
type .OBJ by default. When the linker cannot locate an object file and you
have not identified your input file with the appropriate file type, the linker
signals an error message and does not produce an image file.
Developing Compaq COBOL Programs
•Trying to link a nonexistent module. The linker signals an error message
if you misspell a module name on the command line or if the compilation
contains fatal messages.
•Omitting required module or library names from the command line. The
linker cannot locate the definition for a specified global symbol reference.
Consider, for example, the following LINK command for a main program
module, OCEAN.OBJ, that calls the subprograms REEF, SHELLS, and
SEAWEED:
$ LINK OCEAN,REEF,SHELLS
If the routine SEAWEED.OBJ does not exist in the directory from which
the command is issued, an error occurs and the linker issues the following
diagnostic messages:
%LINK-W-NUDFSYMS, 1 undefined symbol
%LINK-I-UDFSYMS,SEAWEED
%LINK-W-USEUNDEF, undefined symbol SEAWEED referenced
%LINK-W-USEUNDEF, undefined symbol SEAWEED referenced
If an error occurs when you link modules, you can often correct it by
reentering the command string and specifying the correct modules or
libraries.
For a complete list of linker options, see the OpenVMS System Messages andRecovery Procedures Reference Manual.
in psect $CODE offset %X0000000C
in module OCEAN file DEVICE$:[COBOL.EXAMPLES]PROG.OBJ;1
in psect $CODE offset %X00000021
in module OCEAN file DEVICE$:[COBOL.EXAMPLES]PROG.OBJ;1
Developing Compaq COBOL Programs 1–47
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. If you omit
a path specification, the system will expect MYPROG.EXE to be in the current
directory.
When you run your application it makes calls to the Compaq COBOL RunTime Library (RTL) installed on your system. If your application is run on a
system other than the one where the application was compiled, there are two
requirements that must be met:
•The Compaq COBOL Run-Time Library must be installed.
•The RTL version must match (or be higher than) the version of the RTL
on the system where the application was compiled. Otherwise, the system
displays a diagnostic message each time you run the application.
1.3.4.1 Accessing Command-Line Arguments at Run Time
Your Compaq COBOL programs can read command-line arguments and access
(read and write) system logicals. Command-line arguments enable you to provide
information to a program at run time. Your program provides the logic to parse
the command line, identify command-line options, and act upon them. For
example, you might develop a program named MYPROG that will extract a
given amount of data from a specified file, where both the number of records to
read and the file name are highly dynamic, changing for each activation of your
program. In this case your program would contain code that reads a commandline argument for the number of records to read and a second argument for the
file specification.
To run the program with command-line arguments, you must define it as a foreign
command, as follows:
$ MYPROG :== "$device:[dir]MYPROG.EXE"
When you use this command, you will replace device and dir with the valid
device:[dir] names where MYPROG.EXE is located. Your program execution
command could then look like the following:
$ MYPROG 1028 POWERS.DAT
In this hypothetical case, the program MYPROG would read 1,028 records from
the file POWERS.DAT.
Multiple command-line arguments are delimited by spaces, as shown in the
preceding example. If an argument itself contains spaces, enclose that argument
in quotation marks (" ") as follows:
$ myprog2 "all of this is argument 1" argument2
In this example the returned value of argument1 will be the entire string ‘‘all of
this is argument1’’, and argument2 will be simply ‘‘argument2’’.
1–48 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 CompaqCOBOL Reference Manual.
1.3.4.2 Accessing System Logicals at Run Time
You can read and write system logicals at run time through your Compaq COBOL
program.
Example 1–4 allows the user to specify a file specification by putting the directory
in the value of the logical COBOLPATH and the file name in a command-line
argument.
Example 1–4 Accessing Logicals and Command-Line Arguments
END-DISPLAY
ACCEPT file-name FROM COMMAND-LINE-ARGUMENT
ON EXCEPTION
DISPLAY
"Attempt to read beyond end of command line"
UPON STANDARD-ERROR
END-DISPLAY
NOT ON EXCEPTION
STRING env-dir file-name delimited by " " into file-spec
DISPLAY "Would have read " howmany-records " records from " file-spec
END-ACCEPT
END-ACCEPT.
Developing Compaq COBOL Programs
Example 1–4 assumes that the logical COBOLPATH is set as follows:
$ define COBOLPATH MYDEV:[MYDIR]
Developing Compaq COBOL Programs 1–49
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.3 Accessing Input and Output Devices at Run Time
ACCEPT and DISPLAY statements may interact with the input and output
devices by referring to them through the environment variables COBOL_INPUT
and COBOL_OUTPUT, respectively. See Chapter 11 for more information.
1.3.4.4 Debugging Environment
Perhaps the most common qualifier added to the RUN command line is DEBUG.
The form of the RUN command with DEBUG is as follows:
RUN [/[NO]DEBUG] file-spec
In the preceding syntax format file-spec is the name of the executable image to be
run. A typical example would be:
$ RUN /DEBUG MYPROG
In this example, MYPROG is the name of the executable image to be run. You
would specify the /DEBUG qualifier to invoke the OpenVMS Debugger if the
image was not linked with it. You cannot use /DEBUG on images linked with the
/NOTRACEBACK qualifier. If the image (in this case, MYPROG) was linked with
the /DEBUG qualifier and you do not want the debugger to prompt you, use the
/NODEBUG qualifier. The default action depends on whether or not the file was
linked with the /DEBUG qualifier.
Note
Using the /DEBUG qualifier with the RUN command does not produce
symbol table information if you did not specify the /DEBUG qualifier
when you compiled and linked your program.
The following example executes the image MYPROG.EXE without invoking the
debugger:
$ RUN MYPROG/NODEBUG
See Appendix C for more information about debugging programs.
1–50 Developing Compaq COBOL Programs
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.
Run-time messages have the following format:
%COB-s-ident, message-text
%COB
The program name of the Compaq COBOL Run-Time Library. This prefix
indicates a run-time message.
s
The severity of the error. As with messages from the compiler and the linker, the
severity indicator can be F (Fatal), E (Error), W (Warning), or I (Informational).
ident
The message identification. This is a descriptive abbreviation of the message text.
Developing Compaq COBOL Programs
1.3 Developing Programs on OpenVMS Alpha
message-text
The run-time message. This portion may contain 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.
The following example shows a run-time message issued for an illegal divide:
%COB-E-DIVBY-ZER, divide by zero; execution continues
Both the compiler and the OpenVMS Alpha Run-Time Library include facilities
for detecting and reporting errors. You can use the OpenVMS Debugger and the
traceback facility to help you locate errors that occur during program execution.
For a description of Compaq COBOL run-time messages, use the HELP COBOL
Run-Time Messages command.
Run-Time Messages
Faulty program logic can cause abnormal termination. If errors occur at run time,
the Run-Time Library (RTL) displays a message with the same general format as
system error messages. In addition, the system traceback facility displays a list
of the routines that were active when the error occurred.
When an error occurs, TRACEBACK produces a symbolic dump of the active call
frames. A call frame represents one execution of a routine. For each call frame,
TRACEBACK displays the following information:
1. The module name, (program-id)
2. The routine name (program-id)
3. The source listing line number where the error or CALL occurred
4. Program-counter (PC) information
You can also use the OpenVMS Debugger to examine the machine code
instruction. To do this, compile and link the program using the /DEBUG qualifier.
When you run the program, you automatically enter the debugger. Once in the
debugger, you could use the EXAMINE/INSTRUCTION command to examine
the contents of the failed instruction. You could also use the debugger in screen
mode, which would indicate where the error occurred.
Developing Compaq COBOL Programs 1–51
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. Data errors can
sometimes be attributed to one or more of the following actions:
•Incorrect picture size. As shown in the following sample of a partial program,
if the picture size of a receiving data item is too small, your data may be
truncated:
77COUNTERPIC S9.
.
.
.
PROCEDURE DIVISION.
.
.
.
LOOP.
ADD 1 TO COUNTER
IF COUNTER < 10 GO TO LOOP.
The IF clause will produce an infinite loop because of the one-digit size limit
of COUNTER, which is PIC S9. If COUNTER were PIC S99, or if the clause
used 9 instead of 10, the condition could be false, causing a proper exit from
the loop.
•Incorrect record field position. The record field positions that you specify in
your program may not agree with a file’s record field positions. For example,
a file could have this record description:
Incorrectly positioning these fields can produce faulty data.
In the following example, a program references the file incorrectly. The field
described as P-YEARLY-AMT actually contains P-MONTHLY-AMT data, and vice
versa.
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. On OpenVMS Alpha systems, you can also use the COPY FROM
DICTIONARY statement.
Choosing your test data carefully can minimize faulty data problems. For
instance, rather than using actual or ideal data, use test files that include data
extremes.
Determining when a program produces incorrect results can often help your
debugging effort. You can do this by maintaining audit counts (such as total
master in = nnn, total transactions in = nnn, total deletions = nnn, total master
out = nnn) and displaying the audit counts when the program ends. Using
conditional compilation lines (see Section 1.3.2.7) in your program can also help
you to debug it.
.
ADD P-MONTHLY-AMT TO TOTAL-MONTHLY-AMT.
.
.
.
1.4.2 Program Logic Errors
When checking your program for logic errors, first examine your program for
some of the more obvious bugs, such as the following:
•Hidden periods. Periods inadvertently placed in a statement usually produce
unexpected results. For example:
050-DO-WEEKLY-TOTALS.
IF W-CODE = "W"
PERFORM 100-WEEKLY-SUMMARY
ADD WEEKLY-AMT TO WEEKLY-TOTALS.
GO TO 000-READ-A-MASTER.
WRITE NEW-MASTER-REC.
The period at the end of ADD WEEKLY-AMT TO WEEKLY-TOTALS
terminates the scope of the IF statement and changes the logic of
the program. Including the extra period before the GO TO statement
transforms GO TO 000-READ-A-MASTER from a conditional statement to
an unconditional statement. Because the GO TO statement is not within the
scope of the IF statement, it will always be executed. In addition, the WRITE
statement following the GO TO will never be executed.
•Tests for equality, which can cause an infinite loop if the procedure is to be
executed until the test condition is met, for example:
* This is a test for equality
PERFORM ABC-ROUTINE UNTIL A-COUNTER = 10.
Developing Compaq COBOL Programs 1–53
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. The calculations of your program might never produce exact
numerical equality between two floating point values.
•Two negative test conditions combined with an OR. The object of the following
statement is to execute GO TO 200-PRINT-REPORT when TEST-FIELD
contains other than an A or B. However, the GO TO always executes because
no matter what TEST-FIELD contains, one of the conditions is always true.
IF TEST-FIELD NOT = "A" OR NOT = "B"
GO TO 200-PRINT-REPORT.
.
.
.
The following statement does not contain the logic error:
IF TEST-FIELD NOT = "A" AND NOT = "B"
GO TO 200-PRINT-REPORT.
.
.
.
1.4.3 Run-Time Input/Output Errors
An input/output error is a condition that causes an I/O statement to fail. These
I/O errors are detected at run time by the I/O system. Each time an I/O operation
occurs, the I/O system generates a two-character file status value. One way to
determine the nature of an I/O error is to check a file’s I/O status by using file
status data items. (See the Compaq COBOL Reference Manual for a list of file
status values.) See Chapter 7, Handling Input/Output Exception Conditions for
additional information about I/O exception condition handling.
Checking a file’s I/O status within a Declarative USE procedure or in an INVALID
KEY imperative condition can help you determine the nature of an I/O error. For
example:
FDINDEXED-MASTER
ACCESS MODE IS DYNAMIC
FILE STATUS IS MASTER-STATUS
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".
.
.
.
If your program contains a Declarative USE procedure for a file and an I/O
operation for that file fails, the I/O system performs the USE procedure, but does
not display an error message.
A Declarative USE procedure can sometimes avoid program termination. For
example, File Status 91 indicates that the file is locked by another program;
rather than terminate your program, you can perform other procedures and then
try reopening the file. If program continuation is not desirable, the Declarative
USE procedure can perform housekeeping functions, such as saving data or
displaying program-generated diagnostic messages.
If you specify an INVALID KEY phrase for a file and the I/O operation causes
an INVALID KEY condition, the I/O system performs the associated imperative
statement and no other file processing for the current statement. The Declarative
USE procedure (if any) is not performed. The INVALID KEY phrase processes
I/O errors due to invalid key conditions only.
If you do not specify an INVALID KEY phrase but declare a Declarative USE
procedure for the file, the I/O system performs the Declarative USE procedure
and returns control to the program.
If a severe error occurs and you do not have a Declarative Use procedure, your
program will terminate abruptly with a run-time diagnostic. For example, given
a program that looks for AFILE.DAT and that file is missing:
cobrtl: severe: file AFILE.DAT not found
In this case, program run ends because you have not handled the error with a
Declarative Use procedure.
1.4.4 I/O Errors and RMS (OpenVMS)
I/O errors are detected by the I/O system, which (for OpenVMS Alpha systems)
consists of Record Management Services (RMS) and the Run-Time Library (RTL).
You can use the RMS special registers, which contain the primary and secondary
RMS completion codes of an I/O operation, to detect errors. The RMS special
registers are as follows:
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.
*
* This program demonstrates the use of RMS special registers to
* implement a different recovery for each of several errors with RMS files
*
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT OPTIONAL EMP-FILE
ASSIGN TO "SYS$DISK:ART.DAT".
SELECT REPORT-FILE
ASSIGN TO "SYS$OUTPUT".
DATA DIVISION.
FILE SECTION.
FDEMP-FILE
01EMP-RECORD.
FDREPORT-FILEREPORT IS RPT.
WORKING-STORAGE SECTION.
01VAL-OF-IDPIC X(20).
01END-OF-FILEPIC S9(9)COMP VALUE EXTERNAL RMS$_EOF.
01BADNAMEPIC S9(9)COMP VALUE EXTERNAL SS$_BADFILENAME.
01FILE-NOT-FOUNDPIC S9(9)COMP VALUE EXTERNAL RMS$_FNF.
01DIR-NOT-FOUNDPIC S9(9)COMP VALUE EXTERNAL RMS$_DNF.
01INV-DEVICEPIC S9(9)COMP VALUE EXTERNAL RMS$_DEV.
01INV-FILE-IDPIC S9(9)COMP VALUE EXTERNAL RMS$_IFI.
01RMS-ERRPIC S9(9)COMP VALUE EXTERNAL SHR$_RMSERROR.
01D-DATEPIC 9(6).
01EOF-SWPIC X.
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.
READ EMP-FILE.
200-CLEANUP.
TERMINATE RPT.
SET OP-CLOSE TO TRUE.
CLOSE EMP-FILE REPORT-FILE.
END PROGRAM RMS-SPEC-REGISTERS.
Example 1–6 Using RMS-CURRENT Special Registers to Detect Errors
(OpenVMS)
IDENTIFICATION DIVISION.
PROGRAM ID. RMS-CURRENT-SPEC-REGISTERS.
*
* This program demonstrates the use of RMS-CURRENT special registers
* to implement a single recovery for RMS file errors with multiple files
*
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT FILE-1
SELECT FILE-2
SELECT FILE-3
ASSIGN TO "SYS$DISK:ART_1.DAT".
ASSIGN TO "SYS$DISK:ART_2.DAT".
ASSIGN TO "SYS$DISK:ART_3.DAT".
(continued on next page)
1–58 Developing Compaq COBOL Programs
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.
FDFILE-1.
01FILE-1-REC.
USE AFTER STANDARD EXCEPTION PROCEDURE ON INPUT.
DISPLAY "************** ERROR **************".
DISPLAY "Error on file: " RMS-CURRENT-FILENAME.
DISPLAY "Status Values:".
DISPLAY "RMS-STS = " RMS-CURRENT-STS WITH CONVERSION.
DISPLAY "RMS-STV = " RMS-CURRENT-STV WITH CONVERSION.
DISPLAY "***********************************".
OPEN INPUT FILE-1.
OPEN INPUT FILE-2.
OPEN INPUT FILE-3.
.
.
.
CLOSE FILE-1.
CLOSE FILE-2.
CLOSE FILE-3.
STOP RUN.
♦
1.5 Using Program Switches
You can control program execution by defining switches in your Compaq
COBOL program and setting them internally (from within the image) or
externally (from outside the image). Switches exist as the environment variable
COBOL_SWITCHES (on the Tru64 UNIX operating system) or the logical name
COB$SWITCHES (on the OpenVMS Alpha operating system).
On OpenVMS Alpha systems, switches can be defined for the image, process,
group, or system. ♦
On Tru64 UNIX systems, switches can be defined for the image or process. ♦
Developing Compaq COBOL Programs 1–59
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:
To change the status of internal switches during execution, turn them on or off
from within your program. However, be aware that this information is not saved
between runs of the program.
Refer to the Compaq COBOL Reference Manual for more information about
setting internal switches.
1.5.2 Setting and Controlling Switches Externally
On Tru64 UNIX systems, to set switches from outside the image, use the SETENV
command to change the status of program switches, as follows:
% setenv COBOL_SWITCHES "switch-list"
To remove switch settings:
% unsetenv COBOL_SWITCHES
To check switch settings, enter this command:
% printenv COBOL_SWITCHESShows switch settings.
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:
% setenv COBOL_SWITCHES "1,5,13"Sets switches 1, 5, and 13 ON.
% setenv COBOL_SWITCHES "9,11,16"Sets switches 9, 11, and 16 ON.
% setenv COBOL_SWITCHES " "Sets all switches OFF.
♦
On OpenVMS Alpha systems, to set switches from outside the image or for a
process, use the DCL DEFINE or ASSIGN command to change the status of
program switches as follows:
$ DEFINE COB$SWITCHES "switch-list"
1–60 Developing Compaq COBOL Programs
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.
The order of evaluation for logical name assignments is image, process, group,
system. System and group assignments (including Compaq COBOL program
switch settings) continue until they are changed or deassigned. Process
assignments continue until they are changed, deassigned, or until the process
ends. Image assignments end when they are changed or when the image ends.
You should know the system and group assignments for COB$SWITCHES unless
you have defined them for your process or image. To check switch settings, enter
this command:
$ SHOW LOGICAL COB$SWITCHES
Use the DCL DEASSIGN command to remove the switch-setting logical name
from your process and reactivate the group or system logical name (if any):
$ DEASSIGN COB$SWITCHES
To change the status of external switches during execution, follow these steps:
1. Interrupt the image with a STOP (literal-string) COBOL statement. (See the
Compaq COBOL Reference Manual for more information.)
2. Use the DCL DEFINE command to change switch settings.
3. Continue execution with the DCL CONTINUE command. Be sure not to force
the interrupted image to exit by entering a command that executes another
image.
For information about these DCL commands, see the OpenVMS DCL Dictionary.♦
Following is a simple program that displays a message depending on the state
of the logical name COB$SWITCHES (on OpenVMS Alpha systems) or the
environment variable COBOL_SWITCHES (on Tru64 UNIX systems):
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.6 Special Information for Year 2000 Programming
Even subsequent to the turn of the millennium, 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.
Two-digit year formats used in controlling fields, or as keys in indexed files,
can cause program logic to become ambiguous. It is a fundamental rule to use
four-digit years instead of two-digit years in areas where sequential operations
are driven from these values or for comparison of these values.
Compaq COBOL provides programmer access to four-digit and two-digit year
formats:
4-digitACCEPT FROM DATE YYYYMMDD
4-digitACCEPT 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.
You should check program logic in code that uses ACCEPT, to verify that
millennium transition dates are properly handled.
The use of two-digit years in applications does not automatically create a problem,
but a problem could exist. Programmers need to inspect each of their applications
for two-digit year dependencies and change any such instances to check the full
four-digit year value.
Developing Compaq COBOL Programs 1–63
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.7)
2.1 How the Compiler Stores Numeric Data
Understanding how data is stored will help you in the following situations:
2
•When you define data items to participate in group moves or to be the subject
of a REDEFINES clause
•When you move a complex record consisting of several levels of subordination,
to be sure that the receiving item is large enough to prevent data truncation
•When you need to use data storage concepts to minimize storage space,
particularly when the data file is large
The storage considerations applicable to tables are described in Chapter 4.
For each numeric data item, Compaq COBOL stores the numeric value, and a
sign (if an S appears in the PICTURE clause).
The USAGE clause of a numeric data item specifies the data’s internal format in
storage. When you do not specify a USAGE clause, the default usage is DISPLAY.
For further information about internal representations, see the USAGE clause
tables in the Compaq COBOL Reference Manual.
2.2 Specifying Alignment
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. However, the SYNCHRONIZED clause, the
flag (on Tru64 UNIX), the /ALIGNMENT qualifier (on OpenVMS Alpha), and
alignment directives can be used to modify this behavior, causing some numeric
data items to be aligned on a 2-, 4-, or 8-byte boundary. You can thus tune data
alignment for optimum performance, compatibility with Compaq COBOL for
-align
Handling Numeric Data 2–1
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 ReferenceManual 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. Thus, unsigned items only contain the value zero or a positive value.
•The way Compaq COBOL stores signed results in signed data items depends
on the usage and the presence or absence of the SIGN clause.
•When an unsigned result is stored in a signed data item, the sign of the
stored result is positive.
Do not use unsigned numeric items in arithmetic operations. They usually cause
programming errors and are handled less efficiently than signed numeric items.
The following example shows how unsigned numeric items can cause errors:
DATA DIVISION
.
.
.
01 A PIC 9(5) COMP VALUE 2.
01 B PIC 9(5) COMP VALUE 5.
Then:
SUBTRACT B FROM A.(A = 3)
SUBTRACT 1 FROM A.(A = 2)
However:
COMPUTE A = (A - B) - 1(A = 4)
The absence of signs for the numeric items A and B results in two different
answers after parallel arithmetic operations have been done. This occurs because
internal temporaries (required by the COMPUTE statement) are signed. Thus,
the result of (A–B) within the COMPUTE statement is –3; –3 minus 1 is –4 and
the value of A then becomes 4.
2.4 Invalid Values in Numeric Items
All Compaq COBOL arithmetic operations store valid values in their result items.
However, it is possible, through group moves or REDEFINES, to store data in
numeric items that do not conform to the data definitions of those items.
The results of arithmetic operations that use invalid data in numeric items are
undefined. You can use the
system) or the /CHECK=DECIMAL qualifier (on the OpenVMS Alpha operating
system) to validate numeric digits when using display numeric items in a
numeric context; note that this flag or qualifier causes a program to terminate
abnormally if there is invalid data. In the case of data with blanks (typically,
records in a file), you can use the
UNIX) or the /CONVERT qualifier (on OpenVMS Alpha) to change all blanks
to zeroes before performing the arithmetic operation. If you specify both the
-check
decimal and the
-check decimal
-convert leading_blanks
flag (on the Tru64 UNIX operating
-convert leading_blanks
flags (on Tru64 UNIX), or
flag (on Tru64
2–2 Handling Numeric Data
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
information.
2.5 Evaluating Numeric Items
Compaq COBOL provides several kinds of conditional expressions used for
evaluating numeric items. These conditional expressions include the following:
•The numeric relation condition that compares the item’s contents to another
numeric value
•The sign condition that examines the item’s sign to see if it is positive or
negative
•The class condition that inspects the item’s digit positions for valid numeric
characters
•The success/failure condition that checks the return status codes of COBOL
and non-COBOL procedures for success or failure conditions
Handling Numeric Data
2.4 Invalid Values in Numeric Items
man cobol
(on Tru64 UNIX) for more
The following sections explain these conditional expressions in detail.
2.5.1 Numeric Relation Test
A numeric relation test compares two numeric quantities and determines if the
specified relation between them is true. For example, the following statement
compares item FIELD1 to item FIELD2 and determines if the numeric value of
FIELD1 is greater than the numeric value of FIELD2:
IF FIELD1 > FIELD2 ...
If the relation condition is true, the program control takes the true path of the
statement.
The first operand is greater than (or not greater
than) the second operand.
The first operand is less than (or not less than)
the second operand.
The first operand is equal to (or not equal to) the
second operand.
The first operand is greater than or equal to the
second operand.
The first operand is less than or equal to the
second operand.
Comparison of two numeric operands is valid regardless of their USAGE clauses.
Handling Numeric Data 2–3
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.2 Numeric Sign Test
The sign test compares a numeric quantity to zero and determines if it is greater
than (positive), less than (negative), or equal to zero. Both the relation test and
the sign test can perform this function. For example, consider the following
relation test:
IF FIELD1 > 0 ...
Now consider the following sign test:
IF FIELD1 POSITIVE ...
Both of these tests accomplish the same thing and always arrive at the same
result. The sign test, however, shortens the statement and makes it more obvious
that the sign is being tested.
Table 2–2 shows the sign tests and their equivalent relation tests.
Table 2–2 Sign Tests
Sign TestEquivalent Relation Test
IF FIELD1 POSITIVE ...IF FIELD1 > 0 ...
IF FIELD1 NOT POSITIVE ...IF FIELD1 NOT > 0 ...
IF FIELD1 NEGATIVE ...IF FIELD1 < 0 ...
IF FIELD1 NOT NEGATIVE ...IF FIELD1 NOT < 0 ...
IF FIELD1 ZERO ...IF FIELD1 = 0 ...
IF FIELD1 NOT ZERO ...IF FIELD1 NOT = 0 ...
Sign tests do not execute faster or slower than relation tests because the compiler
substitutes the equivalent relation test for every correctly written sign test.
2.5.3 Numeric Class Tests
The class test inspects an item to determine if it contains numeric or alphabetic
data. For example, the following statement determines if FIELD1 contains
numeric data:
IF FIELD1 IS NUMERIC ...
If the item is numeric, the test condition is true, and program control takes the
true path of the statement.
Both relation and sign tests determine only if an item’s contents are within a
certain range. Therefore, certain items in newly prepared data can pass both the
relation and sign tests and still contain data preparation errors.
The NUMERIC class test checks alphanumeric or numeric DISPLAY or COMP-3
usage items for valid numeric digits. If the item being tested contains a sign
(whether carried as an overpunched character or as a separate character), the
test checks it for a valid sign value. If the character position carrying the sign
2–4 Handling Numeric Data
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. You test status-code-id as
follows:
Handling Numeric Data
2.5 Evaluating Numeric Items
status-code-id IS
You can use the SET statement to initialize or alter the status of status-code-id
(which must be a word or longword COMP integer represented by PIC 9(1 to 9)
COMP or PIC S9(1 to 9) COMP), as follows:
SET status-code-id TO
The SET statement is typically in the called program, but the calling program
may also SET the status of status-code-id. The SUCCESS class condition is true
if status-code-id has been set to SUCCESS, otherwise it is false. The FAILURE
class condition is true if status-code-id has been set to FAILURE, otherwise it is
false. The results are unspecified if status-code is not set.
Example 2–1 shows the significant COBOL code relevant to a success/failure test.
Example 2–1 Success/Failure Test
...
PROGRAM-ID.MAIN-PROG.
...
O1RETURN-STATUSPIC S9(9) COMP.
...
CALL "PROG-1" GIVING RETURN-STATUS.
IF RETURN-STATUS IS FAILURE PERFORM FAILURE-ROUTINE.
EXIT PROGRAM.
END PROGRAM PROG-1.
END PROGRAM MAIN-PROG.
SET RETURN-STATUS TO SUCCESS
SET RETURN-STATUS TO FAILURE.
SUCCESS
FAILURE
SUCCESS
FAILURE
Handling Numeric Data 2–5
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. The sending item can be numeric,
alphanumeric, or numeric-edited. The elementary numeric move converts the
data format of the sending item to the data format of the receiving item.
An alphanumeric sending item can be either of the following:
•An elementary alphanumeric data item
•Any alphanumeric literal other than the figurative constants SPACE,
QUOTE, LOW-VALUE, or HIGH-VALUE
The elementary numeric move accepts the figurative constant ZERO and
considers it to be equivalent to the numeric literal 0. It treats alphanumeric
sending items as unsigned integers of DISPLAY usage.
When the sending item is numeric-edited, de-editing is applied to establish the
unedited numeric value, which may be signed; then the unedited numeric value
is moved to the receiving field.
If necessary, the numeric move operation converts the sending item to the data
format of the receiving item and aligns the sending item’s decimal point on that of
the receiving item. Then it moves the sending item’s digits to the corresponding
receiving item’s digits.
If the sending item has more digit positions than the receiving item, the decimal
point alignment operation truncates the value of the sending item, with resulting
loss of digits.
The end truncated (high-order or low-order) depends upon the number of sending
item digit positions that find matches on each side of the receiving item’s decimal
point. If the receiving item has fewer digit positions on both sides of the decimal
point, the operation truncates both ends of the sending item. Thus, if an item
described as PIC 999V999 is moved to an item described as PIC 99V99, it loses
one digit from the left end and one from the right end.
In the execution part of the following examples, the caret ( ^ ) indicates the
assumed stored decimal point position:
01 AMOUNT1 PIC 99V99 VALUE ZEROS.
.
.
.
MOVE 123.321 TO AMOUNT1.
Before execution:00^00
After execution:23^32
2–6 Handling Numeric Data
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.