Top
NetCOBOL V11.0 Syntax Samples
FUJITSU Software

1.50 REVERSE Function

The REVERSE function reverses the order of characters in the string passed as an argument to the function.

000010 @OPTIONS MAIN
000020*-----------------------------------------------------------------------
000030* The REVERSE function reverses the order of character strings in 
000035* arguments.
000040*-----------------------------------------------------------------------
000050 IDENTIFICATION   DIVISION.
000060 PROGRAM-ID.      SAMPLE.
000070 DATA             DIVISION.
000080 WORKING-STORAGE  SECTION.
000090 01 IN-STR        PIC X(10).
000100 01 REV-STR       PIC X(10).
000110 PROCEDURE        DIVISION.
000120     DISPLAY "Please input 10 alphabetic characters. >> " WITH NO
000125              ADVANCING.
000130     ACCEPT IN-STR FROM CONSOLE.
000140*-----------------------------------------------------------------------
000150* The order of the characters in the input string is reversed.
000160*-----------------------------------------------------------------------
000170     MOVE FUNCTION REVERSE (IN-STR) TO REV-STR.
000180*-----------------------------------------------------------------------
000190     DISPLAY " ".
000200     DISPLAY "Input character string:    " IN-STR.
000210     DISPLAY "Reversed character string: " REV-STR.
000220 END PROGRAM SAMPLE.