Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 3: COBOL Program structure


INPUT-OUTPUT SECTION

  • The INPUT-OUTPUT SECTION is used to describe input and output files used by program. It is also used to specify information required for transmission of data between the external medium and the COBOL program
  • This section must be specified in all programs that use files
  • INPUT-OUTPUT SECTION and its Paragraphs, must begin in Margin A and can be continued to Margin B of coding sheet.
  • The basic structure of INPUT-OUTPUT SECTION is as follows:-

    [INPUT-OUTPUT SECTION. [FILE-CONTROL. {file-control-entry}… .] [I-O-CONTROL. {input-output-control-entry}.]]

  • There are two paragraphs which can be coded within INPUT-OUTPUT SECTION, namely ‘FILE-CONTROL’ and ‘I-O-CONTROL’ paragraph

FILE-CONTROL paragraph

  • FILE-CONTROL paragraph is used to specify the input-output files used in program.
  • FILE-CONTROL paragraph must be specified in programs that use files
  • All files used in program must be specified in FILE-CONTROL paragraph.
  • In FILE-CONTROL paragraph, SELECT statement is used to identify a file in COBOL program to be associated with external dataset. Each file must be specified using separate SELECT statement. SELECT statement will be described below
  • The mapping with JCL DDNAME is done here
  • The basic structure of FILE-CONTROL is as follows:-

    FILE-CONTROL. SELECT [OPTIONAL] file-name ASSIGN TO DDNNAME [ORGANIZATION IS {SEQUENTIAL | INDEXED | RELATIVE}] [ACCESS IS {SEQUENTIAL | RANDOM | DYNAMIC}] [RECORD KEY IS key-name] [RELATIVE KEY IS rel-key] [ALTERNATE RECORD KEY IS alt-key {WITH | WITHOUT} DUPLICATES] [FILE STATUS IS file-status] [RESERVE number AREA]

    Let’s understand each part of given structure
  • SELECT must be the first clause in a FILE-CONTROL entry. The other clauses may follow in any order. The SELECT clause may appear in Margin A, all other clauses must appear in Margin B
  • SELECT statement as specified earlier, it is used to identify file used in program and must be specified separately for each files.
  • OPTIONAL clause:-
    • When coded, it is used to indicate that the file need not mandatorily present when the program runs.
    • This clause can be coded only for files opened in input, I-O, or extend mode.
    • If OPTIONAL is not coded, then input file is expected to be present in JCL, otherwise there will be an execution error.
    • If OPTIONAL is coded and the file is not mapped in JCL, the file is considered empty and the first read results in the end-of-file.
  • ASSIGN TO clause :-
    • The ASSIGN clause associates the name of a file in a program with the actual external name of the data file
    • file-name in above mentioned structure indicates the logical name used in the COBOL program and DDNAME is logical name in the JCL mapped with the mainframe dataset
    • DDNAME can be prefixed with ‘UT-S-’ to indicate QSAM file, ‘UT-AS-‘ to indicate ESDS file and with no prefix to indicate KSDS/RRDS file.
  • ORGANIZATION clause :-
    • The ORGANIZATION clause is used to specify the logical structure of the file. This is established when a file is first created and may not be changed.
    • It can be coded SEQUENTIAL (for PS or ESDS files), INDEXED ( for KSDS files) or RELATIVE (for RRDS files)
    • If ORGANIZATION is not coded, then SEQUENTIAL organization is implied.
  • ACCESS clause :-
    • The ACCESS clause is used to specify the order in which records are read or written
    • It can be coded SEQUENTIAL, RANDOM or DYNAMIC. If ACCESS is not coded, then SEQUENTIAL is implied.
    • ACCESS IS SEQUENTIAL :-
      • The records are accessed sequentially according to the organization of the file.
      • When used with ORGANIZATION IS SEQUENTIAL, records in the file are accessed in the sequence established when the file is created or extended.
      • When used with ORGANIZATION IS INDEXED, records in the file are accessed in the sequence of ascending record key values according to the collating sequence of the file.
      • When used with ORGANIZATION IS RELATIVE, records in the file are accessed in the ascending sequence of relative record numbers of existing records in the file.
    • ACESS IS RANDOM :-
      • The records can be accessed randomly using the primary/alternate key of INDEXED file organization or using the relative record number of RELATIVE file organization.
      • It can used only with INDEXED, RELATIVE file organization
    • ACCESS IS DYNAMIC:-
      • This is mixed mode of access. The records can be accessed in random as well as sequential order
      • It can be used only with INDEXED, RELATIVE file organization
  • RECORD KEY clause :-
    • The RECORD KEY clause is used to specify the primary key of INDEXED organization file(i.e. KSDS file)
    • The values contained in primary key data item must be unique among the records and part of indexed record structure
    • It can be used only with INDEXED file organization
  • RELATIVE KEY clause :-
    • The RELATIVE KEY clause is used to specify the data name that specifies the relative record number for a specific logical record within a RELATIVE file organization(i.e. RRDS file)
    • It can be used only with RELATIVE file organization
  • ALTERNATE RECORD KEY clause :-
    • The ALTERNATE RECORD KEY clause is used to specify a data item within the record that provides an alternative path to the data in an INDEXED file organization (i.e. KSDS file).
    • It can be used only with INDEXED files (KSDS) defined with Alternate Index (AIX). We can add WITH DUPLICATES clause if the Alternate Index is defined with duplicates
  • FILE STATUS clause :-
    • The FILE STATUS clause is used to monitor the execution of each I/O operation for the file.
    • When FILE STATUS clause specified, the system moves a value into ‘file-status’ after each I/O operation. The value in the ‘file-status’ can be used to determine next action in program
  • RESERVE clause :-
    • The RESERVE clause is used to specify the number of input/output buffers to be allocated at run time for the files.
    • If the RESERVE clause is not coded, the number of buffers is taken from the DD statement. If none is specified, the system default is taken.
  • Example:-
    JCL Code showing the program call and input file declaration:

    //DEPTJOB JOB A123,’STEVE’ //STEP1 EXEC PGM=MFPROG1 //INPUTFL DD DSN=DEPT1.EMP1.DATA1, // DISP=SHR

    COBOL Code showing use of SELECT statement:-

    IDENTIFICATION DIVISION. PROGRAM-ID. MFPROG1. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INPFILE ASSIGN TO INPUTFL ORGANIZATION IS SEQUENTIAL ACCESS IS SEQUENTIAL.

  • Note:- As of now we have shared only part of COBOL program wherein SELECT statement is used as most of the concepts for file handling need to explain yet. We will share complete example in later modules when file handling will be explained < LINK >

    Explanation:- As shown in JCL code we are calling COBOL program MFPROG1 and specified input file with DDNAME as ’INPUTFL‘. In COBOL code, since we are going to use the file INPUTFL, it is mandatory to specify file using SELECT statement. If you observe SELECT statement, the ‘INPFILE’ is logical name of file which will be used in COBOL program and ASSGIN TO clause associates the ‘INPFILE’ to JCL declared DDNAME ‘INPUTFL’.

I-O-CONTROL paragraph

  • I-O-CONTROL paragraph is used to specify the input-output techniques to be used for the program’s files.
  • I-O-CONTROL paragraph is optional to specify.
  • The basic structure of I-O-CONTROL is as follows:-

    I-O-CONTROL. [ APPLY WRITE-ONLY ON {file-name1} ... ] ... [ SAME [RECORD|SORT|SORT-MERGE] AREA FOR {file-name2} ... ] ...

  • The APPLY WRITE-ONLY clause optimizes buffer and device space allocation for files that have standard sequential organization, have variable-length records, and are blocked.
  • The SAME AREA clause is used to specify that more than one file is to use the same buffer area. The benefit of this clause is it forces program to operate within limited space. Drawback with this is only one file can be open at a time.
  • The SAME RECORD AREA clause is used to specify that the buffer is not shared between files but record area is shared. The benefit of this clause is that it will allow more than one file to be in open state. The drawback of this clause is that we need to be careful when filling record area, as this may destroy the record read most recently
  • The SAME SORT AREA and SAME SORT-MERGE AREA enables more than one sort/merge work files to use same area
  • Example:-

    INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT FILE1 ASSIGN TO FILE1. SELECT FILE2 ASSIGN TO FILE2. I-O-CONTROL. APPLY WRITE-ONLY ON FILE1. APPLY WRITE-ONLY ON FILE2.






© copyright mainframebug.com
Privacy Policy