COBOL FileHandling

32
© 2008 MindTree Consulting © 2009 MindTree Limited CONFIDENTIAL: For limited circulation only An Introduction To File Operations April 2009

description

none

Transcript of COBOL FileHandling

© 2008 MindTree Consulting© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only

An Introduction To File Operations

April 2009

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 2

Topics to be Covered:

•Steps in File-handing

•Sort

•Merge

•Input/Output and Error Handling Techniques

•File Status Codes

•Compiler Options

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 3

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

File Operations:

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 4

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 =>ALL FilesORGANIZATION IS {SEQUENTIAL / INDEXED / RELATIVE} =>ALL FilesACCESS MODE IS {SEQUENTIAL / RANDOM / DYNAMIC } =>ALL Files RECORD KEY IS FILE-KEY1 =>KSDS ALTERNATE KEY IS data-name-2 [WITH/WITHOUT DUPLICATE] =>KSDS WITH AIX[RELATIVE KEY IS WS-FILE-KEY1 ] =>RRDS FILE STATUS IS dataname-1 [dataname-2] . =>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.

E.g.: //DDNAME DD DSN=MAIN.EMPLOYEE.DATA,DISP=SHR

OPTIONAL: This Key Word is used only for Input Files. If OPTIONAL is coded with SELECT, this file need not be present during the execution. If the file is not mapped in JCL, it is considered as Empty File and the first Read results in

End offile. If Omitted, the file must be present in JCL. If not, an Execution Error will occur.

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 5

Allocation of Files Continued….

ACCESS ORG.

SEQ RANDOM DYNAMIC

SEQ ORDER OF WRITE INVALID INVALID

RELATIVE ASC. REL. REC. NO. VALUE OF REL. KEY SEQ. OR RANDOM

INDEXED ASC. KEY VALUE VALUE OF REC. KEY SEQ. OR RANDOM

ACCESS MODE:• SEQUENTIAL: Records are accessed Sequentially.• RANDOM: Records are accessed in any order by giving the key value to

the RECORD KEY variable. A particular records of an Indexed/ Relative file is accessed provided Key Value is set prior to Read/Write Operation.

• DYNAMIC: Records can be accessed both Sequentially and Randomly.

ORGANIZATION: Depending on the input/output requirements and device types,• SEQUENTIAL: File is a Sequential File(PS file/ VSAM ESDS).

The records are placed in First Come First Serve Basis.• INDEXED: File is a VSAM KSDS file. Key Filed called Primary Key should be defined.• RELATIVE: File is VSAM RRDS File. Relative Record Number is used to access

records. Each record has a Unique Address identified by Relative Record

Number.

RECORD KEY: Defined for Indexed files and should be Unique and part of indexed record.ALTERNATE KEY: Defined if records are to be Read using Key Other than Primary Key and need not be Unique, but should be part of the record.

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 6

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/FBRECORD CONTAINS M CHARACTERS (TO N CHARACTERS)BLOCK CONTAINS X CHARACTERS/RECORDS (TO Y

CHARACTERS/RECORDS)LABEL RECORDS ARE OMITTED/STANDARDDATA 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. 

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 7

File Definition Continued….

FD-RECORD CONTAINS Clause : Specifies the Length of the Record in terms of bytes. (For Variable Format Files, it will be RECORD contains m to n CHARACTERS)This has to match with record length in the DD statement parameter. 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.

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 8

INPUT OUTPUT Statements:

3. OPEN: Connects the Dataset to the program. The mode of OPEN decides the operation allowed and the position of the initial pointer in the dataset.

Syntax: OPEN OPENMODE FILENAME

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) 5. CLOSE: Disconnects the File from the program.If we don’t close the files, the completion of the program closes all the files used in theprogram.Syntax: CLOSE Filename

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only

INPUT OUTPUT Statements:

READ: Reads the record from the file.Syntax: READ FILENAME NEXT RECORD [INTO ws-record] [KEY IS FILE-KEY1] [AT END/INVALID KEY imperative statement1] [NOT AT END/NOT INVALID KEY imperative statement2]

END-READ

• NEXT phrase: Optional for SEQUENTIAL 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-INTO: Not preferred for Variable size records where the length of the record being read is not known.

• 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.

Slide 9

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only

INPUT OUTPUT Processing Continued….

Slide 10

SEQUENTIAL READ:

Syntax: READ file-name NEXT RECORD [ INTO identifier-1 ] [ AT END imperative-stmt-1] [ NOT AT END imperative-stmt-2 ]

END-READ.

USAGE: When the Exact Key value is not known.• 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 ] END-READ.

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 11

INPUT OUTPUT Processing Continued….

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 patient’s 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).

EMP # EMP Name0004 RAJESH0010 RAMESH0015 GOPAL0016 RAGHAVAN0100 SARITA0401 RANI 

   Table: File position indicator example

Operation File Position Pointer

Record Area

OPEN input 0004 Not defined

READ NEXT 0010 0004 RAJESH

READ KEY 0100

0401 0100 SARITA

READ NEXT End of File 0401 RANI

