For Programmers: Free Programming Magazines  


Home > Archive > Cobol > April 2004 > Compare two .dat files









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Compare two .dat files
Brent

2004-03-29, 1:30 pm

I am a student and am having troubles reading in two .dat files in
order to compare them. The first file contains a student name and
test answers ex:(John Doe ADCBAADDCC). The other file contains
the answer key ex:(ADDBDCDCDC). I cannot figure out how to read both
files in at the same time and how to assign a field to the correct
information. The output file has to contain their name and number of
answers correct. The assignment says to use paired arrays but the
book doesn't go into this. I am new to COBOL so please be
specific(code examples).

Thanks in advance
James J. Gavan

2004-03-29, 4:30 pm

Brent wrote:

>I am a student and am having troubles reading in two .dat files in
>order to compare them. The first file contains a student name and
>test answers ex:(John Doe ADCBAADDCC). The other file contains
>the answer key ex:(ADDBDCDCDC). I cannot figure out how to read both
>files in at the same time and how to assign a field to the correct
>information. The output file has to contain their name and number of
>answers correct. The assignment says to use paired arrays but the
>book doesn't go into this. I am new to COBOL so please be
>specific(code examples).
>
>Thanks in advance
>
>

I sympathize with your predicament. The instructor has told you all
about using files, and you think you have a handle on it - UNTIL he sets
a particular problem, ZOINK ! Then you mind goes a complete blank ! With
a year or so of COBOL you wont consider it a challenge but it IS for
beginners. (Check back through the archives for a message from Pete
Dashwood which addresses your problem - he provides source. You might
also get some tips if you go to U of Limerick site -
http://www.csis.ul.ie/COBOL/examples/).

Might help if you posted the text of the exercise because you haven't
told us whether your input is ISAM (indexed) files or Sequential Files
*already* in sorted sequence.

You can get over that mental blockage if you try this on a table with a
set of playing cards. Extract the Hearts and Spades, keeping them
separate and sort them ascending sequence - doesn't matter for this
exercise, you could treat the Aces as the 'high' or 'low'. Put the two
sets of cards face down. Now take the first Heart then take the first
Spade and compare for equality. (You can complicate it by removing say,
the 9 of Hearts and the 10 of Spades). Repeat the card pick-up sequence.
Think on what happens when you reach the end of a group of cards. Think
through your own mental logic as you pick up the cards.

If you get part way there, post your *clean compiled* source, even if it
doesn't work.

Jimmy, Calgary AB
Michael Mattias

2004-03-29, 6:32 pm

"James J. Gavan" <jjgavan@shaw.ca> wrote in message
news:j_%9c.44748$QO2.12573@pd7tw1no...
> Brent wrote:
>
[color=darkred]
> You can get over that mental blockage if you try this on a table with a
> set of playing cards. Extract the Hearts and Spades....


I could write the COBOL thing in my sleep. (Probably have, the more I think
about it).

But this playing card thing? Damn, that confuses me.

MCM



Richard

2004-03-29, 9:30 pm

brnetg@yahoo.com (Brent) wrote

> I am a student and am having troubles reading in two .dat files in
> order to compare them. The first file contains a student name and
> test answers ex:(John Doe ADCBAADDCC). The other file contains
> the answer key ex:(ADDBDCDCDC).


You don't need to 'compare two files' at all. There is one file while
appears to have one record with the correct answers, which you would
read and store that set of answers in a table. The other may should
contain a number of records, one for each student.

> I cannot figure out how to read both
> files in at the same time and how to assign a field to the correct
> information.


You do not need to 'read both files at the same time'. You would read
one file for one record and then read the other file for all the
records.

> The output file has to contain their name and number of
> answers correct. The assignment says to use paired arrays but the
> book doesn't go into this.


You would hold the answer keys in one table (array) and then for each
student you would put their answers in a second similar array. You
could then step through the array (PERFORM VARYING I FROM 1 BY 1 UNTIL
...) checking if the two array items were equal (IF Student-Answer(I) =
Key-Answer(I) THEN ..), if so add 1 to the accumulation ( .. ADD 1 TO
Correct-Answers)

> I am new to COBOL so please be specific(code examples).


You also seem to be new to understanding assignments.
LX-i

2004-03-29, 9:30 pm

Brent wrote:
> I am a student and am having troubles reading in two .dat files in
> order to compare them. The first file contains a student name and
> test answers ex:(John Doe ADCBAADDCC). The other file contains
> the answer key ex:(ADDBDCDCDC). I cannot figure out how to read both
> files in at the same time and how to assign a field to the correct
> information. The output file has to contain their name and number of
> answers correct. The assignment says to use paired arrays but the
> book doesn't go into this. I am new to COBOL so please be
> specific(code examples).


There are a couple of thing you can do to break this up into pieces.
First, concentrate on defining the records for the student file and the
score file. If you're not sure how to do the array thing, look up the
"Occurs" clause in your textbook or manual.

As far as reading them "at the same time", don't work about making one
Read work for 2 files - just do them one right after the other. To loop
through the arrays, investigate the "Perform" verb.

As far as code examples, you'll find folks much more willing to help
with code if we see your attempt. You learn a lot more COBOL by doing
than by reading anyway... That's the way it worked for me, anyway. :)
Hope this has helped....

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~ / \ / ~ Live from Montgomery, AL! ~
~ / \/ o ~ ~
~ / /\ - | ~ LXi0007@Netscape.net ~
~ _____ / \ | ~ http://www.knology.net/~mopsmom/daniel ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ I do not read e-mail at the above address ~
~ Please see website if you wish to contact me privately ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~

Brent

2004-04-01, 12:30 am

LX-i <lxi0007@netscape.net> wrote in message news:<106hji331h16l53@corp.supernews.com>...
> Brent wrote:
>
> There are a couple of thing you can do to break this up into pieces.
> First, concentrate on defining the records for the student file and the
> score file. If you're not sure how to do the array thing, look up the
> "Occurs" clause in your textbook or manual.
>
> As far as reading them "at the same time", don't work about making one
> Read work for 2 files - just do them one right after the other. To loop
> through the arrays, investigate the "Perform" verb.
>
> As far as code examples, you'll find folks much more willing to help
> with code if we see your attempt. You learn a lot more COBOL by doing
> than by reading anyway... That's the way it worked for me, anyway. :)
> Hope this has helped....
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
> ~ / \ / ~ Live from Montgomery, AL! ~
> ~ / \/ o ~ ~
> ~ / /\ - | ~ LXi0007@Netscape.net ~
> ~ _____ / \ | ~ http://www.knology.net/~mopsmom/daniel ~
> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
> ~ I do not read e-mail at the above address ~
> ~ Please see website if you wish to contact me privately ~
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~


OK, here is my complied code. I can read in the name and answers but
i can't figure out how to compare each individual answer with the ones
in the key(LAB5ANSW.dat").

ENVIRONMENT DIVISION.
*
INPUT-OUTPUT SECTION.
*
FILE-CONTROL.
*
SELECT CUSTMAST ASSIGN TO
"C:\Lab5\LAB5TEST.DAT"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT CUSTMAST2 ASSIGN TO
"C:\Lab5\LAB5ANSW.DAT"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT SALESRPT ASSIGN TO
"C:\Lab5\LAB5RPT.TXT"
ORGANIZATION IS LINE SEQUENTIAL.
*
DATA DIVISION.
*
FILE SECTION.
*
FD CUSTMAST.
01 FD-CUSTOMER-MASTER-RECORD PIC X(43).

FD CUSTMAST2.
01 FD-ANSWER-MASTER-RECORD PIC X(20).
*
FD SALESRPT.
01 SALES-REPORT PIC X(80).
*
WORKING-STORAGE SECTION.
01 CUSTOMER-MASTER-RECORD.
05 STUDENT-NAME PIC X(20).
05 STUDENT-GRADES PIC X(20).

01 ANSWER-MASTER-RECORD.
05 ANSWER-KEY PIC X(20).
*
01 PRINT-AREA PIC X(80).
*
01 SWITCHES.
05 CUSTMAST-EOF-SWITCH PIC X VALUE "N".
88 CUSTMAST-EOF VALUE "Y".
05 FIRST-RECORD-SWITCH PIC X VALUE "Y".
88 FIRST-RECORD VALUE "Y".
*
*01 CONTROL-FIELDS.
* 05 OLD-BRANCH-NUMBER PIC 99.
*
*01 CALCULATED-FIELDS PACKED-DECIMAL.
* 05 CHANGE-AMOUNT PIC S9(7)V99.
*
01 PRINT-FIELDS PACKED-DECIMAL.
05 PAGE-COUNT PIC S9(3) VALUE ZERO.
05 LINES-ON-PAGE PIC S9(3) VALUE +15.
05 LINE-COUNT PIC S9(3) VALUE +80.
05 SPACE-CONTROL PIC S9.
*
*
01 CURRENT-DATE-AND-TIME.
05 CD-YEAR PIC 9999.
05 CD-MONTH PIC 99.
05 CD-DAY PIC 99.
05 FILLER PIC X(9).
*
01 HEADING-LINE-1.
05 FILLER PIC X(3) VALUE SPACES.
05 FILLER PIC X(38)
VALUE "GRADE REPORT FOR CIS 231 SECTION: B ".
05 FILLER PIC X(25) VALUE SPACES.
05 FILLER PIC X(8) VALUE "PAGE ZZ9".
*
01 HEADING-LINE-2.
05 FILLER PIC X(3) VALUE SPACES.
05 FILLER PIC X(35)
VALUE "REPORT PREPARED BY: ".
05 FILLER PIC X(28) VALUE SPACES.
05 FILLER PIC X(7) VALUE "DATE: ".
05 HL1-MONTH PIC 9(2).
05 FILLER PIC X(1) VALUE "/".
05 HL1-DAY PIC 9(2).
05 FILLER PIC X(1) VALUE "/".
05 HL1-YEAR PIC 9(4).

*
01 HEADING-LINE-3.
05 FILLER PIC X(11) VALUE SPACE.
05 FILLER PIC X(23) VALUE "MIDTERM EXAM RESULTS
".
05 FILLER PIC X(47) VALUE SPACE.

01 HEADING-LINE-3A.
05 FILLER PIC X(80) VALUE SPACE.

01 HEADING-LINE-4.
05 FILLER PIC X(11) VALUE SPACE.
05 FILLER PIC X(12) VALUE "STUDENT NAME".
05 FILLER PIC X(13) VALUE SPACE.
05 FILLER PIC X(7) VALUE "CORRECT".
05 FILLER PIC X(7) VALUE SPACE.
05 FILLER PIC X(7) VALUE "PERCENT".
05 FILLER PIC X(7) VALUE SPACE.
05 FILLER PIC X(5) VALUE "GRADE".
05 FILLER PIC X(17) VALUE SPACE.

*
01 CUSTOMER-LINE.
05 FILLER PIC X(10) VALUE SPACE.
05 CL-STUDENT-NAME PIC X(20).
05 FILLER PIC X(4) VALUE SPACE.
05 CL-STUDENT-GRADES PIC X(20).
05 FILLER PIC X(16) VALUE SPACE.

*
PROCEDURE DIVISION.
*
0000-MAINLINE.
PERFORM 010-INITIALIZE.
PERFORM 300-PREPARE-SALES-LINES
UNTIL CUSTMAST-EOF.
PERFORM 099-END-OF-JOB.
GOBACK.

*
010-INITIALIZE.
OPEN INPUT CUSTMAST
INPUT CUSTMAST2
OUTPUT SALESRPT.
PERFORM 310-READ-CUSTOMER-RECORD.
PERFORM 315-READ-CUSTOMER-RECORD.
PERFORM 100-FORMAT-REPORT-HEADING.

099-END-OF-JOB.
CLOSE CUSTMAST
CUSTMAST2
SALESRPT.
*
100-FORMAT-REPORT-HEADING.
*
MOVE FUNCTION CURRENT-DATE TO CURRENT-DATE-AND-TIME.
MOVE CD-MONTH TO HL1-MONTH.
MOVE CD-DAY TO HL1-DAY.
MOVE CD-YEAR TO HL1-YEAR.
*
300-PREPARE-SALES-LINES.
EVALUATE TRUE
WHEN CUSTMAST-EOF
PERFORM 850-WRITE-REPORT-LINE
WHEN FIRST-RECORD
PERFORM 320-PRINT-CUSTOMER-LINE
MOVE "N" TO FIRST-RECORD-SWITCH
WHEN NOT FIRST-RECORD
PERFORM 320-PRINT-CUSTOMER-LINE
END-EVALUATE.
PERFORM 310-READ-CUSTOMER-RECORD.

310-READ-CUSTOMER-RECORD.
READ CUSTMAST INTO CUSTOMER-MASTER-RECORD
AT END
SET CUSTMAST-EOF TO TRUE.
*
315-READ-CUSTOMER-RECORD.
READ CUSTMAST2 INTO ANSWER-MASTER-RECORD
AT END
SET CUSTMAST-EOF TO TRUE.

320-PRINT-CUSTOMER-LINE.
IF LINE-COUNT > LINES-ON-PAGE
PERFORM 330-PRINT-HEADING-LINES.
MOVE STUDENT-NAME TO CL-STUDENT-NAME.
MOVE STUDENT-GRADES TO CL-STUDENT-GRADES.
MOVE CUSTOMER-LINE TO PRINT-AREA.
PERFORM 850-WRITE-REPORT-LINE.
MOVE 1 TO SPACE-CONTROL.
*
330-PRINT-HEADING-LINES.
*
ADD 1 TO PAGE-COUNT.
MOVE HEADING-LINE-1 TO PRINT-AREA.
PERFORM 800-WRITE-PAGE-TOP-LINE.
MOVE HEADING-LINE-2 TO PRINT-AREA.
MOVE 1 TO SPACE-CONTROL.
PERFORM 850-WRITE-REPORT-LINE.
MOVE HEADING-LINE-3 TO PRINT-AREA.
MOVE 2 TO SPACE-CONTROL.
PERFORM 850-WRITE-REPORT-LINE.
MOVE HEADING-LINE-3A TO PRINT-AREA.
MOVE 1 TO SPACE-CONTROL.
PERFORM 850-WRITE-REPORT-LINE.
MOVE HEADING-LINE-4 TO PRINT-AREA.
MOVE 1 TO SPACE-CONTROL.
PERFORM 850-WRITE-REPORT-LINE.
MOVE 2 TO SPACE-CONTROL.
*
800-WRITE-PAGE-TOP-LINE.
*
WRITE SALES-REPORT FROM PRINT-AREA
AFTER ADVANCING PAGE.
MOVE 1 TO LINE-COUNT.
*
850-WRITE-REPORT-LINE.
*
WRITE SALES-REPORT FROM PRINT-AREA
AFTER ADVANCING SPACE-CONTROL LINES.
ADD SPACE-CONTROL TO LINE-COUNT.

The file that reads the student data is "LAB5TEST"
I need the output to look like this

Name Correct
John Doe 16
Last Boy Scout

2004-04-01, 1:30 am

On 29 Mar 2004 09:32:59 -0800, brnetg@yahoo.com (Brent) wrote:

>I am a student and am having troubles reading in two .dat files in
>order to compare them. The first file contains a student name and
>test answers ex:(John Doe ADCBAADDCC). The other file contains
>the answer key ex:(ADDBDCDCDC). I cannot figure out how to read both
>files in at the same time and how to assign a field to the correct
>information. The output file has to contain their name and number of
>answers correct. The assignment says to use paired arrays but the
>book doesn't go into this. I am new to COBOL so please be
>specific(code examples).
>
>Thanks in advance


First of all you can only read one file at a time. However, in an
AS400 that is not true, because files can be logically described and
liked like a database using a Logical File Description. However, if
you are using windows or mainfram this may not be possible.

This is not rocket science. I am not sure what a paired Array is. In
COBOL we are not suppose to use the term Array. There is no such
thing in the COBOL Standard. We call a collection like an array a
Table. This means they want you to build a table structure and put
each record of the file info into it. Read, Copy, Repeat until end of
file.

If the Key is unique, then you could make a table large enough for
both files and then build the table with one file and then close that
file. After that you read the second file and then use the Search
verb to find the match in the table and just put the matching record
from the second file next to the first. You would not have to store
the key twice.

One of the files may have multiple occurrances of the same key. If
this happens put the file with the multiple occurrances in the table
first. Then you would have to copy the record data multiple times.
This requires a searching technique that searches through the entire
table. The Varying Verb is one method to do this. There are also
search techniques that allow for finding multiple occurrances using
the search verb. It is more common now to see varying. So it might
be better to learn this verb.

Do this program one step at a time. Describe both files. Read one
and put it into the Table(ARRAY). Then if that works do the second
part.

Richard

2004-04-01, 3:30 pm

brnetg@yahoo.com (Brent) wrote

[color=darkred]
> OK, here is my complied code. I can read in the name and answers but
> i can't figure out how to compare each individual answer with the ones
> in the key(LAB5ANSW.dat").


You put them into 'paired array', which is a pair (two) tables holding
the answer key (PIC X OCCURS 10) and the students answers alongside
each other and for each answer (PERFORM VARYING .. UNTIL .. ) counting
(ADD 1) which ones match (IF .. = .. ):

A D D B D C D C D C
A D C B A A D D C C
1 2 3 4 5


> ENVIRONMENT DIVISION.
> INPUT-OUTPUT SECTION.
> FILE-CONTROL.
> SELECT CUSTMAST ASSIGN TO


You have obviously copied another program that was completely
unrelated to the problem. Having 'CUSTMAST' (Customer Master) and
'SALESRPT' (Sales Report) does not help understand the probem and
disguises the solution. Taking another program and mindlessly
changing things that you recognise does not help you learn the process
of solving problems.

> 0000-MAINLINE.
> PERFORM 010-INITIALIZE.
> PERFORM 300-PREPARE-SALES-LINES
> UNTIL CUSTMAST-EOF.
> PERFORM 099-END-OF-JOB.
> GOBACK.


This is the structure that they used to teach 40 years ago. The
paragraph numbers (010- 300- 099-) really useful in finding the code
in the boxes of punched cards that was the source code deck and in the
printed lineflow listings. If you are going to do this then at least
make them useful and keep them in sequence.

To get a sensible solution you need to analyse the problem and break
it down into parts.

The probem is:

read answer key
for each student set of answers:
read stuent answer
compares answers to key
print count of correct answers

First you should be able to define the files, after all this is what
has been given in the question. Using _meaningful_ names:

ENVIRONMENT DIVISION.
FILE-CONTROL.
SELECT Answer-File
ASSIGN TO "C:\Lab5\LAB5ANSW.DAT"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT Test-File
ASSIGN TO "C:\Lab5\LAB5TEST.DAT"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT Result-File
ASSIGN TO "C:\Lab5\LAB5RPT.TXT"
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD Answer-File.
01 Answer-Record PIC X(10).

FD Test-File.
01 Test-Record.
03 Test-Name PIC X(15).
03 Test-Answers PIC X(10).

FD Result-File.
01 Result-Record.
03 Result-Name PIC X(15).
03 Result-Count PIC ZZ9.

There will need to be some working areas including the 'paired
arrays':
WORKING-STORAGE SECTION.

01 Answer-Key.
03 Correct-Answer PIC X OCCURS 10.
01 Answer-Compare.
03 Student-Answer PIC X OCCURS 10.

01 Step PIC S9(4).
01 Answers-Correct PIC S9(4).

PROCEDURE DIVISION.
Process-Students.

PERFORM Read-Answer-Key
PERFORM Process-Student-Answers
STOP RUN
Howard Brazee

2004-04-01, 4:30 pm


On 1-Apr-2004, riplin@Azonic.co.nz (Richard) wrote:

>
> This is the structure that they used to teach 40 years ago. The
> paragraph numbers (010- 300- 099-) really useful in finding the code
> in the boxes of punched cards that was the source code deck and in the
> printed lineflow listings. If you are going to do this then at least
> make them useful and keep them in sequence.


Without being as useful these days, there still can be something said for using
this type of paragraph prefix:

1. A shop can have a standard similar to this:
0000-MAIN.
PERFORM 0100-INIT.
PERFORM 1000-PROCESS-LOOP UNTIL SW-END.
PERFORM 9000-FINALE.
GOBACK.
...
7000-READ.
....
8000-WRITE.

As you imply, don't just stick a number in front - do so for a purpose. We get
some idea where particular code will be found from program to program.

I also like being able to in TSO type
F p'#' 8 prev
to find the previous paragraph name without picking up a comment.
E P Chandler

2004-04-02, 12:30 am

> > Brent wrote:

[snip]

[color=darkred]
> OK, here is my complied code. I can read in the name and answers but
> i can't figure out how to compare each individual answer with the ones
> in the key(LAB5ANSW.dat").
>
> ENVIRONMENT DIVISION.
> *
> INPUT-OUTPUT SECTION.
> *
> FILE-CONTROL.
> *
> SELECT CUSTMAST ASSIGN TO
> "C:\Lab5\LAB5TEST.DAT"
> ORGANIZATION IS LINE SEQUENTIAL.
> SELECT CUSTMAST2 ASSIGN TO
> "C:\Lab5\LAB5ANSW.DAT"
> ORGANIZATION IS LINE SEQUENTIAL.
> SELECT SALESRPT ASSIGN TO
> "C:\Lab5\LAB5RPT.TXT"
> ORGANIZATION IS LINE SEQUENTIAL.
> *
> DATA DIVISION.
> *
> FILE SECTION.
> *
> FD CUSTMAST.
> 01 FD-CUSTOMER-MASTER-RECORD PIC X(43).
>
> FD CUSTMAST2.
> 01 FD-ANSWER-MASTER-RECORD PIC X(20).
> *
> FD SALESRPT.
> 01 SALES-REPORT PIC X(80).
> *


[snip]

It would help if your variable and file names matched the domain of
the problem you are trying to solve. It would make it easier for
others to look at your program and help you. This problem has nothing
to do with updating a master file.

When posting a code sample and asking for help, pare the program down
to the minimum that does the job and exercises the actual problem.

Before writing a program, write some pseudo code, then expand it out
into actual programming statements. Yes, I do use code skeletons, but
they are the bare bones minimums that let me see what I am doing in
solving a problem.
Add the details (like report formatting, header lines, page numbers)
later.

Now that I'm done preaching, let's get to your specific problem. You
only need to read the file of correct answers *once*. Then for each
student, read the student name and answers. Total the correct answers,
and write a report line.

Instead of reading records into one field which is a fixed length
string, why not read directly into an array (table)?

For example, in your FDs use something like:

01 ANSWER-KEY.
02 KEY-ANSWER PIC X OCCURS 20 TIMES.

01 STUDENT-RECORD.
02 STUDENT-NAME PIC X(20).
02 STUDENT-ANSWERS.
04 STUDENT-ANSWER PIC X OCCURS 20 TIMES.

Then just compare STUDENT-ANSWER(index-variable) to
KEY-ANSWER(index-variable).
LX-i

2004-04-02, 11:30 am

Brent wrote:
> OK, here is my complied code. I can read in the name and answers but
> i can't figure out how to compare each individual answer with the ones
> in the key(LAB5ANSW.dat").


I concur with Richard's evaluation - naming files meaningful things
really helps keep things straight in your mind. In fact, it may be this
that has caused some of the problems you're having.

That aside, if your instructor has told you to prefix your paragraph
names with numbers, go ahead and do that - you wouldn't want to fail
just out of style. However, as Richard said, there is no requirement
within COBOL to make that so.

(As it happens, the shop in which I'm currently working has a standard
of prefixing numbers of at least three digits in all main program
paragraphs - so, you may not get away from that. I'll stay out of the
"which is better" debate - but, suffice it to say, if you do use
numbers, try to group them logically and make sure they're always in
sequence. It makes things a lot easier for the next person who comes
behind you.)

Richard gave you enough information to complete this particular
assignment, but I encourage you to take his solution and look into it -
if you don't understand what a particular line or section of code does,
look up those verbs in your textbook or compiler language reference
manual (LRM). If you're still , ask - we here in this newsgroup
don't mind explaining things if we can sense that the person asking is
trying too. :)


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~ / \ / ~ Live from Montgomery, AL! ~
~ / \/ o ~ ~
~ / /\ - | ~ LXi0007@Netscape.net ~
~ _____ / \ | ~ http://www.knology.net/~mopsmom/daniel ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ I do not read e-mail at the above address ~
~ Please see website if you wish to contact me privately ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~

Robert Jones

2004-04-02, 6:30 pm

Hello Brent,

I am glad to see that you have made a start, however there are as
might be expected some faults, at least some of which I shall comment
on in the text. Overall it is quite a tidy program, obviously
cannibalised from an earlier exercise. Such cloning is commendable,
but for clarity and general comprehension it is desirable to ensure
that your new data and procedure names are relevant to the function of
the current program.

brnetg@yahoo.com (Brent) wrote in message news:<ad38a8cd.0403312029.3bda3f37@posting.google.com>...
> LX-i <lxi0007@netscape.net> wrote in message news:<106hji331h16l53@corp.supernews.com>...
>
> OK, here is my complied code. I can read in the name and answers but
> i can't figure out how to compare each individual answer with the ones
> in the key(LAB5ANSW.dat").
>
> ENVIRONMENT DIVISION.
> *
> INPUT-OUTPUT SECTION.
> *
> FILE-CONTROL.
> *
> SELECT CUSTMAST ASSIGN TO
> "C:\Lab5\LAB5TEST.DAT"
> ORGANIZATION IS LINE SEQUENTIAL.
> SELECT CUSTMAST2 ASSIGN TO
> "C:\Lab5\LAB5ANSW.DAT"
> ORGANIZATION IS LINE SEQUENTIAL.
> SELECT SALESRPT ASSIGN TO
> "C:\Lab5\LAB5RPT.TXT"
> ORGANIZATION IS LINE SEQUENTIAL.
> *
> DATA DIVISION.
> *
> FILE SECTION.
> *
> FD CUSTMAST.
> 01 FD-CUSTOMER-MASTER-RECORD PIC X(43).
>
> FD CUSTMAST2.
> 01 FD-ANSWER-MASTER-RECORD PIC X(20).
> *
> FD SALESRPT.
> 01 SALES-REPORT PIC X(80).
> *
> WORKING-STORAGE SECTION.
> 01 CUSTOMER-MASTER-RECORD.
> 05 STUDENT-NAME PIC X(20).
> 05 STUDENT-GRADES PIC X(20).
>

define STUDENT-GRADES as a table (aka array) e.g.

05 STUDENT-GRADES PIC X OCCURS 20.

> 01 ANSWER-MASTER-RECORD.
> 05 ANSWER-KEY PIC X(20).


define the answers as a table similar to student grades e.g.

05 ANSWER-DETAIL PIC X OCCURS 20.

For comprehension, it is preferable not to use the term KEY as part of
a data name unless it is a file key or table key or some other case
where the term is appropriate.
> *
> 01 PRINT-AREA PIC X(80).
> *
> 01 SWITCHES.
> 05 CUSTMAST-EOF-SWITCH PIC X VALUE "N".
> 88 CUSTMAST-EOF VALUE "Y".
> 05 FIRST-RECORD-SWITCH PIC X VALUE "Y".
> 88 FIRST-RECORD VALUE "Y".
> *
> *01 CONTROL-FIELDS.
> * 05 OLD-BRANCH-NUMBER PIC 99.
> *
> *01 CALCULATED-FIELDS PACKED-DECIMAL.
> * 05 CHANGE-AMOUNT PIC S9(7)V99.


reinstate the group item "CALCULATED-FIELDS but instead of
CHANGE-AMOUNt use a meaningful data name such as "CORRECT ANSWERS"
with a PIC S999.
> *
> 01 PRINT-FIELDS PACKED-DECIMAL.
> 05 PAGE-COUNT PIC S9(3) VALUE ZERO.
> 05 LINES-ON-PAGE PIC S9(3) VALUE +15.
> 05 LINE-COUNT PIC S9(3) VALUE +80.
> 05 SPACE-CONTROL PIC S9.


A more reasonable value for LINES-ON-PAGE would be 50>60
> *
> *
> 01 CURRENT-DATE-AND-TIME.
> 05 CD-YEAR PIC 9999.
> 05 CD-MONTH PIC 99.
> 05 CD-DAY PIC 99.
> 05 FILLER PIC X(9).
> *
> 01 HEADING-LINE-1.
> 05 FILLER PIC X(3) VALUE SPACES.
> 05 FILLER PIC X(38)
> VALUE "GRADE REPORT FOR CIS 231 SECTION: B ".
> 05 FILLER PIC X(25) VALUE SPACES.
> 05 FILLER PIC X(8) VALUE "PAGE ZZ9".
> *
> 01 HEADING-LINE-2.
> 05 FILLER PIC X(3) VALUE SPACES.
> 05 FILLER PIC X(35)
> VALUE "REPORT PREPARED BY: ".
> 05 FILLER PIC X(28) VALUE SPACES.
> 05 FILLER PIC X(7) VALUE "DATE: ".
> 05 HL1-MONTH PIC 9(2).
> 05 FILLER PIC X(1) VALUE "/".
> 05 HL1-DAY PIC 9(2).
> 05 FILLER PIC X(1) VALUE "/".
> 05 HL1-YEAR PIC 9(4).
>
> *
> 01 HEADING-LINE-3.
> 05 FILLER PIC X(11) VALUE SPACE.
> 05 FILLER PIC X(23) VALUE "MIDTERM EXAM RESULTS
> ".
> 05 FILLER PIC X(47) VALUE SPACE.
>
> 01 HEADING-LINE-3A.
> 05 FILLER PIC X(80) VALUE SPACE.
>
> 01 HEADING-LINE-4.
> 05 FILLER PIC X(11) VALUE SPACE.
> 05 FILLER PIC X(12) VALUE "STUDENT NAME".
> 05 FILLER PIC X(13) VALUE SPACE.
> 05 FILLER PIC X(7) VALUE "CORRECT".
> 05 FILLER PIC X(7) VALUE SPACE.
> 05 FILLER PIC X(7) VALUE "PERCENT".
> 05 FILLER PIC X(7) VALUE SPACE.
> 05 FILLER PIC X(5) VALUE "GRADE".
> 05 FILLER PIC X(17) VALUE SPACE.
>
> *
> 01 CUSTOMER-LINE.
> 05 FILLER PIC X(10) VALUE SPACE.
> 05 CL-STUDENT-NAME PIC X(20).
> 05 FILLER PIC X(4) VALUE SPACE.
> 05 CL-STUDENT-GRADES PIC X(20).


replace the Picture for CL-STUDENT-GRADES with a usage display numeric
picture.
large enough to contain the value from CORRECT-ANSWERS.

> 05 FILLER PIC X(16) VALUE SPACE.
>
> *
> PROCEDURE DIVISION.
> *
> 0000-MAINLINE.
> PERFORM 010-INITIALIZE.
> PERFORM 300-PREPARE-SALES-LINES
> UNTIL CUSTMAST-EOF.
> PERFORM 099-END-OF-JOB.
> GOBACK.
>
> *
> 010-INITIALIZE.
> OPEN INPUT CUSTMAST
> INPUT CUSTMAST2
> OUTPUT SALESRPT.
> PERFORM 310-READ-CUSTOMER-RECORD.
> PERFORM 315-READ-CUSTOMER-RECORD.
> PERFORM 100-FORMAT-REPORT-HEADING.
>
> 099-END-OF-JOB.
> CLOSE CUSTMAST
> CUSTMAST2
> SALESRPT.
> *
> 100-FORMAT-REPORT-HEADING.
> *
> MOVE FUNCTION CURRENT-DATE TO CURRENT-DATE-AND-TIME.
> MOVE CD-MONTH TO HL1-MONTH.
> MOVE CD-DAY TO HL1-DAY.
> MOVE CD-YEAR TO HL1-YEAR.
> *
> 300-PREPARE-SALES-LINES.
> EVALUATE TRUE
> WHEN CUSTMAST-EOF
> PERFORM 850-WRITE-REPORT-LINE
> WHEN FIRST-RECORD
> PERFORM 320-PRINT-CUSTOMER-LINE
> MOVE "N" TO FIRST-RECORD-SWITCH
> WHEN NOT FIRST-RECORD
> PERFORM 320-PRINT-CUSTOMER-LINE
> END-EVALUATE.


It is always a good idea to have the scope terminator of a statement,
in this case END-EVALUATE in the same column as its statement. In
this program, the EVALUATE is unnecessary. Instead you need a perform
statement that cycles through the current student record's answers
checking them against the corresponding correct answers to tally the
number of correct answers in CORRECT-ANSWERS.

> PERFORM 310-READ-CUSTOMER-RECORD.
>
> 310-READ-CUSTOMER-RECORD.
> READ CUSTMAST INTO CUSTOMER-MASTER-RECORD
> AT END
> SET CUSTMAST-EOF TO TRUE.
> *
> 315-READ-CUSTOMER-RECORD.
> READ CUSTMAST2 INTO ANSWER-MASTER-RECORD
> AT END
> SET CUSTMAST-EOF TO TRUE.
>
> 320-PRINT-CUSTOMER-LINE.
> IF LINE-COUNT > LINES-ON-PAGE
> PERFORM 330-PRINT-HEADING-LINES.
> MOVE STUDENT-NAME TO CL-STUDENT-NAME.
> MOVE STUDENT-GRADES TO CL-STUDENT-GRADES.


Instead of STUDENT-GRADES move CORRECT-ANSWERS

> MOVE CUSTOMER-LINE TO PRINT-AREA.
> PERFORM 850-WRITE-REPORT-LINE.
> MOVE 1 TO SPACE-CONTROL.
> *
> 330-PRINT-HEADING-LINES.
> *
> ADD 1 TO PAGE-COUNT.
> MOVE HEADING-LINE-1 TO PRINT-AREA.
> PERFORM 800-WRITE-PAGE-TOP-LINE.
> MOVE HEADING-LINE-2 TO PRINT-AREA.
> MOVE 1 TO SPACE-CONTROL.
> PERFORM 850-WRITE-REPORT-LINE.
> MOVE HEADING-LINE-3 TO PRINT-AREA.
> MOVE 2 TO SPACE-CONTROL.
> PERFORM 850-WRITE-REPORT-LINE.
> MOVE HEADING-LINE-3A TO PRINT-AREA.
> MOVE 1 TO SPACE-CONTROL.
> PERFORM 850-WRITE-REPORT-LINE.
> MOVE HEADING-LINE-4 TO PRINT-AREA.
> MOVE 1 TO SPACE-CONTROL.
> PERFORM 850-WRITE-REPORT-LINE.
> MOVE 2 TO SPACE-CONTROL.
> *
> 800-WRITE-PAGE-TOP-LINE.
> *
> WRITE SALES-REPORT FROM PRINT-AREA
> AFTER ADVANCING PAGE.
> MOVE 1 TO LINE-COUNT.
> *
> 850-WRITE-REPORT-LINE.
> *
> WRITE SALES-REPORT FROM PRINT-AREA
> AFTER ADVANCING SPACE-CONTROL LINES.
> ADD SPACE-CONTROL TO LINE-COUNT.
>
> The file that reads the student data is "LAB5TEST"
> I need the output to look like this
>
> Name Correct
> John Doe 16


Good luck, Robert
Richard

2004-04-02, 9:30 pm

"Howard Brazee" <howard@brazee.net> wrote

[color=darkred]
> I also like being able to in TSO type
> F p'#' 8 prev
> to find the previous paragraph name without picking up a comment.


Given that TSO is only marginally more recent technology than card
packs, then yes, paragraph numbering may well be useful there too
;-)

>1. A shop can have a standard similar to this:
> 0000-MAIN.
> PERFORM 0100-INIT.
> PERFORM 1000-PROCESS-LOOP UNTIL SW-END.
> PERFORM 9000-FINALE.
> GOBACK.
> ...
> 7000-READ.
>...
> 8000-WRITE.


Granted, if you are rewriting the same program over and over again, as
batch systems tend to be, then it makes sense to have the same
paragraphs names they have had for the last 40 years.

In general the number is used like a page number in the lineflow
listing. Finding a '3201-name' one knows whether to flick the pages
forwards or backwards.

For the last 20 years I have used editors that I just put the cursor
over the name and hit a key and it goes to that point without me
knowing or caring where it might be in a printed listing.

To me, the idea that paragraphs must be in some hierarchical
structural _and_ logical order, and must be coded as such, destroys
the concept of reusability and imposes constraints on structural
decomposition that is entirely unrequired.

Paragraph numbering is, after all, a solution to problems that existed
40 years ago, and was appropriate to the types of programs written
then. My programs do not work in such a simplistic manner that a
hierarchy represents. It is the user that chooses which part of the
code is to run at any particular time, numbering schemes make no sense
and do nothing for finding or understanding.
Brent

2004-04-06, 11:30 am

Last Boy Scout <LastBoyScout@whitehouse.gov> wrote in message news:<hr9n605vnpojd1ebhn89878bqn0fv3giio@4ax.com>...
> On 29 Mar 2004 09:32:59 -0800, brnetg@yahoo.com (Brent) wrote:
>
>
> First of all you can only read one file at a time. However, in an
> AS400 that is not true, because files can be logically described and
> liked like a database using a Logical File Description. However, if
> you are using windows or mainfram this may not be possible.
>
> This is not rocket science. I am not sure what a paired Array is. In
> COBOL we are not suppose to use the term Array. There is no such
> thing in the COBOL Standard. We call a collection like an array a
> Table. This means they want you to build a table structure and put
> each record of the file info into it. Read, Copy, Repeat until end of
> file.
>
> If the Key is unique, then you could make a table large enough for
> both files and then build the table with one file and then close that
> file. After that you read the second file and then use the Search
> verb to find the match in the table and just put the matching record
> from the second file next to the first. You would not have to store
> the key twice.
>
> One of the files may have multiple occurrances of the same key. If
> this happens put the file with the multiple occurrances in the table
> first. Then you would have to copy the record data multiple times.
> This requires a searching technique that searches through the entire
> table. The Varying Verb is one method to do this. There are also
> search techniques that allow for finding multiple occurrances using
> the search verb. It is more common now to see varying. So it might
> be better to learn this verb.
>
> Do this program one step at a time. Describe both files. Read one
> and put it into the Table(ARRAY). Then if that works do the second
> part.


I have got it all figured out! Thanks to all the helped
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com