  | 
		
HP COBOL Reference Manual
 
 
7.31 ORD
Description
 
 
The ORD function returns an integer value that is the ordinal position
of the argument in the collating sequence for the program. The lowest
ordinal position is 1.
  
 
arg
is an alphabetic or alphanumeric argument one character in length.
 
Rules
 
 
  - The type of this function is integer.
  
 - The value returned is the ordinal position of the specified
  character in the program collating sequence. (See the information on
  the ALPHABET clause in Chapter 4.)
  
Example
 
 
 
  
    
       
      
COMPUTE POSITION = FUNCTION ORD (SINGLE-CHAR).
 
 |   
If SINGLE-CHAR (an alphabetic or alphanumeric data item) has the value
"A", the integer representing the ordinal position of "A" in the
program collating sequence (66 for native) is the value returned and
stored in POSITION (a numeric integer data item). (The numeric
representation of a character is not the same as its ordinal position.
Numeric representation starts at 0, whereas ordinals start at 1. Thus,
the ordinal value of a character is always 1 greater than its numeric
value.)
7.32 ORD-MAX
Description
 
 
The ORD-MAX function returns a value that is the ordinal number of the
argument that contains the maximum value.
  
 
arg
is an alphabetic, alphanumeric, integer, or numeric argument.
 
Rules
 
 
  - The type of this function is integer.
  
 - 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 returned value is the ordinal number that corresponds to the
  position of the argument having the greatest value in the argument
  series.
  
 - The comparisons used to determine the greatest value are made
  according to the rules for simple conditions. (See Chapter 6.)
  
 - If more than one argument has the same greatest value, the number
  returned corresponds to the position of the leftmost argument having
  that value.
  
 - If there is only one argument, the value returned is 1.
  
Example
 
 
 
  
    
       
      
COMPUTE RSULT = FUNCTION ORD-MAX (A, B, C).
 
 |   
A, B, and C are alphanumeric data items one character in length. If the
value "A" is in A, "B" is in B, and "C" is in C, the value returned and
stored in RSULT (a numeric data item) is 3, because the third argument,
C, has the greatest value.
7.33 ORD-MIN
Description
 
 
The ORD-MIN function returns a value that is the ordinal number of the
argument that contains the minimum value.
  
 
arg
is an alphabetic, alphanumeric, integer, or numeric argument.
 
Rules
 
 
  - The type of this function is integer.
  
 - 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 returned value is the ordinal number that corresponds to the
  position of the argument having the least value in the argument series.
  
 - The comparisons used to determine the least value are made
  according to the rules for simple conditions. (See Chapter 6.)
  
 - If more than one argument has the same least value, the number
  returned corresponds to the position of the leftmost argument having
  that value.
  
 - If there is only one argument, the value returned is 1.
  
Example
 
 
 
  
    
       
      
COMPUTE RSULT = FUNCTION ORD-MIN (A, B, C).
 
 |   
A, B, and C are alphanumeric data items one character in length. If the
value "A" is in A, "B" is in B, and "C" is in C, the value returned and
stored in RSULT (a numeric data item) is 1, because the first argument,
A, has the least value.
7.34 PRESENT-VALUE
Description
 
 
The PRESENT-VALUE function returns a value that approximates the
present value of a series of future period-end amounts at a discount
rate. The discount rate is specified by the first argument, and the
future period-end amount(s) by one or more subsequent arguments.
  
 
rate
is a numeric argument greater than -1 representing the discount rate.
amt
is a numeric argument representing a future period-end amount.
 
Rules
 
 
  - The type of this function is numeric.
  
 - The period-end amounts specified must be for periods of equal
  duration, and the discount rate must be the rate per period (for
  example, if each period is a year, then use the annual discount rate).
  
 - The returned value is an approximation of the summation of a series
  of calculations with each term in the following form:
There is one term for each occurrence of amt. The exponent, n, is
incremented from 1 by 1 for each term in the series. If there are four
arguments (rate, amt-1, amt-2, amt-3), the calculation is as follows:
 
  
    
       
      
present-value = amt-1 / (1 + rate) ** 1 +
amt-2 / (1 + rate) ** 2 + amt-3 / (1 +
rate) ** 3
     | 
   
 
   
Example
 
 
 
  
    
       
      
COMPUTE RSULT = FUNCTION PRESENT-VALUE (DISCOUNT-RATE, 2000).
 
 |   
DISCOUNT-RATE and RSULT are numeric data items. If DISCOUNT-RATE has
the value 0.08, the value returned and stored in RSULT is approximately
1851.85.
7.35 RANDOM
Description
 
 
The RANDOM function returns a numeric value that is a pseudo-random
number from a rectangular distribution.
  
 
seed
is an optional integer argument with the value of 0 or a positive
integer, used as the seed value to generate a sequence of pseudo-random
numbers. The range of seed values that results in unique sequences of
pseudo-random numbers is 0 through 2147483647.
 
Rules
 
 
  - The type of this function is numeric.
  
 - If the optional seed argument is not specified by the first
  reference to this function in the run unit, the seed value is 0.
  
 - If any subsequent reference to this function in the run unit does
  not specify the seed argument, the value returned is the next number in
  the current sequence of pseudo-random numbers.
  
 - If a subsequent reference to this function in the run unit does
  specify the seed argument, a new sequence of pseudo-random numbers is
  started.
  
 - The returned value is greater than or equal to 0 and less than 1.
  
 - For a given seed value, the sequence of pseudo-random numbers is
  always the same.
  
Example
 
 
 
  
    
       
      
COMPUTE RSULT-1 = FUNCTION RANDOM (12345).
   .
   .
   .
COMPUTE RSULT-2 = FUNCTION RANDOM.
   .
   .
   .
COMPUTE RSULT-3 = FUNCTION RANDOM (12345).
 
 |   
RSULT-1, RSULT-2, and RSULT-3 are numeric data items. Assuming the
three sentences in the example are in the same run unit, the values
returned and stored in RSULT-1 and RSULT-3 are the same. RSULT-2 has a
different value consisting of the next number in the sequence that was
started by the first reference to the function.
  
  
		 |