Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop run

Status
Not open for further replies.

lostso

Technical User
Oct 22, 2002
13
US
I don't know where my stop run should go in my control break. please help.
IDENTIFICATION DIVISION.
PROGRAM-ID. ASSGN-04.
AUTHOR. JESSICA BENNETT
DATE-WRITTEN. 10-29-02.
*REMARKS. THIS PROGRAM LISTS DATA, 80-80.

ENVIRONMENT DIVISION.

CONFIGURATION SECTION.

SPECIAL-NAMES. C01 IS NEXT-PAGE.

INPUT-OUTPUT SECTION.

FILE-CONTROL.

SELECT DATA-FILE ASSIGN TO "A:CHDATA04.DAT".
SELECT PRINT-FILE ASSIGN TO "A:BREAK.CBL".

DATA DIVISION.

FILE SECTION.

FD DATA-FILE.

01 DATA-RECORD.
05 ITEM-NUMBER PIC X(9).
05 ITEM-DESCRIP PIC X(20).
05 FILLER PIC X(10).
05 QUANTITY-SOLD PIC 999.
05 UNIT-PRICE PIC 999V99.
05 SALES-DATE.
10 M-IN PIC 99.
10 D-IN PIC 99.
10 Y-IN PIC 99.
05 SALESMAN PIC X(2).
05 PIC X.


FD PRINT-FILE.

01 PRINT-RECORD PIC x(80).

WORKING-STORAGE SECTION.

01 WS-WORK-AREAS.
05 WS-HOLD-ITEM-NUMBER PIC X(9) VALUE ZEROS.
05 WS-HOLD-SALESMAN PIC X(2) VALUE ZEROS.
05 ARE-THERE-MORE-RECORDS PIC X(3) VALUE "YES".
88 MORE-RECORDS VALUE "YES".
88 NO-MORE-RECORDS VALUE "NO".
05 FIRST-RECORD PIC X(3) VALUE "YES".
05 WS-ITEM-TOTAL PIC 9(4)V99 VALUE ZEROS.
05 WS-SALES-TOTAL PIC 9(4)V99 VALUE ZEROS.

01 NAME-RECORD.
05 PIC x(50) VALUE SPACES.
05 PIC x(30) VALUE "JESSICA BENNETT".

01 HEADING-1.
05 HEADER-DATE PIC x(8) VALUE "11/05/02".
05 PIC x(23) VALUE SPACES.
05 PIC x(18) VALUE "KITCHEN INDUSTRIES".
05 PIC x(24) VALUE SPACES.
05 PIC x(5) VALUE "PAGE".
05 PAGE-NUMBER-OUT PIC Z9.

01 HEADING-2.
05 PIC X(7) VALUE SPACES.
05 PIC X(12) VALUE "ITEM NUMBER".
05 PIC X(6) VALUE SPACES.
05 PIC X(16) VALUE "ITEM DESCRIPTION".

01 HEADING-3.
05 PIC X(7) VALUE SPACES.
05 PIC X(9) VALUE "SALESMAN".
05 PIC X(6) VALUE SPACES.
05 PIC X(13) VALUE "QUANTITY SOLD".
05 PIC X(6) VALUE SPACES.
05 PIC X(5) VALUE "SALES".



01 ITEM-DETAIL-LINE.
05 PIC X(1) VALUE SPACES.
05 ITEM-NUMBER-OUT PIC X(9).
05 PIC X(8) VALUE SPACES.
05 ITEM-DESCRIP-OUT PIC X(16).

01 SALESMAN-DETAIL-LINE.
05 PIC X(8) VALUE SPACES.
05 QUANTITY-SOLD-OUT PIC ZZ9.
05 PIC X(5) VALUE SPACES.
05 SALESMAN-OUT PIC X(2).
05 PIC X(1) VALUE SPACES.
05 SALES-OUT PIC Z(7).99.

01 TOTAL-PRINT-RECORD.
05 PIC X(40) VALUE SPACES.
05 TOTAL-ITEM-TOTAL PIC $$$,$$$.99.
05 PIC X(3) VALUE SPACES.
05 TOTAL-SALES PIC $,$$$.99.
05 UNUSED PIC X(9) VALUE SPACES.

01 COUNTERS.
05 PAGE-NUMBER PIC S99 VALUE ZERO PACKED-DECIMAL.
05 LINE-COUNT PIC S99 VALUE ZERO PACKED-DECIMAL.
05 WS-TOTAL-ITEM-TOTAL PIC S9(7)V99 VALUE ZERO.
05 WS-TOTAL-SALES PIC S9(4)V99 VALUE ZERO.
05 WS-SALES PIC S9(4)V99 VALUE ZERO.

01 FLAGS.
05 MORE-DATA-FLAG PIC x(3) VALUE "YES".
88 NO-MORE-DATA VALUE "No".

PROCEDURE DIVISION.

