HP OpenVMS Systems Documentation 
HP COBOL

Previous  Contents  Index 
Data processing problems frequently require the use of values not directly accessible in the data storage associated with a program. These data values must be derived through operations on other data. Instead of having to write code to specify many common operations step by step, the programmer can use intrinsic functions. An intrinsic function is treated as a temporary elementary data item that contains a temporary data value to be derived automatically at the time of reference during execution of the program.^{1}
The uses of the intrinsic functions can be summarized briefly in the following listing by category:
CATEGORY  FUNCTIONS 

Scientific/Mathematical  ACOS, ASIN, ATAN, COS, FACTORIAL, LOG, LOG10, MOD, REM, SIN, SQRT, SUM, TAN 
Relational  MAX, MIN, ORDMAX, ORDMIN 
String Manipulation  LOWERCASE, NUMVAL, NUMVALC, REVERSE, UPPERCASE 
Date Manipulation 
CURRENTDATE, DATEOFINTEGER,
DATETOYYYYMMDD, DAYTOYYYYDDD, DAYOFINTEGER, INTEGEROFDATE, INTEGEROFDAY, TESTDATEYYYYMMDD, TESTDAYYYYYDDD, WHENCOMPILED, YEARTOYYYY 
Statistical/Accounting 
ANNUITY, MEAN, MEDIAN, MIDRANGE, PRESENTVALUE, RANGE,
STANDARDDEVIATION, VARIANCE 
Other 
ARGCOUNT (OpenVMS), CHAR, INTEGER, INTEGERPART,
LENGTH, ORD, RANDOM 
Later in this chapter (in Function Descriptions) you will find a comprehensive table (Table 71) of functions, including their types, arguments, and values returned. Following the table are complete descriptions, including formats, of the individual functions in alphabetic order.
^{1} With an intrinsic function, the data value that it returns does not persist after the call is complete, unless the data value is moved to a userdeclared field. 
A call to an intrinsic function is constructed as a functionidentifier made up of the word FUNCTION and a name, as well as any applicable arguments and modifiers. The name is one of those shown in Table 71. An argument (see the description in the argument section) is selected according to application requirements.
A functionidentifier is a syntactically correct combination of character strings and separators that uniquely references the data item resulting from the evaluation of a function. Although intrinsic functions are treated as elementary data items, they cannot be receiving operands.
A functionidentifier that references an alphanumeric function can generally be specified wherever a sending identifier is permitted and wherever a reference to a function is not specifically prohibited by generalformat rules. (For example, the rules for the CALL statement prohibit a function from being referenced in a CALL statement as an argument.) An integer or numeric function can be used anywhere an arithmetic expression (defined in Section 6.4) can be used.
functionname
is one of the names listed in the first column of Table 71. A functionname must be specified as part of a functionidentifier. Most functionnames are not reserved words,^{2} and can be used in a program outside the context of a function.argument
is an identifier, a literal, or an arithmetic expression. It complies with the specific rules governing the number, class, and category of arguments for the function. If it is an identifier, it can be subscripted, qualified, or referencemodified, and it can be a functionidentifier. Functions may have between 0 and 250 arguments as specified by the definition of each function. The arguments in an argument list may be separated by a comma.^{3} Arguments are evaluated individually, from left to right.Most intrinsic functions require one or more arguments. The programmer must specify arguments of the proper type and number and within the legal constraints for the function; otherwise, the result of the statement may be undefined.
referencemodifier
can be specified only for alphanumeric functions. It specifies the beginning character position to be selected in the resulting data item and optionally the length of the resulting data item. (For more information on reference modification, see Section 6.2.3.)
An argument of an intrinsic function that permits a variable number of arguments can be a generically subscripted table or portion of a table. Generic, or ALL, subscripting (available only for intrinsic function arguments) is the use of the word ALL to specify all elements in one or more dimensions of a table. (A table element is a data item that contains or is subordinate to an OCCURS clause; if it is an OCCURS DEPENDING ON clause, the range of values is determined by the object of the clause.) Additional arguments, if any, of the function may or may not be table names. The evaluation of an ALL subscript must result in at least one argument; otherwise the result of executing the statement is undefined.
The order of the implicit specification of each occurrence of a table element is from left to right. This process is spelled out in detail in the following paragraph:
The first (or leftmost) specification is the identifier with each subscript specified by ALL replaced by one, and the next specification is the same identifier with the rightmost subscript specified by 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 there are any additional ALL subscripts, the ALL subscript immediately to the left of the rightmost ALL is incremented by one, the rightmost ALL 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 by one 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 that clause.
Also see the definition of subscript in the Glossary.
The reference modifier (if any) of an argument with an ALL subscript applies to each of the implicitly specified elements of the table. See Chapter 6, Procedure Division for the general format of ALL subscripting.
When one subscript of a multidimensional table is ALL, every other subscript must be one of the following:
Another ALL subscript
A positive integer literal
The dataname of a numeric integer elementary item (optionally followed by a plus or minus sign and an integer literal)
An indexname (optionally followed by a plus or minus sign and an integer literal)
The functions that permit generic subscripting of arguments are the following:
MAX
MEAN
MEDIAN
MIDRANGE
MIN
ORDMAX
ORDMIN
PRESENTVALUE
RANGE
STANDARDDEVIATION
SUM
VARIANCE
See MAX and SUM for examples of generically subscripted arguments.
There are three types of functions, based on the type of their resultant values, as follows:
Table 71 lists the intrinsic functions, along with their types, their arguments, and the values they return. Complete descriptions of the functions, arranged alphabetically, follow.
Function  Number and Type of Arguments 
Function Type 
Value Returned 

