Search code examples
c#sqlcobol

Converting Packed COBOL


I am trying to update a COBOL packed field via a SQL query in a C# application. Currently, the COBOL packed field is being stored in a character column (char(50)) in a MS SQL database.

COBOL Data Type = 4 Byte binary number (“PIC S9(9) COMP”):

I can use the following statement to extract the data. I am not sure on how to reverse this processes for data updates.

CAST(CAST(SUBSTRING({Column Name},{Start},4) AS VARBINARY(4)) AS BIGINT) AS {Alias_Name}

Any suggestions?

Thanks,

Brennan Mann


Solution

  • Answer coming late. But anyway ... here goes: If it's indeed PIC S9(9) COMP and not COMP-3 then it's not a 'sinister' COBOL packed field but a simple 4 byte integer!