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

Need better approach to create a sort card


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

New User


Joined: 17 Mar 2009
Posts: 27
Location: Bangalore

PostPosted: Thu Mar 08, 2018 5:59 pm
Reply with quote

Hello,

I need to generate a sort card using the values present in a dataset.

Input:
Code:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
1    INVALIDVALUE   X'BA'     C'_'                                     
2    INVALIDVALUE   X'BB'     C'_'                                     
3    INVALIDVALUE   X'39'     C'__'                                     
4    INVALIDVALUE   X'41'     C'__'                                     
5    VALIDVALUE     X'C1'     C'A'                                     
6    INVALIDVALUE   X'5C'     C'_'                                     
7    INVALIDVALUE   X'54'     C'__'                                     
8    INVALIDVALUE   X'69'     C'__'                                     
9    INVALIDVALUE   X'BA'     C'_'                                     
10   VALIDVALUE     X'40'     C' '                                     
**************************** Bottom of Data ****************************



Outptut:
Code:

***************************** Top of Data ******************************
 OPTION COPY                                                           
 INREC IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'BA',C'_'))),                 
       IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'BB',C'_'))),                 
       IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'39',C'__'))),               
       IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'41',C'__'))),               
       IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'5C',C'_'))),                 
       IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'54',C'__'))),               
       IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'69',C'__')))                 
**************************** Bottom of Data ****************************


I was able to generate the output, but its a crude way of doing it and it involved many steps to achieve the needful. Can anyone help me with a better approach like getting it done in a fewer steps ?

Here is my code

Code:

