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

How to compare Packed date in details with System Date


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

New User


Joined: 18 May 2017
Posts: 4
Location: CAnada

PostPosted: Sun Jan 05, 2020 7:40 am
Reply with quote

!When I run the job now, I have these control statements:

Code:
 SORT FIELDS=COPY
INCLUDE COND=(110,5,PD,LT,20200101,
             AND,110,5,PD,GT,20181231)

but I want to dynamically use the system date. No matter when it runs within year NNNN, it should select all records for the preceding year NNNN-1... I see a few posts about using dates and SYMNAMES, but always in Character format...
I don't know how to use that for a compare with Packed Decimal field...

Thanks for any assistance,
Flora
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


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

PostPosted: Mon Jan 06, 2020 10:42 am
Reply with quote

Something like this should work.
Code:
OPTION COPY
INREC OVERLAY=(200:110,5,Y4V,208:DATE1,             
               208:208,8,Y4T,SUBYEARS,+1,TOGREG=Y4T)
OUTFIL FNAMES=(SORTOUT),                           
  INCLUDE=(200,4,CH,EQ,208,4,CH)                   
END                                                 
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2144
Location: USA

PostPosted: Mon Jan 06, 2020 7:45 pm
Reply with quote

In order to dynamically produce two dates of the required range, several SORT date operations are needed; so, SYMSORT values cannot be used.

You may need to temporary reserve some space with each input record: 10 bytes - to produce two dates in format PD, or 16 bytes - to produce two dates in format ZD.
Code:
//YEARDEC  EXEC  PGM=SORT                                             
//SYSOUT   DD    SYSOUT=*                                             
//SORTIN   DD    *                                                   
20180331                                                             
20190331                                                             
20200331                                                             
//*-+----1----+----2----+----3----+----4----+----5----+----6----+----7
//SORTOUT  DD    SYSOUT=*                                             
//SYSIN    DD *                                                       
 INREC IFTHEN=(WHEN=INIT,                                             
               OVERLAY=(30:&DATE1P,&DATE1P)),                         
       IFTHEN=(WHEN=INIT,                                             
               OVERLAY=(30:30,5,Y4V,SUBYEARS,+2,TOGREG=(Y4V),         
                           35,5,Y4V,SUBYEARS,+1,TOGREG=(Y4V))),       
       IFTHEN=(WHEN=INIT,                                             
               OVERLAY=(30:30,5,Y4V,LASTDAYY,TOGREG=(Y4V),           
                           35,5,Y4V,LASTDAYY,TOGREG=(Y4V))),         
       IFTHEN=(WHEN=INIT,                                             
               OVERLAY=(30:30,5,Y4V,ADDDAYS,+1,TOGREG=(Y4V)))         
 SORT FIELDS=COPY                                                     
 OUTREC IFTHEN=(WHEN=(1,8,ZD,GE,30,5,PD,                             
                  AND,1,8,ZD,LE,35,5,PD),                             
                OVERLAY=(10:C'GOOD!')),                               
        IFTHEN=(WHEN=NONE,                                           
                OVERLAY=(10:C'BAD!'))                                 
 OUTFIL BUILD=(1,30,                                                 
            X,30,5,HEX,                                               
            X,35,5,HEX),                                             
        REMOVECC,                                                     
 HEADER1=('INDATE   COMPARED?             HEX FROM   HEX TO    ',     
        /,'-------- -------------         ---------- ----------')     
 END                                                                 

Code:
INDATE   COMPARED?             HEX FROM   HEX TO       
-------- -------------         ---------- ----------   
20180331 BAD!                  020190101C 020191231C   
20190331 GOOD!                 020190101C 020191231C   
20200331 BAD!                  020190101C 020191231C   
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2144
Location: USA

PostPosted: Mon Jan 06, 2020 8:18 pm
Reply with quote

The calculation can be simplified a little bit:

Code:
//YEARDEC  EXEC  PGM=SORT                                             
//SYSOUT   DD    SYSOUT=*                                             
//SORTIN   DD    *                                                   
20180331                                                             
20190331                                                             
20200331                                                             
//*-+----1----+----2----+----3----+----4----+----5----+----6----+----7
//SORTOUT  DD    SYSOUT=*                                             
//SYSIN    DD *                                                       
 INREC IFTHEN=(WHEN=INIT,                                             
               OVERLAY=(30:&DATE1P,&DATE1P)),                         
       IFTHEN=(WHEN=INIT,                                             
               OVERLAY=(30:30,5,Y4V,SUBYEARS,+2,TOGREG=(Y4V),         
                           35,5,Y4V,SUBYEARS,+1,TOGREG=(Y4V))),       
       IFTHEN=(WHEN=INIT,                                             
               OVERLAY=(30:30,5,Y4V,LASTDAYY,TOGREG=(Y4V),           
                           35,5,Y4V,LASTDAYY,TOGREG=(Y4V)))         
 SORT FIELDS=COPY                                                     
 OUTREC IFTHEN=(WHEN=(1,8,ZD,GT,30,5,PD,    compare to 12/31 two years ago                             
                  AND,1,8,ZD,LE,35,5,PD),   compare to 12/31 one year ago                             
                OVERLAY=(10:C'GOOD!')),                               
        IFTHEN=(WHEN=NONE,                                           
                OVERLAY=(10:C'BAD!'))                                 
 OUTFIL BUILD=(1,30,                                                 
            X,30,5,HEX,                                               
            X,35,5,HEX),                                             
        REMOVECC,                                                     
 HEADER1=('INDATE   COMPARED?             HEX FROM   HEX TO    ',     
        /,'-------- -------------         ---------- ----------')     
 END                                                                 
Back to top
View user's profile Send private message
Floramq

New User


Joined: 18 May 2017
Posts: 4
Location: CAnada

PostPosted: Tue Jan 07, 2020 1:32 am
Reply with quote

Thank you both for such quick replies ! I will try these straight away
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


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

PostPosted: Tue Jan 07, 2020 4:13 pm
Reply with quote

@Flora: You will have a little bit increased runtime depending on the amount of data for both solutions. This is due to the necessity to process data after they have passed the global INCLUDE you had specified.
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 Help with SORT - I need to validate d... DFSORT/ICETOOL 4
No new posts JCL sort to compare dates in two file... DFSORT/ICETOOL 2
No new posts Date format correction using dfsort DFSORT/ICETOOL 3
No new posts System add a USER parm when job submi... TSO/ISPF 4
No new posts Sorting Date Field DFSORT/ICETOOL 4
Search our Forums:

Back to Top