Reverse the value in COBOL.

All sort of Mainframes Interview Questions.
Post Reply
Ankit Gautam
New Member
Posts: 5
Joined: Tue Jul 29, 2014 12:29 pm

Reverse the value in COBOL.

Post 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?
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Reverse the value in COBOL.

Post 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.
Ankit Gautam
New Member
Posts: 5
Joined: Tue Jul 29, 2014 12:29 pm

Re: Reverse the value in COBOL.

Post 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:
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “Interview Questions.”