MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Copying all records except second last record.

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
hari haran
Beginner


Joined: 22 Jun 2004
Posts: 10
Topics: 4

PostPosted: Tue Jul 26, 2005 11:13 am    Post subject: Copying all records except second last record. Reply with quote

Hi All,

The requirement is to copy all the records from input to output except the second last record :

Input Data Considerations:

1. Input file can have any number of records,
2. There is no indentifier for the second last record (thus OMIT COND cannot be used).

Sample Data :

Input file :

1
2
3
4
5

Output File should be:

1
2
3
5

Can the above be done using sort ?

Thanks,
Hari Haran. S
Back to top
View user's profile Send private message
bprasanna
Beginner


Joined: 05 Sep 2003
Posts: 119
Topics: 33
Location: Hyderabad

PostPosted: Tue Jul 26, 2005 1:14 pm    Post subject: Reply with quote

Hi Hari,
I hope the below logic will work fine for your requirement.
.Now I am at home ,So I could not be able to try and test with the actaul code.
1)First generate the sequence number for all the i/p records.

so your o/p in first pass will look libe

1 00000001
2 00000002
3 00000003
4 00000004
5 00000005


2)get the last record seq number and subtract one from the number.

you can use the select statement to get the last record.

5 00000005
once you subtract 1 from the above 0000005 you will get the number 00000004

3)use OMIT condition to omit that record on Sequence number.

Thanks
Back to top
View user's profile Send private message
Alain Benveniste
Beginner


Joined: 04 May 2003
Posts: 92
Topics: 4
Location: Paris, France

PostPosted: Tue Jul 26, 2005 1:20 pm    Post subject: Reply with quote

Yes

That's the logic I would apply. I will try to find a moment to post it.

Alain
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Tue Jul 26, 2005 1:21 pm    Post subject: Reply with quote

Here's a DFSORT job that will do what you asked for. I assumed the input file has RECFM=FB and LRECL=80, but the job can be changed appropriately for other attributes.

You'll need z/OS DFSORT V1R5 PTF UQ95214 or DFSORT R14 PTF UQ95213 (Dec, 2004) in order to use DFSORT's new OVERLAY and COUNT-n functions. Only DFSORT has these functions, so if you don't have DFSORT, you won't be able to use them. If you do have DFSORT, but you don't have the Dec, 2004 PTF, ask your System Programmer to install it (it's free). For complete details on all of the new DFSORT and ICETOOL functions available with the Dec, 2004 PTF, see:

www.ibm.com/servers/storage/support/software/sort/mvs/pdug/

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD DSN=... input file (FB/80)
//SYM DD DSN=&&S1,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//SYSIN    DD    *
  OPTION COPY
* Add seqnum in 81-88
  INREC OVERLAY=(81:SEQNUM,8,ZD)
* Create a DFSORT Symbol as follows:
* LAST-1,+n
* where n=count-1
  OUTFIL FNAMES=SYM,REMOVECC,NODETAIL,OUTREC=(80X),
   TRAILER1=('LAST-1,+',COUNT-1=(M11,LENGTH=8))
* Copy records with seqnum
  OUTFIL FNAMES=T1
//S2    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SYMNAMES DD DSN=&&S1,DISP=(OLD,PASS)
//SORTIN DD DSN=&&T1,DISP=(OLD,PASS)
//SORTOUT DD DSN=... output file (FB/80)
//SYSIN    DD    *
  OPTION COPY
* Omit record with seqnum equal to LAST-1 value.
  OMIT COND=(81,8,ZD,EQ,LAST-1)
* Remove seqnum.
  OUTREC FIELDS=(1,80)
/*

_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Wed Jul 27, 2005 4:46 am    Post subject: Reply with quote

Hariharan,

If you do not have DFSORT or have a older version of it in your shop, you can use the following solution.

Code:

//R010   EXEC  PGM=SYNCTOOL                                   
//INPUT   DD  *                                               
1                                                             
2                                                             
3                                                             
4                                                             
5                                                             
/*                                                             
//CTL2CNTL  DD  DSN=&&T1,DISP=(,PASS)                         
//OUTPUT    DD  SYSOUT=*                                       
//TOOLMSG   DD  SYSOUT=*                                       
//DFSMSG    DD  SYSOUT=*                                       
//TOOLIN    DD  *                                             
  COPY FROM(INPUT)  TO(CTL2CNTL)  USING(CTL1)                 
  COPY FROM(INPUT)  TO(OUTPUT)    USING(CTL2)                 
/*                                                             
//CTL1CNTL  DD  *                                             
  INREC FIELDS=(1,80,SEQNUM,8,ZD,START=0)                     
  OUTFIL TRAILER1=(' INREC FIELDS=(1,80,SEQNUM,8,ZD)',80:X,/, 
  ' OUTFIL OMIT=(81,8,ZD,EQ,',81,8,'),',80:X,/,       
  ' OUTREC=(1,80)',80:X),                             
    NODETAIL,REMOVECC                                 
/*                                                   


Explanation:
This solution follows similar logic mentioned by Bprasanna and Alain.
1. I build a dynamic control card as shown below
Code:

 INREC FIELDS=(1,80,SEQNUM,8,ZD)   
 OUTFIL OMIT=(81,8,ZD,EQ,00000004),
 OUTREC=(1,80)                     


To get this, I insert Sequence numbers in the input file starting at position 81. Note, the seqnum starts from ZERO. So, when I refer 81,8 in OUTFIL TRAILER1, it will have the value 00000004.

2. Now, I read the input file again using the dynamic sort card. But this time I start the seqnum from 1 instead of zero. So, the seqnum '4' pointed by the dynamic sort card will actually be LAST BUT 1 RECORD.

Hope this helps.

Cheers,
Phantom
Back to top
View user's profile Send private message
hari haran
Beginner


Joined: 22 Jun 2004
Posts: 10
Topics: 4

PostPosted: Thu Jul 28, 2005 12:45 pm    Post subject: Reply with quote

Phantom,
Thanks a lot for the above solution..... it worked great !!! Very Happy ...

Frank,
Thanks for the solution but we have Syncsort in our Shop Embarassed ...

Hari Haran. S.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group