I am trying to convert Number to PACKED DEMCIMAL, from web research number 123 will be 123D (C if negative number) as packed number, My question is "is this a correct PACKED DECIMAL?" because requirement that I have states, date will be stored in 3-byte packed number and length is only 2 digits.

Please explain or clear my doubt.

有帮助吗?

解决方案

You have it backwards.

A positive packed decimal ends in a C. A negative packed decimal ends in a D. An unsigned packed decimal, assumed to be positive, ends in an F.

A 3 byte packed number contains 5 digits and a sign. PIC S9(5) COMP-3 is 3 bytes.

I'm not sure what format your date is, if it's only five digits.

其他提示

PIC S999 or S9(3) PACKED-DECIMAL or COMP-3 occupies two bytes of storage. This has a sign.

PIC 999 or 9(3) occupies two bytes of storage, and the sign is "F", to indicate unsigned, which is always treated as positive.

Each digit occupies half a byte, with half a byte for the "sign" - as Gilbert says, C is positive, D is negative.

You have tagged Java and VBScript. Are you trying to so the conversion "outside" Cobol to present it to a Cobol program? If so, it would be much easier to present the data as "plain text" with a "separate" sign. Saves you having to mess about. The "type conversion" is automatic in Cobol, it makes much more sense to give everything to the program in "plain text" and let the Cobol get on with it.

Same with anything that has decimal places. Give a "scaling factor" or a physical decimal point. You'll save yourself time, not waste any time for the Cobol programmer, and have a nice means of creating test data for yourselves - an editor.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top