Custom Search

cobol paragraph names with SQL cobol rules for programmer choose your paragraph names carefully

Paragraph Names

Because paragraph names are used only as bookmarks, it is possible to insert more paragraph names into this program. Remember that you can assign your own paragraph names. The rules for naming paragraphs are similar to the rules for naming variables:

· A paragraph name can contain 30 characters. In fact, a paragraph name can be longer than 30 characters, but the compiler will warn you that it will use only the first 30 characters of the name. The remaining characters can be included in the name but the compiler will ignore them.

· The characters can be A through Z, 0 through 9, and the hyphen (-). Some compilers also allow the lowercase characters a through z.

· The paragraph name must not start with the hyphen.

· Paragraph names must start in Area A, columns 8 through 11, and must end with a period.

DO/DON'T:

DO use uppercase paragraph names if you want your code to be portable.

DON'T use lowercase paragraph names. Even the simplest COBOL programs have a tendency to survive and grow. One day, you might find yourself porting the program to a new computer, and you will curse yourself for having used lowercase. Listing 3.3 is sprinkled with some extra paragraph names. If you compare Listing 3.2 and Listing 3.3, you will see that the sentences are identical. Because a paragraph name does not cause any command to be executed, these two programs behave identically. Enter them both into the computer and compile them. Run them one after the other and you will see no difference.


Adding extra paragraph names.

000100 IDENTIFICATION DIVISION.

000200 PROGRAM-ID. ADD04.

000300 ENVIRONMENT DIVISION.

000400 DATA DIVISION.

000500

000600 WORKING-STORAGE SECTION.

000700

000800 01 FIRST-NUMBER PIC 99.

000900 01 SECOND-NUMBER PIC 99.

001000 01 THE-RESULT PIC 999.

001100

001200 PROCEDURE DIVISION.

001300

001400 PROGRAM-BEGIN.

001500

001600 DISPLAY "This program will add 2 numbers.".

001700

001800 GET-FIRST-NUMBER.

001900

002000 DISPLAY "Enter the first number.".

002100

002200 ACCEPT FIRST-NUMBER.

002300

002400 GET-SECOND-NUMBER.

002500

002600 DISPLAY "Enter the second number.".

002700

002800 ACCEPT SECOND-NUMBER.

002900

003000 COMPUTE-AND-DISPLAY.

003100 COMPUTE THE-RESULT = FIRST-NUMBER + SECOND-NUMBER.

003200

003300 DISPLAY "The result is " THE-RESULT.

003400

003500

003600 PROGRAM-DONE.

003700 STOP RUN.

003800

ANALYSIS: Listing 3.4 includes an empty paragraph at line 001400. At lines 001500, 001800, 002400, and 003000, the paragraph names have been changed to STEP-01, STEP-02, and so on. If you inspect the code, you will notice that, because of the placement of the paragraph names, the paragraph PROGRAM-BEGIN contains no statements. Some compilers allow this, and others complain of an empty paragraph with either a warning or an error. Personal COBOL and ACUCOBOL both allow it. If you want to test your compiler, you can type this and compile it.

An empty paragraph.

000100 IDENTIFICATION DIVISION.

000200 PROGRAM-ID. ADD05.

000300 ENVIRONMENT DIVISION.

000400 DATA DIVISION.

000500

000600 WORKING-STORAGE SECTION.

000700

000800 01 FIRST-NUMBER PIC 99.

000900 01 SECOND-NUMBER PIC 99.

001000 01 THE-RESULT PIC 999.

001100

001200 PROCEDURE DIVISION.

001300

001400 PROGRAM-BEGIN.

001500 STEP-01.

001600 DISPLAY "This program will add 2 numbers.".

001700

001800 STEP-02.

001900

002000 DISPLAY "Enter the first number.".

002100

002200 ACCEPT FIRST-NUMBER.

002300

002400 STEP-03.

002500

002600 DISPLAY "Enter the second number.".

002700

002800 ACCEPT SECOND-NUMBER.

002900

003000 STEP-04.

003100 COMPUTE THE-RESULT = FIRST-NUMBER + SECOND-NUMBER.

003200

003300 DISPLAY "The result is " THE-RESULT.

003400

003500

003600 PROGRAM-DONE.

003700 STOP RUN.

003800