Session 1: What Is COBOL? History Features

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 44

SESSION 1

What is COBOL?
History
Features

1
What is COBOL?

 Abbreviation of COmmon Business Oriented Language


 One of the oldest computer languages in use (Was developed in late 1950s)
 Mainly Used for Information processing in Business Applications
 Used for generating reports through Batch Processing
 Batch processing is also known as periodical processing

Batch Processing Examples: Generation of Utility Bills, Payroll Processing etc.

Also used in Online applications under CICS environment.

Online Processing Examples: Railway/Airline Reservation System, Online


Banking etc.

2
Advantages of Cobol

 High Level Language


 English-like constructs
 Self-documenting Language
 File handling capability
 Easy to write
 Available across several platforms
 Largely Machine independent

3
History of Cobol

COBOL was Developed In 1959 By A Group Called CODASYL (COnference on


DAta SYstems Language).

Later ANSI standards were introduced

COBOL – 68
COBOL – 74
COBOL – 85
COBOL – 2003 ( Enterprise COBOL )

4
Future of Cobol

 COBOL will remain an important language in future also


 Billions of lines of COBOL source are currently in use with millions added each
year
 1000s of COBOL programmers retire every year
 There is a continuous requirement of TRAINED man power in COBOL for
Maintenance and Development of COBOL based applications.

5
Features Of COBOL

• Oriented towards business applications

• English-like

• Self-Documenting

• Machine independent

• Easy to Learn / Read / Write / Test

• I/O operations easily designated

• Structured Programming Support

6
COMPARISON OF IBM COBOL EXTENSIONS
FOR OOCOBOL,
COMPILERS C INTEROP.

INTRINSIC INTRINSIC
FUNCTIONS, FUNCTIONS,
SUPPORT FOR SUPPORT FOR
LANGUAGE LANGUAGE
ENVIRONMENT ENVIRONMENT

COBOL 85 STD. COBOL 85 STD. COBOL 85 STD.


DBCS, DBCS, DBCS,
IMPROVED IMPROVED IMPROVED
CICS CICS CICS
INTERFACE, INTERFACE, INTERFACE,
31 BIT 31 BIT 31 BIT
ADDRESSING , ADDRESSING, ADDRESSING,
SAA SUPPORT, SAA SUPPORT, SAA SUPPORT,
COBOL 74 STD. ETC. ETC. ETC.

COBOL 74 STD. COBOL 74 STD. COBOL 74 STD.

OS/VS COBOL VS COBOL II COBOL/370 COBOL FOR MVS & VM


IBM's latest host COBOL compiler

7
Application Development Cycle

- For writing a COBOL program you have to be provided with program


specification by your BUSINESS ANALYST

- ANALYST studies a customer’s requirement for an application package and


prepares an over all design and finally comes out with a detailed specification for
every program to be developed under an application

- The specification will contain the details of INPUT/OUTPUT file descriptions,


OUTPUT report layouts and descriptions, Processing logic and rules, Calculation
methods, etc.

- A Programmer/ Developer writes the code for each module. And tests each
module after development.

- A Tester prepares a plan for testing and also prepares a set of Test data to test
and ensure that the programs work as intended by the designer and customer

8
Business Analyst End User

System Analyst

Programmer Tester

9
Components of a COBOL program

A COBOL PROGRAM IS DIVIDED INTO

• Divisions

• Sections

• Paragraphs

• Sentences

• Statements

• Words

• Characters

10
COBOL Coding Format

Columns
| | | | |
| | | | |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |……………| 71 | 72 |
|---------- 1 ------| |------ ---|------------------------------ 4 ------------------|
3

1. Sequence Number Area


2 2. Indicator Area
3. Area ‘A’ or Margin ‘A’
4. Area ‘B’ or Margin ‘B’

Indicator Area Characters

a. * (Asterisk) – Comment
b. / (Slash) - Comment + page feed
c. - (Hyphen) - String Continuation
11
Source Coding Rules

