JCL Slides
JCL Slides
Structured language
Compiler based
Program
DIVISIONS
SECTION(S)
PARAGRAPH(S)
SENTENCE(S)
STATEMENT(S)
• When they are not underlined the used for readability only and are
optional. If used they must be spelt correctly
IDENTIFICATION DIVISION.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
IDENTIFICATION DIVISION.
Program Details
DATA DIVISION.
Data Descriptions
PROCEDURE DIVISION.
Algorithm Description
IDENTIFICATION DIVISION.
PROGRAM-ID. NameOfProgram.
[AUTHOR. YourName.]
[INSTALLATION. [comment-entry] . . .]
[DATE-WRITTEN. [comment-entry] . . .]
[DATE-COMPILED. [comment-entry] . . .]
[SECURITY. [comment-entry] . . .]
15
CONFIDENTIAL© Copyright 2007 Tech Mahindra Limited
© Tech Mahindra Limited 2007 Tech Mahindra Limited confidential
The Sections Of The Environment Division
The ENVIRONMENT DIVISION is the only machine-
dependent division of a COBOL program
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. computer-name.
OBJECT-COMPUTER. computer-name.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT file-name-1
ASSIGN TO implementor-name-1.
17
CONFIDENTIAL© Copyright 2007 Tech Mahindra Limited
© Tech Mahindra Limited 2007 Tech Mahindra Limited confidential
THE CONFIGURATION SECTION
Supplies information about the computer on which the
COBOL program will be compiled and executed
y SOURCE-COMPUTER:
• The computer that will be used for compiling the program
y OBJECT-COMPUTER:
• The computer that will be used for executing or running the
program
A SELECT statement
y …defines a file-name
y …assigns a device name to that file*
SELECT file-name-1
ASSIGN TO implementor-name-1
[ORGANIZATION IS SEQUENTIAL]
21
CONFIDENTIAL© Copyright 2007 Tech Mahindra Limited
© Tech Mahindra Limited 2007 Tech Mahindra Limited confidential
The DATA DIVISION
The DATA DIVISION is used to describe most of the data
that a program processes
y FILE SECTION.
y WORKING-STORAGE SECTION.
IDENTIFICATION DIVISION.
PROGRAM-ID. Add-Program.
AUTHOR. ABC.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N1 PIC 9 VALUE ZEROS.
01 N2 PIC 9 VALUE ZEROS.
01 Result PIC 9 VALUE ZEROS.
SELECT INVENTORY-FILE
ASSIGN TO DISK1.
SELECT ERROR-LIST
ASSIGN TO PRINTER.
*
DATA DIVISION.
FILE SECTION.
FD INVENTORY-FILE
.
.
FD ERROR-LIST
Level Numbers
• After a file is described by an FD, the record description entries
for each record format within the file follow
FD TRANSACTION-FILE
LABEL RECORDS ARE OMITTED
RECORD CONTAINS 80 CHARACTERS.
01 TRANSACTION-REC-IN.
{Entries of the record}
e.g:
The record description entries following the FD are:
01 EMPLOYEE-REC-IN.
05 NAME-IN.
05 ANNUAL-SALARY-IN.
05 JOB-DESCRIPTION-IN.
All fields on the 05 level are subordinate to, or part of, the
01-level entry
All fields coded on the same level are independent items
Value Clauses
The syntax of the Value clause is
VALUE IS literal.
33
CONFIDENTIAL© Copyright 2007 Tech Mahindra Limited
© Tech Mahindra Limited 2007 Tech Mahindra Limited confidential
The PROCEDURE DIVISION
The PROCEDURE DIVISION is where all the data described
in the DATA DIVISION is processed and produced.
A section begins with the section name and ends where the
next section name is encountered or where the program text
ends
IDENTIFICATION DIVISION.
PROGRAM-ID. AddProgram.
AUTHOR. ABC.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N1 PIC 9 VALUE ZEROS.
01 N2 PIC 9 VALUE ZEROS.
01 Result PIC 9 VALUE ZEROS.
PROCEDURE DIVISION.
CalculateResult.
ACCEPT N1.
ACCEPT N2.
MULTIPLY N1 BY N2 GIVING Result.
DISPLAY "Result is = ", Result.
STOP RUN.
PROCEDURE DIVISION.
DisplayPrompt.
DISPLAY "I did it".
STOP RUN.
-1 to 30 characters
-Letters, digits and hyphens only
-Should not begin or end with ‘-’
-No embedded blanks are permitted
-Must contain at least one alphabetic character
-Should not be Cobol reserved word like ADD, MOVE etc..
e.g. TotalSal, Gross-Sal, PrintReportTitle, Customer1-Rec
Variables
Literals
Figurative Constants
StudName
StudName
A M O L
StudName
My name is AMOL
A M O L
For the time being we will focus on just two data types,
y numeric
y text or string
From the type of the item the compiler can establish how
much memory to set aside for storing its values
SPACE or SPACES =
ZERO or ZEROS or ZEROS = 0
QUOTE or QUOTES = "
HIGH-VALUE or HIGH-VALUES
HIGH-VALUE HIGH-VALUES = Max Value
LOW-VALUE or LOW-VALUES
LOW-VALUE LOW-VALUES = Min Value
ALL literal = Fill With Literal
MyPay
0 0 0 1 2 5 0
×
z
StudentName
A M I T
CONFIDENTIAL© Copyright 2007 Tech Mahindra Limited 56
Figurative Constants - Examples
01 MyPay PIC 9(5)V99 VALUE 12.5.
ZERO
MOVE ZEROS TO MyPay.
ZEROES
MyPay
0 0 0 0 0 0 0
×
z
StudName
- - - - - - - - - -
CONFIDENTIAL© Copyright 2007 Tech Mahindra Limited 57
Group Items/Records
WORKING-STORAGE SECTION.
01 StudDetails PIC X(26).
StudDetails
A B C D E A B C D E 9 4 1 0 1 8 2 L C 1 1 0 1 1 0 M
WORKING-STORAGE SECTION.
01 StudDetails.
02 SName PIC X(10).
02 SId PIC 9(7).
02 CourseCode PIC X(4).
02 Grant PIC 9(4).
02 Gender PIC X.
StudDetails
A BC D EA B C DE 9 4 1 0 1 8 2 L C 1 1 0 1 1 0 M
SName SId CourseCode Grant Gender
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
• Arithmetic verbs
MOVE “RAYS”
“RAYS” TO Surname.
MOVE “FITZPATRICK” TO Surname.
GrossPay
MOVE ZEROS TO PersonalPay. 0 0 0 0 0 0
×
z
GrossPay
MOVE 11.5 TO PersonalPay. 0 0 1 1 5 0
×
z
GrossPay
MOVE 123.789 TO PersonalPay. 0 1 2 3 7 8 9
×
z
GrossPay
MOVE 12345.858 TO PersonalPay. 1 2 3 4 5 8 58
×
z
y ACCEPT
y DISPLAY