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 Utility to save excluded records to a different dataset
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Tue Jun 03, 2008 11:25 am    Post subject: SORT Utility to save excluded records to a different dataset Reply with quote

Members,

I have a dataset with 10 records as below and the SORT card is created by a program in STEP1 which i am making use of it in this step and i am showing it in SYSIN for understanding purpose.

Code:

//STEP020 EXEC PGM=SORT
//SYSRINT DD SYSOUT=*
//SYSOUT  DD SYSOUT=*
//SORTIN  DD *
ABC
DEF
XYZ
A11
GHJ
ACC
YYY
BBB
KKK
LLL
/*
//SORTOUT DD DSN=USERID.TEST.OUT1,DISP=SHR
//SYSIN   DD *
  INCLUDE COND=(1,1,CH,EQ,C'A)
  SORT FIELDS=COPY
/*

Now when i run this job in the SORTOUT Dataset USERID.TEST.OUT1 i will have 3 records
Code:

ABC
A11
ACC

Now what i want is i want to store the 7 excluded records in a different dataset say USERID.TEST.OUT2 in the same step if possible.

So i expect USERID.TEST.OUT2
Code:

DEF
XYZ
GHJ
YYY
BBB
KKK
LLL

If it is possible can anybody help me out .

I have one more question ,can we form a SORT code like below to use in the same step2 code at run time as it is a batch JCL which will also solve the process.
Code:

  INCLUDE COND=(1,1,CH,NE,C'A)
  SORT FIELDS=COPY


Thanks.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Jun 03, 2008 12:07 pm    Post subject: Reply with quote

yadav2005,

Use the following DFSORT JCL
Code:

//STEP020 EXEC PGM=SORT
//SYSRINT DD SYSOUT=*
//SYSOUT  DD SYSOUT=*
//SORTIN  DD *
ABC
DEF
XYZ
A11
GHJ
ACC
YYY
BBB
KKK
LLL
/*
//OUT1    DD SYSOUT=*
//OUT2    DD SYSOUT=*
//SYSIN   DD *
  SORT FIELDS=COPY
  OUTFIL FNAMES=OUT1,INCLUDE=(1,1,CH,EQ,C'A)
  OUTFIL FNAMES=OUT2,SAVE
/*

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu


Last edited by kolusu on Fri Jun 06, 2008 10:13 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Sun Jun 08, 2008 11:44 am    Post subject: Reply with quote

Kolusu,

I could understand the problem why it did not work at the first time and i am clear.

Now i have a question the SORT CARD created by the program in step1 could be of the following types based on some conditions:
Code:

    SORT FIELDS=(541,10,CH,A,1,41,CH,A)

or
Code:

    SORT FIELDS=(541,10,CH,A,1,41,CH,A)
    INCLUDE COND=(541,3,CH,NE,C'111')

or
Code:

    SORT FIELDS=(541,10,CH,A,1,41,CH,A)
    INCLUDE COND=(541,3,CH,NE,C'111',AND,                                     
                  541,3,CH,NE,C'123',AND,
                  541,3,CH,NE,C'126')

And there could be only 10 maximum conditions in the INCLUDE condition as these values could be populated from an array of maximum 10 elements , how can i form the sort code for step 2 to look something like based on conditons:
Code:

//SYSIN   DD *                                                         
  SORT FIELDS=(541,10,CH,A,1,41,CH,A)                                                     
/*
If i my SORT FIELDS has no include condition then how can i save the excluded records which means there will no exluded records.

OR
Code:

//SYSIN   DD *
  SORT FIELDS=(541,10,CH,A,1,41,CH,A)
  OUTFIL FNAMES=OUT1,INCLUDE=(541,3,CH,NE,C'111')
  OUTFIL FNAMES=OUT2,SAVE
/*

OR
Code:

//SYSIN   DD *
  SORT FIELDS=(541,10,CH,A,1,41,CH,A)
  OUTFIL FNAMES=OUT1,INCLUDE=(541,3,CH,NE,C'111',AND,
                              541,3,CH,NE,C'123',AND,
                              541,3,CH,NE,C'126')
  OUTFIL FNAMES=OUT2,SAVE
/*
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Mon Jun 09, 2008 9:47 am    Post subject: Reply with quote

Quote:
If i my SORT FIELDS has no include condition then how can i save the excluded records which means there will no exluded records.


Huh? If there are no excluded records, then how can you save them? If you just have a SORT statement with an OUTFIL INCLUDE statement, then only the included records will be written to the OUTFIL data set.

If you want to use OUTFIL statements and write all of the records to one data set and none of the records to another data set, you can use DFSORT control statements like this:

Code:

//SYSIN   DD *
  SORT FIELDS=(541,10,CH,A,1,41,CH,A)
  OUTFIL FNAMES=OUT1,INCLUDE=ALL
  OUTFIL FNAMES=OUT2,SAVE
/*

_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Mon Jun 09, 2008 10:41 am    Post subject: Reply with quote

Frank,

Thanks for your reply and i am able to understand.But here my requirement is how to format the SORT card to be used in step2.

Say for example Step1 generated the SORT code by the Program as
Code:

  SORT FIELDS=(541,10,CH,A,1,41,CH,A)

then how to form the Sort code as
Code:

  SORT FIELDS=(541,10,CH,A,1,41,CH,A)
  OUTFIL FNAMES=OUT1,INCLUDE=ALL
  OUTFIL FNAMES=OUT2,SAVE

which means there will be no records to OUT2


Say for example Step1 generated the SORT code by the Program as
Code:

    SORT FIELDS=(541,10,CH,A,1,41,CH,A)
    INCLUDE COND=(541,3,CH,NE,C'111')

then how to form the Sort code as
Code:

  SORT FIELDS=(541,10,CH,A,1,41,CH,A)
  OUTFIL FNAMES=OUT1,INCLUDE=(541,3,CH,NE,C'111')
  OUTFIL FNAMES=OUT2,SAVE

Say for example Step1 generated the SORT code by the Program as
Code:

    SORT FIELDS=(541,10,CH,A,1,41,CH,A)
    INCLUDE COND=(541,3,CH,NE,C'111',AND,                                     
                  541,3,CH,NE,C'123',AND,
                  541,3,CH,NE,C'126')

then how to form the Sort code as
Code:

  SORT FIELDS=(541,10,CH,A,1,41,CH,A)
  OUTFIL FNAMES=OUT1,INCLUDE=(541,3,CH,NE,C'111',AND,
                              541,3,CH,NE,C'123',AND,
                              541,3,CH,NE,C'126')
  OUTFIL FNAMES=OUT2,SAVE

Please let me know how we can form the SORT CODE to be used in Step 2 and there can be maximum 10 conditions in the Include statement as they get populated from an array of 10 elements.
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Mon Jun 09, 2008 2:15 pm    Post subject: Reply with quote

I don't know what you mean by "how we can form the SORT CODE to be used in Step 2".

If you have a program that is generating the SORT statement, just have it generate the OUTFIL statements as well.
_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Tue Jun 10, 2008 2:17 am    Post subject: Reply with quote

Frank,

What i mean exactly is the step1 generates the SORT code which can be of different conditions , now i have to use a sort card formated to have OUTFIL statements in Step 2 for that how i can form the SORT code without doing in the program.

Hope i am clear in my question.Thanks.
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Tue Jun 10, 2008 3:15 am    Post subject: Reply with quote

My interpretation is that you have a step that generates a sort control record and this can have 1 or more lines. These reocrds are writtne to a file which are then used as SYSIN in the sort step.You do not want to change the program (why?) to add an OUTFIL statement but want that added to the sort control records. Why do you not put the O~UTFIL statement into a separate file and concatenate it to the sort step's SYSIN?
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Tue Jun 10, 2008 5:36 am    Post subject: Reply with quote

Frank,

Thanks for your help so far.I am sorry and i am wrong in my understanding.Basically the SORT code created by the program will be of the format:
Code:

    SORT FIELDS=(541,10,CH,A,1,41,CH,A)
    INCLUDE COND=(541,3,CH,NE,C'111')

OR

    SORT FIELDS=(541,10,CH,A,1,41,CH,A)
    INCLUDE COND=(541,3,CH,NE,C'111',AND,                                     
                  541,3,CH,NE,C'123',AND,
                  541,3,CH,NE,C'126')
OR
SOMETHING DIFFERENT

There could be maximum 10 different conditions in the INCLUDE COND as they get populated from an array.

Now my question is i want to use the dataset created by the program with SORT CODE as shown above and form a formatted SORT CODE as below which i can use as a SORT CODE in further step down , please help me how i can generate the formatted SORT CODE
and i do not want to change the program.
Code:

    SORT FIELDS=(541,10,CH,A,1,41,CH,A)
    OUTFIL FNAMES=OUT1,INCLUDE=(541,3,CH,NE,C'111')
    OUTFIL FNAMES=OUT2,SAVE

OR
    SORT FIELDS=(541,10,CH,A,1,41,CH,A)
    OUTFIL FNAMES=OUT1,INCLUDE=(541,3,CH,NE,C'111',AND,                                     
                                541,3,CH,NE,C'123',AND,
                                541,3,CH,NE,C'126')
    OUTFIL FNAMES=OUT2,SAVE
OR
SOMETHING DIFFERENT

Thanks for your help.
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Tue Jun 10, 2008 11:47 am    Post subject: Reply with quote

Here's a DFSORT job that will take the control statements generated by your program and convert them to the control statements you want. I'm assuming your program generates the DFSORT INCLUDE statement with 'INCLUDE COND=' starting in position 5.

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD DSN=... input file (FB/80)
//SORTOUT DD DSN=...  output file (FB/80)
//SYSIN    DD    *
  OPTION COPY
  OUTFIL REMOVECC,IFOUTLEN=80,
    IFTHEN=(WHEN=(5,13,CH,EQ,C'INCLUDE COND='),
      BUILD=(3:C'OUTFIL FNAMES=OUT1,',/,
        10:C'INCLUDE',17,50)),
    TRAILER1=(3:C'OUTFIL FNAMES=OUT2,SAVE')
/*


If SORTIN contained:

Code:

    SORT FIELDS=(541,10,CH,A,1,41,CH,A)     
    INCLUDE COND=(541,3,CH,NE,C'111',AND,   
                  541,3,CH,NE,C'123',AND,   
                  541,3,CH,NE,C'126')       


SORTOUT would contain:

Code:

    SORT FIELDS=(541,10,CH,A,1,41,CH,A)         
  OUTFIL FNAMES=OUT1,                           
         INCLUDE=(541,3,CH,NE,C'111',AND,       
                  541,3,CH,NE,C'123',AND,       
                  541,3,CH,NE,C'126')           
  OUTFIL FNAMES=OUT2,SAVE                       

_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
CraigG
Intermediate


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Tue Jun 10, 2008 11:56 am    Post subject: Reply with quote

Confused That is much better, now an incomplete set of sort control cards are created in one step and they are then manipulated in a second step before being used in the third step. That is much better then admitting that the original program to produce the sort control cards needed to be changed.
Back to top
View user's profile Send private message
sriramla
Beginner


Joined: 22 Feb 2003
Posts: 74
Topics: 1

PostPosted: Tue Jun 10, 2008 3:15 pm    Post subject: Reply with quote

Craig, while I understand your comment about changing the original program I could see some reason as why the original program should not be changed - one of the reasons could be that its a common program used in many places and this specific customization OUTFIL FNAMES=OUT2,SAVE may be applicable only in this JCL. You don't want to change all the other JCL's to have OUT2 dd name dummied out. Again, this is just my guess and may not be the actual reason by original poster...
Back to top
View user's profile Send private message
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Mon Jun 16, 2008 10:22 am    Post subject: Reply with quote

Frank & Kolusu,

Thanks a lot for the needful help and the code worked fine.
Back to top
View user's profile Send private message
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Mon Jul 14, 2008 8:14 am    Post subject: Reply with quote

Frank / Kolusu,

I have a question in the solution given where i am facing problems:

The code is working fine if there were include conditions in the SORTIN
Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD DSN=... input file (FB/80)
//SORTOUT DD DSN=...  output file (FB/80)
//SYSIN    DD    *
  OPTION COPY
  OUTFIL REMOVECC,IFOUTLEN=80,
    IFTHEN=(WHEN=(5,13,CH,EQ,C'INCLUDE COND='),
      BUILD=(3:C'OUTFIL FNAMES=OUT1,',/,
        10:C'INCLUDE',17,50)),
    TRAILER1=(3:C'OUTFIL FNAMES=OUT2,SAVE')
/*


If SORTIN contained:
Code:


    SORT FIELDS=(541,10,CH,A,1,41,CH,A)     
    INCLUDE COND=(541,3,CH,NE,C'111',AND,   
                  541,3,CH,NE,C'123',AND,   
                  541,3,CH,NE,C'126')       


SORTOUT would contain:
Code:



    SORT FIELDS=(541,10,CH,A,1,41,CH,A)         
  OUTFIL FNAMES=OUT1,                           
         INCLUDE=(541,3,CH,NE,C'111',AND,       
                  541,3,CH,NE,C'123',AND,       
                  541,3,CH,NE,C'126')           
  OUTFIL FNAMES=OUT2,SAVE                       


But if SORTIN contained only:
Code:


    SORT FIELDS=(541,10,CH,A,1,41,CH,A)     


Then SORTOUT would contain:
Code:


    SORT FIELDS=(541,10,CH,A,1,41,CH,A)
    OUTFIL FNAMES=OUT2,SAVE


What happens by Frank's code is it will not find any include cond and it will make OUT1 as empty dataset and OUT2 as a dataset with records exactly copied into OUT2 which is not the requirement for me.So what i have done is:
Code:


 OPTION COPY                                                                   
 OUTFIL REMOVECC,IFOUTLEN=80,                                                   
        IFTHEN=(WHEN=(5,13,CH,EQ,C'INCLUDE COND='),                             
          BUILD=(5:C'OUTFIL FNAMES=OUT1,',/,                                   
                10:C'INCLUDE',17,50)),                                         
        IFTHEN=(WHEN=NONE,                                                     
          BUILD=(5:C'SORT FIELDS=(541,10,CH,A,1,41,CH,A),',/,         
                 5:C'OUTFIL FNAMES=OUT1')),                                   
        TRAILER1=(5:C'OUTFIL FNAMES=OUT2,SAVE')                               



It is creating OUT1 with records as well as OUT2 with records but the SORT i guess is treating it in a different way and what is happening is if the input file has 100 records in this case where there were no include cond , OUT1 is having 100 records with lot of mismatches and OUT2 is having more than 100 records and i am really not sure why is this happening.Please help me to solve this problem.Is it because of the SORT FIELDS ? As per the logic OUT1 should have 100 records exactly as SORTIN has and OUT2 should be empty in this case.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Mon Jul 14, 2008 10:25 am    Post subject: Reply with quote

yadav2005,

If your input contained only
Code:
SORT FIELDS=(541,10,CH,A,1,41,CH,A)   
, do you need to copy the entire file into one file? ie. OUT1 and Out2 would be an empty file?
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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