87
Jyothi Sridhar Kini E&R, Infosys Mail-id: [email protected] Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Jyothi Sridhar Kini E&R, Infosys Mail-id: [email protected]@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Embed Size (px)

Citation preview

Page 1: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Jyothi Sridhar KiniE&R, Infosys

Mail-id: [email protected]: 52179

Programming in COBOL-85

For IBM Mainframe System 390

Page 2: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Course Plan

Day 1: Introduction to COBOL

Day 2: Cobol Language constructs

Day 3: Sequential File Handling

Day 4: Index sequential file handling, COPY, CALL

Day 5,6,7: Working on project

Page 3: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Pre-requisites

Programming Fundamentals.

MVS Operating system and its subsystem TSO.

Job Control Language to submit jobs to MVS.

Navigating through ISPF.

Page 4: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Topics beyond the scope

Report writer feature of COBOL

Page 5: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

References

TITLE AUTHOR PUBLISHER

COBOL Programming

M.K.Roy and D. Ghosh Dastidar

Tata McGraw Hill

COBOL Programming

Nancy Stern and Robert Stern

John Wiley & Sons Inc

Programming with Structured COBOL

Newcomer and Lawrence

McGraw Hill Books

(Schaum Series)

Any Time reference IBM manuals

Page 6: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Agenda for Day 1

Evolution and Features of COBOL.

General Coding and Format rules.

Language Fundamentals.

Input and Output verbs.

Arithmetic verbs.

Design and development of simple COBOL programs

Page 7: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Early years.

ANS Versions of COBOL.

Future of COBOL.

http://www.home.swbell.net/mck9/cobol/cobol.html

http://www.infogoal.com/cbd/cbdhome.html

History of COBOL

Page 8: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

1960 – COBOL (Common Business Oriented Language) initial specifications presented by CODASYL (Conference on Data System Languages)

1964 – revised to make COBOL more flexible 1968 – ANSI (American National Standards Institute)

developed American National Standard (ANS) COBOL– Standardized form– Attempted to overcome incompatibilities of different

versions of COBOL 1974 – ANSI published revised version of (ANS) COBOL

– Business applications needed to manipulate character as well as numeric data

– String operations added

History of COBOL

Page 9: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

1985 – ANSI published another revised version of COBOL– Designed to take advantage of structured

programming techniques– Logic errors reduced with END statements– Case statement reduced nested IFs– Less English-like– Maintained readability and business orientation– Compatible with previous versions

History of COBOL

Page 10: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

COBOL

COBOL is an acronym which stands forCOmmon Business Oriented Language.

The name indicates the target area of COBOL applications.

COBOL is used for developing business, typically file-oriented, applications.

It is not designed for writing systems programs. You would not develop an operating system or a compiler using COBOL.

COBOL is one of the oldest computer languages in use (it was developed in late 1950s).

Page 11: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

CODSYL

Page 12: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Nature of COBOL

Business Oriented Language.

Standard Language.

Robust Language.

Structured Programming Language.

English-like Language.

Page 13: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Structure of a COBOL program

PROGRAM

DIVISIONS

SECTIONS

PARAGRAPHS

SENTENCES

STATEMENTS

RESERVEDWORDS

USER DEFINEDWORDS

CHARACTERS

Page 14: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

COBOL Character set

Alphabets (Both upper and lower case)

Digits (0 to 9)

Special characters

b - + *

/ = $ ,

; . “ ‘

< > ( )

Page 15: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

The COBOL DIVISIONs

DIVISIONS are used to identify the principal components of the program text. There are four DIVISIONS in all.

IDENTIFICATION DIVISION.

ENVIRONMENT DIVISION. // Optional

DATA DIVISION. // Optional

PROCEDURE DIVISION.

Page 16: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

IDENTIFICATION DIVISION

The purpose of the IDENTIFICATION DIVISION is to provide information about the program to the programmer and to the compiler.

Most of the entries in the IDENTIFICATION DIVISION are directed at the programmer and are treated by the compiler as comments.

Page 17: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

IDENTIFICATION DIVISION...

An exception to this is the PROGRAM-ID clause. Every COBOL program must have a PROGRAM-ID. It is used to enable the compiler to identify the program.

There are several other informational paragraphs in the IDENTIFICATION DIVISION but we will ignore them for the moment.

