Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

COBOL PROGRAMMING: The Program reads a file with sales transactions. Each record on the file has a state code, sales id and amount. Create a

COBOL PROGRAMMING:

The Program reads a file with sales transactions. Each record on the file has a state code, sales id and amount.

Create a table for sales id and amount, and a table for state code and amount.

Create two summary files; a Sales ID file with one record for each Sales ID with total amount for that Sales ID, and a State code file with a record for each state and the total amount for that state.

Extra Credit Opportunity: Create a trailer record for each file that has a "TR" in the code and the total amount for that file (10pts each file)

See program source code for further details.

SOURCE CODE:

IDENTIFICATION DIVISION. PROGRAM-ID. SALESSUM. * THE PROGRAM READS IN THE SALESIDAMT.DAT FILE AND NEEDS TO * WRITE OUT TWO SUMMARY-FILES; SALES-FILE-OUT AND STATE-FILE-OUT. * EACH SUMMARY FILE HAS ONE RECORD FOR EACH KEY (SALESID OR STATE) * WITH THE TOTAL AMOUNT FOR THAT KEY ON THE RECORD. * YOU MAY WRITE OUT A TRAILER RECORD FOR EACH FILE FOR EXTRA * CREDIT. THE PROGRAM IS MOSTLY CODED AND YOU WILL NEED TO * ADD CODE TO COMPLETE THE ASSIGMENT. THIS IS INDICATED, BUT YOU * MAY HAVE TO ADD ADDITIONAL CODE TO GET IT TO WORK AND COMPILE. ENVIRONMENT DIVISION. CONFIGURATION SECTION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT SALES-FILE-IN ASSIGN TO "C:\Users\call1\SALESIDAMT.DAT" ORGANIZATION IS LINE SEQUENTIAL FILE STATUS IS SALES-FILE-STATUS. SELECT SALES-FILE-OUT ASSIGN TO "C:\Users\call1\SALESIDOUT.DAT" ORGANIZATION IS LINE SEQUENTIAL. SELECT STATE-FILE-OUT ASSIGN TO "C:\Users\call1\STATESOUT.DAT" ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD SALES-FILE-IN RECORDING MODE IS F DATA RECORD ISSALES-RECORD-IN. 01 SALES-RECORD-IN. 05 SALES-STATE-IN PIC X(02). 05 SALES-ID-IN PIC X(03). 05 SALES-AMOUNT-IN PIC 9(04)V99. FD SALES-FILE-OUT RECORDING MODE IS F DATA RECORD IS SALES-RECORD-OUT. 01 SALES-RECORD-OUT. 05 SALES-ID-OUT PIC X(03). 05 SALES-ID-AMT-OUT PIC 9(06)V99. FD STATE-FILE-OUT RECORDING MODE IS F DATA RECORD IS STATE-RECORD-OUT. 01 STATE-RECORD-OUT. 05 STATE-ID-OUT PIC X(02). 05 STATE-ID-AMT-OUT PIC 9(06)V99. WORKING-STORAGE SECTION. 01 TABLE-SALES-ID-ENTRY OCCURS 99 TIMES. 05 TABLE-SALES-ID PIC X(03). 05 TABLE-SALES-ID-AMOUNT PIC 9(06)V99. * YOU MUST CREATE A TABLE HERE TO RECORD THE STATE ENTRIES * AND THE AMOUNT FOR EACH STATE. IT WILL LOOK LIKE THE TABLE * ABOVE, BUT BE FOR THE STATE. YOU WILL ALSO NEED TO CREATE * A SUBSCRIPT FOR THE STATE TABLE, LIKE WS-STATE-SUB. 01 WS-COUNTERS. 05 WS-SALES-TOTAL PIC 9(06)V99 VALUE 0. 05 WS-ID-SUB PIC 9(02).

