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

Module 6: Procedure Division


Structure of PROCEDURE DIVISION

  • All the data described in the Data Division are processed here
  • The programmer implements the algorithm in this division
  • This is the last division and business logic is coded here. It has user-defined sections and paragraphs.
  • The PROCEDURE DIVISION contains statements which specify the operations to be performed by computer.
  • Each of these statements is made with COBOL words & literals. A statement always begins with a COBOL verb.
  • As explained in COBOL- Program structure , several statements can be combined to form one sentence. Sentences can be grouped together to form a paragraph and in turn paragraphs can be grouped to form section.
  • There must be at least one statement in procedure division.
  • Simplified structure of Procedure Division:-
    PROCEDURE DIVISION. [section-name SECTION. [paragraph-name. [sentence ]… ]… ]…

    Simplified structure (when it does not contain sections)

    PROCEDURE DIVISION. [paragraph-name. [sentence]… ]…

  • Rules for sentence/paragraph/section.
    • Naming rule for section-name and paragraph-name
      • User-defined words
      • Can be maximum 30 chars long
      • Only Letters, Digit and ‘-‘ allowed
      • No embedded blanks
      • At least one alphabetic character
      • No COBOL reserved words (like FILLER/RENAMES)
    • paragraph-name or section-name must start in margin A.
    • Line containing section-name must not contain anything else
    • However, any statement may appear in same line that contains the paragraph-name with restriction that there must be a space between the terminating period of paragraph and statement
    • Statement and sentences within a paragraph must be written in Margin B
    • There can be more than one statement or sentence in a line
    • When coding section, section-name must be followed by the word SECTION with at least one space in between
    • section-name must be unique within the program and must be different from paragraph-names
    • paragraph-name must have unique names within section, but it need not be unique in the entire program(if all paragraphs are coded under sections). When section are not coded, paragraph-name must be unique in entire program.
    • When section is coded, reference to a non-unique paragraph-name can be done as shown below:-
      paragraph-name { OF | IN } section-name
    • The paragraph body is terminated by appearance of another paragraph header or section header. The last statement to mark end of the execution in this division is either “STOP RUN” which is used in calling program or “EXIT program” which is used in called programs

Sample example demonstrating use of Procedure division:-
COBOL Program:-

000100 IDENTIFICATION DIVISION. 000200 PROGRAM-ID. PRCDIVI. 000300 ENVIRONMENT DIVISION. 000400 DATA DIVISION. 000500 WORKING-STORAGE SECTION. 000600 01 DATA-A PIC 9(4) VALUE 30. 000700 01 DATA-B PIC 9(4) VALUE 20. 000800 PROCEDURE DIVISION. 000900 PARA-A. 001000 DISPLAY 'PARA-A VISITED. '. 001100 ADD DATA-A TO DATA-B. 001200 DISPLAY 'VALUE IN DATA-A : ' DATA-A. 001300 DISPLAY 'VALUE IN DATA-B : ' DATA-B. 001400 PARA-B. 001500 PARA-C. 001600 DISPLAY 'PARA-C VISITED. '. 001700 STOP RUN.

Mainframe Job Step to run above program:-

//STEP01 EXEC PGM=PRCDIVI //STEPLIB DD DSN=USER.TEST.LOADLIB,DISP=SHR //SYSOUT DD SYSOUT=* //

SYSOUT After Job run:-

PARA-A VISITED. VALUE IN DATA-A : 0030 VALUE IN DATA-B : 0050 PARA-C VISITED

In above example, three paragraphs are coded in program and they are executed in sequence. PARA-B does not contain any sentence.


Advertisements






© copyright mainframebug.com
Privacy Policy