Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

PROGRAM THAT READS IN STATES UNTIL END OF DATA

Posted By: Aidan Campbell     Category: Cobol     Views: 2541

WRITE A PROGRAM THAT READS IN STATES UNTIL END OF DATA.

Code for PROGRAM THAT READS IN STATES UNTIL END OF DATA in Cobol

IDENTIFICATION DIVISION.
PROGRAM-ID.  ASSIGNMENT4.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.    SELECT STATE-DATA    ASSIGN TO "ASSIGN4.DAT".
        SELECT STATE-OUTPUT    ASSIGN TO "ASSIGN4.OUT".


DATA DIVISION.
FILE SECTION.
FD    STATE-DATA            LABEL RECORDS ARE STANDARD.
01    STATE-RECORD.
    05  STATE-NO            PIC 99.
    05  COUNTY-NO            PIC X(2).
    05  DISTRICT-NO            PIC X(2).
    05  POPULATION            PIC 9(6).

FD      STATE-OUTPUT            LABEL RECORDS ARE STANDARD.
01    STATE-PRINT            PIC X(132).

WORKING-STORAGE SECTION.
01     WORK-AREAS.
    05  WS-DATE            PIC 9(6).
       05  DATE-OTHER REDEFINES WS-DATE.
            10  DATE-YEAR        PIC 99.
        10  DATE-MONTH        PIC 99.
        10  DATE-DAY        PIC 99.
    05  WS-PAGE-COUNT        PIC 99     VALUE ZEROS.
    05  STATE-COUNT            PIC 99       VALUE ZEROS.
    05  ARE-THERE-MORE-RECORDS    PIC X(3)   VALUE 'YES'.
        88  MORE-RECORDS               VALUE 'YES'.
        88  NO-MORE-RECORDS                   VALUE 'NO '.
    05  STATE-POP            PIC 9(8).
    05  TOTAL-POP            PIC 9(9).
    05  STATE-HOLD            PIC 99       VALUE ZEROS.

01    HEADER-1.
    05  FILLER            PIC X(40)  VALUE SPACES.
    05  FILLER            PIC X(17)  VALUE 'POPULATION REPORT'.
    05  FILLER            PIC X(3)   VALUE SPACES.
    05  DATE-OUT.
        10  MONTH-OUT        PIC 99.
        10  FILLER            PIC X      VALUE '/'.
        10  DAY-OUT            PIC 99.
        10  FILLER            PIC X      VALUE '/'.
        10  YEAR-OUT        PIC 99.
    05  FILLER            PIC X(2)   VALUE SPACES.
        05  FILLER            PIC X(4)   VALUE 'PAGE'.
    05  FILLER            PIC X      VALUE SPACE.
    05  PAGE-OUT            PIC Z9.
    05  FILLER            PIC X(55)  VALUE SPACES.


01    HEADER-2.
    05  FILLER            PIC X(19)  VALUE SPACES.
    05  FILLER            PIC X(8)   VALUE 'STATE NO'.
    05  FILLER            PIC X(13)  VALUE SPACES.
    05  FILLER            PIC X(16)  VALUE 'TOTAL POPULATION'.
    05  FILLER            PIC X(77)  VALUE SPACES.

01     FOOTER-1.
    05  FILLER            PIC X(40)  VALUE SPACES.
    05  FILLER            PIC X(20)  VALUE 'TOTAL USA POPULATION'.
        05  TOTAL-USA-POP        PIC ZZZ,ZZZ,ZZ9.
        05  FILLER            PIC X(61)  VALUE SPACES.


01    POPULATION-DETAILS.
    05  FILLER            PIC X(23).
    05  STATE-NO-OUT        PIC Z9.
    05  FILLER            PIC X(16).
    05  POPULATION-OUT        PIC ZZ,ZZZ,ZZ9.
    05  FILLER            PIC X(81).


PROCEDURE DIVISION.

100-MAIN-MODULE.
    OPEN INPUT  STATE-DATA
         OUTPUT STATE-OUTPUT.
        PERFORM 200-DATE-ROUTINE THRU 300-HEADING-ROUTINE.
        READ STATE-DATA
             AT END MOVE 'NO ' TO ARE-THERE-MORE-RECORDS.
    IF MORE-RECORDS
        MOVE STATE-NO TO STATE-HOLD.
        PERFORM 400-POPULATION-ROUTINE
        UNTIL NO-MORE-RECORDS.
    PERFORM 700-TOTAL-ROUTINE.
    CLOSE STATE-DATA
          STATE-OUTPUT.
        STOP RUN.

200-DATE-ROUTINE.
    ACCEPT WS-DATE FROM DATE
    MOVE DATE-MONTH TO MONTH-OUT.
    MOVE DATE-DAY TO DAY-OUT.
    MOVE DATE-YEAR TO YEAR-OUT.

300-HEADING-ROUTINE.
    ADD 1 TO WS-PAGE-COUNT.
    MOVE WS-PAGE-COUNT TO PAGE-OUT.
    IF STATE-COUNT<10
    WRITE STATE-PRINT FROM HEADER-1
        AFTER ADVANCING 2 LINES
    ELSE WRITE STATE-PRINT FROM HEADER-1
        AFTER ADVANCING PAGE.
    WRITE STATE-PRINT FROM HEADER-2
        AFTER ADVANCING 2 LINES.

400-POPULATION-ROUTINE.
    IF STATE-NO NOT EQUAL TO STATE-HOLD
        PERFORM 800-STATE-BREAK
        MOVE STATE-NO TO STATE-HOLD.
    ADD POPULATION TO STATE-POP.
        READ STATE-DATA
             AT END MOVE 'NO ' TO ARE-THERE-MORE-RECORDS.
    IF NO-MORE-RECORDS 
        PERFORM 800-STATE-BREAK.
    
500-WRITE-ROUTINE.
        MOVE STATE-HOLD TO STATE-NO-OUT.
    MOVE STATE-POP TO POPULATION-OUT.
    WRITE STATE-PRINT FROM POPULATION-DETAILS
        AFTER ADVANCING 2 LINES.
    ADD STATE-POP TO TOTAL-POP.
    
600-BREAK-ROUTINE.
    PERFORM 300-HEADING-ROUTINE.
    MOVE ZEROS TO STATE-COUNT.

700-TOTAL-ROUTINE.
    MOVE TOTAL-POP TO TOTAL-USA-POP.
    WRITE STATE-PRINT FROM FOOTER-1
        AFTER ADVANCING 10 LINES.

800-STATE-BREAK.
    ADD 1 TO STATE-COUNT.
        IF STATE-COUNT>10
                PERFORM 600-BREAK-ROUTINE.
        PERFORM 500-WRITE-ROUTINE.
    MOVE ZEROS TO STATE-POP.
  
Share: 


Didn't find what you were looking for? Find more on PROGRAM THAT READS IN STATES UNTIL END OF DATA Or get search suggestion and latest updates.

Aidan Campbell
Aidan Campbell author of PROGRAM THAT READS IN STATES UNTIL END OF DATA is from Toronto, Canada.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!