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!

Perform Varying for a three-level table.

Status
Not open for further replies.

shellshell

Technical User
Apr 8, 2001
4
US
I am stuck on instructions for a program I was given minimal specs for. Here is the info I was give:

"Write the COBOL instructions to update the employee hours and earnings table. The hours and earnings have been calculated and are contained in the fields cal-hours and cal-erngs.

This table will contain information for 100 employees. Each employee will have been able to work in up to 25 departments.
Each department will allow for 5 jobs.

All fields in the table have been initialized to spaces and zeros.

01 HRSERN-TBL.
05 HRSERN-IT1 OCCURS 100 TIMES.
10 HRSERN-EMP PICTURE X(4).
10 HRSERN-IT2 OCCURS 25 TIMES.
15 HRSERN-DEP PICTURE XX.
15 HRSERN-IT3 OCCURS 5 TIMES.
20 HRSERN-JOB PICTURE XX.
20 HRSERN-HRS PICTURE 9(4)V99.
20 HRSERN-ERN PICTURE 9(6)V99.

Listed below are some additional fields that may be used in your instructions. some of these you may not use and feel free to add any of your own.

01 HRSERN-SB1 PICTURE 9(4).
01 HRSERN-SB2 PICTURE 9(4).
01 HRSERN-SB3 PICTURE 9(4).
01 HRSERN-SB4 PICTURE 9(4).

01 CAL-HOURS PICTURE 9(4)V99.
01 CAL-ERNGS PICTURE 9(6)V99.

01 INP-EMP-ID PICTURE X(4).
01 INP-DEP-ID PICTURE XX.
01 INP-JOB-ID PICTURE XX.

01 PERFORM-DN1 PICTURE X.
01 PERF0RM-DN2 PICTURE X.
01 PERFORM-DN3 PICTURE X.
01 PERFORM-DN4 PICTURE X. "


I am concerned with the read I have started, not sure if I should have the priming read, and then a Read routine or not. Then I am also confused with the three-level table with the Perform Varying statements. I am not quite sure I am thinking this through correctly. Here is what I have so far.

FD EMPLOYEE-ERNGS-FILE
RECORD CONTAINS 18 CHARACTERS
DATA RECORD IS EMPLOYEE-ERNGS-RECORD.
01 EMPLOYEE-ERNGS-RECORD.
05 INP-EMP-ID PICTURE X(4).
05 INP-DEP-ID PICTURE XX.
05 INP-JOB-ID PICTURE XX.
05 CAL-HOURS PICTURE 9(4)V99.
05 CAL-ERNGS PICTURE 9(6)V99.

01 SWITCHES-AND-COUNTERS.
05 EOF-SWITCH PICTURE X VALUE 'N'
05 EMP-COUNT PICTURE 9(3).
05 DEPT-COUNT PICTURE 9(3).
05 JOB-COUNT PICTURE 9(3).

(Just wanted to give you the file coming in. I'm not really running a report, yet, so I haven't set up the detail fields or anything yet.)

PROCEDURE DIVISION.
100-MAIN.
OPEN INPUT EMPLOYEE-ERNGS-FILE
OUTPUT (????NOT SURE ABOUT THIS YET)
PERFORM UNTIL EOF-SWITCH = 'Y'
READ EMPLOYEE-ERNGS-FILE
AT END
MOVE 'Y' TO EOF-SWITCH
NOT AT END
PERFORM 200-PROCESS-HOURS-AND-EARNINGS
END PERFORM.
PERFORM 220-UPDATE-CURRENT-TABLE.
CLOSE EMPLOYEE-ERNGS-FILE
(??? --- ???).
STOP RUN.

200-PROCESS-HOURS-AND-EARNINGS.
PERFORM 300-EMP-ID-RTN
VARYING HRSERN-SB1 FROM 1 BY 1
UNTIL HRSERN-SB1 > 100
END PERFORM.
IF HRSERN-SB1 > 100
MOVE 'Y' TO EOF-SWITCH
END-IF.

300-EMP-ID-RTN.
IF INP-EMP-ID NOT = WS-EMP-ID
INITIALIZE WS-EMP-ID
MOVE INP-EMP-ID TO WS-EMP-ID
ADD 1 TO EMP-COUNT
PERFORM 400-DEPT-RTN
VARYING HRSERN-SB2 FROM 1 BY 1
UNTIL HRSERN-SB2 > 25
IF HRSERN-SB2 > 25
MOVE 'Y' TO PERFORM-DN1
END-IF
END PERFORM
END-IF.

400-DEPT-RTN.
IF INP-DEPT-ID NOT = WS-DEPT-ID
INITIALIZE WS-DEPT-ID
MOVE INP-DEPT-ID TO WS-DEPT-ID
ADD 1 TO WS-DEPT-ID
PERFORM 500-JOB-RTN
VARYING HRSERN-SB3 FROM 1 BY 1
UNTIL HRSERN-SB3 > 5
IF HRSERN-SB3 > 5
MOVE 'Y' TO PERFORM-DN2
END-IF
END PERFORM
END-IF.

