Brennan Mann
Brennan Mann

Reputation: 1537

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

Upvotes: 2

Views: 1116

Answers (2)

Brennan Mann
Brennan Mann

Reputation: 1537

In case anyone needs this... This was the solution with C#

 public string ConvertToFourByteBinaryNumber(Int32 value)
    {
        byte[] intBytes = BitConverter.GetBytes(value);

        Array.Reverse(intBytes); // IsLittleEndian

        return Encoding.Default.GetString(intBytes);
    }

    public string ConvertToEightByteBinaryNumber(long value)
    {
        byte[] intBytes = BitConverter.GetBytes(value);

        Array.Reverse(intBytes); // IsLittleEndian

        return Encoding.Default.GetString(intBytes);
    }

Upvotes: 0

HaWe
HaWe

Reputation: 26

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!

Upvotes: 1

Related Questions