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

Merge files with a key and insert a blank line if key change


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

New User


Joined: 03 Nov 2022
Posts: 12
Location: INDIA

PostPosted: Wed Nov 09, 2022 12:04 am
Reply with quote

Merge 2 files with a key and insert a blank line if key changes.
Both files have same layout and PS, LRECL=80.
Key length is 9, STARTPOS= 12.
Key is repeatable in both files. Both input files are already sorted by the key. It is not necessary that key in INPUT-FILE1 file always has matching records in INPUT-FILE2 and vice versa.
Code:

----+----1----+----2----+----3----+----4----+----5
INPUT-FILE1 :
FILE1-L1W1 F1K1     FILE1-L1W2FILE1-L1W3
FILE1-L2W1 F1K1     FILE1-L2W2FILE1-L2W3
FILE1-L3W1 F1K2     FILE1-L3W2FILE1-L3W3
FILE1-L4W1 F1K3     FILE1-L4W2FILE1-L4W3
FILE1-L5W1 F1K3     FILE1-L5W2FILE1-L5W3
FILE1-L6W1 F1K3     FILE1-L6W2FILE1-L6W3

----+----1----+----2----+----3----+----4----+----5
INPUT-FILE2 :
FILE2-L1W1 F1K1     FILE2-L1W2FILE2-L1W3
FILE2-L2WA F1K1     FILE2-L2WBFILE2-L2WC
FILE2-L3W1 F1K3     FILE2-L3W2FILE2-L3W3
FILE2-L4W1 F1K3     FILE2-L4W2FILE2-L4W3
FILE2-L5W1 F1K4     FILE2-L5W2FILE2-L5W3
FILE2-L6W1 F1K4     FILE2-L6W2FILE2-L6W3
FILE2-L7W1 F1K5     FILE2-L7W2FILE2-L7W3

----+----1----+----2----+----3----+----4----+----5
OUTPUT-FILE :
FILE1-L1W1 F1K1     FILE1-L1W2FILE1-L1W3
FILE1-L2W1 F1K1     FILE1-L2W2FILE1-L2W3
FILE2-L1W1 F1K1     FILE2-L1W2FILE2-L1W3
FILE2-L2WA F1K1     FILE2-L2WBFILE2-L2WC

FILE1-L3W1 F1K2     FILE1-L3W2FILE1-L3W3

FILE1-L4W1 F1K3     FILE1-L4W2FILE1-L4W3
FILE1-L5W1 F1K3     FILE1-L5W2FILE1-L5W3
FILE1-L6W1 F1K3     FILE1-L6W2FILE1-L6W3
FILE2-L3W1 F1K3     FILE2-L3W2FILE2-L3W3
FILE2-L4W1 F1K3     FILE2-L4W2FILE2-L4W3

FILE2-L5W1 F1K4     FILE2-L5W2FILE2-L5W3
FILE2-L6W1 F1K4     FILE2-L6W2FILE2-L6W3

FILE2-L7W1 F1K5     FILE2-L7W2FILE2-L7W3

I know this can be done using SORT-JOINKEYS. But I don't know how to write it. When refering few topics here, some code like below will do; but I dont know what to write in JNF1& JNF2 control cards and how to insert blank lines.
Code:

//JOINSTEP EXEC PGM=SORT
//IN1      DD DISP=SHR,DSN=<INPUT-FILE1>
//IN2      DD DISP=SHR,DSN=<INPUT-FILE2>
//SORTOUT  DD DISP=SHR,DSN=<OUTPUT-FILE>
//SYSIN DD *
  JOINKEYS F1=IN1,FIELDS=(12,9,A),SORTED,NOSEQCK
  JOINKEYS F2=IN2,FIELDS=(12,9,A),SORTED,NOSEQCK
  JOIN UNPAIRED,F1,F2,ONLY
  OPTION COPY
  OUTREC BUILD=(1,80)
//JNF1CNTL DD *
  INREC OVERLAY=?
//JNF2CNTL DD *
  INREC OVERLAY=?
