Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

MODULE 7: COBOL Control statements


Iteration statement

  • COBOL’s iteration statement is PERFORM. This statement create what we commonly call “loops”.
  • A loop repeatedly executes the same set of statements until a termination condition is met

PERFORM Statement

  • Reusable set of instructions can be coded in paragraphs that we already know. These paragraphs can be used/called using PERFORM statement multiple times and at multiple places of the program as per our need
  • On completion of paragraph execution, control is returned back to the next statement following PERFORM
  • PERFORM is used to repeat the same set of instructions or block while it’s controlling expression(when coded) is true
  • PERFORM is a powerful and versatile construct of COBOL programming
  • Below listed are different formats in which PERFORM can be coded to achieve our programming goal
    • Simple PERFORM
      • This is simplest form of PERFORM statement. It is used to execute specified paragraph, and on completion of paragraph execution, control is returned back to the next statement following PERFORM
      • This format is explaned in detail here < LINK >
    • Inline PERFORM
      • As name suggests, Inline PERFORM is used to execute those set of instructions which are coded in line between PERFORM and END-PERFORM.
      • This format of PERFORM doesn’t require any separate PARAGRAPH or SECTION to be coded to enclose the set of instructions.
      • This format is explaned in detail here < LINK >
    • PERFORM THRU
      • This format allows us to execute set of paragraphs at one go
      • This format is explaned in detail here < LINK >
    • PERFORM TIMES
      • This format is used when you want to execute set of instruction specific number of times
      • This format is explaned in detail here < LINK >
    • PERFORM UNTIL
      • This format is used when you want to execute set of instructions multiple times until some condition is met
      • The data items used in condition(s) must be modified within the paragraph(s) being executed; otherwise the paragraphs will be executed indefinitely
      • This format is explaned in detail here < LINK >
    • PERFORM VARYING
      • This format is similar to "FOR loop" of other programming language
      • This format is explaned in detail here < LINK >
    • PERFORM WITH TEST BEFORE/AFTER
      • When WITH TEST BEFORE is coded, Condition is checked first, if it evaluates to false the paragraphs are executed and then repeats process until condition is met (evaluates to true). This is default option. It is similar to WHILE…DO of the other language
      • When WITH TEST AFTER is coded, It first executes paragraphs, then evaluates the conditional expression. If this condition evaluates to false, the paragraphs will be executed again. Otherwise, it terminates and control is returned to next statement after PERFORM. It is similar to REPEAT… UNTIL of other programming construct.
      • This format is explaned in detail here < LINK >
    • PERFORM for Multi-dimensional arrays
      • Also referred to as “PERFORM with VARYING AFTER”.
      • This kind of PERFORM browse through each elements of multi-dimensional array.
      • This format is explaned in detail here < LINK >
  • Each of them are explained in detail in upcoming section






© copyright mainframebug.com
Privacy Policy