|
|
| Author |
Message |
ashokkumarsahu
New User
Joined: 03 Aug 2005 Posts: 6 Location: bangalore
|
|
|
|
| How can we read the last record of a sequential file? |
|
| Back to top |
|
 |
References
|
|
 |
priyesh.agrawal
Global Moderator
Joined: 28 Mar 2005 Posts: 1509 Location: Chicago, IL
|
|
|
|
Hi ashok,
| Quote: |
| How can we read the last record of a sequential file? |
Answer is a simple READ stmt....Use AT END there to identify its a last record....Like....
| Code: |
READ INPUT-FILE INTO INPUT-REC
AT END SET END-INFILE-YES TO TRUE
GO TO PARA-EXIT
END-READ.
IF END-INFILE-YES
...
...
END-IF. |
IF statement will be executed at lastr record only....you can give your executable statements there, as per your need....
Regards,
Priyesh. |
|
| Back to top |
|
 |
shivashunmugam Muthu
Active User
Joined: 22 Jul 2005 Posts: 114 Location: Chennai
|
|
|
|
Hi Priyesh,
If the file isvery huge, we shall sort it as per the discussion we had earlier & then proceed from first.
I think it will give superior performance rather than reading the file till end.
Correct me if am wrong....
Shiva |
|
| Back to top |
|
 |
priyesh.agrawal
Global Moderator
Joined: 28 Mar 2005 Posts: 1509 Location: Chicago, IL
|
|
|
|
Hi Shiva,
You are correct in terms of Performance.... There can be more solutions considering more IFs & BUTs ....Adding SEQNUM to the records will be very effactive.... That is more optimized than a simple read till LAST considering performance issue.
Regards,
Priyesh. |
|
| Back to top |
|
 |
Frank Yaeger
DFSORT Moderator
Joined: 15 Feb 2005 Posts: 4687 Location: San Jose, CA
|
|
|
|
Actually, we can use a DFSORT copy which will be more efficient than a sort. For this example, I'll assume that the input file has RECFM and LRECL=80, but the job can be changed appropriately for other attributes.
| Code: |
//S1 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=... input file (FB/80)
//SORTOUT DD DSN=... output file (FB/80)
//SYSIN DD *
OPTION COPY
OUTFIL REMOVECC,NODETAIL,TRAILER1=(1,80)
/*
|
|
|
| Back to top |
|
 |
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1526
|
|
|
|
Hi Ashok,
If you have FileAid you can try this. It's probably one of the more efficient ways to get what you want because it probably uses Assembler to go directly to the last rec.
| Code: |
//COPYREC EXEC PGM=FILEAID
//DD01 DD DSN=YOUR.FILE,etc...
//DD01O DD DSN=file.contains.last.rec,etc...
//SYSIN DD *
$$DD01 COPYBACK OUT=1
/* |
[/code] |
|
| Back to top |
|
 |
Frank Yaeger
DFSORT Moderator
Joined: 15 Feb 2005 Posts: 4687 Location: San Jose, CA
|
|
|
|
You can now do this kind of thing quite easily using the new SUBSET operator of DFSORT's ICETOOL available with z/OS DFSORT V1R5 PTF UK90013 (July, 2008) like this:
| Code: |
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=... input file
//OUT DD DSN=... output file
//TOOLIN DD *
SUBSET FROM(IN) TO(OUT) KEEP INPUT LAST
/*
|
For complete details on the new SUBSET function and the other new functions available with PTF UK90013, see:
www.ibm.com/systems/support/storage/software/sort/mvs/ugpf/ |
|
| Back to top |
|
 |
|
|