# Compaq COBOLReference Manual

 Previous Contents Index

# 7.2 ACOS

The ACOS function returns a numeric value in radians that approximates the arccosine of the argument.

General Format
 FUNCTION ACOS (arg)

### arg

is a numeric argument with a value greater than or equal to -1 and less than or equal to +1.
1. The type of this function is numeric.
2. The returned value is the approximation of the arccosine of arg and is greater than or equal to 0 and less than or equal to Pi sign (approximately 3.14159).

 ```COMPUTE RSULT = FUNCTION ACOS (.85). ```
The value returned and stored in RSULT (a numeric data item) is a number that approximates the arccosine of .85.

# 7.3 ANNUITY

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 the second argument) to an initial investment of one. Interest is earned at the rate specified (by the first argument), and is applied at the end of the period, before the payment. ### interest-rate

is a numeric argument with a value greater than or equal to 0, representing the interest rate applied at the end of the period before the payment.

### num-periods

is a positive integer argument representing the number of periods.
1. The type of this function is numeric.
2. When the value of interest-rate is 0, the value of the function is the approximation of 1 / num-periods.
3. When the value of interest-rate is not 0, the value of the function is the approximation of
interest-rate / (1 --(1 + interest-rate) ** (-- num-periods)).

 ```COMPUTE RSULT = FUNCTION ANNUITY (INTEREST-RATE, NUM-PERIODS). ```
INTEREST-RATE is a numeric data item, and NUM-PERIODS is a numeric integer data item. If the value of INTEREST-RATE is 0 and the value of NUM-PERIODS is 6, RSULT has a value approximating 1/6. If the value of INTEREST-RATE is .11 and the value of NUM-PERIODS is 6, RSULT (a numeric data item) has a value of approximately 0.2364.

# 7.4 ARGCOUNT (OpenVMS Only)

The ARGCOUNT function returns a numeric integer equal to the number of arguments passed to the Compaq COBOL program. 1. The type of this function is integer.
2. The returned value represents the actual number of arguments passed to the Compaq COBOL program that contains the function.

 ```IF FUNCTION ARGCOUNT = 3 PERFORM PROCESS-OPTIONAL-3RD-ARGUMENT. ```
If there are three arguments passed to the Compaq COBOL program containing the ARGCOUNT function, a third argument supplied with the COBOL program calling command will be parsed and processed.

See the Argument Information Register in the OpenVMS Calling Standard. <>

# 7.5 ASIN

The ASIN function returns a numeric value in radians that approximates the arcsine of the argument. ### arg

is a numeric argument with a value greater than or equal to -1 and less than or equal to +1.
1. The type of this function is numeric.
2. The returned value is the approximation of the arcsine of arg and is greater than or equal to - Pi sign /2 and less than or equal to + Pi sign /2. ( Pi sign is approximately 3.14159.)

 ```COMPUTE RSULT = FUNCTION ASIN (.675). ```
The value returned and stored in RSULT (a numeric data item) is a number that approximates the arcsine of .675.

# 7.6 ATAN

The ATAN function returns a numeric value in radians that approximates the arctangent of the argument. ### arg

is a numeric argument.
1. The type of this function is numeric.
2. The returned value is the approximation of the arctangent of arg and is greater than - Pi sign /2 and less than + Pi sign /2. ( Pi sign is approximately 3.14159.)

 ```COMPUTE RSULT = FUNCTION ATAN (MEASUREMENT-IN-RADIANS). ```
MEASUREMENT-IN-RADIANS and RSULT are numeric data items. The value returned and stored in RSULT is a number that approximates the arctangent of the value of MEASUREMENT-IN-RADIANS.

# 7.7 CHAR

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 the argument. ### position

is a positive integer argument representing the ordinal position of the desired character in the program collating sequence, and having a value less than or equal to the number of positions in the collating sequence.
1. The type of this function is alphanumeric.
2. The character returned as the function value is the character in the program collating sequence. (See the information on the ALPHABET clause in Chapter 4.)
3. 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.

 ```MOVE FUNCTION CHAR (13) TO FORM-FEED-CH. ```
The character occupying the 13th position in the program collating sequence (that is, a form feed in the default collating sequence) is returned and stored in FORM-FEED-CH, which is an alphanumeric data item one character in length. (The numeric representation of a character is not the same as its ordinal position. Numeric representation starts at 0, whereas ordinals start at 1. Always add 1 to the numeric value of the desired character.)

# 7.8 COS

The COS function returns a numeric value that approximates the cosine of an angle or arc, expressed in radians, that is specified by the argument. ### angle

