CobolDay4

34
06/26/22 16:33 E&R Dept., ITLInfosys Programming in COBOL-85 For IBM Mainframe System 390 Jyothi Sridhar Kini E&R, Infosys Mail-id: [email protected] Phone: 52179

Transcript of CobolDay4

Page 1: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys

Programming in COBOL-85

For IBM Mainframe System 390

Jyothi Sridhar KiniE&R, Infosys

Mail-id: [email protected]: 52179

Page 2: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 2

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.

Page 3: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 3

Indexed file organization Essentially comprises of two files namely (1) A data file and (2) An index file.

Provides both sequential and random access.

Slowest of all types of file organizations.

Facilitates the use of multiple alphanumeric keys.

Moderately storage efficient.

Page 4: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 4

Example

Data File

REGNO NAME AGE

BU103 Roopa 19BU101 Deeptha 20BU102 Bhavana 18

Index File

REGNO ADDRESS

BU101 00a3c2 BU102 00a3d4BU103 00b943

Index

Page 5: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 5

Indexed and RelativeFiles

Page 6: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 6

ED Entries for Indexed Files

ENVIRONMENT

RANDOM

DYNAMIC

DIVISION.

INPUT- OUTPUT SECTION.

FILE - CONTROL.

SELECT [LogicalFN ] FileName

ASSIGN TO FileSpec

ORGANIZATION IS INDEXED

ACCESS MODE IS

SEQUENTIAL

RECORD KEY IS UniqueRecKey

ALTERNATE RECORD KEY IS AltKey WITH DUPLICATES

FILE STATUS IS FileStatus

Page 7: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 7

About index sequential file

An indexed file in Cobol can be accessed either sequentially or randomly.

When accessed randomly, the sequence in which the records are accessed can be specified by the data item called record key

Page 8: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 8

Prime key and alternate key

The field which is specified in the RECORD KEY clause is known as prime key

Alternate key for the file can be specified using the ALTERNATE KEY clause

Alternate keys are unique by default If the file has duplicate values for the alternate

key then WITH DUPLICATES phrase should be specified

Page 9: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 9

Indexed File Verbs OPEN

OPEN

INPUT

OUTPUT

I-O

FileName

Page 10: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 10

READTo read the records in the file in direct fashion

To read the records in the file in sequential fashion

Page 11: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 11

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

Page 12: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 12

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

Page 13: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 13

START statement

The START positions the file to the first logical record whose record key satisfies the condition specified by the key phrase

The access mode must be SEQUENTIAL OR DYNAMIC

File must be opened in the I-O or input mode.

Page 14: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 14

START

Page 15: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 15

Relative Files

Page 16: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys

Select and Assign for Relative Files

Page 17: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys

Relative File Verbs

All the verbs discussed with INDEXED files holds good in Relative Organization too.

Point to remember is that relative key is not part of Relative record and is declared as WS variable and must contain proper values.

Page 18: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 18

File ORGANIZATIONs - A comparative study

SEQUENTIAL INDEXED RELATIVE

Slow when the hit Slowest Direct Access Wasteful of storage hit rate is low. organization if the file is only partially populated.

Complicated to Especially slow while Complicated to change. (Insert, adding or deleting of program.Delete). records.

Page 19: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 19

File ORGANIZATIONs - A comparative study

SEQUENTIAL INDEXED RELATIVE

Simplest Can use multiple, Only a single, ORGANIZATION. Alphanumeric keys numeric key is allowed.

Most storage Not very storage Least storage efficient. efficient. Efficient.

Page 20: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 20

Demonstration of

Sample Programs

Page 21: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 21

Break

Page 22: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 22

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.

Page 23: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 23

Word2

Literal2

2Identifier

==2PseudoText==

BY

Word1

Literal1

1Identifier

==1PseudoText==

REPLACING

eLiteralLibraryNam

eLibraryNam

IN

OF

ralleNameLiteExternalFi

TextName COPY

Examples

(1) COPY “EMPLOYEE-RECORD”.

(2) COPY ”STUDENT" REPLACING ABC BY XYZ.

COPY Verb

Page 24: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys

IDENTIFICATION DIVISION. PROGRAM-ID. COPYEG1. AUTHOR. JYOTHI SRIDHAR. ENVIRONMENT DIVISION. FILE-CONTROL. SELECT StudentFile ASSIGN TO "STUDENTS” ORGANIZATION IS SEQUENTIAL. DATA DIVISION. FILE SECTION. FD StudentFile. COPY COPYFILE. PROCEDURE DIVISION. A0001-MAIN-PARA. -------- -------- --------- STOP RUN.

