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

IFTHEN to reformat the matching and non matching condition


IBM Mainframe Forums -> SYNCSORT
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
maki_psg

New User


Joined: 28 Jan 2010
Posts: 47
Location: India

PostPosted: Fri Sep 25, 2015 2:53 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Sep 25, 2015 3:28 pm
Reply with quote

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
View user's profile Send private message
maki_psg

New User


Joined: 28 Jan 2010
Posts: 47
Location: India

PostPosted: Fri Sep 25, 2015 3:59 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Sep 25, 2015 4:20 pm
Reply with quote

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
View user's profile Send private message
maki_psg

New User


Joined: 28 Jan 2010
Posts: 47
Location: India

PostPosted: Fri Sep 25, 2015 6:42 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Sep 25, 2015 7:27 pm
Reply with quote

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
View user's profile Send private message
maki_psg

New User


Joined: 28 Jan 2010
Posts: 47
Location: India

PostPosted: Fri Sep 25, 2015 9:47 pm
Reply with quote

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
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 -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts How to Reformat a file using File Man... All Other Mainframe Topics 14
No new posts Rexx pattern matching on PS qualifer ... CLIST & REXX 1
No new posts Reformat and relocate content DFSORT/ICETOOL 4
No new posts File matching functionality in Easytr... DFSORT/ICETOOL 14
No new posts Problem with IFTHEN=(WHEN=GROUP,BEGIN... DFSORT/ICETOOL 5
Search our Forums:

Back to Top