Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Sort and merge 2 files

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
sameetshetty

New User


Joined: 19 Jan 2007
Posts: 11
Location: bangalore

PostPosted: Fri Nov 23, 2007 6:30 pm    Post subject: Sort and merge 2 files
Reply with quote

Hi,

I have to sort and merge 2 files, but there is no way I can distinguish the detail records from the header and trailer records. Below is an example of how the file would look like

File 1
000000 (Header Record)
111111
333333
222222
000000
999999 (Trailer record)

File 2 (contains only detail record)
777777
999999
888888

and expected output file is

000000 (Header record from file 1)
000000
111111
222222
333333
777777
888888
999999
999999 (Trailer record from File 1)

Please note that the detail record can have records which are same as the header and trailer. As shown above, the detail record have 000000 and 999999 which are equal to the header and trailer respectively.

Could anyone please help me with this.
Back to top
View user's profile Send private message

shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Fri Nov 23, 2007 7:21 pm    Post subject:
Reply with quote

sameetshetty,

Please check with the following code for your requirement.
Code:
// EXEC PGM=ICETOOL                                     
//DFSMSG DD SYSOUT=*                                     
//TOOLMSG DD SYSOUT=*                                   
//FILE1 DD DSN=FILE1,DISP=SHR
//FILE2 DD DSN=FILE2,DISP=SHR     
//HEADER DD DSN=&&HEADER,DISP=(,PASS),SPACE=(TRK,(1,1)) 
//TRAILER DD DSN=&&TRAILER,DISP=(,PASS),SPACE=(TRK,(1,1))
//T1 DD DSN=&&T1,DISP=(,PASS),SPACE=(CYL,(5,5))         
//T2 DD DSN=*.T1,DISP=(OLD,PASS),VOL=REF=*.T1           
//   DD DSN=*.FILE2,DISP=(OLD,PASS),VOL=REF=*.FILE2     
//OUT DD DSN=OUT,DISP=(NEW,CATLG,DELETE),DCB=(FILE1),SPACE=(CYL,(5,5)) 
//TOOLIN DD *                                                     
 COPY FROM(FILE1) TO(HEADER) USING(CTL1)                           
 SORT FROM(FILE1) TO(TRAILER) USING(CTL2)                         
 COPY FROM(HEADER) TO(OUT)                                         
 SORT FROM(T2) TO(OUT) USING(CTL3)                                 
 COPY FROM(TRAILER) TO(OUT)                                       
/*                                                                 
//CTL1CNTL DD *                                                   
 OPTION STOPAFT=1                                                 
/*                                                                 
//CTL2CNTL DD *                                                   
 INREC OVERLAY=(81:SEQNUM,8,ZD)                                   
 SORT FIELDS=(81,8,ZD,D)                                           
 OUTFIL FNAMES=(TRAILER),STARTREC=1,ENDREC=1,OUTREC=(1,80)         
 OUTFIL FNAMES=(T1),OMIT=(81,8,ZD,EQ,1),STARTREC=2,OUTREC=(1,80)   
/*                                                                 
//CTL3CNTL DD *                                                   
 SORT FIELDS=(1,6,CH,A)                                           
/*
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


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

PostPosted: Sat Nov 24, 2007 12:10 am    Post subject:
Reply with quote

sameetshetty,

Shankar's solution will NOT work unless you use a MOD data set for //OUT.

Here's another way to do what you asked for with DFSORT:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD DSN=...  input file1 (FB/80)
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//SYM DD DSN=&&S1,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)
//SYSIN    DD    *
  OPTION COPY
  OUTFIL FNAMES=T1,OVERLAY=(81:C' ',82:SEQNUM,8,ZD)
  OUTFIL FNAMES=SYM,REMOVECC,NODETAIL,
    BUILD=(80X),
    TRAILER1=('LASTR,+',COUNT=(M11,LENGTH=8))
/*
//S2 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//SYMNAMES DD DSN=&&S1,DISP=(OLD,PASS)
//FILE2 DD DSN=...  input file2 (FB/80)
//T1 DD DSN=&&T1,DISP=(OLD,PASS)
//T2 DD DSN=&&T2,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//T3 DD DSN=&&T3,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//TOOLIN DD *
SORT FROM(T1) TO(T2) USING(CTL1)
SORT FROM(FILE2) TO(T3) USING(CTL2)
/*
//CTL1CNTL DD *
  INREC IFOUTLEN=81,
        IFTHEN=(WHEN=INIT,OVERLAY=(81:C'1')),
        IFTHEN=(WHEN=(82,8,ZD,EQ,+1),OVERLAY=(81:C'0')),
        IFTHEN=(WHEN=(82,8,ZD,EQ,LASTR),OVERLAY=(81:C'2'))
  OPTION EQUALS
  SORT FIELDS=(81,1,CH,A,1,6,CH,A)
/*
//CTL2CNTL DD *
  INREC BUILD=(1,80,81:C'1')
  OPTION EQUALS
  SORT FIELDS=(1,6,CH,A)
/*
//S3    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN01 DD DSN=&&T2,DISP=(OLD,PASS)
//SORTIN02 DD DSN=&&T3,DISP=(OLD,PASS)
//SORTOUT DD DSN=...  output file (FB/80)
//SYSIN    DD    *
  OPTION EQUALS
  MERGE FIELDS=(81,1,CH,A,1,6,CH,A)
  OUTREC BUILD=(1,80)
/*
Back to top
View user's profile Send private message
Karthigaiselvan

New User


Joined: 11 Dec 2006
Posts: 35
Location: India

PostPosted: Mon Nov 26, 2007 3:01 pm    Post subject: Reply to: Sort and merge 2 files
Reply with quote

Frank,

Looks awesome.

I'm looking to customizing this job for my requirement posted in the link http://www.ibmmainframes.com/viewtopic.php?t=26216

Though i am not sure if that's possible. Could you please think of any other solution for the requirement i posted in the above link? Thanks!
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


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

PostPosted: Mon Nov 26, 2007 10:02 pm    Post subject:
Reply with quote

I don't see how the requirement here and the requirement in your other post are related.

I posted a solution for the other requirement in that thread.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 15 Thu Dec 01, 2016 8:28 pm
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts Match or compare two files in VB Format anatol DFSORT/ICETOOL 14 Thu Nov 03, 2016 7:41 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us