comp-1

Hi all,

We have huge data files with a data field PIC 9(2) defined in the primary key (it is a counter). Until now, there was no need for values > 99. But now we are facing a situation with a need for larger values > 99.

How can we change the data type and keep the original information and record size?

We tried by changing the PIC 9(2) to PIC 9(2) USAGE IS COMP-1 but the original values somehow changed: new_value = old_value 12336 e.g if old_value = 1 then new_value = 12337

Regards

Th.

  • Verified Answer

    PIC 99 is really an abbreviation for PIC 99 USAGE DISPLAY.  The data representation in the two character positions is ASCII, that is, hexadecimal 30-39 for the digits 0-9.  When you change the USAGE to COMP-1, you are seeing the same data interpreted as signed binary.  I would not recommend this approach.

    Assuming you wish to maintain the integrity of the existing counter, so that the first 100 records in the key have values 00-99, then you must use values that create a key value greater than "99" in the alphanumeric sense. The most obvious would be to change the key to PIC XX, and use A-Z, then a-z, as your new digit values.  This would give you a two 'digit' number using a base 62 number system.  (This is much the same way we represent base 16 numbers - hexadecimal - as 0-9A-F.)  As shown, the possible number of counter values is expanded to more than 3800.

    So, how do you "ADD 1" to such a 'number'?  You make a paragraph that you can perform.  Likewise, if you need a numeric value for the 'counter' then you need another paragraph to convert from base 62 to a base 10 number.

    I have typed - but not tested - a possible solution.  (If AcuCOBOL INSPECT statement does not permit a literal as the source operand - as in COMPUTE-KEY-SEQUENCE-VALUE - then merely define a data item PIC X(62) VALUE...).

    Best regards,
    Tom Morrison


    01 my-example pic XX.

    01 my-key-value pic 9(4).

    78 base-62-digits 
          value "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".
    78 base-62-digits-plus-1 
          value "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0".


    ADD-1-TO-KEY.

        inspect my-example (2:1)
            converting base-62-digits
                    to base-62-digits-plus-1.
        if my-example (2:1) equal "0"
            inspect my-example (1:1)
                    converting base-62-digits
                            to base-62-digits-plus-1.
        if my-example (1:1) equal "0"

            *> handle key overflow
            continue.

    COMPUTE-KEY-SEQUENCE-VALUE.
        move 0 to my-key-value.
        inspect base-62-digits
            tallying my-key-value for characters before initial my-example (2:1).
        multiply 62 by my-key-value.
        inspect base-62-digits
            tallying my-key-value for characters before initial my-example (1:1).