Do we have REVERSE command in COBOL?

4 posts / 0 new
Last post
Do we have REVERSE command in COBOL?




Can some one tell me if REVERSE command is available in COBOL? I tried in manuals but could not get it to work :(

I am looking to reverse a string.

"; ; ; ;
Joined: 07/07/2011 - 19:59
Reverse Command

Not as far as i am aware of but COBOL can call C functions that may achieve the same result. i have not done that yet so am unaware of exactly how to go about that.

otherwise you can always do the following:

01 i pic s9(4) binary.
01 j pic s9(4) binary.

01 original-string pic x(255).
02 reversed-string pic X(255).

move length of original-string to j

perform varying i from 1 by +1 until i > length of original-string

move original-string(i:1) to reversed-string(j:1)
subtract 1 from j


Joined: 07/07/2011 - 19:59
MOVE FUNCTION REVERSE(original-string) TO reversed-string. The best way to reverse a string in COBOL.
function reverse(your

function reverse(your string)

after reverse inspect for initial spaces and do reference move from initial character

Log in or register to post comments
Sponsored Listing