View previous topic :: View next topic
|
Author |
Message |
dineshsjce Currently Banned New User
Joined: 16 Apr 2007 Posts: 41 Location: Bangalore
|
|
|
|
Supposing a sequential file contains 1 million records. How to read the last record directly without going through all the records ( It would be a tedious task !). |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
It's a sequential file - you have to read each record one-by-one. There is no magic trick.
... unless the file is on tape ... |
|
Back to top |
|
|
dineshsjce Currently Banned New User
Joined: 16 Apr 2007 Posts: 41 Location: Bangalore
|
|
|
|
Ya that we can do. But it is a cumbersome task to read all the records. I think there must be some other logic. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Yea, Kevin, surely there must be a way..... |
|
Back to top |
|
|
shankar.v
Active User
Joined: 25 Jun 2007 Posts: 196 Location: Bangalore
|
|
|
|
It's not possible to read the last record directly in sequential file. we will add a sequence number at the end of the record and sort the sequence numbers on descending order and get the first record of output that will be the last record of sequential file.
Code: |
// EXEC PGM=SORT
//SORTIN DD DSN=INFILE
//SORTOUT DD DSN=&&LASTREC,DISP=(MOD,PASS)
//SYSOUT DD SYSOUT=*
//SYSIN DD *
INREC OVERLAY=(81:SEQNUM,9,ZD)
SORT FIELDS=(81,9,ZD,D)
OUTREC FIELDS=(1,80)
OUTFIL ENDREC=1
/*
// EXEC PGM=COBOLPGM
//STEPLIB DD DSN=LOADLIB
//SYSOUT DD SYSOUT=*
//<ddname> DD DSN=&&LASTREC,DISP=(OLD,DELETE)
//SYSIN DD *
.
.
/*
// |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Ya that we can do. But it is a cumbersome task to read all the records. I think there must be some other logic. |
Why would you think so? Just because some people want it?
Quote: |
( It would be a tedious task !). |
It is not tedious for the program - it cannot get bored as we might hitting PF8. It just takes some machine cycles and does what it is told. There is no need to assign a sequence number and then sort descending - that will just use more machine cycles than simply reading the records and "using" the last one read. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi dineshsjce,
If you have FileAid you can try this:
Code: |
//COPYREC EXEC PGM=FILEAID
//DD01 DD DSN=YR1MM.REC.FILE,DISP=SHR
//DD01O DD DSN=NEW1.REC.FILE,DISP=(,CATLG,DELETE),
// DCB=*.DD01
//SYSIN DD *
$$DD01 COPYBACK OUT=1
//SYSPRINT DD SYSOUT=A |
This will also get the VSAM rec w/the highest key |
|
Back to top |
|
|
HARLEEN SINGH MANN Warnings : 2 New User
Joined: 03 Aug 2007 Posts: 17 Location: Pune
|
|
|
|
cant we read the file as a direct/random, file?
if we can using "access is random", then we can directly read any record. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
HARLEEN SINGH MANN,
If the file structure has I/O routines that support random reads then yes.
e.g. VSAM with keys (KSDS), rel rec num (RRDS), rba (ESDS) .. yes
BSAM, used in IMS I believe supports random reads.
But the understanding here is that the file is QSAM, which means that it has no keys--- just a sequential file --- and the I/O routines for QSAM files do not support random reads. |
|
Back to top |
|
|
shankar.v
Active User
Joined: 25 Jun 2007 Posts: 196 Location: Bangalore
|
|
|
|
mmwife,
The file-aid batch program you posted works fine for VSAM file and not for PS file.
When i gave the PS file as input, i got the following messages in SYSPRINT with RC=8 and it's showing "ABOVE FUNCTION ENDED ON EMPTY DATA SET". But i have some records in PS file.
Code: |
DD01 DSN=xxxxx.xxxxxxx.xxxxxx OPENED AS PS(BACKWARD),
RECFM=FB,LRECL=80,BLKSIZE=800,VOL=xxxxxx
DD01O DSN=xxxxxxx.xxxxxxx.xxxxxxxx.xxxxxxxx OPENED AS PS,
RECFM=FB,LRECL=80,BLKSIZE=800,VOL=xxxxxx
$$DD01 COPYBACK OUT=1
ABOVE FUNCTION ENDED ON EMPTY DATA SET RC=8
0 RECORDS WRITTEN TO DD01O-xxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx ***RECORD COUNT***
VOL= |
|
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi shankar.v,
I don't know why you're having this problem, but I do know the facility works for PS files. Are you sure you're using a PS file and that it has data?
From all you've said, it s/b working. Perhaps you can post your JCL (cut & paste it, to be sure it represents the JCL you submitted). That may show something. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Quote: |
But i have some records in PS file. |
Quote: |
ABOVE FUNCTION ENDED ON EMPTY DATA SET |
Prove it...... |
|
Back to top |
|
|
shankar.v
Active User
Joined: 25 Jun 2007 Posts: 196 Location: Bangalore
|
|
|
|
mmwife & CICS Guy,
I had taken the input as instream input data, so i got that error, which i was posted earlier.
I got the output by using the PS file now.
While posting the error i wrongly mentioned that i am using PS file. My Apologizes for wrongly mentioning as "PS file" instead of "instream input data". |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi shankar.v,
Thanx for keeping us posted. |
|
Back to top |
|
|
acevedo
Active User
Joined: 11 May 2005 Posts: 344 Location: Spain
|
|
|
|
dineshsjce wrote: |
How to read the last record directly without going through all the records ( It would be a tedious task !). |
if you use sort with the sequence 'trick' or fileaid with copyback...then you're going through all the records... not with a cobol program but with a utility. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Quote: |
if you use sort with the sequence 'trick' or fileaid with copyback...then you're going through all the records... not with a cobol program but with a utility. |
Not when you use FileAid. It uses an assembler "read backwards" (don't remember the exact technique - think it's a GET macro option) and reads the last rec in the file.
PS - You can copy any number of recs, just change the OUT= to the number you want. They'll be in reverse order. |
|
Back to top |
|
|
acevedo
Active User
Joined: 11 May 2005 Posts: 344 Location: Spain
|
|
|
|
FileAid is not available in my shop (changed for StarTool 10 years ago)... could you test it with a input file of, let's say, 1.000.000 records an post the job statistics? |
|
Back to top |
|
|
|