Problem:
When executing a write on one specific table MSSQL raises an error "Invalid character value for cast specification" and the program halts with file status 9D,00
Resolution:
The error occurs when the data does not match the database definition for that column. Specifically in this case the problem was due to a file that contained multiple record formats.
To correctly handle multiple record formats add the WHEN directive to the FD to cause the XFD to be generated in a way that the database will recognize multiple record formats. For example, the following file definition has three distinct record formats each identified by a separate WHEN directive:
FD SAMPLEFILE.
$XFD WHEN REC-01-TYPE<5
01 REC-01.
03 REC-01-KEY PIC 9(10).
03 REC-01-TYPE PIC 9.
03 REC-01-DATA-01 PIC 9(5).
03 REC-01-DATA-02 PIC X(45).
$XFD WHEN REC-01-TYPE=5
01 REC-02.
03 REC-02-KEY PIC 9(10).
03 REC-02-TYPE PIC 9.
03 REC-02-DATA-01 PIC 9(5).
03 REC-02-DATA-02 PIC X(2).
03 REC-02-DATA-03 PIC 9(3).
03 REC-02-DATA-04 PIC X(40).
$XFD WHEN REC-01-TYPE=OTHER
01 REC-03.
03 REC-03-KEY PIC 9(10).
03 REC-03-TYPE PIC 9.
03 REC-03-DATA PIC X(50).
In this example when REC-01-TYPE is 0,1, 2, 3, or 4 the first record layout applies, when it is 5 the second record layout applies, and for all other values the third record layout applies.
Refer to Section 5.3.3.13 of the AcuCOBOL-GT User's Guide for complete information on the WHEN directive.



