Procedural Code

All procedural code also follows naming standards. The following program segment shows many of the standards applications use to format 4GL code.

016800************************************************************
016900 600-CALC-WEEKLY-PAY.
017000************************************************************
017100
017200     IF (EMP-ANNUAL-HOURS = ZEROES)
017300         MOVE ZEROES              TO XX01WS-CALC-HOURLY-PAY
017400         GO TO 600-CONTINUE.
017500
017600     COMPUTE XX01WS-CALC-HOURLY-PAY =
017700                      EMP-ANNUAL-SALARY / EMP-ANNUAL-HOURS.
017800
017900 600-CONTINUE.
018000     IF (XX01WS-CALC-HOURLY-PAY > 1.00)
018100         MOVE ZEROES              TO XX01WS-CALC-HOURLY-PAY.
018200
018300 600-END.
018400

The following rules apply to procedural code.

  • The format of a paragraph label is Prefix-ParagraphName. The Prefix for a paragraph is a three- or four-digit number.

  • The format of a section label is Prefix-SectionName. The Prefix is made up of the program code, an S for online programs or an R for batch programs, the form or report number, and a hyphen (-). For example, the section prefix for the first form of GL20 would be GL20S1-.

    All sections must have a START label following the section name so each sentence inside the section belongs to a paragraph. The following example illustrates this.

    000400********************************************************
    000500 GL20S1-TRANSACTION              SECTION 10.
    000600********************************************************
    010300 GL20S1-START.
  • All paragraph labels in a section must have the same Prefix.

  • The label that ends a paragraph or section is Prefix - END.

  • The precompiler allows GO TO statements only if they are confined to the section where they are used. In the example above, all labels are part of the 600 routine and the GO TO statement jumps to a 600 label.

  • Sentences start in position 12. Nested statements are each indented four spaces.

  • Groups of statements should be locally aligned. For example, the second half of statements that move form data should be aligned on or near position 48, and statements that move error data on or near position 53.

  • The COBOL INITIALIZE statement should be used to initialize variables to zeroes or spaces.

  • HIGH-VALUES should not be used for numeric fields; WS-HIGH-VALUES should be used instead. HIGH-VALUES may be used for alpha fields.

  • WS-TRUE and WS-FALSE should be used for Boolean operations. Because the values of TRUE and FALSE can change from machine to machine, this construct provides consistency across machine lines.

  • A THRU clause should be used when you perform a paragraph series. The following code performs the 600-CALC-WEEKLY-PAY paragraph shown earlier.

    010000     PERFORM 600-CALC-WEEKLY-PAY
    010100     THRU    600-END.

    A THRU clause is not needed when performing a section.