|
View previous topic :: View next topic
|
| Author |
Message |
maki_psg
New User
Joined: 28 Jan 2010 Posts: 47 Location: India
|
|
|
|
Hi,
I have a requirement to reformat the input file record and write to output file if at least one condition given in IFTHEN statements is satisfied, else I can ignore the record for output file. I would like to know if it is possible to handle using IFTHEN statement so that I may not need two steps to handle this scenario.
Sample Code below
| Code: |
//********************************************************
//SORTSTEP EXEC PGM=SORT
//********************************************************
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTIN DD *
123455
ABC123
PQR456
/*
//SYSIN DD *
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=((01,03,CH,EQ,C'ABC')),
BUILD=(1:C'TEST1',6:4,6,69X)),
IFTHEN=(WHEN=((01,03,CH,EQ,C'PQR')),
BUILD=(1:C'TEST2',6:4,6,69X))
/*
|
Output
| Code: |
123455
TEST1123
TEST2456
|
since the 1st record in my input did not match any IFTHEN conditions, I do not want the 1st record to be reformatted and copied to output file.
Thanks. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
So, use
| Code: |
INCLUDE COND=(1,3,CH,EQ,C'ABC',
OR,
1,3,CH,EQ,C'PQR') |
or
| Code: |
| INCLUDE COND=(1,3,SS,EQ,C'ABC.PQR') |
The "." in the literal can be any character which does not appear in the data.
On large datasets, prefer the first version anyway. |
|
| Back to top |
|
 |
maki_psg
New User
Joined: 28 Jan 2010 Posts: 47 Location: India
|
|
|
|
| Bill Woodger wrote: |
So, use
| Code: |
INCLUDE COND=(1,3,CH,EQ,C'ABC',
OR,
1,3,CH,EQ,C'PQR') |
or
| Code: |
| INCLUDE COND=(1,3,SS,EQ,C'ABC.PQR') |
The "." in the literal can be any character which does not appear in the data.
On large datasets, prefer the first version anyway. |
Thanks, Bill.
I did a mistake when I chose the sample data. Here, the reformatting would not be same for each condition e.g. reformatting for ABC will not be same as PQR.
If I go with INCLUDE COND for different format, I think we need to copy the output to separate files (say OUTFIL01, OUTFIL02) for each condition. However, I would like to copy both the reformatted record into same output file. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
The INCLUDE COND=/OMIT COND= are just a filter on the input file. You do whatever you want in the rest of the code. There is no connection between the two things.
Don't confuse these with INCLUDE=/OMIT= on OUTFIL. Those would filter that OUTFIL data only. |
|
| Back to top |
|
 |
maki_psg
New User
Joined: 28 Jan 2010 Posts: 47 Location: India
|
|
|
|
| Bill Woodger wrote: |
The INCLUDE COND=/OMIT COND= are just a filter on the input file. You do whatever you want in the rest of the code. There is no connection between the two things.
Don't confuse these with INCLUDE=/OMIT= on OUTFIL. Those would filter that OUTFIL data only. |
Thanks, Bill.
Please help me to handle the below scenario using INCLUDE COND.
Input
| Code: |
123455
ABC123
ABC789
PQR456
PQR012
|
When the 1st three bytes is ABC, I would like to reformat the input rec to output file as below.
| Code: |
TEST1123BBB
TEST1789BBB
|
When the 1st three bytes is PQR, I would like to reformat the input rec to output file as below.
| Code: |
TEST2BBB456
TEST2BBB012
|
In above output, B represents Blank Space. I would like to reformat and copy the matched recs to one output file and ignore unmatched rec (in my sample - 1st record). |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| Code: |
SORT FIELDS=COPY
INCLUDE COND=(1,3,CH,EQ,C'ABC',
OR,
1,3,CH,EQ,C'PQR')
INREC IFTHEN=(WHEN=((01,03,CH,EQ,C'ABC')),
BUILD=(1:C'TEST1',6:4,6,69X)),
IFTHEN=(WHEN=((01,03,CH,EQ,C'PQR')),
BUILD=(1:C'TEST2',6:4,6,69X)) |
Find Figure 2. Record Processing Order in the DFSORT Application Programming Guide and see if that helps clarify things.
The order of processing is the same for SyncSORT (may be more options) you can check in your own manual and let us know. |
|
| Back to top |
|
 |
maki_psg
New User
Joined: 28 Jan 2010 Posts: 47 Location: India
|
|
|
|
| Bill Woodger wrote: |
| Code: |
SORT FIELDS=COPY
INCLUDE COND=(1,3,CH,EQ,C'ABC',
OR,
1,3,CH,EQ,C'PQR')
INREC IFTHEN=(WHEN=((01,03,CH,EQ,C'ABC')),
BUILD=(1:C'TEST1',6:4,6,69X)),
IFTHEN=(WHEN=((01,03,CH,EQ,C'PQR')),
BUILD=(1:C'TEST2',6:4,6,69X)) |
Find Figure 2. Record Processing Order in the DFSORT Application Programming Guide and see if that helps clarify things.
The order of processing is the same for SyncSORT (may be more options) you can check in your own manual and let us know. |
Thanks a lot, Bill. It really helped me to reduce the number of steps, and get the expected result. :) |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|