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!

tables-arrays

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I want a already sorted file to load into a table (of 300 records or so)that I can tell it to display 20 records at a time on the screen and then if there are more than 20 records to continue and display the next 20 records and so on. I do need help, I have never done this before.

select sort-name-file
assign to disk
????
???

I created my fd

FD in the file section

fd sort-name-file
01 name-rec
03 lastname-1 pic x(30).
03 firstname-1 pic x(10).
03 lastname-2 pic x(30).
03 firstname-2 pic x(10).
03 ssn pic 9(09).

in working storage
01 sort-idx pic 9(03).

01 table-name-sort records occurs 300
indexed by sort-index
03 table-lastname-1 pic x(30)
03 lastname-1 pic x(30).
03 firstname-1 pic x(10).
03 lastname-2 pic x(30).
03 firstname-2 pic x(10).
03 ssn pic 9(09).

procedure division

set sort-index to 1.
perform display sort-fields
varying 1 by 1
until sort-idx = 20.

read input-file into table-name-sort
at end
display table-name-sort.

move firstname-1 to table-firstname-1.
lastname-1 to table-lastname-1.
firstname-2 to table-firstname-2.
lastname-2 to table-lastname-2.
ssn to table-ssn.

I am confused with the microfocus books and I am not sure what else needs to be done????
 
If you are going to have several elements in each table you may want to add an extra step to make it easier to code.

1. Move spaces to display set.

2. Move the elements for each table to a working storage line( Name SSN etc.), and add the space elements in between!

2. Move the entire group as a single group move to a table.
move display-set to info-table (sub).

When you unload the table the information will be preformatted. So you dont have to move each element one at a time to the screen, and add spaces. You just say display info-table (sub).

01 Display-set.
05 filler pic x(02) value spaces.
05 D-name pic x(25).
05 filler pic x(02) value spaces.
05 d-ssn pic xxxbxxbxxxx. (you can add dashes)


01 Display-info.
05 info-table occurs 300 times pic x(35).

You read the file just as if you were printing it with no page numbers or headings. Instead of writing a print line, you just move it to the table one record at a time. Of course you have to select the information you want, and move it to the table. You use a counter (sub) to move it to the table. "Move Display-Set to info-table (sub)". Then you just add 1 to sub. When you get to the end-of-file you are done loading the table.

Unloading will be trickier. You have to know when you reach the last element in the table, or if the table has spaces, which would indicate you didnt load the maximum amount in the table. You have to design some kind of loop that looks for the table-max (300?) so it knows when to stop.

If you had the possibility of going forward and backward you could make the process countinue till you enter the kill command or key.

If you loaded 253 elements you would want to know not to display blank screens also. You may have to use a switch you can set when spaces at the end of the table are encountered.

 
Bead2,

did you open for output and tried to read the file ?

Regards,
Ronald.
 
I opened for input and output. If I display the using "display info-table(sub)" won't there be a problem. I have the table idexed by name-idx and a separate screen

NAME-TABLE-DATA.
05 NAME-TABLE OCCURS 300 TIMES
indexed by name-idx.
10 NT-LNAME PIC X(20).
10 NT-FNAME PIC X(14).
10 FILLER PIC X(01).
10 NT-HHLNAME PIC X(20).
10 NT-HHFNAME PIC X(14).
10 FILLER PIC X(01).
10 NT-HHID PIC 9(09).


