Static Call

Simple Program

STATIC CALL: Main Program

STATIC CALL: Compile JCL

STATIC CALL: RUN JCL

Dynamic call :Sub Program .

Dynamic Call : Main Program .

Dynamic Call Main Pgm Compile JCL .

DYNAMIC CALL MAIN PROGRAM RUN JCL .

Instead of a STOP RUN statement. Entries in the LINKAGE SECTION can be in any order.Rules for coding CALLed programs The called program needs to have a LINKAGE SECTION. the called program must contain an EXIT PROGRAM statement to transfer control back to the calling program. but the entries in the USING clause must be in the order of their usage in the CALL statement of the CALLing program. The PROCEDURE DIVISION needs to have a USING clause. This must appear after the WORKING-STORAGE SECTION in the DATA DIVISION. . This identifies the variables passed to the program and their ordering.

SORTING AND MERGING DATA FILES Overview .

 Sorting is a common procedure used for arranging records into a specific order so that sequential processing can be performed. Querying or Generating Reports.COBOL Sorting  Records in files must be sorted into specific sequences for Updating.  Sorting is done on the basis of a key field numeric or non numeric .

When more than one SortKeyIdentifier is specified. the keys decrease in significance from left to right (leftmost key is most significant. These files are automatically opened by the SORT. When the SORT executes they must not be already open. It is defined in the FILE SECTION using an SD entry. ASCENDING ¾ ® ® ¾ SORT WorkFileName ¯ON ¯ KEY _SortKeyIdentifiera . Each SortKeyIdentifier identifies a field in the record of the work file upon which the file will be sequenced. InFileName and OutFileName. are the names of the input and output files.¿ ¿ DESCENDINGÀ ° ° À USING _InFileNamea GIVING _OutFileNamea -  The WorkFileName identifies a temporary work file that the SORT process uses for the sort. rightmost is least significant).Simplified Sort Syntax.    .

02 SalesmanNum PIC 9(5). 02 QtySold PIC 9(4). 02 02 SD 01 salesmanno FILLER pic x(5) PIC X(5). SORT WorkFile ON ASCENDING KEY WSalesmanNum USING SalesFile GIVING SortedSalesFile. . FD 01 SalesFile.Sort Example. PROCEDURE DIVISION. WorkRec. 02 WSalesmanNum 02 FILLER PIC 9(5). Begin. SortedSalesRec. 02 ItemType PIC X. SalesRec. PIC X(5). WorkFile. FD 01 SortedSalesFile.

How the SORT works. . SalesFile SortedSalesFile Unsorted Records Sorted Records SORT Process WorkFile SORT WorkFile ON ASCENDING KEY WSalesmanNum USING SalesFile GIVING SortedSalesFile.

INPUT FILE .

OUTPUT File .

SIMPLE SORT PROGRAM .

SIMPLE SORT PROGRAM .

RUN JCL .

SIMPLE SORT OUTPUT .

COMPLEX SORT Overview .

.How the INPUT PROCEDURE works. SalesFile SortedSalesFile Unsorted Records Unsorted Hat Records Sorted Records SORT Process SelectHatSales WorkFile SORT WorkFile ON ASCENDING KEY WSalesmanNum INPUT PROCEDURE IS SelectHatSales GIVING SortedSalesFile.

INPUT PROCEDURE Template OPEN INPUT InFileName READ InFileName RECORD PERFORM UNTIL Condition RELEASE SDWorkRec READ InFileName RECORD END-PERFORM CLOSE InFile .

In the paragraph check-valid-para :     Open input file. SORT WorkFile ON ASCENDING KEY WSalesmanNum INPUT PROCEDURE IS SelectHatSales GIVING SortedSalesFile. Check for validity Release the record Close the file After that control is passed to SORT. .g.COBOL SORT Input Procedure e.

It is similar to writing a record to the sort file. The format of RELEASE is : RELEASE Sort-record-name-1 [ FROM Identifier-1 ]  . processes input records and releases them into the sort file.COBOL SORT Release  The input procedure opens the input file.

Complex Sort :INPUT FILE .

COMPLEX SORT:INPUT PROCEDURE .

COMPLEX SORT:INPUT PROCEDURE .

COMPLEX SORT: INPUT PROCEDURE .

COMPLEX SORT:RUN JCL .

COMPLEX SORT : OUTPUT FILE .

COMPLEX SORT : Input File .

COBOL SORT: OUTPUT PROCEDURE .

Instead of giving option an output procedure can be used.COBOL  SORT Output Procedure In case of sort if the giving option is used. then the sorted records are automatically written onto the out-file after they are used.   . In an output procedure we RETURN records from the sort file rather than READING them. In an input procedure we RELEASE records to a sort file rather than WRITING them.

SORT WORK-FILE e. USING IN-FILE OUTPUT PROCEDURE CHECK-PARA. .  Close the file. STOP RUN.  In the paragraph CHECK-PARA:  Open output file.g.COBOL SORT Output Procedure MAIN-PARA.  Process records before writing to Out-file.  Return records from sort file.

PERFORM PROCESS-PARA UNTIL NO-MORE-RECORDS = NO CLOSE OUTPUT-FILE.COBOL SORT Typical Program MAIN-PARA.02 TO DISCOUNT ELSE MOVE 0. RETURN SORT-FILE AT END MOVE NO TO NO-MORE-RECORDS. . IF AMT-OF-PURCHASE > 6000 MOVE 0. CALC-PARA. WRITE OUT-REC FROM SORT-REC. PROCESS-PARA. OPEN OUTPUT OUTPUT-FILE.00 TO DISCOUNT END-IF. STOP RUN. SORT SORT-FILE ON ASCENDING KEY TRANS-NO USING INPUT-FILE OUTPUT PROCEDURE CALC-PARA.

COMPLEX SORT: Output Procedure .

Complex Sort : Output Procedure .

COMPLEX SORT : OUTPUT PROCEDURE .

COMPLEX SORT : RUN JCL .

COMPLEX SORT: OUTPUT DATA .

  . closing. The files to be merged must be in sequence by the key-field (ascending or descending).COBOL  Merge COBOL has a MERGE statement that will combine two or more files into a single file. The MERGE statement automatically handles the opening. and any I-O (read/write functions) associated with the files.

. KEY data -1} . . OUTPUT PROCEDURE IS proc-1 GIVING {file-4}.COBOL Merge Merge syntax MERGE file-1 { ON ASCENDING DESCENDING USING file-2 { file-3 } .

COBOL FILE CONTROL. FD 01 FD 01 SD 01 IN-FILE1. MERGE M-FILE ON ASCENDING KEY KEY-FIELD USING IN-FILE1. 05 KEY-FIELD 05 REST-OF REC FD 01 OUT-FILE. Merge Typical Program ASSIGN TO E-FILE1. PIC X(100). MAIN-PARA. ASSIGN TO WORK. M-REC. ASSIGN TO E-FILE2. IN-REC2 M-FILE. PROCEDURE DIVISION. OUT-REC PIC X(100). ASSIGN TO E-FILE. SELECT IN-FILE1 SELECT IN-FILE2 SELECT M-FILE SELECT OUT-FILE DATA DIVISION. IN-FILE2 GIVING OUT-FILE STOP RUN . PIC X(100). PIC X(5). PIC X(100). IN-REC1 IN-FILE2.

MERGE EXAMPLE Overview .

COBOL Sort & Merge Summary    SORT is used for sorting records in either ascending or descending order Processing of records can be carried out before or after sorting by using Input or Output procedures or using both Merge is used to merge two or more files .