Top Banner
COBOL (COMMON BUSINESS COBOL (COMMON BUSINESS ORIENTED LANGUAGE) ORIENTED LANGUAGE) Overview
56
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: COBOL DAY 1

COBOL (COMMON COBOL (COMMON BUSINESS ORIENTED BUSINESS ORIENTED

LANGUAGE)LANGUAGE)

Overview

Page 2: COBOL DAY 1

COBOL COBOL FundamentalsFundamentals

DAY1

Page 3: COBOL DAY 1

Session PlanSession Plan

Day 1:

◦Introduction to COBOL

◦Evolution, Features & Language Fundamentals

◦Program Structure

◦Data description entry

Page 4: COBOL DAY 1

ReferencesReferences

M.K.Roy and D. Ghosh Dastidar, COBOL Programming, Tata McGraw Hill, New York, 1973.

Nancy Stern and Robert Stern, COBOL Programming, John Wiley & Sons, New York, 1973.

Newcomer and Lawrence, Programming with Structured COBOL, McGraw Hill Books, New York, 1973.

Page 5: COBOL DAY 1

History of COBOLHistory of COBOL

1959 – United States Department of Defense 1960 - COBOL initial specifications presented by CODASYL

(Conference on Data Systems Languages)

1964 – BASIC COBOL extended to Visual COBOL 1968 – ANSI (American National Standards Institute)

developed American National Standard (ANS) COBOL

1974 – ANSI published revised version of (ANS) COBOL– Business applications needed to manipulate character as well as numeric data

– String operations added 1985 – COBOL 85 Standards was introduced with revised

version of COBOL-74.

Page 6: COBOL DAY 1

COBOLCOBOL

What does COBOL stand for?COmmon Business Oriented

Language.

Which are target area of COBOL applications?

Defense, Aircraft, Insurance, Finance, Retail etc

(file & data oriented applications involved)

So we can say that COBOL is basically used for writing business applications and not for developing system software

Page 7: COBOL DAY 1

COBOL – Program Structure

Principal portions of a program. There are 4 divisions –a) Identification (Required)b) Environment (Optional)c) Data (Optional)d) Procedure (Required)

User defined chunk of code which consists of one/more paragraphs.

e.g. a) U000-CHECK-LOG SECTION.

b) FILE SECTION.

User defined chunk of code which consists of one/more sentences.

e.g. a) P000-PRINT-FINAL-TOTALS.

b) PROGRAM-ID.A SENTENCE consists of one or

more statements and is terminated by a full stop.

e.g. a) MOVE .21 TO VAT-RATE

b) COMPUTE VAT-AMOUNT =

PRODUCT-COST * VAT-RATE.

PROGRAM

DIVISIONS

SECTIONS

PARAGRAPHS

SENTENCES

STATEMENTS

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

e.g. SUBTRACT T-TAX FROM GROSS-

PAY GIVING NET-PAYCHARACTERS

RESERVED WORDS

USER DEFINED WORDS

Page 8: COBOL DAY 1

COBOL CHARACTER SETCOBOL CHARACTER SETOverview

Page 9: COBOL DAY 1

Character Meaning

  Space

+ Plus sign

- Minus sign or hyphen

* Asterisk

/ Forward slash or solidus

= Equal sign

$ Currency sign1

, Comma

; Semicolon

. Decimal point or period

" Quotation mark2

( Left parenthesis

) Right parenthesis

> Greater than

< Less than

: Colon

' Apostrophe

A-Z Alphabet (uppercase)

a-z Alphabet (lowercase)

0-9 Numeric characters

Page 10: COBOL DAY 1

IDENTIFICATION DIVISION.PROGRAM-ID. PROG1.AUTHOR. R.R.

BHATT.INSTALLATION. ABC CORP.DATE-WRITTEN. 01-JAN-2005.DATE-COMPILED. 01-JAN-

2005.SECURITY. HIGH.

IDENTIFICATION DIVISION.PROGRAM-ID. PROG1.AUTHOR. R.R.

BHATT.INSTALLATION. ABC CORP.DATE-WRITTEN. 01-JAN-2005.DATE-COMPILED. 01-JAN-

2005.SECURITY. HIGH.

OPTIONAL

Compiler takes this as Program Identifier.

PROGRAM-ID comes immediately after ID

Division.

IDENTIFICATION DIVISION …

Page 11: COBOL DAY 1

ENVIRONMENT DIVISION

CONFIGURATION SECTION INPUT-OUTPUTT SECTION

Identifies the computer used for

compiling of programs

Identifies the resources used for

executing the program

ENVIRONMENT DIVISION

Page 12: COBOL DAY 1

The DATA DIVISION is used to describe the data structures used in the program.

There are sections in the DATA DIVISION

FILE SECTION WORKING-STORAGE SECTION LINKAGE SECTION REPORT SECTIONThe two most commonly used components (sections) are

a) WORKING-STORAGE SECTIONInternal data structures are

defined here.b) FILE SECTION

File I/O buffer areas are defined here.

DATA DIVISION

Page 13: COBOL DAY 1

DATA DIVISION.FILE SECTION.FD INVENTORY-FILE RECORD CONTAINS 78 CHARACTERS.01 INVENTORY-REC. 05 IF-PART-NUMBER PIC X(09). 05 PIC X(24). 05 IF-WHSE-LOCS. 10 IF-MAIN-LOC PIC X(06). 10 IF-ALT-LOC PIC X(06). 05 PIC X(33).FD PRINT-FILE.01 PRINT-REC. 05 PIC X(10). 05 P-PART-NUMBER PIC X(09). 05 PIC X(05). 05 P-MAIN-LOC PIC X(06). 05 PIC X(05). 05 P-ALT-LOC PIC X(06).WORKING-STORAGE SECTION.01 FLAGS. 05 F-MORE-RECORDS PIC X VALUE 'Y'.

DATA DIVISIONDATA DIVISION

Page 14: COBOL DAY 1

PROCEDURE DIVISION ..PROCEDURE DIVISION ..

The PROCEDURE DIVISION consists of the following –

Sections

Paragraphs

Sentences

Statements

Page 15: COBOL DAY 1

PROCEDURE DIVISIONPROCEDURE DIVISION

PROCEDURE DIVISION.

0001-ACCOUNT-SECTION.

001-ACCOUNT-READ-PARA. READ ACC-FILE AT END MOVE ‘Y’ TO EOF. MOVE TAX-REDUCT TO TAX-AMOUNT

001-ACCOUNT-VALIDATE-PARA. ADD AMOUNT TO TOT-AMOUNT.

ACCEPT EMPLOYEE-SALARY DISPLAY “Current Employee Salary “

EMPLOYEE-SALARY.001-EXIT-PARA. STOP RUN.

Section

Paragraph

Sentences

statement

Section contain one or more Paragraphs.

A PARAGRAPH comprises of one or

more sentences

A SENTENCE is a combination of one or more statements and is terminated by a full stop.

A STATEMENT is a combination of a COBOL verb and one or more operands.

Page 16: COBOL DAY 1

First COBOL programFirst COBOL program

IDENTIFICATION DIVISION.

PROGRAM-ID. FIRSTPG.

PROCEDURE DIVISION. A0000-MAIN-PARA. DISPLAY ‘-------------------------------’. DISPLAY ‘ WELCOME TO COBOL’.DISPLAY ‘--------------------------------’. STOP RUN.

IDENTIFICATION DIVISION.

PROGRAM-ID. FIRSTPG.

PROCEDURE DIVISION. A0000-MAIN-PARA. DISPLAY ‘-------------------------------’. DISPLAY ‘ WELCOME TO COBOL’.DISPLAY ‘--------------------------------’. STOP RUN.

Page 17: COBOL DAY 1

COBOL coding sheetCOBOL coding sheetColumn 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 18: COBOL DAY 1

COBOL coding sheetCOBOL coding sheet

Almost all COBOL compilers treat a line of COBOL code as if it contained two distinct areas. These are -

AREA A

*) Between Column 8 to 11*) Division, Section, Paragraph names, FD entries & 01 level entries must start in Area A

AREA B

*) Between Column 12 to 72*) All Sentences & Statements start in Area B

Page 19: COBOL DAY 1

COBOL coding rulesCOBOL 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 specialmeaning to the compiler.

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

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 20: COBOL DAY 1

Basic data typesBasic data types

Alphabetic ( A)Numeric( 9)Alphanumeric (X)Edited numeric ( Z, $)Edited alphanumeric(/,-)

Page 21: COBOL DAY 1

Data namesData 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 for Arrays.

Are user defined words .

Page 22: COBOL DAY 1

Rules for forming User-defined Rules for forming User-defined wordswords

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 like ADD,SUBTRACT,MOVE,DISPLAY etc….

Page 23: COBOL DAY 1

Description of data namesDescription 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 the following –

(1) Level number(2) PICTURE clause(3) VALUE clause

DATA DIVISION.01 WS-EMPL-NO PIC X(10) VALUE 1001.

LEVEL NO Data Name Picture Clause VALUE Clause

Page 24: COBOL DAY 1

DATA NAME DATA NAME LEVEL NO LEVEL NO

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 25: COBOL DAY 1

Code Meaning

9 Numeric

A Alphabetic

X Alphanumeric

V Implicit Decimal

S Sign bit

Piture Clause Piture Clause

PICTURE

clause

Page 26: COBOL DAY 1

COBOL ‘PICTURE’ ClausesCOBOL ‘PICTURE’ Clauses

Some examples◦ PICTURE 999 a three digit (+ive only) integer◦ PICTURE S999 a three digit (+ive/-ive) integer◦ PICTURE XXXX a four character text item or string◦ PICTURE 99V99 a +ive ‘real’ in the range 0 to

99.99◦ PICTURE S9V9 a +ive/-ive ‘real’ in the range ?

If you wish you can use the abbreviation PIC.

Numeric values can have a maximum of 18 (eighteen) digits (i.e. 9’s).

The limit on string values is usually system-dependent.

Page 27: COBOL DAY 1

Abbreviating recurring Abbreviating recurring symbolssymbols

Recurring symbols can be specified using a ‘repeat’ factor inside round brackets◦PIC 9(6) is equivalent to PICTURE 999999◦PIC 9(6)V99 is equivalent to PIC 999999V99◦PICTURE X(10) is equivalent to PIC XXXXXXXXXX◦PIC S9(4)V9(4) is equivalent to PIC S9999V9999◦PIC 9(18) is equivalent to PIC

999999999999999999

Page 28: COBOL DAY 1

Declaring DATA in COBOLDeclaring DATA in COBOL

In COBOL a variable declaration consists of a line containing the following items;

ŒA level number. A data-name or identifier.ŽA PICTURE clause.

We can give a starting value to variables by means of an extension to the picture clause called the value clause.

DATA DIVISION.WORKING-STORAGE SECTION.01 Num1 PIC 999 VALUE ZEROS.01 VatRate PIC V99 VALUE .18.01 StudentName PIC X(10) VALUE SPACES.

Num1 VatRate StudentNameNum1 VatRate StudentName

000000 .18.18

DDATAATA

Page 29: COBOL DAY 1

VALUE clause

Description of data names ..Description of data names ..

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 30: COBOL DAY 1

LiteralsLiterals

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 31: COBOL DAY 1

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

ALL ALL literalliteral Fill With Literal

Literals – Figurative ConstantsLiterals – Figurative Constants

Page 32: COBOL DAY 1

Figurative Constants - ExamplesFigurative Constants - Examples

01 GrossPay PIC 9(5)V99 VALUE 13.5.

MOVE TO GrossPay.

01 GrossPay PIC 9(5)V99 VALUE 13.5.

MOVE TO GrossPay.ZEROZEROSZEROES

01 StudentName PIC X(10) VALUE "MIKE".

MOVE ALL "-" TO StudentName.

01 StudentName PIC X(10) VALUE "MIKE".

MOVE ALL "-" TO StudentName.

StudentName

M I K E M I K E

GrossPay

0 0 0 1 3 5 0

Page 33: COBOL DAY 1

Figurative Constants - ExamplesFigurative Constants - Examples

01 GrossPay PIC 9(5)V99 VALUE 13.5.

MOVE TO GrossPay.

01 GrossPay PIC 9(5)V99 VALUE 13.5.

MOVE TO GrossPay.ZEROZEROSZEROES

01 StudentName PIC X(10) VALUE "MIKE".

MOVE ALL "-" TO StudentName.

01 StudentName PIC X(10) VALUE "MIKE".

MOVE ALL "-" TO StudentName.

StudentName

- - - - - - - - - -- - - - - - - - - -

GrossPay

0 0 0 0 0 0 0

Page 34: COBOL DAY 1

Group and elementary itemsGroup 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.

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

WORKING-STORAGE SECTION.01 EMPLOYEE-DETAILS PIC X(30).

01 EMPLOYEE-DETAILS. 05 EMP-NUM PIC 9(4). 05 EMP-NAME PIC X(10). 05 EMP-DEPT PIC X(4). 05 EMP-LOC PIC X(12).

WORKING-STORAGE SECTION.01 EMPLOYEE-DETAILS PIC X(30).

01 EMPLOYEE-DETAILS. 05 EMP-NUM PIC 9(4). 05 EMP-NAME PIC X(10). 05 EMP-DEPT PIC X(4). 05 EMP-LOC PIC X(12).

Page 35: COBOL DAY 1

WORKING-STORAGE SECTION.01 EMPLOYEE-DETAILS PIC X(20).

01 EMPLOYEE-DETAILS. 05 EMP-NUM PIC 9(4). 05 EMP-NAME PIC X(10). 05 EMP-DEPT PIC X(4). 05 EMP-LOC PIC X(12).

WORKING-STORAGE SECTION.01 EMPLOYEE-DETAILS PIC X(20).

01 EMPLOYEE-DETAILS. 05 EMP-NUM PIC 9(4). 05 EMP-NAME PIC X(10). 05 EMP-DEPT PIC X(4). 05 EMP-LOC PIC X(12).

Group item

Sub-Items

Group Items/Records - Group Items/Records - ExampleExample

Page 36: COBOL DAY 1

123456789012345678901234567890 (cols)1234JyothiS E&R Bangalore2234Archana E&R Marathi9999Bhushan E&R C++

Data in input file

WORKING-STORAGE SECTION.01 EMPLOYEE-DETAILS PIC X(30).

WORKING-STORAGE SECTION.01 EMPLOYEE-DETAILS PIC X(30).

1234JyothiS E&R Bangalore1234JyothiS E&R Bangalore

Variable for file read Value

Group Items/Records - Group Items/Records - ExampleExample

Page 37: COBOL DAY 1

WORKING-STORAGE SECTION.01 EMPLOYEE-DETAILS PIC X(30).

01 EMPLOYEE-DETAILS. 05 EMP-NUM PIC 9(4). 05 EMP-NAME PIC X(10). 05 EMP-DEPT PIC X(4). 05 EMP-LOC PIC X(12).

WORKING-STORAGE SECTION.01 EMPLOYEE-DETAILS PIC X(30).

01 EMPLOYEE-DETAILS. 05 EMP-NUM PIC 9(4). 05 EMP-NAME PIC X(10). 05 EMP-DEPT PIC X(4). 05 EMP-LOC PIC X(12).

1234JyothiS E&R Bangalore

1234JyothiSE&RBangalore

1234JyothiS E&R Bangalore

1234JyothiSE&RBangalore

Variable for file read Value

