IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Copying a file based on two other files


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Parthasarathy

New User


Joined: 24 Feb 2006
Posts: 18
Location: Chennai

PostPosted: Tue Jul 26, 2011 7:23 pm
Reply with quote

Hi All,

I have the following requirement which i'm looking for a solution.

I have 3 input files.
File A - Control file in following layout lrecl = 4
RecNo (3 Bytes key field) and Indicator (1 Byte)
Code:
100Y
110N
120N
130N
140Y
150N


File B - Product "Lookup" file in following layout lrecl = 8
Product id (7 bytes Key field) and Product type (1 Byte and values will be A or B)
Code:
1212111A
1212122A
1212133B
1212144A
1212155B


File C- Location "Master" file lrecl = 16
Location id (5 Bytes and Key field), Product ID (7 bytes) and Year (4bytes)
(same product will be available in multiple locations)
Code:
DABCA12121112009
DABCB12121112010
DABCC12121112008
DABCD12121222010
DABCF12121222009
DABCG12121332008
DABCH12121332005



I need the file C to be copied to output file D of same layout and same data but the year populated with zeros or values from input file C based on the following condition.
1. If file A rec no 120 has indicator N then always populate zeros to year.
2. If file A rec no 120 has indicator Y, then look for the products in File B for product type, if A then populate year same as available in input and if B populate zeros to year field.
(In file A we should always look for rec no 120 and ignore the remaining records)

Partha
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Tue Jul 26, 2011 8:07 pm
Reply with quote

Parthasarathy,
I am assuming that in control file, 1 byte indicator is always populated with either 'N' or 'Y'.

See if below works...
Code:
//STEP0001 EXEC PGM=SORT                                     
//SYSOUT   DD SYSOUT=*                                       
//SORTIN   DD CONTROL FILE/FB-4                               
//SORTOUT  DD DSN=&&CNTL,DISP=(,PASS),SPACE=(TRK,(1,0),RLSE) 
//SYSIN    DD *                                               
 OPTION COPY                                                 
 INCLUDE COND=(1,3,CH,EQ,C'120')                             
 OUTREC BUILD=(C'CONTROL-FIELD,C''',4,1,C'''',80:X)           
/*                                                           
//STEP0002 EXEC PGM=SORT                                     
//SYMNAMES DD DSN=&&CNTL,DISP=SHR                             
//SORTJNF1 DD PRODUCT LOOKUP FILE/FB-8                       
//SORTJNF2 DD LOCATION MASTER FILE/FB-16                     
//SORTOUT  DD  SYSOUT=*                                       
//SYSIN    DD  *                                             
  JOINKEYS FILE=F1,FIELDS=(1,7,A)                             
  JOINKEYS FILE=F2,FIELDS=(6,7,A)                             
  JOIN UNPAIRED,F2                                           
  REFORMAT FIELDS=(F2:01,16,F1:8,1)                           
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(18:CONTROL-FIELD)),       
        IFTHEN=(WHEN=(18,1,CH,EQ,C'N'),OVERLAY=(13:4C'0')),   
        IFTHEN=(WHEN=(17,1,CH,EQ,C'B'),OVERLAY=(13:4C'0'))   
  SORT FIELDS=COPY                                           
  OUTFIL BUILD=(1,16)                                         
/*                                                   
//SYSOUT   DD  SYSOUT=*                               
//SYSPRINT DD  SYSOUT=*                               
//SYSUDUMP DD  SYSOUT=D                               
//SYSDBOUT DD  SYSOUT=D                               


OUTPUT with Control Field as N
Code:
DABCA12121110000
DABCB12121110000
DABCC12121110000
DABCD12121220000
DABCF12121220000
DABCG12121330000
DABCH12121330000


OUTPUT with Control Field as Y
Code:
DABCA12121112009
DABCB12121112010
DABCC12121112008
DABCD12121222010
DABCF12121222009
DABCG12121330000
DABCH12121330000

Thanks,
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Tue Jul 26, 2011 10:29 pm
Reply with quote

sqlcode1 wrote:
See if below works...


Run your job with the following scenario's

1. There is no type 120 record FB-4/CONTROL FILE or Empty FB-4/CONTROL
2. More than 1 record for type 120 record with Y and N indicator.

I am not sure as to why you have SYSPRINT,SYSUDUMP,SYSDBOUT DDnames in your JCL. You don't need them.

Parthasarathy,

Use the following JCL which will give you the desired results. This job also takes care of not reading the product file when there is an "n" indicator in the control file.

Code:

//STEP0100 EXEC PGM=SORT   
//SYSOUT   DD SYSOUT=*     
//SORTIN   DD DSN=Your FB 4 byte control file,DISP=SHR
//INR      DD DSN=&&INR,DISP=(,PASS),SPACE=(TRK,(1,0),RLSE)       
//JNF      DD DSN=&&JNF,DISP=(,PASS),SPACE=(TRK,(1,0),RLSE)       
//SYSIN    DD *                                                   
  INCLUDE COND=(1,3,CH,EQ,C'120')                                 
  OPTION COPY,STOPAFT=1                                           
                                                                   
  OUTFIL FNAMES=INR,REMOVECC,NODETAIL,                             
  HEADER1=(3:'INREC IFOUTLEN=16,',/,                               
           3:'IFTHEN=(WHEN=INIT,OVERLAY=(18:C''',4,1,'''',')),',/,
           3:'IFTHEN=(WHEN=(18,1,CH,EQ,C''','N''',                 
             '),OVERLAY=(13:4C''','0''',')),',/,                   
           3:'IFTHEN=(WHEN=(17,1,CH,EQ,C''','B''',                 
             '),OVERLAY=(13:4C''','0''','))',80:X)                 
                                                                   
  OUTFIL FNAMES=JNF,INCLUDE=(4,1,CH,EQ,C'N'),                     
  BUILD=(3:C'OMIT COND=ALL',80:X)                                 

