Programming in COBOL85 For IBM Mainframe System 390
Programming in COBOL-85 For IBM Mainframe System 390 Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys. com Phone: 52179 12/18/2021 E&R Dept. , ITLInfosys
Objectives of the Session (1) Index sequential file organization. (2) Relative file organization. (3) The COPY verb. (4) The CALL verb. (5) Demonstration of sample programs. 12/18/2021 E&R Dept. , ITLInfosys 2
Indexed file organization Essentially comprises of two files namely (1) A data file and (2) An index file. w Provides both sequential and random access. w Slowest of all types of file organizations. w Facilitates the use of multiple alphanumeric keys. w Moderately storage efficient. w 12/18/2021 E&R Dept. , ITLInfosys 3
Example Data File REGNO BU 103 BU 101 BU 102 NAME Roopa Deeptha Bhavana AGE 19 20 18 Index File Index 12/18/2021 REGNO ADDRESS BU 101 BU 102 BU 103 00 a 3 c 2 00 a 3 d 4 00 b 943 E&R Dept. , ITLInfosys 4
Indexed and Relative Files 12/18/2021 E&R Dept. , ITLInfosys 5
ED Entries for Indexed Files ENVIRONMENT DIVISION. INPUT - OUTPUT SECTION. FILE - CONTROL. SELECT [Logical. FN ] File. Name ASSIGN TO File. Spec [ ORGANIZATION IS] INDEXED é ìSEQUENTIAL ü ù ê ï ïú êACCESS MODE IS í ì RANDOM ü ý ú ý ïú ïí ê î î DYNAMICþ þ û ë [ RECORD KEY IS Unique. Rec. Key] [ ] ALTERNATE RECORD KEY IS Alt. Key [ WITH DUPLICATES] [ FILE STATUS IS File. Status] 12/18/2021 E&R Dept. , ITLInfosys 6
About index sequential file w An indexed file in Cobol can be accessed either sequentially or randomly. w When accessed randomly, the sequence in which the records are accessed can be specified by the data item called record key 12/18/2021 E&R Dept. , ITLInfosys 7
Prime key and alternate key w The field which is specified in the RECORD KEY clause is known as prime key w Alternate key for the file can be specified using the ALTERNATE KEY clause w Alternate keys are unique by default w If the file has duplicate values for the alternate key then WITH DUPLICATES phrase should be specified 12/18/2021 E&R Dept. , ITLInfosys 8
Indexed File Verbs OPEN ì INPUT ü ï ï OPEN íOUTPUTý File. Name ï ï ïî I-O ïþ 12/18/2021 E&R Dept. , ITLInfosys 9
READ To read the records in the file in direct fashion To read the records in the file in sequential fashion 12/18/2021 E&R Dept. , ITLInfosys 10
Write and Rewrite The records are written to the logical position as determined from the value of the record key REWRITE statement requires that the file must be opened in the I -O mode 12/18/2021 E&R Dept. , ITLInfosys 11
DELETE • The record last read by the READ statement is deleted in case of sequential read • In case of random read the record to be deleted is specified in the record key option • File must be opened in the I-O mode 12/18/2021 E&R Dept. , ITLInfosys 12
START statement w The START positions the file to the first logical record whose record key satisfies the condition specified by the key phrase w The access mode must be SEQUENTIAL OR DYNAMIC w File must be opened in the I-O or input mode. 12/18/2021 E&R Dept. , ITLInfosys 13
START 12/18/2021 E&R Dept. , ITLInfosys 14
Relative Files 12/18/2021 E&R Dept. , ITLInfosys 15
Select and Assign for Relative Files
Relative File Verbs w All the verbs discussed with INDEXED files holds good in Relative Organization too. w Point to remember is that relative key is not part of Relative record and is declared as WS variable and must contain proper values.
File ORGANIZATIONs - A comparative study SEQUENTIAL INDEXED Slow when the hit rate is low. Slowest Direct Access organization Complicated to change. (Insert, Delete). Especially slow while adding or deleting of records. 12/18/2021 E&R Dept. , ITLInfosys RELATIVE Wasteful of storage if the file is only partially populated. Complicated to program. 18
File ORGANIZATIONs - A comparative study SEQUENTIAL Simplest ORGANIZATION. Most storage efficient. 12/18/2021 INDEXED Can use multiple, Alphanumeric keys Not very storage efficient. E&R Dept. , ITLInfosys RELATIVE Only a single, numeric key is allowed. Least storage Efficient. 19
Demonstration of Sample Programs 12/18/2021 E&R Dept. , ITLInfosys 20
Break 12/18/2021 E&R Dept. , ITLInfosys 21
COPY Verb The COPY is executed at compile time unlike other COBOL verbs which are executed at run time. The COPY statement allows programs to include frequently used source code text from a copy file or a copy library. The COPY can include source code text with or without change into the client program. Each client program which wants to use items described in the copy library uses the COPY verb to include the descriptions it requires. 12/18/2021 E&R Dept. , ITLInfosys 22
COPY Verb Examples (1) COPY “EMPLOYEE-RECORD”. (2) COPY ”STUDENT" REPLACING ABC BY XYZ. 12/18/2021 E&R Dept. , ITLInfosys 23
COPY Example IDENTIFICATION DIVISION. PROGRAM-ID. COPYEG 1. AUTHOR. JYOTHI SRIDHAR. Copy member resides in OPERN. CICS 3. COPYLIB ENVIRONMENT DIVISION. FILE-CONTROL. SELECT Student. File ASSIGN TO "STUDENTS” ORGANIZATION IS SEQUENTIAL. 01 DATA DIVISION. FILE SECTION. FD Student. File. COPYFILE. PROCEDURE DIVISION. A 0001 -MAIN-PARA. -----------STOP RUN. Student. 88 End. Of. SF VALUE 02 Student. Number 02 Student. Name 02 Course. Code 02 Fees. Owed 02 Amount. Paid HIGH-VALUES. PIC 9(7). PIC X(60). PIC X(4). PIC 9(4)V 99.
CALL Verb w Is the most important verb that provides structured programming capabilities in COBOL. w Is equivalent to a function or a sub-routine call in other computer languages. w Is similar to the COPY verb, in the sense that it provides code re-usability. w Provides two ways of passing parameters to the called program (1) By REFERENCE and (2) By CONTENT. 12/18/2021 E&R Dept. , ITLInfosys 25
Syntax of call statement w CALL NAME OF THE SUB PROGRAM USING THE PARAMETER NAMES Example CALL SUBPGM 1 USING NUM 1, NUM 2 12/18/2021 E&R Dept. , ITLInfosys 26
Passing by reference and value w By REFERENCE – CALL SUBPGM 1 USING WS-NUM 1. w BY VALUE – CALL SUBPGM 1 USING BY CONTENT WS-NUM 1 BY REFERENCE WS-NUM 2 BY REFERENCE WS-NUM 3. 12/18/2021 E&R Dept. , ITLInfosys 27
Rules for coding CALLed Programs DATA DIVISION. WORKING –STORAGE SECTION. w The CALLed programs should have a LINKAGE ---- SECTION in the DATA DIVISION. LINKAGE SECTION. w If the CALLed programs possess WORKING- STORAGEPIC SECTION, then the LINKAGE 01 WS-NUM 1 9(3). SECTION must appear after it. 01 WS-NUM 2 PIC 9(3). w The PROCEDURE DIVISION of the CALLed PROCEDURE DIVISION USING WS-NUM 1, WS-NUM 2 program must have a USING clause to identify the variables passed from the CALLing program. 12/18/2021 E&R Dept. , ITLInfosys 28
Rules for coding CALLed Programs DATA DIVISION. WORKING –STORAGE w The variables defined. SECTION. in the LINKAGE ----SECTION can be defined in any order. LINKAGE SECTION. w The variables in the USING clause must be in same order as in the CALL statement of the 01 the WS-NUM 1 PIC 9(3). CALLing program. 01 WS-NUM 2 PIC 9(3). w Instead of a. DIVISION STOP RUN statement, the CALLed PROCEDURE USING WS-NUM 1, WS-NUM 2. program must contain an EXIT PROGRAM A 001 -MAIN-PARA. statement to transfer the control back to the ----CALLed program. EXIT PROGRAM 12/18/2021 E&R Dept. , ITLInfosys 29
Review w Index sequential file organization. w Relative file organization. w The COPY verb. w The CALL verb. 12/18/2021 E&R Dept. , ITLInfosys 30
Review questions w DELETE statement should be followed by ( file/record) File name _____ w For updation and deletion, the files are to be opened in Input-output (I-O) __________ mode w COPY statement is allowed only in the data division ( True / false ) w Indicate which of the following COBOL verb does not use FROM phrase – – ACCEPT DISPLAY PERFORM WRITE 12/18/2021 E&R Dept. , ITLInfosys 31
Review Questions w LINKAGE SECTION cannot have any value clause (True / False ) w RENAMES clause cannot be used in LINKAGE SECTION (True / False ) w COPY statement is executed during compile time rather then run time ( True/ False) 12/18/2021 E&R Dept. , ITLInfosys 32
Any Questions ? ? 12/18/2021 E&R Dept. , ITLInfosys 33
Thank you Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys. com Phone: 52179 12/18/2021 E&R Dept. , ITLInfosys 34
- Slides: 34