[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
Reference Manual


Previous Contents Index

7.14 FACTORIAL

Description

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.

Rules

  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.

Example


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

Description

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


num

is a numeric argument.

Rule

The type of this function is integer.

Example


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

Description

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.

Rules

  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.

Examples


  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.

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

  1. The type of this function is integer.
  2. 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.
  3. 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

  1. The type of this function is integer.
  2. If the value of the argument is 0, the returned value is 0.
  3. 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.
  4. 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

  1. The type of this function is integer.
  2. 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.
  3. The returned value includes implicit FILLER characters, if any.
  4. 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


  1. COMPUTE RSULT = FUNCTION LENGTH ("J. R. Donaldson").
    
    The value 15 is returned and stored in RSULT (a numeric integer data item).

  2. 
    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.)


Previous Next Contents Index