100-MAIN-LINE-ROUTINE.
PERFORM 700-INITIALIZATION-ROUTINE.
PERFORM 200-DETAIL-ROUTINE
UNTIL NO-MORE-DATA.
PERFORM 400-ITEM-NUMBER-BREAK
PERFORM 500-FINAL-ROUTINE.

200-DETAIL-ROUTINE.
EVALUATE TRUE
WHEN FIRST-RECORD = "YES"
MOVE SALESMAN TO WS-HOLD-SALESMAN
MOVE ITEM-NUMBER TO WS-HOLD-ITEM-NUMBER
PERFORM 600-HEADER-ROUTINE
MOVE "NO" TO FIRST-RECORD
WHEN ITEM-NUMBER NOT = WS-HOLD-ITEM-NUMBER
PERFORM 400-ITEM-NUMBER-BREAK
WHEN SALESMAN NOT = WS-HOLD-SALESMAN
PERFORM 300-FIRST-BREAK
END-EVALUATE.
PERFORM 800-INITIALIZATION-ROUTINE.
STOP RUN.


300-FIRST-BREAK.
MOVE WS-ITEM-TOTAL TO TOTAL-ITEM-TOTAL
MOVE WS-HOLD-SALESMAN TO SALESMAN-OUT
WRITE PRINT-RECORD FROM SALESMAN-DETAIL-LINE
AFTER ADVANCING 2 LINES
ADD WS-SALES TO WS-ITEM-TOTAL
IF MORE-RECORDS
MOVE ZERO TO WS-ITEM-TOTAL
MOVE QUANTITY-SOLD TO WS-HOLD-SALESMAN
END-IF.

400-ITEM-NUMBER-BREAK.
PERFORM 300-FIRST-BREAK
MOVE WS-SALES TO TOTAL-SALES
WRITE PRINT-RECORD FROM ITEM-DETAIL-LINE
AFTER ADVANCING 2 LINES
IF MORE-RECORDS
MOVE ZEROS TO WS-SALES
MOVE ITEM-DESCRIP TO WS-HOLD-ITEM-NUMBER
PERFORM 600-HEADER-ROUTINE
END-IF.


500-FINAL-ROUTINE.
CLOSE DATA-FILE, PRINT-FILE.

600-HEADER-ROUTINE.
MOVE NAME-RECORD TO PRINT-RECORD.
ADD 1 TO PAGE-NUMBER.
MOVE PAGE-NUMBER TO PAGE-NUMBER-OUT.
WRITE PRINT-RECORD AFTER ADVANCING NEXT-PAGE.
MOVE HEADING-1 TO PRINT-RECORD.
WRITE PRINT-RECORD AFTER ADVANCING 2 LINES.
MOVE HEADING-2 TO PRINT-RECORD.
WRITE PRINT-RECORD AFTER ADVANCING 2 LINES.
MOVE HEADING-3 TO PRINT-RECORD.
WRITE PRINT-RECORD AFTER ADVANCING 2 LINES.
MOVE SPACES TO PRINT-RECORD.

700-INITIALIZATION-ROUTINE.
OPEN INPUT DATA-FILE
OUTPUT PRINT-FILE.
READ DATA-FILE AT END MOVE "No"
TO MORE-DATA-FLAG.
WRITE PRINT-RECORD AFTER ADVANCING 2 LINES.
MOVE 8 TO LINE-COUNT.

800-INITIALIZATION-ROUTINE.
MOVE "YES" TO MORE-DATA-FLAG.
WRITE PRINT-RECORD AFTER ADVANCING 2 LINES.
MOVE 8 TO LINE-COUNT.
 
The STOP RUN ends the execution of the program, so you always want to make sure everything you want gets executed. Usually it is at the end of your main routine always. This also makes it clear to anyone looking at your code.

So, in your case it would be the last line of para 100. confusedlady
 
It loops if I do that and won't stop.
 
Within the detail routine, you need to read the next record so that the statement (below) in your main routine will be true at some point. Since "until no-more-data" is never true, the program just loops (and loops...)

PERFORM 200-DETAIL-ROUTINE
UNTIL NO-MORE-DATA.
confusedlady
 
I do have that in my program.
 
At the end of '200-DETAIL-ROUTINE' you need to read the next record. I do not see anywhere that you are reading after the inital open and read.
 
Also, at the end of 200-DETAIL-ROUTINE (assuming you remove the misplaced STOP RUN) you have coded:
Code:
 PERFORM 800-INITIALIZATION-ROUTINE.

Don't you suspect that 800-INITIALIZATION-ROUTINE might be doing something that causes 200-DETAIL-ROUTINE to be PERFORMed one more time....? Tom Morrison
 
It loops with out the 800-Initialization routine
 
Note that I used the word also. You need to follow the advice of kkitt as well. Tom Morrison
 
I went and did this instead now all I go to do is try it. lol

100-MAIN-LINE-ROUTINE.
PERFORM 700-INITIALIZATION-ROUTINE.
PERFORM UNTIL NO-MORE-DATA
READ DATA-FILE
AT END
MOVE "NO" TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 200-DETAIL-ROUTINE
END-READ
END-PERFORM
PERFORM 400-ITEM-NUMBER-BREAK
PERFORM 500-FINAL-ROUTINE.
STOP RUN.
 
