Page 1 of 1

Moving negative values into unsigned data variable.

Posted: Mon Sep 21, 2015 2:25 pm
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?

Re: Moving negative values into unsigned data variable.

Posted: Mon Sep 21, 2015 3:32 pm
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.