Page 18: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

IDENTIFICATION DIVISION...

The IDENTIFICATION DIVISION has the following structureIDENTIFICATION DIVISION.PROGRAM-ID. PGM-NAME.[AUTHOR. YourName.]

IDENTIFICATION DIVISION.PROGRAM-ID. FIRSTPGM.AUTHOR. Michael Coughlan.

IDENTIFICATION DIVISION.PROGRAM-ID. FIRSTPGM.AUTHOR. Michael Coughlan.

Page 19: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

IDENTIFICATION DIVISION...The keywords IDENTIFICATION DIVISION

represent the division header and signal the commencement of the program text.

The paragraph name PROGRAM-ID is a keyword. It must be specified immediately after the division header.

The program name can be up to 8 characters long on MF(30 in case of windows).

Page 20: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

IDENTIFICATION DIVISION...

IDENTIFICATION DIVISION. PROGRAM-ID. Member-name. ( Max 8 chars, letters & digits only )

AUTHOR. / Optional entry INSTALLATION. / Optional entryDATE-WRITTEN. / Optional entry DATE-COMPILED. / Optional entry

Is used to identify the program to the computer.

Is the least significant DIVISION of a COBOL program.

Page 21: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

ENVIRONMENT DIVISION

The ENVIRONMENT DIVISION is totally optional unless you want to use files / specify special devices to the compiler in your program.

Is used to indicate the Specific Computers used to develop and execute the program.The general format of ED is

ENVIRONMENT DIVISION.CONFIGURATION SECTION.SOURCE-COMPUTER. VAX-6410.OBJECT-COMPUTER. IBM-ES9000.INPUT-OUTPUT SECTION.FILE-CONTROL.

SELECT EMPL-FILE ASSIGN TO DISC.

...

ENVIRONMENT DIVISION.CONFIGURATION SECTION.SOURCE-COMPUTER. VAX-6410.OBJECT-COMPUTER. IBM-ES9000.INPUT-OUTPUT SECTION.FILE-CONTROL.

SELECT EMPL-FILE ASSIGN TO DISC.

...

Page 22: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

The DATA DIVISION

The DATA DIVISION is used to describe most of the data that a program processes.

The DATA DIVISION has two main sections-– FILE SECTION.– WORKING-STORAGE SECTION.

The FILE SECTION is used to describe most of the data that is sent to, or comes from, the computer’s peripherals.

The WORKING-STORAGE SECTION is used to describe the general variables used in the program.

Page 23: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

DATA DIVISION

DATA DIVISION. / Optional entry FILE SECTION.FD filename. . . . . . . SD sortfile. . . . . . .WORKING-STORAGE SECTION.. . . . . . .

Is used to describe the structure of the fields, records, files and temporary variables used for calculations.

Page 24: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

PROCEDURE DIVISION

Is the most significant DIVISION of a COBOL program.

Includes statements and sentences necessary for reading input, processing it and writing the output. These are theinstructions that are executed by the computer at the RUN TIME.

Page 25: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

PROCEDURE DIVISION…

The PROCEDURE DIVISION is where all the data described in the DATA DIVISION is processed and produced desired results. It is here that the programmer describes his algorithm.

The PROCEDURE DIVISION is hierarchical in structure and consists of Sections, Paragraphs, Sentences and Statements.

Page 26: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

PROCEDURE DIVISION...

Only the Section is optional. There must be at least one paragraph, sentence and statement in the PROCEDURE DIVISION .

In the PROCEDURE DIVISION, paragraph and section names are chosen by the programmer.

The names used should reflect the processing being done in the paragraph or section.

Page 27: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Sections A SECTION is a block of code made up of one

or more paragraphs.

A SECTION begins with the section-name and ends where next section name is encountered or where the program text ends.

A SECTION name consists of a name devised by the programmer or defined by the language followed by the word SECTION followed by a full stop.

– U0000-SELECT-USER-RECORDS SECTION.– FILE SECTION.

Page 28: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Paragraphs

Each section consists of one or more paragraphs. A PARAGRAPH is a block of code made up of

one or more sentences. A PARAGRAPH begins with the paragraph-

name and ends with the next paragraph or section name or the end of the program text.

The paragraph-name consists of a name devised by the programmer or defined by the language followed by a full stop.