500-JOB-RTN.
IF INP-JOB-ID NOT = WS-JOB-ID
INITIALIZE WS-JOB-ID
MOVE INP-JOB-ID TO WS-JOB-ID
ADD 1 TO JOB-COUNT
PERFORM 600-CALCULATE-NEW-ERNGS

Ok this is where I am stuck. First of all if I have one employee working in more than one dept. or more than one job I need to make sure that the earnings are getting to the correct dept. and job. I don't know how I am going to keep that tracked to hold the dept. id and the job id to calculate the earnings. Does it sound like I need to be calculating the earnings per employee, department, and job? This is why I haven't designed any report fields yet.
Also, am I even doing the Perform Varying correct? Do I want to check for > 25 for HRSERN-SB2 and > 5 for HRSERN-SB3, or should I be setting a different flag? I set the PERFORM-DN#, but I don't know where to take it after that. Do I need a priming READ, and then a READ-EMPLOYEE-ERNGS-RECORD routine as well? Please, if anyone can offer any help and/or suggestions it would greatly appreciated. I don't have much time left on this and have struggled for awhile with it.

Thank you in advance,
shellshell


 
Hi Shell,

I see a few coding errors in your pgm, but I think we're getting ahead of ourselves.

The good news is that you've given some thought to the problem, the bad news is I don't think you understand how the table will look in memory. If you'll allow me, I'd like to get you to think about that, for example:

emp1....emp2....empn....emp100

What will the "...." look like between emp1 & emp2? Don't worry about the lengths of the fields, just their names. Lay it out the way I have. Just show the first few iterations of each level.

Thinking about this will give you insight into how to code your loops. Let us see what you come up with.

Thanx, Jack

 
Hi,

Thanks for responding.

To tell you the truth, I have looked and looked at this and I don't know how it is going to look. I don't know how to set up a table that looks backwards to me. I have reviewed my book and it looks like this table is not set up properly. I'm thinking that I should be starting with Dept, then Job, and then Employee, but my instructor set up the table? I'm having difficulty picturing it the way he laid it out. I don't I like the way he named the table. How can I start with 100, go to 25, and then to 5. Isn't that backwards?

Maybe it's just me.

Shellshell
 
Hi Shell,

I hope you'll forgive me for not giving you the answer outright, but I just think you'll get more out of the experience this way.

Here's an example I've used before:

Suppose you're my assistant and your sole duty is to go to the bookcase and give me the bookshelf#, the name of the book and the title of any chapter I ask for. The bookcase has 10 shelves; each shelf contains 25 books; and each book contains 5 chapters.

I tell you the bookshelf#, the book#, and the chapter# I want. What do you do to get it for me?

Now, this goes on for months and you're getting tired of jumping up and getting me the info every time I ask. So the thought hits you: if you could draw a diagram of the bookshelf: shelves in the bkslf, the books(names) in the shelves, the chapters (titles) in the books, you could sit in your easychair and give me the info I want without moving a muscle.

How would that diagram look? Give it some thought.

Thanx, Jack.
 
I think I figured it out - I was getting lost in the route to the correct location to total the hours and earnings. I think the key to this (after looking and analyzing the question you asked) is with nested IF statements.

HRSERN TABLE
____________________________________________________________
EMP(1) EMP(2) EMP(...) EMP(100)
____________________________________________________________
DPT(1)..DPT(25) and so on through each EMP.................
____________________________________________________________
J(1)...J(5) and so on through each EMP\DPT................
____________________________________________________________
9999.99 (updated hours)
99999.99 (updated earnings)
____________________________________________________________

I know that this doesn't look real pretty, but when I created it, it looked much better.

What I am going to do from that point is to calculate the updated hours and the updated earnings using the rolling totals method. I think with all of this discovery I can now figure out what I want the report to look like and create the rest of my WS-Fields and TOTAL fields.

If you have any other suggestions or think that I am still not understanding it correctly, please feel free to let me know. Your help is greatly appreciated, as well as your "not giving me the answer right out".

Thank you,
Shellshell
 
Hi Shell,

By Jove, I think you've got it! :) You mentioned nested IFs; have you studied SEARCH stmts/subscripts yet? If so give them some thought. Keep me posted and good luck.

Jack
 
Hi Jack,

I have studied on Search statments, but not much. I know that I use Search or Search All statments with Indexed files. I'm not sure if I know how to do this correctly. The other option I have looked at is the CASE OF statement.

Do you recommend the Search statement? I know the nested IF statements can get pretty messy and hard to follow when working with this level of tables. I will look into it some more though.

Thank you for all of your help!!!
Shell
 
Hi Shell,

It looks like you won't be needing the SEARCH stmt but you'll need to know how subscripts (or indexes) work.

Now, back to our "bookcase" scenerio. What you didn't know, was that all the while you were delivering those books to me opened at the proper chapter, I was tearing out the page and keeping it. Now I tell you to put one of these pages back into the book it came from. You ask, "How do I know which book it came from?" I say "Oh" and hand you this:

CHAPT(3,15,2)

What do you think it means? How does it relate to your class problem?

Regards, Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top