Presentation is loading. Please wait.

Presentation is loading. Please wait.

Explanation of SAMPLEIF (if88in1.cbl or if88in1.html) Please use speaker notes for additional information!

Similar presentations


Presentation on theme: "Explanation of SAMPLEIF (if88in1.cbl or if88in1.html) Please use speaker notes for additional information!"— Presentation transcript:

1 Explanation of SAMPLEIF (if88in1.cbl or if88in1.html) Please use speaker notes for additional information!

2 IDENTIFICATION DIVISION. PROGRAM-ID. SAMPLEIF. AUTHOR. GROCER. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INS-FILE ASSIGN TO "C:\PCOBWIN\CIS12FST\INS.DAT". SELECT PRINT-FILE ASSIGN TO PRINTER. DATA DIVISION. FILE SECTION. FD INS-FILE DATA RECORD IS INS-REC. 01 INS-REC. 05 IDNO PIC XXXX. 05 NAMZ PIC X(20). 05 TYPZ PIC X. 88 TYPE-LIFE VALUE "L". 88 TYPE-CAR VALUE "C". 88 TYPE-HOME VALUE "H". 05 AMT-COV PIC 9(7)V99. 05 PREM-YR PIC 9(4)V99. FD PRINT-FILE DATA RECORD IS PRINTZ. 01 PRINTZ PIC X(80). Code TYPZ is a code with three possible valid characters: L, C and H. Processing will vary depending on what character is in this field. The level 88 allows me to assign a name to each of the valid characters. If TYPZ contains an L, then this condition is named TYPE-LIFE. If TYPZ contains a C, than this condition is named TYPE-CAR and if TYPZ contains an H, than this condition is named TYPE-HOME. The detail line contain the data that I want to write to the report is not set up in the FILE SECTION (it is set up in WORKING-STORAGE. Therefore, PRINTZ is simply given a picture of X(80).

3 WORKING-STORAGE SECTION. 01 INDICATORS. 05 MORE-RECS PIC XXX VALUE "YES". 88 END-OF-FILE VALUE "NO ". 01 WORK-AREAS. 05 PREM-MO-WS PIC 999V99 VALUE 0. 01 ACCUMULATORS. 05 TOT-MO-PREM-WS PIC 9(5)V99 VALUE 0. 01 PAGE-CONTROL. 05 PAGE-NO-WS PIC 99 VALUE 1. 05 LINE-CT-WS PIC 99 VALUE 0. 05 DATE-WS. 10 YR-WS PIC 99. 10 MO-WS PIC 99. 10 DA-WS PIC 99. Code MORE-RECS has a level 88 beneath it that defines the condition where MORE-RECS = “NO “. The name of that condition is END-OF-FILE. Note that you can still give a value to MORE-RECS when you are using level 88 condition names. PREM-MO-WS is a work area that will hold the result of the calculation to determine the premium. TOT-MO-PREM-WS is an accumulator that is added as the record are processed and printed on the total line when end of file is reached. PAGE-NO-WS is initialized at 1. It is moved to the header to print and is used to determine when to print the header on the first page. LINE-CT-WS is used to keep track of the number of lines on a page. In this program, when it passes 55 a new line is printed. DATE-WS is the date that is accepted from the system. It is then broken down into its parts - the first two characters are the year, the next two characters are the month and the final two characters are the day.

4 01 DETAIL-LINE. 05 FILLER PIC X. 05 IDNO-PR PIC XXXX. 05 FILLER PIC XXXX. 05 NAMZ-PR PIC X(20). 05 FILLER PIC XXXX. 05 TYPZ-MSG-PR PIC X(13). 05 FILLER PIC XXXX. 05 AMT-COV-PR PIC $$,$$$,$$$.99. 05 FILLER PIC XXXX. 05 PREM-MO-PR PIC $$$$.99. 05 FILLER PIC X(6). Code IDNO, NAMZ and AMT-COV are fields on the input. The data in these fields is moved to IDNO-PR, NAMZ-PR AND AMT- COV-PR. TYPZ-MSG-PR is determined by checking to see what character is contained in the input TYPZ field and moving an appropriate level to the line. The checking uses the level 88 condition names. PREM-MO-PR is the result of a calculation. The answer is stored in PREM-MO-WS and when the calculation is complete it is moved to PREM-MO-PR.

5 01 PAGE-HDR. 05 FILLER PIC X VALUE SPACES. 05 DATE-HDR. 10 MO-HDR PIC 99. 10 FILLER PIC X VALUE "/". 10 DA-HDR PIC 99. 10 FILLER PIC X VALUE "/". 10 YR-HDR PIC 99. 05 FILLER PIC X(23) VALUE SPACES. 05 FILLER PIC X(16) VALUE "INSURANCE REPORT". 05 FILLER PIC X(21) VALUE SPACES. 05 FILLER PIC X(5) VALUE "PAGE". 05 PAGE-NO-HDR PIC Z9. 05 FILLER PIC X(6) VALUE SPACES. 01 COL-HDR. 05 FILLER PIC X(13) VALUE " ID # NAME". 05 FILLER PIC X(20) VALUE SPACES. 05 FILLER PIC X(17) VALUE "INSURANCE ". 05 FILLER PIC X(15) VALUE " COVERAGE ". 05 FILLER PIC X(15) VALUE "MONTH PREM ". Code The date was brought in from the system and stored in WORKING-STORAGE. Now the components of the date are moved to the fields on the print line. Notice that the setup also puts a slash in between the month, day and year. The information on the column header is set up to align with the information in the columns. The PAGE-NO-WS is moved to PAGE-NO-HDR prior to writing the header.

6 01 TOTAL-LINE. 05 FILLER PIC X(64) VALUE SPACES. 05 TOT-MO-PREM-TL PIC $$$,$$$.99. 05 FILLER PIC X(6) VALUE SPACES. Code 01 ACCUMULATORS. 05 TOT-MO-PREM-WS PIC 9(5)V99 VALUE 0. As the records are processed, the calculated PREM-MO-WS is added to TOT-MO-PREM-WS. When end of file is reached and all records have been processed, PREM-MO-WS is moved to TOT- MO-PREM-TL and the total line is written.

7 This is the input file (ins.dat): 1111John L Brown L100000000100000 1212Jennifer Ames H015000000050000 1234John Anders C050000000120000 2424Stephen Daniels L050000000045000 2567Carl Hersey L050000000070000 3000Susan Ash H200000000200000 4567Lawrence Morgan C100000000150000 5678Marilyn Wilson H035000000070000 FD INS-FILE DATA RECORD IS INS-REC. 01 INS-REC. 05 IDNO PIC XXXX. 05 NAMZ PIC X(20). 05 TYPZ PIC X. 88 TYPE-LIFE VALUE "L". 88 TYPE-CAR VALUE "C". 88 TYPE-HOME VALUE "H". 05 AMT-COV PIC 9(7)V99. 05 PREM-YR PIC 9(4)V99. Input data - ins.dat

8 10/27/00 INSURANCE REPORT PAGE 1 ID # NAME INSURANCE COVERAGE MONTH PREM 1111 John L Brown LIFE $1,000,000.00 $83.33 1212 Jennifer Ames HOME OWNERS $150,000.00 $41.67 1234 John Anders AUTOMOBILE $500,000.00 $100.00 2424 Stephen Daniels LIFE $500,000.00 $37.50 2567 Carl Hersey LIFE $500,000.00 $58.33 3000 Susan Ash HOME OWNERS $2,000,000.00 $166.67 4567 Lawrence Morgan AUTOMOBILE $1,000,000.00 $125.00 5678 Marilyn Wilson HOME OWNERS $350,000.00 $58.33 $670.83 01 PAGE-HDR. 05 FILLER PIC X VALUE SPACES. 05 DATE-HDR. 10 MO-HDR PIC 99. 10 FILLER PIC X VALUE "/". 10 DA-HDR PIC 99. 10 FILLER PIC X VALUE "/". 10 YR-HDR PIC 99. 05 FILLER PIC X(23) VALUE SPACES. 05 FILLER PIC X(16) VALUE "INSURANCE REPORT". 05 FILLER PIC X(21) VALUE SPACES. 05 FILLER PIC X(5) VALUE "PAGE". 05 PAGE-NO-HDR PIC Z9. 05 FILLER PIC X(6) VALUE SPACES. Output - page header

9 Output - column header 01 COL-HDR. 05 FILLER PIC X(13) VALUE " ID # NAME". 05 FILLER PIC X(20) VALUE SPACES. 05 FILLER PIC X(17) VALUE "INSURANCE ". 05 FILLER PIC X(15) VALUE " COVERAGE ". 05 FILLER PIC X(15) VALUE "MONTH PREM ". 10/27/00 INSURANCE REPORT PAGE 1 ID # NAME INSURANCE COVERAGE MONTH PREM 1111 John L Brown LIFE $1,000,000.00 $83.33 1212 Jennifer Ames HOME OWNERS $150,000.00 $41.67 1234 John Anders AUTOMOBILE $500,000.00 $100.00 2424 Stephen Daniels LIFE $500,000.00 $37.50 2567 Carl Hersey LIFE $500,000.00 $58.33 3000 Susan Ash HOME OWNERS $2,000,000.00 $166.67 4567 Lawrence Morgan AUTOMOBILE $1,000,000.00 $125.00 5678 Marilyn Wilson HOME OWNERS $350,000.00 $58.33 $670.83

10 Code 10/27/00 INSURANCE REPORT PAGE 1 ID # NAME INSURANCE COVERAGE MONTH PREM 1111 John L Brown LIFE $1,000,000.00 $83.33 1212 Jennifer Ames HOME OWNERS $150,000.00 $41.67 1234 John Anders AUTOMOBILE $500,000.00 $100.00 2424 Stephen Daniels LIFE $500,000.00 $37.50 2567 Carl Hersey LIFE $500,000.00 $58.33 3000 Susan Ash HOME OWNERS $2,000,000.00 $166.67 4567 Lawrence Morgan AUTOMOBILE $1,000,000.00 $125.00 5678 Marilyn Wilson HOME OWNERS $350,000.00 $58.33 $670.83 01 DETAIL-LINE. 05 FILLER PIC X. 05 IDNO-PR PIC XXXX. 05 FILLER PIC XXXX. 05 NAMZ-PR PIC X(20). 05 FILLER PIC XXXX. 05 TYPZ-MSG-PR PIC X(13). 05 FILLER PIC XXXX. 05 AMT-COV-PR PIC $$,$$$,$$$.99. 05 FILLER PIC XXXX. 05 PREM-MO-PR PIC $$$$.99. 05 FILLER PIC X(6).

11 Code 01 TOTAL-LINE. 05 FILLER PIC X(64) VALUE SPACES. 05 TOT-MO-PREM-TL PIC $$$,$$$.99. 05 FILLER PIC X(6) VALUE SPACES. 10/27/00 INSURANCE REPORT PAGE 1 ID # NAME INSURANCE COVERAGE MONTH PREM 1111 John L Brown LIFE $1,000,000.00 $83.33 1212 Jennifer Ames HOME OWNERS $150,000.00 $41.67 1234 John Anders AUTOMOBILE $500,000.00 $100.00 2424 Stephen Daniels LIFE $500,000.00 $37.50 2567 Carl Hersey LIFE $500,000.00 $58.33 3000 Susan Ash HOME OWNERS $2,000,000.00 $166.67 4567 Lawrence Morgan AUTOMOBILE $1,000,000.00 $125.00 5678 Marilyn Wilson HOME OWNERS $350,000.00 $58.33 $670.83

12 Layout of program MAINLINE A-100-INITIALB-100-PROCESSC-100-TERMINATE B-200-LOOPB-210-TOTAL-ROUT B-300-HDR-ROUT

13 Logic flowchart MAINLINE A-100-INITIALIZE C-100-TERMINATE B-100-PROCESS END MAINLINE A-100- INITIALIZE END A-100- INITIALIZE Move date to header line ACCEPT system date OPEN files B-100- PROCESS READ FILE END B-100- PROCESS NO to MORE-RECS B-200-LOOP B-210- TOTAL-ROUT NOT END-OF-FILE

14 Logic flowchart B-200-LOOP Page = 1 or line-ct > 55 B-300- HDR- ROUT Y Y N Start setting up the line A A TYPE-LIFE TYPE-CAR TYPE-HOME LIFE to msg on line N Y HOME to msg on line N N Y AUTOMOBILE to msg on line Move amt-cov to line B

15 READ FILE NO to MORE-RECS Logic flowchart B Calculate prem-mo-ws Move prem-mo-ws to line Add to tot-mo-prem-ws accum Write line Add 1 to line-ct END B-200-LOOP B-210-TOTAL- ROUT END B-210- TOTAL-ROUT B-300-HDR- ROUT Move tot-mo-prem-ws to total line Write total line Move page no to header Write page hdr line Write column hdr line Write blank line ADD 1 to page no ADD 4 to line ct END B-300- HDR-ROUT C-100- TERMINATE Close files END C-100- TERMINATE

16 Code PROCEDURE DIVISION. MAINLINE. PERFORM A-100-INITIAL. PERFORM B-100-PROCESS. PERFORM C-100-TERMINATE. STOP RUN. A-100-INITIAL. OPEN INPUT INS-FILE OUTPUT PRINT-FILE. ACCEPT DATE-WS FROM DATE. MOVE MO-WS TO MO-HDR. MOVE DA-WS TO DA-HDR. MOVE YR-WS TO YR-HDR. B-100-PROCESS. READ INS-FILE AT END MOVE "NO " TO MORE-RECS. PERFORM B-200-LOOP UNTIL END-OF-FILE. PERFORM B-210-TOTAL-ROUT. ACCEPT is used to get data from outside the program. In this case, the program is getting the current date from the system. The reserve word for the system date is DATE. 01 INDICATORS. 05 MORE-RECS PIC XXX VALUE "YES". 88 END-OF-FILE VALUE "NO ". Note that END-OF-FILE is the condition name for MORE-RECS containing NO. This routine performs the total routine which will set up and print the final total line.

17 B-200-LOOP. IF PAGE-NO-WS = 1 OR LINE-CT-WS > 55 PERFORM B-300-HDR-ROUT. MOVE SPACES TO DETAIL-LINE. MOVE IDNO TO IDNO-PR. MOVE NAMZ TO NAMZ-PR. IF TYPE-LIFE MOVE "LIFE" TO TYPZ-MSG-PR ELSE IF TYPE-CAR MOVE "AUTOMOBILE" TO TYPZ-MSG-PR ELSE IF TYPE-HOME MOVE "HOME OWNERS" TO TYPZ-MSG-PR ELSE MOVE "** INVALID **" TO TYPZ-MSG-PR. MOVE AMT-COV TO AMT-COV-PR. DIVIDE PREM-YR BY 12 GIVING PREM-MO-WS ROUNDED. MOVE PREM-MO-WS TO PREM-MO-PR. ADD PREM-MO-WS TO TOT-MO-PREM-WS. WRITE PRINTZ FROM DETAIL-LINE AFTER ADVANCING 1 LINES. ADD 1 TO LINE-CT-WS. READ INS-FILE AT END MOVE "NO " TO MORE-RECS. Code This IF statement controls when headers are written. This is an OR setup. IF the first IF is true the action move “LIFE” is taken. If the first IF is not true then the ELSE is taken which asks the second IF. This continues through three Ifs. If all three Ifs are NO then the invalid message is moved to the line. This statement adds to the accumulator that will be moved to the final total line when processing is complete. This statement adds 1 to LINE-CT-WS which is tested at the top of the page to determine whether a new page should be started.

18 B-210-TOTAL-ROUT. MOVE TOT-MO-PREM-WS TO TOT-MO-PREM-TL. WRITE PRINTZ FROM TOTAL-LINE AFTER ADVANCING 2 LINES. B-300-HDR-ROUT. MOVE PAGE-NO-WS TO PAGE-NO-HDR. WRITE PRINTZ FROM PAGE-HDR AFTER ADVANCING PAGE. WRITE PRINTZ FROM COL-HDR AFTER ADVANCING 2 LINES. MOVE SPACES TO PRINTZ. WRITE PRINTZ AFTER ADVANCING 1 LINES. ADD 1 TO PAGE-NO-WS. MOVE 4 TO LINE-CT-WS. C-100-TERMINATE. CLOSE INS-FILE PRINT-FILE. Code This routine sets up and writes the total line. The accumulator has been being added to as the processing was done. See the previous slide. When the code on the previous slide determines that the headers should be written, this routine is performed. The page number is moved to the line and the total lines are written. Then the page number is increased by 1 for the next time and the line count is reset to 4 because the header routine used 4 lines to write the headers.


Download ppt "Explanation of SAMPLEIF (if88in1.cbl or if88in1.html) Please use speaker notes for additional information!"

Similar presentations


Ads by Google