MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SORT - Write to two files

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
mf_user
Intermediate


Joined: 01 Jun 2003
Posts: 372
Topics: 105

PostPosted: Thu Sep 16, 2010 9:39 am    Post subject: SORT - Write to two files Reply with quote

Hi,

Input file: LRECL=80, RECFM=FB.

INPUT:
Code:

HDRXXXCOUNT00006
DTL00001
DTL00002
DTL00003
DTL00004
HDRXXXCOUNT00006
DTL00001
DTL00002
DTL00003
DTL00004
DTL00005
DTL00006
HDRXXXCOUNT00005
DTL00001
DTL00002
DTL00003
DTL00004
DTL00005


The above given input file has total number of detail records count given in header at 12th column followed by no. of details records. It is evident that the total count between header and no. of detail records does not match in first set of records.

Expected OUTPUT:

Output-File-1: BAD set of records
Code:

HDRXXXCOUNT00006
DTL00001
DTL00002
DTL00003
DTL00004

Output-File-2: GOOD sets of records
Code:

HDRXXXCOUNT00006
DTL00001
DTL00002
DTL00003
DTL00004
DTL00005
DTL00006
HDRXXXCOUNT00005
DTL00001
DTL00002
DTL00003
DTL00004
DTL00005


Would you please let me know how to split good sets of records into one output file and bad set of records into another output file after comparing the count in header and no.of detail records?

Thanks.
_________________
MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
==
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Thu Sep 16, 2010 10:28 am    Post subject: Reply with quote

mf_user,

Use the following DFSORT JCL which will give you the desired results

Code:

//STEP0100 EXEC PGM=SORT           
//SYSOUT   DD SYSOUT=*             
//INA      DD DSN=Your input FB 80 byte file,DISP=SHR
//INB      DD DSN=same input FB 80 byte file,DISP=SHR
//GOODREC  DD SYSOUT=*                                             
//BADREC   DD SYSOUT=*                                             
//SYSIN    DD *                                                   
  OPTION COPY                                                     
  JOINKEYS F1=INA,FIELDS=(86,8,A),SORTED,NOSEQCK                   
  JOINKEYS F2=INB,FIELDS=(09,8,A)                                 
  JOIN UNPAIRED                                                   
  REFORMAT FIELDS=(F1:1,85,F2:4,5)                                 
  OUTFIL FNAMES=BADREC,INCLUDE=(81,5,ZD,NE,86,5,ZD),BUILD=(1,80)   
  OUTFIL FNAMES=GOODREC,SAVE,BUILD=(1,80)                         
//*                                                               
//JNF1CNTL DD *                                                   
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,3,CH,EQ,C'HDR'),               
        PUSH=(81:12,5,ID=8))                                       
//*                                                               
//JNF2CNTL DD *                                                   
  INREC IFTHEN=(WHEN=INIT,BUILD=(1,3,C'00001')),                   
  IFTHEN=(WHEN=GROUP,BEGIN=(1,3,CH,EQ,C'HDR'),PUSH=(9:ID=8)),     
  IFTHEN=(WHEN=(1,3,CH,EQ,C'HDR'),OVERLAY=(8:C'0'))               
  SUM FIELDS=(4,5,ZD)                                             
//*

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mf_user
Intermediate


Joined: 01 Jun 2003
Posts: 372
Topics: 105

PostPosted: Thu Sep 16, 2010 11:38 am    Post subject: Reply with quote

Kolusu, I thought it takes some time for me to understand this solution though it has given me desired result bonk

Would you please let me know why to use SORTED,NOSEQCK on first file alone !?

Thanks a lot.
_________________
MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
==
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Thu Sep 16, 2010 12:32 pm    Post subject: Reply with quote

mf_user wrote:
Kolusu, I thought it takes some time for me to understand this solution though it has given me desired result bonk

Would you please let me know why to use SORTED,NOSEQCK on first file alone !?

Thanks a lot.


The solution is quite simple

1. Using When=group keyword we number the groups and we know that it is already in the sequence since we are generating the ID using PUSH in pos 86. This is how the data looks like from JNF1CNTL. The key we are using to sort is in pos 86 which is already in the sorted order. So we don't need to sort it. SORTED,NOSEQCK will override the sort statement of JNF1 with a COPY statement.

Code:

RECORD                                  COUNT  ID     
(1-80)                                  81-85  86-93 
======================================= ===== ========
HDRXXXCOUNT00006                        00006 00000001
DTL00001                                00006 00000001
DTL00002                                00006 00000001
DTL00003                                00006 00000001
DTL00004                                00006 00000001
HDRXXXCOUNT00006                        00006 00000002
DTL00001                                00006 00000002
DTL00002                                00006 00000002
DTL00003                                00006 00000002
DTL00004                                00006 00000002
DTL00005                                00006 00000002
DTL00006                                00006 00000002
HDRXXXCOUNT00005                        00005 00000003
DTL00001                                00005 00000003
DTL00002                                00005 00000003
DTL00003                                00005 00000003
DTL00004                                00005 00000003
DTL00005                                00005 00000003



but for the second file we are just getting 1 record per group. before the sum statement this is how the records look. For the sum to work we need a sort statement.

Code:

IND CONST  ID     
1-3 4-8   9-16     
=== ===== ========
HDR 00000 00000001
DTL 00001 00000001
DTL 00001 00000001
DTL 00001 00000001
DTL 00001 00000001
HDR 00000 00000002
DTL 00001 00000002
DTL 00001 00000002
DTL 00001 00000002
DTL 00001 00000002
DTL 00001 00000002
DTL 00001 00000002
HDR 00000 00000003
DTL 00001 00000003
DTL 00001 00000003
DTL 00001 00000003
DTL 00001 00000003
DTL 00001 00000003


after the sum statement , the records looks like this

Code:

IND CONST  ID     
1-3 4-8   9-16     
=== ===== ========
HDR 00004 00000001
HDR 00006 00000002
HDR 00005 00000003


Now the match is done on the id from both files and the no:of details records is tagged at the end of file1 record and compared on OUTFIL with INCLUDE
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mf_user
Intermediate


Joined: 01 Jun 2003
Posts: 372
Topics: 105

PostPosted: Fri Sep 17, 2010 3:52 am    Post subject: Reply with quote

Thanks a lot for the detail explanation. It is lot helpful.
_________________
MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
==
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group