SCREENS*************************
01 SCREEN-NAME-OUT AUTO.
02 BACKGROUND-COLOR 5 FOREGROUND-COLOR 3.
03 BLANK SCREEN.
03 LINE 2 COL 20 HIGHLIGHT VALUE "SEARCH".
03 COL 27 HIGHLIGHT VALUE "RESULTS FOR LAST NAME:".
03 COL 50 BACKGROUND-COLOR 2 FOREGROUND-COLOR 4
PIC X(20) FROM SI-LNAME.
03 LINE 3 COL 1 HIGHLIGHT VALUE "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
-"ÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍ»".
03 LINE 4 COL 1 HIGHLIGHT VALUE "º".
03 COL 15 HIGHLIGHT VALUE "NAME".
03 COL 35 HIGHLIGHT VALUE "º".
03 COL 45 HIGHLIGHT VALUE "HEAD".
03 COL 50 HIGHLIGHT VALUE "OF".
03 COL 53 HIGHLIGHT VALUE "HOUSEHOLD".
03 COL 70 HIGHLIGHT VALUE "º".
03 COL 74 HIGHLIGHT VALUE "HH-ID".
03 COL 80 HIGHLIGHT VALUE "º".
03 LINE 5 COL 1 HIGHLIGHT VALUE "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
-"ÍÍÍÍÍÎÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍ͹".
03 LINE 6 COL 1 HIGHLIGHT VALUE "º".
03 COL 2 PIC X(20) FROM NT-LNAME(NAME-IDX).
03 COL 23 PIC X(14) FROM NT-FNAME(NAME-IDX).
03 COL 35 HIGHLIGHT VALUE "º".
03 COL 36 PIC X(20) FROM NT-HHLNAME(NAME-IDX).
03 COL 70 HIGHLIGHT VALUE "º".
03 COL 71 PIC 9(09) FROM NT-HHID(NAME-IDX).
03 COL 80 HIGHLIGHT VALUE "º".
03 LINE 7 COL 1 HIGHLIGHT VALUE "º".
03 COL 2 PIC X(20) FROM NT-LNAME(NAME-IDX).
03 COL 23 PIC X(14) FROM NT-FNAME(NAME-IDX).
03 COL 35 HIGHLIGHT VALUE "º".
03 COL 36 PIC X(20) FROM NT-HHLNAME(NAME-IDX).
03 COL 70 HIGHLIGHT VALUE "º".
03 COL 71 PIC 9(09) FROM NT-HHID(NAME-IDX).
03 COL 80 HIGHLIGHT VALUE "º".
03 LINE 8 COL 1 HIGHLIGHT VALUE "º".
03 COL 2 PIC X(20) FROM NT-LNAME(NAME-IDX).
03 COL 23 PIC X(14) FROM NT-FNAME(NAME-IDX).
03 COL 35 HIGHLIGHT VALUE "º".
03 COL 36 PIC X(20) FROM NT-HHLNAME(NAME-IDX).
03 COL 70 HIGHLIGHT VALUE "º".
03 COL 71 PIC 9(09) FROM NT-HHID(NAME-IDX).
03 COL 80 HIGHLIGHT VALUE "º".
03 LINE 9 COL 1 HIGHLIGHT VALUE "º".
03 COL 2 PIC X(20) FROM NT-LNAME(NAME-IDX).
03 COL 23 PIC X(14) FROM NT-FNAME(NAME-IDX).
03 COL 35 HIGHLIGHT VALUE "º".
03 COL 36 PIC X(20) FROM NT-HHLNAME(NAME-IDX).
03 COL 70 HIGHLIGHT VALUE "º".
03 COL 71 PIC 9(09) FROM NT-HHID(NAME-IDX).
03 COL 80 HIGHLIGHT VALUE "º".
03 LINE 10 COL 1 HIGHLIGHT VALUE "º".
03 COL 2 PIC X(20) FROM NT-LNAME(NAME-IDX).
03 COL 23 PIC X(14) FROM NT-FNAME(NAME-IDX).
03 COL 35 HIGHLIGHT VALUE "º".
03 COL 36 PIC X(20) FROM NT-HHLNAME(NAME-IDX).
03 COL 70 HIGHLIGHT VALUE "º".
03 COL 71 PIC 9(09) FROM NT-HHID(NAME-IDX).
03 COL 80 HIGHLIGHT VALUE "º".
03 LINE 11 COL 1 HIGHLIGHT VALUE "º".
03 COL 2 PIC X(20) FROM NT-LNAME(NAME-IDX).
03 COL 23 PIC X(14) FROM NT-FNAME(NAME-IDX).
03 COL 35 HIGHLIGHT VALUE "º".
03 COL 36 PIC X(20) FROM NT-HHLNAME(NAME-IDX).
03 COL 70 HIGHLIGHT VALUE "º".
03 COL 71 PIC 9(09) FROM NT-HHID(NAME-IDX).
03 COL 80 HIGHLIGHT VALUE "º".
03 LINE 12 COL 1 HIGHLIGHT VALUE "º".
03 COL 2 PIC X(20) FROM NT-LNAME(NAME-IDX).
03 COL 23 PIC X(14) FROM NT-FNAME(NAME-IDX).
03 COL 35 HIGHLIGHT VALUE "º".
03 COL 36 PIC X(20) FROM NT-HHLNAME(NAME-IDX).
03 COL 70 HIGHLIGHT VALUE "º".
03 COL 71 PIC 9(09) FROM NT-HHID(NAME-IDX).
03 COL 80 HIGHLIGHT VALUE "º".
03 LINE 13 COL 1 HIGHLIGHT VALUE "º".
03 COL 2 PIC X(20) FROM NT-LNAME(NAME-IDX).
03 COL 23 PIC X(14) FROM NT-FNAME(NAME-IDX).
03 COL 35 HIGHLIGHT VALUE "º".
03 COL 36 PIC X(20) FROM NT-HHLNAME(NAME-IDX).
03 COL 70 HIGHLIGHT VALUE "º".
03 COL 71 PIC 9(09) FROM NT-HHID(NAME-IDX).
03 COL 80 HIGHLIGHT VALUE "º".
03 LINE 14 COL 1 HIGHLIGHT VALUE "º".
03 COL 2 PIC X(20) FROM NT-LNAME(NAME-IDX).
03 COL 23 PIC X(14) FROM NT-FNAME(NAME-IDX).
03 COL 35 HIGHLIGHT VALUE "º".
03 COL 36 PIC X(20) FROM NT-HHLNAME(NAME-IDX).
03 COL 70 HIGHLIGHT VALUE "º".
03 COL 71 PIC 9(09) FROM NT-HHID(NAME-IDX).
03 COL 80 HIGHLIGHT VALUE "º".
03 LINE 15 COL 1 HIGHLIGHT VALUE "º".
03 COL 2 PIC X(20) FROM NT-LNAME(NAME-IDX).
03 COL 23 PIC X(14) FROM NT-FNAME(NAME-IDX).
03 COL 35 HIGHLIGHT VALUE "º".
03 COL 36 PIC X(20) FROM NT-HHLNAME(NAME-IDX).
03 COL 70 HIGHLIGHT VALUE "º".
03 COL 71 PIC 9(09) FROM NT-HHID(NAME-IDX).
03 COL 80 HIGHLIGHT VALUE "º".
03 LINE 16 COL 1 HIGHLIGHT VALUE "º".
03 COL 2 PIC X(20) FROM NT-LNAME(NAME-IDX).
03 COL 23 PIC X(14) FROM NT-FNAME(NAME-IDX).
03 COL 35 HIGHLIGHT VALUE "º".
03 COL 36 PIC X(20) FROM NT-HHLNAME(NAME-IDX).
03 COL 70 HIGHLIGHT VALUE "º".
03 COL 71 PIC 9(09) FROM NT-HHID(NAME-IDX).
03 COL 80 HIGHLIGHT VALUE "º".
03 LINE 17 COL 1 HIGHLIGHT VALUE "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
-"ÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍͼ".

