HP COBOL II/iX Enhancements [ COMMUNICATOR 3000 MPE MPE/iX RELEASE 4.0 ] MPE/iX Communicators
COMMUNICATOR 3000 MPE MPE/iX RELEASE 4.0
HP COBOL II/iX Enhancements
by Jan Merrill
Systems Technology Division
This version of the HP COBOL II/iX compiler introduces the built-in
functions of the new, optional module to the ANSI COBOL'85 standard. The
new module, called the Intrinsic Function module, is a significant
enhancement in the development of standard COBOL. The Intrinsic Function
module is defined by Addendum 1 of the ANSI COBOL'85 standard. The
specifications of this addendum are published in the American National
Standards Institute document X3.23A-1989. This compiler also conforms to
the Federal Information Processing Standards (FIPS) Publication 21-3.
Most of the other enhancements in this version of the compiler support
the COBOL functions.
CONFORMANCE TO ADDENDUM 1 OF ANSI COBOL'85
The Intrinsic Function module consists of 42 built-in COBOL functions.
The new functions include 4-digit-year date functions, string and numeric
conversion functions, and arithmetic, financial, and trigonometric
functions. You can use the COBOL functions in place of manually coding
the task of the function in your programs. Using COBOL functions can
increase programmer productivity by saving design and development time.
In addition, the function names improve program readability.
The COBOL functions are separate and distinct from the MPE operating
system intrinsics, such as FOPEN. The COBOL functions are intrinsic to
this version of HP COBOL II/iX in the sense that they are built into the
language. The code to perform each function is either generated in-line
by the compiler, or contained in a language run-time library routine,
depending on the specific function. New routines have been added to the
COBOL run-time library to support some COBOL functions.
Two of the COBOL functions have the same names as two HP extensions to
special register words. The CURRENT-DATE and WHEN-COMPILED functions are
separate and distinct from the special register words by the same names,
and both features can be used in the same program. The format of the
special register words has not been changed.
A complete list of the COBOL functions is provided on the following
pages.
Date Functions
CURRENT-DATE Current date and time and difference from
Greenwich Mean Time
DATE-OF-INTEGER Standard date equivalent (YYYYMMDD) of integer
date
DAY-OF-INTEGER Julian date equivalent (YYYYDDD) of integer
date
INTEGER-OF-DATE Integer date equivalent of standard date
(YYYYMMDDD)
INTEGER-OF-DAY Integer date equivalent of Julian date
(YYYYDDD)
WHEN-COMPILED Date and time program was compiled
String Functions
CHAR Character in position I of program collating
sequence
LENGTH Length of argument
LOWER-CASE All letters in the argument are set to
lowercase
NUMVAL Numeric value of simple numeric string
NUMVAL-C Numeric value of numeric string with optional
commas and currency sign
ORD Ordinal position of the argument in collating
sequence
REVERSE Reverse order of the characters of the argument
UPPER-CASE All letters in the argument are set to
uppercase
General Functions
MAX Value of maximum argument
MIN Value of minimum argument
ORD-MAX Ordinal position of maximum argument
ORD-MIN Ordinal position of minimum argument
Arithmetic Functions
INTEGER The greatest integer not greater than N
INTEGER-PART Integer part of N
LOG Natural logarithm of N
LOG10 Logarithm to base 10 of N
MOD I1 modulo I2
RANDOM Random number
REM Remainder of N1/N2
SQRT Square root of N
SUM Sum of arguments
Financial and Statistical Functions
ANNUITY Ratio of annuity period for I periods at
interest of N to initial investment of one
FACTORIAL Factorial of I
MEAN Arithmetic mean of arguments
MEDIAN Median of arguments
MIDRANGE Mean of minimum and maximum arguments
PRESENT-VALUE Present value of a series of future period-end
amounts at a discount rate of N
RANGE Value of maximum argument minus value of
minimum argument
STANDARD-DEVIATION Standard deviation of arguments
VARIANCE Variance of argument
Trigonometric Functions
ACOS Arccosine of N
ASIN Arcsine of N
ATAN Arctangent of N
COS Cosine of N
SIN Sine of N
TAN Tangent of N
A COBOL function is a temporary data item whose value is determined at
the time the function is referenced during the execution of a statement.
The general format of the COBOL functions is:
FUNCTION function-name [(argument-1 argument-2 ...)]
where the number of arguments varies depending on the specific function
used.
At the time that your program references a COBOL function, its arguments
are evaluated individually in the order specified in the list of
arguments, from left to right.
If an ALL subscript is specified for a table used as an argument of a
function, the effect is as if each table element associated with that
subscript position were specified. That is, the function applies to each
of the implicitly specified elements of the table.
The COBOL functions are defined as alphanumeric, numeric, or integer,
depending on their returned values. The definition of an integer
function provides that all digits to the right of the decimal point are
zero in the returned value for any possible evaluation of the function.
A numeric function is a function whose class and category are numeric but
which for some possible evaluation does not satisfy the requirements of
an integer function.
The following list contains the alphanumeric functions:
CHAR
CURRENT-DATE
LOWER-CASE
MAX
MIN
REVERSE
UPPER-CASE
WHEN-COMPILED
The alphanumeric functions are of class and category alphanumeric and
have an implicit usage of DISPLAY. Alphanumeric functions can be
specified in the general formats where an alphanumeric identifier is
permitted. For example:
MOVE FUNCTION UPPER-CASE (LAST-NAME) TO PR-LAST-NAME.
Numeric and integer functions may be specified only in arithmetic
expressions, such as in COMPUTE statements, relation conditions, or
reference modification. For example:
IF FUNCTION SUM (TAB-B(ALL)) > 100 PERFORM CHECK-TOTAL.
Several COBOL functions are classified as the same type as their
arguments: the MAX and MIN functions can be alphanumeric, numeric, or
integer; the RANGE and SUM functions can be numeric or integer. For
example:
COMPUTE MAX-SCORE = FUNCTION MAX (TAB-SCORE(ALL)).
IF FUNCTION MAX (TAB-GRADE(ALL)) = "A" PERFORM DEANS-LIST.
NEW COMPILER OPTION AND COMPATIBILITY
A new compiler option, $CONTROL POST85, enables the Intrinsic Function
enhancement. The Intrinsic Function enhancement to the HP COBOL II/iX
compiler was implemented so that existing source code does not require
modification unless the new enhancements are used.
The $CONTROL POST85 option is required for the compiler to process
FUNCTION as a COBOL reserved word. If a program contains a variable
named FUNCTION, and the program is compiled with $CONTROL POST85, the
compiler will produce one or more compilation errors, depending on the
context. FUNCTION is the only COBOL reserved word added with this
release. The names of the COBOL functions that were not reserved words
before this release, such as ANNUITY, MAX, and NUMVAL, can be used as
variables in programs compiled with $CONTROL POST85.
The following information represents incompatibilities between this
version of HP COBOL II/iX and previous versions:
* Use of some COBOL functions will generate calls to new COBOL
run-time library procedures. This means that programs using COBOL
functions must use the latest library.
* New error messages for COBOL functions have been added to the
COBOL message catalog, COBCAT.PUB.SYS, and macros in the COBOL
Debug macro file, COBMAC.PUB.SYS, have been modified. Programs
using COBOL functions must use the latest version of these files
to correctly process errors.
* Since some of the COBOL functions convert arguments to IEEE
floating point to calculate the function result, this version of
HP COBOL II/iX arms the IEEE traps. If your non-COBOL program or
subprogram calls a COBOL subprogram, calling the COBOLTRAP
procedure now arms the IEEE traps, in addition to arming the
arithmetic traps. You may need to modify the arming or disarming
of the software trap mechanism required by the calling program
after returning from the COBOL subprogram. See the "MPE XL System
Dependencies" appendix in the HP COBOL II/XL Reference Manual
(31500-90001) for more information.
LOCAL TIME DIFFERENTIAL
The COBOL functions CURRENT-DATE and WHEN-COMPILED return the local date
and time, plus the difference between Greenwich Mean Time and local time.
To set the local time differential so that it is available to the date
functions, set the TZ system variable by using the SETVAR command. For
example, to set TZ for Central Standard Time and Central Daylight Time in
Chicago, Illinois:
:SETVAR TZ 'CST6CDT'
If the TZ variable is not set, the date functions will use Eastern
Standard Time (EST5EDT) as the default in calculating the difference
between Greenwich Mean Time and local time. Chapter 10 of the HP COBOL
II/XL Reference Manual (31500-90001) contains a list of commonly used
time zones and the TZ environment variable strings that correspond to
those time zones.
The hardware clock must be set to Greenwich Mean Time (Coordinated
Universal Time or UTC) for the CURRENT-DATE and WHEN-COMPILED
functions to return the correct local time. The book|System Startup,
Configuration, and Shutdown Reference Manual| (32650-90042) describes how
to set the hardware clock with the ISL utility CLKUTIL when the system is
started.
NEW MESSAGE FOR SORT/MERGE FILES
This version of the compiler was also enhanced to output a new message at
compile time if the definition of sort or merge files in the program
indicates that data may be lost. The enhancement can help your programs
more fully conform to the ANSI Standard.
The compiler outputs the new Questionable message 323, "Record size of FD
<file-name> conflicts with the SD," if one of the following situations is
detected:
with USING file(s):
for a sort or merge file (SD) with fixed length records,
* the largest record size of a USING file is greater than the
largest SD record size.
for a sort or merge file with variable length records,
* the largest record size of a USING file is greater than the
largest SD record size or
the smallest record size of a USING file is less than the smallest
SD record size.
with GIVING file(s):
for a GIVING file with fixed length records,
* the largest record size of a GIVING file is less than the
largest SD record size.
for a GIVING file with variable length records,
* the largest record size of a GIVING file is less than the
largest SD record size or
* the smallest record size of a GIVING file is greater than
the smallest SD record size.
The following paragraphs describe examples of this new enhancement.
If the record size of an input file specified in the USING phrase is 50
bytes and the SD record size is 40 bytes, the compiler will output error
323 because only 40 bytes of each 50-byte record will be sorted.
If the record size of an input file specified in the USING phrase is 50
bytes and the SD specifies records varying from 30 to 40 bytes, the
compiler will output error 323 because only 40 bytes of each 50-byte
record will be sorted.
If the record size of an output file specified in the GIVING phrase is 30
bytes and the SD record size is 40 bytes, the compiler will output error
323 because data may be lost when the SORT outputs 40-byte records to
30-byte records in the output file.
To better implement the ANSI Standard, the compiler compares the USING
file(s) to the SD file, and compares the SD file to the GIVING file(s).
Because the compiler does not compare the USING to the GIVING files, the
compiler outputs error 323 if the record sizes of the USING and GIVING
files are the same and the SD record size is larger, although this case
does not cause data loss.
You may receive error 323 in other cases that will not cause data loss.
The error is a Questionable so that you can determine whether the data
loss will impact the execution of your program. If not, you can ignore
the message. To modify your program to conform to the ANSI Standard and
to eliminate the message, you can change the record length of the USING
and GIVING files to match the record length of the SD. Another
alternative is to add or change the RECORD clause of the SD or GIVING
file to specify variable length records that pass the new checking.
MPE/iX Communicators