123456789012345678901234567890 (cols)1234JyothiS E&R Bangalore2234Archana E&R Mysore9999Bhushan E&R Chennai

Data in input file

Group Items/Records - Group Items/Records - ExampleExample

Page 38: COBOL DAY 1

LEVEL Numbers & DATA LEVEL Numbers & DATA hierarchyhierarchy

In COBOL, Level numbers are used to express data hierarchy. The higher the level number, the lower the item is in the hierarchy.

So Group items contain sets of elementary items with lower level numbers. At the lowest level the data is completely atomic.

WORKING-STORAGE SECTION.01 POLICY-DETAILS. 05 POLICY-NO. 10 POLICY-TYP PIC X(4). 10 POLICY-LOC PIC X(2). 10 POLICY-ID PIC X(5). 05 POLICY-TYPE PIC X(10). 05 POLICY-EXPDT PIC X(10).

WORKING-STORAGE SECTION.01 POLICY-DETAILS. 05 POLICY-NO. 10 POLICY-TYP PIC X(4). 10 POLICY-LOC PIC X(2). 10 POLICY-ID PIC X(5). 05 POLICY-TYPE PIC X(10). 05 POLICY-EXPDT PIC X(10).

Page 39: COBOL DAY 1

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.

Description of data namesDescription of data names

Page 40: COBOL DAY 1

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 Group Items/RecordItems/Recordss

StudentDetails

WORKING-STORAGE SECTION.01 StudentDetails PIC X(26).

WORKING-STORAGE SECTION.01 StudentDetails PIC X(26).

Page 41: COBOL DAY 1

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

StudentDetails

StudentName StudentId CourseCode Grant Gender

Group Group Items/RecordItems/Recordss

WORKING-STORAGE SECTION.01 StudentDetails.

0202 StudentNameStudentName PIC X(10).PIC X(10).0202 StudentIdStudentId PIC 9(7).PIC 9(7).0202 CourseCodeCourseCode PIC X(4).PIC X(4).0202 GrantGrant PIC 9(4).PIC 9(4).0202 GenderGender PIC X.PIC X.

WORKING-STORAGE SECTION.01 StudentDetails.

0202 StudentNameStudentName PIC X(10).PIC X(10).0202 StudentIdStudentId PIC 9(7).PIC 9(7).0202 CourseCodeCourseCode PIC X(4).PIC X(4).0202 GrantGrant PIC 9(4).PIC 9(4).0202 GenderGender PIC X.PIC X.

Page 42: COBOL DAY 1

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

StudentDetails

Surname Initials

WORKING-STORAGE SECTION.01 StudentDetails.

0202 StudentName.StudentName.03 Surname03 Surname PIC X(8).PIC X(8).03 Initials03 Initials PIC XX.PIC XX.

0202 StudentIdStudentId PIC 9(7).PIC 9(7).0202 CourseCodeCourseCode PIC X(4).PIC X(4).0202 GrantGrant PIC 9(4).PIC 9(4).0202 GenderGender PIC X.PIC X.

WORKING-STORAGE SECTION.01 StudentDetails.

0202 StudentName.StudentName.03 Surname03 Surname PIC X(8).PIC X(8).03 Initials03 Initials PIC XX.PIC XX.

0202 StudentIdStudentId PIC 9(7).PIC 9(7).0202 CourseCodeCourseCode PIC X(4).PIC X(4).0202 GrantGrant PIC 9(4).PIC 9(4).0202 GenderGender PIC X.PIC X.

StudentName StudentId CourseCode Grant Gender

Group Group Items/RecordItems/Recordss

Page 43: COBOL DAY 1

MOVE VERBMOVE VERBOverview

Page 44: COBOL DAY 1

The MOVE The MOVE VerbVerb

MOVE copies data from the source identifier or literal to one or more destination identifiers.

MOVE copies data to Group or elementary data items.

MOVE always performs LEFT JUSTIFICATION to Character

MOVE always perform RIGHT JUSTIFICATION to Numeric data.

