|
View previous topic :: View next topic
|
| Author |
Message |
Vamshi Veludandi
New User
Joined: 17 Mar 2009 Posts: 27 Location: Bangalore
|
|
|
|
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 |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
Vamshi,
Will you always have 10 records in the input? |
|
| Back to top |
|
 |
Marso
REXX Moderator

Joined: 13 Mar 2006 Posts: 1356 Location: Israel
|
|
|
|
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 |
|
 |
Vamshi Veludandi
New User
Joined: 17 Mar 2009 Posts: 27 Location: Bangalore
|
|
|
|
| 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 |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
| 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 |
|
 |
Vamshi Veludandi
New User
Joined: 17 Mar 2009 Posts: 27 Location: Bangalore
|
|
|
|
| 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 |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
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 |
|
 |
Vamshi Veludandi
New User
Joined: 17 Mar 2009 Posts: 27 Location: Bangalore
|
|
|
|
| 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 |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
| 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 |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|