[an error occurred while processing this directive]

HP OpenVMS Systems

ask the wizard
Content starts here

COBOL conversion syntax quiz!

» close window

The Question is:

 
In COBOL, when an '*' is moved to a pic 9 field what conversion is done and
what value is now in that pic 9 field?
 
 


The Answer is :

identification division.
program-id. w3688.
environment division.
data division.
working-storage section.
01 w1.
02  w2 pic 9 value 5.
01 w3  pic 9 value 6.
procedure division.
p0.	move '*' to w1.
	display w2 with conversion.
	move '*' to w3.
	display w3 with conversion.
	stop run.
 
    From a syntax perspective, you can do a straightforward move to the pic
    9 field, and the Compaq COBOL compilers on VAX and Alpha will diagnose
    the invalid move at compile time (move to w3).  However, many
    programmers use a backdoor approach (move to w1) for many different
    reasons.  The bottom line is that '*' is invalid decimal data, and the
    results with invalid decimal data are undefined.  The undefined results
    are not 100% consistent between VAX and Alpha.  In some cases the VAX
    hardware does invalid decimal data checking at run time.  We added
    /CHECK=DECIMAL on Alpha to handle some of these cases, but the
    operation of /CHECK=DECIMAL on Alpha is not 100% compatible with VAX
    hardware.  Note that /CHECK=DECIMAL on Alpha operates when the invalid
    data is actually used (display with conversion) and not during the
    move.
 
    Compaq COBOL for OpenVMS VAX
    ------------------------------
$ cobol w3688
   12             move '*' to w3.
                  1
%COBOL-E-ERROR  135, (1) Invalid character in nonnumeric literal moved to numeric item
%COBOL-E-ENDDIAGS, COB$USER2:[BRAFFITT.WORK]W3688.COB;1 completed with 1 diagnostic
$ link  w3688
%LINK-W-WRNERS, compilation warnings
    in module W3688 file COB$USER2:[BRAFFITT.WORK]W3688.OBJ;1
$ run   w3688
 
 
 
    Compaq COBOL for OpenVMS Alpha
    ------------------------------
$ cobol w3688
 
	move '*' to w3.
.............^
%COBOL-E-INVCHAR, Invalid character in nonnumeric literal moved to numeric item
at line number 12 in file COB$USER2:[BRAFFITT.WORK]W3688.COB;1
%COBOL-E-ENDDIAGS, COB$USER2:[BRAFFITT.WORK]W3688.COB;1 completed with 1 diagnostic
$ link  w3688
$ run   w3688
 
 
$ cobol w3688/check=decimal
	move '*' to w3.
.............^
%COBOL-E-INVCHAR, Invalid character in nonnumeric literal moved to numeric item
at line number 12 in file COB$USER2:[BRAFFITT.WORK]W3688.COB;1
%COBOL-E-ENDDIAGS, COB$USER2:[BRAFFITT.WORK]W3688.COB;1 completed with 1 diagnostic
$ link  w3688
$ run   w3688
%SYSTEM-F-DECINV, decimal invalid operand, PC=00000000000301D4, PS=0000001B
%TRACE-F-TRACEBACK, symbolic stack dump follows
  image    module    routine             line      rel PC           abs PC
 W3688  W3688  W3688                       11 00000000000001D4 00000000000301D4

answer written or last revised on ( 30-JAN-2000 )

» close window