When data is MOVEd into an item the contents of the item are completely replaced.

◦ If the source data is too small to fill the destination item entirely the remaining area is zero or space filled.

MOVE TO ...Identifier

LiteralIdentifier

Page 45: COBOL DAY 1

MOVE “RYAN” TO Surname.MOVE “FITZPATRICK” TO Surname.

MOVE “RYAN” TO Surname.MOVE “FITZPATRICK” TO Surname.

01 Surname PIC X(8).

MOVEing MOVEing DataData

C O U G H L A N

Page 46: COBOL DAY 1

MOVEing MOVEing DataData

R Y A N

MOVE “RYAN” TO Surname.MOVE “RYAN” TO Surname.MOVE “FITZPATRICK” TO Surname.

MOVE “RYAN” TO Surname.MOVE “RYAN” TO Surname.MOVE “FITZPATRICK” TO Surname.

01 Surname PIC X(8).

Page 47: COBOL DAY 1

MOVE “RYAN” TO Surname.MOVE “FITZPATRICK” TO Surname.MOVE “FITZPATRICK” TO Surname.

MOVE “RYAN” TO Surname.MOVE “FITZPATRICK” TO Surname.MOVE “FITZPATRICK” TO Surname.

01 Surname PIC X(8).

MOVEing MOVEing DataData

F I T Z P A T R I C K

Page 48: COBOL DAY 1

MOVEing to a MOVEing to a numeric item.numeric item.

When the destination item is numeric, or edited numeric, then data is aligned along the decimal point with zero filling or truncation as necessary.

When the decimal point is not explicitly specified in either the source or destination items, the item is treated as if it had an assumed decimal point immediately after its rightmost character.

Page 49: COBOL DAY 1

MOVE ZEROS TO GrossPay.

MOVE 12.4 TO GrossPay.

MOVE 123.456 TO GrossPay.

MOVE 12345.757 TO GrossPay.

01 GrossPay PIC 9(4)V99.

0 0 0 0 0 0

0 0 1 2 4 0 0 1 2 3 4 5 6

1 2 3 4 5 7 5 7

GrossPay

GrossPay

GrossPay

GrossPay

Page 50: COBOL DAY 1

MOVE 1234 TO CountyPop.

MOVE 12.4 TO CountyPop.

MOVE 154 TO Price.

MOVE 3552.75 TO Price.

01 CountyPop PIC 999.01 Price PIC 999V99.

1 2 3 4

0 1 2 4

1 5 4 0 0

3 5 5 2 7 5

Price

CountyPop

CountyPop

Price

Page 51: COBOL DAY 1

Before

WS00-OUT1 0000

WS00-OUT2 000000

After

WS00-OUT1 3456

WS00-OUT2 345678

Before

WS00-OUT3 000000

After

WS00-OUT3 123456

Before

WS00-OUT4 00000000

After

WS00-OUT4 12345678

Page 52: COBOL DAY 1

MOVE .. example

****************************

WS00-OUT1 : HARAYANA

WS00-OUT2 : HARAYANA

****************************

Output SPOOL

Page 53: COBOL DAY 1

The DISPLAY The DISPLAY VerbVerb

From time to time it may be useful to display messages and data values on the screen.

A simple DISPLAY statement can be used to achieve this.

A single DISPLAY can be used to display several data items or literals or any combination of these.

The WITH NO ADVANCING clause suppresses the carriage return/line feed.

DISPLAY Identifier

Literal

Identifier

Literal ...

UPON WITH NO ADVANCING

Mnemonic - Name

Page 54: COBOL DAY 1

The ACCEPT The ACCEPT verbverb

Format 1. ACCEPT Identifier FROM Mnemonic - name

Format 2. ACCEPT Identifier FROM

DATE

DAY

DAY - OF - WEEK

TIME

01 CurrentDate01 CurrentDate PIC 9(6).PIC 9(6).* YYMMDD

01 DayOfYear01 DayOfYear PIC 9(5).PIC 9(5).* YYDDD

