Created On:  03 February 2012

Problem:

Customer is migrating from a Unisys mainframe to Net Express 5.1 using SQL Server 2008 database.

On mainframe they had a table with a column defined as CHAR(30) into which they stored a string of data that included a COBOL COMP data type.

They redefined the host variable in their program as follows:

01 char-field.
     05  num-field       pic 9(6)   comp.
     05  x-field           pic x(20).
     05  x-field2         pic x(7).

and before inserting the columns into the database they would initialize the num-field to a numeric value starting with 1 and incrementing by 1 for each row.

The INSERT worked fine and sqlcode was 0.

When they fetched the data back into the program, however the value in the num-field was always = 105376.

This worked correctly on the mainframe.
Why does it have this behavior in Net Express?

Resolution:

SQL Server CHAR type fields only allow for displayable ASCII character type data in them so when any binary value that resulted in a non-displayable character existed during the insert the field was converted to spaces.

This is the value that was seen after fetching the data back into the program.
105376 is the decimal value for the hex bytes 20 20 20 which are ASCII spaces.

To resolve this issue the SQL Server column type should be BINARY(30) instead of CHAR(30) as this allows for any string of bytes to be inserted into the column.

Incident #2561913