Compaq COBOL
Reference Manual
7.17 INTEGER-OF-DAY
Description
The INTEGER-OF-DAY function converts a date in the Gregorian calendar
from year-day (YYYYDDD) form (sometimes called "Julian") to an integer
date form representing the number of days after December 31, 1600.
num
is an integer argument of the form YYYYDDD representing a date
subsequent to December 31, 1600.
Rules
- The type of this function is integer.
- The value of the argument is obtained from the calculation (YYYY *
1000) + DDD. YYYY represents the year in the Gregorian calendar, and
must be an integer in the range 1601 through 9999. DDD represents a day
and is an integer in the range 1 through 366; the value of DDD must be
valid for the specified year.
- The returned value is an integer that is the number of days the
specified date succeeds December 31, 1600, in the Gregorian calendar.
Example
COMPUTE RSULT = FUNCTION INTEGER-OF-DAY (1601365).
|
The value returned and stored in RSULT (a numeric integer data item) is
365, which is the number of days succeeding December 31, 1600, and
which represents December 31, 1601.
7.18 INTEGER-PART
Description
The INTEGER-PART function returns an integer that is the integer
portion of the argument.
num
is a numeric argument.
Rules
- The type of this function is integer.
- If the value of the argument is 0, the returned value is 0.
- If the value of the argument is positive, the returned value is the
greatest integer less than or equal to the value of the argument.
- If the value of the argument is negative, the returned value is the
least integer greater than or equal to the value of the argument.
Example
COMPUTE RSULT = FUNCTION INTEGER-PART (NUM).
|
NUM is a numeric data item, and RSULT is a numeric integer data item.
If NUM has the value 0, the value returned is 0. If NUM has the value
+1.5, the value returned is +1. If NUM has the value -1.5, the value
returned is -1 (the least integer greater than or equal to the value of
-1.5).
7.19 LENGTH
Description
The LENGTH function returns an integer equal to the length of the
argument in character positions.
arg
is a nonnumeric literal or a data item of any class or category.
Rules
- The type of this function is integer.
- The value returned is an integer equal to the length of the
argument in character positions. However, if the argument is a group
data item containing a variable occurrence data item, the returned
value is an integer determined by evaluation of the data item specified
in the DEPENDING phrase of the OCCURS clause for that variable
occurrence data item. This evaluation is accomplished according to the
rules in the OCCURS clause dealing with the data item as a sending data
item.
- The returned value includes implicit FILLER characters, if any.
- For items that are not USAGE DISPLAY, the returned value represents
the allocated physical storage in bytes as described in Tables
5_12 and 5-13.
Examples
-
COMPUTE RSULT = FUNCTION LENGTH ("J. R. Donaldson").
|
The value 15 is returned and stored in RSULT (a numeric integer data
item).
-
01 RECORD-SIZE PIC 9(9).
01 RECORD1.
05 REC-TYPE PIC 9(4) VALUE 23.
05 REC-CNT PIC 9(4) VALUE 50.
05 A-REC PIC X(30) OCCURS 1 TO 100 TIMES
DEPENDING ON REC-CNT.
.
.
.
COMPUTE RECORD-SIZE = FUNCTION LENGTH (RECORD1).
CALL 'SUBR' USING RECORD1, RECORD-SIZE.
|
RECORD-SIZE is a numeric integer data item. The value returned by the
function and stored in RECORD-SIZE is 1508. (The computation is 4 + 4 +
(50 * 30) = 1508.)
7.20 LOG
Description
The LOG function returns a numeric value that approximates the
logarithm to the base e (natural log) of the argument.
num
is a positive numeric argument.
Rules
- The type of this function is numeric.
- The returned value is an approximation of the logarithm to the base
e of the argument.
Example
COMPUTE RSULT = FUNCTION LOG (NUM).
|
NUM and RSULT are numeric data items; the value of NUM must be greater
than 0. The value returned and stored in RSULT is an approximation of
the logarithm to the base e of NUM.
7.21 LOG10
Description
The LOG10 function returns a numeric value that approximates the
logarithm to the base 10 of the argument.
num
is a positive numeric argument.
Rules
- The type of this function is numeric.
- The returned value is an approximation of the logarithm to the base
10 of the argument.
Example
COMPUTE RSULT = FUNCTION LOG10 (NUM).
|
NUM and RSULT are numeric data items; the value of NUM must be greater
than 0. The value returned and stored in RSULT is an approximation of
the logarithm to the base 10 of NUM.
7.22 LOWER-CASE
Description
The LOWER-CASE function returns a character string that is the same
length as the argument with each uppercase letter in the argument
replaced by the corresponding lowercase letter.
string
is an alphabetic or alphanumeric argument at least one character in
length.
Rules
- The type of this function is alphanumeric.
- The returned value is the same character string as the argument,
except that each uppercase letter in the argument is replaced by the
corresponding lowercase letter.
Example
MOVE FUNCTION LOWER-CASE (STR) TO LC-STR.
|
If STR (an alphanumeric data item six characters in length) contains
the value "Autumn" the value returned and stored in LC-STR (also an
alphanumeric data item six characters in length) is "autumn"; if STR
contains "fall98" the value returned is unchanged ("fall98").
7.23 MAX
Description
The MAX function returns the contents of the argument that contains the
maximum value.
argument
is an alphabetic, alphanumeric, integer, or numeric argument.
Rules
- The arguments must be all alphabetic, all alphanumeric, all
integer, or all numeric, except that integer and numeric arguments can
be mixed and alphabetic and alphanumeric arguments can be mixed.
- The type of the function depends on the arguments, as follows:
Arguments |
Function Type |
Alphabetic and/or alphanumeric
|
Alphanumeric
|
Integer (all arguments)
|
Integer
|
Numeric (some arguments might be integer)
|
Numeric
|
- The returned value consists of the contents of the argument having
the greatest value, as determined by comparisons made according to the
rules for simple conditions. (See Chapter 6.)
- If more than one argument has the same value, and that value is
the maximum, the returned value consists of the contents of the
leftmost of these arguments.
- If there is only one argument, the returned value consists of the
contents of that argument.
- If the type of the function is alphanumeric, the size of the
returned value is the same as the size of the argument selected as the
maximum.
Examples
-
MOVE FUNCTION MAX ("A", "B", "C") TO MAX-LETTER-OUT.
MOVE FUNCTION MAX (1, 2, 3) TO MAX-NUMBER-OUT.
|
MAX-LETTER-OUT is alphabetic or alphanumeric, and receives the value
"C"; MAX-NUMBER-OUT is integer and receives the value 3.
-
COMPUTE ITEMC = (ITEMA + FUNCTION MAX (ITEMB, 10)).
|
If ITEM A and ITEMB both contain the value 1, this statement results in
ITEMC having the value 11.
IF FUNCTION MAX (A, B, C) > 100 ...
|
This is equivalent to the following more complex code:
IF A >= B
IF A >= C
MOVE A TO TMP
ELSE
MOVE C TO TMP
ELSE
IF B >= C
MOVE B TO TMP
ELSE
MOVE C TO TMP.
IF TMP > 100 ...
|
- The following example shows generic subscripting with reference
modification:
05 TABLE1 PIC X(7) OCCURS 3 TIMES.
.
.
.
MOVE "XAAAAAQ" TO TABLE1(1).
MOVE "XBBBBBQ" TO TABLE1(2).
MOVE "XCCCCCQ" TO TABLE1(3).
MOVE FUNCTION MAX(TABLE1(ALL)(2:5)) TO RSULT.
|
The value "CCCCC" is returned and stored in RSULT, an alphanumeric
data item. The reference modifier, (2:5), applies to each element
implicitly specified by the ALL subscript. Thus,
FUNCTION MAX(TABLE1(ALL)(2:5))
|
is equivalent to
FUNCTION MAX(TABLE1(1)(2:5),
TABLE1(2)(2:5),
TABLE1(3)(2:5))
|
7.24 MEAN
Description
The MEAN function returns a numeric value that is the arithmetic mean
(average) of its arguments.
arg
is a numeric argument.
Rules
- The type of this function is numeric.
- The return value is the arithmetic mean of the arguments in the
argument list; that is, it is the sum of the arguments divided by the
number of arguments.
Examples
-
COMPUTE AVERAGE-VALUE = FUNCTION MEAN (9, 2, 6, 7, 1).
|
The value returned and stored in AVERAGE-VALUE (a numeric data item) is
5 (the sum of the arguments divided by the number of arguments).
-
COMPUTE MEAN-ANSWER = FUNCTION MEAN(A, B, C).
|
MEAN-ANSWER, A, B, and C are numeric data items. This code is
equivalent to
COMPUTE MEAN-ANSWER = (A + B + C ) / 3.
|
7.25 MEDIAN
Description
The MEDIAN function returns the median value of a list of numbers,
represented by the arguments. This value is such that at least half of
the values are greater than or equal to the returned value, and at
least half are less than or equal.
num
is a numeric argument.
Rules
- The type of this function is numeric.
- If the number of arguments is odd, the returned value is the middle
occurrence in the sorted list.
- If the number of arguments is even, the returned value is the
arithmetic mean of the values referenced by the two middle occurrences
in the sorted list.
- The comparisons used to arrange the argument values in sorted order
are made according to the rules for simple conditions. (See
Chapter 6.)
Examples
-
COMPUTE RSULT = FUNCTION MEDIAN (1, 1, 9, 2, 1).
|
The value returned and stored in RSULT (a numeric data item) is 1.
-
COMPUTE RSULT = FUNCTION MEDIAN (1, 1, 9, 2).
|
The value returned and stored in RSULT is 1.5.
7.26 MIDRANGE
Description
The MIDRANGE (middle range) function returns a numeric value that is
the arithmetic mean (average) of the values of the minimum argument and
the maximum argument.
num
is a numeric argument.
Rules
- The type of this function is numeric.
- The returned value is the arithmetic mean of the greatest argument
value and the least argument value. The comparisons used to determine
the greatest and least values are made according to the rules for
simple conditions. (See Chapter 6.)
- The values of the arguments that are neither the greatest nor the
least in value do not affect the value returned.
Example
COMPUTE RSULT = FUNCTION MIDRANGE (1, 2, 50, 4, 3).
|
The value returned and stored in RSULT (a numeric data item) is 25.5,
which is the arithmetic mean of the greatest and least arguments; that
is, the sum of 50 and 1 divided by 2.
7.27 MIN
Description
The MIN function returns the content of the argument that contains the
minimum value.
argument
is an alphabetic, alphanumeric, integer, or numeric argument.
Rules
- The arguments must be all alphabetic, all alphanumeric, all
integer, or all numeric, except that integer and numeric arguments can
be mixed and alphabetic and alphanumeric arguments can be mixed.
- The type of the function depends on the arguments, as follows:
Arguments |
Function Type |
Alphabetic and/or alphanumeric
|
Alphanumeric
|
Integer (all arguments)
|
Integer
|
Numeric (some arguments might be integer)
|
Numeric
|
- The returned value consists of the contents of the argument having
the least value, as determined by comparisons made according to the
rules for simple conditions. (See Chapter 6.)
- If more than one argument has the same value, and that value is
the minimum, the returned value consists of the contents of the
leftmost of these arguments.
- If there is only one argument, the returned value consists of the
contents of that argument.
- If the type of the function is alphanumeric, the size of the
returned value is the same as the size of the argument selected as the
minimum.
Example
COMPUTE ITEMC = (ITEMA + FUNCTION MIN (ITEMB, 10)).
|
If ITEMA and ITEMB both contain the value 1, this statement results in
ITEMC having the value 2.
7.28 MOD
Description
The MOD function returns the value of argument-1 modulo argument-2.
argument-1
is an integer argument.
argument-2
is an integer argument whose value cannot be 0.
Rules
- The type of this function is integer.
- The returned value is an integer value and is defined as the
following:
argument-1 -- (argument-2 * FUNCTION INTEGER (argument-1 / argument-2))
|
(The INTEGER function returns the greatest integer value that is less
than or equal to the argument. See Section 7.15 for more information.)
Example
COMPUTE RSULT = FUNCTION MOD (ARGUMENT-1, ARGUMENT-2).
|
ARGUMENT-1 and ARGUMENT-2 are numeric integer data items. Following are
the expected results for some values of ARGUMENT-1 and ARGUMENT-2:
ARGUMENT-1 |
ARGUMENT-2 |
RETURN |
11
|
5
|
1
|
-11
|
5
|
4
|
11
|
-5
|
-4
|
-11
|
-5
|
-1
|
7.29 NUMVAL
Description
The NUMVAL function returns the numeric value represented by the
character string specified by the argument. Leading and trailing spaces
are ignored.
arg
is an alphanumeric argument whose content has one of the following two
formats:
where space is a string of 0 or more spaces, and digit is a string of 1
to 18 digits.
Rules
- The type of this function is numeric.
- The total number of digits in the argument must not exceed 18.
- If the DECIMAL-POINT IS COMMA clause is specified in the
SPECIAL-NAMES paragraph, a comma must be used in the argument rather
than a decimal point.
- The returned value is the numeric value represented by the argument.
- The number of digits returned is 18.
Examples
-
COMPUTE RSULT = FUNCTION NUMVAL ("4540").
|
The value returned and stored in RSULT (a numeric data item) is 4540.
-
MOVE "-123.49" TO OLD-ID.
COMPUTE NEW-ID = 2 + FUNCTION NUMVAL (OLD-ID).
|
OLD-ID is an alphanumeric data item, and NEW-ID is a numeric data item.
The value returned by the function is the numeric value -123.49, which
is added to 2, giving the sum -121.49, which is stored in NEW-ID.
7.30 NUMVAL-C
Description
The NUMVAL-C function returns the numeric value represented by the
character string specified by the first argument. Any currency sign
found in the character string and any commas preceding the decimal
point are ignored in determining the result.
arg-1
is an alphanumeric argument whose content has one of the following two
formats:
where space is a string of 0 or more spaces, cs is a
string of 1 or more characters specified by arg-2, and
digit is a string of 1 or more digits.
arg-2
is an alphanumeric argument.
Rules
- The type of this function is numeric.
- The total number of digits in the first argument must not exceed 18.
- If the DECIMAL-POINT IS COMMA clause is specified in the
SPECIAL-NAMES paragraph, the functions of the comma and decimal point
in the first argument are reversed.
- If the optional second argument is not specified, the character
used for cs is the currency symbol specified for the program.
- The returned value is the numeric value represented by the first
argument.
- The number of digits returned is 18.
Example
COMPUTE RSULT = FUNCTION NUMVAL-C ("#1,000.00", "#").
|
The numeric value returned and stored in RSULT (a numeric data item) is
1000.