Check dates for non-processing days.



Support for NetApp SyncSort for z/OS, Visual SyncSort, SYNCINIT, SYNCLIST and SYNCTOOL

Check dates for non-processing days.

Postby chillmo » Sat Jun 15, 2024 12:36 am

Team,

I have a file with multiple dates and need to determine which is a processing day (B), Mon - Fri, but I need to account for weekends (N), Sat Sun, and holidays.

This is what I used, but is there a more efficient without creating a COBOL program....any suggestions would be greatly appreciated.

Date is formatted as CCYY-MM-DD, so I convert to CCYYMMDD before I execute the following code.


SORT FIELDS=COPY                                                  
INREC IFTHEN=(WHEN=INIT,OVERLAY=(111:25,10,UFF,TO=ZD,LENGTH=8)),  
IFTHEN=(WHEN=INIT,BUILD=(1,110,119:111,8,Y4T,WEEKDAY=DIGIT1)),    
      IFTHEN=(WHEN=(119,1,SS,EQ,C'1,7',OR,111,8,ZD,EQ,20240527,  
                 OR,111,8,ZD,EQ,20240101,OR,111,8,ZD,EQ,20240219,
                 OR,111,8,ZD,EQ,20240101,OR,111,8,ZD,EQ,20240611,
                 OR,111,8,ZD,EQ,20240704,OR,111,8,ZD,EQ,20241225),
                                        OVERLAY=(110:C'N')),      
      IFTHEN=(WHEN=(119,1,SS,EQ,C'2,3,4,5,6'),OVERLAY=(110:C'B'))
 


I changed it to below.


SORT FIELDS=COPY                                                  
INREC IFTHEN=(WHEN=INIT,OVERLAY=(111:25,10,UFF,TO=ZD,LENGTH=8)),  
IFTHEN=(WHEN=INIT,BUILD=(1,110,119:111,8,Y4T,WEEKDAY=DIGIT1)),    
      IFTHEN=(WHEN=(119,1,SS,EQ,C'1,7'),OVERLAY=(110:C'N')),      
      IFTHEN=(WHEN=(119,1,SS,EQ,C'2,3,4,5,6'),OVERLAY=(110:C'B')),
      IFTHEN=(WHEN=(111,8,ZD,EQ,20240527,                        
                 OR,111,8,ZD,EQ,20240101,OR,111,8,ZD,EQ,20240115,
                 OR,111,8,ZD,EQ,20240527,OR,111,8,ZD,EQ,20240619,
                 OR,111,8,ZD,EQ,20240704,OR,111,8,ZD,EQ,20241225),
                                        OVERLAY=(110:C'N'))      
 


Both executes but I don't get the desired results, which is for holidays that fall on a weekday, to have a "N" in position 110.
chillmo
 
Posts: 13
Joined: Wed Aug 30, 2017 8:56 pm
Has thanked: 1 time
Been thanked: 0 time

Re: Check dates for non-processing days.

Postby chillmo » Sat Jun 15, 2024 3:54 am

So, I got it to work by using the code below (it appears I was missing the HIT=NEXT parm):


SORT FIELDS=COPY                                                  
INREC IFTHEN=(WHEN=INIT,OVERLAY=(111:25,10,UFF,TO=ZD,LENGTH=8)),  
IFTHEN=(WHEN=INIT,BUILD=(1,110,119:111,8,Y4T,WEEKDAY=DIGIT1)),    
IFTHEN=(WHEN=(119,1,SS,EQ,C'1,7'),OVERLAY=(110:C'N'),HIT=NEXT),  
IFTHEN=(WHEN=(119,1,SS,EQ,C'2,3,4,5,6'),                          
                 OVERLAY=(110:C'B'),HIT=NEXT),                    
IFTHEN=(WHEN=(111,8,SS,EQ,C'20240101,20240115,20240527,20240704'),
                                        OVERLAY=(110:C'N'))      
 


NOT sure if it's efficient, but it provides the desired result. Any suggestions to tweak on performance are more than welcomed.

Thanks all!
chillmo
 
Posts: 13
Joined: Wed Aug 30, 2017 8:56 pm
Has thanked: 1 time
Been thanked: 0 time

Re: Check dates for non-processing days.

Postby sergeyken » Mon Jun 17, 2024 7:10 pm

It makes sense to have a separate file with holiday dates listed there.
20240101     [optional holiday name here]
20240115     [optional holiday name here]
20240527     [optional holiday name here]
20240704     [optional holiday name here]
. . . . . .


Then you may need to make a JOIN with your main file, to exclude/mark/process somehow the records matching holiday dates.

P.S.
It is recommended to specify all sort statements in the order they are really processed:

 JOINKEYS ...
 JOIN ...
 REFORMAT ...
 INCLUDE ...
 INREC ...
 SORT ...
 SUM/DUPKEYS ...
 OUTREC ...
 OUTFIL ...
 END
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 453
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 8 times
Been thanked: 40 times

Re: Check dates for non-processing days.

Postby sergeyken » Mon Jun 17, 2024 8:02 pm

