Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to read a last record from a sequential file ?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
dineshsjce
Currently Banned

New User


Joined: 16 Apr 2007
Posts: 41
Location: Bangalore

PostPosted: Wed Aug 22, 2007 5:32 pm    Post subject: How to read a last record from a sequential file ?
Reply with quote

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
View user's profile Send private message

superk

Moderator Team Head


Joined: 26 Apr 2004
Posts: 4648
Location: Raleigh, NC, USA

PostPosted: Wed Aug 22, 2007 5:35 pm    Post subject: Reply to: How to read a last record from a sequential file ?
Reply with quote

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
View user's profile Send private message
dineshsjce
Currently Banned

New User


Joined: 16 Apr 2007
Posts: 41
Location: Bangalore

PostPosted: Wed Aug 22, 2007 5:39 pm    Post subject:
Reply with 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.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Wed Aug 22, 2007 5:44 pm    Post subject:
Reply with quote

Yea, Kevin, surely there must be a way..... icon_confused.gif
Back to top
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Wed Aug 22, 2007 6:05 pm    Post subject:
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Aug 22, 2007 7:31 pm    Post subject:
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Aug 23, 2007 9:39 pm    Post subject:
Reply with quote

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
View user's profile Send private message
HARLEEN SINGH MANN
Warnings : 2

New User


Joined: 03 Aug 2007
Posts: 17
Location: Pune

PostPosted: Sun Aug 26, 2007 12:03 am    Post subject: Reply to: How to read a last record from a sequential file ?
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sun Aug 26, 2007 12:12 am    Post subject: Reply to: How to read a last record from a sequential file ?
Reply with quote

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
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Mon Aug 27, 2007 4:03 pm    Post subject:
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Aug 30, 2007 4:02 am    Post subject: Reply to: How to read a last record from a sequential file ?
Reply with quote

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
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Thu Aug 30, 2007 4:12 am    Post subject:
Reply with quote

Quote:
But i have some records in PS file.

Quote:
ABOVE FUNCTION ENDED ON EMPTY DATA SET

Prove it......
Back to top
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Thu Aug 30, 2007 12:01 pm    Post subject:
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri Aug 31, 2007 6:38 am    Post subject:
Reply with quote

Hi shankar.v,

Thanx for keeping us posted.
Back to top
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Fri Aug 31, 2007 2:17 pm    Post subject: Re: How to read a last record from a sequential file ?
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Sep 01, 2007 2:06 am    Post subject:
Reply with quote

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
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Mon Sep 03, 2007 11:47 am    Post subject:
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts CICS Roll back partially - Need to re... dwijadas CICS 4 Wed Nov 16, 2016 4:30 pm
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us