The REVERSE function returns a character string of exactly the same length as argument-1 and whose characters are exactly the same as those of argument-1, except that they are in reverse order.
The type of this function depends upon the argument types as follows:
Argument type | Function type |
alphabetic | alphanumeric |
Format
FUNCTION
REVERSE
(argument-1)
Arguments
argument-1 must be class alphabetic, alphanumeric or national and must be at least one character in length.
argument-1 must not be defined in the ANY LENGTH clause.
Returned values
If argument-1 is a character string of length n, the returned value is a character string of length n such that for 1 <= j <= n, the character in position j of the returned value is the character from position n
-
j + 1 of argument-1.The error default value is a space.
Example 9-40
... DATA DIVISION. WORKING-STORAGE SECTION. 01 REV PIC X(17) VALUE "never odd or even". 01 RES PIC X(17). PROCEDURE DIVISION. P1 SECTION. MAIN. MOVE FUNCTION REVERSE (REV) TO RES. DISPLAY RES UPON T. STOP RUN.
Result: neve ro ddo reven