Page 1 of 1

Reverse the value in COBOL.

Posted: Mon Dec 21, 2015 4:31 pm
by Ankit Gautam
Hi,

Another question which I face goes like this:

I have a string of size 26. Basically it's the letters from alphabet. With value like "ABCDE....WXYZ". Now I want to display this variable in reverse direction like "ZYXW....EDCBA".

I replied that we can do it using OOCURS. In which I can start from 26 and subtract 1 until the counter reach to 1. But question became complex when he said what if you don't know the PIC clause value of the variable?

Another question with which I need he is, he told that there can be other ways to do it but I could not answer. What are the other ways?

Re: Reverse the value in COBOL.

Posted: Mon Dec 21, 2015 6:24 pm
by Robert Sample
There is the LENGTH function if you don't know the PIC clause value of the variable.

There is an intrinsic function REVERSE which could be used.

You could use reference modification instead of OCCURS to address the individual bytes.

Re: Reverse the value in COBOL.

Posted: Mon Dec 28, 2015 2:45 pm
by Ankit Gautam
Robert Sample wrote:There is the LENGTH function if you don't know the PIC clause value of the variable.

There is an intrinsic function REVERSE which could be used.

You could use reference modification instead of OCCURS to address the individual bytes.
Thanks Robert. :yes: