Académique Documents
Professionnel Documents
Culture Documents
April 2009
Topics to be Covered:
Steps in File-handing Sort Merge Input/Output and Error Handling Techniques File Status Codes Compiler Options
Slide 2
File Operations:
FILE:
A Data File(Data Set) is Collection of relevant Records that are stored Permanently and a Record is Collection of relevant Fields. Files can be associated with an external device like Disk, Tape, Printer etc. FILE NAME: A file has Two names: Physical and Logical Name. The JCL DD Statement Connects both Logical and Physical Files. The File Handling in COBOL program involves Five steps: 1. ALLOCATION 2. DEFINITION 3. OPEN 4. PROCESS 5. CLOSE
Slide 3
Allocation of Files:
1. ALLOCATION: Files used in the program should be declared in FILE-CONTROL paragraph of
INPUT-OUTPUT SECTION. The mapping with JCL DDNAME is done here. FILE-CONTROL Syntax:
SELECT [OPTIONAL] Filename ASSIGN TO DDNAME ORGANIZATION IS {SEQUENTIAL / INDEXED / RELATIVE} ACCESS MODE IS {SEQUENTIAL / RANDOM / DYNAMIC } RECORD KEY IS FILE-KEY1 ALTERNATE KEY IS data-name-2 [WITH/WITHOUT DUPLICATE] [RELATIVE KEY IS WS-FILE-KEY1 ] FILE STATUS IS dataname-1 [dataname-2] . =>ALL Files =>ALL Files =>ALL Files =>KSDS =>KSDS WITH AIX =>RRDS =>ALL Files
SELECT: Gives the Relationship between the Logical File and the Physical file. Filename: Logical File Name used by COBOL to refer inside the program. DD Name: Associates the Symbolic file with External DDNAME given in JCL. DD Name can be Disk/ Printer/ Tape.
SEQ ORDER OF WRITE ASC. REL. REC. NO. ASC. KEY VALUE
File Definition:
2. DEFINITION:
The File that is defined in the SELECT clause, should have an FD entry in the FILE SECTION. The layout of the file and its attributes are defined in the FD section of FILE SECTION. File Layout: FD FILENAME RECORDING MODE IS V/VB/F/FB RECORD CONTAINS M CHARACTERS (TO N CHARACTERS) BLOCK CONTAINS X CHARACTERS/RECORDS (TO Y CHARACTERS/RECORDS) LABEL RECORDS ARE OMITTED/STANDARD DATA RECORD IS FILE-RECORD. 01 FILE-RECORD PIC X(nnn). RECORDING MODE IS Clause : Records in a file Can be F / V / FB / VB
Variable record file identification: If there is no Recording Mode/Record Contains Clause, it is still possible to identify variable length records. If there is an OCCURS depending on clause or there are multiple 01 levels and every 01 level is of different size, then the file would be of variable length.
E.G for Implicit Redefinition : Multiple 01 level in File section.
CONFIDENTIAL: For limited circulation only 2009 MindTree Limited Slide 6
FD-BLOCK CONTAINS Clause : The BLOCK CONTAINS RECORDS specifies the No of Logical Records in each Physical Record, i.e., Multiples of LRECL. The BLOCK CONTAINS CHARACTERS clause Specifies the Physical Record Size.(for Disk Files) It is suggested to code BLOCK CONTAINS 0 RECORDS, so that system will decide the optimum size for the file based on the device used for storing the file. BLOCK CONTAINS clause is treated as comments for VSAM files.
Advantage of Blocking: I-O time is reduced as n No of records are read into main memory buffer during an I-O. Inter Record Gap is removed and the gap exist only between blocks. So memory wastage due to IRG is avoided. FD-LABEL RECORDS Clause: LABEL RECORDS are STANDARD is coded for Disk and Tape files, LABEL RECORDS ARE OMITTED is coded for printer files. FD-DATA RECORD IS Clause: It is used to name the data record(s) of the file. More than one record can be coded here.
CONFIDENTIAL: For limited circulation only 2009 MindTree Limited Slide 7
Syntax:
OPENMODE can be: INPUT To READ an Existing File. OUTPUT To Write/To add to an Existing File/Create New file. I-O - FOR READ, WRITE, REWRITE and DELETE an existing File. EXTEND - FOR appending records at the End of the File. EXTEND mode allows only write access and the pointer is kept on the End of File to append.
4. PROCESS: Files can be Processed as per requirement, using the I-O statements
provided by COBOL. (READ/READ NEXT, START, WRITE, REWRITE and DELETE)
Access Mode but is must for DYNAMIC. When the READ NEXT statement is the first statement to be executed after the OPEN statement on the file, the next record is the first record in the file.
INTO Clause: If coded, then the file is directly read into Working Storage Section record.
It is preferred as it avoids another move of File-Section record to Working-Storage-record followed by simple READ. read is not known.
READ-INTO: Not preferred for Variable size records where the length of the record being
KEY IS Clause: Used while accessing a record randomly using Primary/Alternate Record Key. AT END / NOT AT END: Used during sequential file READ. INVALID KEY / NOT INVALID KEY: Used during Random File Read.
Before accessing the file randomly, the key field should have a value before READ.
CONFIDENTIAL: For limited circulation only 2009 MindTree Limited Slide 9
To search the VSAM file for a Particular Key for processing. When Alternate key is used as key to the Indexed File. This is because the
Alternate Key may not be unique. To process records with part of the key matching.
E.G: The key field of the EMP-MATER file is Emp-No, Designation, Date-of-Joining. To process all employees belonging to designation Associates, we use Sequential Read of the Indexed File. RANDOM READ: The random read of Indexed File is faster. Syntax: READ file-name RECORD [ INTO identifier-1 ] [ KEY IS data-name-1 ] [ INVALID KEY imperative-stmt-3 ] [ NOT INVALID KEY imperative-stmt-4 ]
2009 MindTree Limited Slide 10
END-READ.
CONFIDENTIAL: For limited circulation only
USAGE:- When the key value for the file is exactly known. In Real Time Systems like Patient monitoring system in hospitals to retrieve a particular patients record. The full key value for the Patient master file is known. Hence we use random read in this case. READ Example: File- Indexed, Dynamic Access, and Record Key is EMP-NO. Record Description: 01 EMP-REC 05 EMP-NO PIC 9(4). 05 EMP-NAME PIC X(10).
Operation OPEN input READ NEXT READ KEY 0100 READ NEXT READ KEY 0015 READ KEY 0090 READ NEXT File Position Pointer 0004 0010 0401 End of File 0016 Undefined Undefined Record Area Not defined 0004 RAJESH 0100 SARITA 0401 RANI 0015 GOPAL Undefined (Invalid key) Undefined
Slide 11
Positions the pointer at a Specific Position. Establishes the current location in the cluster for READ NEXT statement. START itself does not retrieve any record. It only sorts the current record pointer described under File position indicator .
RULES: Invalid Key arises if the record position is empty. When the KEY phrase is not specified, KEY IS EQUAL (to the prime record key) is implied. All the Numeric and Nonnumeric comparison rules apply.
When the START statement is executed, a comparison is made between the current value
in the key data-name and the corresponding key field in the file's index.
If the operands in the comparison are of unequal lengths, the comparison proceeds as if
the longer field were truncated on the right to the length of the shorter field. Syntax: START Filename [KEY IS EQUAL TO/NOT LESS THAN/GREATER THAN key-name] [INVALID KEY Imperative Statement1] END-START.
2009 MindTree Limited Slide 12
Slide 13
EXTEND mode, the record will be appended. OUTPUT mode, the record will be added at the current position.
WRITE File-record [FROM identifer-1] [INVALID KEY imperative statement1] [NOT INVALID KEY imperative statement2] END-WRITE.
FROM Clause: Avoids the Explicit move of Working Storage record to File Section record
before WRITE. INVALID KEY: Not Allowed for ESDS.
WRITE Syntax for Printer File : WRITE File-record [FROM identifer-1] [{BEFORE ADVANCING {(N Lines/identifer-2 Lines) AFTER ADVANCING {(N Lines/identifer-2 Lines) Mnemonic-Name PAGE }] [AT { END-OF-PAGE stmt-1 EOP } ] [NOT AT { END-OF-PAGE stmt-2 EOP } ] END-WRITE.
CONFIDENTIAL: For limited circulation only 2009 MindTree Limited Slide 14
INPUT OUTPUT Processing Continued. ADVANCING phrase is only for Printer Files.
RULES: 1.BEFORE ADVANCING specifies, the line is printed before the page is advanced. 2.AFTER ADVANCING specifies, the page is advanced before the line is printed. 3.When identifier-2 is specified, the page is advanced the number of lines equal to the current value in identifier-2. Identifier-2 must name an elementary integer data item.
- First char of record is reserved for Printer Control. - If compiler has ADV, the LRECL of file should be more than FD entry record area length. - If compiler option is NOADV then LRECL of file is same as FD entry record area length.
For a file in sequential access mode, the INVALID KEY and NOT INVALID KEY phrases should not be specified.
DELETE: Logically Removes the most recently read record in the file.
Syntax: DELETE Filename RECORD [INVALID KEY imperative statement1] [NOT INVALID KEY imperative statement2] END-DELETE.
For Random or Dynamic Access, system removes record pointed by the RECORD
2009 MindTree Limited Slide 16
The INVALID KEY and NOT INVALID KEY phrases should not be specified. Logically Removes the most recently read record in the file.
FILE SORTING:
SORT: The process of sequencing records in file in some predetermined order on some fields in which it was not initially stored is called SORTING.
External Sort: The SORT in JCL is External Sort. Internal Sort : The Programming SORT is Internal Sort.
SORT accepts an Input File and creates a Sorted Output File. The SORT uses a Temporary file called SORT Work File for sorting the given input file.
SORT requires 3 Files for processing : 1.Unsorted Input File, 2.SORT Work file/ SORTFILE 3.Sorted Output File.
The fields based on which the records are sequenced are called SORT KEYS. The sequencing can be ascending or descending order of the KEY. Internal Sort is preferred, When we want to manipulate the data before feeding to sort
or after sorting before writing it to the output file. Internal Sort, in turn invokes the SORT product of the installation (DFSORT). In the run JCL, we need to allocate at least three sort work files.(SORT-WKnn). nn =(00-99).
CONFIDENTIAL: For limited circulation only 2009 MindTree Limited Slide 17
The result of the SORT can be checked in SORT-RETURN Register. If Sorting is Successful, the Value will be 0 else 16.
Syntax:
SORT SORTFILE ON ASCENDING /DESCENDING KEY sd-key-1 sd-key2 USING file1 file2 / INPUT PROCEDURE IS section-1 GIVING file3 / OUTPUT PROCEDURE IS section-2 END-SORT
File1, File2 are Unsorted Input Files and File3 is Sorted-Output file that should be defined in FD(File Description) Entry. SORTFILE is SORT Work file that is defined at SD Entry. It is not associated with any Physical File hence No Explicit Opening or Closing. The format of SD entry is same as the FD entry. The SORT verb opens input, output and the work files before the sorting begins and closes these files when sorting is over.
INPUT PROCEDURE and USING are Mutually Exclusive. If USING is used, then file1 and file2 should not be Opened or READ explicitly.
CONFIDENTIAL: For limited circulation only 2009 MindTree Limited Slide 18
INPUT-PROCEDURE is specified to Select or Modify the Input record before Sort. It validates data in the input record. Eliminates records with blank fields and Removes records that are not needed. Counts the input records. Syntax: RELEASE Sort-Work-Record FROM Input-File-Record.
Transfers records to the initial phase of Sort operation. Its like WRITE statement that should be used in conjunction with SORT File only. At-least one RELEASE stmt must be executed, for every INPUT PROCEDURE used.
If GIVING is used, then file3 should not be Opened or Written explicitly. If OUTPUT PROCEDURE is used, File3 will be Opened and then the required sorted records
from Sort Work File are RETURNed to the Out File for WRITE. Once AT END is reached for Sort-Work-File, Close the Output file. OUTPUT-PROCEDURE is specified to Select or Modify the Output record after Sort.
CONFIDENTIAL: For limited circulation only 2009 MindTree Limited Slide 19
Transfers records from the final phase of a sorting or merging operation to an OUTPUT PROCEDURE. Its like READ statement. If OUTPUT PROCEDURE is used, at-least one RETURN statement must be executed.
The INPUT and OUTPUT PROCEDURES are nothing but Sections placed outside the SORT statement. They are performed implicitly by sort statement in order to perform editing.
Simple SORT E.G: To SORT the file on DEPARTMENT in Ascending order and then within each DEPARTMENT, Arrange BASIC-PAY on Descending Order.
ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMP-FILE SELECT OUTPUT-FILE SELECT SORT-FILE DATA DIVISION. FILE SECTION.
Slide 20
PIC 9(6). PIC X(24). PIC X(10). PIC 9(5)V99. PIC 9(4)V99. PIC 9(4)V99.
PROCEDURE DIVISION. 1000-Para. SORT SORT-FILE ON ASCENDING KEY S-DEPARTMENT DESCENDING KEY S-BASIC-PAY USING EMP-FILE GIVING OUTPUT-FILE. STOP RUN. 1000-EXIT. EXIT. -------------------------------------------------------------------------------------------------------------------------------Advanced SORT E.G: To SORT the file on TERRITORY, AREA and DEPARTMENT in Ascending order and To Eliminate records with BLANK TERRITORY.
Slide 21
FILE MERGING:
MERGE: Merges Two or more identical files sorted on the same field.
Syntax:
Sometimes it becomes necessary to create a new output file from 2 input files. These 2 files needs to be merged and new file needs to be created. It is same as sort. USING is mandatory. There should be minimum two files in USING. MERGE SORTFILE ON ASCENDING/DESCENDING KEY dataname1 dataname2 USING file1 file2 GIVING file3 / OUTPUT PROCEDURE is section-1 THRU section-2 END-MERGE.
Example: MERGE SORTED-FILE ON ASCENDING S-LAST-NM S-FIRST-NM DESCENDING S-EMP-NBR USING EMP-PH-FILE EMP-ADDON-PH-FILE GIVING NEW-EMP-PH-FILE END-MERGE.
Slide 22
INVALID KEY Phrase: Control will be given to INVALID KEY when an Input/Output Error occurs because of a Faulty Index Key. The sudden termination can be avoided by handling this error, with INVALID KEY clause. We can include INVALID KEY phrases on READ, START, WRITE, REWRITE, and DELETE requests for Indexed and Relative Files.
If we specify INVALID KEY in a statement that causes an INVALID Condition, Control is transferred to the INVALID KEY imperative statement. In which case, any ERROR Declaratives that are coded will not be executed.
Slide 24
FILE STATUS Key: The system updates the FILE STATUS key for every Input/Output Execution and Places the values of Status Code in two digits of the File Status Key. The First Digit denotes general category under which the Error Code Falls. The Second Digit will denote the particular type of error under that category.
FILE STATUS Key is established using the FILE STATUS clause in the FILE-CONTROL and Data Definitions in the Data Division.
Slide 25
ERROR CODES:
If FILE STATUS key has a non allowable Return Code, then program will be ended abnormally with error statements that would be easier to debug. This is MOST PREFERRED ERROR HANDLING METHOD in structured programming. If FILE STATUS Code has: - Status key 1: Tells the type of error . - Status key 2: Gives the detail.
Slide 26
COMPILER OPTIONS:
Ways of Overriding the Default Options: 1. Compiler options can be passed to COBOL Compiler Program (IGYCRCTL) through the PARM in JCL. 2. PROCESS or CBL statement with compiler options, can be placed before the IDENTIFICATION DIVISION. 3. If the Organization uses any third party product or its own utility then these options can be coded in the pre-defined line of the utility panel. Precedence of Compiler Options:
Slide 27
COMPILER OPTIONS:
List of Compiler Option are: ASPECT
SOURCE LANGUAGE DATE PROCESSING MAPS, LISTING AND DIAGNOSTICS OBJECT CODE GENERATION OBJECT CODE CONTROL DEBUGGING OTHER
COMPILER OPTION
APOST, CMPR2, CURRENCY, DBCS, LIB, NUMBER, QUOTE, SEQUENCE, WORD. DATEPROC, INTDATE, YEARWINDOW LANGUAGE, LINECOUNT, LIST, MAP, NUMBER, OFFSET, SEQUENCE,SOURCE, SPACE, TERMINAL, VBREF, XREF COMPILE, DECK, NAME, OBJECT, PGMNAME,CMPR2 ADV, AWO, DLL, EXPORTALL, FASTSRT, OPTIMIZE, NUMPROC, OUTDD, RENT, RESIDENT, SSRANGE, TRUNC, ZWB DUMP, FLAG, FLAGMIG, FLAGSTD, SSRANGE, TYPECHK , FDUMP, TEST ADATA, ANALYZE, EXIT, IDLGEN
ADV: To ADD 1 BYTE FOR PRINTER CONTROL CHARACTER. Used in Programs with Printer Files with WRITE..ADVANCING keyword. If we are Manually populating Printing Control Character in the Program, then we compile the Program with NOADV.
It also avoids any meaningless operation on Reference Modification like Negative Number in the Starting Position of Reference Modification Expression.
If the program is compiled with NOSSRANGE, then the program may proceed further with junk or irrelevant data. Usually the programs are compiled with SSRANGE during development and testing.
CONFIDENTIAL: For limited circulation only 2009 MindTree Limited Slide 29
RESIDENT: Used to request the COBOL Library Management Feature. (The COBOL Library Management Feature causes most COBOL library routines to be located dynamically at run time, instead of being link-edited with the COBOL program.). CICS Programs should be compiled with RESIENT option.
XREF: STORED CROSS REFERENCE PROV DUP/UND/EXT/IMP ERRORS Used to get a Sorted Cross-Reference Listing. EBCDIC Data-names and Procedure-names will be listed in Alphanumeric Order. It also includes listing, where all the data-names that are referenced within the program and the line number where they are defined. This is useful for identifying the fields that are defined but not used anywhere after the development of new program.
CONFIDENTIAL: For limited circulation only 2009 MindTree Limited Slide 30
Web-Links
www.ibmmainframes.com
Slide 31
Thank You