Sort and merge two files with a condition
Moderators: Frank Yaeger, Moderator Group
-
- Member
- Posts: 2
- Joined: Mon Aug 09, 2010 4:55 pm
Sort and merge two files with a condition
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
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
- Frank Yaeger
- Moderator
- Posts: 812
- Joined: Sat Feb 18, 2006 5:45 am
- Location: San Jose, CA
- Contact:
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
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
-
- Moderator
- Posts: 1625
- Joined: Sat Aug 09, 2008 9:02 am
- Location: Mumbai, India
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...
Regards,
Anuj
Anuj
- Frank Yaeger
- Moderator
- Posts: 812
- Joined: Sat Feb 18, 2006 5:45 am
- Location: San Jose, CA
- Contact:
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
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
-
- Member
- Posts: 2
- Joined: Mon Aug 09, 2010 4:55 pm
- Frank Yaeger
- Moderator
- Posts: 812
- Joined: Sat Feb 18, 2006 5:45 am
- Location: San Jose, CA
- Contact:
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.
OUT would have:
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)
/*
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
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
- Frank Yaeger
- Moderator
- Posts: 812
- Joined: Sat Feb 18, 2006 5:45 am
- Location: San Jose, CA
- Contact:
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
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
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
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page