chillmo wrote:So, I got it to work by using the code below (it appears I was missing the HIT=NEXT parm):


 SORT FIELDS=COPY                                                  
 INREC IFTHEN=(WHEN=INIT,
               OVERLAY=(111:25,10,UFF,TO=ZD,LENGTH=8)),  
       IFTHEN=(WHEN=INIT,
               BUILD=(1,110,119:111,8,Y4T,WEEKDAY=DIGIT1)),    
       IFTHEN=(WHEN=(119,1,SS,EQ,C'1,7'),
               OVERLAY=(110:C'N'),HIT=NEXT),  
       IFTHEN=(WHEN=(119,1,SS,EQ,C'2,3,4,5,6'),                          
               OVERLAY=(110:C'B'),HIT=NEXT),                    
       IFTHEN=(WHEN=(111,8,SS,EQ,C'20240101,20240115,20240527,20240704'),
               OVERLAY=(110:C'N'))      
 


NOT sure if it's efficient, but it provides the desired result. Any suggestions to tweak on performance are more than welcomed.

In this case, to avoid undesired HIT=NEXT, you can just reorder your IFTHEN parameters.
0) set default 110:C'B'
1) check for holidays, set 110:C'N'
2) check for weekends; set 110:C'N'
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 453
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 8 times
Been thanked: 40 times

Re: Check dates for non-processing days.

Postby sergeyken » Mon Jun 17, 2024 9:12 pm

Holidays file:

//HOLYDAYS DD  *
2024-01-01   New Year’s Day
2024-01-15   Martin Luther King Day
2024-02-19   President’s Day
2024-05-27   Memorial Day
2024-06-19   Juneteenth
2024-07-04   Independence Day
2024-09-02   Labor Day
2024-10-14   Columbus Day
2024-11-11   Veterans Day
2024-11-28   Thanksgiving Day
2024-12-25   Christmas Day
//*
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 453
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 8 times
Been thanked: 40 times

Re: Check dates for non-processing days.

Postby sergeyken » Mon Jun 17, 2024 9:52 pm

One example.
You can delete unneeded intermediate data from SORTOUT, if you want

//*====================================================================
//DAYSCHK  EXEC PGM=SORT                                              
//*                                                                    
//SYSOUT   DD  SYSOUT=*                                                
//*                                                                    
//SORTIN   DD  *                                                      
                        2024-01-01                                    
                        2024-01-02                                    
                        2024-01-03                                    
                        2024-01-04                                    
                        2024-01-05                                    
                        2024-01-06                                    
                        2024-01-07                                    
                        2024-01-08                                    
                        2024-01-09                                    
                        2024-01-10                                    
                        2024-01-11                                    
                        2024-01-12                                    
                        2024-01-13                                    
                        2024-01-14                                    
                        2024-01-15                                    
                        2024-07-04                                    
                        2024-12-25                                    
//*                                                                    
//HOLYDAYS DD  *                                                      
2024-01-01   New Year-s Day                                            
2024-01-15   Martin Luther King Day                                    
2024-02-19   President-s Day                                          
2024-05-27   Memorial Day                                              
2024-06-19   Juneteenth                                                
2024-07-04   Independence Day                                          
2024-09-02   Labor Day                                                
2024-10-14   Columbus Day                                              
2024-11-11   Veterans Day                                              
2024-11-28   Thanksgiving Day                                          
2024-12-25   Christmas Day                                            
//*                                                                    
//*====================================================================
//SYSIN    DD  *                                                      
 JOINKEYS F1=SORTIN,                                                  
          FIELDS=(25,10,A)             master file date                
 JOINKEYS F2=HOLYDAYS,                                                
          FIELDS=(1,10,A),SORTED       holyday date                    
 JOIN UNPAIRED,F1                                                      
 REFORMAT FIELDS=(F1:1,80,?)                                          
 INREC IFTHEN=(WHEN=INIT,                                              
               OVERLAY=(111:25,10,UFF,TO=ZD,LENGTH=8)),                
       IFTHEN=(WHEN=INIT,                                              
               BUILD=(1,118,119:111,8,Y4T,WEEKDAY=DIGIT1)),            
       IFTHEN=(WHEN=INIT,                                              
               OVERLAY=(110:C'B')),                                    
       IFTHEN=(WHEN=(81,1,CH,EQ,C'2',          matching holyday?      
                 OR,119,1,CH,EQ,L(C'1',C'7')), matching weekend?      
               OVERLAY=(110:C'N'))                                    
 SORT FIELDS=COPY                                                      
 END                                                                  
//*                                                                    
//SORTOUT  DD  SYSOUT=*                                                
//*====================================================================


********************************* TOP OF DATA *************************************
                        2024-01-01                                              B                            B202401012
                        2024-01-02                                              1                            B202401023
                        2024-01-03                                              1                            B202401034
                        2024-01-04                                              1                            B202401045
                        2024-01-05                                              1                            B202401056
                        2024-01-06                                              1                            N202401067
                        2024-01-07                                              1                            N202401071
                        2024-01-08                                              1                            B202401082
                        2024-01-09                                              1                            B202401093
                        2024-01-10                                              1                            B202401104
                        2024-01-11                                              1                            B202401115
                        2024-01-12                                              1                            B202401126
                        2024-01-13                                              1                            N202401137
                        2024-01-14                                              1                            N202401141
                        2024-01-15                                              B                            B202401152
                        2024-07-04                                              B                            B202407045
                        2024-12-25                                              B                            B202412254
