Cob Basics 5

download Cob Basics 5

of 20

Transcript of Cob Basics 5

  • 8/12/2019 Cob Basics 5

    1/20

  • 8/12/2019 Cob Basics 5

    2/20

  • 8/12/2019 Cob Basics 5

    3/20

    3

    IF Statement

    Format for IF statements

    IF condition-1[THEN]

    imperative statement-1 . . .

    [ELSE

    imperative statement-2 . . . ]

    [END-IF]

  • 8/12/2019 Cob Basics 5

    4/20

    4

    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 GREATER THAN OR EQUAL TO

  • 8/12/2019 Cob Basics 5

    5/20

    5

    IF Statement

    There are times when you might want to execute a series of steps

    only if a certain condition does not exist.

    The COBOL expression CONTINUE (COBOL 85) or NEXTSENTENCE (COBOL 74) will enable you:

    (1) to avoid performing any operation if a condition exists

    (2) to execute instructions only if the ELSE condition is met

    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

  • 8/12/2019 Cob Basics 5

    6/20

    6

    IF Statement

    A nested conditional is a conditional in which an IF statementitself can contain additional IF clauses.

    IF condition-1

    statement-1ELSE

    IF condition-2

    statement-2

    ELSE

    statement-3END-IF

    END-IF

  • 8/12/2019 Cob Basics 5

    7/20

    7

    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).

    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.

  • 8/12/2019 Cob Basics 5

    8/20

  • 8/12/2019 Cob Basics 5

    9/20

    9

    IF Statement

    We can test whether a field is POSITIVE, NEGATIVE, or ZEROwith a sign test.

    We can test for the type of data in a field by coding IF identifier- 1

    IS NUMERIC or IF identifier-1 IS ALPHABETIC

    Format

    IF identifier-1 IS [NOT ]

    {{GREATER THAN (>)}

    {LESS THAN (

  • 8/12/2019 Cob Basics 5

    10/20

    10

    IF Statement

    IF identifier-1 IS [NOT]

    {{ NUMERIC}

    {POSITIVE}

    {NEGATIVE }

    {ZERO}

    {ALPHABETIC}

    {ALPHABETIC-UPPER*}{ALPHABETIC-LOWER*}}

  • 8/12/2019 Cob Basics 5

    11/20

  • 8/12/2019 Cob Basics 5

    12/20

    12

    Evaluate Statement

    EVALUATE {identifier-1}

    {expression-1}WHEN condition-1 imperative- statement-1 . . .

    [WHEN OTHER imperative-statement-2]

    [END-EVALUATE]

  • 8/12/2019 Cob Basics 5

    13/20

    13

    Perform Statement

    In-Line PERFORMPERFORM

    Statements to

    be executed

    END-PERFORM

    An in-line PERFORM begins with the word PERFORM, is followed

    by statements to be executed, and ends with an END-PERFORM

    scope terminator.

    All instructions within the PERFORM ... END-PERFORM are

    executed in sequence.

  • 8/12/2019 Cob Basics 5

    14/20

    14

    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.

  • 8/12/2019 Cob Basics 5

    15/20

    15

    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 statementsbeginning at paragraph-name-1 until the end of paragraph-name-2

    is reached.

    Control is then transferred to the statement directly following thePERFORM.

  • 8/12/2019 Cob Basics 5

    16/20

    16

    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 originalPERFORM.

    It is used, when necessary, as an end point in a paragraph being

    performed.

  • 8/12/2019 Cob Basics 5

    17/20

    17

    Perform Statement

    The format of a PERFORM UNTIL ... is:

    Format 2

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

    paragraph-name-2]

    UNTIL condition-1

  • 8/12/2019 Cob Basics 5

    18/20

  • 8/12/2019 Cob Basics 5

    19/20

    19

    Perform Statement

    FormatPERFORM paragraph-name-1 [{THROUGH} {THRU}

    paragraph-name-2]

    VARYING identifier-1 FROM {identifier-2}{integer-1}

    BY {identifier-3} {integer-2}

    UNTIL condition-1

    1. The innermost PERFORM VARYING loop is executed first.

    2. The next outer PERFORM VARYING loop in sequence is then

    executed.

  • 8/12/2019 Cob Basics 5

    20/20

    20

    Perform Statement

    PERFORM paragraph-name-1

    [WITH TEST {BEFORE} {AFTER}]

    UNTIL condition-1

    The WITH TEST AFTER clause can also be used with the

    VARYING option of the PERFORM. The format is: PERFORM

    WITH TEST AFTER VARYING ....