Moving negative values into unsigned data variable.

All sort of Mainframes Interview Questions.
Post Reply
Technocrat
Registered Member
Posts: 31
Joined: Thu Oct 03, 2013 1:32 pm

Moving negative values into unsigned data variable.

Post by Technocrat »

Hi,

One of the filed is defined as PIC 9(4) in the program. If input file has got negative values for this variable, what the program will receive? Will program just take the value and ignores the sign OR interpretes into some other value?

I was not able to answer the question well. I think move will be fine but it'll move in the absolute value of the sending field. Can there be some erroror warning by compiler? Or is there a way we can receive the value with sign?
Regards
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Moving negative values into unsigned data variable.

Post by William Collins »

If you MOVE a signed value to an unsigned numeric field, you will simply get the absolute value as you suspect. The is no compiler diagnostic for this.

You could get an actual sign into an unsigned field using REDEFINES. This would be a bad idea. If using NUMPROC(PFD) you could get unexpected results (using PFD, all your data should conform to PICture). Using NOPFD your program would produce expected results, although it would take longer to do so. You'd also risk a mixture of equivalent values (signed and unsigned) being SORTed upon, with unexpected results. So, it can be done, manually, and it is a bad idea.
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.”