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

Using Multiple IFTHEN and WHEN condition to check & replace


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

New User


Joined: 30 Apr 2020
Posts: 10
Location: United States

PostPosted: Tue Jul 16, 2024 4:03 am
Reply with quote

I have a requirement, where i need to check and replacement few conditions in each single record.

Here is my input



Code:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
AB...*01241940155514..¬1213 123*3456789 99US7ABCD 1220124356778 01......
AB...*01YYDDD0HHMMSS..¬ECSS éââ*             ABCD  220


Code:

----+----1----+----2----+----3----+----4----+----5----+
SYSTEM INPUT             07/12/2024-21.14.00.000000   



here is my SYSIN code


//SYSIN DD *
INREC IFTHEN=(WHEN=(52,3,CH,EQ,C'220'),
OVERLAY=(1,25,C'SYSTEM INPUT')),
IFTHEN=(WHEN=INIT,
BUILD=(26:9,5,Y2T,DT=(MD4/),
C'-',37:15,2,C'.',40:17,2,C'.',43:19,2,C'.',C'000000'))
OPTION COPY

I'm getting INIT syntax error.
check for position 52 (3) in i/p = 220 or 230 then change the output position 1-25 as SYSTEM INPUT,
then change the Julian date in Position (9 - YYDDD, pos 37 - hhmmss) to DD/MM/YYYY-hh:mm:ss:000000

Cant we check multiple condition in each record? if so, please advise
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1334
Location: Bamberg, Germany

PostPosted: Tue Jul 16, 2024 6:43 am
Reply with quote

If you use the right sequence of statements, it's easier to read. Check the manual icon_exclaim.gif

Also you write DD/MM/YYYY but have coded MD4/ plus a different time format icon_confused.gif
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2140
Location: USA

PostPosted: Tue Jul 16, 2024 5:53 pm
Reply with quote

Don't forget to use the Code button:
andy12 wrote:
here is my SYSIN code


Code:
//SYSIN    DD *                                                 
  INREC IFTHEN=(WHEN=(52,3,CH,EQ,C'220'),                       
       OVERLAY=(1,25,C'SYSTEM INPUT')),                       
        IFTHEN=(WHEN=INIT,                                     
       BUILD=(26:9,5,Y2T,DT=(MD4/),                             
       C'-',37:15,2,C'.',40:17,2,C'.',43:19,2,C'.',C'000000')) 
  OPTION COPY 


please advise
Back to top
View user's profile Send private message
andy12

New User


Joined: 30 Apr 2020
Posts: 10
Location: United States

PostPosted: Tue Jul 16, 2024 8:57 pm
Reply with quote

Joerg.Findeisen wrote:
If you use the right sequence of statements, it's easier to read. Check the manual icon_exclaim.gif

Also you write DD/MM/YYYY but have coded MD4/ plus a different time format icon_confused.gif



Sorry for the typo.. i was expecting MM/DD/YYYY format..



Code:

OPTION COPY                                                         
INREC IFTHEN=(WHEN=INIT,                                             
         BUILD=(1:1,25,26:9,5,Y2T,DT=(MD4/),                           
             C'-',37:15,2,C'.',40:17,2,C'.',43:19,2,C'.',C'000000',   
             52:55,10,62:46,5)),                                       
        IFTHEN=(WHEN=(52,3,CH,EQ,C'220'),                             
         OVERLAY=(1:1,25,C'SYSTEM INPUT'))   



Input

Code:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
//SORTIN   DD *                                                         
AB...*01241940155514..¬1213 123*3456789 99US7ABCD 1220124356778 01......




output
Code:

----+----1----+----2----+----3----+----4----+----5----+
SYSTEM INPUT             07/12/2024-21.14.00.000000 124356778



I'm getting the output but position 1:25 is not overlaid with 'SYSTEM INPUT'
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2140
Location: USA

PostPosted: Tue Jul 16, 2024 9:38 pm
Reply with quote

It might be easier to understand, even for yourself!
Code:
 OPTION COPY                                     
 INREC IFTHEN=(WHEN=INIT,                       
               BUILD=(1:1,25,                   
                     26:9,5,Y2T,DT=(MD4/),C'-', 
                     37:15,2,C'.',               
                     40:17,2,C'.',               
                     43:19,2,C'.',C'000000',     
                     52:55,10,                   
                     62:46,5)),                 
       IFTHEN=(WHEN=(52,3,CH,EQ,C'220'),         
               OVERLAY=(1:1,25,                 
                          C'SYSTEM INPUT'))     
                                                 
 END                                             


