Вы находитесь на странице: 1из 120

03-23-05 30 Sept 2005

page 1 EDS Internal


COMMON BUSINESS ORIENDTED LANGUAGE
E D S India A D U.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 2 EDS Internal
OBJECTIVES
Understand the standard format of the COBOL program.

Write COBOL programs using modular design techniques

Compile, Link edit and Execute the soure code.


Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 3 EDS Internal
INTRODUCTION
BE

COBOL stands for COMMON BUSINESS ORIENTED LANGUAGE.

COBOL can be referred as

High-level programming language oriented towards business
applications

Procedural language

Problem oriented and Machine independent

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 4 EDS Internal
HISTORY
Developed in 1959 as standard language to meet business
need.

Committee was formed to maintain the COBOL.

Included representatives from academia, business,
computer manufacturers.`
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 5 EDS Internal
STANDARD VERSIONS OF COBOL
1960s Versions of COBOL compilers

1968 First COBOL standard set by American national
Standards Institute (ANSI) known as COBOL-68

1974 Second COBOL known as COBOL-74 was approved
by ANSI.

1985 ANSI approved the COBOL-85 in which structured
programming techniques were incorporated.

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 6 EDS Internal
CHARACTERSTICS
COBOL self documenting.

COBOL is simple

COBOL is non proprietary (Portable)

COBOL is maintainable
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 7 EDS Internal
LANGUAGE CONSTRUCTION
COBOL is like English language

Character is the lowest component

Word is made up of one or more characters.

Clause consists of word and characters.

Statement is syntactically valid combination of words and
clauses.

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 8 EDS Internal
LANGUAGE CONSTRUCTION
Statement is syntactically valid combination of words and
clauses.

Sentence is a sequence of one or more statements
terminated by period.

Paragraph consists of one or more statements

Section consists of one or more paragraphs.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 9 EDS Internal
LANGUAGE CONSTRUCTION
Division consists of one or more paragraphs.

Program is made up of divisions.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 10 EDS Internal
CHARACTER SET
Set of 51 characters


0,. 9
A,.Z
b
+, -, *, /, (,), =, $, ., , <, >
DIGITS
LETTERS
SPACE/BALNK CHARACTER
SPECIAL SYMBOLS
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 11 EDS Internal
WORDS
User defined words
Words declared by programmer like paragraph
names, identifiers etc.

Reserved words
Words that are having specific meaning to the
compiler
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 12 EDS Internal
CODING FORMAT
Columns
1 6 Sequence numbers identifying pages or lines of a
program
7 Continuation, comment or starting of a new page
872 Program statements
73-80 Remarks.

in column 7
* designates the entire line is as a comment
/ forces page break when printing source listing
- to indicate a continuation of non numeric literal
columns 8 72 divided into two areas.


Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 13 EDS Internal
CODING FORMAT
AREA A - Columns 8 to 11

AREA B - Columns 12 to 72

Division, Section and Paragraph names must all begin in
Area A and end with a period.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 14 EDS Internal
DIVISIONS
COBOL program contains up to 4 separate divisions in the
following order

IDENTIFICATION DIVISION
ENVIRONMENT DIVISION
DATA DIVISION
PROCEDURE DIVISION

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 15 EDS Internal
IDENTIFICATION DIVISION
First division of a COBOL program

Identifies the program name to the Operating system

Provides documentation about program

Should begin in Area A.

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 16 EDS Internal
IDENTIFICATION DIVISION
Syntax

IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM NAME.
AUTHOR.COMMENT ENTRY.
INSTALLATION.COMMENT ENTRY.
DATE-WRITTEN.COMMENT ENTRY.
DATE-COMPILED.COMMENT ENTRY.
SECURITY.COMMENT ENTRY.


Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 17 EDS Internal
IDENTIFICATION DIVISION
Paragraph PROGRAM-ID followed by user defined name is
mandatory. Other paragraphs are optional

Security here does not pertian to the operating system
security, but the information that is passed to the user of
the program about the Security features of the program.

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 18 EDS Internal
ENVIRONMENT DIVISION
Machine dependent division

The division is optional but for file handling it is essential

Should begin in Area A.

Division is terminated by a period.

Describes the computers used, devices, peripherals etc.

Contains two sections namely, CONFIGURATION and
INPUT-OUTPUT

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 19 EDS Internal
CONFIGURATION SECTION
Describes the computer to be used for compiling and
executing the program.

Consists of the following paragraphs
SOURCE COMPUTER
OBJECT COMPUTER
SPECIAL NAMES.

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 20 EDS Internal
SOURCE COMPUTER
Used to specify the name of computer for compiling the
COBOL program.

The With Debugging Mode option can be mentioned
enabling the compiler to include D in the 7
th
column for all
lines as syntax.

Syntax
SOURCE COMPUTER. XYZ-2901


Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 21 EDS Internal
OBJECT COMPUTER
Used to specify the name of the computer for executing
the program

Syntax
OBJECT-COMPUTER. Computer-name
MEMORY SIZE integer-1 CHARACTERS/WORDS
PROGRAM COLLATING SEQUENCE IS alphabet-name
SEGMENT-LIMIT IS integer-2.

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 22 EDS Internal
OBJECT COMPUTER
Memory Size used to indicate the amount of storage
available to Object computer.

The Program Collating Sequence clause specifies the
collating sequence that is to be used to compare non-
numeric data items. The alphabet-name is to be defined in
Special names paragraph.

The Segment-Limit clause is used to indicate that the
section having segment number less than the specified
should be held in Permanent area of storage.


Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 23 EDS Internal
SPECIAL NAMES
Is used to relate some IBM specified environment names to
user defined names.

Regardless of number of entries in this paragraph there
should be only one period in the end.

Syntax
SPECIAL-NAMES. CURRENCY SIGN IS literal-1
DECIMAL-POINT IS COMMA
CHANNEL integer IS mnemonic-names
ALPHABET alphabet-name IS
STANDARD/NATIVE/implementer name
Implementer-name IS mnemonic-name.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 24 EDS Internal
SPECIAL NAMES
CURRENCY SIGN literal-1
used to change the currency sign other than $ with one
character symbol (literal-1).

DECIMAL-POINT IS COMMA
Used to interchange the roles of . and , as edit
characters.

CHANNEL integer IS mnemonic-name
Used to control the line spacing of line printers.
The mnemonic-name can only be used in a WRITE
statement.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 25 EDS Internal
SPECIAL NAMES
ALPHABET alphabet-name IS
STANDARD/NATIVE/implementer name
Implementer-name is mnemonic-name
Used to indicate the collating sequence
Standard stands for the ASCII collating sequence
NATIVE stands for the computers own collating
sequence

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 26 EDS Internal
INPUT-OUTPUT SECTION
Contains information regarding files to be used in the
program

Consists FILE-CONTROL and I-O-CONTROL (INPUT-
OUTPUT-CONTROL) paragraphs.

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 27 EDS Internal
FILE-CONTROL
Associates each file used in program with an external DD
name. The DD name is associated to a physical file in JCL.

The simplified format of file association is done using
SELECT clause.

Coding rules
SELECT clause must appear first
Other clauses can appear in any order
Each clause must start in Area B.

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 28 EDS Internal
I-O-CONTROL
Optional paragraph.

Must begin in Area A.

Specifies when check points are to be taken

Specifies the storage areas to be shared by different files

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 29 EDS Internal
DATA DIVISION
Used to define data needed to be accessed by program

Describes input and output format of data files

Defines any constants and work areas

Consists of three sections namely
FILE SECTION
WORKING STORAGE SECTION
LINKAGE SECTION

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 30 EDS Internal
FILE SECTION
Includes the description of all the files.

SYNTAX of file description

FD file-name
RECORD IS OMITTED
LABEL
RECORDS ARE STANDARD
RECORD CONTAINS integer-1 CHARACTERS
BLOCK CONTAINS integer-2 RECORDS

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 31 EDS Internal
FILE SECTION
LABEL RECORDS clause used if labels stored in file

BLOCK CONTAINS clause indicates blocking factor for disk
files.

RECORD CONTAINS clause indicates size of each record.

Defining a Record
Each FD followed by record description entries for the file.
Record name is defined at 01 level considered highest
level of data
Fields within a record are defined at subordinate level
with level numbers from 02 to 49.

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 32 EDS Internal
WORKING-STORAGE SECTION
Must start in Area A and end with Period.

All items must be defined at 01 level or at subordinate to
01 level

Rules for user-defined entry names apply

Elementary items :
Must include PICTURE (PIC) clause
May be assigned initial value with VALUE clause
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 33 EDS Internal
LITERALS AND FIGURATIVE CONSTANTS
Literal is a constant representing a number or non-number
(Alpha numeric) like 33.3 or TEACHER

Literals are storable in a memory location having a user
defined name called Data name or identifier or Variable or
Field

Figurative constant is a COBOL reserved word representing
frequently used constants like ZEROS or SPACES

Figurative constants are used in program for better
readability.
Ex: MOVE SPACES TO WS-RECORD.

Literals are classified into Numeric and Non-numeric literals
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 34 EDS Internal
NUMERIC LITERAL
Must contain at least one digit.

+ or sign, if used must be the left most character

Not more than one decimal point

Decimal may not be the right most character

Maximum of 18 digits

TOTAL-COUNT PIC 9(3) VALUE 100.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 35 EDS Internal
NON-NUMERIC LITERAL
May consist of any character in the character set

Must be enclosed in quotes

A numeric literal in quotes is non-numeric literal

Maximum length of 120 characters

COMPANY-NAME PIC X(3) VALUE EDS.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 36 EDS Internal
FIGURATIVE CONSTANTS
List of Figurative constants












ZERO/ZEROS/ZEROES

Quote/Quotes

Space/Spaces

HIGH VALUE/HIGH VALUES

LOW VALUE/LOW VALUES

ALL
One or more zeros

One or more

One or more spaces

Value in collating sequence

Value in collating sequence

One or more string vlaues
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 37 EDS Internal
DATA DESCRIPTION
The general format of data description is
Level Number
Data name
Filler clause
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 38 EDS Internal
LEVEL NUMBERS
Specifies the hierarchical structure of data item

Is a two digit number starting from 01.

Single digit numbers must be written in a two-digit form
with a 0 or space preceding them.

Are values taken from set of integers between 1 and 40, or
one from 66, 77 and 88 which are called Special level
numbers
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 39 EDS Internal
LEVEL NUMBERS
01 level
Specifies a group of data items called record or an
elementary data item
Must begin in Area A

02 49 levels
Specifies group items or elementary item within a record.

Group level data items will not have Picture Clause


Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 40 EDS Internal
SPECIAL LEVEL NUMBERS
66 identifies items that contain RENAME clause

77 identifies independent elementary data item

77 has to appear only as elementary data item

88 identifies any condition name that is associated with a
particular value of conditional variable
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 41 EDS Internal
DATA NAMES
Identifier name or Data name should not exceed 30
characters

There should be at least one alphabet anywhere in the
name.

Only special character allowed is (Hyphen) but should
not be at the beginning or at the End.

Should be unique within a record

If Data name is duplicated across records then it should be
qualified as identifier-name of Record name
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 42 EDS Internal
DATA NAMES
Examples
CURRENT-DATE
EMPLOYEE
11RAIL
99-DETAIL-LINE
MOVE BALANCE OF BILLING-RECORD TO TOTAL-AMOUNT

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 43 EDS Internal
FILLER
Used whenever there is no specific reference to fields in a
record.

Used wherever there is fixed information like SPACES or
Headings are stored.

Example
01 DETAIL-RECORD
05 FILLER PIC X(05) VALUE SPACES.
05 NAME PIC X(20).
05 PIC X(02) VALUE SPACES.
05 FILLER PIC X(05) VALUE BASIC.
05 AMT PIC 9(9)V99.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 44 EDS Internal
PICTURE CLAUSE
Describes the class (numeric, alphabetic, alphanumeric),
sign(signed/unsigned), decimal point location and size of a
data item.
Specified for every elementary data item









Type Character String Remark
Numeric 9 Used for arithmetic
operations
V Assumed decimal point
S Signed data item
P Position of assumed
decimal point when the
point lies outside data
item
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 45 EDS Internal
PICTURE CLAUSE
Type Character String Remark
Alphabetic A Data item contains only a
letter or space
B Blank insertion character
Alpha numeric X Data item contains only
allowable character from
the COBOL character set
Examples
01 COMPANY PIC X(10). - Defines 10
characters of Alphanumeric.
01 BASIC-AMOUNT PIC 9(9)V99. Defines
9 digits before decimal
and two digits after
decimal. The decimal
will not be displayed.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 46 EDS Internal
EDITED PICTURE CLAUSE
Edited Picture Clause
Used to display Numeric and other data in the user
readable format

Edited types
Numeric data
Alphabetic
Alphanumeric

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 47 EDS Internal
EDITED PICTURE CLAUSE
PIC OF THE FIELD NUMERIC VALUE EDITED VALUE
ZZZV99
* * 999
$ * *999
-ZZZV99
+999
+999
9999+
ZZ,Z99
ZZZZ.ZZ
$$$$9.99
99B99B99
09990
999/999/99
38
^
4
00052
985
-46
^
52
-382
382
-382
2456
5
342
46
456
3254
b3840
* * 052
$**985
-b4652
-382
+382
0382-
b2,456
bbbb.05
b$342.00
00b00b46
04560
000/032/54
ZZZ.99 BLANK WHEN ZERO

999.99 BLANK WHEN ZERO
2 5

0
bb2.50

bbbbbb
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 48 EDS Internal
VALUE CLAUSE
Assigns initial value to a data item.

Should not exceed the picture clause

Should be consistent with the picture clause

Not used for for items whose size is variable

Example
01 WS-RECORD
05 WS-COMPANY PIC X(03) VLAUE EDS.
05 FILLER PIC X(15) VALUE ALL -.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 49 EDS Internal
USAGE CLAUSE
Specifies how data item is represented internally

Types
DISPLAY number of bytes required is equal to the size of
data item. This is default type.
COMPUTATIONAL Maintained in Binary and only for
integers. Stored either in half or full word.

Syntax
USAGE IS DISPLAY
COMPUTATIONAL OR COMP , COMP -1, COMP-2, COMP-3
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 50 EDS Internal
SIGN CLAUSE
Indicates the data item is Signed.

Only for numeric fields

Picture clause should contain S

Usage should be display

To represent the position either LEDING or TRAILING can be
used.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 51 EDS Internal
OCCURS CLAUSE
Used to represent and store table of values
When used allocates physically contiguous memory
locations to store table values
Values are accessed either by using index or subscript

Example
01 WS-TABLE.
05 WS-NAME OCCURS 10 TIMES PIC X(20).
01 WS-TABLE.
05 WS-RECORD OCCURS 15 TIMES.
10 WS-DEPT PIC X(10).
10 WS-DIV PIC 9(05).
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 52 EDS Internal
REDEFINES CLAUSE
Allows to reference same memory area for more than one
data-name with different formats and sizes.
Syntax
Level-number data-name-1 REDEFINES data-name-2

Rules
Level-number of data-name-1 and data-name-2 must be
identical and not 66 or 88
Redefines clause must follow immediately after data-
name-2
data-name-1 cannot have value clause
data-name-1 size should not exceed data-name-2 size

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 53 EDS Internal
REDEFINES CLAUSE
Rules
Multiple Redefinitions are allowed provided no new
storage areas defined in between
At 01 level, OCCURS and REDEFINES cannot be
combined


Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 54 EDS Internal
RENAMES CLAUSE
Regrouping of elementary data items in a Record.

Example
01 WS-RESPONSE.
05 W-CHAR-123 PIC XXX.
05 W-CHAR-4 PIC X.
05 W-CHAR-56 PIC XX.
66 ADD-RESPONSE RENAMES W-CHAR-123.
66 VIEW-RESPONSE RENAMES W-CHAR-123 THRU
W-CHAR-4.
66 DELETE-RESPONSE RENAMES W-CHAR-123 THRU
W-CHAR-56.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 55 EDS Internal
JUSTIFIED CLAUSE
Overrides standard positioning rules for a receiving stem
of the alphabetic or alphanumeric categories

Default is Left Justified

Does not alter initial settings as determined by the value
clause
May not be specified at 66 and 88 level.

Example
01 WS-CHAR PIC X(05) JUSTIFIED RIGHT.

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 56 EDS Internal
PROCEDURE DIVISION
Contains statements which specify the operations to be
performed

Last division in a COBOL program

Contains following structure
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 57 EDS Internal
PROCEDURE DIVISION
DIVISION
Is a block of code, usually containing one or more
sections
Starts with a Division name and ends where a new
Division starts or program text ends

SECTION
Is a block code usually containing one or more
paragraphs.
Starts with a Section name and ends where next section
starts or program text ends

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 58 EDS Internal
PROCEDURE DIVISION
PARAGRAPH
A block of code made up of one or more sentences
Starts with a paragraph name and ends where next
paragraph or next section starts or program text ends

Sentences and Statements
Sentence consists of one or more statements and is
terminated by a period
Example
MOVE 0.12 TO TAX-RATE
COMPUTE PRICEA = PROD-COST * TAX-RATE

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 59 EDS Internal
PROCEDURE DIVISION
Statement consists of a COBOL verb and an operand or
operands

Example
SUBTRACT TAX FROM GROSS-PAY GIVING NETPAY.

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 60 EDS Internal
PROCEDURE DIVISION
Guidelines
Paragraph names section names should start in Area A

Statements and Sentences should start in Area B

Section names and Paragraph names are user defined

Section names must be unique and must be different from
paragraph names

Paragraph names must be unique in a section

If paragraph name is duplicated across sections then it should
be qualified as paragraph-name of/in section name
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 61 EDS Internal
PROCEDURE DIVISION
Statements in Procedure division
Can be broadly classified as
Imperative statements which directs the program to take a
specific action during execution
Examples: MOVE , ADD, GOTO , EXIT

Conditional statements - Specified that the truth of a
condition is to be determined and that the subsequent action of
the object program is dependent on this truth value
Examples: IF, EVALUATE, ADDON SIZE ERROR

Compiler Directive statement is beginning with a compiler
verb, that causes compiler to take specific action during
compilation
Examples: USE, COPY
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 62 EDS Internal
PROCEDURE DIVISION
Explicit Scope Terminator Terminates the scope of the
conditional statements
Examples : END-IF, END-READ, END-EVALUATE,
END-CALL, END-SORT

Implicit Scope Terminator is a period that terminates the
scope of all previous statements not yet terminated
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 63 EDS Internal
DATA MOVEMENT
MOVE
To move data into a place in a memory
Format
MOVE {IDENTIFIER-1/LITERAL-1} TO IDENTIFIER-2,
[,IDENTIFIER-3],

RULES
Only one sending field, one or more receiving fields
Value of the sending field remains unaltered after the
statement execution

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 64 EDS Internal
DATA MOVEMENT
Numeric Data Transfer Rules
When sending field is numeric or numeric-edited, the
data movement is called Numeric data transfer

Dominant factor is the decimal points alignment in two
the fields

If the receiving field is not large enough then truncation
occurs either ends or both the ends

If the receiving field is large then the unused positions
will be filled with spaces.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 65 EDS Internal
DATA MOVEMENT
Alphanumeric Data Transfer Rules
When both the sending and receiving fields are
alphabetic, alphanumeric or alphanumeric edited the data
movement is called Alphanumeric

Receiving field is filled from left to right

When receiving field is smaller then truncation occurs
from the right, compiler will give warning
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 66 EDS Internal
DATA MOVEMENT
Group Moves
When at least one of the fields is a group item, it is
called Group Move
Example
01 RECORD-1.
05 A1 PIC 9(3).
05 A2 PIC A(2).
05 A3 PIC XXXX.
01 RECORD-2.
05 A1 PIC 9(3).
05 A2 PIC A(2).
05 A3 PIC XXXX.

MOVE RECORD-1 TO RECORD-2.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 67 EDS Internal
DATA MOVEMENT
Move Corresponding
When the names of the corresponding data item of two
groups are same, this statement can be used for
substitute for a set of move statements
Example
01 PAY-REC.
05 EMP-NO PIC 9(05).
05 EMP-NAME PIC X(20).
01 PRINT-REC.
05 FILLER PIC X(05).
05 EMP-NO PIC 9(05).
05 FILLER PIC X(05).
05 EMP-NAME PIC X(20).
MOVE CORRESPONDING PAY-REC TO PRINT-REC.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 68 EDS Internal
ARITHMETIC VERBS
ADD
To sum two or more numbers and store the result
ADD [CORRESPONDING] [Identifier-1/Literal-1] [Identfier-
2/Literal-2] [TO /GIVING] Identifier-3, Identifier-4..

Example
ADD A TO B.
ADD A , B GIVING C.
ADD CORR OLD-REC TO NEW-REC.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 69 EDS Internal
ARITHMETIC VERBS
SUBTRACT
Used to subtract one or the sum of two or more from
one or more numbers

SUBTRACT [CORR] [Identifier-1/Literal-1] [Identifier-
2/Literal-2] [FROM/GIVING] Identifier-3 Identifier-4.

Example
SUBTRACT A FROM B.
SUBTRACT A B FROM C.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 70 EDS Internal
ARITHMETIC VERBS
MULTIPLY
Used to multiply one or more multiplicands by multiplier

MULTIPLY {IDENTIFIER-1 BY IDENTIFIER-2
[ ,IDENTIFIER-3]...LITERAL - 1}
[GIVING IDENTIFIER-4 [ , IDENTIFIER-5]...]

Example

MULTIPLY A BY B.

MUYLTIPLY A BY B GIVING C.

MULTIPLY 2 BY A.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 71 EDS Internal
ARITHMETIC VERBS
DIVIDE
Used to divide one number by another

DIVIDE {Identifier-1 / Literal-1}
INTO[BY] identifier-2 { ,identifier-3}....
[GIVING identifier-4 [ ,identifier-5]...]
[REMAINDER identifier-6.

Example
DIVIDE 5 INTO A.

DIVIDE A INTO B GIVING C.

DIVIDE A BY B GIVING C REMINDER
D.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 72 EDS Internal
ARITHMETIC VERBS
COMPUTE
Used as a substitute for any other arithmetic verbs like
ADD, SUBTRACT, MULTIPLY and DIVIDE.

COMPUTE IDENTIFIER-1 [ROUNDED]
[ , IDENTIFIER-2 [ ROUNDED ] ]
= ARITHMETIC-EXPRESSION
[ : ON SIZE ERROR]
IMPERATIVE STATEMENT.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 73 EDS Internal
ARITHMETIC OPERATORS
Permitted operators

** Exponentiation
/ Division
* Multiplication
- Subtraction
+ Addition
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 74 EDS Internal
ARITHMETIC OPERATION
ROUNDED OPERATION
It will round the number to the picture clause during
arithmetic operations.
Cant be specified for the identifier that receives the
remainder in a Divide operation
ADD WS-A WS-B GIVING WS-C ROUNDED

ON SIZE ERROR
If the result after an arithmetic operation exceeds the
largest value that can be accommodated in the result field
the error occurs is called ON SIZE ERROR
Used to continue the process instead of terminating
because of error.
ADD A TO B ON SIZE ERROR PERFORM ERROR-PARA.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 75 EDS Internal
COBOL DEFINED VERBS
ACCEPT
To transfer data from an input/output device, or system
information contained in the specified data items like
DATE, TIME etc.
ACCEPT Identifier [FROM mnemonic name
DATE / DAY/ TIME / DAY-OF-WEEK]

DISPLAY
Used to display data on to a terminal
DISPLAY {identifier-1 identifier-2 literal-1} ,literal-2
UPON [mnemonic name]
Example: DISPLAY TOTAL STRENGTH = TOTAL-ST
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 76 EDS Internal
COBOL DEFINED VERBS
INITIALIZE
Used to initialize value of either a group item or an
elementary item

INITIALIZE {identifier-1 } . . .
REPLACING { ALPHABETIC
ALPHANUMERIC
NUMERIC
ALPHA-NUMERIC-EDITED.
NUMERIC-EDITED }
DATA BY { identifier-2
literal-2 }

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 77 EDS Internal
CONDITIONAL AND UNCONDITIONAL TRANSFER

Simple IF statement

IF condition
statement-1
statement-2
ELSE
statement-3
statement-4
END-IF.

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 78 EDS Internal
CONDITIONAL AND UNCONDITIONAL TRANSFER

Nested IF statement

IF condition-1
IF condition-2
statement-1
ELSE
IF condition-3
statement-3
END-IF
END-IF
END-IF.

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 79 EDS Internal
CONDITIONAL AND UNCONDITIONAL TRANSFER

EVALUATE Statement

EVALUATE SUBJECT-1 [ALSO SUBJECT-2]...

{WHEN OBJECT-1 [ALSO OBJECT-2}...}

[WHEN OTHER {IMPERATIVE-STATEMENT-2}...]

[END-EVALUATE].


Can be used instead of nested IF statements
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 80 EDS Internal
CONDITIONAL AND UNCONDITIONAL TRANSFER

GO TO statement
Is an unconditional transferring of control to the
specified paragraph
Advised to avoid GO TO as the structured programming
technique doesnt support unconditional transfer
statements
Example : GO TO REPORT-PARA.

ALTER
Used to modify the targets of GO TO statements written
elsewhere in the procedure division.

ALTER PROCEDURE-NAME-1 TO
[PROCEED TO ] PROCEDURE-NAME-2
[PROCEDURE-NAME-3 TO {PROCEED TO }
PROCEDURE-NAME-4 ]....
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 81 EDS Internal
PERFORM STATEMENT

A PERFORM statement is used to execute a group of
consecutive statements elsewhere in the program, under a
paragraph
Types of PERFORM
PERFORM Para-name-1.
Para-name-1 specifies the range, which contains
statements to be executed

PERFORM para-name-1 thru para-name-2.
This statement executes all the statements
beginning in para-name-1 till the last statement in
para-name-2 including the paragraphs in between
both the paragraphs

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 82 EDS Internal
PERFORM STATEMENT

Types of PERFORM
PERFORM para-name-1 [THRU para-name-2] {identifier-
1/ integer} TIMES
This is a looping statement which executes the
specified range of statements a fixed number of times.

PERFORM para-name-1 [THRU para-name-2] UNTIL
condition.
This statement executes the specified range of
statements repeatedly until the condition becomes
TRUE.
The condition is to be made TRUE within the
paragraph performed
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 83 EDS Internal
PERFORM STATEMENT

Types of PERFORM
PERFORM VARYING {identifier-1 FROM {identifier-2
/integer-1} BY {identifier-3 / integer-2}
UNTIL Condition-1 AFTER identifier-1
FROM {identifier-2/integer-1}
BY {identifier-3/integer-2} UNTIL Condition-2
[imperative statement]
END-PERFORM.

Example

PERFORM VARYING I FROM 1 BY 1 UNTIL I > 3
AFTER J FROM 1 BY 1 UNTIL J > 4
Display SALE ( I , J )
END-PERFORM.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 84 EDS Internal
PERFORM STATEMENT

RELATIONAL CONDITION
Compares two operands either of which can be
identifier literal, arithmetic expression or index-name
A non-numeric literal can be enclosed in parentheses
within a relational condition
Relational operators are: < , <= , >, >=
NOT GREATER THAN / LESS THAN/ EQUAL TO

SIGN CONDITION
Determines whether or not the algebraic value of a
numeric operand is greater than or less than or equal to
Zero
Possible conditions are
POSITIVE, NEGATIVE OR ZERO

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 85 EDS Internal
CONDITIONAL EXPRESSIONS

CLASS CONDITION
Determines whether the content of data item is
alphabetic, numeric or contains only characters in the
set of characters specified by the CLASS clause in the
SPECIAL NAMES paragraph

CONDITION-NAME CONDITION
Tests a conditional variable to determine its value is
equal to any value(s) associated with the condition
name
Are declared at 88 level

NEGATED CONDITION
A condition is negated by using use of operator NOT

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 86 EDS Internal
CONDITIONAL EXPRESSIONS

COMPOUND CONDITION
Two or more conditions can be logically connected
to form a compound condition
Possible values are: AND, OR
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 87 EDS Internal
FILE HANDLING

RECORD : is a collection of relevant fields pertaining to an
item/case/account/transaction
FILE
Is a collection of relevant records of an application
Is organized in storage media either in SEQUENTIAL
or INDEXED or RELATIVE way.

SEQUENTIAL FILES
Records can be accessed in the order in which they
appear in the file
Records can be appended at the end of the file but
cannot be inserted
Records cannot be deleted
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 88 EDS Internal
FILE HANDLING

INDEXED FILES
Records can be accessed Randomly or Sequentially
using key called Primary-key
There can be more than one key called Alternate
keys to access records
Records can be inserted and deleted

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 89 EDS Internal
FILE HANDLING STEPS

STEP 1:
All files handled in a program should be assigned to
logical name
The DDNAME assigned, Organization of the file, its
primary key and alternate keys to be specified in File-
control paragraph.

STEP-2:
Describe the details like record-name, record structure
in File section including number of records grouped as
BLOCK for input output operation

STEP-3
Open the files to do read/write operations in Procedure
division.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 90 EDS Internal
FILE HANDLING STEPS

STEP 4:
If we have to read records then READ statement should
be used
Syntax: READ file-name

STEP 5:
If we have to write record then WRITE statement should
be used
Syntax: WRITE record-name

STEP 6:
After all operations are completed the file has to be
CLOSED to disconnect file from COBOL program
Syntax: CLOSE file-name

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 91 EDS Internal
SELECT STATEMENT

Syntax:

SELECT file-name ASSIGN TO DD Name
ORGANIZATION IS
[SEQUENTIAL/INDEXED/RELATIVE]

ACESS MODE IS
[SEQUENTIAL/DYNAMIC/RANDOM]

[RECORD KEY data-name-1 ]

[ALTERNATE KEY IS data-name-2. WITH
DUPLICATE]

FILE-STATUS IS data-name-2.


Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 92 EDS Internal
SELECT STATEMENT

ORGANIZATION CLAUSE
Following file organizations can be chosen
o SEQUENTIAL
This option is used for PS data set or VSAM ESDS.
The records are places in first come first served
basis
o INDEXED
This option is used to handle a VSAM KSDS
Key field called Primary key should be defined
o RELATIVE
This option is used to handle a VSAM RRDS
Record number is used to access records
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 93 EDS Internal
SELECT STATEMENT

ACCESS MODE CLAUSE
Based on Organization file can be accessed in different
modes
o SEQUENTIAL Access mode To access records in
sequential order

o RANDOM Access mode To access particular record
of an indexed / relative file provided key value is set
prior to read / write operation

o DYNAMIC Access mode To access a particular
record or in sequential order from an indexed / relative
file
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 94 EDS Internal
SELECT STATEMENT

RECORD KEY PHRASE
To be defined for indexed files
To be unique and is to be part of indexed record

ALTERNATE KEY PHRASE
To be defined if records are to be read by using key
other than Primary key
Need not be unique but need to be part of the record
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 95 EDS Internal
FD ENTRY

Syntax
FD file-name.
[BLOCK CONTAINS [int-1 TO] int-2
RECORDS[CHARACTERS]
[RECORDS CONTAINS{int-3 to} int-4 CHARACTERS
[LABEL RECORD/RECORDS IS/ARE STANDARD/OMITTED
RECORDING MODE [F/V]
[DATA RECORD/RECORDS IS/ARE data-name-2
01 record-name
05 field-1 PIC X(10).
.

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 96 EDS Internal
FD ENTRY

BLOCK CONTAINS / RECORD CONTAINS PHRASE
Length of the record can be specified in terms of
characters
Number of characters / records for a Block can be
specified

RECORDING MODE CLAUSE
Specifies as that all the records in a file are of same
length (FIXED) or different (Variable )
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 97 EDS Internal
FD ENTRY

BLOCK CONTAINS / RECORD CONTAINS PHRASE
Length of the record can be specified in terms of
characters
Number of characters / records for a Block can
be specified

RECORDING MODE CLAUSE
Specifies as that all the records in a file are of
same length (FIXED) or different (Variable )
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 98 EDS Internal
INPUT AND OUTPUT STATEMENTS

OPEN Statement
OPEN INPUT file-name - Connects data set to program
to records from the first enabling to read records
OPEN OUTPUT file-name Connects data set to
program though file is empty enabling to write records
OPEN I-O file-name Connects data set to program to
Read/ Write / Rewrite the records to file
OPEN EXTEND file-name Connects the existing data set
to program to append new records at the end of the
existing records in the file

WRITE
Adds records to the file
Key to be used for indexed file

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 99 EDS Internal
INPUT AND OUTPUT STATEMENTS

START
Establishes the current location in the cluster for a
READ NEXT statement
This doesnt retrieve record
It only sorts the current record pointer described under
File position indicator

READ
Used to read record from the file
Reads next record for sequential file
Reads the corresponding key specified


Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 100 EDS Internal
INPUT AND OUTPUT STATEMENTS

REWRITE
Updates record

DELETE
Logically removes the records from the
Indexed/relative files

CLOSE
Disconnects file from the program
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 101 EDS Internal
SUBPROGRAMS

Programs compiled and stored in library to be called
when needed

The program that calls another program is referred as
calling program, and the program it calls is referred as
called program

Called program itself can call another program

During execution, called program can either transfer
control back to the calling program or end the run unit


Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 102 EDS Internal
SUBPROGRAMS

ADVANTAGES
Avoids duplication effort

Improves programmer productivity

Provides greater flexibility

Changes to the called program can be made without
changing the calling program

Results in greater standardization

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 103 EDS Internal
SUBPROGRAMS



Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 104 EDS Internal
SUBPROGRAMS

LINKAGE SECTION
Describes data made available for another
program
Storage for data items within the program is not
reserved because the area exists elsewhere
Value clause may not be specified for items other
than 88 level items

STATIC CALL
The compiler treats the CALL literal statement
where the literal is program name, as a static call
when NODYNUM compiler option is in effect

DYNAMIC CALL
Loads the subprogram at the run time
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 105 EDS Internal
SUBPROGRAMS

CALL by Reference or by Content
To pass an identifiers value only then use CALL
BY REFERENCE

To pass literals value then use CALL BY CONTENT
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 106 EDS Internal
STRING, UNSTRING AND INSPECT STATEMENTS

STRING Statement
Strings together the partial or complete contents of
two or more DATA ITESM or LITERALS into single data
item

STRING IDENTIFIER1 DELIMITED BY
IDENTIFIER 2
LITERAL1 LITERALS
SIZE
INTO IDENTIFIER3 WITH POINTER
IDENTIFIER4
ON OVERFLOW IMPERATIVE STATEMENT1
NOT ON OVERFLOW IMPERATIVE
STATEMENT2
END-STRING
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 107 EDS Internal
STRING, UNSTRING AND INSPECT STATEMENTS

UNSTRING Statement
Causes contiguous data in a sending field to be
separated and placed into multiple receiving fields

UNSTRING IDENTIFIER1 DELIMITED BY
ALL IDENTIFIER 2 LITERAL1
OR ALL IDENTIFIER-3 LITERAL2
INTO IDENTIFIER4 DELIMITER IN
IDENTIFIER5 COUNT IN
IDENTIFIER6
WITH POINTER IDENTIFIER7
TALLYING IN IDENTIFIER8
ON OVERFLOW IMPERATIVE
STATEMENT1
NOT ON OVERFLOW IMPERATIVE
STATEMENT2
END-UNSTRING
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 108 EDS Internal
STRING, UNSTRING AND INSPECT STATEMENTS

INSPECT
Specifies that characters or group of characters in a
data item are to be countered or (tallied) or replaces
or both
Counts all the occurrences of a specific character
Will fill all portions of data item with specified
characters such as spaces or zeros
Will convert all occurrences of specific characters in
a data item to user supplied replacement character

INSPECT IDENTIFIER1 TALLYING
IDENTIFIER2
FOR [ALL/LEADING]
[IDENTIFIER3/LITERAL1] [PHRASE]
[PHRASE] here is AFTER / BEFORE
[INITIAL] IDENTIFIER4/LITERAL2.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 109 EDS Internal
STRING, UNSTRING AND INSPECT STATEMENTS

INSPECT

INSPECT IDENTIFIER1 REPLACING
CHARACTERS
BY [IDENTIFIER2/LITERAL1]
BEFORE/AFTER INITIAL [IDENTIFIER3 /
LITERAL 2] AFTER / LEADING/FIRST
[IDENTIFIER/LITERAL.]
By IDENTIFIER/LITERAL [PHRASE]
PHRASE] here is AFTER / BEFORE
[INITIAL] IDENTIFIER4/LITERAL2.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 110 EDS Internal
DECLARATIVES

Used for tracing the paragraph or procedure executed
by the program as per the instruction given by the
programmer
WITH DEBUGGING MODE option has to be specified
in the OBJECT-C0MPUTER paragraph
Has to be first section in PROCEDURE DIVISION

PROCEDURE DIVISION.

DECLARATIVES.
DEBUG -DECLARATIVES SECTION.
USE FOR DEBUGGING ALL PROCEDURE .
DEBUG -DECLARATIVES -PARA.
DISPLAY TRACING DEBUG-NAME
END DECLARATIVES.


Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 111 EDS Internal
SORT STATEMENT

Accepts records from on or more files and arranges the records
in the ascending/descending order and makes sorted records
available either through an OUTPUT-PROCEDURE or in an
output file.
Can be appeared anywhere in PROCEDURE DIVISION

SORT file-name-1 ON
[ASCENDING/DESCENDING KEY]
data-name-1
[WITH DUPLICATES ] [IN ORDER
COLLATING SEQUENCE IS
Alphabet- name-1]
INPUT PROCEDURE IS procedure-name-1
THRU procedure-name-2
OUTPUT-PROCEDURE IS procedure-name- 3
THRU procedure-name-4
END-SORT.
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 112 EDS Internal
SORT STATEMENT

File-name -1 is the name given in the SD entry that describes
the records to be sorted
data-name-1 specifies a KEY data item on which the SORT
statement will be based
Each data name must identify a data item in a record
associated with file-name -1
Alphabet-name1 must be specified in the alphabet clause of
SPECIAL-NAMES para
USING and INPUT-PROCEDURE are mutually exclusive
Input-Procedure is specified to Select or Modify the Input
Record before Sort
This Procedure can do any modifications in the record and copy
Using RELEASE Statement
GIVING and OUTPUT-PROCEDURE are mutually exclusive
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 113 EDS Internal
SORT STATEMENT

Output-Procedure is specified to Select or Modify the output
Record After Sort
This Procedure can do any modifications in the record and copy
Using RETURN Statement
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 114 EDS Internal
MERGE STATEMENT

Merges two or more input files based on common key.
The merged records are made available to an output file or to
an output procedure

MERGE file-name-1 ON [ASCENDING/DESCENDING KEY]
data-name-1 USING file-name-2 file-name-3
[COLLATING SEQUENCE IS Alphabet-name-1]
GIVING file-name-4 /
OUTPUT-PROCEDURE IS procedure-name-3 THRU
procedure-name-4

File-name -1 is the name given in the SD entry that describes
the records to be merged

GIVING and OUTPUT-PROCEDURE are mutually exclusive
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 115 EDS Internal
INTRINSIC FUNTIONS

NUMBER HANDLING
LENGTH Returns the length of the Picture clause
FUNCTION LENGTH(NAME)
MAX Returns the content of the argument that contains
the maximum value
FUNCTION MAX(MARKS)
MIN Returns the content of the argument that contains
the minimum value
FUNCTION MIN(MARKS)
NUMVAL Returns the numeric value represented by the
alphanumeric character string specified in the argument

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 116 EDS Internal
DATE - TIME

CURRENT DATE
Returns 21 characters alphanumeric value
1..4 Year in the Gregorian calendar
5,6 Month of the year
7,8 Day of the Month
9..14 HHMMSS and so on
DATE-OF-INTERGER
Converts a date in the Gregorian calendar from integer
date form to standard date form yyyymmdd
DAY-OF-INTEGER
Converts a date in the Gregorian calendar from integer
date form to Julian date form yyyymmdd

Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 117 EDS Internal
COMPILER OPTIONS

NOC
Specified to do only Syntax check
NOC (W), NOC (E), NOC (S)
W is warning, E is for error and S for severe. When an
error level of specified or of a more severe level occurs,
compilation stops.
Default is S
DYNAM
Causes subprograms that are invoked through the CALL
literal statement to load dynamically
NODYNAM
Causes the text files of subprograms called with a CALL
literal statement to be included with the calling program into
a single module file
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 118 EDS Internal
ERROR CODES

File Status will have Picture clause of length 2 digits
The first digit denotes general category under which the
error code falls
The second digit will denote the particular type of error
under that category
The first digit categories are:
0 Returned When Successful Open / Read / Write /
Operation.
1 Returned When At End Condition Fails
2 Returned When Index Key Fails
3 Returned When Permanent Open Error Occurs.
4 Returned When Logic Error in
opening/closing/deleting etc
9 Implementer Defined
Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 119 EDS Internal
ERROR CODES

00 - Successful completion
02 - Duplicate key detected
10 - Sequential READ was attempted on an optional file that
was not present or after end of file is reached
21 A sequence error exists for a sequentially accessed
indexed file
39 - An OPEN statement was unsuccessful because of a
conflict between the fixed file attributes and the
attributes specified for the file in the program
03-23-05 30 Sept 2005
page 120 EDS Internal
EDS
RMZ Millenia Business Park
Chennai 600113
91 44 6612 2358
harinath.munupalle@eds.com
Presentation by Harinath M.
EDS and the EDS logo are registered trademarks of Electronic Data Systems Corporation. EDS is an equal opportunity employer
and values the diversity of its people. 2005 Electronic Data Systems Corporation. All rights reserved.

Вам также может понравиться