MOVE "abcd" in 9(10) and DISPLAY.

All sort of Mainframes Interview Questions.
Post Reply
Ashish Mathew
Registered Member
Posts: 50
Joined: Thu Jun 27, 2013 6:17 pm

MOVE "abcd" in 9(10) and DISPLAY.

Post by Ashish Mathew »

Hello All,

I faced this question in an interview:

Can I redefine X(10) as 9(10)? If yes, If I move 'abcd' to X(10) and DISPLAY 9(10) - what will it DISPLAY?


I could anot answer it and checkd it later it showed abcd? Why did it show abcd, it's a numeric field?
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: MOVE "abcd" in 9(10) and DISPLAY.

Post by Robert Sample »

REDEFINES changes the way COBOL views certain bytes of memory -- it does not otherwise impact the data. Hence, moving 'abcd' to the PIC X(10) variable means your memory locations contain X'81828384404040404040' -- which is EBCDIC 'abcd' followed by six spaces. So the PIC 9(10) variable HAS to contain X'81828384404040404040' as well. When you use REDEFINES, you can have anything in the numeric variable. That doesn't mean you won't get an ABEND if you use the numeric variable, just that it may contain non-numeric (or even non-displayable) characters. Many people new to COBOL (and even some with several years experience) believe that a numeric variable can only contain numbers -- and that is not always true.
Ashish Mathew
Registered Member
Posts: 50
Joined: Thu Jun 27, 2013 6:17 pm

Re: MOVE "abcd" in 9(10) and DISPLAY.

Post by Ashish Mathew »

But PIC9(10) should have shown the numeric equivalent of the abcd right? Like the only the numeric part of the HEX equivalent.
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: MOVE "abcd" in 9(10) and DISPLAY.

Post by Robert Sample »

No, it should not have shown the numeric equivalent. You did nothing to modify the data, so the value in the PIC X(10) is what will be displayed. If you did MOVE 'abcd' TO NUMERIC-VARIABLE, then most likely the zones will be changed to F from 8 so the value becomes numeric, but there are now options in COBOL about handling zones.
Ashish Mathew
Registered Member
Posts: 50
Joined: Thu Jun 27, 2013 6:17 pm

Re: MOVE "abcd" in 9(10) and DISPLAY.

Post by Ashish Mathew »

So can i say, unless a MOVE happens PIC (10) and PIC X(10) are just same? Please suggest.
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: MOVE "abcd" in 9(10) and DISPLAY.

Post by Robert Sample »

Sigh. You completely misunderstand the concept of PICTURE in COBOL, AND you have completely misunderstood the previous comments in this thread. You need to learn about internal formats for variables (read chapter 3 in the Enterprise COBOL Language Reference Guide manual to start).
So can i say, unless a MOVE happens PIC (10) and PIC X(10) are just same? Please suggest.
You can say this if you want. However, if you say so in an interview, that is a good way to GUARANTEE you will never (I repeat: NEVER) be hired for any position that requires COBOL coding. There are major and significant differences between numeric and alphanumeric variables, and I'm saying so assuming that you made a typo in your post since PIC 9(10) and PIC (10) are not the same. If you have access to an Enterprise COBOL compiler, try coding ADD 1 TO each type of variable and see what happens. Furthermore, there are plenty of other verbs for which the type of variable makes a difference (ADD, SUBTRACT, MULTIPLY, DIVIDE, COMPUTE are examples).
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.”