is a numeric argument having the value of the measurement in radians of an angle or arc.
1. The type of this function is numeric.
2. The returned value is the approximation of the cosine of angle, and is greater than or equal to -1 and less than or equal to +1.

 ```COMPUTE COSIN-RSLT = FUNCTION COS (X). ```
X and COSIN-RSULT are numeric data items. If the value of X is 3, the approximate cosine of an angle of 3 radians is moved to COSIN-RSLT.

# 7.9 CURRENT-DATE

The CURRENT-DATE function returns a 21-character alphanumeric value that represents the calendar date and the time of day. 1. The type of this function is alphanumeric.
2. The contents of the character positions returned, numbered from left to right, are as follows:
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 (Tru64 UNIX and OpenVMS systems. The digits are 00 Windows NT systems, which does not show fractions of a second.)
17-21 The value 00000. (Reserved for future use.)

The COBOL syntax for this function (similar to the example) is common to all platforms:

 ```MOVE FUNCTION CURRENT-DATE TO RSULT. ```

 ```199701101652313200000 (Tru64 UNIX and OpenVMS systems) 199701101652310000000 (Windows NT systems) ```
This is a sample value returned by the example CURRENT-DATE function. Reading from left to right, it shows

• The year, 1997
• The month, January
• The day of the month, the 10th

• The time of day, 16:52 (4:52 P.M.)
• On Tru64 UNIX and OpenVMS, the seconds, 31, and the hundredths
of seconds, 32, after 16:52 <>
• On Windows NT, the seconds, 31, followed by zeros (Windows NT systems do
not show hundredths of seconds) <>

# 7.10 DATE-OF-INTEGER

The DATE-OF-INTEGER function converts a date from an integer date form representing the number of days after December 31, 1600, to standard date form (YYYYMMDD). ### num-days

is a positive integer argument that represents a number of days succeeding December 31, 1600, in the Gregorian calendar.
1. The type of this function is integer.
2. The returned value represents the ISO Standard date, in the form YYYYMMDD, that is equivalent to the integer specified. YYYY is an integer in the range 1601 through 9999. MM is an integer in the range 1 through 12. DD is an integer in the range 1 through 31.

 ```COMPUTE RSULT = FUNCTION DATE-OF-INTEGER (20). ```
The value returned and stored in RSULT (a numeric integer data item) is

 ```16010120 ```
This value represents January 20, 1601, which is 20 days after December 31, 1600.

# 7.11 DATE-TO-YYYYMMDD

The DATE-TO-YYYYMMDD function converts a date in the form YYMMDD to the form YYYYMMDD. An optional second argument, when added to the current year (at the time the program executes), defines the ending year of a 100-year interval. This interval determines to what century the two-digit year belongs.

General Format
 FUNCTION DATE-TO-YYYYMMDD ( arg-1 [ arg-2 ] )

### arg-1

is a nonnegative integer between 0 and 999999.

### arg-2

is an integer. Its value, when added to the current year, must be between 1700 and 9999. If it is omitted, the default value is 50.
1. The type of this function is integer.
2. The returned value is an integer representing YYYYMMDD and is calculated as follows:

 ``` YY = int(arg-1 / 10000) mmdd = mod (arg-1, 10000) return FUNCTION YEAR-TO-YYYY(YY, arg-2) * 10000 + mmdd ```

 ```IF FUNCTION DATE-TO-YYYYMMDD (801123, 50 ) = 19801123 DISPLAY "correct". IF FUNCTION DATE-TO-YYYYMMDD (801123, 100 ) = 20801123 DISPLAY "correct". IF FUNCTION DATE-TO-YYYYMMDD (801123, -100 ) = 18801123 DISPLAY "correct". ```

DATE-TO-YYYYMMDD implements a sliding window algorithm. To use it for a fixed window, you can specify arg-2 as follows:

 ```(fixed-ending-year - function numval (function current-date (1:4))) ```

If fixed-ending-year is 2100, then in 1999 arg-2 has the value 101. If arg-1 is 501123, the returned-value is 20501123. If arg-1 is 991123, the returned-value is 20991123.

# 7.12 DAY-OF-INTEGER

The DAY-OF-INTEGER function converts a date from an integer date form representing the number of days succeeding December 31, 1600, to a date form (sometimes called "Julian") representing year and days (YYYYDDD). ### num-days

is a positive integer argument that represents a number of days succeeding December 31, 1600, in the Gregorian calendar.
1. The type of this function is integer.
2. The returned value is an integer of the form YYYYDDD, where YYYY represents a year in the Gregorian calendar and DDD represents the day of that year. YYYY is an integer in the range 1601 through 9999. DDD is an integer in the range 1 through 366.

 ```COMPUTE RSULT = FUNCTION DAY-OF-INTEGER (28). ```