ACOS  1 numeric, num  Numeric  Arccosine of num 
ANNUITY  1 numeric, num, and 1 integer, int  Numeric  Ratio of annuity paid for each of int periods at interest of num to initial investment of one monetary unit 
ARGCOUNT (OpenVMS)  None  Integer  Number of arguments passed to the COBOL program 
ASIN  1 numeric, num  Numeric  Arcsine of num 
ATAN  1 numeric, num  Numeric  Arctangent of num 
CHAR  1 integer, int  Alphanumeric  Character in position int of program collating sequence 
COS  1 numeric, num  Numeric  Cosine of num 
CURRENTDATE  None  Alphanumeric  Current date and time 
DATEOFINTEGER  1 integer  Integer  Standard date equivalent (YYYYMMDD) of integer date ^{5} 
DATETOYYYYMMDD  1 or 2 integer  Integer  YYYYMMDD date converted from YYMMDD date 
DAYOFINTEGER  1 integer  Integer  YYYYDDD date equivalent of integer date ^{5} 
DAYTOYYYYDDD  1 or 2 integer  Integer  YYYYDDD date converted from YYDDD date 
FACTORIAL  1 integer, int  Integer  Factorial of int 
INTEGER  1 numeric, num  Integer  The greatest integer not greater than num 
INTEGEROFDATE  1 integer  Integer  Integer date ^{5} equivalent of standard date (YYYYMMDD) 
INTEGEROFDAY  1 integer  Integer  Integer date ^{5} equivalent of date in YYYYDDD format 
INTEGERPART  1 numeric, num  Integer  Integer part of num 
LENGTH  1 alphabetic or numeric or alphanumeric data item, or 1 nonnumeric literal  Integer  Length of argument 
LOG  1 numeric, num  Numeric  Natural logarithm of num 
LOG10  1 numeric, num  Numeric  Logarithm to base 10 of num 
LOWERCASE  1 alphabetic or 1 alphanumeric  Alphanumeric  All letters in the argument set to lowercase 
MAX  1 or more alphabetic and/or alphanumeric, or 1 or more integer and/or numeric  Depends on arguments ^{6}  Value of maximum argument 
MEAN  1 or more numeric  Numeric  Arithmetic mean of arguments 
MEDIAN  1 or more numeric  Numeric  Median of arguments 
MIDRANGE  1 or more numeric  Numeric  Mean of minimum and maximum arguments 
MIN  1 or more alphabetic and/or alphanumeric, or 1 or more integer and/or numeric  Depends on arguments ^{6}  Value of minimum argument 
MOD  2 integer, int1 and int2  Integer  Value of int1 modulo int2 
NUMVAL  1 alphanumeric  Numeric  Numeric value of simple numeric string 
NUMVALC  1 or 2 alphanumeric  Numeric  Numeric value of numeric string with optional commas and currency sign 
ORD  1 alphabetic or 1 alphanumeric  Integer  Ordinal position of the argument in collating sequence 
ORDMAX 
1 or more alphabetic,
or 1 or more numeric, or 1 or more alphanumeric 
Integer  Ordinal position of maximum argument 
ORDMIN 
1 or more alphabetic,
or 1 or more numeric, or 1 or more alphanumeric 
Integer  Ordinal position of minimum argument 
PRESENTVALUE  1 numeric, num1; and 1 or more additional numeric, num2  Numeric  Present value of a series of future periodend amounts, num2, at a discount rate of num1 
RANDOM  1 integer or none  Numeric  Pseudorandom number 
RANGE 
1 or more integer, or
1 or more numeric 
Integer or numeric depending on arguments  Value of maximum argument minus value of minimum argument 
REM  2 numeric, num1 and num2  Numeric  Remainder of num1/ num2 
REVERSE  1 alphabetic or 1 alphanumeric  Alphanumeric  Reverse order of the characters of the argument 
SIN  1 numeric, num  Numeric  Sine of num 
SQRT  1 numeric, num  Numeric  Square root of num 
STANDARD
DEVIATION 
1 or more numeric  Numeric  Standard deviation of arguments 
SUM  1 or more integer or 1 or more numeric  Integer or numeric depending on arguments  Sum of arguments 
TAN  1 numeric, num  Numeric  Tangent of num 
TESTDATEYYYYMMDD  1 integer  Integer  0,1,2, or 3, indicating whether the date is a valid date in the Gregorian calendar, and reason if invalid 
TESTDAYYYYYDDD  1 integer  Integer  0, 1, or 2, indicating whether the Julian date is a valid date in the Gregorian calendar, and reason if invalid 
UPPERCASE  1 alphabetic or 1 alphanumeric  Alphanumeric  All letters in the argument set to uppercase 
VARIANCE  1 or more numeric  Numeric  Variance of argument 
WHENCOMPILED  None  Alphanumeric  Date and time program was compiled 
YEARTOYYYY  1 or 2 integer  Integer  4digit year, converted from 2digit year 
^{2} The exceptions are the functionnames LENGTH, RANDOM, and SUM, which are reserved words. Note that FUNCTION is also a reserved word.^{3} Whereas in other contexts, the comma, semicolon, and space can be used interchangeably as separators, the comma has special relevance in the argument lists of intrinsic functions. It is sometimes necessary to use commas as separators between arguments to resolve ambiguity. 
Previous  Next  Contents  Index 