转换打包 COBOL

发布于 2024-08-10 23:11:30 字数 308 浏览 1 评论 0原文

我正在尝试通过 C# 应用程序中的 SQL 查询更新 COBOL 打包字段。目前,COBOL 打包字段存储在 MS SQL 数据库的字符列 (char(50)) 中。

COBOL 数据类型 = 4 字节二进制数(“PIC S9(9) COMP”):

我可以使用以下语句来提取数据。我不确定如何逆转此数据更新过程。

CAST(CAST(SUBSTRING({列名},{开始},4) AS VARBINARY(4)) AS BIGINT) AS {Alias_Name}

有什么建议吗?

谢谢,

布伦南·曼

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

八巷 2024-08-17 23:11:30

回答来晚了。但无论如何......这里是:
如果它确实是 PIC S9(9) COMP 而不是 COMP-3,那么它不是一个“险恶”的 COBOL 打包字段,而是一个简单的 4 字节整数!

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!

忘羡 2024-08-17 23:11:30

如果有人需要这个...这是 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);
    }

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);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文