0% found this document useful (0 votes)
148 views32 pages

COBOL-PPT-6 - Procedure Division - Conditional Statements

The document discusses the COBOL programming language and some of its core concepts. It covers conditional statements like the IF statement, looping constructs like PERFORM, and the usage of COPY books. The learning objectives are to understand COBOL's control structures and program flow, conditional execution, and using IF statements for decision making. Various formats and uses of IF statements, PERFORM statements, COPY statements, and other constructs are described.

Uploaded by

Nagface
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
148 views32 pages

COBOL-PPT-6 - Procedure Division - Conditional Statements

The document discusses the COBOL programming language and some of its core concepts. It covers conditional statements like the IF statement, looping constructs like PERFORM, and the usage of COPY books. The learning objectives are to understand COBOL's control structures and program flow, conditional execution, and using IF statements for decision making. Various formats and uses of IF statements, PERFORM statements, COPY statements, and other constructs are described.

Uploaded by

Nagface
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

MAINFRAMES

COBOL – Common Business Oriented


Language
NAGARAJU DOMALA
Session 2: Learning Objectives

Explain conditional statements and looping constructs

Explain usage of COPY books

Nagaraju Domala
Learning OBJECTIVES :

 Be aware of the control structures in COBOL


 Be aware of altering the program flow
 Be aware of conditional execution of programs
 By using IF statement participants can write decision making programs

Nagaraju Domala
IF Statement
Format for IF statements

IF condition-1
[THEN]
imperative statement-1 . . .
[ELSE
imperative statement-2 . . . ]
[END-IF]

Nagaraju Domala
IF Statement
Using Relational Operators in Place of Words.

RELATIONAL OPERATORS

Symbol Meaning
< IS LESS THAN
> IS GREATER THAN
= IS EQUAL TO

COBOL 85 only
<= IS LESS THAN OR EQUAL TO
>= IS GREATER THAN OR EQUAL TO

Nagaraju Domala
IF Statement

 Do Not Mix Field Types in a Comparison.

 Conditional statements must use fields with the same data types to obtain
proper results.

Numeric Fields Should Not Contain Blanks

There are times when you might want to execute a series of steps only if a
certain condition does not exist.

Nagaraju Domala
IF Statement

 The COBOL expression CONTINUE (COBOL 85) or NEXT SENTENCE (COBOL 74)
will enable you:

 To avoid performing any operation if a condition exists

 To execute instructions only if the ELSE condition is met

Nagaraju Domala
IF Statement
A nested conditional is a conditional in which an IF statement itself can contain
additional IF clauses.

Syntax:
IF condition-1
statement-1
ELSE
IF condition-2
statement-2
ELSE
statement-3
END-IF
END-IF

Nagaraju Domala
IF Statement
To perform an operation or a series of operations if any one of several
conditions exists, use a compound OR condition.

 This means that if any one of several conditions exists, the imperative
statement(s) specified will be executed.

By using OR in a compound conditional, any of the conditions


specified causes execution of the statement(s).

Nagaraju Domala
IF STATEMENT
 If none of the conditions is met, the computer executes either the ELSE
clause, if coded, or the next sentence.

 Any number of conditions separated by ORs may be coded in a single


statement.

 If a statement or statements are to be executed only when all of several


conditions are met, use the word AND in the compound conditional.

Nagaraju Domala
IF Statement
1. Conditions surrounding the word AND are evaluated first.

2. Conditions surrounding the word OR are evaluated last.

3. When there are several AND or OR connectors, the AND


conditions are evaluated first, as they appear in the statement,
from left to right. Then the OR conditions are evaluated, also
from left to right.

4. To override Rules 1--3, use parentheses around conditions you


want to be evaluated first.

Nagaraju Domala
IF Statement
We can test whether a field is POSITIVE, NEGATIVE, or ZERO with a sign test.
Format:
IF identifier IS POSITIVE / NEGATIVE / ZERO

We can test for the type of data in a field by coding


IF identifier- 1 IS NUMERIC

OR

IF identifier-1 IS ALPHABETIC

Nagaraju Domala
IF statement

 Format

IF identifier-1 IS [NOT ]
{{GREATER THAN (>)}
{LESS THAN (<)}
{EQUAL TO (=)}
{LESS THAN OR EQUAL TO (<=)}
{GREATER THAN OR EQUAL TO (>=)}
identifier-2}

Nagaraju Domala
IF Statement

IF identifier-1 IS [NOT]
{{ NUMERIC}
{POSITIVE}
{NEGATIVE }
{ZERO}
{ALPHABETIC}
{ALPHABETIC-UPPER*}
{ALPHABETIC-LOWER*}}

Nagaraju Domala
Condition Names
 A condition-name is a user-defined word established in the DATA DIVISION that
gives a name to a specific value that an identifier can assume.

Conditional Names

It is always coded on the 88 level in the DATA DIVISION

