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

All sort of Mainframes Interview Questions.

Topic author
Ashish Mathew
Registered Member
Posts: 38
Joined: Thu Jun 27, 2013 6:17 pm
Has thanked: 1 time

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

Postby Ashish Mathew » Tue Jan 10, 2017 12:00 pm

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?



Online
User avatar

Robert Sample
Global Moderator
Global Moderator
Posts: 1275
Joined: Fri Jun 28, 2013 1:22 am
Location: East Dubuque Illinois
Has thanked: 2 times
Been thanked: 90 times

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

Postby Robert Sample » Tue Jan 10, 2017 6:16 pm

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.




Topic author
Ashish Mathew
Registered Member
Posts: 38
Joined: Thu Jun 27, 2013 6:17 pm
Has thanked: 1 time

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

Postby Ashish Mathew » Thu Jan 12, 2017 2:35 pm

But PIC9(10) should have shown the numeric equivalent of the abcd right? Like the only the numeric part of the HEX equivalent.



Online
User avatar

Robert Sample
Global Moderator
Global Moderator
Posts: 1275
Joined: Fri Jun 28, 2013 1:22 am
Location: East Dubuque Illinois
Has thanked: 2 times
Been thanked: 90 times

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

Postby Robert Sample » Thu Jan 12, 2017 4:30 pm

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.




Topic author
Ashish Mathew
Registered Member
Posts: 38
Joined: Thu Jun 27, 2013 6:17 pm
Has thanked: 1 time

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

Postby Ashish Mathew » Wed Jan 18, 2017 11:10 am

So can i say, unless a MOVE happens PIC (10) and PIC X(10) are just same? Please suggest.



Online
User avatar

Robert Sample
Global Moderator
Global Moderator
Posts: 1275
Joined: Fri Jun 28, 2013 1:22 am
Location: East Dubuque Illinois
Has thanked: 2 times
Been thanked: 90 times

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

Postby Robert Sample » Wed Jan 18, 2017 3:31 pm

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).




Return to “Interview Questions.”

Who is online

Users browsing this forum: CommonCrawl [Bot] and 0 guests