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 

Copy a file depending on the contents of two other files

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


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

PostPosted: Sat Apr 17, 2004 12:23 am    Post subject: Copy a file depending on the contents of two other files Reply with quote

I have 3 input files each of LRECL=80 and RECFM=FB. File 1 and 2 are control files which will have only one record as shown below. File 3 is the actual data file (Its very huge !!!).

My requirement is to copy File 3 to File 4 (ouput file) if the contents of File 1 and 2 match. Else File 4 should be created empty. This needs to accomplished using SORT in one step. (Our installation has only SYNCSORT 1999 version)...TOOO OLD !!! Laughing

Code:

File 1: LRECL=80, RECFM=FB
TRAILER RECORD (TOTAL RECORDS: 000000001)                             

File 2: LRECL=80, RECFM=FB
TRAILER RECORD (TOTAL RECORDS: 000000002)                             


As shown above I should check whether the count in File 1 and 2 match. In the above case it does not. So the output file must be empty. If they match, File 4 should have all the records in File 3.

Code:

File 3: LRECL=80, RECFM=FB
AAAAAAA
BBBBBBB
CCCCCC


For this I have written a small synctool code. Could someone review my code and let me know if this could be improved. (I'm a novice in sort..and just wanted to learn new things....).

Synctool Code
Code:

//R012     EXEC PGM=SYNCTOOL                               
//TOOLMSG  DD  SYSOUT=*                                     
//DFSMSG   DD  SYSOUT=*                                     
//INCNTL   DD  DSN=My Input File 1,
//             DISP=SHR                                     
//         DD  DSN=My Input File 2,
//             DISP=SHR                                     
//DATAIN   DD  DSN=My Data File,
//             DISP=SHR                                     
//CTL2CNTL DD  DSN=Temporary Sort Control File,
//             DISP=(NEW,CATLG,DELETE),                     
//             UNIT=SYSDA,                                 
//             AVGREC=K,                                   
//             SPACE=(TRK,(1,1),RLSE)                       
//DATAOUT  DD  DSN=My Output File,
//             DISP=(NEW,CATLG,DELETE),                     
//             UNIT=SYSDA,                                 
//             AVGREC=K,                                   
//             SPACE=(80,(10,2),RLSE),                     
//             DCB=(RECFM=FB,LRECL=80)                     
//TOOLIN   DD  *                                           
 SORT FROM(INCNTL) USING(CTL1)                         
 COPY FROM(DATAIN) TO(DATAOUT) USING(CTL2)             
/*                                                     
//CTL1CNTL DD  *                                       
 OPTION EQUALS                                         
 INREC FIELDS=(1,80,SEQNUM,2,ZD)                       
 SORT FIELDS=(32,9,ZD,A)                               
 SUM FIELDS=(81,2,ZD)                                   
 OUTFIL FNAMES=CTL2CNTL,                               
 OUTREC=(81,2,CHANGE=(18,C'03',C' INCLUDE COND=ALL ',   
                         C'01',C' INCLUDE COND=NONE'), 
             NOMATCH=(C' '),80:X)                       
/*                                                     


Thanks for your help.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Sat Apr 17, 2004 8:45 am    Post subject: Reply with quote

Phantom,


Couple of minor changes. You will be creating 2 records in the control cards when the counts do not match. Even though it does not matter, it can be solved by coding ENDREC on the outfil statement in the first sort step.
Code:

OUTFIL FNAMES=CTL2CNTL,ENDREC=1,


Always remember that with sort you do not have to hardcode the LRECL & RECFM. They will be automatically calculated.so remove AVGREC & DCB parms.

Also change the DISP of the CTL2CNTL file to DISP=(NEW,PASS) instead of cataloging the dataset, so that the dataset will be deleted at the end of the Job. You can catalog that dataset if you want to verify( but that can be done just by browing the count files).

Other than that the solution looks good and a clever Idea

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
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: Sun Apr 18, 2004 11:19 pm    Post subject: Reply with quote

Thanks for your advice kolusu,

First I tried STOPAFT=1 in the sort command. In that case the SUM FIELDS did not work since it took only one record from the input. I thought ENDREC will do the same....and didn't try it...So I decided to go for NOMATCH=(C' ') which will just create a blank record. Now, I learnt the use of ENDREC with ur help.

Thanks again for your suggestions...
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