The value returned and stored in RSULT (a numeric integer data item) shows the 28th day of the year 1601 (that is, 28 days succeeding December 31, 1600), as follows:

 ```1601028 ```

# 7.13 DAY-TO-YYYYDDD

The DAY-TO-YYYYDDD function converts a date in the form YYDDD to the form YYYYDDD. An optional second argument, when added to the current year (at the time the program executes), defines the ending year of a 100-year interval. This interval determines to what century the two-digit year belongs.

General Format
 FUNCTION DAY-TO-YYYYDDD ( arg-1 [ arg-2 ] )

### arg-1

is a nonnegative integer between 0 and 99999.

### arg-2

is an integer. Its value, when added to the current year, must be between 1700 and 9999. If it is omitted, the default value is 50.
1. The type of this function is integer.
2. The returned value is an integer representing YYYYDDD and is calculated as follows:

 ``` YY = int(arg-1 / 1000) ddd = mod (arg-1, 1000) return FUNCTION YEAR-TO-YYYY(YY, arg-2) * 1000 + ddd ```

 ```IF FUNCTION DAY-TO-YYYYDDD (80111, 50 ) = 1980111 DISPLAY "correct". IF FUNCTION DAY-TO-YYYYDDD (80111, 100 ) = 2080111 DISPLAY "correct". IF FUNCTION DAY-TO-YYYYDDD (80111, -100 ) = 1880111 DISPLAY "correct". ```
DAY-TO-YYYYDDD implements a sliding window algorithm. To use it for a fixed window, you can specify arg-2 as follows:

 ```(fixed-ending-year - function numval (function current-date (1:4))) ```
If fixed-ending-year is 2100, then for 1999 arg-2 has the value 101. If arg-1 is 50111, the returned-value is 2050111. If arg-1 is 99111, the returned-value is 2099111.

# 7.14 FACTORIAL

The FACTORIAL function returns an integer that is the factorial of the argument specified. ### num

is 0 or a positive integer argument whose value is less than or equal to 19.
1. The type of this function is integer.
2. If the value of the argument is 0, the value 1 is returned.
3. If the value of the argument is positive, its factorial is returned.

 ```COMPUTE RSULT = FUNCTION FACTORIAL (NUM). ```
NUM and RSULT are numeric integer data items. If NUM has the value of 5, the value returned and stored in RSULT is 120.
(5! = 5 * 4 * 3 * 2 * 1 = 120.)

# 7.15 INTEGER

The INTEGER function returns the greatest integer value that is less than or equal to the argument. ### num

is a numeric argument.

The type of this function is integer.

 ```COMPUTE RSULT = FUNCTION INTEGER (NUM). ```
If the value of NUM (a numeric data item) is -1.5, the value returned and stored in RSULT (a numeric integer data item) is -2, because -2 is the greatest integer that is less than or equal to -1.5. If the value of NUM is +1.5, the value returned and stored in RSULT is +1, because +1 is the greatest integer that is less than or equal to +1.5.

# 7.16 INTEGER-OF-DATE

The INTEGER-OF-DATE function converts a date from standard date form (YYYYMMDD) to an integer date form representing the number of days after December 31, 1600. ### num

is an integer argument of the form YYYYMMDD representing a date subsequent to December 31, 1600.
1. The type of this function is integer.
2. The value of the argument is obtained from the calculation (YYYY * 10,000) + (MM * 100) + DD. YYYY represents the year in the Gregorian calendar, and must be an integer in the range 1601 through 9999. MM represents a month and is an integer in the range 1 through 12. DD represents a day and is an integer in the range 1 through 31; the value of DD must be valid for the specified month and year combination.
3. The returned value is an integer that is the number of days the specified date succeeds December 31, 1600, in the Gregorian calendar.
1.  ```COMPUTE RSULT = FUNCTION INTEGER-OF-DATE (NUM). ```
NUM and RSULT are numeric integer data items. If NUM has the value 16010215 (that is, February 15, 1601), the value returned and stored in RSULT is 46 (the 46th day after December 31, 1600).

2.  ```COMPUTE DAYS-IN-BILLING-CYCLE = FUNCTION INTEGER-OF-DATE(THIS-ENDING-DATE) - FUNCTION INTEGER-OF-DATE(LAST-ENDING-DATE) ```
DAYS-IN-BILLING-CYCLE, THIS-ENDING-DATE, and LAST-ENDING-DATE are numeric integer items. If THIS-ENDING-DATE has the value 19970301 (representing March 1, 1997), and LAST-ENDING-DATE has the value 19970201 (representing February 1, 1997), the value returned is 28.

 Previous Next Contents Index