******************************** BOTTOM OF DATA ********************************
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 453
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 8 times
Been thanked: 40 times

Re: Check dates for non-processing days.

Postby sergeyken » Mon Jun 17, 2024 10:04 pm

Sorry for the typo, it must be  IFTHEN=(WHEN=(81,1,CH,EQ,C'B',          matching holyday?      


//*====================================================================
//DAYSCHK  EXEC PGM=SORT                                              
//*                                                                    
//SYSOUT   DD  SYSOUT=*                                                
//*                                                                    
//SORTIN   DD  *                                                      
                        2024-01-01                                    
                        2024-01-02                                    
                        2024-01-03                                    
                        2024-01-04                                    
                        2024-01-05                                    
                        2024-01-06                                    
                        2024-01-07                                    
                        2024-01-08                                    
                        2024-01-09                                    
                        2024-01-10                                    
                        2024-01-11                                    
                        2024-01-12                                    
                        2024-01-13                                    
                        2024-01-14                                    
                        2024-01-15                                    
                        2024-07-04                                    
                        2024-12-25                                    
//*                                                                    
//HOLYDAYS DD  *                                                      
2024-01-01   New Year-s Day                                            
2024-01-15   Martin Luther King Day                                    
2024-02-19   President-s Day                                          
2024-05-27   Memorial Day                                              
2024-06-19   Juneteenth                                                
2024-07-04   Independence Day                                          
2024-09-02   Labor Day                                                
2024-10-14   Columbus Day                                              
2024-11-11   Veterans Day                                              
2024-11-28   Thanksgiving Day                                          
2024-12-25   Christmas Day                                            
//*                                                                    
//*====================================================================
//SYSIN    DD  *                                                      
 JOINKEYS F1=SORTIN,                                                  
          FIELDS=(25,10,A)             master file date                
 JOINKEYS F2=HOLYDAYS,                                                
          FIELDS=(1,10,A),SORTED       holyday date                    
 JOIN UNPAIRED,F1                                                      
 REFORMAT FIELDS=(F1:1,80,?)                                          
 INREC IFTHEN=(WHEN=INIT,                                              
               OVERLAY=(111:25,10,UFF,TO=ZD,LENGTH=8)),                
       IFTHEN=(WHEN=INIT,                                              
               BUILD=(1,118,119:111,8,Y4T,WEEKDAY=DIGIT1)),            
       IFTHEN=(WHEN=INIT,                                              
               OVERLAY=(110:C'B')),                                    
       IFTHEN=(WHEN=(81,1,CH,EQ,C'B',          matching holyday?      
                 OR,119,1,CH,EQ,L(C'1',C'7')), matching weekend?      
               OVERLAY=(110:C'N'))                                    
 SORT FIELDS=COPY                                                      
 END                                                                  
//*                                                                    
//SORTOUT  DD  SYSOUT=*                                                
//*====================================================================


********************************* TOP OF DATA *************************************************************************
                        2024-01-01                                              B                            N202401012
                        2024-01-02                                              1                            B202401023
                        2024-01-03                                              1                            B202401034
                        2024-01-04                                              1                            B202401045
                        2024-01-05                                              1                            B202401056
                        2024-01-06                                              1                            N202401067
                        2024-01-07                                              1                            N202401071
                        2024-01-08                                              1                            B202401082
                        2024-01-09                                              1                            B202401093
                        2024-01-10                                              1                            B202401104
                        2024-01-11                                              1                            B202401115
                        2024-01-12                                              1                            B202401126
                        2024-01-13                                              1                            N202401137
                        2024-01-14                                              1                            N202401141
                        2024-01-15                                              B                            N202401152
                        2024-07-04                                              B                            N202407045
                        2024-12-25                                              B                            N202412254
******************************** BOTTOM OF DATA ***********************************************************************
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 453
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 8 times
Been thanked: 40 times

Re: Check dates for non-processing days.

Postby sergeyken » Tue Jan 21, 2025 8:28 pm

After half a year there is no reaction at all...
As usually, nobody of newcomers is interested in learning something, besides of getting a ready-to-use sample for their immediate task.

The approach to search for the date (or any other key) from a table is a very trivial one. The serious issue is: it requires updating the search table every year, to add holiday dates for each particular year, separately. I've been faced similar problem in one project, and decided to replace this method to support search on the unified table, which is suitable for holiday search for any year between 0001, and 9999. In my case is was done in Assembler code, but the algorithm is the same for all environments, including DB2 and other databases.

If there is someone yet who may be interested, I can share this approach.
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 453
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 8 times
Been thanked: 40 times


Return to Syncsort/Synctool

 


  • Related topics
    Replies
    Views
    Last post