loopsdispacc.ppt - Looping in your COBOL Program Please see...

Info icon This preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Looping in your COBOL Program Please see speaker notes for additional information!
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
IDENTIFICATION DIVISION. PROGRAM-ID. ADDLOOP. AUTHOR. GROCER. *ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT-AREA. 05 GET-ACCEPT-ANS PIC X VALUE SPACES. 05 FIRST-NUMBER PIC 999 VALUE 0. 05 SECOND-NUMBER PIC 999 VALUE 0. 05 ADD-ANS PIC 9999 VALUE 0. PROCEDURE DIVISION. MAINLINE. PERFORM B-100-PROCESS UNTIL GET-ACCEPT-ANS = "Q". STOP RUN. B-100-PROCESS. DISPLAY "ENTER THE FIRST NUMBER (UNDER 1000)". ACCEPT FIRST-NUMBER. DISPLAY "ENTER THE SECOND NUMBER (UNDER 1000)". ACCEPT SECOND-NUMBER. ADD FIRST-NUMBER TO SECOND-NUMBER GIVING ADD-ANS. DISPLAY "THE ANSWER IS " ADD-ANS. DISPLAY "PRESS Q FOLLOWED BY ENTER TO END THE PROGRAM". DISPLAY "PRESS ENTER ALONE TO CONTINUE". ACCEPT GET-ACCEPT-ANS . ADDDALP.CBL ADDDALP.CBL This is a traditional way of labeling paragraphs. We will see more about this in future slides. The PERFORM…UNTIL loop means do the paragraph over and over again until the user enters Q.
Image of page 2
GET-ACCEPT-ANS NOT = “Q” PERFORM B-100-PROCESS UNTIL GET-ACCEPT-ANS = "Q". STOP RUN. Logic of PERFORM…UNTIL Logic of PERFORM…UNTIL PERFORM B-100-PROCESS YES STOP RUN NO The logic of the PERFORM…UNTIL is that the UNTIL is checked first. If the condition is not true, then the routine is performed. If the condition is true then the logic drops to the next command which in this case is STOP RUN.
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
ADDDALP.INT ADDDALP.INT
Image of page 4
ADDDALP.INT ADDDALP.INT
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
IDENTIFICATION DIVISION. PROGRAM-ID. CREATE1. AUTHOR. GROCER ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT PAY-FILE ASSIGN TO "A:\PAY.DAT". DATA DIVISION. FILE SECTION. FD PAY-FILE DATA RECORD IS PAY-REC. 01 PAY-REC. 05 PAY-ID PIC 9999. 05 PAY-NAME PIC X(20). 05 PAY-TYPE PIC X. 05 PAY-RATE PIC 999V99. 05 PAY-HOURS PIC 99. WORKING-STORAGE SECTION. 01 WORK-AREA. 05 STOP-PROCESSING PIC X. Create1.cbl Create1.cbl This program is going to create a file. To do this we need to make entries in the ENVIRONMENT DIVISION. First we establish an INPUT-OUTPUT SECTION (there can be different sections in the ENVIRONMENT DIVISION), and then we specify that we are going to do FILE-CONTROL. We now use the SELECT statement to establish a link between the physical file which is called PAY.DAT and will be on the A drive and the logical file which we are going to name PAY- FILE. Note that the ASSIGN statement points to the physical file.
Image of page 6
IDENTIFICATION DIVISION. PROGRAM-ID. CREATE1. AUTHOR. GROCER ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT PAY-FILE ASSIGN TO "A:\PAY.DAT". DATA DIVISION. FILE SECTION. FD PAY-FILE DATA RECORD IS PAY-REC . 01 PAY-REC . 05 PAY-ID PIC 9999. 05 PAY-NAME PIC X(20). 05 PAY-TYPE PIC X. 05 PAY-RATE PIC 999V99. 05 PAY-HOURS PIC 99. WORKING-STORAGE SECTION. 01 WORK-AREA. 05 STOP-PROCESSING PIC X. Create1.cbl Create1.cbl We are now adding the FILE SECTION to the DATA DIVISION.
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern