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

MODULE 7: COBOL Control statements


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
  • Syntax:-

    PERFORM para-name

    Where, para-name is paragraph you want to execute
  • Example:-
    In PROCUEDURE DIVISION,

    PARA-0. DISPLAY ‘IN PARA-0’. PERFORM PARA-1. DISPLAY ‘RETURNED FROM PARA-1’. STOP RUN. PARA-1. DISPLAY ‘IN PARA-1’.

  • SYSOUT display (output):-

    IN PARA-0 IN PARA-1 RETURNED FROM PARA-1

  • In above example, program first starts by executing first instruction of PARA-0, then since PERFORM is coded it will call PARA-1, once all instruction from PARA-1 is executed, control will be returned back to the next instruction following PERFORM and thus, in SYSOUT we can see ‘RETURNED FROM PARA-1’ is displayed. Above example is also demonstrated in flow chart form below.
  • Using PERFORM statement versus GO TO statement
  • PERFORM:
    In case if we had used GO TO in place of PERFORM then flow would be like:-
    GO TO:-

    Since GO TO is used, control is not returned back and thus statements coded in PARA-0 after GO TO will remain unexecuted






© copyright mainframebug.com
Privacy Policy