//*
//STEP0200 EXEC PGM=SORT   
//SYSOUT   DD SYSOUT=*     
//SORTJNF1 DD DSN=Your FB 16 byte Location Master file,DISP=SHR
//SORTJNF2 DD DSN=Your FB 8 byte Product Lookup file,DISP=SHR
//SORTOUT  DD SYSOUT=*             
//SYSIN    DD *                     
  OPTION COPY                       
  JOINKEYS FILE=F1,FIELDS=(6,7,A)   
  JOINKEYS FILE=F2,FIELDS=(1,7,A)   
  JOIN UNPAIRED,F1                 
  REFORMAT FIELDS=(F1:01,16,F2:8,1)
//         DD DSN=&&INR,DISP=SHR
//*   
//JNF2CNTL DD DSN=&&JNF,DISP=SHR
//*
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue Jul 26, 2011 10:52 pm
Reply with quote

Quote:
I am not sure as to why you have SYSPRINT,SYSUDUMP,SYSDBOUT DDnames in your JCL. You don't need them.


sqlcode1,

I would advise only adding SYSUDUMP if you get an ABEND from a DFSORT job and want to look at a dump. SYSPRINT and SYSDBOUT are NOT used by DFSORT.

I have been deleting these DD statements from your posts when I see them. They ARE NOT NEEDED. Please don't use them or post them in your solutions because people will use your JCL as a model and will propagate these unnecessary statements from job to job.
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Tue Jul 26, 2011 11:29 pm
Reply with quote

Kolusu,
Quote:
1. There is no type 120 record FB-4/CONTROL FILE or Empty FB-4/CONTROL
2. More than 1 record for type 120 record with Y and N indicator.

Based on sample data, I assumed that Control File would have atleast one and unique type 120 record. Because OP didn't provided that information, I had to make that assumption. I may/could be wrong.

Quote:
I am not sure as to why you have SYSPRINT,SYSUDUMP,SYSDBOUT DDnames in your JCL. You don't need them.


Quote:
I would advise only adding SYSUDUMP if you get an ABEND from a DFSORT job and want to look at a dump. SYSPRINT and SYSDBOUT are NOT used by DFSORT.
I have been deleting these DD statements from your posts when I see them. They ARE NOT NEEDED. Please don't use them or post them in your solutions because people will use your JCL as a model and will propagate these unnecessary statements from job to job.


Thank you for the information and I will take them off next time onwards.

Thanks,
Back to top
View user's profile Send private message
Parthasarathy

New User


Joined: 24 Feb 2006
Posts: 18
Location: Chennai

