Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
prolinkdata_gr Trusted Contributor.
Trusted Contributor.
1122 views

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.

0 Likes
1 Solution

Accepted Solutions
Knowledge Partner
Knowledge Partner

RE: comp-1

Jump to solution

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).


Tom Morrison
Consultant

View solution in original post

0 Likes
2 Replies
Knowledge Partner
Knowledge Partner

RE: comp-1

Jump to solution

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).


Tom Morrison
Consultant

View solution in original post

0 Likes
prolinkdata_gr Trusted Contributor.
Trusted Contributor.

RE: comp-1

Jump to solution

seems it's a good approach, thank you!

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.