Sorting in JCL or COBOL

87 Views Asked by At

I have an input file that goes like the following :

01 heading of data
inline-data of heading 01
inline-data of heading 01
09 heading of data
inline-data of heading 09
inline-data of heading 09
inline-data of heading 09
inline-data of heading 09
05  heading of data
inline-data of heading 05

Expected output :

01 heading of data
inline-data of heading 01
inline-data of heading 01
05  heading of data
inline-data of heading 05
09 heading of data
inline-data of heading 09
inline-data of heading 09
inline-data of heading 09
inline-data of heading 09
  • My break point in my program is the heading.
  • I need to sort the whole block of data (heading with its inline-data) to manage the lower numbers first.
  • The inline data can vary from 1 to an infinit number of lines
  • There is nothing on inline-data lines that indicates that they belong to a heading or another.

(although I am almost certain that there isn't because I searched), I'd like to know if there a way to do this in either JCL or the program ?

Thank you in advance.

SORT in JCL : sorted the headings separately from data,

Breaking point by program (if numeric, and if not, but cannot store the inline data beucase I don't know how many lines can there be for any given heading) : it requires reading the input file multiple times (hundreds of thousands of lines).

2

There are 2 best solutions below

0
Kolusu On BEST ANSWER

Shecodes,

Look at the DFSORT smart trick "Sort groups of records" which can found be at

https://www.ibm.com/support/pages/smart-dfsort-tricks

In your case assuming that your input has LRECL=80 and RECFM=FB, you can use the following control cards

//SYSIN    DD *                                   
  INREC IFTHEN=(WHEN=GROUP,                       
               BEGIN=(04,08,CH,EQ,C'heading'),    
                PUSH=(81:01,02))                  
                                                  
  SORT FIELDS=(81,02,CH,A),EQUALS                 
                                                  
  OUTREC BUILD=(01,80)                            
/*                              

              

If your input is RECFM=V or VB then you can use the following control cards

//SYSIN    DD *                                  
  INREC IFTHEN=(WHEN=INIT,                       
               BUILD=(01,04,2X,5)),              
        IFTHEN=(WHEN=GROUP,                      
               BEGIN=(10,08,CH,EQ,C'heading'),   
                PUSH=(05:07,02))                 
                                                 
  SORT FIELDS=(05,02,CH,A),EQUALS                
                                                 
  OUTREC BUILD=(01,04,07)                        
/*                                

           
0
Rick Smith On

If the headings are distinguishable, then a three-part key may be used to maintain the order for the inline data within each group while rearranging the heading groups.

Three-part key
  Sequence number for the major group (01 heading)
  Heading level (01, 05, 09)
  Sequence number for the original position in the input file

For each input record:

If 01 heading, increment the sequence number for the major group.

If xx heading, insert the heading number into the heading level.

Increment the sequence number for the original position.

Combine the three-part key and the input record.

Release the combined record to SORT. (Sorting on ASCENDING three-part key.)

After the SORT:

For each RETURN, drop the three-part key and WRITE the remainder of the sorted (original input) record to the output.