PostPosted: Wed Jul 27, 2011 11:41 am
Reply with quote

Thanks a lot.

sqlcode1 wrote:
Kolusu,
Based on sample data, I assumed that Control File would have atleast one and unique type 120 record. Because OP didn't provided that information, I had to make that assumption. I may/could be wrong.


In My control file I may or may not have record "120". If I don't have "120" then it should be treated as record with indicator "N" and hence populate zeros to year in output without considering product file.

The control file will never have duplicates on "120".
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Wed Jul 27, 2011 7:49 pm
Reply with quote

Parthasarathy,
Grrrr...Why would you not say that control file may or may not have 120 records. However, did you try Kolusu's solution?

Code:
//STEP0001 EXEC PGM=SORT                                               
//SYSOUT   DD SYSOUT=*                                                 
//SORTIN   DD *                                                         
100Y                                                                   
110N                                                                   
130N                                                                   
140Y                                                                   
150N                                                                   
//CNTL     DD DSN=&&CNTL,DISP=(,PASS),SPACE=(TRK,(1,0),RLSE)           
//SYSIN    DD *                                                         
 OPTION COPY                                                           
 INCLUDE COND=(1,3,CH,EQ,C'120')                                       
 OUTFIL FNAMES=CNTL,REMOVECC,NODETAIL,                                 
                    TRAILER1=('CONTROL-FIELD,C''',04,01,C'''')         
/*                                                                     
//STEP0002 EXEC PGM=SORT                                               
//SYMNAMES DD DSN=&&CNTL,DISP=SHR                                       
//SORTJNF1 DD  *                                                       
1212111A                                                               
1212122A                                                               
1212133B                                                               
1212144A                                                               
1212155B                                                               
/*                                                                     
//SORTJNF2 DD  *                                                       
DABCA12121112009                                                       
DABCB12121112010                                                       
DABCC12121112008                                                       
DABCD12121222010                                                       
DABCF12121222009                                                       
DABCG12121332008                                                       
DABCH12121332005                                                       
/*                                                                     
//SORTOUT  DD  SYSOUT=*                                                 
//SYSIN    DD  *                                                       
  JOINKEYS FILE=F1,FIELDS=(1,7,A)                                       
  JOINKEYS FILE=F2,FIELDS=(6,7,A)                                       
  JOIN UNPAIRED,F2                                                     
  REFORMAT FIELDS=(F2:01,16,F1:8,1)                           
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(18:CONTROL-FIELD)),         
        IFTHEN=(WHEN=(18,1,SS,EQ,C'N, '),OVERLAY=(13:4C'0')), 
        IFTHEN=(WHEN=(17,1,CH,EQ,C'B'),OVERLAY=(13:4C'0'))     
  SORT FIELDS=COPY                                             
  OUTFIL BUILD=(1,16)                                         
/*                                                             
//SYSOUT   DD  SYSOUT=*                                       
//SYSUDUMP DD  SYSOUT=D                                       

OUTPUT WITH NO 120 TYPE RECORD
Code:
DABCA12121110000
DABCB12121110000
DABCC12121110000
DABCD12121220000
DABCF12121220000
DABCG12121330000
DABCH12121330000

Thanks,
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Wed Jul 27, 2011 7:51 pm
Reply with quote

Frank,
Sorry I missed below comment earlier. Thanks a lot for the clean up.

Quote:
I have been deleting these DD statements from your posts when I see them.

Thanks,
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Wed Jul 27, 2011 11:11 pm
Reply with quote

sqlcode1,

Your solutions are quite good, so I usually just needed to do that minor cleanup. I meant to mention it to you sooner.

Thanks.
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Thu Jul 28, 2011 2:34 am
Reply with quote

Frank,
I am glad that I am learning from you guys and correcting my mistakes.

36_8_15.gif


Thanks,
Back to top
View user's profile Send private message
Parthasarathy

New User


Joined: 24 Feb 2006
Posts: 18
Location: Chennai

PostPosted: Thu Jul 28, 2011 1:38 pm
Reply with quote

sqlcode1 wrote:
Parthasarathy,
Grrrr...Why would you not say that control file may or may not have 120 records.

Sorry, I have missed to mention this earlier.

Thanks for the solution. I'm currently testing the solution. Will come back if I find any problem. Thanks all for the help
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top