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

compare an unknown number of counters

Status
Not open for further replies.

RubyL

Programmer
Apr 28, 2001
14
0
0
US
I am doing my senior project which is to assign advisors
automatically when a new student logs in. When I knew how many advisors there were I could just compare each advisor counter to that number of counters in working storage. Now
I have to allow them to add new advisors, so I'm lost because i will not know how many counters to compare. I tried to do a sort on counter but when I move the advisor-name I keep getting the same name. The adv-rec is:
advisor-code, advisor-name, counter, phone, e-mail. I was trying to sort on counter and move the advisor-name of the counter with the smallest number. Heeelp please. I am running out of time.
 
Hi Ruby,

Sorry, but you lost me with the "counter". I'm not sure of how you're using it. Do you have the original problem statement? Why don't you post that and the code you've already written. Sometimes a minor correction to the code is all that's needed.

Regards, Jack.
 
Hi Jack,
Thank you for responding, I hope you can help me


I am doing an interactive assign advisor program and have everthing working except this. Before I knew exactly how many advisor i had and was just reading next record and comparing the amount of students in the adv-rec counter with a corresponding working-storage counter. Now that they can add advisors I haven't been able to think of a way that students can be assigned automatically to counselors without loading up one couselor. That's why I thought maybe a sort would work and I could just assign a counselor and add 1 to his counter to keep the proper number of students per counselor.


select advisor-file assign to "tds23502.e"
organization is indexed
access mode is dynamic
record code is advisor-code.
select sorted-advisor-file
assign to "works".
select sort-file assign to "sortworks"

data division.
file section.
fd advisor-file
record contains 51 characters
label records are standard
data-record is adv-rec.
01 adv-rec.
05 advisor-code pic 99.
05 advisor-name pic x920).
05 counter pic 9(3).
05 phone pic x(8).
05 e-mail pic x(18).
fd sorted-advisor-file.
01 sorted advisor-record.
sd sort-file.
01 sort-record.
05 filler pic x(2).
05 sr-Advidor-name pic x(20).
05 sr-counter pic 9(3).
05 filler pic x(26).






061-asts.
sort sort-file
on ascending key sr-counter
using advisor-file
output procedure 200-assign-advisor
stop run.

200-assign-advisor
open output sorted-advisor-file
perform until eof-rr = "yes"
return sort-file.
move advisor-name to advisor-name-sc.
display advisor name at 0925.

my counters for the adv-rec are 88 levels of counter.
I have one counter for each advisor. I also have counters in working-storage section (1) to match each of the counters in the adv-rec. When I rewrite adv-rec I add 1 to counter and also add 1 to the corresponding counter in the working storage.
I am using an indexed file, just tried using the sort as ouput procedure. No matter what I do it will only give me the same name.

 
Hi Beth,

Before I get to your problem. Are you cut & pasting the code into your post or typing it directly? The reason I ask is that I saw a typo in your code ( pic x920) s/b x(20) ). Have you tried C&P?

Back to your problem:

Here's what I think I heard or it's what I inferred anyway. The student info is inputed via a terminal. The pgm is to assign the advisor with the smallest workload, indicated by the counter. The counter holds the # of students he's currently advising. The advisor info is stored in an indexed file retrievable thru the advisor-code as index.

Do you have any say about the design of the indexed file? If you don't, you probably want to build a table in pgm memory to store the advisor info. You would do that when the user 1st calls the pgm and never again; as a one time event and less than 100 recs it's a workable approach. Since the table is in advisor-code order, you can use a binary search to find the advisor with the least students. Use ODO to construct the table; this limits the search to the # of recs in the file, i.e. the # of entries in the table.

Hope this helps, Jack.
 
Jack , I was typing directly. Yes, ican dessign the index file any way i would like and i am open to any suggestions. I am unfamiliar with the term ODO. I will try the table in the meantime.
Ruby
 
Hi Ruby,

I'm assuming my take on your problem is correct. On second thought, I think the table solution is what your prof is looking for. What I had in mind may be a solution for another day.

The ODO ref means "occurs depending on"; are you familiar with this? It may help if you let me know the last few concepts you've studied.

Regards, Jack.
 
Hi Jack,
The last concepts we studied in Cobol II were screens and interactivity, I think we did one table in Cobol I and none in Cobol II. I'm not familiar with but I will look it up in one of books. Any further help will truly be appreciated.

Thanks,
Ruby
 
Jack, this is how I am creating the index file right now.




ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT ADVISOR-FILE
ASSIGN TO "TDS23502.E"
ORGANIZATION IS INDEXED
ACCESS MODE IS RANDOM
RECORD KEY IS ADVISOR-CODE.