– P0000-PRINT-FINAL-TOTALS.– PROGRAM-ID.

Page 29: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Sentences and Statements

A PARAGRAPH consists of one or more sentences. A SENTENCE consists of one or more statements and is terminated by

a full stop.– MOVE .21 TO VAT-RATE

COMPUTE VAT-AMOUNT = PRODUCT-COST * VAT-RATE.

– DISPLAY "Enter Name " WITH NO ADVANCINGACCEPT STUDENT-NAMEDISPLAY "Name Entered was " STUDENT-NAME.

A STATEMENT consists of a COBOL verb and an operand or operands.

– SUBTRACT T-TAX FROM GROSS-PAY GIVING NET-PAY

– READ STUDENT-FILE AT END SET END-OF-FILE TO TRUEEND-READ

Page 30: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

First COBOL program

IDENTIFICATION DIVISION.PROGRAM-ID.FIRSTPGM.AUTHOR. Michael Coughlan.DATA DIVISION.WORKING-STORAGE SECTION.01 WS-NUM-1 PIC 9(001) VALUE ZEROS.01 WS-NUM-2 PIC 9(001) VALUE ZEROS.01 WS-RESULT-1 PIC 9(002) VALUE ZEROS.PROCEDURE DIVISION.A0000-MAIN-PARA. ACCEPT WS-NUM-1 ACCEPT WS-NUM-2 MULTIPLY WS-NUM-1 BY WS-NUM-2 GIVING

WS-RESULT-1 DISPLAY "Result is = ", WS-RESULT-1 STOP RUN

.

IDENTIFICATION DIVISION.PROGRAM-ID.FIRSTPGM.AUTHOR. Michael Coughlan.DATA DIVISION.WORKING-STORAGE SECTION.01 WS-NUM-1 PIC 9(001) VALUE ZEROS.01 WS-NUM-2 PIC 9(001) VALUE ZEROS.01 WS-RESULT-1 PIC 9(002) VALUE ZEROS.PROCEDURE DIVISION.A0000-MAIN-PARA. ACCEPT WS-NUM-1 ACCEPT WS-NUM-2 MULTIPLY WS-NUM-1 BY WS-NUM-2 GIVING

WS-RESULT-1 DISPLAY "Result is = ", WS-RESULT-1 STOP RUN

.

Page 31: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

The minimum COBOL program

IDENTIFICATION DIVISION.PROGRAM-ID. SMALLPGM.

PROCEDURE DIVISION.A0000-DISPLAY-PARA. DISPLAY "I did it." STOP RUN

.

IDENTIFICATION DIVISION.PROGRAM-ID. SMALLPGM.

PROCEDURE DIVISION.A0000-DISPLAY-PARA. DISPLAY "I did it." STOP RUN

.

What is the model we have used to What is the model we have used to describe thedescribe theCOBOLCOBOL program structure? program structure?

TOP-DOWNTOP-DOWN

Page 32: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

COBOL coding rules

Almost all COBOL compilers treat a line of COBOL code as if it contained two distinct areas. These are known as; Area A and Area B

When a COBOL compiler recognizes these two areas, all division, section, paragraph names, FD entries and 01 level entries must start in Area A. All other sentences/statements must start in Area B.

Area A is four characters wide and is followed by Area B.

Page 33: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

COBOL coding rules...

In some COBOL compilers these coding restrictions are removed.

– For example In Microfocus COBOL compiler directive$ SET SOURCEFORMAT"FREE" frees us from all formatting restrictions.

$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. ProgramFragment.* This is a comment. It starts* with an asterisk in column 1

$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. ProgramFragment.* This is a comment. It starts* with an asterisk in column 1

Page 34: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

COBOL coding sheet

Column numbers

1 2 3 4 5 6 7 8 9 10 11

12 72

80

Column numbers

* Area A Area B I

D

E

N

T

I

F

I

C

A

T

I

O

N

A

R

E

A

-

/

Page 35: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

COBOL coding rules Each line is considered to be made up of 80

columns.

Columns 1 to 6 are reserved for line numbers.

Column 7 is an indicator column and has special meaning to the compiler.

Asterisk ( * ) indicates commentsHyphen ( - ) indicates continuationSlash ( / ) indicates form feed

