Logic flowchart:

A logic flowchart is a way to think out and plan a program prior to doing the code. This is the logic flowchart for the program called SAMPLE1. The entire program appears at the bottom of the screen. To go to the entire program, click here:
SAMPLE1 program
As you are looking at the flowchart, click on any of the elements of the flowchart and branch to an explanation.


MAIN-PROGRAM.

This is the entry point to the MAIN-PROGRAM routine at the beginning of the procedure division. It relates directly to the paragraph name MAIN-PROGRAM. The program code for the flowchart module is:

MAIN-PROGRAM.
    PERFORM A-100-INITIALIZATION.
    PERFORM B-100-PROCESS-FILE.
    PERFORM C-100-WRAP-UP.
    STOP RUN.

Go to top

PERFORM A-100-INITIALIZATION.

This will translate into the statement PERFORM A-100-INITIALIZATION which means that the program will go out and execute that paragraph. When the paragraph has been executed, control will return and drop through to the next command. The program code for the flowchart module is:

MAIN-PROGRAM.
    PERFORM A-100-INITIALIZATION.
    PERFORM B-100-PROCESS-FILE.
    PERFORM C-100-WRAP-UP.
    STOP RUN.

Go to top

PERFORM B-100-PROCESS-FILE

This will translate into the statement PERFORM B-100-PROCESS-FILE which means that the program will go out and execute that paragraph. When the paragraph has been executed, control will return and drop through to the next command. The program code for the flowchart module is:

MAIN-PROGRAM.
    PERFORM A-100-INITIALIZATION.
    PERFORM B-100-PROCESS-FILE.
    PERFORM C-100-WRAP-UP.
    STOP RUN.

Go to top

PERFORM C-100-WRAPUP

This will translate into the statement PERFORM C-100-WRAPUP which means that the program will go out and execute that paragraph. When the paragraph has been executed, control will return and drop through to the next command. The program code for the flowchart module is:

MAIN-PROGRAM.
    PERFORM A-100-INITIALIZATION.
    PERFORM B-100-PROCESS-FILE.
    PERFORM C-100-WRAP-UP.
    STOP RUN.

Go to top

STOP RUN.

This means that the flowchart is complete. It translates into the STOP RUN instruction in the program which ends the program. The program code for the flowchart module is:

MAIN-PROGRAM.
    PERFORM A-100-INITIALIZATION.
    PERFORM B-100-PROCESS-FILE.
    PERFORM C-100-WRAP-UP.
    STOP RUN.

Go to top

A-100-INITIALIZATION.

This is the entry point for the flowchart module that initializes the program. It relates to the paragraph name A-100-INITIALIZATION. The program code for the flowchart module is:

A-100-INITIALIZATION.
    OPEN INPUT CUSTOMER-FILE
        OUTPUT CUSTOMER-REPORT.

Go to top

OPEN...

This is the flowchart module that indicates the files should be opened. It relates the program OPEN statement. The program code for the flowchart module is:

A-100-INITIALIZATION.
    OPEN INPUT CUSTOMER-FILE
        OUTPUT CUSTOMER-REPORT.


Go to top

end of initialization

This is the flowcharting code indicating that the initialization paragraph is over. It does not show in the code. A new paragraph name in the code indicates that the previous paragraph is complete.

Go to top

B-100-PROCESS-FILE.

This is the entry point to the process portion of the flowchart. In the program it is B-100-PROCESS-FILE. The program code for the flowchart module is:

B-100-PROCESS-FILE.
    READ CUSTOMER-FILE
        AT END
            MOVE "YES" TO END-OF-FILE.
    PERFORM B-200-PROCESS-RECORD
        UNTIL END-OF-FILE = "YES".

Go to top

READ...

This is the logic for the READ statement. After the READ is issued, it is checked to see if it successfully read a record of if end of file has been reached. If end of file has been reached the indicator is changed from the initial value of NO to YES. Note that this is an "initializing read", that is, it reads the first record of the file. The read at the end of B-200-PROCESS-RECORD is used for the rest of the program. In fact, the test for end of file here would read a record unless there are no records written on the file in which case end of file would be reached. The program code for the flowchart module is:

B-100-PROCESS-FILE.
    READ CUSTOMER-FILE
        AT END
            MOVE "YES" TO END-OF-FILE.

    PERFORM B-200-PROCESS-RECORD
        UNTIL END-OF-FILE = "YES".


Go to top

PERFORM...

This is the logic that causes the program to loop until all records are processed. It is the PERFORM a paragraph UNTIL a condition is met logic. According to this logic, the test is made before the paragraph is performed which is why you see the question first. If the answer to the question is Yes, then the B-200-PROCESS-RECORD routine is performed once. The logic then returns to the question. Each time the process routine is performed, the logic will return to the question to determine if the routine should be processed again. The question tests the indicator to find out if end of file has been reached. This works because the last thing in the routine that is being processed is the READ instruction. If the READ detects end of file, then the indicator will be changed from NO to YES and when the UNTIL question is asked, the answer will be NO. This means that the B-200-PROCESS-RECORD will not be done again. The program code for this flowchart module is:

B-100-PROCESS-FILE.
    READ CUSTOMER-FILE
        AT END
            MOVE "YES" TO END-OF-FILE.
    PERFORM B-200-PROCESS-RECORD
        UNTIL END-OF-FILE = "YES".



end of main process control...

This is the flowcharting code indicating that the main processing paragraph is over. It does not show in the code. A new paragraph name in the code indicates that the previous paragraph is complete.

Go to top

B-200-PROCESS-RECORD.

This is the entry point to the routine that will process a record. This routine is processed over and over again by the PERFORM...UNTIL until all of the records in the file have been processed and end of file has been reached. The program code for this flowchart module is:

B-200-PROCESS-RECORD.
    MOVE SPACES TO PRINTZ.
    MOVE CUSTOMER-ID TO CUSTOMER-ID-PR.
    MOVE CUSTOMER-NAME TO CUSTOMER-NAME-PR.
    MOVE CUSTOMER-STREET TO CUSTOMER-STREET-PR.
    MOVE CUSTOMER-CITY TO CUSTOMER-CITY-PR.
    MOVE CUSTOMER-STATE TO CUSTOMER-STATE-PR.
    MOVE CUSTOMER-ZIP TO CUSTOMER-ZIP-PR.
    WRITE PRINTZ
        AFTER ADVANCING 1 LINE.
    READ CUSTOMER-FILE
        AT END
            MOVE "YES" TO END-OF-FILE.


Go to top

MOVE...

This is the logic that sets up the print line so that it can be written on the report. First, the area in memory where the line will be setup needs to be cleared (this is done by moving spaces to the area). Second, the fields that contain data to be printed must be moved to areas on the print line so that the data will appear on the line. The program code for this flowchart module is:

B-200-PROCESS-RECORD.
    MOVE SPACES TO PRINTZ.
    MOVE CUSTOMER-ID TO CUSTOMER-ID-PR.
    MOVE CUSTOMER-NAME TO CUSTOMER-NAME-PR.
    MOVE CUSTOMER-STREET TO CUSTOMER-STREET-PR.
    MOVE CUSTOMER-CITY TO CUSTOMER-CITY-PR.
    MOVE CUSTOMER-STATE TO CUSTOMER-STATE-PR.
    MOVE CUSTOMER-ZIP TO CUSTOMER-ZIP-PR.

    WRITE PRINTZ
        AFTER ADVANCING 1 LINE.
    READ CUSTOMER-FILE
        AT END
            MOVE "YES" TO END-OF-FILE.


Go to top

WRITE PRINTZ...

This is the logic that will write the line. Note that when you look at the code you are writing the name that was defined in the 01 level of the FD. In the actual code that goes with the flowchart, the after advancing 1 line clause moves down one line on the printer. The program code for this flowchart module is:

B-200-PROCESS-RECORD.
    MOVE SPACES TO PRINTZ.
    MOVE CUSTOMER-ID TO CUSTOMER-ID-PR.
    MOVE CUSTOMER-NAME TO CUSTOMER-NAME-PR.
    MOVE CUSTOMER-STREET TO CUSTOMER-STREET-PR.
    MOVE CUSTOMER-CITY TO CUSTOMER-CITY-PR.
    MOVE CUSTOMER-STATE TO CUSTOMER-STATE-PR.
    MOVE CUSTOMER-ZIP TO CUSTOMER-ZIP-PR.
    WRITE PRINTZ
        AFTER ADVANCING 1 LINE.

    READ CUSTOMER-FILE
        AT END
            MOVE "YES" TO END-OF-FILE.


Go to top