READ KEY 0015

0016 0015 GOPAL

READ KEY 0090

Undefined Undefined (Invalid key)

READ NEXT Undefined Undefined

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 12

INPUT OUTPUT Processing Continued…. START: Used with Dynamic Access Mode of Indexed Files.

• Position’s 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 LimitedCONFIDENTIAL: For limited circulation only Slide 13

INPUT OUTPUT Processing Continued….

OPERATION POINTER VALUE

REC-AREA

OPEN I-O Top of File Not definedSTART ASSOC.NO-KEY = 0004

0004 Not defined

READ NEXT 0010 0004 RAJESHSTART ASSOC-NO-KEY > 0016

0100 0004 RAJESH

READ NEXT 0401 0100 SARITASTART ASSOC-NO-KEY > 0401

Unknown 0100 SARITA

START – 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). EMP # EMP Name0004 RAJESH0010 RAMESH0015 GOPAL0016 RAGHAVAN0100 SARITA 0401 RANI

Table: Illustration of START statement

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 14

INPUT OUTPUT Processing Continued…. WRITE: Writes a New Record to the file. If the file is Opened in :

• EXTEND mode, the record will be appended. • OUTPUT mode, the record will be added at the current position.

WRITE Syntax for Disk File : 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.

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 15

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.

• When ADVANCING option is used- 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.

• File Position is not affected by this statement.

• Facilities for Paper Movement are provided by:- Print and Advance- Advance and Print- Position to New Page- Advance by given number of lines - End of Page Logic (FD entry for this file must contain a LINAGE clause)

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 16

INPUT OUTPUT Processing Continued….

REWRITE: Updates an already read record.

Syntax: REWRITE File-record [FROM identifier-1] [INVALID KEY imperative statement1]

[NOT INVALID KEY imperative statement2]END-REWRITE.

• 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 a file in Sequential Access Mode:• The INVALID KEY and NOT INVALID KEY phrases should not be specified.• Logically Removes the most recently read record in the file.

• For Random or Dynamic Access, system removes record pointed by the RECORD key(KSDS) or RELATIVE key(RRDS).

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 17

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).

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 18

FILE SORTING Continued….

FASTSRT “BY PASS COBOL IN/OUT SORT PROCS BY USING DFSORT”.That is FASTSRT Compiler option makes the DFSORT to do all file I-O operation than the COBOL program and would significantly improve the performance.

• 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.

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 19

FILE SORTING Continued….

• If INPUT PROCEDURE is used, File1 and file2 are Opened and all the records are READ one by one until End of File and the required records are passed to Sort-Work-File using the command RELEASE.

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. • It’s 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.

OUTPUT PROCEDURE and GIVING are Mutually Exclusive.

• 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.

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 20

FILE SORTING Continued….

Syntax: RETURN Sort-Work-File-Name AT END Imperative Statement.

• Transfers records from the final phase of a sorting or merging operation to an OUTPUT PROCEDURE.

• It’s 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 ASSIGN TO EMPIN. SELECT OUTPUT-FILE ASSIGN TO EMPOUT. SELECT SORT-FILE ASSIGN TO WORKFILE.

DATA DIVISION.FILE SECTION.

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 21

FILE SORTING Continued….

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.

FD EMP-FILE.01 EMP-REC. 02 EMP-NO PIC 9(6). 02 EMP-NAME PIC X(24). 02 DEPARTMENT PIC X(10). 02 BASIC-PAY PIC 9(5)V99. 02 ALLOWANCE PIC 9(4)V99. 02 DEDUCTION PIC 9(4)V99.

 SD SORT-FILE 01 SORT-REC. 02 FILLER PIC X(30). 02 S-DEPARTMENTPIC X(10). 02 S-BASIC-PAY PIC 9(5)V99. 02 FILLER PIC X(12).

FD OUTPUT-FILE.01 OUT-REC PIC X(59).

Microsoft Office Word 97 - 2003 Document

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 22

FILE MERGING:

MERGE: Merges Two or more identical files sorted on the same field.

• 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.

Syntax: MERGE SORTFILE ON ASCENDING/DESCENDING KEY dataname1 dataname2 USING file1 file2 GIVING file3 / OUTPUT PROCEDURE is section-1

THRU section-2END-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.

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 23

INPUT/OUTPUT ERROR HANDLING TECHNIQUES:

The following are techniques of intercepting and Handling input/output Errors.

• The END-OF-FILE PHRASE (AT END)

• The EXCEPTION/ERROR declarative

• The INVALID KEY phrase.

• The FILE STATUS key

THE END-OF-FILE PHRASE (AT END): An End-of-File condition may or may not represent an error.

During Sequential Read, the End of a File is expected. And If We code an AT END phrase, the specified phrase will be executed upon End-of-File condition.

If We do not have any Error Handling in our program(if we don’t have an AT END phrase) and if we don’t have a specific record in the file, the random read of a record would immediately terminate the program with error ‘RECORD NOT FOUND’.

Example: When we are processing a file containing transactions in order to update a Master File.