Page 36: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

COBOL coding rules

Columns 8 to 11 are called Area A. All COBOL DIVISIONs, SECTIONs, paragraphs and some special entries must begin in Area A.

Columns 12 to 72 are called Area B. All COBOL statements must begin in Area B.

Columns 73 to 80 are identification area.

Page 37: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

COBOL data description

COBOL uses what could be described as a “declaration by example” strategy.

In effect, the programmer provides the system with an example, or template, or PICTURE of what the data item looks like.

From the “picture” the system derives the information necessary to allocate it.

Page 38: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Basic data types

Alphabetic

Numeric

Alphanumeric

Edited numeric

Edited alphanumeric

Page 39: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Literals

Literals are symbols whose value does not change in a program.

There are 3 types of literals namely

(1) Numeric literals.

(2) Non-numeric literals.

(3) Figurative constants.

Page 40: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Literals

Are formed using digits only.

May include a sign which must be the extreme left character.

There must not be any blank between the sign and the first digit.

May include a decimal point which can not be the right most character.

Can have at most 18 digits.

Numeric literals

Page 41: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Literals

Are used display headings or messages.

Are a sequence of characters (except quotes) from

the COBOL character set enclosed within quotes.

May contain up to 160 characters including spaces.

Non-numeric literals

Page 42: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Literals

Figurative constants Meaning

ZERO(S) or ZEROES Represents the value 0, one ormore depending on the context

SPACE(S) Represents one or more spaces

HIGH-VALUE(S) Represents the highest value

LOW-VALUE(S) Represents the lowest value

QUOTE(S) Represents single or double quotes

Figurative constants

Page 43: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Data names

Are named memory locations.

Must be described in the DATA DIVISION before they can be used in the PROCEDURE DIVISION.

Can be of elementary or group type.

Can be subscripted.

Are user defined words.

Page 44: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Rules for forming User-defined words

Are used to form section, paragraph and data names.

Can be at most 30 characters in length.

Only alphabets, digits and hyphen are allowed.

Blanks are not allowed.

May not begin or end with a hyphen.

Should not be a COBOL reserved word.

Page 45: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Description of data names

All the data names used in the PROCEDURE DIVISION must be described in the DATA DIVISION.

The description of a data name is done with the aid of

(1) Level number

(2) PICTURE clause

(3) VALUE clause

Page 46: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Description of data names

Is used to specify the the data hierarchy.

Level number

Level Number Purpose

01 Record description and independent items

02 to 49 Fields within records and sub items

66 RENAMES clause

77 Independent items

88 Condition names

Page 47: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Description of data names

Is used to specify the following

(1) The data type

(2) The storage requirement.

Can be abbreviated as PIC.

Can be abbreviated in case of recurring symbols.

Is used only elementary items.

PICTURE clause

Page 48: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Description of data names PICTURE clause

Code Meaning

9 Numeric

A Alphabetic

X Alphanumeric

V Decimal Point

S Sign bit

Page 49: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Description of data names

VALUE clause

Is used to assign an initial value to a elementary data item.

The initial value can be numeric literal, non- numeric literal or figurative constant.

Is an optional clause.

Page 50: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Group and elementary items

In COBOL the term “group item” is used to describe a data item which has been further subdivided.– A Group item is declared using a level

number and a data name. It cannot have a picture clause.

– Where a group item is the highest item in a data hierarchy it is referred to as a record and uses the level number 01.

Page 51: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Group and elementary items..

The term “elementary item” is used to describe data items which are atomic, that is, not further subdivided.

An elementary item declaration consists of; • a level number, • a data name • picture clause.

An elementary item must have a picture clause. Every group or elementary item declaration must

be followed by a full stop.

Page 52: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

PICTURE Clauses for Group Items

Picture clauses are NOT specified for ‘group’ data items because the size of a group item is the sum of the sizes of its subordinate, elementary items and its type is always assumed to be PIC X.

The type of a group items is always assumed to be PIC X, because group items may have several different data items and types subordinate to them.

An X picture is the only one which could support such collections.

Page 53: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

H E N N E S S Y R M 9 2 3 0 1 6 5 L M 5 1 0 5 5 0 F

Group Items/Records - Example

STUDENT-DETAILS

WORKING-STORAGE SECTION.01 STUDENT-DETAILS PIC X(026).