//**********************************************************************
//*                                                                     
//PS002   EXEC PGM=SORT                                                 
//SYSOUT   DD  SYSOUT=*                                                 
//SYSPRINT DD  SYSOUT=*                                                 
//SYSUDUMP DD  SYSOUT=*                                                 
//SORTIN   DD  *                                                       
1    INVALIDVALUE   X'BA'     C'_'                                     
2    INVALIDVALUE   X'BB'     C'_'                                     
3    INVALIDVALUE   X'39'     C'__'                                     
4    INVALIDVALUE   X'41'     C'__'                                     
5    VALIDVALUE     X'C1'     C'A'                                     
6    INVALIDVALUE   X'5C'     C'_'                                     
7    INVALIDVALUE   X'54'     C'__'                                     
8    INVALIDVALUE   X'69'     C'__'                                     
9    INVALIDVALUE   X'BA'     C'_'                                     
10   VALIDVALUE     X'40'     C' '                                     
/*                                                                     
//*                                                                     
//SORTOUT  DD  DSN=OUTPUT.FILE1,                                       
//             DISP=(NEW,CATLG,DELETE),                                 
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)                       
//*                                                                     
//SYSIN    DD  *                                                       
  OPTION COPY                                                           
  INCLUDE COND=(6,12,CH,EQ,C'INVALIDVALUE')                             
  OUTREC BUILD=(01:1X,                                                 
    02:C'INREC IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(',                     
    42:21,5,                                                           
    47:C',',                                                           
    48:31,5,                                                           
    53:C'))),',                                                         
    57:24X)                                                             
//*                                                                     
//**********************************************************************
//** STEP TO REMOVE SPACES IN THE FILE                                 *
//**********************************************************************
//*                                                                     
//PS004   EXEC PGM=SORT                                                 
//SYSOUT   DD  SYSOUT=*                                                 
//SYSPRINT DD  SYSOUT=*                                                 
//SYSUDUMP DD  SYSOUT=*                                                 
//SORTIN   DD  DISP=SHR,DSN=OUTPUT.FILE1                               
//SORTOUT  DD  DSN=OUTPUT.FILE2,                                       
//             DISP=(NEW,CATLG,DELETE),                                 
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)                       
//*                                                                     
//SYSIN    DD  *                                                       
  OPTION COPY                                                           
  OUTREC BUILD=(01:1,40,                                               
                41:41,40,SQZ=(SHIFT=LEFT))                             
//*                                                                     
//**********************************************************************
//**********************************************************************
//*   SEPARATE THE HEADER RECORD                                       
//**********************************************************************
//PS006 EXEC  PGM=ICETOOL                                               
//SYSOUT   DD  SYSOUT=*                                                 
//DFSMSG   DD  SYSOUT=*                                                 
//TOOLMSG  DD  SYSOUT=*                                                 
//IN       DD  DISP=SHR,DSN=OUTPUT.FILE2                               
//OUT      DD  DSN=OUTPUT.HDR,                                         
//             DISP=(NEW,CATLG,DELETE),                                 
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)                       
//TOOLIN   DD  *                                                       
  SUBSET FROM(IN) TO(OUT) KEEP INPUT FIRST                             
/*                                                                     
//*                                                                     
//**********************************************************************
//**********************************************************************
//*   COPY DETAIL RECORDS AND TRALER RECORD                             
//**********************************************************************
//PS008 EXEC  PGM=ICETOOL                                               
//SYSOUT   DD  SYSOUT=*                                                 
//DFSMSG   DD  SYSOUT=*                                                 
//TOOLMSG  DD  SYSOUT=*                                                 
//IN       DD  DISP=SHR,DSN=OUTPUT.FILE2                               
//OUT      DD  DSN=OUTPUT.FILE3,                                       
//             DISP=(NEW,CATLG,DELETE),                                 
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)                       
//TOOLIN   DD    *                                                     
  SUBSET FROM(IN) TO(OUT) REMOVE INPUT FIRST                           
/*                                                                     
//*                                                                     
//**********************************************************************
//**********************************************************************
//*   REPLACE INREC WITH SPACES                                         
//**********************************************************************
//*                                                                     
//PS010   EXEC PGM=SORT                                                 
//SYSOUT   DD  SYSOUT=*                                                 
//SYSPRINT DD  SYSOUT=*                                                 
//SYSUDUMP DD  SYSOUT=*                                                 
//SORTIN   DD  DISP=SHR,DSN=OUTPUT.FILE3                               
//SORTOUT  DD  DSN=OUTPUT.FILE4,                                       
//             DISP=(NEW,CATLG,DELETE),                                 
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)                       
//*                                                                     
//SYSIN    DD  *                                                       
  OPTION COPY                                                           
  INREC IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'INREC',C'     ')))         
//*                                                                     
//**********************************************************************
//**********************************************************************
//*   COPY ALL THE RECORDS EXCEPT THE TRAILER RECORD                   
//**********************************************************************
//PS012 EXEC  PGM=ICETOOL                                               
//SYSOUT   DD  SYSOUT=*                                                 
//DFSMSG   DD  SYSOUT=*                                                 
//TOOLMSG  DD  SYSOUT=*                                                 
//IN       DD  DISP=SHR,DSN=OUTPUT.FILE4                               
//OUT      DD  DSN=OUTPUT.DTL,                                         
//             DISP=(NEW,CATLG,DELETE),                                 
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)                       
//TOOLIN   DD    *                                                     
  SUBSET FROM(IN) TO(OUT) REMOVE INPUT LAST                             
/*                                                                     
//*                                                                     
//**********************************************************************
//**********************************************************************
//*   COPY THE TRAILER RECORD                                           
//**********************************************************************
//PS014 EXEC  PGM=ICETOOL                                               
//SYSOUT   DD  SYSOUT=*                                                 
//DFSMSG   DD  SYSOUT=*                                                 
//TOOLMSG  DD  SYSOUT=*                                                 
//IN       DD  DISP=SHR,DSN=OUTPUT.FILE4                               
//OUT      DD  DSN=OUTPUT.FILE6,                                       
//             DISP=(NEW,CATLG,DELETE),                                 
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)                       
//TOOLIN   DD    *                                                     
  SUBSET FROM(IN) TO(OUT) KEEP INPUT LAST                               
/*                                                                     
//*                                                                     
//**********************************************************************
//**********************************************************************
//*   REMOVE THE COMMA AT THE END OF THE RECORD                         
//**********************************************************************
//*                                                                     
//PS016   EXEC PGM=SORT                                                 
//SYSOUT   DD  SYSOUT=*                                                 
//SYSPRINT DD  SYSOUT=*                                                 
//SYSUDUMP DD  SYSOUT=*                                                 
//SORTIN   DD  DISP=SHR,DSN=OUTPUT.FILE6                               
//SORTOUT  DD  DSN=OUTPUT.TRL,                                         
//             DISP=(NEW,CATLG,DELETE),                                 
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)                       
//*                                                                     
//SYSIN    DD  *                                                       
  OPTION COPY                                                           
  INREC IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'))),',C'))) ')))           
//*                                                                     
//**********************************************************************
//**********************************************************************
//*   CREATE A NEW FILE CONTAINING 'OPTION COPY'                       
//**********************************************************************
//*                                                                     
//PS018   EXEC PGM=SORT                                                 
//SYSOUT   DD  SYSOUT=*                                                 
//SYSPRINT DD  SYSOUT=*                                                 
//SYSUDUMP DD  SYSOUT=*                                                 
//SORTIN   DD  DISP=SHR,DSN=OUTPUT.FILE6                               
//SORTOUT  DD  DSN=OUTPUT.OPTCPY,                                       
//             DISP=(NEW,CATLG,DELETE),                                 
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)                       
//*                                                                     
//SYSIN    DD  *                                                       
  OPTION COPY                                                           
  OUTREC BUILD=(01:C' OPTION COPY ',                                   
                14:67X)                                                 
//*                                                                     
//**********************************************************************
//**********************************************************************
//*   MERGE ALL THE FILES TO CREATE THE FINAL SORT CARD                 
//**********************************************************************
//*                                                                     
//PS020   EXEC PGM=SORT                                                 
//SYSOUT   DD  SYSOUT=*                                                 
//SYSPRINT DD  SYSOUT=*                                                 
//SYSUDUMP DD  SYSOUT=*                                                 
//SORTIN   DD  DISP=SHR,DSN=OUTPUT.OPTCPY                               
//         DD  DISP=SHR,DSN=OUTPUT.HDR                                 
//         DD  DISP=SHR,DSN=OUTPUT.DTL                                 
//         DD  DISP=SHR,DSN=OUTPUT.TRL                                 
//SORTOUT  DD  DSN=OUTPUT.FINAL,                                       
//             DISP=(NEW,CATLG,DELETE),                                 
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)                       
//*                                                                     
//SYSIN    DD  *                                                       
  OPTION COPY                                                           
//*                                                                     
//**********************************************************************
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Thu Mar 08, 2018 7:05 pm
Reply with quote

Vamshi,

Will you always have 10 records in the input?
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Mar 08, 2018 7:16 pm
Reply with quote

That's a lot of steps you have here...
As I don't have much free time, I just wrote this:
Code:
  SORT FIELDS=COPY                                       
  INCLUDE COND=(6,12,CH,EQ,C'INVALIDVALUE')             
  OUTFIL HEADER1=(' OPTION COPY',/,' INREC '),           
         OUTREC=(8:C'IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(',
                 21,5,C',',31,5,C'))),')
and got most of your request in one step.
But are you sure the command you are building is syntactically correct ?
Back to top
View user's profile Send private message
Vamshi Veludandi

New User


Joined: 17 Mar 2009
Posts: 27
Location: Bangalore

PostPosted: Thu Mar 08, 2018 7:38 pm
Reply with quote

Arun Raj wrote:
Vamshi,

Will you always have 10 records in the input?


Arun Raj,
No, the input file would contain thousands of records. But the 'INVALIDVALUE' records would be just around 10.

Thanks,
Vamshi.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Thu Mar 08, 2018 7:58 pm
Reply with quote

Quote:
would be just around 10
okay, so that is something varying. That is what I meant to ask. And if all you are doing is just FINDREP, you might not need the IFTHEN construct, a simple INREC with multiple INOUTs would do.
Code:
  OPTION COPY                       
  INREC FINDREP=(INOUT=(X'BA',C'_', 
                        X'BB',C'_', 
                        X'39',C'__',
                        X'41',C'__',
                        X'5C',C'_', 
                        X'54',C'__',
                        X'69',C'__'))
Also since you might end up replacing 1 byte with 2 bytes, make sure you are not messing up other data, or you could also end up in an OVERRUN error, if any of those 'invalid' characters occur in the last byte of your input record.
Back to top
View user's profile Send private message
Vamshi Veludandi

New User


Joined: 17 Mar 2009
Posts: 27
Location: Bangalore

PostPosted: Thu Mar 08, 2018 8:20 pm
Reply with quote

Marso wrote:
That's a lot of steps you have here...
As I don't have much free time, I just wrote this:
Code:
  SORT FIELDS=COPY                                       
  INCLUDE COND=(6,12,CH,EQ,C'INVALIDVALUE')             
  OUTFIL HEADER1=(' OPTION COPY',/,' INREC '),           
         OUTREC=(8:C'IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(',
                 21,5,C',',31,5,C'))),')
and got most of your request in one step.
But are you sure the command you are building is syntactically correct ?



Thanks Marso,
Yes final sort card is syntactically correct.
I modified your code a bit and was able generate the below.


Code:

//PS002   EXEC PGM=SORT                                                 
//SYSOUT   DD  SYSOUT=*                                                 
//SYSPRINT DD  SYSOUT=*                                                 
//SYSUDUMP DD  SYSOUT=*                                                 
//SORTIN   DD  *                                                       
1    INVALIDVALUE   X'BA'     C'_'                                     
2    INVALIDVALUE   X'BB'     C'_'                                     
3    INVALIDVALUE   X'39'     C'__'                                     
4    INVALIDVALUE   X'41'     C'__'                                     
5    VALIDVALUE     X'C1'     C'A'                                     
6    INVALIDVALUE   X'5C'     C'_'                                     
7    INVALIDVALUE   X'54'     C'__'                                     
8    INVALIDVALUE   X'69'     C'__'                                     
9    INVALIDVALUE   X'BA'     C'_'                                     
10   VALIDVALUE     X'40'     C' '                                     
/*                                                                     
//*                                                                     
//SORTOUT  DD  DSN=OUTPUT.FILE1,                                       
//             DISP=(NEW,CATLG,DELETE),                                 
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)                       
//*                                                                     
//SYSIN    DD  *                                                       
  SORT FIELDS=COPY                                                     
     INCLUDE COND=(6,12,CH,EQ,C'INVALIDVALUE')                         
     OUTFIL REMOVECC,                                                   
            HEADER1=(C' OPTION COPY',/,                                 
            C' INREC IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(',               
            21,5,C',',31,5,C'))),',24X),                               
            OUTREC=(8:C'IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(',           
                    21,5,C',',31,5,C'))),',24X)                         
//*                                                                     


Output:
Code:

****** ***************************** Top of Data ******************************
000001  OPTION COPY                                                           
000002  INREC IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'BA',C'_' ))),               
000003        IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'BA',C'_' ))),               
000004        IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'BB',C'_' ))),               
000005        IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'39',C'__'))),               
000006        IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'41',C'__'))),               
000007        IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'5C',C'_' ))),               
000008        IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'54',C'__'))),               
000009        IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'69',C'__'))),               
000010        IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(X'BA',C'_' ))),               
****** **************************** Bottom of Data ****************************


I now, need to get rid of the spaces and the comma at the end of the last record.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Thu Mar 08, 2018 8:34 pm
Reply with quote

Here is a quick dirty version. Note that I have let the first replace repeat, but no harm I guess. And added a 'dummy' replace at the end.
Code:
  SORT FIELDS=COPY                                           
  INCLUDE COND=(6,12,CH,EQ,C'INVALIDVALUE')                   
  OUTREC IFTHEN=(WHEN=INIT,BUILD=(24:21,5,C',',31,5,C',')),   
         IFTHEN=(WHEN=INIT,OVERLAY=(34:34,2,JFY=(SHIFT=LEFT)))
  OUTFIL REMOVECC,                                           
         HEADER1=(' OPTION COPY',/,                           
                  ' INREC FINDREP=(INOUT=(',24,12,80:X),     
           BUILD=(1,35,80:X),                                 
        TRAILER1=(24:'C'' '',C'' ''))')                   
Created a SORTOUT like this:
Code:
 OPTION COPY                       
 INREC FINDREP=(INOUT=(X'BA',C'_',
                       X'BA',C'_',
                       X'BB',C'_',
                       X'39',C'__',
                       X'41',C'__',
                       X'5C',C'_',
                       X'54',C'__',
                       X'69',C'__',
                       X'BA',C'_',
                       C' ',C' '))
Like I mentioned earlier in this thread, you don't really need the IFTHEN construct here, and I am not sure if you paid attention to - replacing 1 byte with 2 bytes, you could end up in trouble later if such an input comes. Another thing, I see the - X'BA' C'_' repeated in your input. You might want to remove duplicates before building your sort card.
Good luck.
Back to top
View user's profile Send private message
Vamshi Veludandi

New User


Joined: 17 Mar 2009
Posts: 27
Location: Bangalore

PostPosted: Thu Mar 08, 2018 9:36 pm
Reply with quote

Arun Raj wrote:
Here is a quick dirty version. Note that I have let the first replace repeat, but no harm I guess. And added a 'dummy' replace at the end.
Code:
  SORT FIELDS=COPY                                           
  INCLUDE COND=(6,12,CH,EQ,C'INVALIDVALUE')                   
  OUTREC IFTHEN=(WHEN=INIT,BUILD=(24:21,5,C',',31,5,C',')),   
         IFTHEN=(WHEN=INIT,OVERLAY=(34:34,2,JFY=(SHIFT=LEFT)))
  OUTFIL REMOVECC,                                           
         HEADER1=(' OPTION COPY',/,                           
                  ' INREC FINDREP=(INOUT=(',24,12,80:X),     
           BUILD=(1,35,80:X),                                 
        TRAILER1=(24:'C'' '',C'' ''))')                   
Created a SORTOUT like this:
Code:
 OPTION COPY                       
 INREC FINDREP=(INOUT=(X'BA',C'_',
                       X'BA',C'_',
                       X'BB',C'_',
                       X'39',C'__',
                       X'41',C'__',
                       X'5C',C'_',
                       X'54',C'__',
                       X'69',C'__',
                       X'BA',C'_',
                       C' ',C' '))
Like I mentioned earlier in this thread, you don't really need the IFTHEN construct here, and I am not sure if you paid attention to - replacing 1 byte with 2 bytes, you could end up in trouble later if such an input comes. Another thing, I see the - X'BA' C'_' repeated in your input. You might want to remove duplicates before building your sort card.
Good luck.


Arun Raj,

Thanks a lot.
Its working as expected.
Yes, In some places we are replacing 1 byte with 2 bytes. But it needs to be that way.
One of the find replace conditions is repeated twice. But would that make any difference in the performance ? I would get try to get rid of it though.
Also, I have a doubt. In the trailer record, you have used a space. But since space is probably the most frequently occurred character, I suppose it be better to use any different character say "@' or something similar.

Regards,
Vamshi
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Thu Mar 08, 2018 9:46 pm
Reply with quote

Quote:
One of the find replace conditions is repeated twice. But would that make any difference in the performance ? I would get try to get rid of it though
You could simply change the SORT FIELDS=COPY to sort on the 'invalid' hex value and remove duplicates in the same step.
Quote:
Also, I have a doubt. In the trailer record, you have used a space. But since space is probably the most frequently occurred character, I suppose it be better to use any different character say '@' or something similar.
You could do that and you can also limit the 'area of search' by using the STARTPOS and ENDPOS parameters to avoid a whole record scan if that applies to your requirement.
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 JCL sort card - get first day and las... JCL & VSAM 9
No new posts How to create a list of SAR jobs with... CA Products 3
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
No new posts how to calculate SUM value for VB fil... DFSORT/ICETOOL 1
No new posts how to calculate SUM for VB file usin... JCL & VSAM 1
Search our Forums:

Back to Top