Comp-X behavior

We have a variable defined as Pic X(5) Comp-X. This is able to handle 13 digits, which it does. However, whenever we move this value to a alphanumeric field, which is defined as Pic X(13), the high order digit is dropped and the field contains 12 digits and a space. If we would move the comp-x field to a numeric field, that is defined as Pic 9(13), and then move this to the alphanumeric field it moves all 13 digits correctly. There seems to be a bug in the way that Micofocus moves the comp-x field to alphanumeric. Is there a compile setting that must be used to get the correct behavior?

Parents
  • This is not a bug.  PIC X(5) COMP-X only handles 12 digits fully; because it's binary, it partially handles the thirteenth digit, but cannot handle a number 9999999999999 (13 nines).  Its maximum value is 1099511627775 (a 12-digit number) with the value h"FFFFFFFFFF" (10 hex-digits).  Thus the compiler assigns a digit-length of 12.

    In the latest versions of Visual COBOL, what you want could be described as Pic 9(13) Binary(5).  This describes a 13-digit item in a 5-byte binary item.  Moves using this as a sending item will move a 13-digit number to an alphanumeric item.  As described above, the 13-digit item cannot contain a value greater than 1099511627775, that is, not all 13-digit values are possible.

    This sample program:

          01 Digits12      PIC X(5) COMP-X VALUE 1099511627775.

          01 Digits13      PIC 9(13) BINARY(5) VALUE 1099511627775.

          01 Alpha13       PIC X(13).

              move digits12 to alpha13.

              display "alpha13 from digits12 = """ alpha13 """".

              move digits13 to alpha13.

              display "alpha13 from digits13 = """ alpha13 """".

    when run, displays:

           alpha13 from digits12 = "099511627775 "

           alpha13 from digits13 = "1099511627775"

Reply
  • This is not a bug.  PIC X(5) COMP-X only handles 12 digits fully; because it's binary, it partially handles the thirteenth digit, but cannot handle a number 9999999999999 (13 nines).  Its maximum value is 1099511627775 (a 12-digit number) with the value h"FFFFFFFFFF" (10 hex-digits).  Thus the compiler assigns a digit-length of 12.

    In the latest versions of Visual COBOL, what you want could be described as Pic 9(13) Binary(5).  This describes a 13-digit item in a 5-byte binary item.  Moves using this as a sending item will move a 13-digit number to an alphanumeric item.  As described above, the 13-digit item cannot contain a value greater than 1099511627775, that is, not all 13-digit values are possible.

    This sample program:

          01 Digits12      PIC X(5) COMP-X VALUE 1099511627775.

          01 Digits13      PIC 9(13) BINARY(5) VALUE 1099511627775.

          01 Alpha13       PIC X(13).

              move digits12 to alpha13.

              display "alpha13 from digits12 = """ alpha13 """".

              move digits13 to alpha13.

              display "alpha13 from digits13 = """ alpha13 """".

    when run, displays:

           alpha13 from digits12 = "099511627775 "

           alpha13 from digits13 = "1099511627775"

Children
No Data