General Formats (Cont.) [ Micro Focus COBOL Language Reference ] MPE/iX 5.0 Documentation
Micro Focus COBOL Language Reference
General Formats (Cont.)
For ANS85: Intrinsic Functions
The Intrinsic Function module allows you to reference a data item whose
value is derived automatically at the time of reference during the
execution of the object program.
If your program uses intrinsic functions, you will also require the
floating-point module. See your COBOL System Reference for details of
run-time system support modules.
Function-name.
In the Intrinsic Function module, a function is a temporary data item
whose value is determined at the time the function is referenced during
the execution of a statement. A function-name is a COBOL word that is
one of a specified list of COBOL words which can be used in COBOL source
programs. (See the section Definitions of Functions later in this
chapter.)
Function Definition and Returned Value.
A function is defined as:
* for alphanumeric functions, the size of the returned value
* for numeric and integer functions, the sign of the returned value
and whether the function is integer
* for some other cases, the value returned.
Function-identifier.
A function-identifier is used by the programmer to reference a function
in the Procedure Division of a COBOL source program. (See the section
Function-Identifier in the chapter Concepts of the COBOL Language.)
Value Returned by a Function.
The value returned by a function is considered to be a data value. A
mechanism is provided at run time to assign a data value to a function
when it is referenced. In order to determine the function's value, the
evaluation mechanism requires access to data values provided by the
referencing program. These data values are provided by specifying
parameters, known as arguments, when referencing the function. Specific
functions can place constraints on these arguments, such as range, and so
on. If, at the time a function is referenced, the arguments specified
for that reference do not have values that comply with the specified
constraints, then the returned value for the function is undefined.
Date Conversion Functions.
The Gregorian calendar is used in the date conversion functions. The
starting date of Monday, January 1, 1601, was chosen to establish a
simple relationship between the Standard Date and DAY-OF-WEEK; that is,
the integer date 1 was a Monday, DAY-OF-WEEK 1.
For example, the statement:
COMPUTE DoW = FUNCTION REM (FUNCTION INTEGER-OF-DATE
(date-field) , 7)
will return the day of week for a given date, where 0 is Sunday, 1 is
Monday, and so on.
Arguments.
Arguments specify values used in the evaluation of a function. Arguments
are specified in the function-identifier. These arguments can be
specified as identifiers, as arithmetic expressions, or as literals. The
definition of a function specifies the number of arguments required,
which can be zero, one, or more. For some functions, the number of
arguments which can be specified is variable. The order in which
arguments are specified in a function-identifier determines the
interpretation given to each value in arriving at the function value.
Arguments may be required to have a certain class or a subset of a
certain class. The four types of argument are:
1. Numeric. An arithmetic expression must be specified. The value
of the arithmetic expression, including operational sign, is used
in determining the value of the function.
2. Alphabetic. An elementary data item of the class alphabetic or a
nonnumeric literal containing only alphabetic characters must be
specified. The size associated with the argument can be used in
determining the value of the function.
3. Alphanumeric. A data item of the class alphabetic or alphanumeric
or a nonnumeric literal must be specified. The size associated
with the argument can be used in determining the value of the
function.
4. Integer. An arithmetic expression which will always result in an
integer value must be specified. The value of the arithmetic
expression, including operational sign, is used in determining the
value of the function.
The rules for a function can place constraints on the permissible values
for arguments, in order to accurately determine the function's value.
If, at the time a function is referenced, the arguments specified for
that reference do not have values within the permissible range, the
returned value for the function is undefined.
When the definition of a function permits an argument to be repeated a
variable number of times, a table can be referenced by specifying the
data-name and any qualifiers that identify the table, followed
immediately by subscripting where one or more of the subscripts is the
word ALL.
When ALL is specified as a subscript, the effect is as if each table
element associated with that subscript position were specified. The
order of the implicit specification of each occurrence is from left to
right, with the first (or leftmost) specification being the identifier
with each subscript specified by the word ALL replaced by one, the next
specification being the same identifier with the rightmost subscript
specified by the word ALL incremented by one.
This process continues with the rightmost ALL subscript being incremented
by one for each implicit specification until the rightmost ALL subscript
has been incremented through its range of values. If any additional ALL
subscripts exist, the subscript immediately to the left of the rightmost
ALL subscript is incremented by one, the rightmost ALL subscript is reset
to one and the process of varying the rightmost ALL subscript is
repeated. The ALL subscript to the left of the rightmost ALL subscript
is incremented through its range of values. For each additional ALL
subscript this process is repeated in turn until the leftmost ALL
subscript has been incremented by one through its range of values.
If the ALL subscript is associated with an OCCURS DEPENDING ON clause,
the range of values is determined by the object of the OCCURS DEPENDING
ON clause. The evaluation of an ALL subscript must result in at least
one argument, or the returned value is undefined.
Example.
01 Test-Fields.
10 OT-Elem PIC 9(02).
10 Arr.
15 Ind Occurs 5 times PIC 9(02).
Compute OT-Elem = Function sum (IND(ALL)).
is equivalent to specifying
Compute OT-Elem = Function sum (IND(1), IND(2), IND(3),
IND(4),IND(5)).
Types of Functions.
Data item functions are elementary data items and return alphanumeric,
numeric or integer values. Data item functions are treated as elementary
data items and cannot be receiving operands. The three types of data
item functions are:
1. Alphanumeric functions. These are of the class and category
alphanumeric. The number of character positions in this data item
is specified in the function definition. Alphanumeric functions
have an implicit usage of DISPLAY.
2. Numeric functions. These are of the class and category numeric.
A numeric function is always considered to have an operational
sign.
A numeric function can be used only in an arithmetic
expression or as the source of a MOVE statement (MF only).
A numeric function can not be referenced where an integer
operand is required, even though a particular reference can
yield an integer value.
3. Integer functions. These are of the class and category numeric.
An integer function is always considered to have an operational
sign.
An integer function can be used only in an arithmetic
expression or as the source of a MOVE statement (MF only).
An integer function can be referenced where an integer
operand is required and where a signed operand is allowed.
Definitions of Functions.
The following table summarizes the functions that are available.
The Arguments column defines the type and number of arguments as follows:
A means alphabetic
I means integer
N means numeric
X means alphanumeric.
The Type column defines the type of the function as follows:
I means integer
N means numeric
X means alphanumeric.
----------------------------------------------------------------------
| | | | |
| Function-Name | Arguments| Type | Value Returned |
| | | | |
----------------------------------------------------------------------
| | | | |
| ACOS | N1 | N | Arcosine of N1 |
| | | | |
----------------------------------------------------------------------
| | | | |
| ANNUITY | N1, I2 | N | Ratio of annuity paid for |
| | | | I2 periods at interest of |
| | | | N1 to initial investment |
| | | | of one |
| | | | |
----------------------------------------------------------------------
| | | | |
| ASIN | N1 | N | Arcsine of N1 |
| | | | |
----------------------------------------------------------------------
| | | | |
| ATAN | N1 | N | Arctangent of N1 |
| | | | |
----------------------------------------------------------------------
| | | | |
| CHAR | I1 | X | Character in position I1 |
| | | | of program collating |
| | | | sequence |
| | | | |
----------------------------------------------------------------------
| | | | |
| COS | N1 | N | Cosine of N1 |
| | | | |
----------------------------------------------------------------------
| | | | |
| CURRENT-DATE | None | X | Current date and time and |
| | | | difference from Greenwich |
| | | | Mean Time |
| | | | |
----------------------------------------------------------------------
----------------------------------------------------------------------
| | | | |
| Function-Name | Arguments| Type | Value Returned |
| | | | |
----------------------------------------------------------------------
| | | | |
| DATE-OF- | I1 | I | Standard date equivalent |
| INTEGER | | | (YYYYMMDD) of integer date |
| | | | I1 |
| | | | |
----------------------------------------------------------------------
| | | | |
| DAY-OF-INTEGER | I1 | I | Julian date equivalent |
| | | | (YYYYDDD) of integer date |
| | | | I1 |
| | | | |
----------------------------------------------------------------------
| | | | |
| FACTORIAL | I1 | I | Factorial of I1 |
| | | | |
----------------------------------------------------------------------
| | | | |
| INTEGER | N1 | I | The greatest integer not |
| | | | greater than N1 |
| | | | |
----------------------------------------------------------------------
| | | | |
| INTEGER-OF- | I1 | I | The integer date |
| DATE | | | equivalent of standard |
| | | | date (YYYYMMDD) |
| | | | |
----------------------------------------------------------------------
| | | | |
| INTEGER-OF-DAY | I1 | I | The integer date |
| | | | equivalent of Julian date |
| | | | (YYYYDDD) |
| | | | |
----------------------------------------------------------------------
| | | | |
| INTEGER-PART | N1 | I | Integer part of N1 |
| | | | |
----------------------------------------------------------------------
| | | | |
| LENGTH | A1 or N1 | I | Length of argument |
| | or X1 | | |
| | | | |
----------------------------------------------------------------------
| | | | |
| LOG | N1 | N | Natural logarithm of N1 |
| | | | |
----------------------------------------------------------------------
| | | | |
| LOG10 | N1 | N | Logarithm of base 10 of N1 |
| | | | |
----------------------------------------------------------------------
| | | | |
| LOWER-CASE | A1 or X1 | X | All letters in the |
| | | | argument are set of |
| | | | lowercase |
| | | | |
----------------------------------------------------------------------
| | | | |
| MAX | A1...or | Depends | Value of maximum arguments |
| | I1...or | upon | |
| | N1...or | arguments | |
| | X1... | (1) | |
| | | | |
----------------------------------------------------------------------
| | | | |
| MEAN | N1... | N | Arithmetic mean of |
| | | | arguments |
| | | | |
----------------------------------------------------------------------
(1) A function that has only alphabetic arguments is type alphanumeric
----------------------------------------------------------------------
| | | | |
| Function-Name | Arguments| Type | Value Returned |
| | | | |
----------------------------------------------------------------------
| | | | |
| MEDIAN | N1... | N | Median of arguments |
| | | | |
----------------------------------------------------------------------
| | | | |
| MIDRANGE | N1... | N | Mean of minimum and |
| | | | maximum arguments |
| | | | |
----------------------------------------------------------------------
| | | | |
| MIN | A1...or | Depends | Value of minimum argument |
| | I1...or | upon | |
| | N1...or | arguments | |
| | X1... | (1) | |
| | | | |
----------------------------------------------------------------------
| | | | |
| MOD | I1, I2 | I | I1 modulo I2 |
| | | | |
----------------------------------------------------------------------
| | | | |
| NUMVAL | X1 | N | Numeric value of simple |
| | | | numeric string |
| | | | |
----------------------------------------------------------------------
| | | | |
| NUMVAL-C | X1,| X2 | N | Numeric value of numeric |
| | | | string with optional |
| | | | commas and currency sign |
| | | | |
----------------------------------------------------------------------
| | | | |
| ORD | A1 or X1 | I | Ordinal position of the |
| | | | argument in collating |
| | | | sequence |
| | | | |
----------------------------------------------------------------------
| | | | |
| ORD-MAX | A1...or | I | Ordinal position of |
| | N1...or | | maximum argument |
| | X1 | | |
| | | | |
----------------------------------------------------------------------
| | | | |
| ORD-MIN | A1...or | I | Ordinal position of |
| | N1...or | | minimum argument |
| | X1 | | |
| | | | |
----------------------------------------------------------------------
| | | | |
| PRESENT-VALUE | N1 N2... | N | Present value of a series |
| | | | of future period-end |
| | | | amounts, N2, at a discount |
| | | | rate of N1 |
| | | | |
----------------------------------------------------------------------
| | | | |
| RANDOM | I1 | N | Random number |
| | | | |
----------------------------------------------------------------------
(1) A function that has only alphabetic arguments is type alphanumeric
----------------------------------------------------------------------
| | | | |
| Function-Name | Arguments| Type | Value Returned |
| | | | |
----------------------------------------------------------------------
| | | | |
| RANGE | I1...or | Depends | Value of maximum argument |
| | N1 | upon | minus value of minimum |
| | | arguments | arguments |
| | | (1) | |
| | | | |
----------------------------------------------------------------------
| | | | |
| REM | N1, N2 | N | Remainder of N1 N2 |
| | | | |
----------------------------------------------------------------------
| | | | |
| REVERSE | A1 or X1 | X | Reverse order of the |
| | | | characters in the argument |
| | | | |
----------------------------------------------------------------------
| | | | |
| SIN | N1 | N | Sine of N1 |
| | | | |
----------------------------------------------------------------------
| | | | |
| SQRT | N1 | N | Square root of N1 |
| | | | |
----------------------------------------------------------------------
| | | | |
| STANDARD- | N1... | N | Standard deviation of |
| DEVIATION | | | arguments |
| | | | |
----------------------------------------------------------------------
| | | | |
| SUM | I1...or | Depends | Sum or arguments |
| | \N1... | on | |
| | | arguments | |
| | | (1) | |
| | | | |
----------------------------------------------------------------------
| | | | |
| TAN | N1 | N | Tangent of N1 |
| | | | |
----------------------------------------------------------------------
| | | | |
| UPPER-CASE | A1 of X1 | X | All letters in the |
| | | | argument are set to |
| | | | uppercase |
| | | | |
----------------------------------------------------------------------
| | | | |
| VARIANCE | N1... | N | Variance of argument |
| | | | |
----------------------------------------------------------------------
| | | | |
| WHEN-COMPILED | None | X | Date and time program was |
| | | | compiled |
| | | | |
----------------------------------------------------------------------
(1) A function that has only alphabetic arguments is type alphanumeric
For ANS85 only: The ACOS Function.
Description.
The ACOS function returns a numeric value in radians that approximates
the arccosine of argument-1. The type of this function is numeric.
General Format.
Arguments.
1. Argument-1 must be class numeric.
2. The value of argument-1 must be greater than or equal to -1 and
less than or equal to +1.
Returned Values.
1. The returned value is the approximation of the arccosine of
argument-1 and is greater than or equal to zero and less than or
equal to pi.
2. Floating-point format is used for numeric non-integer results.
For ANS85 only: The ANNUITY Function.
Description.
The ANNUITY function (annuity immediate) returns a numeric value that
approximates the ratio of an annuity paid at the end of each period for
the number of periods specified by argument-2 to an initial investment of
one. Interest is earned at the rate specified by argument-1 and is
applied at the end of the period, before the payment. The type of this
function is numeric.
General Format.
Arguments.
1. Argument-1 must be class numeric.
2. The value of argument-1 must be greater than or equal to zero.
3. Argument-2 must be a positive integer.
Returned Values.
1. When the value of argument-1 is zero, the value of the function is
the approximation of:
1 / argument-2
2. When the value of argument-1 is not zero, the value of the
function is the approximation of:
argument-1 / (1 - (1 + argument-1) ** (- argument-2))
3. Floating-point format is used for numeric non-integer results.
For ANS85 only: The ASIN Function.
Description.
The ASIN function returns a numeric value in radians that approximates
the arcsine of argument-1. The type of this function is numeric.
General Format.
Arguments.
1. Argument-1 must be class numeric.
2. The value of argument-1 must be greater than or equal to -1 and
less than or equal to +1.
Returned Values.
1. The returned value is the approximation of the arcsine of
argument-1 and is greater than or equal to -pi/2 and less than or
equal to +pi/2.
2. Floating-point format is used for numeric non-integer results.
For ANS85 only: The ATAN Function.
Description.
The ATAN function returns a numeric value in radians that approximates
the arctangent of argument-1. The type of this function is numeric.
General Format.
Argument.
Argument-1 must be class numeric.
Returned Values.
1. The returned value is the approximation of the arctangent of
argument-1 and is greater than -pi/2 and less than +pi/2.
2. Floating-point format is used for numeric non-integer results.
For ANS85 only: The CHAR Function.
Description.
The CHAR function returns a one character alphanumeric value that is a
character in the program collating sequence having the ordinal position
equal to the value of argument-1. The type of this function is
alphanumeric.
General Format.
Arguments.
1. Argument-1 must be an integer.
2. The value of argument-1 must be greater than zero and less than or
equal to the number of positions in the collating sequence.
Returned Values.
1. If more than one character has the same position in the program
collating sequence, the character returned as the function value
is that of the first literal specified for that character position
in the ALPHABET clause.
2. For MF only: If the current program collating sequence was not
specified by an ALPHABET clause, the native collating sequence is
used .
For ANS85 only: The COS Function.
Description.
The COS function returns a numeric value that approximates the cosine of
an angle or arc, expressed in radians, that is specified by argument-1.
The type of this function is numeric.
General Format.
Argument.
Argument-1 must be class numeric.
Returned Values.
1. The returned value is the approximation of the cosine of
argument-1 and is greater than or equal to -1 and less than or
equal to +1.
2. Floating-point format is used for numeric non-integer results.
For ANS85 only: The CURRENT-DATE Function.
Description.
The CURRENT-DATE function returns a 21-character alphanumeric value that
represents the calendar date, time of day, and local time differential
factor provided by the system on which the function is evaluated. The
type of this function is alphanumeric.
General Format.
Returned Value.
The character positions returned, numbered from left to right, are:
Character
Positions Contents
--------------------------------------------------------
1-4 Four numeric digits of the year in the
Gregorian calendar.
5-6 Two numeric digits of the month of the
year, in the range 01 through 12.
7-8 Two numeric digits of the day of the month,
in the range 01 through 31.
9-10 Two numeric digits of the hours past
midnight, in the range 00 through 23.
11-12 Two numeric digits of the minutes past the
hour, in the range 00 through 59.
13-14 Two numeric digits of the seconds past the
minute, in the range 00 through 59.
15-16 Two numeric digits of the hundredths of a
second past the second, in the range 00
through 99
. If the system does not have the facility to
provide fractional parts of a second, the
value 00 is returned.
Character
Positions Contents
--------------------------------------------------------
17 Either the character "-", the character
"+", or the character "0". The character
"-" is returned if the local time indicated
in the previous character positions is
behind Greenwich Mean Time. The character
"+" is returned if the local time indicated
is the same or ahead of Greenwich Mean
Time. The character "0" is returned if the
system on which this function is evaluated
does not have the facility to provide the
local time differential factor.
If the system does not have the facility to
provide the local time differential factor,
the value 00000 is returned in character
positions 17 through 21.
18-19 If character position 17 is "-", two
numeric digits are returned in the range 00
through 12 indicating the number of hours
that the reported time is behind Greenwich
Mean Time. If character position 17 is
"+", two numeric digits are returned in the
range 00 through 13 indicating the number
of hours that the reported time is ahead of
Greenwich Mean Time. If character position
17 is "0", the value 00 is returned.
20-21 Two numeric digits are returned in the
range 00 through 59 indicating the number
of additional minutes that the reported
time is ahead of or behind Greenwich Mean
Time, depending on whether character
position 17 is "+" or "-" , respectively.
If character position 17 is "0", the value
00 is returned.
For ANS85 only: The DATE-OF-INTEGER Function.
Description.
The DATE-OF-INTEGER function converts a date in the Gregorian calendar
from integer date form to standard date form (YYYYMMDD). The type of this
function is integer.
General Format.
Argument.
Argument-1 is a positive integer that represents a number of days
succeeding December 31, 1600, in the Gregorian calendar.
Returned Values.
1. The returned value represents the ISO Standard date equivalent of
the integer specified in argument-1.
2. The returned value is in the form (YYYYMMDD) where YYYY represents
a year in the Gregorian calendar; MM represents the month of that
year; and DD represents the day of that month.
MPE/iX 5.0 Documentation