150 likes | 310 Views
COBOL (COMMON BUSINESS ORIENTED LANGUAGE). Overview. SEQUENCE CONTROL verbs. GO TO IF . . . THEN . . . PERFORM EVALUATE STOP RUN. GO TO Verb. Syntax-1 GO TO paragraph-name. Example GO TO READ-PARA. GO TO. Syntax-2
E N D
SEQUENCE CONTROL verbs • GO TO • IF . . . THEN . . . • PERFORM • EVALUATE • STOP RUN
GO TO Verb • Syntax-1GO TO paragraph-name. • ExampleGO TO READ-PARA.
GO TO . . • Syntax-2 GO TO paragraph-name-1 [paragraph-name-2 ]Example GO TO INSERT-PARA, UPDATE-PARA, DELETE-PARA DEPENDING ON TRANS-CODE.
IF statement • 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 GRADE ELSE MOVE ‘B’ TO GRADE END-IF. (2) IF NOT OK-BALANCE THEN MOVE 2 TO BALANCE-CODE ELSE NEXT-SENTENCE END-IF
CONDITION • The condition can be any one of the conditions • Simple Conditions • Relation Conditions • Class Conditions • Sign Conditions • Compound Conditions • Condition Names
IF statement • Syntax-2 ( Nested IF ) IF condition-1 [ THEN ] statement-1 ELSE IF condition-2 [ THEN ] statement-2 ELSE statement-3 END-IF END-IF. Example IF ( Var1 < 10 ) THEN DISPLAY “Zero” ELSE IF Var2 = 14 THEN DISPLAY “First” ELSE DISPLAY “Second” END-IF END-IF.
Sign condition • Syntax ExampleIF DISCRIMINANT IS NEGATIVE THEN DISPLAY “The roots are imaginary”.
Class condition • Syntax Example IF REGNO IS NOT NUMERIC THEN DISPLAY “Records will not be sorted”.
Compound Condition • 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 ! “.
Defining Condition Names. • 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 identifythe values which make the Condition Name TRUE.
Condition Names • Are essentially boolean variables. • Are always associated with data names called condition variables. • Is defined in the DATA DIVISION with levelnumber 88. • Syntax88 condition-name {VALUE IS, VALUES ARE } literal-1 [ { THRU, THROUGH } literal-2 ].
Condition-Names .. example 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. Condition Names PROCEDURE DIVISION Statements.DISPLAY ‘ENTER MARTIAL STATUS.:’. ACCEPT MARITAL-STATUS. IF SINGLE SUBTRACT 125 FROM DEDUCTIONS. IF ONCE-MARRIED ADD 300 TO SPECIAL-PAY. IF MARRIED PERFORM B000-MARRIAGE-GIFT. Martial-status = 0 Martial-status = 2 Martial-status = 1
Thank You Overview