Procedure Division & Basic Verbs
-
Upload
murtaza-abbas -
Category
Technology
-
view
3.315 -
download
0
description
Transcript of Procedure Division & Basic Verbs
Introduction to COBOL Programming
Overview and Examples
PROCEDURE DIVISION consists of uniquely named SECTIONS section-name SECTION.
A SECTION can have zero or more PARAGRAPHS
A PARAGRAPH has zero or more SENTENCES
SENTENCES are a set of STATEMENTS terminated by a period
STATEMENTS are operations to be performed by the computer
PROCEDURE DIVISION. { section-name SECTION. [paragraph-name. [sentence 1] … … [sentence n] ] … }
PROCEDURE DIVISION. [paragraph-name. [sentence 1] …
[sentence n] ] …
Structure Of Procedure Division
A STATEMENT always starts with a VERB and consists of words and literals
A SENTENCE is a set of one or more STATEMENTS terminated by a period ‘.’
ADD A TO B. IF X GREATER THAN 1000 GO TO PARA-BIG.
There can be more than one STATEMENT or SENTENCE in a line. Alternatively, a STATEMENT can be broken and can be continued in the next line
Structure Of Procedure Division
SECTIONS in PROCEDURE DIVISION are user-defined and not fixed as in DATA and ENVIRONMENT DIVISIONS
SECTIONS are terminated either by the appearance of another SECTION HEADER or at the end of PROCEDURE DIVISION
SECTIONS must start with a name followed by SECTION keyword with at least one space in between
Section-name SECTION.
A PARAGRAPH consists of zero or more statements
The PARAGRAPH is terminated by the appearance of another PARAGRAPH HEADER or SECTION HEADER or at the end of PROCEDURE DIVISION
Para-one. MOVE d-rate TO rate MULTIPLY amt BY rate GIVING dividend.
Para-two. Para-three.
SENTENCES and STATEMENTS must be written in AREA B
To avoid ambiguity, all section names must be unique and different from paragraph names, data names
All paragraphs within a section must have unique name, but need not be unique in the entire program
Paragraph-name OF section-name
sect1 SECTION. this-para. [statements] second-para. [statements]
sect2 SECTION. this-para. [sentences]
Paragraph-name OF section-name
sect1 SECTION. this-para. [statements] this-
para OF sect1 second-para. [statements]
sect2 Section. this-para. [sentences] this-para
OF sect2
Basic Verbs
MOVE verb is necessary to transfer a data from one place to another.
MOVE {identifier1 / literal 1} TO identifer2, [,id3]…
MOVE A TO B. MOVE 3 TO C. MOVE X TO Y, Z.
Before Execution
After Execution
Before Execution
After Execution
Before Execution
After Execution
Before Execution
After Execution
Before Execution
After Execution
Before Execution
After Execution
Before Execution
After Execution MOVE 15 TO A MOVE “THERE IS AN ERROR” TO
B MOVE A TO B, C, D
Arithmetic Verbs
To compute sum of two or more numbers.
ADD {identifier1 / literal1} [id2, lit2] .. TO identifier3 [, id4] …
ADD {identifier1 / literal1} {id2, lit2} .. GIVING identifr3 [, id4] …
ADD A To B B = A + B ADD A B C TO D D = A + B + C + D ADD 15 A TO B B = 15 + A + B ADD A B GIVING C C = A + B ADD A B GIVING C D E C = D = E = A + B
Arithmetic Verbs
To subtract one, or the sum of two or more numbers from one or more numbers.
SUBTRACT {identifier1 / literal1} [id2, lit2] .. FROM identifier3 [, id4] … [, GIVING identifier5 [, identifier6] … ]
SUBTRACT A FROM B B = B – A SUBTRACT A B FROM C C = C – A – B [=C – (A+B) ] SUBTRACT A B FROM C GIVING D D = C – (A + B) SUBTRACT A B From 50 GIVING C C = 50 – (A +
B) SUBTRACT 15 FROM A B A = A – 15 & B = B – 15