PERFORM UNTIL WS-TRAN-EOF = "TRUE" READ UPDATE-TRANS-FILE INTO WS-TRANS-RECORD AT END DISPLAY "END OF TRANSACTION UPDATE FILE REACHED" MOVE "TRUE" TO WS-TRAN-EOF END READEND-PERFORM.

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 24

INPUT/OUTPUT ERROR HANDLING TECHNIQUES:

EXCEPTION/ERROR Declarative: We can have one or more ERROR declarative procedures in the program that will be given control, if an Input/Output Error occurs:

• A Single, Common Procedure for the entire program.

• Group procedures for each file open mode (whether INPUT, OUTPUT, I-O, or EXTEND).

• Individual procedures for each particular file.

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 istransferred to the INVALID KEY imperative statement. In which case, any ERRORDeclaratives that are coded will not be executed.

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 25

INPUT/OUTPUT ERROR HANDLING TECHNIQUES:

INVALID KEY phrase differ from ERROR declaratives in three ways:

1. INVALID KEY phrases operates for only limited types of errors, Whereas the ERROR declarative encompasses all forms.

2. INVALID KEY phrases are coded directly onto the Input/Output verb, Whereas ERROR declaratives are coded separately.

3. INVALID KEY phrases are specific for a Single Input/Output operation, Whereas ERROR declaratives are more general.

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.

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 26

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.

Attached is the List of Error Codes with different Status Codes:

Microsoft Word Document

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 27

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:

4. (Highest precedence). Installation defaults, fixed by the installation.

5. Options coded on PROCESS /CBL statement.

6. Options coded on JCL PARM parameters.

7. (Lowest Precedence). Installation defaults, but not fixed. 

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 28

COMPILER OPTIONS:

List of Compiler Option are:

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. 

DUMP: “TO PRODUCE A SYSTEM DUMP OF THE COMPILER”.

ASPECT COMPILER OPTION

SOURCE LANGUAGE

APOST, CMPR2, CURRENCY, DBCS, LIB, NUMBER, QUOTE, SEQUENCE, WORD.

DATE PROCESSING

DATEPROC, INTDATE, YEARWINDOW

MAPS, LISTING AND DIAGNOSTICS

LANGUAGE, LINECOUNT, LIST, MAP, NUMBER, OFFSET, SEQUENCE,SOURCE, SPACE, TERMINAL, VBREF, XREF

OBJECT CODE GENERATION

COMPILE, DECK, NAME, OBJECT, PGMNAME,CMPR2

OBJECT CODE CONTROL

ADV, AWO, DLL, EXPORTALL, FASTSRT, OPTIMIZE, NUMPROC, OUTDD, RENT, RESIDENT, SSRANGE, TRUNC, ZWB

DEBUGGING DUMP, FLAG, FLAGMIG, FLAGSTD, SSRANGE, TYPECHK , FDUMP, TEST

OTHER ADATA, ANALYZE, EXIT, IDLGEN

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 29

COMPILER OPTIONS Continued….

LIST/OFFSET: LIST and OFFSET are mutually exclusive. If We use both, LIST will be ignored.

LIST: “OBJECT CODE LISTING IN ASSEMBLY LANGUAGE (-OFFSET)” (LIST produces Listing of the Assembler Language expansion of the code). OFFSET: “LIST RELATIVE ADDRESSES OF PROCEDURE DIVISION (-LIST)” (OFFSET produces a Condensed Procedure Division listing).With OFFSET, the procedure portion of the listing will contain Line Numbers, Statement References, and the Location of the First Instruction generated for each statement.

MAP: “REQUEST TO LIST DATA DIVISION MAP” (Used to produce a Listing of the Items Defined in the Data Division). SSRANGE: “RANGE CHECK FOR SUBSCRIPT/INDEXES/REFERENCE MOD”If the program is compiled with SSRANGE option, then any attempt to refer an area outside the region of the table will abnormally terminate with Protection Exception, usually S0C4.

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.

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 30

COMPILER OPTIONS Continued….

DYNAM: “TREAT ALL UNRESOLVED CALL IDs AS DYNAMIC (RESIDENT +)”Loads the Separately Compiled programs dynamically at run time that are invoked through the CALL literal. DYNAM causes dynamic loads (for CALL) and deletes (for CANCEL) of separately compiledprograms at object time. When we specify DYNAM, RESIDENT is also put into effect.

RENT: “TO COMPILE THE PROGRAM TO BE REENTRANT (RESIDENT+)”A program compiled as RENT is generated as a Re-Entrant Object Module. CICS programs should be compiled with RENT option to share the same copy of the program by multiple transactions (Multithreading). 

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 thedevelopment of new program.

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 31

Reference Books

Cobol Programming by M K ROY and D GHOSH DASTIDAR

Structured COBOL Programming by STERN / STERN

Web-Links

www.ibmmainframes.com

Reference Books and Web-Links

© 2009 MindTree LimitedCONFIDENTIAL: For limited circulation only Slide 32 © 2009 MindTree Limited

Seema NarasimhaiahSeema_ [email protected]

www.mindtree.com

Thank YouThank You