View previous topic :: View next topic |
Author |
Message |
Milind Beginner
Joined: 29 Dec 2004 Posts: 26 Topics: 20
|
Posted: Tue May 17, 2005 9:10 am Post subject: How to read a particular record from VSAM file |
|
|
Hi All,
I have a query regarding reading of particular reord from vsam file:
I have 1000 records in my vsam file and I want to read record number 200. I don't know know the key of this record number 200. How to read this record directly?
IInd:
I want to read the last record of the vsam file directly.
One solution is I will move HIGH-VALUES to key part , read vsam file and then read previous. Is this solution correct?
What are the other simplest way to achive both the reads.
Genious please help...
Thanks in advance,
Milind deshmukh. |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Tue May 17, 2005 9:36 am Post subject: |
|
|
Milind,
1. You can use SKIP & COUNT parms of repro to read the desired record.
Code: |
//STEP0100 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//IN DD DSN=YOUR VSAM CLUSTER,
// DISP=SHR
//OUT DD DSN=YOUR 200TH RECORD FILE,
// DISP=(NEW,CATLG,DELETE),
// UNIT=SYSDA,
// SPACE=(CYL,(X,Y),RLSE),
// DCB=(LRECL=ZZZ,RECFM=FB,BLKSIZE=0)
//SYSIN DD *
REPRO IFILE(IN) OFILE(OUT) SKIP(199) COUNT(1)
/*
|
2. If your shop has file-aid then you can use COPYBACK function to read just the last record.
Code: |
//STEP0100 EXEC PGM=FILEAID
//SYSPRINT DD SYSOUT=*
//SYSLIST DD SYSOUT=*
//DD01 DD DSN=YOUR VSAM CLUSTER,
// DISP=SHR
//DD01O DD DSN=YOUR LAST RECORD FILE,
// DISP=(NEW,CATLG,DELETE),
// UNIT=SYSDA,
// SPACE=(CYL,(X,Y),RLSE)
//SYSIN DD *
$$DD01 COPYBACK OUT=1
/*
|
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
Milind Beginner
Joined: 29 Dec 2004 Posts: 26 Topics: 20
|
Posted: Tue May 17, 2005 10:38 am Post subject: |
|
|
Thx kolusu for your quick reply.
With first query I am very much clear.
For the second query I don't have FILE-AID utility with me. In this cae how to achieve last read. The solution which I have given is ok? or do u have some other solution with you.
If I want to read 200th record using cobol program only. Is this achievable without using JCL. i.e. without using count and skip?
Thanks in advance
Milind |
|
Back to top |
|
|
dtf Beginner
Joined: 10 Dec 2004 Posts: 110 Topics: 8 Location: Colorado USA
|
Posted: Tue May 17, 2005 4:18 pm Post subject: |
|
|
You probably could do this with an ESDS file (of fixed length records) by calculating the RBA of the record you want and accessing the file by RBA. Don't know if this can be done in COBOL. Or with an RRDS, again never used one in COBOL.
However, it seems unlikely that you would ever be able to do this with a KSDS at least without doing something silly like having the record number be the key, or having an alternate index whose record number is the key. This in of itself would seem to be a very strange request, but then who knows what people might come up with.
________
Honda Cb400F History
Last edited by dtf on Tue Mar 15, 2011 5:01 am; edited 1 time in total |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Tue May 17, 2005 4:42 pm Post subject: |
|
|
Quote: |
For the second query I don't have FILE-AID utility with me. In this cae how to achieve last read. The solution which I have given is ok? or do u have some other solution with you.
|
Milind,
You can also use SORT to get the last record from the vsam cluster. If you want to do it programmatically, your approach is good.
Quote: |
If I want to read 200th record using cobol program only. Is this achievable without using JCL. i.e. without using count and skip?
|
If your vsam cluster is an RRDS then you can use the RBA to read the desired record as DTF mentioned in the above post.
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
vjkumk Beginner
Joined: 28 Sep 2005 Posts: 98 Topics: 33
|
Posted: Tue Dec 27, 2005 9:37 am Post subject: |
|
|
Quote: |
I want to read the last record of the vsam file directly.
|
acutally you can read the vsam file in reverse.In pl1 if i am right the declaration is as follows
dcl ddname input|output env (vsam bkwd);
so by giving the file declaration in this way the last record is readed first. |
|
Back to top |
|
|
vjkumk Beginner
Joined: 28 Sep 2005 Posts: 98 Topics: 33
|
Posted: Wed Dec 28, 2005 10:10 am Post subject: |
|
|
the correct declaration in pl1,
DCL DDNAME INPUT SEQUENTIAL ENV(VSAM BKWD); |
|
Back to top |
|
|
|
|