* 03 LINE 6 COL 2 PIC X(20) FROM NT-LNAME(NAME-IDX)
* 03 LINE 6 COL 21 PIC X(14) FROM NT-FNAME(NAME-IDX)
* 03 LINE 6 COL 36 PIC X(20) FROM NT-HHLNAME(NAME-IDX)
* 03 LINE 6 COL 57 PIC X(14) FROM NT-HHFNAME(NAME-IDX)
* 03 LINE 6 COL 57 PIC X(14) FROM NT-HHFNAME(NAME-IDX)
* 03 LINE 6 COL 71 PIC 9(09) FROM NT-HHID(NAME-IDX)

03 LINE 18 COL 3 HIGHLIGHT VALUE
"PRESS".
03 COL 9 BACKGROUND-COLOR 2 FOREGROUND-COLOR 4
"RETURN".
03 COL 16 HIGHLIGHT VALUE
"TO GO BACK TO AIS MAIN MENU".
03 LINE 18 COL 58 PIC X USING SNO-IN AUTO.
01 PROCESSING-MESSAGE-NAME-SCREEN.
03 BLANK SCREEN.
03 LINE 12 COL 34 HIGHLIGHT FOREGROUND-COLOR 6
'LAST NAME ENTERED " '.
03 LINE 13 COL 34 BACKGROUND-COLOR 2 FOREGROUND-COLOR 4
PIC X(20) FROM SI-LNAME.
03 LINE 14 COL 30 HIGHLIGHT FOREGROUND-COLOR 6
'" WAS NOT FOUND-PLEASE TRY ANOTHER.'.
03 LINE 15 COL 3 HIGHLIGHT VALUE
"PRESS".
03 COL 9 BACKGROUND-COLOR 2 FOREGROUND-COLOR 4
"RETURN".
03 COL 16 HIGHLIGHT VALUE
"TO RETURN TO MAIN ONLINE SEARCH MENU".
03 LINE 16 COL 58 PIC X USING SNO-IN AUTO.

01 PROCESSING-CONTINUE-SCREEN.
03 LINE 19 COL 34 HIGHLIGHT FOREGROUND-COLOR 6
'PRESS RETURN TO SEE'.
03 LINE 19 COL 54 HIGHLIGHT FOREGROUND-COLOR 6
'THE NEXT 12 RECORDS!'.
 
bead2 wrote:
-------------
" I opened for input and output. "
-------------
The following, from the IBM COBOL II PROGRAMMING LANGUAGE REFERENCE GUIDE, might be relevant:

