COBOL Manual for TNS and TNS/R Programs
Intrinsic Functions
HP COBOL Manual for TNS and TNS/R Programs—522555-006
14-44
ORD-MAX Function
The returned value is the ordinal number of the argument with the greatest value
(according to the rules for evaluating simple conditions). If more than one argument
has the same greatest value, the returned value is the ordinal number of the leftmost
argument with that value. The returned value is at least one.
Example 14-30. ORD-MAX Function
Code:
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NUMERIC-ARRAY.
05 PICTURE 9(1) VALUE 4.
05 PICTURE 9(1) VALUE 9.
05 PICTURE 9(1) VALUE 3.
05 PICTURE 9(1) VALUE 7.
05 PICTURE 9(1) VALUE 5
01 NUM-ARRAY REDEFINES NUMERIC-ARRAY.
05 NUM OCCURS 5 TIMES PICTURE 9(1).
01 ALPHABETIC-ARRAY.
05 PICTURE X(5) VALUE "dog".
05 PICTURE X(5) VALUE "cat".
05 PICTURE X(5) VALUE "horse".
05 PICTURE X(5) VALUE "sheep".
05 PICTURE X(5) VALUE "goat".
01 ALPHA-ARRAY REDEFINES ALPHABETIC-ARRAY.
05 ALPHA OCCURS 5 TIMES PICTURE X(5).
PROCEDURE DIVISION.
DISPLAY FUNCTION ORD-MAX (NUM(ALL))
DISPLAY FUNCTION ORD-MAX (ALPHA(ALL))
DISPLAY FUNCTION ORD-MAX (NUM(1) NUM(4))
DISPLAY FUNCTION ORD-MAX (ALPHA(3) "bird" "fish")
DISPLAY FUNCTION ORD-MAX (3.4 5 6.2 9)
Output:
0000000002
0000000004
0000000002
0000000001
0000000004