01 WS-DATA-SWITCH pic 9 VALUE 1. 88 EOF VALUE 0. 01 SALES-FILE-STATUS PIC X(02). 88 NO-DATA VALUE '02' THRU '99'. PROCEDURE DIVISION. 0000-DRIVER. DISPLAY 'SALESSUM PROGRAM START'. OPEN INPUT SALES-FILE-IN. OPEN OUTPUT SALES-FILE-OUT STATE-FILE-OUT. PERFORM 0100-INITIALIZE-TABLE. READ SALES-FILE-IN. PERFORM 0200-POPULATE-TABLES UNTIL NO-DATA or WS-DATA-SWITCH = 0. PERFORM 0300-WRITE-SUMMARY-FILES. PERFORM 0400-WRITE-TRAILERS. CLOSE SALES-FILE-IN SALES-FILE-OUT STATE-FILE-OUT. GOBACK. 0100-INITIALIZE-TABLE. * INITIALIZE THE SALES ID TABLE: PERFORM VARYING WS-ID-SUB ....... UNTIL ....... MOVE SPACES TO ............. (WS-ID-SUB) MOVE ZEROES TO ............. (WS-ID-SUB) END-PERFORM. * INITIALIZE THE STATE TABLE: PERFORM VARYING ................. UNTIL ....... MOVE ............. MOVE ............. END-PERFORM. 0200-POPULATE-TABLES. * SEARCH SALES TABLE FOR THE SALES ID OR AN ENTRY WITH SPACES: PERFORM VARYING WS-ID-SUB ........ UNTIL ......... OR ....................................... OR ....................................... END-PERFORM. * CHECK TO SEE IF THE SALE ID WAS FOUND: IF ................................ ADD SALES-AMOUNT-IN TO TABLE-SALES-ID-AMOUNT (WS-ID-SUB) ELSE .......................................... ........................................... * SEARCH STATE TABLE FOR THE STATE ID OR AN ENTRY WITH SPACES: PERFORM VARYING WS-STATE-SUB ........ UNTIL ......... OR ....................................... OR ....................................... END-PERFORM. * CHECK TO SEE IF THE STATE WAS FOUND: IF ................................ ADD SALES-AMOUNT-IN TO ...... (WS-STATE-SUB) ELSE .......................................... ........................................... READ SALES-FILE-IN AT END MOVE 0 TO WS-DATA-SWITCH. 0300-WRITE-SUMMARY-FILES. * READ THROUGH EACH SALES ID TABLE OCCURENCE AND MOVE TO THE * SALES SUMMARY OUTPUT RECORD AND WRITE THE RECORD. PERFORM VARYING WS-ID-SUB .......... UNTIL ......... OR TABLE-SALES-ID(WS-ID-SUB) = SPACES MOVE ......... TO SALES-ID-OUT MOVE ......... TO SALES-ID-AMT-OUT WRITE SALES-RECORD-OUT ADD SALES-ID-AMT-OUT TO WS-SALES-TOTAL END-PERFORM. * READ THROUGH EACH STATE ID TABLE OCCURENCE AND MOVE TO THE * STATE SUMMARY OUTPUT RECORD AND WRITE THE RECORD. PERFORM VARYING WS-STATE-SUB .......... UNTIL ......... OR ......... MOVE ......... TO ........... MOVE ......... TO ........... WRITE STATE-RECORD-OUT ADD .......... TO ........... END-PERFORM. 0400-WRITE-TRAILERS. * IF YOU WANT EXTRA CREDIT FOR CREATING A TRAILER RECORD, REMOVE * EXIT STATEMENT AND INSERT THE EXTRA CREDIT CODE: EXIT.

SALESIDAMNT.DAT:

MO101100000 MO101100000 MO102200000 MO103050000 MO103045050 MO103020050 MO104075000 MO105080000 IL101100000 IL101100000 IL102200000 IL103050000 IL103045050 IL103020050 IL104075000 IL105080000 IA101100000 IA101100000 IA102200000 IA103050000 IA103045050 IA103020050 IA104075000 IA105080000 MS101100000 MS101100000 MS102200000 MS103050000 MS103045050 MS103020050 MS104075000 MS105080000 NE205120000 KS105130000 KS103005000 KY305040000 KY101095075

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

What is a global industry?

Answered: 1 week ago