WORKING-STORAGE SECTION.01 STUDENT-DETAILS PIC X(026).

Page 54: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

H E N N E S S Y R M 9 2 3 0 1 6 5 L M 5 1 0 5 5 0 F

STUDENT-DETAILS

STUDENT-NAMESTUDENT-NAME STUDENT-IDSTUDENT-ID COURSE-CODE GRANT GENDERCOURSE-CODE GRANT GENDER

Group Items/Records - Example

WORKING-STORAGE SECTION.01 STUDENT-DETAILS.

0202 STUDENT-NAMESTUDENT-NAME PIC X(010).PIC X(010).0202 STUDENT-IDSTUDENT-ID PIC 9(007).PIC 9(007).0202 COURSE-CODECOURSE-CODE PIC X(004).PIC X(004).0202 GRANTGRANT PIC 9(004).PIC 9(004).0202 GENDERGENDER PIC X(001).PIC X(001).

WORKING-STORAGE SECTION.01 STUDENT-DETAILS.

0202 STUDENT-NAMESTUDENT-NAME PIC X(010).PIC X(010).0202 STUDENT-IDSTUDENT-ID PIC 9(007).PIC 9(007).0202 COURSE-CODECOURSE-CODE PIC X(004).PIC X(004).0202 GRANTGRANT PIC 9(004).PIC 9(004).0202 GENDERGENDER PIC X(001).PIC X(001).

Page 55: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

H E N N E S S Y R M 9 2 3 0 1 6 5 L M 5 1 0 5 5 0 F

STUDENT-DETAILS

SURNAME INITIALS

WORKING-STORAGE SECTION.01 STUDENT-DETAILS.

0202 STUDENT-NAME.STUDENT-NAME.03 SURNAME03 SURNAME PIC X(008).PIC X(008).03 INITIALS03 INITIALS PIC X(002).PIC X(002).

0202 STUDENT-ID STUDENT-ID PIC 9(007).PIC 9(007).0202 COURSE-CODE COURSE-CODE PIC X(004).PIC X(004).0202 GRANT GRANT PIC 9(004).PIC 9(004).0202 GENDER GENDER PIC X(001).PIC X(001).

WORKING-STORAGE SECTION.01 STUDENT-DETAILS.

0202 STUDENT-NAME.STUDENT-NAME.03 SURNAME03 SURNAME PIC X(008).PIC X(008).03 INITIALS03 INITIALS PIC X(002).PIC X(002).

0202 STUDENT-ID STUDENT-ID PIC 9(007).PIC 9(007).0202 COURSE-CODE COURSE-CODE PIC X(004).PIC X(004).0202 GRANT GRANT PIC 9(004).PIC 9(004).0202 GENDER GENDER PIC X(001).PIC X(001).

STUDENT-NAMESTUDENT-NAME STUDENT-IDSTUDENT-ID COURSE-CODECOURSE-CODE GRANTGRANT GENDERGENDER

Group Items/Records

Page 56: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

LEVEL Numbers & DATA hierarchy

In COBOL, level numbers are used to decompose a structure into it’s constituent parts.

In this hierarchical structure the higher the level number, the lower the item is in the hierarchy. At the lowest level the data is completely atomic.

The level numbers 01 through 49 are general level numbers, but there are also special level numbers such as 66, 77 and 88.

In a hierarchical data description what is important is the relationship of the level numbers to one another, not the actual level numbers used.

01 STUDENT-DETAILS.02 STUDENT-NAME.

03 SURNAME PIC X(008).03 INITIALS PIC X(002).

02 STUDENT-ID PIC 9(007).02 COURSE-CODE PIC X(004).02 GRANT PIC 9(004).02 GENDER PIC X(001).

01 STUDENT-DETAILS.02 STUDENT-NAME.

03 SURNAME PIC X(008).03 INITIALS PIC X(002).

02 STUDENT-ID PIC 9(007).02 COURSE-CODE PIC X(004).02 GRANT PIC 9(004).02 GENDER PIC X(001).

01 STUDENT-DETAILS.05 STUDENT-NAME.

10 SURNAME PIC X(008).10 INITIALS PIC X(002).

05 STUDENT-ID PIC 9(007).05 COURSE-CODE PIC X(004).05 GRANT PIC 9(004).05 GENDER PIC X(001).

01 STUDENT-DETAILS.05 STUDENT-NAME.

10 SURNAME PIC X(008).10 INITIALS PIC X(002).

05 STUDENT-ID PIC 9(007).05 COURSE-CODE PIC X(004).05 GRANT PIC 9(004).05 GENDER PIC X(001).

Page 57: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Description of data names

Example

DATA DIVISION.WORKING-STORAGE SECTION.01 WS-REGNO PIC X(5).01 WS-NAME.

05 WS-FIRST-NAME PIC A(15).05 WS-MID-NAME PIC A(15).05 WS-LAST-NAME PIC A(10).

01 WS-AGE PIC 99V99. 01 WS-SCHOLARSHIP PIC 9(4) VALUE 1000.

Page 58: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Break

Page 59: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Edited picture symbols

Edit symbol Meaning

Z Zero suppression

* Check protection

, Comma insertion

- Minus sign insertion

+ Plus or minus sign insertion

Page 60: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Edited picture symbols

Edit symbol Meaning

$ Dollar sign insertion

CR Credit symbol

DB Debit symbol

B Blank insertion

/ Slash insertion

. Decimal point insertion

BLANK WHEN ZERO Blank insertion when the value is zero.

Page 61: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Data movement verb.

Arithmetic Verbs.

Input / Output Verbs.

Sequence control verbs.

File handling verbs.

PROCEDURE DIVISION Verbs

Page 62: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

ACCEPT Verb

Syntax

ACCEPT identifier [ FROM { DATE, DAY, TIME, mnemonic-name }].

Examples

(1) ACCEPT NUMBER-1.

(2) ACCEPT TODAY-DATE FROM DATE.

Input / Output Verbs

Page 63: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

DISPLAY Verb

Syntax

DISPLAY { identifier-1, literal-1 } , . . .

Examples

(1) DISPLAY “The sum is ” SUM.

Input / Output Verbs

Page 64: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Arithmetic Verbs

ADD

SUBTRACT

MULTIPLY

DIVIDE

COMPUTE

Page 65: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

ADD Verb Syntax-1

ADD { identifier-1, literal-1 } [ , identifier-2, literal-2 ] . . . TO identifier-3 [ , identifier-4 ] . . .

Syntax-2

ADD { identifier-1, literal-1 } { identifier-2, literal-2 } [ identifier-3, literal-3 ] GIVING identifier-4 . . .

Page 66: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

ADD Verb

Examples

(1) ADD NUM-1 TO NUM-2.

(2) ADD NUM-1, NUM-2 TO NUM-3.

(3) ADD 12, NUM-1, NUM-2 TO NUM-3, NUM-4.

(4) ADD NUM-1, NUM-2 GIVING NUM-3.

(5) ADD 12, NUM-1 GIVING NUM-2, NUM-3.

Page 67: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

ADD Examples

ADD Cash TO Total.BeforeBefore 3 1000AfterAfter

ADD Cash, 20 TO Total, Wage.Before Before 3 1000 100AfterAfter

ADD Cash, Total GIVING Result.BeforeBefore 3 1000 0015AfterAfter

ADD Males TO Females GIVING TotalStudents.Before Before 1500 0625 1234AfterAfter

ADD Cash TO Total.BeforeBefore 3 1000AfterAfter

ADD Cash, 20 TO Total, Wage.Before Before 3 1000 100AfterAfter

ADD Cash, Total GIVING Result.BeforeBefore 3 1000 0015AfterAfter

ADD Males TO Females GIVING TotalStudents.Before Before 1500 0625 1234AfterAfter

3 1003

3 1023 123

3 1000 1003

1500 0625 2125

Page 68: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

SUBTRACT Verb

Syntax

SUBTRACT { identifier-1, literal-1 } [ identifier-2,

literal-2 ] . . . FROM identifier-3 [ , identifier-4 ]

[ , GIVING identifier-5 [ , identifier-6 ] . . . ]

Page 69: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

SUBTRACT Verb

Examples

(1) SUBTRACT NUM-1 FROM NUM-2.

(2) SUBTRACT NUM-1, NUM-2 FROM NUM-3.

(3) SUBTRACT 5, NUM-1 FROM NUM-2, NUM-3.

