{"id":95,"date":"2015-06-10T19:40:59","date_gmt":"2015-06-10T14:10:59","guid":{"rendered":"http:\/\/ibm-mainframes.com\/blog\/?p=95"},"modified":"2015-07-29T21:28:59","modified_gmt":"2015-07-29T15:58:59","slug":"compare-two-files-on-mainframe-dfsort","status":"publish","type":"post","link":"https:\/\/zmainframes.com\/zlog\/compare-two-files-on-mainframe-dfsort\/","title":{"rendered":"Compare two files on mainframe &#8211; DFSORT."},"content":{"rendered":"<h4 style=\"text-align: center;\"><span style=\"text-decoration: underline;\">Compare two files\u00a0on mainframe\u00a0and write the match &amp; no-match records<\/span><\/h4>\n<p>&nbsp;<\/p>\n<p>If you work in a Mainframe shop &#8211; once in a while you&#8217;ll get to the situation where you&#8217;ll want to compare two files<strong>*<\/strong> and your mind might wander to answer the question in the subject line above heading real quick. You may compare two files on mainframe using DFSORT or possibly SyncSort, however, we&#8217;ll talk about DFSORT in this article.<\/p>\n<p>This can be done using a <em>utility <\/em>(SORT<em>)<\/em> instead of writing a COBOL program. Here, you might also be tempted to ask if writing a program is better or writing a SORT code is &#8211; well, I&#8217;d say we&#8217;ll leave that discussion for other time and for now will discuss about how can we do it using the SORT at your shop.<\/p>\n<p>Your shop can have DFSORT or SyncSort, usually not both of them. After all they are pay-for-product and you would not want to pay twice for the same <em>vehicle<\/em>. DFSORT and SyncSort are the predominant Mainframe sorting products. Their control cards have many similarities, and some differences. We&#8217;ll discuss both of them below.<\/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>Let&#8217;s directly get to the work &#8211; 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>A &#8220;JOINKEYS&#8221; is made up of three Tasks. Sub-Task-1 &#8211; \u00a0is the first JOINKEYS. Sub-Task-2 is the second JOINKEYS. Sub-Task-3, the Main Task, follows and is where the joined data is processed. In the example above it is a simple COPY operation. The joined data will simply be written to SORTOUT.<\/p>\n<p>The JOIN statement defines that as well as matched records, UNPAIRED F1 and F2 records are to be presented to the Main Task.\u00a0The REFORMAT statement defines the record which will be presented to the Main Task.<\/p>\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, as shown below:<\/p>\n<pre class=\"theme:cisco-router lang:default decode:true\">\u00a0REFORMAT FIELDS=(F1:1,80,F2:1,80,?)<\/pre>\n<p>This increases the length of the REFORMAT record by one byte. The ? is optional and can be specified anywhere on the REFORMAT record, and need not be specified. The ? is resolved by DFSORT to: B, data sourced from Both files; 1, unmatched record from F1; 2, unmatched record from F2.<\/p>\n<p>The requirement is for all unmatched records, from either F1 or F2, to be written to one file. This requires a REFORMAT statement which includes both records completely. For DFSORT and SYNCSORT the statements will be different. For SyncSort we&#8217;ll talk later.<\/p>\n<p>DFSORT, output unmatched records:<\/p>\n<pre class=\"theme:cisco-router lang:default decode:true \"> REFORMAT FIELDS=(F1:1,80,F2:1,80,?)\r\n\u00a0 OUTFIL FNAMES=NOMATCH,INCLUDE=(161,1,SS,EQ,C'1,2'),\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 IFTHEN=(WHEN=(161,1,CH,EQ,C'1'),\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BUILD=(1,80)),\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 IFTHEN=(WHEN=NONE,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BUILD=(81,80))<\/pre>\n<p>Getting matched records out are easy:<\/p>\n<pre class=\"theme:cisco-router lang:default decode:true\">\u00a0 OUTFIL FNAMES=MATCH,SAVE<\/pre>\n<p>Putting all pieces together will look like this:<\/p>\n<p><strong>DFSORT:<\/strong><\/p>\n<pre class=\"theme:cisco-router lang:default decode:true\">JOINKEYS FILE=F1,FIELDS=(1,7,A)\r\n\u00a0 JOINKEYS FILE=F2,FIELDS=(1,7,A)\r\n\u00a0 JOIN UNPAIRED,F1,F2\r\n\u00a0 REFORMAT FIELDS=(F1:1,80,F2:1,80,?)\r\n\u00a0 SORT FIELDS=COPY\r\n\u00a0 OUTFIL FNAMES=NOMATCH,INCLUDE=(161,1,SS,EQ,C'1,2'),\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 IFTHEN=(WHEN=(161,1,CH,EQ,C'1'),\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BUILD=(1,80)),\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 IFTHEN=(WHEN=NONE,\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0BUILD=(81,80))\r\n\u00a0 OUTFIL FNAMES=MATCH,SAVE,\r\n\u00a0\u00a0\u00a0\u00a0 BUILD=(1,80)<\/pre>\n<p>&nbsp;<\/p>\n<p>* &#8211; May be you want to compare more files &#8211; but we&#8217;ll pick two files for current post. For more files we might talk later.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Compare two files\u00a0on mainframe\u00a0and write the match &amp; no-match records &nbsp; If you work in a Mainframe shop &#8211; once [&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-95","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":60,"rttpg_category":"<a href=\"https:\/\/zmainframes.com\/zlog\/mainframes\/sort\/\" rel=\"category tag\">sort<\/a>","rttpg_excerpt":"Compare two files\u00a0on mainframe\u00a0and write the match &amp; no-match records &nbsp; If you work in a Mainframe shop &#8211; once [&hellip;]","_links":{"self":[{"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/posts\/95","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=95"}],"version-history":[{"count":11,"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/posts\/95\/revisions"}],"predecessor-version":[{"id":474,"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/posts\/95\/revisions\/474"}],"wp:attachment":[{"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/media?parent=95"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/categories?post=95"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zmainframes.com\/zlog\/wp-json\/wp\/v2\/tags?post=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}