You are going in the correct direction. Tom Morrison
 
lotso,
You need to follow kkit's advice. You will do this inb many of the programs you write later, so you may as well get it down now. Whenever you want to process each record in a sequential file (first to last), the general idea is the same.

In your main para., direct a processing para (like your 200) to be done until there are no more records (you've hit EOF). PRIOR to this, you have read the first record (like you originally did in your initialization)

The processing para. (your 200-detail) is what is executed for each pass in the loop. On pass 1 (remember, that 1st record is in memory), do whatever is required for processing, and read the next record and check for more data. If there is more data, you perform the para. again (and so on and so on. This is a loop). If there is no more data, (the "until") you drop out of the loop and do your ending stuff.

I hope this is clear :) confusedlady
 
This forum has a wonderful group of experts. Jack (aka slade) has written a FAQ on the topic of control breaks that is now right on point:
faq209-780

Check it out. If you find it helpful, be sure to reward Jack through the rating system. Tom Morrison
 

For you coding setup this way:

100-MAIN-LINE-ROUTINE.
PERFORM 700-INITIALIZATION-ROUTINE.
PERFORM UNTIL NO-MORE-DATA
READ DATA-FILE
AT END
MOVE "NO" TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 200-DETAIL-ROUTINE
END-READ
END-PERFORM
PERFORM 400-ITEM-NUMBER-BREAK
PERFORM 500-FINAL-ROUTINE.
STOP RUN.

I hope that in the 700-INITIALIZATION-ROUTINE you have removed the priming read, if not then you will be missing the first record.

I pesonally perfer this coding style of the inline performs and reads for controlling my logic. As you can see from you code there is no longer a need to do a read after the open to "prime" the process.
 
Hi kkitt,

I like the priming read because an EOF on the 1st read usually (but not always) indicates a problem and requires special processing, E.G.:

DISPLAY 'ERROR!!!! NO DATA PROVIDED
STOP RUN

There are other ways of handeling this situation, for example adding to a counter after every read and checking the counter for zero at EOF.

In any event, it's always a good idea to check for "no data provided" situations.

BTW, instead of:

MOVE "NO" TO ARE-THERE-MORE-RECORDS

my pref is:

SET NO-MORE-DATA TO TRUE

rEGARDS, jACK.
 
Lotso,
I can't search find the thread right now, but I remember one discussing the pros/cons of using a prime (also called seed) read.

Whatever way you go, you just have to make sure:

-you process every rec (common error in logic to not get either first one or last one, so be careful).

-you do any special processing at end

-as Slade mentioned, specifically doing special processing for no recs in file is wise

The basic logic for processing a sequential file doesn't really change because the pgm is a control-break one. confusedlady
 
You are all very helpful thank you
 
try this ::

procedure division.


500-final-routine.
close data-file, print-file.
stop run.

or

01 acc pic 9.

procedure division.

500-final-routine.
close date-file, print-file.
display (, ) "continue?".
accept acc
if acc = "n" or "N"
stop run else
(condition)
end-if.


 
Usually STOP RUN is in the FINAL-ROUTINE.

Your paragraph names are goofy. Initialization is something that is only done once in the beginning of a program.

Usually in mainline you do your initialization and then keep doing your process of reading and printing until you reach the end of file. When you reach the last read you change the flag to no-more-records. This is what should be the variable that the process checks and should end the main process loop. You have to have code that turns on a flag when there are no more records.

Then you go to the next step in mainline which is FINAL routine. In the final routine after you close the files you do a stop run. Either that or do the final routine and then put STOP RUN in the mainline logic.

You keep setting lines to 8. Why do you do this? Are you going to put each salesman on a separate page? If you are performing breaks, what happens if there are over 100 sales by one salesman? When will you page break?

There are some simple things you can add for your program that help to debug.

1. Put the read in a separate perform.
2. Check for end of file in the read and change the flag to NO-MORE-RECORDS.
3. Put the print of the detail line in a separate perform.
4. You could check for the breaks at the point of reading the record.
5. Add a counter for records read.
6. Add a counter for records printed.
7. Add a counter for detail lines in case you get too many on a page.
8. Add a counter for page number to increment every time you print headings so you can move that to the page number before you print. There are times when you dont want page numbers also. Often when you plan on splitting up the report you leave this off. It just confuses people.
9. Put a display that lets you know when you enter your final routine and you will know if you ever get there.
10 In your final routine print out the counters for records read and records printed and/or display them on the screen.
11. In the process you perform for each record if the records read count gets too high change the flag to no-more-records. This is a failsafe to end the program. You can put something similar in the heading routine als and count the page numbers and end the job should the page number get too high. This helps you to find the logic errors.
12. In the final routine you can display or print different data to let you know what the values of various variables were when you end the program. If you do not like my post feel free to point out your opinion or my errors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top