Call Slides

download Call Slides

of 46

Transcript of Call Slides

  • 8/7/2019 Call Slides

    1/46

    Static Call Simple Program

  • 8/7/2019 Call Slides

    2/46

    STATIC CALL: Main Program

  • 8/7/2019 Call Slides

    3/46

    STATIC CALL: Compile JCL

  • 8/7/2019 Call Slides

    4/46

    STATIC CALL: RUN JCL

  • 8/7/2019 Call Slides

    5/46

    Dynamic call :Sub Program

  • 8/7/2019 Call Slides

    6/46

    Dynamic Call : Main Program

  • 8/7/2019 Call Slides

    7/46

    Dynamic Call Main Pgm Compile JCL

  • 8/7/2019 Call Slides

    8/46

    DYNAMIC CALL MAIN PROGRAM RUN JCL

  • 8/7/2019 Call Slides

    9/46

    Rules for coding CALLed programs

    The called program needs to have a LINKAGE SECTION. This must appear after

    the WORKING-STORAGE SECTION in the DATA DIVISION.

    The PROCEDURE DIVISION needs to have a USING clause. This identifies the

    variables passed to the program and their ordering.

    Entries in the LINKAGE SECTION can be in any order, but the entries in the

    USING clause must be in the order of their usage in the CALL statement of

    the CALLing program.

    Instead of a STOP RUN statement, the called program must contain an EXIT

    PROGRAM statement to transfer control back to the calling program.

  • 8/7/2019 Call Slides

    10/46

    SORTING AND MERGING

    DATA FILES

    Overview

  • 8/7/2019 Call Slides

    11/46

    COBOL Sorting

    Records in files must be sorted into specific sequences for Updating,

    Querying or Generating Reports.

    Sorting is a common procedure used for arranging records into a

    specific order so that sequential processing can be performed.

    Sorting is done on the basis of a key field numeric or non numeric

  • 8/7/2019 Call Slides

    12/46

    Simplified Sort Syntax.

    The WorkFileName identifies a temporary work file that the SORT

    process uses for the sort. It is defined in the FILE SECTION using an SD

    entry.

    Each SortKeyIdentifier identifies a field in the record of the work file

    upon which the file will be sequenced.

    When more than one SortKeyIdentifier is specified, the keys decrease in

    significance from left to right (leftmost key is most significant, rightmost

    is least significant).

    InFileName and OutFileName, are the names of the input and output

    files. These files are automatically opened by the SORT. When the SORTexecutes they must not be already open.

    _ a

    _ a_ a

    SORT

    USING

    GIVING

    WorkFileName ONASCENDING

    DESCENDINGKEY SortKeyIdentifier

    InFileName

    OutFileName

    - -

    -

    -

  • 8/7/2019 Call Slides

    13/46

    FD SalesFile.

    01 SalesRec.

    02 salesmanno pic x(5)

    02 FILLER PIC X(5).

    SD WorkFile.

    01 WorkRec.

    02 WSalesmanNum PIC 9(5).02 FILLER PIC X(5).

    FD SortedSalesFile.

    01 SortedSalesRec.

    02 SalesmanNum PIC 9(5).

    02 ItemType PIC X.

    02 QtySold PIC 9(4).

    PROCEDURE DIVISION.

    Begin.

    SORT WorkFile ON ASCENDING KEY WSalesmanNum

    USING SalesFile

    GIVING SortedSalesFile.

    Sort Example.

  • 8/7/2019 Call Slides

    14/46

    SORTSORT

    ProcessProcess

    WorkFileWorkFile

    How the SORT works.

    SORT WorkFile ON ASCENDING KEY WSalesmanNum

    USING SalesFile

    GIVING SortedSalesFile.

    SalesFileSalesFile SortedSalesFileSortedSalesFile

    Unsorted

    Records

    Sorted

    Records

  • 8/7/2019 Call Slides

    15/46

    INPUT FILE

  • 8/7/2019 Call Slides

    16/46

    OUTPUT File

  • 8/7/2019 Call Slides

    17/46

    SIMPLE SORT PROGRAM

  • 8/7/2019 Call Slides

    18/46

    SIMPLE SORT PROGRAM

  • 8/7/2019 Call Slides

    19/46

    RUN JCL

  • 8/7/2019 Call Slides

    20/46

    SIMPLE SORT OUTPUT

  • 8/7/2019 Call Slides

    21/46

  • 8/7/2019 Call Slides

    22/46

    SORTSORT

    ProcessProcess

    How the INPUT PROCEDURE works.

    SORT WorkFile ON ASCENDING KEY WSalesmanNum

    INPUT PROCEDURE IS SelectHatSales

    GIVING SortedSalesFile.

    WorkFileWorkFile

    SalesFileSalesFile SortedSalesFileSortedSalesFile

    Sorted

    Records

    SelectHatSalesSelectHatSales

    Unsorted

    Hat

    Records

    Unsorted

    Records

  • 8/7/2019 Call Slides

    23/46

    OPEN INPUT InFileName

    READ InFileName RECORD

    PERFORM UNTIL ConditionRELEASE SDWorkRec

    READ InFileName RECORD

    END-PERFORM

    CLOSE InFile

    INPUT PROCEDURE Template

  • 8/7/2019 Call Slides

    24/46

  • 8/7/2019 Call Slides

    25/46

    COBOL SORT Release

    The input procedure opens the input file, processes input recordsand releases them into the sort file. It is similar to writing arecord to the sort file.

    The format of RELEASE is :

    RELEASE Sort-record-name-1

    [ FROM Identifier-1 ]

  • 8/7/2019 Call Slides

    26/46

  • 8/7/2019 Call Slides

    27/46

    COMPLEX SORT:INPUT PROCEDURE

  • 8/7/2019 Call Slides

    28/46

    COMPLEX SORT:INPUT PROCEDURE

  • 8/7/2019 Call Slides

    29/46

    COMPLEX SORT: INPUT PROCEDURE

  • 8/7/2019 Call Slides

    30/46

    COMPLEX SORT:RUN JCL

  • 8/7/2019 Call Slides

    31/46

    COMPLEX SORT : OUTPUT FILE

  • 8/7/2019 Call Slides

    32/46

    COMPLEX SORT : Input File

  • 8/7/2019 Call Slides

    33/46

    COBOL SORT: OUTPUT

    PROCEDURE

  • 8/7/2019 Call Slides

    34/46

    COBOL SORT Output Procedure

    In case of sort if the giving option is used, then the sorted records areautomatically written onto the out-file after they are used.

    Instead of giving option an output procedure can be used.

    In an input procedure we RELEASE records to a sort file rather than WRITINGthem. In an output procedure we RETURN records from the sort file ratherthan READING them.

  • 8/7/2019 Call Slides

    35/46

    COBOL SORTOutput Procedure e.g.

    MAIN-PARA.

    SORT WORK-FILE

    USING IN-FILE

    OUTPUT PROCEDURE CHECK-PARA.

    STOP RUN.

    In the paragraph CHECK-PARA:

    Open output file.

    Return records from sort file. Process records before writing to Out-file.

    Close the file.

  • 8/7/2019 Call Slides

    36/46

    COBOL SORTTypical Program

    MAIN-PARA.

    SORT SORT-FILE ON ASCENDING KEY TRANS-NO

    USING INPUT-FILE

    OUTPUT PROCEDURE CALC-PARA.

    STOP RUN.

    CALC-PARA.OPEN OUTPUT OUTPUT-FILE.

    PERFORM PROCESS-PARA UNTIL NO-MORE-RECORDS = NO

    CLOSE OUTPUT-FILE.

    PROCESS-PARA.

    RETURN SORT-FILE AT END MOVE NO TO NO-MORE-RECORDS.

    IF AMT-OF-PURCHASE > 6000

    MOVE 0.02 TO DISCOUNT

    ELSE

    MOVE 0.00 TO DISCOUNT

    END

    -IF.

    WRITE OUT-REC FROM SORT-REC.

  • 8/7/2019 Call Slides

    37/46

    COMPLEX SORT: Output Procedure

  • 8/7/2019 Call Slides

    38/46

    Complex Sort : Output Procedure

  • 8/7/2019 Call Slides

    39/46

    COMPLEX SORT : OUTPUT PROCEDURE

  • 8/7/2019 Call Slides

    40/46

    COMPLEX SORT : RUN JCL

  • 8/7/2019 Call Slides

    41/46

    COMPLEX SORT: OUTPUT DATA

  • 8/7/2019 Call Slides

    42/46

    COBOL Merge

    COBOL has a MERGE statement that will combine two or more filesinto a single file.

    The MERGE statement automatically handles the opening, closing,and any I-O (read/write functions) associated with the files.

    The files to be merged must be in sequence by the key-field(ascending or descending).

  • 8/7/2019 Call Slides

    43/46

    COBOL MergeMerge syntax

    MERGE file-1 { ON ASCENDING KEY data -1}

    DESCENDING

    USING file-2 { file-3 } . . .

    OUTPUT PROCEDURE IS proc-1

    GIVING {file-4}.

  • 8/7/2019 Call Slides

    44/46

    COBOL Merge Typical Program

    FILE CONTROL.

    SELECT IN-FILE1 ASSIGN TO E-FILE1.

    SELECT IN-FILE2 ASSIGN TO E-FILE2.

    SELECT M-FILE ASSIGN TO WORK.

    SELECT OUT-FILE ASSIGN TO E-FILE.

    DATA DIVISION.

    FD IN-FILE1.

    01 IN-REC1 PIC X(100).FD IN-FILE2.

    01 IN-REC2 PIC X(100).

    SD M-FILE.

    01 M-REC.

    05 KEY-FIELD PIC X(5).

    05 REST-OF REC PIC X(100).

    FD OUT-FILE.01 OUT-REC PIC X(100).

    PROCEDURE DIVISION.

    MAIN-PARA.

    MERGE M-FILE ON ASCENDING KEY KEY-FIELD

    USING IN-FILE1, IN-FILE2

    GIVING OUT-FILE

    STOP RUN

  • 8/7/2019 Call Slides

    45/46

  • 8/7/2019 Call Slides

    46/46

    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 Inputor Output procedures or using both

    Merge is used to merge two or more files