The REVERSE phrase in COBOL is used to reverse the order of characters in a string, typically using the FUNCTION REVERSE intrinsic function. It is useful for data formatting, string manipulation, and certain business logic scenarios.
123456789101112131415* Reverse a string using FUNCTION REVERSE MOVE FUNCTION REVERSE(name) TO reversed-name * Example 01 NAME PIC X(10) VALUE 'COBOL'. 01 REVERSED-NAME PIC X(10). PROCEDURE DIVISION. MOVE FUNCTION REVERSE(NAME) TO REVERSED-NAME DISPLAY REVERSED-NAME *> Output: 'LOBOC' * Reverse a numeric value (convert to string first) MOVE FUNCTION REVERSE(FUNCTION NUMVAL-C("12345")) TO reversed-num * Note: INSPECT REVERSED is not standard COBOL syntax
Use FUNCTION REVERSE to reverse strings. INSPECT REVERSED is not standard COBOL.
1. What is the primary use of the REVERSE phrase in COBOL?
2. Which COBOL statement or function uses REVERSE to manipulate strings?
3. How do you reverse a string in COBOL using an intrinsic function?
4. Is REVERSE supported in all COBOL compilers?
5. Which of the following is a valid use of REVERSE?