Reformatting and calculating time and date values

In this Mainframe Forum - You can post your queries on DFSORT, ICETOOL , SyncSort & JCL Utilities

Moderators: Frank Yaeger, Moderator Group

Post Reply
Martin G.
Member
Posts: 7
Joined: Thu Mar 11, 2010 6:39 pm

Reformatting and calculating time and date values

Post by Martin G. » Tue Jul 06, 2010 6:41 pm

hello to the forum,

actually I am working on a preedited file with some SMF-record information included.
The file looks like follows:

Code: Select all

 
00110186  02000268  00110186  02000310  PJDTED71  00000007  
00110186  20040443  00110186  20292051  PJDTTG12  00012542 

The rows represent the following informations:
startdate - starttime - enddate - endtime - jobname - cputime.
Date values are given in the format '001'yyddd (julian date),
time values format is hhmmssxx (xx = hundredths of a second),
cputime format is ssssssxx (seconds and hundredths of a second).
I would like to rearrange and reformat the given file using dfsort to a format as follows

Code: Select all

PJDTED71  02:00:02  02:00:03  00:00:00,42     0'00,07"  20100705 
PJDTTG12  20:04:04  20:29:20  00:25:16,08     2'05,42"  20100705 

The content of the rows is now:
jobname - starttime - endtime - duration - cputime - startdate
Time values are now given in format hh:mm:ss,
duration with additional hundredths of a second, separated with comma,
cputime in mmmm'ss,xx" (minutes, seconds and hundredths of a second with separators shown),
and the date in eight digits format without separators.
As a special challenge I would like to subtract the starttime from endtime given in the original file to get the duration of the job run in 'real' time as a result.
*
Of course it was easy to get the first three rows by using OUTREC:

Code: Select all