/*
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Wed Nov 09, 2022 12:25 am
Reply with quote

Those statements are not needed for your task:
Code:
  JOIN UNPAIRED,F1,F2,ONLY

Code:
//JNF1CNTL DD *
  INREC OVERLAY=?
//JNF2CNTL DD *
  INREC OVERLAY=?

This statement must be added, to format a combined line properly:
Code:
  REFORMAT FIELDS=(F1:...,F2:...)


In order to insert empty lines, read about
Code:
 OUTFIL ...,SECTIONS=(...,HEADER3=,...TRAILER3=...)


That's it.
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1252
Location: Bamberg, Germany

PostPosted: Wed Nov 09, 2022 7:17 pm
Reply with quote

Better approach would be to use MERGE instead of JOINKEYS. Your input is already sorted, so only the OUTFIL SECTIONS is required after the merge. The result from my test:
Code:
****** **************************** Datenanfang *******
000001 FILE1-L1W1 F1K1     FILE1-L1W2FILE1-L1W3       
000002 FILE1-L2W1 F1K1     FILE1-L2W2FILE1-L2W3       
000003 FILE2-L1W1 F1K1     FILE2-L1W2FILE2-L1W3       
000004 FILE2-L2WA F1K1     FILE2-L2WBFILE2-L2WC       
000005                                                 
000006 FILE1-L3W1 F1K2     FILE1-L3W2FILE1-L3W3       
000007                                                 
000008 FILE1-L4W1 F1K3     FILE1-L4W2FILE1-L4W3       
000009 FILE1-L5W1 F1K3     FILE1-L5W2FILE1-L5W3       
000010 FILE1-L6W1 F1K3     FILE1-L6W2FILE1-L6W3       
000011 FILE2-L3W1 F1K3     FILE2-L3W2FILE2-L3W3       
000012 FILE2-L4W1 F1K3     FILE2-L4W2FILE2-L4W3       
000013                                                 
000014 FILE2-L5W1 F1K4     FILE2-L5W2FILE2-L5W3       
000015 FILE2-L6W1 F1K4     FILE2-L6W2FILE2-L6W3       
000016                                                 
000017 FILE2-L7W1 F1K5     FILE2-L7W2FILE2-L7W3       
****** **************************** Datenende *********
Back to top
View user's profile Send private message
justjpr

New User


Joined: 03 Nov 2022
Posts: 12
Location: INDIA

PostPosted: Thu Nov 10, 2022 1:13 pm
Reply with quote

Thank you Joerg.Findeisen for working on my request. BTW you posted the result (looks good), but not the SORTCARD that you have used. Please post SORTCARD also, that is very useful to me.
FYI. I started learning JOINKEYS, SECTIONS, SPLICE etc.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Thu Nov 10, 2022 6:22 pm
Reply with quote

Always search before posting and try with closest solution you find and then post if it still not working.
Joerg may have not given ready solution purposely to let you try.
See here is the link to how it’s done. Trailer will add spaces once key changes in sections and now you can get it to work.
ibmmainframes.com/about60093.html
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Thu Nov 10, 2022 6:49 pm
Reply with quote

justjpr wrote:
Thank you Joerg.Findeisen for working on my request. BTW you posted the result (looks good), but not the SORTCARD that you have used. Please post SORTCARD also, that is very useful to me.
FYI. I started learning JOINKEYS, SECTIONS, SPLICE etc.

Much more useful for you would be: learning how to do your own job, not only how to use the result of others work as if it was done by yourself.
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1252
Location: Bamberg, Germany

PostPosted: Mon Nov 14, 2022 12:08 pm
Reply with quote

Assign DD:SORTIN01 and DD:SORTIN02 accordingly, then this minimalistic snippet should work.

Code:
MERGE FIELDS=(12,9,CH,A,1,11,CH,A)
OUTFIL SECTIONS=(12,9,SKIP=L)
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 Write line by line from two files DFSORT/ICETOOL 7
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Merge two VSAM KSDS files into third ... JCL & VSAM 6
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
Search our Forums:

Back to Top