(4) SUBTRACT 12 FROM NUM-1 GIVING NUM-2.

(5) SUBTRACT NUM-1 FROM NUM-2 GIVING NUM-3.

Page 70: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

SUBTRACT Examples

SUBTRACT Tax FROM GrossPay, Total.Before Before 120 4000 9120 AfterAfter

SUBTRACT Tax, 80 FROM Total.Before Before 100 480AfterAfter

SUBTRACT Tax FROM GrossPay GIVING NetPay.BeforeBefore 750 1000 0012AfterAfter

SUBTRACT Tax FROM GrossPay, Total.Before Before 120 4000 9120 AfterAfter

SUBTRACT Tax, 80 FROM Total.Before Before 100 480AfterAfter

SUBTRACT Tax FROM GrossPay GIVING NetPay.BeforeBefore 750 1000 0012AfterAfter

120 3880 9000

100 300

750 1000 0250

Page 71: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

MULTIPLY Verb

Syntax

MULTIPLY { identifier-1, literal-1 } BY identifier-2

[ identifier-3 ] . . . [ , GIVING identifier-4

[ , identifier-5 ] . . . ]

Page 72: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

MULTIPLY Verb

Examples

(1) MULTIPLY NUM-1 BY NUM-2.

(2) MULTIPLY NUM-1 BY NUM-2 GIVING NUM-3.

(3) MULTIPLY 5 BY NUM-1 GIVING NUM-2.

(4) MULTIPLY NUM-1 BY NUM-2 GIVING

NUM-4, NUM-5.

Page 73: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

DIVIDE Verb Syntax-1

DIVIDE { identifier-1, literal-1 } INTO identifier-2

[ , identifier-2 ] . . . [ GIVING identifier-4

[ , identifier-5 ] . . . ] ..

Syntax-2

DIVIDE { identifier-1, literal-1 } BY { identifier-2,

literal-2 } GIVING identifier-3 [ , identifier-4 ].

Page 74: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

DIVIDE Verb

Syntax-3

DIVIDE { identifier-1, literal-1 } { INTO , BY }

{ identifier-2, literal-2 } GIVING identifier-3

REMAINDER identifier-4 .

Page 75: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

DIVIDE Verb

Examples

(1) DIVIDE 5 INTO NUM-1.

(2) DIVIDE 6 INTO NUM-1 GIVING NUM-2, NUM-3.

(3) DIVIDE NUM-1 BY 3 GIVING NUM-2, NUM-3.

(4) DIVIDE NUM-1 BY NUM-2 GIVING NUM-3.

(5) DIVIDE NUM-1 BY NUM-2 GIVING NUM-3

REMAINDER NUM-4.

Page 76: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

MULTIPLY and DIVIDEMULTIPLY Subs BY Members GIVING TotalSubs

ON SIZE ERROR DISPLAY "TotalSubs too small" END-MULTIPLY. Subs Members TotalSubsSubs Members TotalSubs

BeforeBefore 15.50 100 0123.45AfterAfter

MULTIPLY 10 BY Magnitude, Size.

BeforeBefore 355 125AfterAfter

DIVIDE Total BY Members GIVING Average ROUNDED.BeforeBefore 9234.55 100 1234.56AfterAfter

MULTIPLY Subs BY Members GIVING TotalSubs ON SIZE ERROR DISPLAY "TotalSubs too small" END-MULTIPLY. Subs Members TotalSubsSubs Members TotalSubs

BeforeBefore 15.50 100 0123.45AfterAfter

MULTIPLY 10 BY Magnitude, Size.

BeforeBefore 355 125AfterAfter

DIVIDE Total BY Members GIVING Average ROUNDED.BeforeBefore 9234.55 100 1234.56AfterAfter

15.50 100 1550.00

3550 1250

9234.55 100 92.35

Page 77: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

ROUNDED Option

Syntax

Arithmetic statement [ ROUNDED ].

Examples

(1) ADD NUM-1, NUM-2, NUM-3 GIVING NUM-4ROUNDED.

(2) DIVIDE NUM-1 BY NUM-2 GIVING NUM-3 ROUNDED.

Page 78: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

The ROUNDED option

Receiving Field Actual Result Truncated Result Rounded Result

PIC 9(3)V9. 123.25

