Presentation is loading. Please wait.

Presentation is loading. Please wait.

Analysis of SAMPLE1.CBL Please check speaker notes for additional information!

Similar presentations


Presentation on theme: "Analysis of SAMPLE1.CBL Please check speaker notes for additional information!"— Presentation transcript:

1 Analysis of SAMPLE1.CBL Please check speaker notes for additional information!

2 IDENTIFICATION DIVISION. PROGRAM-ID. SAMPLE1. AUTHOR. GROCER. These commands are written starting in column 8 which is also referred to as margin A. The name of the program is provided by the programmer. It should be 8 characters or less, made up of letters and numbers. The first character should be a letter. This is a required entry. The name of the programmer is optional to COBOL but required for this course. IDENTIFICATION DIVISION, PROGRAM-ID, and AUTHOR are reserved words. They must be coded in exactly this way. Note also the use of periods. The periods are required.

3 ENVIRONMENT DIVISION. Column 8 Margin A Column 12 Margin B Column 16 Still Margin B ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CUSTOMER-FILE ASSIGN TO "C:\PCOBWIN\CIS12FST\C12FIRST.DAT". SELECT CUSTOMER-REPORT ASSIGN TO PRINTER. Note the different assignments. Above I am saying the customer file will be found on the A drive as CUSTP00.DAT. To the right, I am saying it will be found on the C drive under PCOBWIN, CIS12FSR and will be named C12FIRST.DAT. When dealing with the select the programmer must know the name and location. The RESERVED words must be coded as required by COBOL. The ASSIGN TO clause points to the physical location of the file. The CUSTOMER-FILE is being read from a disk and the CUSTOMER-REPORT is being written to the PRINTER. CUSTOMER-FILE and CUSTOMER-REPORT are the names of the logical file that the programmer made up. Names must consist of letters, numbers and hyphens only.

4 Program

5 DATA DIVISION. Column 8 Margin A Column 12 Margin B The DATA DIVISION is made up of two sections, the FILE SECTION and the WORKING-STORAGE SECTION.

6 DATA DIVISION. FILE SECTION. DATA DIVISION. FILE SECTION. 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). Reserved words must be used as specified in COBOL. FD stands for file description. The name after the FD was the name used in the SELECT statement in the ENVIRONMENT DIVISION - CUSTOMER-FILE. CUSTOMER-FILE is the name of the whole file - all of the records in the file. Each record when it is referred to individually is called CUSTOMER- RECORD. The record name CUSTOMER-RECORD is then repeated at the 01 level of the FD. Each record on the record is described on the 05 level in this program. Each field is given a unique name and the type and length are specified. X means that the data is alphanumeric (letters, number, special characters). The number inside the parenthesis is describing the length of the field.

7 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). 1234Jane Doe 123 Elm St Fall River MA02771 2345Ann Smith 45 Oak St Braintree MA02184 3456Susan Ash 234 Maple St Weymouth MA02180 Record Layout - Input File

8 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). DATA DIVISION. FILE SECTION. (continued) DATA DIVISION. FILE SECTION. (continued) CUSTOMER-REPORT is the output report that has been assigned to the printer. Each line on that report is called PRINTZ. Each field is given a unique name. I like to use the name I used on the input record and add the -PR to make it unique. Then I know what data is going to the field. FILLER is used to put spaces between the fields. 80 characters

9 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). Record Layout - Output File 1234 Jane Doe 123 Elm St Fall River MA 02771 2345 Ann Smith 45 Oak St Braintree MA 02184 3456 Susan Ash 234 Maple St Weymouth MA 02180

10 WORKING-STORAGE SECTION. 01 INDICATORS. 05 END-OF-FILE PIC XXX VALUE "NO ". DATA DIVISION. WORKING-STORAGE SECTION. DATA DIVISION. WORKING-STORAGE SECTION. There is one entry here - the END-OF-FILE field set up in memory. In COBOL we try to group the things in the WORKING-STORAGE SECTION, so I have the name INDICATORS here. If there were other indicators, they would all be grouped as separate 05 fields under the 01. This sets up a three character field called END-OF-FILE in memory and gives it an initial value of NO followed by a space (since there is room for 3 characters).

11 PROCEDURE DIVISION. The PROCEDURE DIVISION is made up of paragraphs. Column 8 Margin A Paragraphs Column 12 Margin B Instructions Each paragraph contains instructions to the computer. Paragraph names start in column 8 (margin A)while instruction start in column 12 (margin B).

12 MAINLINE PERFORM INITIALIZE PERFORM PROCESS FILE PERFORM WRAPUP STOP RUN INITIALIZE END INITIALIZE OPEN FILES PROCESS RECORD READ INITIAL RECORD EOF Move YES to EOF indicator Y N EOF indicator NOT = YES PERFORM PROCESS RECORD Y N END PROCESS FILE PROCESS FILE SET UP LINE - clear - move data WRITE LINE READ RECORD EOF Move YES to EOF indicator Y N ENDPROCESS RECORD WRAPUP END WRAPUP CLOSE FILES

13 MAINLINE PERFORM INITIALIZE PERFORM PROCESS FILE PERFORM WRAPUP STOP RUN INITIALIZE END INITIALIZE OPEN FILES PROCESS RECORD READ INITIAL RECORD EOF Move YES to EOF indicator Y N EOF indicator NOT = YES PERFORM PROCESS RECORD Y N END PROCESS FILE PROCESS FILE SET UP LINE - clear - move data WRITE LINE READ RECORD EOF Move YES to EOF indicator Y N ENDPROCESS RECORD WRAPUP END WRAPUP CLOSE FILES

14 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. PROCEDURE DIVISION.

15 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. MAIN-PROGRAM A-100- INITIALIZATION B-100- PROCESS- FILE C-100- WRAP-UP B-200- PROCESS- RECORD MAIN-PROGRAM controls the flow of the program. All the things that it controls are at the 100 level. Things involved with initialization have an A at the beginning of the paragraph name, things involved with processing have a B at the beginning of the paragraph name, things involved with termination or wrap-up, have a C at the beginning of the paragraph name. The B-100 controls the processing. The loop that actually processes each record is called the B-200 and it is controlled by the B-100.

16 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. 1 2 3 6 7 8 9 10 11 12 13 14 15 5 4 1234Jane Doe 123 Elm St Fall River MA02771 7 891011 12 1234 Jane Doe 123 Elm St Fall River MA 02771 13 1234Jane Doe 123 Elm St Fall River MA02771 2345Ann Smith 45 Oak St Braintree MA02184 1234 Jane Doe 123 Elm St Fall River MA 02771

17 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. 25 16 17 18 19 20 21 22 23 24 15 17 18192021 22 1234 Jane Doe 123 Elm St Fall River MA 02771 23 2345Ann Smith 45 Oak St Braintree MA02184 3456Susan Ash 234 Maple St Weymouth MA02180

18 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. 37 25 35 26 27 28 29 30 31 32 33 34 36 27 28293031 32 1234 Jane Doe 123 Elm St Fall River MA 02771 33 2345 Ann Smith 45 Oak St Braintree MA 02184 3456Susan Ash 234 Maple St Weymouth MA02180 END-OF-FILE YES 3456 Susan Ash 234 Maple St Weymouth MA 02180 39 38


Download ppt "Analysis of SAMPLE1.CBL Please check speaker notes for additional information!"

Similar presentations


Ads by Google