cobol programming day 2. copyright © 2005, infosys technologies ltd 2 er/corp/crs/la01/003 version...

73
COBOL Programming DAY 2

Upload: allison-mitchell

Post on 27-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

COBOL ProgrammingDAY 2

Page 2: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

2ER/CORP/CRS/LA01/003

Version 1.0

Data Movement verbs.

Sequence Control verbs.

Types of conditions.

REDEFINES, RENAMES, USAGE clauses.

Design and development of sample programs.

Agenda for Day2

Page 3: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

3ER/CORP/CRS/LA01/003

Version 1.0

• The MOVE copies data from the source identifier or literal to one or more destination identifiers.

• The source and destination identifiers can be group or elementary data items.

• When the destination item is alphanumeric or alphabetic (PIC X or A) data is copied into the destination area from left to right with space filling or truncation on the right.

• When data is MOVEd into an item the contents of the item are completely replaced. If the source data is too small to fill the destination item entirely the remaining area is zero or space filled.

MOVE VERB

Page 4: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

4ER/CORP/CRS/LA01/003

Version 1.0

MOVE verb…

... TO MOVE IdentifierLiteral

Identifier

Page 5: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

5ER/CORP/CRS/LA01/003

Version 1.0

(1) MOVE

(2) MOVE . . . CORRESPONDING ( CORR )

(3) MOVE . . . OF . . . TO . . . OF

DATA movement verbs…

Page 6: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

6ER/CORP/CRS/LA01/003

Version 1.0

Before

WS00-OUT1 ‘BEST’

WS00-OUT2 1234

Before

WS00-OUT1 ‘ ’

WS00-OUT2 0

Before

WS00-OUT3 0786

After

WS00-OUT3 2345

Before

WS00-OUT4 ‘PAYAL PAREKH’

After

WS00-OUT4 ‘SHUTI DEY’

Page 7: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

7ER/CORP/CRS/LA01/003

Version 1.0

MOVE to a numeric item

• When the destination item is numeric, or edited numeric, then data is aligned along the decimal point with zero filling or truncation as necessary.

• When the decimal point is not explicitly specified in either the source or destination items, the item is treated as if it had an assumed decimal point immediately after its rightmost character.

Page 8: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

8ER/CORP/CRS/LA01/003

Version 1.0

Before

WS00-OUT1 0000

WS00-OUT2 000000

Before

WS00-OUT1 3456

WS00-OUT2 345678

Before

WS00-OUT3 000000

After

WS00-OUT3 123456

Before

WS00-OUT4 00000000

After

WS00-OUT4 12345678

Page 9: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

9ER/CORP/CRS/LA01/003

Version 1.0

MOVE .. example

****************************

WS00-OUT1 : HARAYANA

WS00-OUT2 : HARAYANA

****************************

Output SPOOL

Page 10: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

10ER/CORP/CRS/LA01/003

Version 1.0

Is used to change the default type movement of alphabetic and alphanumeric data.

Example

01 NAME PIC X(10) JUSTIFIED RIGHT.

MOVE “KAJOL” TO NAME.

Contents of NAME field is

bbbbbKAJOL

JUSTIFIED RIGHT clause

Page 11: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

11ER/CORP/CRS/LA01/003

Version 1.0

JUSTIFIED RIGHT clause .. example

*********************************************

WS00-OUT1 : ABCDEFGHIJKLMNOPQRSTUVWXYZ

WS00-OUT2 : ABCDEFGHIJKLMNOPQRSTUVWXYZ

*********************************************

Output SPOOL

Page 12: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

12ER/CORP/CRS/LA01/003

Version 1.0

• Facilitates movement of value of sub-item of a group item to a similar named sub-item of another group item

Syntax

MOVE { CORRESPONDING, CORR } identifier-1 TO identifier-2

where identifier-1 and identifier-2 are group items.

MOVE CORRESPONDING

Page 13: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

13ER/CORP/CRS/LA01/003

Version 1.0

MOVE CORRESPONDING .. example

****************************

WS00-GR2 : NISHANT 00000

****************************

Output SPOOL

Page 14: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

14ER/CORP/CRS/LA01/003

Version 1.0

Facilitates the movement of a particular field of a record to a particular field of another record. (in other words it facilitates movement of value of a individual/group item of one group item to an individual/group item of another group item).

Example:

MOVE NAME OF STUD-REC TO WS-NAME OF WS-STUD-REC.

MOVE . . . OF . . . TO . . . OF

Page 15: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

15ER/CORP/CRS/LA01/003

Version 1.0

Certain combinations of sending and receiving data types are not permitted.

Alphabetic Alphanumeric

Edited Alphanumeric

Numeric Numeric non integer

Edited numeric

Alphabetic Y Y Y N N N

Alphanumeric Y Y Y Y Y Y

Edited Alphanumeric

Y Y Y N N N

Numeric N Y Y Y Y Y

Numeric non integer

N N N Y Y Y

Edited numeric

N Y Y Y Y Y

Receiving field

Sen

ding

fie

ldLEGAL MOVES

Page 16: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

16ER/CORP/CRS/LA01/003

Version 1.0

• GOTO

• IF . . . THEN . . .

• PERFORM

• EVALUATE

• STOP RUN

SEQUENCE CONTROL verbs

Page 17: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

17ER/CORP/CRS/LA01/003

Version 1.0

• Syntax-1

GO TO Paragraph Name.

• Example

GO TO 400-READ-PARA.

GO TO Verb

Page 18: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

19ER/CORP/CRS/LA01/003

Version 1.0

• Syntax-1

IF condition [ THEN ] {statement-1, NEXT SENTENCE} [ELSE {statement-2, NEXT SENTENCE}]

[ END-IF ].

• Examples

(1) IF MARKS >= 80 THEN MOVE ‘A’ TO GRADEELSE MOVE ‘B’ TO GRADE

END-IF.

(2) IF NOT OK-BALANCE THEN MOVE 2 TO BALANCE-CODE ELSE NEXT-SENTENCE END-IF

IF statement

Page 19: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

20ER/CORP/CRS/LA01/003

Version 1.0

• Syntax-2 ( Nested IF )IF condition-1 [ THEN ] statement-1ELSE IF condition-2 [ THEN ] statement-2 ELSE statement-3

END-IFEND-IF.

• Example

IF ( Var1 < 10 ) THEN DISPLAY “Zero” ELSE IF Var2 = 14 THEN DISPLAY “First”

ELSE DISPLAY “Second” END-IF

END-IF.

IF statement

Page 20: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

21ER/CORP/CRS/LA01/003

Version 1.0

• Example

IF TIME < 2 AND TIME > 1 THEN MOVE “SLOW” TO SPEED

END-IF.

Is equivalent to

IF TIME < 2 AND > 1 THEN MOVE “SLOW” TO SPEED.

• Note: The following statement is invalid.

IF TOT-1 OR TOT-2 = 7 THEN DISPLAY “ The Sum is 7.”.

IF statement - Implied Operands

Page 21: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

22ER/CORP/CRS/LA01/003

Version 1.0

• Relational condition

• Sign condition

• Class condition

• Compound condition

• Condition-name

Classification of Conditions

Page 22: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

23ER/CORP/CRS/LA01/003

Version 1.0

Identifier

Literal

ArithmeticExpression

Identifier

Literal

ArithmeticExpression

IS

NOT GREATER THAN

NOT >

NOT LESS THAN

NOT <

NOT EQUAL TO

NOT =

GREATER THAN OR EQUAL TO

>=

LESS THAN OR EQUAL TO

<=

Relational condition

Page 23: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

24ER/CORP/CRS/LA01/003

Version 1.0

• Syntax

• Example

IF DISCRIMINANT IS NEGATIVE THEN

DISPLAY “The roots are imaginary”.

ZERO

NEGATIVE

POSITIVE

]NOT[ IS Expression Arithmetic

Sign condition

Page 24: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

25ER/CORP/CRS/LA01/003

Version 1.0

• Syntax

• Example

IF REGNO IS NOT NUMERIC

THEN DISPLAY “Records will not be sorted”.

Identifier IS [NOT]

NUMERIC

ALPHABETIC

ALPHABETIC - LOWER

ALPHABETIC - UPPER

UserDefinedClassName

Class condition

Page 25: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

26ER/CORP/CRS/LA01/003

Version 1.0

• Syntax

Condition-1 { AND, OR } Condition-2

• Examples

(1) IF PERCENT > 80 AND TOTAL > 480

THEN MOVE ‘A’ TO GRADE.

(2) IF ROW-NUMBER > 24 OR COLUMN > 80

THEN DISPLAY “Page Error ! “.

Compound Condition

Page 26: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

27ER/CORP/CRS/LA01/003

Version 1.0

• Are essentially boolean variables.

• Are always associated with data names called condition variables.

• Is defined in the DATA DIVISION with levelnumber 88.

• Syntax

88 condition-name {VALUE IS, VALUES ARE } literal-1 [ { THRU, THROUGH } literal-2 ].

Condition Names

Page 27: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

28ER/CORP/CRS/LA01/003

Version 1.0

01 MARITAL STATUS PIC 9.

88 SINGLE VALUE IS ZERO. 88 MARRIED VALUE IS 1. 88 WIDOWED VALUE IS 2. 88 DIVORCED VALUE IS 3. 88 ONCE-MARRIED VALUES ARE 1, 2, 3. 88 VALID-STATUS VALUES ARE 0 THRU 3.

PROCEDURE DIVISION Statements.

IF SINGLE SUBTRACT 125 FROM DEDUCTIONS.IF ONCE-MARRIED ADD 300 TO SPECIAL-PAY.IF MARRIED PERFORM B000-MARRIAGE-GIFT.

Condition Variable

Condition Names

Condition-Names .. example

Page 28: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

29ER/CORP/CRS/LA01/003

Version 1.0

• Condition Names are defined using the special level number 88 in the DATA DIVISION of a COBOL program.

• They are defined immediately after the definition of the data item with which they are associated with.

• We can use Condition Names for a group as well as an elementary item.

• A condition name takes the value TRUE or FALSE depending on the value of the data item with which it is associated. The VALUE clause of the associated data item is used to identify the values which make the Condition Name TRUE.

88 ConditionName VALUE

VALUES

Literal

LowValue THROUGH

THRU HighValue

Defining Condition Names.

Page 29: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

30ER/CORP/CRS/LA01/003

Version 1.0

Before

WS00-MARKS 000

WS00-DISP

After

WS00-MARKS 050

WS00-DISP NOT CLEARED COMPRE

Before

WS00-MARKS 000

WS00-DISP

After

WS00-MARKS 081

WS00-DISP PASSED COMPRE

JCL

000100 //ER4857C JOB ,,NOTIFY=&SYSUID,CLASS=B

000500 //STEP1 EXEC PGM=COND88

000700 //STEPLIB DD DSN=OPERN.CICS3.LOADLIB,DISP=SHR

000800 //SYSIN DD *

000900 050

001000 081

001100 /*

Page 30: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

31ER/CORP/CRS/LA01/003

Version 1.0

Break

Page 31: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

32ER/CORP/CRS/LA01/003

Version 1.0

• Iteration constructs are used when we need to repeat the same instructions over and over again in our programs.

• Other programming languages have a variety of iteration / looping constructs (e.g. WHILE, FOR, REPEAT). Each of these in turn facilitate the creation of different ‘types’ of iteration structure.

• In COBOL we have ‘PERFORM’ verb which is used to create these looping constructs. The PERFORM has several variations each of which simulates different looping constructs of other programming languages.

The PERFORM Verb

Page 32: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

33ER/CORP/CRS/LA01/003

Version 1.0

Paragraphs - Revisited

• A PARAGRAPH comprises of one or more sentences.

• The paragraph-name indicates the start of a paragraph. The next paragraph or section name or the end of the program text terminates the paragraph.

• Paragraph names are either user defined or language enforced. They are followed by a full stop.

– B0000-PERF-PARA.– PROGRAM-ID.

Page 33: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

34ER/CORP/CRS/LA01/003

Version 1.0

P0000-PROCESS-RECORD. DISPLAY StudentRecord READ StudentFile

AT END MOVE HIGH-VALUES TO StudentRecord END-READ.

D0000-PRODUCE-OUTPUT. DISPLAY “Here is a message”.

NOTENOTE

Scope of P0000-PROCESS-RECORD is delimited by the occurrence the paragraph name D0000-PRODUCE-OUTPUT.

NOTENOTE

Scope of P0000-PROCESS-RECORD is delimited by the occurrence the paragraph name D0000-PRODUCE-OUTPUT.

Paragraph Example

Page 34: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

35ER/CORP/CRS/LA01/003

Version 1.0

• Simple PERFORM

• In-line PERFORM

• Nested PERFORM

• PERFORM . . . THRU

• PERFORM . . . UNTIL

• PERFORM . . . TIMES

• PERFORM . . . VARYING

PERFORM Verb - variations

Page 35: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

36ER/CORP/CRS/LA01/003

Version 1.0

• Syntax

PERFORM Paragraph-Name.

• Example

PERFORM 500-PROCESS-PARA.

• This is not iterative but instructs the computer to execute the chunk of code inside the mentioned paragraph before reverting back to the sentence following the PERFORM coded.

PERFORM Verb - Simple PERFORM

Page 36: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

37ER/CORP/CRS/LA01/003

Version 1.0

PERFORM Verb – Simple PERFORM example

****************************************

WE ARE INSIDE B000-LAST-PARA

WE ARE INSIDE B001-FIRST-PARA

WE ARE INSIDE B002-MIDDLE-PARA

****************************************

Output SPOOL

Page 37: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

38ER/CORP/CRS/LA01/003

Version 1.0

• Syntax

PERFORM imperative-statements.

• Example

PERFORM MOVE NUM-1 TO MAXIF NUM-2 > MAX THEN MOVE NUM-2 TO MAXDISPLAY “Maximum is ” MAX.

END-PERFORM

Lets see an example ..

PERFORM Verb - In-line PERFORM

Page 38: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

39ER/CORP/CRS/LA01/003

Version 1.0

INLINE PERFORM PROGRAM

Page 39: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

40ER/CORP/CRS/LA01/003

Version 1.0

JCL FOR THE INLINE PERFORM PROGRAM

Page 40: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

41ER/CORP/CRS/LA01/003

Version 1.0

When SYSIN data satisfies the condition WS-STRING = ‘KARINA’ the scope of the INLINE PERFORM gets

terminated

Page 41: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

42ER/CORP/CRS/LA01/003

Version 1.0

• Syntax

Paragraph-Name-1. PERFORM Paragraph-Name-2. . . . . . . . . . .Paragraph-Name-2. PERFORM Paragraph-Name-3.

. . . . . . . . . .Paragraph-Name-3. MOVE A TO B.

. . . . . . . . . .

PERFORM Verb – Nested PERFORM

Page 42: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

43ER/CORP/CRS/LA01/003

Version 1.0

PERFORM Verb – Nested PERFORM

****************************************

WE ARE INSIDE B000-LAST-PARA

WE ARE INSIDE B001-FIRST-PARA

WE ARE INSIDE B002-MIDDLE-PARA

****************************************

Output SPOOL

Page 43: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

44ER/CORP/CRS/LA01/003

Version 1.0

• Syntax

PERFORM Paragraph-Name-1 [ { THRU, THROUGH }

Paragraph-Name-2 ].

• Example

PERFORM 300-READ-PARA THRU 600-UPDATE-PARA.

PERFORM Verb – PERFORM … THRU …

Page 44: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

45ER/CORP/CRS/LA01/003

Version 1.0

PERFORM … THRU … - example

****************************

WE ARE INSIDE B000-DISP-PARA

WE ARE INSIDE B001-DISP-PARA

WE ARE INSIDE B002-DISP-PARA

****************************

Output SPOOL

Page 45: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

46ER/CORP/CRS/LA01/003

Version 1.0

• Syntax

PERFORM Paragraph-Name-1 [ { THRU, THROUGH }

Paragraph-Name-2 ] UNTIL condition.

• Example

PERFORM 300-READ-PARA UNTIL EOF = ‘N’.

PERFORM Verb – PERFORM .. UNTIL ..

Page 46: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

47ER/CORP/CRS/LA01/003

Version 1.0

• Syntax

PERFORM Paragraph-Name-1 [ { THRU, THROUGH }

Paragraph-Name-2 ]

[WITH TEST {BEFORE, AFTER}]

UNTIL condition.

• ExamplePERFORM 300-PROCESS-PARA WITH TEST AFTER

UNTIL VALUE NOT = 0.

PERFORM Verb – PERFORM . . UNTIL .. WITH TEST AFTER OPTION

Page 47: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

48ER/CORP/CRS/LA01/003

Version 1.0

• This format is used where the WHILE or REPEAT constructs are used in other languages.

• If the WITH TEST BEFORE phrase is used the PERFORM behaves like a WHILE loop and the condition is tested before the loop body is entered.

• If the WITH TEST AFTER phrase is used the PERFORM behaves like a REPEAT loop and the condition is tested after the loop body is entered.

• The WITH TEST BEFORE phrase is the default and so is rarely explicitly stated.

PERFORM . . UNTIL .. WITH TEST AFTER OPTION

Page 48: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

49ER/CORP/CRS/LA01/003

Version 1.0

PERFORM Verb – PERFORM . . UNTIL .. WITH TEST BEFORE

****************************

****************************Output SPOOL

Page 49: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

50ER/CORP/CRS/LA01/003

Version 1.0

PERFORM Verb – PERFORM . . UNTIL .. WITH TEST AFTER

****************************

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

****************************

Output SPOOL

10 Times!! Why?

Page 50: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

51ER/CORP/CRS/LA01/003

Version 1.0

• Syntax

PERFORM Paragraph-Name-1 [ { THRU, THROUGH }

Paragraph-Name-2 ] { integer, identifier } TIMES.

• Example

PERFORM 500-PROCESS-PARA THRU 800-END-PARA 8 TIMES.

PERFORM Verb – PERFORM .. TIMES

Page 51: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

52ER/CORP/CRS/LA01/003

Version 1.0

PERFORM Verb – PERFORM .. TIMES …… Example

****************************

HELLO GUEST. WELCOME TO E&R TRAINING

HELLO GUEST. WELCOME TO E&R TRAINING

HELLO GUEST. WELCOME TO E&R TRAINING

HELLO GUEST. WELCOME TO E&R TRAINING

HELLO GUEST. WELCOME TO E&R TRAINING

****************************

Output SPOOL

Page 52: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

53ER/CORP/CRS/LA01/003

Version 1.0

• Syntax

PERFORM Paragraph-Name-1 [ { THRU, THROUGH }Paragraph-Name-2 ] VARYING identifier-1 FROM{identifier-2, integer-1} BY { identifier-3, integer-2 } UNTIL condition.

• Example

PERFORM 500-WRITE-PARA VARYING I FROM 1 BY 1 UNTIL I > 5.

PERFORM Verb - PERFORM . . . VARYING

Page 53: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

54ER/CORP/CRS/LA01/003

Version 1.0

PERFORM Verb - PERFORM . . . VARYING

****************************

HELLO GUEST. WISH YOU ALL THE BEST

HELLO GUEST. WISH YOU ALL THE BEST

HELLO GUEST. WISH YOU ALL THE BEST

HELLO GUEST. WISH YOU ALL THE BEST

****************************

Output SPOOL

Page 54: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

55ER/CORP/CRS/LA01/003

Version 1.0

• Is used to transfer the control back to the statement following the

“PERFORM statement” from within a paragraph invoked by the

PERFORM statement.

Syntax

EXIT.

Note:

It is recommended to avoid using EXIT similar to GO TO since it is against the

idea of structured programming.

EXIT statement

Page 55: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

57ER/CORP/CRS/LA01/003

Version 1.0

EVALUATE

Identifier

Literal

CondExpression

ArithExpression

TRUE

FALSE

WHEN

ANY

Condition

TRUE

FALSE

NOT

Identifier

Literal

ArithExpression

THRU

THROUGH

Identifier

Literal

ArithExpression

StatementBlock

WHEN OTHER StatementBlock

END - EVALUATE

The Evaluate

Page 56: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

58ER/CORP/CRS/LA01/003

Version 1.0

EVALUATE Verb .. example

There are two valid ranges

which the logic checks for –

1) Marks > 79

2) Marks > 64 & <= 79

*************************************

YOU HAVE CLEARED EXAM WITH A GRADE

*************************************Output SPOOL

Page 57: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

59ER/CORP/CRS/LA01/003

Version 1.0

• Syntax : STOP RUN.

• Instructs the computer to terminate the program.

• Closes all the files that were opened for file operations.

• The STOP RUN is usually the last statement in the main paragraph.

STOP RUN statement

Page 58: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

60ER/CORP/CRS/LA01/003

Version 1.0

• Facilitates two or more data-names to point to the same memory location

Syntax

data-name-1 REDEFINES data-name-2.

Example

01 STUD-DETAILS. 05 STUD-NAME. 10 FIRST-NAME PIC A(15). 10 MIDDLE-NAME PIC A(10). 10 LAST-NAME PIC A(10). 05 NAME REDEFINES STUD-NAME.

REDEFINES Clause

Page 59: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

61ER/CORP/CRS/LA01/003

Version 1.0

Rules governing REDEFINES clause

Multiple REDEFINES is allowed for a data-item.

REDEFINES clause must not be used for 01 level in FILE SECTION.

Must not be used for data-items defined in level numbers 66 and 88.

The REDEFINING item should not have an OCCURS clause.

Any change in REDEFINED item reflects on the value of the REDEFINING item and vice-versa.

REDEFINES Clause

Page 60: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

62ER/CORP/CRS/LA01/003

Version 1.0

REDEFINES CLAUSE … example

************************************

YEAR FOR ENTERED DATE IS : 2005

MONTH FOR ENTERED DATE IS : 01

DAY FOR ENTERED DATE IS : 01

************************************

Output SPOOL

WS00-YEAR2 redefines WS00-YEAR1.

It is the same 8 bytes of information which WS00-YEAR2 provides in the Year, Month & Day format in it’s sub-items.

Any change in WS00-YEAR1 changes value of WS00-YEAR2 and vice-versa.

Page 61: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

63ER/CORP/CRS/LA01/003

Version 1.0

• Facilitates re-grouping of elementary data items in a record. After the renames enforcement the elementary items would belong to the original (renamed) group item as well as the new (renaming) group item.

Syntax

66 data-name-1 RENAMES data-name-2 THRU data-name-3.

Rules to be followed while using RENAMES

RENAMES must be used after the description of the fields required.

Must be coded only with level number 66.

Data-names 2 and 3 should not have level numbers 01 and OCCURS Clause.

The elementary items getting renamed should be contiguous.

RENAMES Clause

Page 62: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

64ER/CORP/CRS/LA01/003

Version 1.0

Example

01 STUD-DETAILS.05 REG-NO PIC 9(5).05 S-F-NAME PIC X(15).05 S-M-NAME PIC X(12).05 S-L-NAME PIC X(8).

66 STUD-NAME RENAMES S-F-NAME THRU S-L-NAME.

RENAMES Clause

Page 63: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

65ER/CORP/CRS/LA01/003

Version 1.0

RENAMES clause .. example

*********************************

WS-REN VALUE IS : 341234

*********************************

Output SPOOL

WS-REN would be picking up the value of the sub-items from WS-IN12 to WS-22 (spreading across WS-IN1 & WS-IN2 values).

Note that WS-IN11 is left out.

Page 64: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

66ER/CORP/CRS/LA01/003

Version 1.0

• Is used to specify the internal form in which the data is to be stored.

• Every variable will have an attached usage clause (even if not declared by the programmer).

• Syntax

USAGE IS {DISPLAY, COMPUTATIONAL, COMP} [ - {1, 2, 3}].

USAGE Clause

Page 65: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

67ER/CORP/CRS/LA01/003

Version 1.0

• USAGE is DISPLAY– Each character of the data is represented in one byte

• USAGE IS COMPUTATIONAL– The data item is represented as pure binary

• USAGE IS COMP-1– The data item is represented as a single precision floating point number

(similar to real or float).

• USAGE IS COMP-2– The data item is represented internally as Double precision floating

number (similar to Long or Double).

• USAGE IS COMP-3– In decimal form but 1 digit takes half a byte (nibble). The sign is stored as

right most half a byte character.

USAGE Clause

Page 66: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

68ER/CORP/CRS/LA01/003

Version 1.0

Rules to followed while using USAGE clause

Usage clause cannot be used with data items declared with 66 or 88 levels.

Usage clause when declared for a group item, ensures that all the sub-items of the group item default to the same USAGE clause as

thegroup item’s.

USAGE Clause

Page 67: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

69ER/CORP/CRS/LA01/003

Version 1.0

USAGE Clause .. exampleB0001-POPULATE-FIELDS.

MOVE 99999 TO WS00-COMP-FORM

MOVE 99999 TO WS00-COMP1-FORM

MOVE 99999 TO WS00-COMP2-FORM

MOVE 99999 TO WS00-COMP3-FORM

B0002-DISPLAY-FIELDS.

DISPLAY '******************************************'

DISPLAY '* COMP DISPLAY IS : ' WS00-COMP-FORM

DISPLAY '* COMP1 DISPLAY IS : ' WS00-COMP1-FORM

DISPLAY '* COMP2 DISPLAY IS : ' WS00-COMP2-FORM

DISPLAY '* COMP3 DISPLAY IS : ' WS00-COMP3-FORM

DISPLAY '******************************************'

******************************************

* COMP DISPLAY IS : 99999

* COMP1 DISPLAY IS : .99999000E 05

* COMP2 DISPLAY IS : .99999000000000000E 05

* COMP3 DISPLAY IS : 99999

******************************************

Output SPOOL

Page 68: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

70ER/CORP/CRS/LA01/003

Version 1.0

Data Movement verbs. (MOVE)

Sequence Control verbs (IF,PERFORM,EVALUATE)

Types of conditions.

REDEFINES, RENAMES, USAGE clauses

Review

Page 69: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

71ER/CORP/CRS/LA01/003

Version 1.0

• What is wrong with the following code

(1) IF A EQUALS B

MOVE 1 TO A

END –IFThis should be ; IF A IS EQUAL TO B

Review questions

Page 70: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

72ER/CORP/CRS/LA01/003

Version 1.0

• How many times will the paragraph named100-PARA be executed by the following PERFORM STATEMENTPERFORM 100-PARA VARYING X FROM 1 BY 1 UNTIL X=10

PERFORM 100-PARA VARYING X FROM 1 BY 1 UNTIL X > 10

PERFORM 100-PARA VARYING XFROM 0 BY 1 UNTIL X=10

9 TIMES

10 TIMES

10 TIMES

Review questions ..

Page 71: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

73ER/CORP/CRS/LA01/003

Version 1.0

• State true or false

– The justified clause can be used for any data type

– The redefines clause can be used to redefine only elementary items

– The data item at the level 49 will always have a picture clause

– In a move statement, though the sending field is one, the receiving fields may be more than one.

False

False

True

True

Review questions

Page 72: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

74ER/CORP/CRS/LA01/003

Version 1.0

Summary

• Data Movement verbs.

• Sequence Control verbs.

• Types of conditions.

• REDEFINES, RENAMES, USAGE clauses.

• Design and development of sample programs

Page 73: COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs

Copyright © 2005, Infosys Technologies Ltd

75ER/CORP/CRS/LA01/003

Version 1.0

Thank You!