IDENTIFICATION DIVISION. PROGRAM-ID. COPYEG1. AUTHOR. JYOTHI SRIDHAR. ENVIRONMENT DIVISION. FILE-CONTROL. SELECT StudentFile ASSIGN TO "STUDENTS” ORGANIZATION IS SEQUENTIAL. DATA DIVISION. FILE SECTION. FD StudentFile. COPY COPYFILE. PROCEDURE DIVISION. A0001-MAIN-PARA. -------- -------- --------- STOP RUN.

01 Student. 88 EndOfSF VALUE HIGH-VALUES. 02 StudentNumber PIC 9(7). 02 StudentName PIC X(60). 02 CourseCode PIC X(4). 02 FeesOwed PIC 9(4). 02 AmountPaid PIC 9(4)V99.

01 Student. 88 EndOfSF VALUE HIGH-VALUES. 02 StudentNumber PIC 9(7). 02 StudentName PIC X(60). 02 CourseCode PIC X(4). 02 FeesOwed PIC 9(4). 02 AmountPaid PIC 9(4)V99.

COPY Example Copy member resides in OPERN.CICS3.COPYLIB

Page 25: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 25

CALL Verb Is the most important verb that provides structured

programming capabilities in COBOL.

Is equivalent to a function or a sub-routine call in other computer languages.

Is similar to the COPY verb, in the sense that it provides code re-usability.

Provides two ways of passing parameters to the called program(1) By REFERENCE and (2) By CONTENT.

Page 26: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 26

Syntax of call statement

CALL NAME OF THE SUB PROGRAM

USING THE PARAMETER NAMES

Example

CALL SUBPGM1 USING NUM1,NUM2

Page 27: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 27

Passing by reference and value

By REFERENCE– CALL SUBPGM1 USING WS-NUM1.

BY VALUE– CALL SUBPGM1 USING

BY CONTENT WS-NUM1

BY REFERENCE WS-NUM2

BY REFERENCE WS-NUM3.

Page 28: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 28

Rules for coding CALLed Programs

The CALLed programs should have a LINKAGE SECTION in the DATA DIVISION.

If the CALLed programs possess WORKING-STORAGE SECTION, then the LINKAGE SECTION must appear after it.

The PROCEDURE DIVISION of the CALLed program must have a USING clause to identify the variables passed from the CALLing program.

DATA DIVISION.

WORKING –STORAGE SECTION.

----

LINKAGE SECTION.

01 WS-NUM1 PIC 9(3).

01 WS-NUM2 PIC 9(3).

DATA DIVISION.

WORKING –STORAGE SECTION.

----

LINKAGE SECTION.

01 WS-NUM1 PIC 9(3).

01 WS-NUM2 PIC 9(3).

PROCEDURE DIVISION USING WS-NUM1,WS-NUM2

Page 29: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 29

The variables defined in the LINKAGE SECTION can be defined in any order.

The variables in the USING clause must be in the same order as 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 the control back to the CALLed program.

Rules for coding CALLed Programs

DATA DIVISION.

WORKING –STORAGE SECTION.

----

LINKAGE SECTION.

01 WS-NUM1 PIC 9(3).

01 WS-NUM2 PIC 9(3).

PROCEDURE DIVISION USING WS-NUM1,WS-NUM2.

A001-MAIN-PARA.

-----

EXIT PROGRAM

Page 30: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 30

Review

Index sequential file organization.

Relative file organization.

The COPY verb.

The CALL verb.

Page 31: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 31

Review questions DELETE statement should be followed by ( file/record)

_________ For updation and deletion, the files are to be opened in

___________________ mode COPY statement is allowed only in the data division

( True / false )

Indicate which of the following COBOL verb does not use FROM phrase– ACCEPT– DISPLAY– PERFORM– WRITE

File name

Input-output (I-O)

Page 32: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 32

Review Questions LINKAGE SECTION cannot have any

value clause (True / False )

RENAMES clause cannot be used in LINKAGE SECTION (True / False )

COPY statement is executed during compile time rather then run time ( True/ False)

Page 33: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 33

Any Questions ????

Page 34: CobolDay4

04/11/23 09:25 E&R Dept., ITLInfosys 34

Thank you

Jyothi Sridhar Kini

E&R, Infosys

Mail-id: [email protected]

Phone: 52179