Sequence Number Area:

Columns 1 – 6 - Line numbers. Each line of code may have a 6 digit


line number. Line numbers to be in ascending order

Indicator Area

* in column 7 Line treated as a comment ; Shown in the source listing

/ in column 7 Line treated as a comment ; Source listing begins a


new page before printing the line

- ( hyphen ) in column 7 Line treated as continuation of previous line

Except when non-numeric literals are continued, all trailing spaces on


the preceding line and all leading spaces on the continuation line, are
ignored

12
Source Coding Rules (contd.) it
Area A

Area A (columns 8 thru 11)

Area A Reserved for DIVISION, SECTION & PARAGRAPH headers, File


description entry indicators (FD & SD), level numbers 01 and 77.

Comment lines also accepted, provided column 7 contains an * or /.

Area B

Area B (Columns 12 – 72 )

Reserved for Filenames associated with FD or SD indicators and the


SELECT clause of Input-Output Section.
Level nos. 02 to 49 and 66 and 88

Descriptive clauses and/or data descriptions that make up specific


paragraph entries. Continuation lines, provided column 7 contains a -
(hyphen).
13
• DIVISIONS/SECTIONS identify various parts of a COBOL program.

• File declarations, descriptions, temporary variables, processing logic,


communication with other programs etc., are handled by various DIVISONS/
SECTIONS of a COBOL program.

There are four DIVISIONS in all.

IDENTIFICATION DIVISION. ( MANDATORY )


ENVIRONMENT DIVISION. ( OPTIONAL )
DATA DIVISION. ( OPTIONAL )
PROCEDURE DIVISION. ( MANDATORY )

14
• The IDENTIFICATION DIVISION is used to specify the name of program
and programmer.

• The ENVIRONMENT DIVISION is used to define the data sets that are used
by a program and links the data sets to the corresponding DD names of JCL

• The DATA DIVISION is used to provide the complete descriptions of data


sets including record description and field description and working storage
variables.

• The PROCEDURE DIVISION contains executable instructions ( statements


containing VERBS ) to process the data contained in DATA DIVISION.

COBOL provides a means for specifying sequence, selection and iteration


constructs to code your processing logic.

15
COBOL coding rules

• COBOL coding lines start in Margin A or Margin B

• DIVISION, SECTION, PARAGRAPH names start in Margin A

• FD entries,01,77 level entries, Procedure division paragraph names start in


Margin A

• STATEMENTS, 02-49, 66, 88 level entries start in Margin B

• Procedure division sentences, statements start in Margin B

16
Sample COBOL program

1 2 3 4 5 6 7
123456789012345678901234567890123456789012345678901234567890123456789012
IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE1.
AUTHOR. SRG.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 NUM1 PIC 9 VALUE ZEROS.
77 NUM2 PIC 9 VALUE ZEROS.
77 RESULT PIC 99 VALUE ZEROS.
77 WS-NAME PIC X(10) VALUE ‘ARICH INFOTECHS’.
PROCEDURE DIVISION.
CALC-RTN1.
ACCEPT NUM1.
ACCEPT NUM2.
MULTIPLY NUM1 BY NUM2 GIVING RESULT.
DISPLAY "RESULT IS = ", RESULT.
STOP RUN.

17
Recap!!!!!!

 What is COBOL and where it is used?

 What are the advantages of COBOL?

 Who is a Business Analyst?

 How is a COBOL Program classified into?

 How many divisions are available in COBOL? Name them.

18
Identification Division

- THE SMALLEST
- USED TO IDENTIFY THE PROGRAM AND AUTHOR
- NO SECTIONS
- CONTAINS ONLY PARAGRAPHS

IDENTIFICATION DIVISION
PROGRAM-ID. TEST123.
AUTHOR. TESM.
INSTALLATION. ARICH INFOTECH.
DATE-WRITTEN. 17-01-2010.
DATE-COMPILED. 18-01-2010.
- PROGRAM-ID is the only required Paragraph for this division.
- Program name can be only 8 characters
- All other entries are optional and for documentation purposes only

