Question

I am working on my first project with Cobol Sort VSAM files. I ran into a keyword RELEASE.

The way the book read that I have is the "The release statement transfers records from the INPUT PROCEDURE to the input Phase of the sort operation.

My Question is: That takes what ever I have in my Sort-Rec (or whatever I called it) and sends it directly into the OUTPUT PROCEDURE part of my SORT?

Seems confusing to me here.

Cobol Code:

SORT SORT-FILE ASCENDING KEY SORT-PROVIDER       
  INPUT  PROCEDURE IS PROC-THE-REC  THRU PTR-X   
  OUTPUT PROCEDURE IS WRITE-THE-RPT THRU WTR-X.  

 MOVE CC-CERT-NO         TO SAVE-CERT-NO.         
 MOVE CC-CERT-STATUS     TO SAVE-CERT-STATUS.     
 MOVE CC-CERT-BEGIN-DATE TO SAVE-CERT-BEGIN-DATE. 
 MOVE CC-CERT-END-DATE   TO SAVE-CERT-END-DATE.   
 MOVE CC-CERT-FUNDING    TO SAVE-CERT-FUNDING.    
 MOVE CC-PROV-NUMB       TO SAVE-PROV-NUMB.       
 MOVE CC-PROV-RES-CNTY   TO SAVE-PROV-RES-CNTY.   
 MOVE CC-PROV-TYPE       TO SAVE-PROV-TYPE.       
 MOVE CC-WORKER-USERID   TO SAVE-WORKER-USERID.   
 MOVE CC-WORKER-NAME     TO SAVE-WORKER-NAME.     

 RELEASE SORT-REC.                                
Was it helpful?

Solution

Following from Bill,

When using a sort in Cobol is a bit like having two or three separate programs in the one program.

 Pre-Sort  (PROC-THE-REC in your case)
    |
    V
   Sort
    |
    V
 Post sort (WRITE-THE-RPT in your case)

The RELEASE statement "Writes" a record to the "Sort" step.

In Unix you could achieve the same thing by

  • writing 2 separate programs (Pre and post sort)
  • Replacing the Release with Writes
  • piping the output from the Pre-Sort to the sort.

On the mainframe you would use 3 JCL steps and temporary files.


On the mainframe, most sites I worked at discourage (ban) the use of the Cobol sort verb and you would write 2 programs and use the utility sort.

OTHER TIPS

The release statement transfers records from the INPUT PROCEDURE to the input Phase of the sort operation.

The input Phase of a sort is where SORT gets its data from, in this case.

COBOL Program
 Loop-construct 
  Some COBOL code
  Release
  Next

The sort is actually an external program. In the case of the Mainframe, 
it is the installed SORT product (usually DFSORT or SyncSort)
   Input Phase of SORT
   SORT
   Output Phase of SORT

 Another-Loop-construct 
  Some COBOL code
  Return
  Next
COBOL Program

Your input procedure will process, release, and then continue. When all data has been released, the sort will take place. The sorted records will be presented back to your program at the point of the RETURN statement you will have coded, and this will continue (return, stuff after return, another return, repeat until finished) until all the sorted file is processed (assuming that nothing goes wrong an you want to stop early).

normally, COBOL sort procedures are :

SORT SORTFILE ON SORT-ID, SORT-NAME, SORT-PHONE

 INPUT PROCEDURE IS READ-IN
 OUTPUT PROCEDURE IS PRINT-SORTED.

READ-IN SECTION.

 loop:

  READ INPUTFILE.
  MOVE IN-ID TO SORT-ID.
  MOVE IN-NAME TO SORT-NAME.
  MOVE IN-PHONE TO SORT-PHONE.
  RELEASE SORT-REC.

PRINT-SORTED SECTION.

 loop:

  RETURN SORT-REC.
  DISPLAY "id#: " SORT-ID.
  DISPLAY "Name: " SORT-NAME.
  DISPLAY "Phone: " SORT-PHONE.

An INPUT PROCEDURE supplies records to the sort process by writing them to the work file declared in the SORT's SD entry. But to write the records to the work file a special verb - the RELEASE verb is used.

An operational template for an INPUT PROCEDURE, which gets records from and input file and RELEASEs them to the work file, is shown below.

OPEN INPUT InFileName
READ InFileName
PERFORM UNTIL TerminatingCondition
  Process input record to create SDWorkRec
  RELEASE SDWorkRec
  READ InFileName
END-PERFORM 
CLOSE InFileName

For further details on the SORT see my tutorial at http://www.csis.ul.ie/cobol/course/SortMerge.htm

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top