Given following code:
VAR X PIC S9(7)V9(2).
VAR Y PIC X(15)
Following code having compile error.
MOVE X TO Y. * compile error.
the error message is something like this “cannot move non-integer numbers to alphanumeric variable”
is there any way to fix this issue without making use of another variables (e.g. display vars) ?
The fix sometimes involves REDEFINES as in:
Notice that
Xoccupies less storage thanYsoXcanREDEFINE Ybut not the other way round. Since bothXandYnow occupy the same physical storage, theMOVEcan be dropped as the following program and output illustrate:Output:
As you can quickly see, the result is probably not what you were hoping for since
Ydoes not contain a human readable formatted number (i.e. one with a leading sign and a decimal point).So my advice to you is don’t try bend COBOL into something that it is not. Use the language as it was intended to be used. What you probably need to do is something along the lines of:
Which outputs:
Yes, the above program uses an additional variable in the middle to convert numeric format to display format, but that is exactly how the language was designed. Long winded but very straight forward. At the end of the exercise variable
Ycontains something that is readable and makes sense to the normal human eye.