After this line your input record has changed:
Code:
 . . . . . . . . . . . . .
                     52:55,10,                   
 . . . . . . . . . . .   


So, what do you expect to check by this???
Code:
. . . . . . . . . . . .
       IFTHEN=(WHEN=(52,3,CH,EQ,C'220'),         
 . . . . . . . . . . .


P.S.
A very ancient hint:
Debug your code step-by-step, not all-in-one.
E.g., try your first IFTHEN=clause only, verify its result, and ONLY AFTER VERIFICATION start adding extra IFTHEN=
Back to top
View user's profile Send private message
andy12

New User


Joined: 30 Apr 2020
Posts: 10
Location: United States

PostPosted: Tue Jul 16, 2024 9:48 pm
Reply with quote

sergeyken wrote:
It might be easier to understand, even for yourself!
Code:
 OPTION COPY                                     
 INREC IFTHEN=(WHEN=INIT,                       
               BUILD=(1:1,25,                   
                     26:9,5,Y2T,DT=(MD4/),C'-', 
                     37:15,2,C'.',               
                     40:17,2,C'.',               
                     43:19,2,C'.',C'000000',     
                     52:55,10,                   
                     62:46,5)),                 
       IFTHEN=(WHEN=(52,3,CH,EQ,C'220'),         
               OVERLAY=(1:1,25,                 
                          C'SYSTEM INPUT'))     
                                                 
 END                                             


After this line:
Code:
 . . . . . . . . . . . . .
                     52:55,10,                   
 . . . . . . . . . . .   


Quote:
What do you expect to check by this???
Code:
. . . . . . . . . . . .
       IFTHEN=(WHEN=(52,3,CH,EQ,C'220'),         
 . . . . . . . . . . .



I wanted to replace position 1 to 25 as SYSTEM INPUT. if position 52,3 = ('220' or '100' or '001')

Thanks @sergeyken. Appreciate your help.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2140
Location: USA

PostPosted: Tue Jul 16, 2024 9:54 pm
Reply with quote

andy12 wrote:

I wanted to replace position 1 to 25 as SYSTEM INPUT. if position 52,3 = ('220' or '100' or '001')

Please, re-read my reply more carefully. I tried to add more clarification...
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1334
Location: Bamberg, Germany

PostPosted: Tue Jul 16, 2024 10:06 pm
Reply with quote

That should be enough hints to get over the hump icon_smile.gif

I would have used IFTHEN <cond> BUILD and another IFTHEN NONE afterwards.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2140
Location: USA

PostPosted: Tue Jul 16, 2024 10:10 pm
Reply with quote

Joerg.Findeisen wrote:
That should be enough hints to get over the hump icon_smile.gif

I would have used IFTHEN <cond> BUILD and another IFTHEN NONE afterwards.

... and do it STEP-BY-STEP, please!
Back to top
View user's profile Send private message
andy12

New User


Joined: 30 Apr 2020
Posts: 10
Location: United States

PostPosted: Tue Jul 16, 2024 11:11 pm
Reply with quote

sergeyken wrote:
andy12 wrote:

I wanted to replace position 1 to 25 as SYSTEM INPUT. if position 52,3 = ('220' or '100' or '001')

Please, re-read my reply more carefully. I tried to add more clarification...



Yes. i understand now.. with INIT and BUILD my layout was changed.. Let me add condition to move my check condition from 52,3 = ('220' or '100' or '001') to new position in the output file.



Code:

OPTION COPY                                               
 INREC IFTHEN=(WHEN=INIT,                                 
               BUILD=(1:1,25,                             
                     26:9,5,Y2T,DT=(MD4/),C'-',           
                     37:15,2,C'.',                       
                     40:17,2,C'.',                       
                     43:19,2,C'.',C'000000',             
                     52:55,10,                           
                     62:46,5,                             
                     78:52,3)),     --> moving it to new location                     
       IFTHEN=(WHEN=(78,3,CH,EQ,C'230'),                 
               OVERLAY=(1:SYSTEM INPUT             '))   --> goes till position 25
 
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2140
Location: USA

PostPosted: Tue Jul 16, 2024 11:49 pm
Reply with quote

Code:
 OPTION COPY                                                   
                                                               
 INREC OVERLAY=(26:9,5,Y2T,DT=(MD4/),C'-',                     
                   15,2,C'.',                                 
                   17,2,C'.',                                 
                   19,2,C'.000000')                             
                                                               
 OUTREC IFTHEN=(WHEN=(52,3,CH,EQ,L(C'220',C'100',C'001')),     
                OVERLAY=(1:C'SYSTEM INPUT             '))     
                                                               
 OUTFIL  BUILD=(1,51,                                         
               55,10,                                         
               46,5)                                         
                                                               
 END                                                           
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2140
Location: USA

PostPosted: Fri Jul 19, 2024 7:16 pm
Reply with quote

In the last sample there is a bug: the original field (46,5) has been overridden by the time it is used at the end.

For more clarity I would suggest to perform date/time conversion in separate fields, and rebuild the output record in full at the very end.
Code:
* format date/time as separate fields                                 
 INREC OVERLAY=(81:9,5,Y2T,DT=(MD4/),    'MM/DD/YYYY'                 
                91:15,2,C'.',            'HH.MM.SS'                   
                   17,2,C'.',                                         
                   19,2)                                               
                                                                       
 SORT FIELDS=COPY                                                     
                                                                       
* make conditional replacement of selected records                     
 OUTREC IFTHEN=(WHEN=(52,3,CH,EQ,L(C'220',C'100',C'001')),             
                OVERLAY=(1:C'SYSTEM INPUT             '))             
                                                                       
* combine final record from parts of original one, field after field   
 OUTFIL BUILD=(1,25,              old/replaced part                   
               81,10,C'-',        formatted date                       
               91,8,C'.000000',   formatted time                       
               55,10,             moved old part                       
               46,5)              moved old part                       
*----+----1----+----2----+----3----+----4----+----5----+----6----+----7
*AB...*01241940155514..¬1207/12/2024-15.55.14.000000124356778 ABCD     
*SYSTEM INPUT             07/12/2024-15.55.14.000000124356778 ABCD     
*SYSTEM INPUT             07/12/2024-15.55.14.000000124356778 ABCD     
*SYSTEM INPUT             07/12/2024-15.55.14.000000124356778 ABCD     
*SYSTEM INPUT             99/99/9999-HH.MM.SS.000000          ABCD     
*----+----1----+----2----+----3----+----4----+----5----+----6----+----7
 END                                                                   
Back to top
View user's profile Send private message
andy12

New User


Joined: 30 Apr 2020
Posts: 10
Location: United States

PostPosted: Fri Jul 19, 2024 8:46 pm
Reply with quote

sergeyken wrote:
In the last sample there is a bug: the original field (46,5) has been overridden by the time it is used at the end.

For more clarity I would suggest to perform date/time conversion in separate fields, and rebuild the output record in full at the very end.
Code:
* format date/time as separate fields                                 
 INREC OVERLAY=(81:9,5,Y2T,DT=(MD4/),    'MM/DD/YYYY'                 
                91:15,2,C'.',            'HH.MM.SS'                   
                   17,2,C'.',                                         
                   19,2)                                               
                                                                       
 SORT FIELDS=COPY                                                     
                                                                       
* make conditional replacement of selected records                     
 OUTREC IFTHEN=(WHEN=(52,3,CH,EQ,L(C'220',C'100',C'001')),             
                OVERLAY=(1:C'SYSTEM INPUT             '))             
                                                                       
* combine final record from parts of original one, field after field   
 OUTFIL BUILD=(1,25,              old/replaced part                   
               81,10,C'-',        formatted date                       
               91,8,C'.000000',   formatted time                       
               55,10,             moved old part                       
               46,5)              moved old part                       
*----+----1----+----2----+----3----+----4----+----5----+----6----+----7
*AB...*01241940155514..¬1207/12/2024-15.55.14.000000124356778 ABCD     
*SYSTEM INPUT             07/12/2024-15.55.14.000000124356778 ABCD     
*SYSTEM INPUT             07/12/2024-15.55.14.000000124356778 ABCD     
*SYSTEM INPUT             07/12/2024-15.55.14.000000124356778 ABCD     
*SYSTEM INPUT             99/99/9999-HH.MM.SS.000000          ABCD     
*----+----1----+----2----+----3----+----4----+----5----+----6----+----7
 END                                                                   



Thanks for redoing it again.
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 combine multiple unique records into ... DFSORT/ICETOOL 2
No new posts Add condition to a FINDREP SORT card DFSORT/ICETOOL 4
No new posts SORT JCL to merge multiple tow into s... DFSORT/ICETOOL 6
No new posts To Omit records based n SORT condition DFSORT/ICETOOL 6
No new posts Check if CICS is online in JCL CICS 10
Search our Forums:

Back to Top