COBOL-PPT-6 - Procedure Division - Conditional Statements
COBOL-PPT-6 - Procedure Division - Conditional Statements
Nagaraju Domala
Learning OBJECTIVES :
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
Conditional statements must use fields with the same data types to obtain
proper results.
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:
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.
Nagaraju Domala
IF STATEMENT
If none of the conditions is met, the computer executes either the ELSE
clause, if coded, or the next sentence.
Nagaraju Domala
IF Statement
1. Conditions surrounding the word AND are 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
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
Nagaraju Domala
Conditional Names
Format :
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
Nagaraju Domala
Perform Statement
PERFORM Paragraph-Name
PERFORM [paragraph-name-1]
Nagaraju Domala
Perform Statement
Expanded format for the PERFORM paragraph-name statement:
Nagaraju Domala
EXIT Statement
Nagaraju Domala
Perform Statement
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
Nagaraju Domala
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
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
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.
Nagaraju Domala
The Full Format for the COPY Statement
Nagaraju Domala
COPY STATEMENT
REPLACING clause
Nagaraju Domala
The Full Format for the COPY Statement
Using the library entry called CUSTOMER in the preceding example, suppose we code:
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:
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