I-O
Permits opening the file for both input and output operations. The I-O phrase can be specified only for files assigned to direct access devices.

How is your file assigned?

Hope this helps, Nina Too
 
Nina,

if the file is located on a direct acces device, that shouldn't be a problem. Doesn't hurt to check, though; maybe it has a read-only setting, or something like that ...

Bead2,

in your original post you indicated wanting to read the file, fill a table and display the contents of that table on the screen. If you're only going to read the file, why opening it for I-O ? Simply opening for input should do. It may not solve your problem, but might help to avoid future ones.

Regards,
Ronald.
 
I was going to wirte it to a file as well to the screen, but I decided not to. I am still having the same problems when trying to display. I am using a screen that I built and the nt-lname, nt-fname, etc is to display within the screen.
 
Bead2: It you are writing the data that you read from the original file, then you open the original file as an input file. Then define and open a different file as your output file. That's the way I've always done it.

And then you can take what you read, display it on screen, and then write it to your output file.

However, if you are supposed to be actually updating the file you are reading, then I believe that you have to do a "rewrite" command rather than a "write" command when you do your update.

Hope this helps, Nina Too
 
when moving data to the table, do I have to do as Ronald B suggested move lastname to last-name(4). I am doing it for approx. 200 records, so does that mean I have to move my data to each in the table field 200 times?
 
Bead2, Ronald wrote originally: MOVE ... TO table-firstname-1 (4)

What I think that he meant was that this is a general table-handling statement.

You will have to eventually move 200 records. But the neat thing about table-handling is that you don't actually have to write 200 statements.

Instead, you use your PERFORM UNTIL to move all these 200 records. It's easy to code once you get used to it. Initialize all counters, and make sure that you code it in such a way so that the ending condition will be met. Otherwise you get an endless loop -- which is not any fun. %-(

After your initial read, and after you load all your records onto your working storage indexed table, and you've counted your records as you read, then set up something like this:

MOVE REC-CTR TO NUMBER-OF-RECS.

MOVE +0 TO REC-CTR.
SET SORT-INDEX TO 1.
PERFORM 4000-DISPLAY-RECORDS
UNTIL SORT-INDEX > NUMBER-OF-RECS.


This will set the ball rolling. Here is the actual paragraph you will perform:

4000-DISPLAY-RECORDS.

DISPLAY TABLE-REC (SORT-INDEX).
ADD +1 TO REC-CTR.

Here is where you do your display of 200 records. But you don't have to write the code 200 times because this code sets up an iteration; it will do the same thing 200 times. SORT-INDEX is a variable which will be kicked up each iteration, so each of your 200 records will be covered by this.

Now you want to have a "break" for each 20th record. So you add +1 to REC-CTR. Then you do the following:

DIVIDE 20 INTO REC-CTR GIVING REC-RESULT
REMAINDER EVERY-20-FLAG.

When the remainder = 0, then we are at 20 or a multiple of 20, and you will display a '----------' at this point, which will separate the records into groups of 20.

IF EVERY-20-FLAG = 0
DISPLAY '-----------------'
END-IF.

If you want, you can do something other than display a line. You can write it to another record, move the set of records off somewhere else or whatever. It's a sort of "control-break."

Next, you will kick up your index, so that you'll move to the next record.

SET SORT-INDEX UP BY 1.

It will return to the 3000 paragraph, but because you have coded a PERFORM UNTIL, you'll keep coming back here until your UNTIL condition has been met. So when your SORT-INDEX has reached NUMBER-OF-RECS, the processing will stop.

Hope this helps, Nina Too
 
Instead of a separate

SET SORT-INDEX UP BY 1.

statement, you can do

PERFORM 4000-DISPLAY-RECORDS
varying sort-index
from 1
by 1
UNTIL SORT-INDEX > NUMBER-OF-RECS.

I prefer to do it here; less chance of a maintenance programmer messing up the increment later on.


Stephen J Spiro
Member, J4 COBOL Standards Committee
check it out at
 
Stephen, what you say is true.

I'm just in the habit of mostly using PERFORM UNTIL's rather than PERFORM VARYING. But you have a point. Some maintainer sometime in the future might forget to increment.

Though with me, it's almost become an instinct to increment. Which maybe is why I'm uneasy in using PERFORM VARYING because then I look toward the end of the coding for the increment -- and then realize that I don't have to do this with a PERFORM VARYING. :-D

But also, there are certain times when only a PERFORM UNTIL will work. Usually when you have to keep track of a subscript's count, such as when you are "walking through" a series of records.

Nina Too
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top