19
ENVIRONMENT DIVISION
• This follows the identification division.
• This is the most hardware dependent division.
• The computer and other device requirements are described in this
section.
• It has two sections.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. S390. (where the program is compiled)
OBJECT-COMPUTER. DEC ALPHA. (where the program is executed)
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT employee-master ASSIGN TO DD1
organization is sequential.
I-O-CONTROL.
SPECIAL-NAMES.
CURRENCY SIGN IS literal-1.
DECIMAL POINT IS COMMA.
20
DATA DIVISION

- Has TWO sections FILE SECTION and WORKING-STORAGE SECTION

File Section.

- Describes the characteristics of FILES used in the program RECORD SIZE,


BLOCK SIZE, FORMAT ETC…

- IT CONTIANS RECORD STRUCTURE AND FIELD DESCRIPTION entries.

Working-Storage Section.

- Declare temporary memory variables used in the program.

- In essence, the contents of FILE SECTION variables are stored in the


devices like hard disk/printer where as the contents of WORKING-STORAGE
section are in RAM buffers and are lost once the program is terminated

21
DATA DIVISION

DATA DIVISION HAS Four SECTIONS

• FILE SECTION.
• WORKING-STORAGE SECTION.
• LINKAGE SECTION.
• LOCAL-STORAGE SECTION.
• REPORT SECTION
• SCREEN SECTION.

The last 2 sections are not supported in IBM MAINFRAME COBOL

SCREEN SECTION REQUIREMENTS ARE TAKEN CARE BY THE OLTP


SOFTWARE CICS

22
The DATA DIVISION has the following structure

DATA DIVISION.
FILE SECTION.
……….. FILE SECTION ENTRIES …………..
WORKING-STORAGE SECTION.
……TEMPORARY MEMEORY VARIABLES, GROUP AND
ELEMENTARY ITEMS..

EXAMPLE:
IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE1.
AUTHOR. SRG.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Num1 PIC 9 VALUE ZEROS.
01 Num2 PIC 9 VALUE ZEROS.
01 Result PIC 99 VALUE ZEROS.

23
VARIABLES

Let us start with working-storage section

VARIABLES can be declared in WS section.

Variables are also known as data items or identifiers.

A data item starts with a level number followed by its name, PIC clause and
optionally VALUE and other clauses

A variable name can be maximum of 30 chars consisting of A-Z, 0-9, and


hyphen

No other special characters, no blanks are allowed.

Must have at least one Alphabet

24
DATA ITEMS / VARIABLES

DATA ITEMS CAN BE ELEMENTARY OR GROUP ITEMS

ELEMENTARY ITEM IS ONE THAT IS NOT FURTHER SUBDIVIDED

A SET OF RELATED ELEMENTARY ITEMS IS CALLED A GROUP ITEM

01 LEVEL IS USED FOR DECLARING GROUP ITEMS

ELEMENTARY ITEMS WHICH ARE NOT PART OF ANY GROUP IS


CALLED INDEPENDENT ELEMENTARY ITEMS

Generally Independent elementary items are declared in WS


with level number 77

Independent elementary items can also be declared with level number


01 from COBOL-85 version

25
DATA ITEMS / VARIABLES (Contd.)

01 AND 77 LEVEL ITEM NAMES MUST BE UNIQUE

01 LEVEL IS ALSO USED FOR DECLARING GROUP ITEMS ,


IN WHICH CASE IT MAY HAVE SUB LEVEL ITEMS WITH LEVEL NUMBERS
02-49

02-49 LEVEL DATA ITEMS MAY have duplicates

01 77 levels are used in MARGIN-A where as other levels in MARGIN-B

26
Example Code