01 Day0fWeek01 Day0fWeek PIC 9.PIC 9.* D (1=Monday)

01 CurrentTime 01 CurrentTime PIC 9(8).PIC 9(8).* HHMMSSss s = S/100

01 CurrentDate01 CurrentDate PIC 9(6).PIC 9(6).* YYMMDD

01 DayOfYear01 DayOfYear PIC 9(5).PIC 9(5).* YYDDD

01 Day0fWeek01 Day0fWeek PIC 9.PIC 9.* D (1=Monday)

01 CurrentTime 01 CurrentTime PIC 9(8).PIC 9(8).* HHMMSSss s = S/100

Page 55: COBOL DAY 1

PROCEDURE DIVISION.Begin. DISPLAY "Enter student details using template below". DISPLAY "NNNNNNNNNNSSSSSSSCCCCGGGGS ". ACCEPT StudentDetails. ACCEPT CurrentDate FROM DATE. ACCEPT DayOfYear FROM DAY. ACCEPT CurrentTime FROM TIME. DISPLAY "Name is ", Initials SPACE Surname. DISPLAY "Date is " CurrentDay SPACE CurrentMonth SPACE CurrentYear. DISPLAY "Today is day " YearDay " of the year". DISPLAY "The time is " CurrentHour ":" CurrentMinute. STOP RUN.

PROCEDURE DIVISION.Begin. DISPLAY "Enter student details using template below". DISPLAY "NNNNNNNNNNSSSSSSSCCCCGGGGS ". ACCEPT StudentDetails. ACCEPT CurrentDate FROM DATE. ACCEPT DayOfYear FROM DAY. ACCEPT CurrentTime FROM TIME. DISPLAY "Name is ", Initials SPACE Surname. DISPLAY "Date is " CurrentDay SPACE CurrentMonth SPACE CurrentYear. DISPLAY "Today is day " YearDay " of the year". DISPLAY "The time is " CurrentHour ":" CurrentMinute. STOP RUN.

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

DATA DIVISION.WORKING-STORAGE SECTION.01 StudentDetails. 02 StudentName. 03 Surname PIC X(8). 03 Initials PIC XX. 02 StudentId PIC 9(7). 02 CourseCode PIC X(4). 02 Grant PIC 9(4). 02 Gender PIC X.

01 CurrentDate. 02 CurrentYear PIC 99. 02 CurrentMonth PIC 99. 02 CurrentDay PIC 99.

01 DayOfYear. 02 FILLER PIC 99. 02 YearDay PIC 9(3).

01 CurrentTime. 02 CurrentHour PIC 99. 02 CurrentMinute PIC 99. 02 FILLER PIC 9(4).

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

DATA DIVISION.WORKING-STORAGE SECTION.01 StudentDetails. 02 StudentName. 03 Surname PIC X(8). 03 Initials PIC XX. 02 StudentId PIC 9(7). 02 CourseCode PIC X(4). 02 Grant PIC 9(4). 02 Gender PIC X.

01 CurrentDate. 02 CurrentYear PIC 99. 02 CurrentMonth PIC 99. 02 CurrentDay PIC 99.

01 DayOfYear. 02 FILLER PIC 99. 02 YearDay PIC 9(3).

01 CurrentTime. 02 CurrentHour PIC 99. 02 CurrentMinute PIC 99. 02 FILLER PIC 9(4).

Enter student details using template belowNNNNNNNNNNSSSSSSSCCCCGGGGSCOUGHLANMS9476532LM511245MName is MS COUGHLANDate is 24 01 94Today is day 024 of the yearThe time is 22:23

Enter student details using template belowNNNNNNNNNNSSSSSSSCCCCGGGGSCOUGHLANMS9476532LM511245MName is MS COUGHLANDate is 24 01 94Today is day 024 of the yearThe time is 22:23

Run of Accept and Display programRun of Accept and Display program

Page 56: COBOL DAY 1

Example Program - Example Program - DateDate

Overview