It has only a VALUE clause associated with it.

 it will not contain a PICTURE clause.

Nagaraju Domala
Conditional Names

 Format :

88 condition-name VALUE literal.

 The condition-name must be unique and its VALUE must be a literal


consistent with the data type of the field preceding it:

Nagaraju Domala
Evaluate Statement

EVALUATE {identifier-1}
{expression-1}
WHEN condition-1 imperative- statement-1 . . .
[WHEN OTHER imperative-statement-2]
[END-EVALUATE]

Nagaraju Domala
Perform Statement

•To introduce how structured programming can be done using perform verb

•Different types of perform statements

Nagaraju Domala
Perform Statement

PERFORM Paragraph-Name
PERFORM [paragraph-name-1]

The PERFORM paragraph-name statement will:

1. Execute all instructions in the named paragraph.

2. Transfer control to the next instruction in sequence, after the


PERFORM paragraph-name.

Nagaraju Domala
Perform Statement
Expanded format for the PERFORM paragraph-name statement:

PERFORM paragraph-name-1 {THROUGH} {THRU}


paragraph-name-2

The PERFORM paragraph-name executes all statements beginning at


paragraph-name-1 until the end of paragraph-name-2 is reached.

Control is then transferred to the statement directly following the PERFORM.

Nagaraju Domala
EXIT Statement

EXIT is a COBOL reserved word that performs no operation.

It is used to allow execution to pass over other statements or to transfer


control back to the statement following the original PERFORM.

It is used as an end point in a paragraph being performed.

Nagaraju Domala
Perform Statement

The format of a PERFORM UNTIL ... is:

Format 2
PERFORM [paragraph-name-1] [{THROUGH} {THRU}
paragraph-name-2]
UNTIL condition-1

Nagaraju Domala
Perform Statement
Format
PERFORM paragraph-name-1 [{THROUGH}
{THRU} paragraph-name-2]
{integer-} {identifier-1} TIMES

(1) the identifier must be specified in the DATA DIVISION

(2) it must have a numeric PICTURE clause; and

(3) it must contain only integers or zeros.

Nagaraju Domala
COPY STATEMENT

 Different types of Call statements


 How to use COPY statement

Nagaraju Domala
COPY STATEMENT

Objectives:
1. The COPY statement for copying parts of a program that are stored in
a library.

Nagaraju Domala
COPY STATEMENT

 A COPY statement is used to bring into a program a series of prewritten


COBOL entries that have been stored in a library.

ADVANTAGES:
(1) it could save a programmer a considerable amount of coding and debugging
time;

(2) it promotes program standardization since all programs that copy entries from
a library will be using common data-names and/or procedures;

Nagaraju Domala
COPY STATEMENT

3) It reduces the time it takes to make modifications and reduces duplication of


effort

4) If a change needs to be made to a data entry, it can be made just once in


the library without the need to alter individual programs;

5) Library entries are extensively annotated so that they are meaningful to all
users; this annotation results in better-documented programs and systems.

Nagaraju Domala
COPY STATEMENT

 COPY statement is used to copy FD and 01 entries that define and describe
files and records.

 Standard modules to be used in the PROCEDURE DIVISION of several programs


may also be stored in a library and copied as needed.

Nagaraju Domala
The Full Format for the COPY Statement

 The Full Format for the COPY Statement is:

COPY text-name-1 [{OF}{IN} library-name-1]


[REPLACING {{==pseudo-text-1==}{identifier-1}{literal-1} {word-1}
BY
{==pseudo-text-2}{identifier-2}{literal-2}{word-2}..]

Nagaraju Domala
COPY STATEMENT

 REPLACING clause

 It is omitted from the COPY statement, the library text is copied


unchanged.

 It allows virtually any library entry to be changed when it is being copied


into the user's source program.

Nagaraju Domala
The Full Format for the COPY Statement
Using the library entry called CUSTOMER in the preceding example, suppose we code:

COPY CUSTOMER REPLACING CUST-NO BY


CUST-NUMBER. ==X(5)== BY
==X(6)==.

This results in the following changes to the library entry when it is called into the source program:
14c 01 customer-rec.
15c 05 cust-number pic x(6)
16c 05 cust-name pic x(20).
17c 05 cust-address pic x(30).
18c 05 cust-bal-due pic 9(4)v99.

Nagaraju Domala
The Full Format for the COPY Statement
Using the library entry called CUSTOMER in the preceding example, suppose we code:

COPY CUSTOMER REPLACING CUST-NO BY


CUST-NUMBER. ==X(5)== BY
==X(6)==.

This results in the following changes to the library entry when it is called into the source program:
14c 01 customer-rec.
15c 05 cust-number pic x(6)
16c 05 cust-name pic x(20).
17c 05 cust-address pic x(30).
18c 05 cust-bal-due pic 9(4)v99.

Nagaraju Domala

You might also like