PIC 9(3). 123.25

123.2 123.3

123 123

The The ROUNDEDROUNDED option takes effect when, after option takes effect when, after decimal point alignment, the result calculated decimal point alignment, the result calculated must be truncated on the right hand side. must be truncated on the right hand side.

The option adds 1 to the receiving item when the The option adds 1 to the receiving item when the leftmost truncated digit has an absolute value of 5 leftmost truncated digit has an absolute value of 5 or greater.or greater.

Page 79: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

ON SIZE ERROR Option Syntax

Arithmetic statement [ON SIZE ERROR imperative statement . . .]

Examples

(1) ADD NUM-1, NUM-2, NUM-3 TO NUM-4 ON SIZE

ERROR PERFORM 900-EXIT-PARA.

(2). DIVIDE NUM-1 BY NUM-2 ON SIZE ERROR

PERFORM 800-ERROR-PARA.

Page 80: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

A size error condition exists when, after decimal A size error condition exists when, after decimal point alignment, the result is truncated on either point alignment, the result is truncated on either the the leftleft or the or the rightright hand side.hand side.

If an arithmetic statement has a rounded phrase If an arithmetic statement has a rounded phrase then a size error only occurs if there is truncation then a size error only occurs if there is truncation on the on the leftleft hand side (most significant digits). hand side (most significant digits).

Receiving Field Actual Result SIZE ERROR

PIC 9(3)V9. 245.96

PIC 9(3)V9. 1245.9

PIC 9(3). 124

PIC 9(3). 1246

PIC 9(3)V9 Not Rounded 124.45

PIC 9(3)V9 Rounded 124.45

PIC 9(3)V9 Rounded 3124.45

On size error option

Yes

Yes

No

Yes

Yes

No

Yes

Page 81: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

COMPUTE Verb

Syntax

COMPUTE identifier-1 . . . [ ROUNDED ]

= algebraic expression [ ON SIZE ERROR ]

imperative statement. Example

COMPUTE VOLUME = ( 4 / 3) * ( 22 / 7 ) * R ** 3.

Note: If the ROUNDED and ON SIZE ERROR both appear, then the ROUNDED option should precede the ON SIZE ERROR.

Page 82: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Compute IrishPrice = SterlingPrice / Rate * 100.Before Before 1000.50 156.25 87 AfterAfter

Compute IrishPrice = SterlingPrice / Rate * 100.Before Before 1000.50 156.25 87 AfterAfter 179.59 156.25 87

The COMPUTE

COMPUTE Identifier [ ROUNDED ] . . . = ArithmeticExpression

ON SIZE ERROR

NOT ON SIZE ERROR StatementBlock END - COMPUTE

Precedence Rules.Precedence Rules.1.1. **** = POWER NN

2.2. ** = MULTIPLY x// = DIVIDE ÷

3.3. ++ = ADD +-- = SUBTRACT -

Precedence Rules.Precedence Rules.1.1. **** = POWER NN

2.2. ** = MULTIPLY x// = DIVIDE ÷

3.3. ++ = ADD +-- = SUBTRACT -

Page 83: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

ReviewFeatures of COBOL.

General Coding and Format rules.

Language Fundamentals.

Input and Output verbs.

Arithmetic verbs.

Page 84: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Review questions If an entry must begin in area A ,it must begin in

If an entry must begin in area B,it must begin in position

Program-id is the paragraph name that appears in the

The word rounded (precedes, follows) the ON SIZE ERROR clause in an arithmetic statement

Column number 8,9,10,11

12 to 72 any where;

identification division

precedes

Page 85: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Review questions

A numeric literal in COBOL can have at most A Non numeric literal can have maximum

Indicate True or False– A 01 level entry cannot have a picture class – In COBOL a data name must contain at least 8

characters – A COBOL sentence consists of one or more than one

statement the last of which is terminated by a period

18 digits

160 characters including spaces

False

False

True

Page 86: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Any Questions ????

Page 87: Jyothi Sridhar Kini E&R, Infosys Mail-id: Jyothis@infosys.comJyothis@infosys.com Phone: 52179 Programming in COBOL-85 For IBM Mainframe System 390

Thank you

Jyothi Sridhar Kini

E&R, Infosys

Mail-id: [email protected]

Phone: 52179