{"id":189,"date":"2015-06-13T15:56:39","date_gmt":"2015-06-13T10:26:39","guid":{"rendered":"http:\/\/ibm-mainframes.com\/blog\/?p=189"},"modified":"2015-07-29T23:56:32","modified_gmt":"2015-07-29T18:26:32","slug":"compare-two-files-on-mainframe-syncsort","status":"publish","type":"post","link":"https:\/\/zmainframes.com\/zlog\/compare-two-files-on-mainframe-syncsort\/","title":{"rendered":"Compare two files on mainframe using SyncSort."},"content":{"rendered":"<h4 style=\"text-align: center;\"><span style=\"text-decoration: underline;\">Compare two files\u00a0on mainframe using SyncSort<\/span><\/h4>\n<p style=\"text-align: left;\">As we talked about <a href=\"http:\/\/ibm-mainframes.com\/blog\/?p=95\" target=\"_blank\" rel=\"noopener\">comparing two files using DFSORT and writing matched and unmatched records to the output<\/a>, in this post we&#8217;ll address the same question that compare two files\u00a0on mainframe using SyncSort and write the match &amp; no-match records.<\/p>\n<p>&nbsp;<\/p>\n<p>For the below example some consideration are as follows:<\/p>\n<ol>\n<li>Files are fixed-block, RECFM=FB<\/li>\n<li>Files length is 80, LRECL=80<\/li>\n<li>The key on which the files are compared starts at position and are 7 characters long.<\/li>\n<\/ol>\n<p>With above attributes, the following SORT statements should get you what you want:<\/p>\n<pre class=\"theme:cisco-router lang:default decode:true \">JOINKEYS FILE=F1,FIELDS=(key1startpos,7,A)\r\nJOINKEYS FILE=F2,FIELDS=(key2startpos,7,A)\r\nJOIN UNPAIRED,F1,F2\r\nREFORMAT FIELDS=(F1:1,80,F2:1,80)\r\nSORT FIELDS=COPY<\/pre>\n<p>We need the matched and non-matched records in different files. \u00a0For this in \u00a0DFSORT, there is a matching-marker, specified with ? in the REFORMAT, <a href=\"http:\/\/ibm-mainframes.com\/blog\/?p=95\" target=\"_blank\" rel=\"noopener\">as discussed in the other topic.<\/a><\/p>\n<p>But SyncSort does not have this &#8220;match marker&#8221; available. The absence or presence of data on the REFORMAT record has to be determined by values. Pick a byte on both input records which cannot contain a particular value (for instance, within a number, decide on a non-numeric value). Then specify that value as the FILL character on the REFORMAT.<\/p>\n<pre class=\"theme:cisco-router lang:default decode:true \">REFORMAT FIELDS=(F1:1,80,F2:1,80),FILL=C'#'<\/pre>\n<p>If position 1 on F1 does not have &#8220;#&#8221; as part of data and position 20 on F2 cannot either, then those two positions can be used to establish the result of the match. The entire record can be tested if necessary, but you end up payin gfor more CPU. SyncSort, output unmatched records:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"theme:cisco-router lang:default decode:true \">REFORMAT FIELDS=(F1:1,80,F2:1,80),FILL=C'#'\r\nOUTFIL FNAMES=NOMATCH,INCLUDE=(1,1,CH,EQ,C'#',\r\nOR,100,1,CH,EQ,C'#'),\r\nIFTHEN=(WHEN=(1,1,CH,EQ,C'#'),\r\nBUILD=(1,80)),\r\nIFTHEN=(WHEN=NONE,\r\nBUILD=(81,80))<\/pre>\n<p>Collecting all the pieces, the code for SyncSort would look like this:<\/p>\n<pre class=\"theme:cisco-router lang:default decode:true \">JOINKEYS FILE=F1,FIELDS=(1,7,A)\r\nJOINKEYS FILE=F2,FIELDS=(1,7,A)\r\nJOIN UNPAIRED,F1,F2\r\nREFORMAT FIELDS=(F1:1,80,F2:1,80),FILL=C'#'\r\nSORT FIELDS=COPY\r\nOUTFIL FNAMES=NOMATCH,INCLUDE=(1,1,CH,EQ,C'#',\r\nOR,100,1,CH,EQ,C'#'),\r\nIFTHEN=(WHEN=(1,1,CH,EQ,C'#'),\r\nBUILD=(1,80)),\r\nIFTHEN=(WHEN=NONE,\r\nBUILD=(81,80))\r\nOUTFIL FNAMES=MATCH,SAVE,\r\nBUILD=(1,80)<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Compare two files\u00a0on mainframe using SyncSort As we talked about comparing two files using DFSORT and writing matched and unmatched [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[45,49,48,47,46,44,37,51,50,52],"class_list":["post-189","post","type-post","status-publish","format-standard","hentry","category-sort","tag-ibm","tag-icegener-syncsort","tag-iceman","tag-icetool","tag-jcl","tag-mainframe","tag-mainframes","tag-syncgener","tag-synctool","tag-zos"],"amp_enabled":true,"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"Anuj Dhawan","author_link":"https:\/\/zmainframes.com\/zlog\/author\/anuj-dhawan\/"},"rttpg_comment":279,"rttpg_category":"<a href=\"https:\/\/zmainframes.com\/zlog\/mainframes\/sort\/\" rel=\"category tag\">sort<\/a>","rttpg_excerpt":"Compare two files\u00a0on mainframe using SyncSort As we talked about comparing two files using DFSORT and writing matched and unmatched [&hellip;]","_links":{"self":[{"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/posts\/189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/comments?post=189"}],"version-history":[{"count":10,"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/posts\/189\/revisions"}],"predecessor-version":[{"id":708,"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/posts\/189\/revisions\/708"}],"wp:attachment":[{"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/media?parent=189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/categories?post=189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/tags?post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}