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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with conbreaks 1

Status
Not open for further replies.

imac900

Programmer
Feb 18, 2001
1
GB
i am currently learning COBOL and have been set the following task.
design a program that will read records from disk and produce report.
each record terminated by newline.
data already validated.
record contains..
ref number 6 alphanumeric
type code 1 numeric ( 1 to 6 )
weight 4 numeric
quantity 4 numeric
calculation method 1 numeric (1 or 2)
unit buying price 4 numeric 1 decimal place
unit sale price 4 numeric 1 decimal place

records sorted by type code ascending order

when reading records a change of type code results in CONBREAK to print totals for each type code then moves to next type code.
this is where im stuck how do i do the conbreak part?

please help.
 
Hi Imac,

This problem represents a major construct in business programming, so the time you devote to this is well spent.

Input data is usually presented to a pgm in some sort sequence, e.g:

file
acct#1
product1
date1
date2
etc.
product2
date1
date3
date4
etc.
acct#2
product1
date3
etc.

So you have a file level, an acct level, a product level and a date level. These levels are important because they are used to process the breaks in the program.

The general form is as follows:

perform level n until level n-1 is finished

For the file described above the perform sequence would be:

perform acct-lev until file-is-finished
perform prod-lev until acct-is-finished
perform date-lev until prod-is-finished
perform detl-lev until date-is-finished

OK now lets flesh this out. How do we determine when each level is finished? One way is to expand the function of the read routine to do this:

7000-read-rtn.
move ws-ip-rec to ws-ip-prev
read ip-file into ws-ip-rec
at end set ip-eof to true
move high-values to ws-ip-rec
not at end add +1 to ws-ip-cnt
end-read
perform 7010-set-breaks
.
7010-set-breaks.
if curr-acct not = prev-acct
set acct-is-finished to true
set prod-is-finished to true
set date-is-finished to true
end-if
if curr-prod not = prev-prod
set prod-is-finished to true
set date-is-finished to true
end-if
if curr-date not = prev-date
set date-is-finished to true
end-if
.

Second question: We haven't read any data yet, how can we test if the levels are finished? We do a priming read outside of the loops, usually in the init or mainline section. After this read, if EOF is detected, an error msg is displayed and the pgm is usually exited because no input data has been provided.

How can the loops be executed if the "is-finished" switch has already been set? They can't. So, we reset the switch before executing each lower level:

0000-main-line.
perform 7000-read-ip
if ip-eof
display error msg
stop run
end-if
perform acct-lev until file-is-finished
perform 6900-print-rpt-end
perform 9000-end-it
stop run
.
acct-lev.
perform 6000-print-rpt-heads
set reset-acct-sw to true
perform prod-lev until acct-is-finished
perform 6100-print-acct-tots
zero tots, etc.
.
prod-lev.
set reset-prod-sw to true
perform date-lev until prod-is-finished
.
date-lev.
set reset-date-sw to true
perform detl-lev until date-is-finished
.
detl-lev.
move ip data to rpt-line or whatever
perform 7000-read-ip
.

Note that the form of each level except the detail level is:

Do pre-break stuff (print rpt heads, save data that wont't be available after return from perform, etc.)

Reset the level switch.

Perform the next lower level.

Do post-break stuff (strike and/or zero or roll totals, write total recs, etc.)

At the detail level process the previous rec and read the next rec before exiting.

At entry to each level the record has already been read and is ready for processing.

Here's what a break switch would look like:

01 ws-break-switches.
05 ws-acct-sw pic x(001).
88 acct-is-finished value 'f'.
88 reset-acct-sw value 'r'.

Your problem, Imac, only has 2 levels so your performs would look like:

0000-mainline.
.
.
.
preform 1000-process-codes until ip-eof
.
.
.
1000-process-codes.
set reset-code-sw to true
perform 1100-process-detl until code-is-finished
.
1100-process-detl.
collect data, etc.
perform 7000-read-ip
.

You have to ask: What do I do before the breaks: what do I do after.

I hope this helps.

Jack
 
I had to do conditional breaks in my first COBOL class... and in all of my programs since then (the usual being a page check), but also to do sub-totals, etc, etc..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top