OUTREC BUILD=(40,10,11,6,ZD,M8,C'  ',31,6,ZD,M8,C'  ', 

But I cannot find a solution for the other rows. I tried
(11,8,TE4,SUB,31,8,TE4),EDIT=(TT:TT:TT,TT) -
there is no error, but the result I received is not the difference between start- and endtime ??
*
Any idea to help me doing this with sort?
Thanks in advance !
Martin

skolusu
Member
Posts: 43
Joined: Sat Jul 26, 2008 12:38 am

Post by skolusu » Wed Jul 07, 2010 1:18 am

Martin,

The following DFSORT JCL will give you the desired results. I assumed that your input is FB recfm and 80 byte LRECL and the time difference can only span over 24 hours.

Code: Select all

//STEP0100 EXEC PGM=SORT                                                
//SYSOUT   DD SYSOUT=*                                                  
//SORTIN   DD *                                                         
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
00110186  02000268  00110186  02000310  PJDTED71  00000007              
00110186  20040443  00110186  20292051  PJDTTG12  00012542              
00110365  23590443  00111001  00002051  PJDTTG13  00012542              
//SORTOUT  DD SYSOUT=*                                                  
//SYSIN    DD *                                                         
  SORT FIELDS=COPY                                                      
  INREC IFTHEN=(WHEN=INIT,                                              
  OVERLAY=(081:(11,2,ZD,MUL,+3600,ADD,      $ HH1 * 3600 +              
                13,2,ZD,MUL,+0060,ADD,      $ MM1 * 0060 +              
                15,2,ZD),M11,LENGTH=8,      $ SS1 = T1 (SECS)           
                X,                          $ SPACE                     
               (31,2,ZD,MUL,+3600,ADD,      $ HH2 * 3600 +              
                33,2,ZD,MUL,+60,ADD,        $ MM2 * 0060 +              
                35,2,ZD),M11,LENGTH=8,      $ SS2 = T2 (SECS)           
                X,                          $ SPACE                     
           099:90,8,ZD,SUB,81,8,ZD,                                     
               ZD,LENGTH=8,                 $ T2 - T1 = TDIFF           
                X,                          $ SPACE                     
           108:24,2,ZD,SUB,04,2,ZD,                                     
               ZD,LENGTH=2,                 $ YY2 - YY1 = YDIFF         
                X,                          $ SPACE                     
           111:26,3,ZD,SUB,06,3,ZD,                                     
               ZD,LENGTH=3)),               $ DDD2 - DDD1 = DDIFF       
                                                                        
  IFTHEN=&#40;WHEN=&#40;111,3,ZD,NE,0&#41;,             $ IF DAY DIFF <> 0          
  OVERLAY=&#40;099&#58;+86400,ADD,99,8,ZD,          $ YES ADD 24 HOUR           
               M11,LENGTH=8&#41;&#41;                                           
                                                                        
  OUTREC IFOUTLEN=80,IFTHEN=&#40;WHEN=INIT,                         
  OVERLAY=&#40;115&#58;99,8,ZD,DIV,+3600,EDIT=&#40;TT&#41;, $ HH                
               C'&#58;',                        $ COLON             
               &#40;99,8,ZD,MOD,+3600&#41;,                             
                DIV,+60,EDIT=&#40;TT&#41;,          $ MM                
               C'&#58;',                        $ COLON             
               &#40;&#40;99,8,ZD,MOD,+3600&#41;,                            
                MOD,+60&#41;,EDIT=&#40;TT&#41;,         $ SS                
               C',',                        $ COMMA             
               &#40;+100,SUB,17,2,ZD&#41;,ADD,      $ &#40;100 - HS1&#41; +     
                 37,2,ZD,EDIT=&#40;TT&#41;,         $ HS2 = HSDIFF      
                X,                          $ SPACE             
           127&#58;&#40;51,6,ZD,MOD,+3600&#41;,                             
                DIV,+60,EDIT=&#40;TT&#41;,          $ CPU MM            
               C'&#58;',                        $ COLON             
               &#40;&#40;51,6,ZD,MOD,+3600&#41;,                            
                MOD,+60&#41;,EDIT=&#40;TT&#41;,         $ CPU SS            
               C',',                        $ COMMA             
               57,2,                        $ CPU HS            
               C'"'&#41;&#41;,                                          
  IFTHEN=&#40;WHEN=INIT,                                            
  BUILD=&#40;41,8,                              $ JOBNAME           
         2X,                                $ SPACE             
         11,06,ZD,EDIT=&#40;TT&#58;TT&#58;TT&#41;,          $ START TIME        
         2X,                                $ SPACE             
         31,06,ZD,EDIT=&#40;TT&#58;TT&#58;TT&#41;,          $ END TIME          
         2X,                                $ SPACE             
         115,11,                            $ TIME DIFF         
         2X,                                $ SPACE             
         127,9,                             $ CPU TIME          
         2X,                                $ SPACE             
         4,5,Y2T,TOGREG=Y4T&#41;&#41;               $ START DATE        
//*


The output from this job is

Code: Select all

PJDTED71  02&#58;00&#58;02  02&#58;00&#58;03  00&#58;00&#58;01,42  00&#58;00,07"  20100705 
PJDTTG12  20&#58;04&#58;04  20&#58;29&#58;20  00&#58;25&#58;16,08  02&#58;05,42"  20100705 
PJDTTG13  23&#58;59&#58;04  00&#58;00&#58;20  00&#58;01&#58;16,08  02&#58;05,42"  20101231 
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

Martin G.
Member
Posts: 7
Joined: Thu Mar 11, 2010 6:39 pm

Post by Martin G. » Wed Jul 07, 2010 7:02 pm

Hello Skolusu,

that is a very nice solution, thank you for that!
I never thought about calculating the timestamps like you did, because I wanted to do it with format identifiers, but maybe those fields are not suitable for "mathematical operations".
One correction I have to add, but maybe that happened because of the short time of your answer. The difference in runtime between 02000268 and 02000310 is not 1.42 secs, as your solution presents, but only 0.42 secs. You calculated the difference between the hhmmss-part of the timestamps and made an extra-calculation for the hundredths of a second. In fact the hundredths of a second should be included in the calculation, but the correction was only adding a few zeroes and a slight change to the code. The space you provided for the figures was sufficient.
Now the code looks like:

Code: Select all

...
OVERLAY=&#40;081&#58;&#40;11,2,ZD,MUL,+360000,ADD,        $ HH1 * 3600 +     
              13,2,ZD,MUL,+006000,ADD,        $ MM1 * 0060 +     
              15,2,ZD,MUL,+000100,ADD,        $ SS1 * 100  +     
              17,2,ZD&#41;,M11,LENGTH=8,          $ HS1 = T1 &#40;HSECS&#41; 
              X,                              $ SPACE            
             &#40;31,2,ZD,MUL,+360000,ADD,        $ HH2 * 3600 +     
              33,2,ZD,MUL,+6000,ADD,          $ MM2 * 0060 +     
              35,2,ZD,MUL,+100,ADD,           $ SS2 * 0100 +     
              37,2,ZD&#41;,M11,LENGTH=8,          $ HS2 = T2 &#40;HSECS&#41; 
              X,                              $ SPACE            
         099&#58; ...
...
IFTHEN=&#40;WHEN=INIT,                                      
OVERLAY=&#40;115&#58;99,8,ZD,DIV,+360000,EDIT=&#40;TT&#41;,  $ HH       
             C'&#58;',                           $ COLON    
             &#40;99,8,ZD,MOD,+360000&#41;,                     
              DIV,+6000,EDIT=&#40;TT&#41;,           $ MM       
             C'&#58;',                           $ COLON    
             &#40;&#40;99,8,ZD,MOD,+360000&#41;,                    
              MOD,+6000&#41;,DIV,+100,                      
             EDIT=&#40;TT&#41;,                      $ SS       
             C',',                           $ COMMA    
             &#40;&#40;99,8,ZD,MOD,+360000&#41;,                    
              MOD,+6000&#41;,MOD,+100,                      
             EDIT=&#40;TT&#41;,                      $ HS       
              X,                             $ SPACE    
         127&#58; ... 
...
This, together with the rest of your code, works as I wanted it to do.
Thank you once again,
Martin

skolusu
Member
Posts: 43
Joined: Sat Jul 26, 2008 12:38 am

Post by skolusu » Wed Jul 07, 2010 9:14 pm

Martin G. wrote:Hello Skolusu,
One correction I have to add, but maybe that happened because of the short time of your answer. The difference in runtime between 02000268 and 02000310 is not 1.42 secs, as your solution presents, but only 0.42 secs. You calculated the difference between the hhmmss-part of the timestamps and made an extra-calculation for the hundredths of a second. In fact the hundredths of a second should be included in the calculation, but the correction was only adding a few zeroes and a slight change to the code. The space you provided for the figures was sufficient.
This, together with the rest of your code, works as I wanted it to do.
Thank you once again,
Martin
Hi martin,

Oops. Sorry I was calculating in DB2 timestamp format with Microseconds in place. I am glad you could change it easily.
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others