Sort and merge two files with a condition

In this Mainframe Forum - You can post your queries on DFSORT, ICETOOL , SyncSort & JCL Utilities

Moderators: Frank Yaeger, Moderator Group

Post Reply
Jobin.Luke
Member
Posts: 2
Joined: Mon Aug 09, 2010 4:55 pm

Sort and merge two files with a condition

Post by Jobin.Luke » Mon Aug 09, 2010 5:02 pm

Hi

I have two files. I need to sort it and get a single output file as shown below

File A
====
1
2
3
4
5

File B
====
1
2
3
4
5

Output
=====
1
5
2
4
3
3
4
2
5
1

Can any one give a clue...

Thanks in Advance
Jobin

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Mon Aug 09, 2010 10:30 pm

Huh? How would you expect anyone to help you with this when you haven't given any clue as to what it is you actually want to do? You need to explain the "rules" you want to use for getting from input to output. You can't expect us to guess what you want or read your mind. You have to tell us.
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort

Anuj Dhawan
Moderator
Posts: 1625
Joined: Sat Aug 09, 2008 9:02 am
Location: Mumbai, India

Post by Anuj Dhawan » Tue Aug 10, 2010 12:48 pm

I think - in output:
  • Last record of 2nd input-file is placed after first record of input-file-1 ("5" from input-file-2 comes after "1" from input-file-1 )
  • Second-last record of 2nd input-file is placed after second record of input-file-1("4" from input-file-2 comes after second-record, "2", from input-file-1 )
  • ... and so on...
Hope this helps.
Regards,
Anuj

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Tue Aug 10, 2010 9:28 pm

Yes, that's a good guess and may be correct, but whey should we guess? We need the OP to tell us what HE wants. (Why should we spend time coming up with a solution that might not correspond to what is actually wanted?)
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort

Jobin.Luke
Member
Posts: 2
Joined: Mon Aug 09, 2010 4:55 pm

Post by Jobin.Luke » Wed Aug 25, 2010 11:46 pm

Hi Anuj & Frank,

The assumption is right. Can you please help on this.

Thanks
Jobin

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Thu Aug 26, 2010 12:47 am

Given that assumption, here's a DFSORT/ICETOOL job that will what you asked for. I added F1 and F2 to the input records to show the actual order of the output records.

Code: Select all

//S1    EXEC  PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN1 DD *
1 F1
2 F1
3 F1
4 F1
5 F1
/*
//IN2 DD *
1 F2
2 F2
3 F2
4 F2
5 F2
/*
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(MOD,PASS)
//OUT DD SYSOUT=*
//TOOLIN DD *
COPY FROM(IN1) TO(T1) USING(CTL1)
SORT FROM(IN2) TO(T1) USING(CTL2)
SORT FROM(T1) TO(OUT) USING(CTL3)
/*
//CTL1CNTL DD *
  OUTREC OVERLAY=(81:SEQNUM,8,ZD,START=1,INCR=2)
/*
//CTL2CNTL DD *
  SORT FIELDS=(1,1,CH,D)
  OUTREC OVERLAY=(81:SEQNUM,8,ZD,START=2,INCR=2)
/*
//CTL3CNTL DD *
  SORT FIELDS=(81,8,ZD,A)
  OUTREC BUILD=(1,80)
/*
OUT would have:

Code: Select all

1 F1        
5 F2        
2 F1        
4 F2        
3 F1        
3 F2        
4 F1        
2 F2        
5 F1        
1 F2        
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Thu Aug 26, 2010 12:51 am

Here's an alternate way to do it if you have the DFSORT PTF for the MERGE operator:

Code: Select all

//S2    EXEC  PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN1 DD *
1 F1
2 F1
3 F1
4 F1
5 F1
//IN2 DD *
1 F2
2 F2
3 F2
4 F2
5 F2
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//T2 DD DSN=&&T2,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//OUT DD SYSOUT=*
//TOOLIN DD *
COPY FROM(IN1) TO(T1) USING(CTL1)
SORT FROM(IN2) TO(T2) USING(CTL2)
MERGE FROM(T1,T2) TO(OUT) USING(CTL3)
/*
//CTL1CNTL DD *
  OUTREC OVERLAY=(81:SEQNUM,8,ZD,START=1,INCR=2)
/*
//CTL2CNTL DD *
  SORT FIELDS=(1,1,CH,D)
  OUTREC OVERLAY=(81:SEQNUM,8,ZD,START=2,INCR=2)
/*
//CTL3CNTL DD *
  MERGE FIELDS=(81,8,ZD,A)
  OUTREC BUILD=(1,80)
/*
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort

academyindia4

Topic deleted by Admin

Post by academyindia4 » Mon Jan 25, 2016 10:03 pm

<< Content deleted By Admin >>

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others