转换COMP和COMP-3压缩十进制到用C可读价值 [英] Convert COMP and COMP-3 Packed Decimal into readable value with C

查看:368
本文介绍了转换COMP和COMP-3压缩十进制到用C可读价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从大型机到C模块处理的EBCDIC平面文件。有什么可以在转换COMP和COMP-3的值转换为可读取值的好方法?我必须对EBCDIC字符转换为ASCII然后COMP-3六角?怎么样的COMP?谢谢

I have an EBCDIC flat file to be processed from a mainframe into a C module. What can be a good process in converting the COMP and COMP-3 values into readable values? Do I have to convert the ebcdic characters to ascii then hex for COMP-3? What about for COMP? Thanks

推荐答案

伍杰比尔给你一些非常好的建议,通过他的评论是你的问题,其实他回答了这个问题,应该有
发表他的言论作为一个答案。

Bill Woodger has given you some very good advice through his comments to your question, actually he answered the question and should have posted his comments as an answer.

我想重申他的几个点,扩大对其他几个人。

I would like to reiterate a few of his points and expand on a few others.

如果你需要转换创建的文件恐怕是一个COBOL应用程序,它可以被读
通过一些其他非COBOL程序,可能用不同的所述一个在创建它,则一个体系结构的机器上
你应该要求该文件只使用显示格式的数据(即所有字符数据)创建。糖化不显示
在创建它的运行环境外(二进制,压缩,连接codeD)的数据仅仅是一个公式
长期的痛苦。你将受到梳理各种字节序问题的乐趣
架构和 code页面转换之间。这些都是事
文件传输协议被设计来管理 - 他们做得很好,所以不要试图彻底改造他们。简短的回答,使用FTP或
类似的文件传输机制在机器之间移动数据。而且,只有交通显示屏(字符)的数据。

If you need to convert a file created from what is probably a COBOL application so it may be read by some other non-COBOL program, possibly on a machine with an architecture unlike the one where it was created, then you should demand that the file be created using only display formatted data (i.e. all character data). Mashing non-display (binary, packed, encoded) data outside of the operating environment where it was created is just a formula for long term pain. You will be subjected to the joys of sorting out various endianness issues between architectures and code page conversions. These are the things that file transfer protocols are designed to manage - they do it well so don't try to reinvent them. Short answer, use FTP or similar file transport mechanism to move data between machines. And only transport display (character) based data.

盒装十进制(COMP-3)的数据类型占据这取决于它们的具体图像布局不同数量的字节。小数点的位置
是隐含所以不能没有提及用来定义它的图像来确定。压缩十进制字段可以有符号
或无符号。如果签约,标志是在最显著位的低4位嵌入。压缩十进制的每个字节
数据类型包含两个数字,可能除了第一个和最后字节。第一个字节包含仅1位如果该字段被签名
并包含一个偶数个数字。最后一个字节包含2位无符号,如果仅当签订1。还有其他一些subtlies的
你需要知道,如果你想要做自己的压缩十进制字符转换。在这一点上,我希望你能看到
这不会是一件容易的事。

Packed Decimal (COMP-3) data types occupy a varying number of bytes depending on their specific PICTURE layout. The position of the decimal point is implied so cannot be determined without reference to the PICTURE used to define it. Packed Decimal fields may be either signed or unsigned. If signed, the sign is imbedded in the low 4 bits of the least significant digit. Each byte of a Packed Decimal data type contains two digits, except possibly the first and last bytes. The first byte contains only 1 digit if the field is signed and contains an even number of digits. The last byte contains 2 digits if unsigned but only 1 if signed. There are several other subtlies that you need to be aware of if you want to do your own Packed Decimal to character conversions. At this point I hope you can see that this is not going to be a trivial exercise.

二进制(COMP)数据类型有不同,但同样复杂的问题需要解决。同样,不是一件容易的事。

Binary (COMP) data types have a different but no less complex set of issues to resolve. Again, not a trivial exercise.

所以,你应该怎么做?基本上,做比尔建议。有一个生成该文件使用的显示格式的程序
输出(这意味着你必须做什么)。或者,做不到这一点,使用一个实用程序,如DFSORT / Syncsort公司做转换
为你。去效用
路线仍然需要你有原来的COBOL文件格式(和您了解的话),以进行转换。
不得已只是写一个简单的读一个记录,写一个记录COBOL程序,它在未格式化的数据,MOVEes
每个COMP-任何字段添加到相应的显示字段并再次写了出来。

So what should you be doing? Basically, do as Bill suggested. Have the program that generates this file use display formats for output (meaning you have to do nothing). Or, failing that, use a utility program such as DFSORT/SYNCSORT do the conversions for you. Going the utility route still requires that you have the original COBOL file layout (and that you understand it) in order to do the conversion. The last resort is simply writing a simple read-a-record-write-a-record COBOL program that takes in the unformatted data, MOVEes each COMP-whatever field to a corresponding DISPLAY field and write it out again.

由于比尔说,如果生成此文件组告诉你,实在是太难/昂贵的生产格式化的DISPLAY
输出文件的他们是骗你的或的他们是无能的或的只是懒得
做他们被雇用来完成这项工作
的。我能想到的没有其他借口。

As Bill said, if the group that produced this file tells you that it is too difficult/expensive to produce a DISPLAY formatted output file they are lying to you or they are incompetent or just too lazy to do the job they were hired to do. I can think of no other excuses.

这篇关于转换COMP和COMP-3压缩十进制到用C可读价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