01 REC1.
05 ID-FIELD1 PIC XX.
05 AMOUNT PIC 9(5)V99.
05 DESCRIPTION PIC X(40).
01 PRINT-REC1.
05 ID-FIELD PIC XX VALUE SPACES.
05 AMOUNT PIC ZZ,ZZ9.99.
05 DESCRIPTION PIC X(40) VALUE SPACES.
PROCEDURE DIVISION.
……..
SET-PRINT.
MOVE CORRESPONDING REC1 TO PRINT-REC1.

27
COBOL Data Types
There are THREE basic data types in COBOL
Numeric, Alphabetic, Alphanumeric

The contents in ALPHANUMERIC items are left justified


The contents in NUMERIC items are right justified

Poor in type Checking

28
Declare Variables in WS

Variables are declared with a level number, user defined name and PIC clause
WORKING-STORAGE SECTION.
77 WS-NAME PIC X(15) VALUE “ARICH INFOTECH”.

77 WS-CTR1 PIC 9(6) VALUE 1234. 001234

77 WS-CTR2 PIC 9(4) VALUE ZERO.

77 WS-LINE PIC X(10) VALUE ALL “-”. ------------

77 WS-ADDR PIC X(10) VALUE SPACES.

77 WS-AMT PIC 9(4)v9(3) value 12.56. 0012560

Level number 77 indicates the item is independent data item


PIC means PICTURE Clause indicating the type and size of the item
Type can be X A 9 indicating alphanumeric, alphabetic, Numeric items

29
Declare Variables in WS (contd.)

VALUE indicates the initial contents of the variable

The constants are three types in COBOL

STRING CONSTANT, NUMERIC CONSTANT, FIGURATIVE CONSTANT

Though the initial values are called constants, the contents can be modified late
in the program.

The max size of X and A is 32000 chars without value clause and 180 with VALUE
clause.

The maximum for numeric data item max allowed is 18 digits but mainframe
COBOL allows up to 31 digits. You have to set the compiler option
PARM.COBOL=ARITH(EXTEND)

30
More examples
77 WS-CTR2 PIC 9(5) VALUE 123. ( STORED AS 00123 )
77 EMP-NAME PIC A(15) VALUE “ARICH INFOTECH ”.
01 EMP-ADDRESS PIC X(12) VALUE “45, I STREET”.
01 WS-GRP.
02 WS-EC PIC 9(3).
02 WS-EN PIC X(12).
02 WS-DOB.
03 WS-DD PIC 9(2).
03 WS-MM PIC 9(2).
03 WS-YY PIC 9(2).
01 WS-GRP.
05 WS-EC PIC 9(3).
05 WS-EN PIC X(12).
05 WS-DOB.
10 WS-DD PIC 9(2).
10 WS-MM PIC 9(2).
10 WS-YY PIC 9(2).

31
Figurative Constants
COBOL provides special types of constants called Figurative Constants.

They are:

• SPACE or SPACES

• ZERO or ZEROS or ZEROES equivalent to 0

• HIGH-VALUE or HIGH-VALUES equal to Max Value


This consists of “All bits on” condition in a variable. Represents a non-
standard, non-printable character used to specify the highest value in the
computer’s collating sequence.

• LOW-VALUE or LOW-VALUES equal to Min Value

32
THE PROCEDURE DIVISION

• The PROCEDURE DIVISION is where all the data described in the DATA
DIVISION is processed .

• It contains the logic to process the data .

• The PROCEDURE DIVISION is hierarchical in structure and consists of


Sections, Paragraphs, Sentences and Statements.

• There must be at least one paragraph, sentence and statement in the


PROCEDURE DIVISION.

33
EXAMPLE – PROCEDURE DIVISION STATEMENT

IDENTIFICATION DIVISION.
PROGRAM-ID. PRG1.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 WS-NAME PIC X(10) VALUE ‘ARICH INFOTECH’.
PROCEDURE DIVISION.
DISPLAY “HELLO” WS-NAME.
STOP RUN.

Note: DISPLAY statement IN MAIN FRAME COBOL CANNOT


control the LINE or COLUMN position of the SCREEN

34
You have to use multiple display statements to show the contents on
separate lines