FD ADVISOR-FILE
RECORD CONTAINS 51 CHARACTERS.
01 ADV-REC.
05 ADVISOR-CODE PIC 99.
05 ADVISOR-NAME PIC X(20).
05 COUNTER PIC 9(3).
05 PHONE PIC X(8).
05 E-MAIL PIC X(18).
WORKING-STORAGE SECTION.
01 ADVISOR-TEXT.
05 FILLER PIC X(51) VALUE
"01ALBERT EINSTIEN 001868-5555rrando3379@aol.com".
05 FILLER PIC X(51) VALUE
"11MARY SMITH 002868-4444rrando3378@aol.com".
05 FILLER PIC X(51) VALUE
"17JOHN SMITH 003868-3333rrando3376@aol.com".
05 FILLER PIC X(51) VALUE
"26ROBERT DEAN 003868-2222rrando3377@aol.com".
05 FILLER PIC X(51) VALUE
"30FRANK ADAMS 003868-1111rrando3375@aol.com".
05 FILLER PIC X(51) VALUE
"32JOHN MORRISON 002868-6666rrando3374@aol.com".
01 INTIALVALUEARRAY REDEFINES ADVISOR-TEXT.
05 VALUEARRAY PIC X(51) OCCURS 6 TIMES.
77 I PIC 9(2).
77 ADVISORFILESTATUS PIC XX VALUE "00".
PROCEDURE DIVISION.
MAINLINE.
OPEN OUTPUT ADVISOR-FILE.
IF ADVISORFILESTATUS IS NOT EQUAL TO "00"
DISPLAY "OPEN FAILED:" ADVISORFILESTATUS
STOP RUN
END-IF.
PERFORM VARYING I FROM 1 BY 1
UNTIL I IS GREATER THAN 6
MOVE VALUEARRAY(I) TO ADV-REC
WRITE ADV-REC
INVALID KEY
DISPLAY "INVALID KEY ERROR" ADVISORFILESTATUS
END-WRITE
END-PERFORM
CLOSE ADVISOR-FILE.
STOP RUN.
Ruby
 
Hi Ruby,

We discussed the table method for solving the problem. Since you can define your table, you can do this:

Order the table in memory by counter then adv-code, i.e.

Code:
00101etc.  
00211 "
00232 "
00317 "
00326 "
00330 "

Do you know what a START command is?
Have you read about READ NEXT?
If you have, can you see where I'm going with this?

OK, that was method #2, here's a hint for method #3:

Have you learned about alternate indexes? If you have let me know and I'll explain this approach.

I hope you're not offended by my acting like a "teacher", it's just that I feel uncomfortable with just "giving" the answer.

Regards, Jack.
 
Hi Jack,
No I'm not offended at all, I understand. I'm just so glad you are willing to take the time to help. I'm familiar with the start command, the read next and I know about alternate indexes. I will arrange the table in this order, and look forward to method #3.
Thanks
Ruby
 
Hi Ruby,

OK, #3 - alt indexes. If you do a START ALT-IDX > 0 then READ NEXT, you'll always get the (an) advisor with the lowest (one of the lowest) workload (s) in the file. In real life there may be performance considerations to this approach, but not here.

There are also some planning and coding pitfalls with this approach, but, ahh, that's half the fun. So, you've got a decision to make; let me know what you decide or if you have any ques.

Regards, Jack.
 
Sorry Ruby,

I forgot one important fact & gave you misleading syntax. The COUNT field in the adv-rec s/b your alt-index and it should be defined WITH DUPLICATES. Move 0 to COUNTER, then START ADV-FILE KEY >= COUNTER. Remember when you rewrite the rec after updating the COUNT field you're changing the KEY ref.

Jack
 
Hi Jack,
Sorry it took me so long to respond, but work and school happened in between. I did exactly what you said in method three and it works like a charm. i don't know how to thank you. I have another question on the same topic, the way I
am defining my index file with the array do I have to change that or does it just initialize those 6 when it creates the index file.

Ruby
 
Hi Ruby,

Just a reality check to affirm we're still one the same page:

You have two pgms; one that creates the indexed file (that's the pgm code you posted); the other is the on-line update pgm (that's the pgm snippet you posted).

I'll proceed on that assumption; you can correct me if I'm wrong.

The way you use the array in your "file create" pgm doesn't change. In your update pgm, because you can always ref the lowest use rec, you don't need an array. You just read the lowest rec, assign the adv to the student, bump the adv count by 1 and DIRECTly rewrite the rec.

If I didn't understand your ques or you have any others, you know where I live.

Regards, Jack.
 
Hi Jack,
Okay that answers my question. I think I'll be okay. I demo
Monday. I'll let you know how it goes. Thank you so much.
Ruby
 
Good Luck, ruby, but you won't need it; you put a lot of effort into it.

Regards, Jack.
 
Hi Jack,
Just wanted to let you know that the demo went smooth as silk yesterday. Now trying to catch up on my VB.
Thank you so much.

Ruby
 
Hi Ruby,

CONGRATULATIONS!!!!!!

Good luck in your studies, Jack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top