|
View previous topic :: View next topic
|
| Author |
Message |
useit
Active User
Joined: 05 Oct 2006 Posts: 152
|
|
|
|
hi,
i have a file of record length(80).
first two byte of file can have odd or even numbers. i just have to seperate odd numbers and even numbers and write it into two different files using SORT?.
say for example.
my input file:
| Code: |
01AAAAAAAAAAAAAAAA
02BBBBBBBBBBBBBBBB
04CCCCCCCCCCCCCC
07DDDDDDDDDDDDDD |
OUTPUT FILE 1:(Should contain only odd numbers )
| Code: |
01AAAAAAAAAAAAAAAA
07DDDDDDDDDDDDDD |
OUTPUT FILE 2:(Should contain only Even numbers )
| Code: |
02BBBBBBBBBBBBBBBB
04CCCCCCCCCCCCCC |
how can we differentiate odd numbers and even numbers using sort?
kindly help me in this regard
Regds,
useit. |
|
| Back to top |
|
 |
useit
Active User
Joined: 05 Oct 2006 Posts: 152
|
|
|
|
hi,
i have tried this syntax. and below sort card worked for me. thanks a lot:)
| Code: |
//SORT01 EXEC PGM=SORT
//SORTIN DD *
01
02
03
04
//ODD DD SYSOUT=*
//EVEN DD SYSOUT=*
//SYSIN DD *
OPTION COPY
OUTFIL FNAMES=(ODD,EVEN),SPLIT
/* |
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| Try it with your original sample data and let us know. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
If you look at this, there is so code to identify odd and even numbers.
| Code: |
OUTFIL FNAMES=EVEN,INCLUDE=(2,1,BI,EQ,B'.......0')
OUTFIL FNAMES=ODD,SAVE |
|
|
| Back to top |
|
 |
useit
Active User
Joined: 05 Oct 2006 Posts: 152
|
|
|
|
| thanks a lot Bill..i tried this and it is working fine:) |
|
| Back to top |
|
 |
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
Hi..I was just trying something and came up with a solution using MOD function. Not sure if this is the best way..so just posting here.
| Code: |
//STEP01 EXEC PGM=SORT
//SORTIN DD *
01AAA
02BBB
04CCC
05DDD
07EEE
//ODD DD SYSOUT=*
//EVEN DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
BUILD=(1,5,6:1,2,ZD,MOD,+2,TO=ZD,LENGTH=1))
OUTFIL FNAMES=ODD,INCLUDE=(6,1,CH,EQ,C'1'),BUILD=(01,05)
OUTFIL FNAMES=EVEN,INCLUDE=(6,1,CH,EQ,C'0'),BUILD=(01,05)
/* |
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Yes, MOD will do it. but it uses more CPU than just testing the riight-most bit of the final byte for being 0 (even) or 1 (odd). Frank Yaeger said so :-) (Remember, Vasanthz?).
Using the SAVE is a good habit to get into. There's one fewer set of conditions to worry about, no tortuous negation which is sometimes necessary otherwise, and you can be sure all the records end up "somewhere" at least.
Where conditions are "theoretically" mutually exclusive but not logically so, I'd even code an extra OUTFIL, just to covered in case the spec was not correct on that :-) Then check that the OUTFIL is empty. |
|
| Back to top |
|
 |
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
| Quote: |
| Yes, MOD will do it. but it uses more CPU than just testing the riight-most bit of the final byte for being 0 (even) or 1 (odd). |
Thanks Bill. I was not aware of this. |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
| Bit data checking is efficient when compared to using MOD function. |
|
| Back to top |
|
 |
|
|