000100 IDENTIFICATION DIVISION.


200 PROGRAM-ID. PRG1.
300 DATA DIVISION.
400 WORKING-STORAGE SECTION.
500 77 WS-NAME PIC X(10) VALUE ‘ARICH INFOTECH’.
600 PROCEDURE DIVISION.
700 DISPLAY “HELLO”
800 DISPLAY WS-NAME.
900 DISPLAY “HOW ARE YOU?”.
1000 STOP RUN.

35
Procedure to compile and execute a COBOL program

1. Allocate two PDS

2. Enter your COBOL program as a member of PDS

3. Create a JCL named COMPLINK as follows, in ARICH03.COBOL.PDS


and submit

//ARICH56R JOB NOTIFY=ARICH03,CLASS=M


// JCLLIB ORDER=(ZOS.PROCLIB)
//S1 EXEC PROC=IGYWCL,MEM=PRG1
//COBOL.SYSIN DD DSN=ARICH03.COBOL.PDS(&MEM),DISP=SHR
//LKED.SYSLMOD DD DSN=ARICH03.LOAD.PDS(&MEM),DISP=SHR
//

36
CREATE A JCL NAMED RUNJCL AS FOLLOWS IN ARICH03.COBOL.PDS
AND SUBMIT

//ARICH03R JOB NOTIFY=&SYSUID,CLASS=M


//JOBLIB DD DSN=ARICH03.LOAD.PDS,DISP=SHR
//S1 EXEC PGM=PRG1
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
….. ………… ……
/*
//
==================================================================

NOTE: //GO.SYSIN DD * is to be used for giving the input when we use IGYWCLG

37
ACCEPT

IDENTIFICATION DIVISION.
PROGRAM-ID. PRG1.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 WS-NAME PIC X(10).
77 WS-NUM PIC 9(5).
PROCEDURE DIVISION.
ACCEPT WS-NAME.
DISPLAY WS-NAME.
ACCEPT WS-NUM.
DISPLAY WS-NUM.
STOP RUN.

38
EXAMPLE: 1

IDENTIFICATION DIVISION.
PROGRAM-ID. EX1.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 NAME PIC X(15).
01 AGE PIC 9(2).
PROCEDURE DIVISION.
PARA-1.
ACCEPT NAME.
ACCEPT AGE.
DISPLAY “HELLO " NAME.
DISPLAY “YOUR AGE IS " AGE.
STOP RUN.

39
ACCEPT variable
FROM {DATE/TIME/DAY/DAY-OF-WEEK } [ YYYYMMDD ].

DISPLAY VAR1/LIT1 VAR2/LIT2 .. .. .. .. ..

40
ACCEPT can be used to capture system registers like DATE, TIME etc.

IDENTIFICATION DIVISION.
PROGRAM-ID. PRG1.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 WS-DATE PIC 9(8).
PROCEDURE DIVISION.
ACCEPT WS-DATE
FROM DATE YYYYMMDD.
DISPLAY WS-DATE.
STOP RUN.

41
IDENTIFICATION DIVISION.
PROGRAM-ID. PRG1.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 WS-TIME PIC 9(8) VALUE 0.
PROCEDURE DIVISION.
ACCEPT WS-TIME FROM TIME.
DISPLAY WS-TIME.
STOP RUN.

42
IDENTIFICATION DIVISION.
PROGRAM-ID. PRG1.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 WS-DAY PIC 9(6) VALUE 0.
PROCEDURE DIVISION.
ACCEPT WS-DAY FROM DAY YYYYDDD.
DISPLAY WS-DAY.
ACCEPT WS-DWK FROM DAY-OF-WEEK
DISPLAY WS-DWK.
STOP RUN.

43
 What is the purpose of using the Environment
Division?
 What are the different section available in Data
Division.
 What is the purpose of a Display statement?
 When do you use an ACCEPT keyword?
 List out atleast five different Reserved words
that you have come across so far.

44

You might also like