READ...(reads all records after the initial record in the file

This is the logic that will read all records after the initial record in the file. The initializing read is in the B-100-PROCESS-FILE where it reads the first record only. In a sense this primes the pump. It then performs the B-200-PROCESS-RECORD routine which processes the record that was just read. At the bottom of this routine, the READ being discussed here occurs. This READ reads the next record on the file. If there are no more records, end of file has occured and the indicator gets changed from NO to YES. When logic returns to the PERFORM...UNTIL in the B-100-PROCESS-FILE, this change will stop the PERFORM from doing the B-200-PROCESS-RECORD routine again and the logic will drop out of the B-100-PROCESS-FILE routine and return to the MAIN-PROGRAM routine where the logic will drop through to PERFORM the wrapup routine (C-100-WRAPUP).

Again, the logic of the read is to attempt to read a record from the file. If the read is successful, the record is moved into the file section where it is described under the 01 level of the FD. If the read is not successful, it means that end of file has been reached so the AT END clause is activated and the indicator called END-OF-FILE is changed from NO to YES. The program code for this flowchart module is:

B-200-PROCESS-RECORD.
    MOVE SPACES TO PRINTZ.
    MOVE CUSTOMER-ID TO CUSTOMER-ID-PR.
    MOVE CUSTOMER-NAME TO CUSTOMER-NAME-PR.
    MOVE CUSTOMER-STREET TO CUSTOMER-STREET-PR.
    MOVE CUSTOMER-CITY TO CUSTOMER-CITY-PR.
    MOVE CUSTOMER-STATE TO CUSTOMER-STATE-PR.
    MOVE CUSTOMER-ZIP TO CUSTOMER-ZIP-PR.
    WRITE PRINTZ
        AFTER ADVANCING 1 LINE.
    READ CUSTOMER-FILE
        AT END
            MOVE "YES" TO END-OF-FILE.


Go to top

end of record process...

This is the flowcharting code indicating that the record processing paragraph is over. It does not show in the code. A new paragraph name in the code indicates that the previous paragraph is complete.

Go to top

C-100-WRAPUP.

This is the entry point to the routine that will close down the files in anticipation of ending the program. The program code for this flowchart module is:

C-100-WRAP-UP.
    CLOSE CUSTOMER-FILE
        CUSTOMER-REPORT.


Go to top

CLOSE...

This is the place where the files are closed. The program code for this flowchart module is:

C-100-WRAP-UP.
    CLOSE CUSTOMER-FILE
        CUSTOMER-REPORT.


Go to top

end of record process...

This is the flowcharting code indicating that the record processing paragraph is over. It does not show in the code. A new paragraph name in the code indicates that the previous paragraph is complete. When control returns to the MAINLINE (MAIN-PROGRAM in the code), the logic will drop through to the STOP RUN. statement and the program will be complete.

Go to top


SAMPLE1 Program

       IDENTIFICATION DIVISION.
       PROGRAM-ID.   SAMPLE1.
       AUTHOR.  GROCER.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT CUSTOMER-FILE
               ASSIGN TO "C:\PCOBWIN\CIS12FST\C12FIRST.DAT".
           SELECT CUSTOMER-REPORT
               ASSIGN TO PRINTER.
       DATA DIVISION.
       FILE SECTION.
       FD  CUSTOMER-FILE
           DATA RECORD IS CUSTOMER-RECORD.
       01  CUSTOMER-RECORD.
           05  CUSTOMER-ID                  PIC X(4).
           05  CUSTOMER-NAME                PIC X(20).
           05  CUSTOMER-STREET              PIC X(20).
           05  CUSTOMER-CITY                PIC X(15).
           05  CUSTOMER-STATE               PIC X(2).
           05  CUSTOMER-ZIP                 PIC X(5).
           05  FILLER                       PIC X(10).
       FD  CUSTOMER-REPORT
           DATA RECORD IS PRINTZ.
       01  PRINTZ.
           05  FILLER                       PIC X.
           05  CUSTOMER-ID-PR               PIC X(4).
           05  FILLER                       PIC X(2).
           05  CUSTOMER-NAME-PR             PIC X(20).
           05  FILLER                       PIC X(2).
           05  CUSTOMER-STREET-PR           PIC X(20).
           05  FILLER                       PIC X(2).
           05  CUSTOMER-CITY-PR             PIC X(15).
           05  FILLER                       PIC X(2).
           05  CUSTOMER-STATE-PR            PIC X(2).
           05  FILLER                       PIC X(2).
           05  CUSTOMER-ZIP-PR              PIC X(5).
           05  FILLER                       PIC X(3).
       WORKING-STORAGE SECTION.
       01  INDICATORS.
           05  END-OF-FILE                  PIC XXX      VALUE "NO ".
       PROCEDURE DIVISION.
       MAIN-PROGRAM.
           PERFORM A-100-INITIALIZATION.
           PERFORM B-100-PROCESS-FILE.
           PERFORM C-100-WRAP-UP.
           STOP RUN.
       A-100-INITIALIZATION.
           OPEN INPUT CUSTOMER-FILE
                OUTPUT CUSTOMER-REPORT.
       B-100-PROCESS-FILE.
           READ CUSTOMER-FILE
               AT END
                  MOVE "YES" TO END-OF-FILE.
           PERFORM B-200-PROCESS-RECORD
               UNTIL END-OF-FILE = "YES".
       B-200-PROCESS-RECORD.
           MOVE SPACES TO PRINTZ.
           MOVE CUSTOMER-ID TO CUSTOMER-ID-PR.
           MOVE CUSTOMER-NAME TO CUSTOMER-NAME-PR.
           MOVE CUSTOMER-STREET TO CUSTOMER-STREET-PR.
           MOVE CUSTOMER-CITY TO CUSTOMER-CITY-PR.
           MOVE CUSTOMER-STATE TO CUSTOMER-STATE-PR.
           MOVE CUSTOMER-ZIP TO CUSTOMER-ZIP-PR.
           WRITE PRINTZ
               AFTER ADVANCING 1 LINE.
           READ CUSTOMER-FILE
               AT END
                  MOVE "YES" TO END-OF-FILE.
       C-100-WRAP-UP.
           CLOSE CUSTOMER-FILE
                 CUSTOMER-REPORT.
Go to the beginning