Highlighted
Absent Member.
Absent Member.
2340 views

Indexed file key > 250 bytes

Jump to solution

What would be the best way to sort an indexed file with a composite key that is > 250 bytes. 

Composite key : 

 02 SRTKEY.
      05 SRTIND             PIC 9.
      05 SRTACC           PIC X(350).
      05 SRTCONTRA   PIC X(350).
      05 SRTCNT           PIC 9(8). |KEEP KEY UNIQUE

Any input would be appreciated.

Thanks.

0 Likes
1 Solution

Accepted Solutions
Highlighted
Knowledge Partner
Knowledge Partner

RE: Indexed file key > 250 bytes

Jump to solution

If SRTCONTRA is used to obtain a reverse ordering, that can be achieved using START LESS THAN and READ PREVIOUS.  So lets presume that rids you of 350 characters.

Can I also presume that the X(350) field is that long because it has subfields?  For example:

       03  my-key.
           05  my-key-1 pic x(20).
           05  my-key-2 pic x(100).
           05  my-key-3 pic x(100).
           05  my-key-4 pic x(130).

You can use SORT to achieve the desired results.  Define your indexed file key to contain as many fields as you can get into 250 characters, then use SORT with INPUT and OUTPUT procedures to sort those fields that do not fit into 250 characters.  The limit on a SORT key is 32767.  Since the data will be partially sorted due to the indexed file key, the SORT should be quite efficient.  (In fact, if this is a temporary indexed file, I would simply not use an indexed file and use SORT for the entire process.  It very well might be faster.)

If these subfields typically have trailing spaces, then you can effectively compress the information using STRING:

           MOVE LOW-VALUES TO SRTACC.
           STRING my-key-1 delimited by "    "
                  LOW-VALUE delimited size
                  my-key-2 delimited by "    "
                  LOW-VALUE delimited size
                  my-key-3 delimited by "    "
                  LOW-VALUE delimited size
                  my-key-4 delimited by "    "
               into SRTACC

This key value should allow you to determine control breaks.  The LOW-VALUE serves as a proxy for trailing spaces in the subfields in the sorting process and you can UNSTRING the SRTACC value delimited by ALL LOW-VALUE to recover the subfields with trailing spaces.

If your PIC X(350) item contains only printable characters, or better even 0-9, A-Z and space, then you can compress the data by using an encoding scheme that uses fewer bits per character.  For example, 64 characters can be represented by 6 bits.  Unfortunately this will not fit 350 characters into 250 octets.

Knowing more about the actual data you are trying to accommodate would help with other possibilities.

Tom Morrison
Hill Country Software


Tom Morrison
Consultant

View solution in original post

0 Likes
4 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Indexed file key > 250 bytes

Jump to solution

Hi, as this is an index file you can in COBOL do a start, start > or a start < so you can order the file anyway you would like. Perhaps I am misunderstanding your question. Tell us what you are trying to accomplish and we can help you from there.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Indexed file key > 250 bytes

Jump to solution

Hi Shjerpe,

thanks for the reply. I want to create a temporary file from different data sources and this temp file must have a certain key(srtkey in my example) to enable me to determine breaks points as I read through the file. My problem is that the key I want to declare  will be > 250 bytes and the maximum size for an indexed file key is 250 bytes and this results in a compile error.    

As far as I know, I have to specify a key to start a file in a certain ordered sequence -  start srt-file key not < srtkey to start at the beginning, after low values was moved to the key. Naturally, srtkey will have to be defined in the select as either a primary or alternate key.

Thanks.

0 Likes
Highlighted
Knowledge Partner
Knowledge Partner

RE: Indexed file key > 250 bytes

Jump to solution

If SRTCONTRA is used to obtain a reverse ordering, that can be achieved using START LESS THAN and READ PREVIOUS.  So lets presume that rids you of 350 characters.

Can I also presume that the X(350) field is that long because it has subfields?  For example:

       03  my-key.
           05  my-key-1 pic x(20).
           05  my-key-2 pic x(100).
           05  my-key-3 pic x(100).
           05  my-key-4 pic x(130).

You can use SORT to achieve the desired results.  Define your indexed file key to contain as many fields as you can get into 250 characters, then use SORT with INPUT and OUTPUT procedures to sort those fields that do not fit into 250 characters.  The limit on a SORT key is 32767.  Since the data will be partially sorted due to the indexed file key, the SORT should be quite efficient.  (In fact, if this is a temporary indexed file, I would simply not use an indexed file and use SORT for the entire process.  It very well might be faster.)

If these subfields typically have trailing spaces, then you can effectively compress the information using STRING:

           MOVE LOW-VALUES TO SRTACC.
           STRING my-key-1 delimited by "    "
                  LOW-VALUE delimited size
                  my-key-2 delimited by "    "
                  LOW-VALUE delimited size
                  my-key-3 delimited by "    "
                  LOW-VALUE delimited size
                  my-key-4 delimited by "    "
               into SRTACC

This key value should allow you to determine control breaks.  The LOW-VALUE serves as a proxy for trailing spaces in the subfields in the sorting process and you can UNSTRING the SRTACC value delimited by ALL LOW-VALUE to recover the subfields with trailing spaces.

If your PIC X(350) item contains only printable characters, or better even 0-9, A-Z and space, then you can compress the data by using an encoding scheme that uses fewer bits per character.  For example, 64 characters can be represented by 6 bits.  Unfortunately this will not fit 350 characters into 250 octets.

Knowing more about the actual data you are trying to accommodate would help with other possibilities.

Tom Morrison
Hill Country Software


Tom Morrison
Consultant

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Indexed file key > 250 bytes

Jump to solution

The 250 byte key size limit should only apply to the indexed file FD, not the SD.  Try using the usual FD for the indexed file, and then specifying your large SORT key in the SD.  Then SORT USING the indexed file on the large key, GIVING your temporary file.  You may also find acusort useful.

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.