Skip to main content

Posts

Showing posts with the label COBOL

How to Reverse a string with or without using REVERSE function?

Hello Readers! Have you ever wanted to REVERSE a string a Mainframe COBOL program, or have you ever been asked to reverse a string without using REVERSE function? If the answer is Yes, then you may find this post useful to you. In the below mentioned COBOL program, I used two different ways of reversing a string in COBOL program. Using FUNCTION REVERSE REVERSE function returns a character string of exactly same length as input, but in the reverse order. Using PERFORM VARYING UNTIL In this logic, we loop through each character of input string from end of input (i.e. Length) to beginning of input (i.e. Position=1) and store the characters in result variable using reference modification. Output: From the output, we can say that we are able to reverse the input, but have you noticed something? Reverse string output has leading spaces. It is because string variable is declared with 20 length, but the actual length length of string (i.e. z/OS Mainframer ) is 15. As input WS-STRING is Alpha...