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

Calculate the time difference


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Jasand

New User


Joined: 23 Jan 2009
Posts: 32
Location: Tamil nadu

PostPosted: Mon Apr 11, 2011 5:47 pm
Reply with quote

Hi,

Please advise me on the below SORT to calculate the time diff in HH:SS

Input: FB/74
Code:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
******************  REPORT START  ******                           

XXXX 09:02 09:02 09:09 09:09 09:16 09:45 09:50 09:51  20110407           
YYY  17:42 17:45 17:52 17:52 17:56 19:15 19:36 20:05  20110407               
                                                                   
******************  REPORT END    ******


need to calculate the difference between the first and last time fields
eg: In first record(09:51 - 09:02) and populate the o/p in 64th field

The difficulty is that, the START and STOP timings may be both before midnight, after midnight , or one before midnight.
eg:
Code:
A1:A2  B1:B2                                   
22:10  23:20                                   
23:20  2:10                                     
2:40   5:30                                     
                                               
CALCULATE HOURS HH       CALCULATE SECONDS SS   
--------------------     --------------------- 
 IF      THEN              IF       THEN       
--------------------     --------------------- 
B1>A1    B1-A1            B2>A2    B2-A2       
B1<A1    (24-A1)+B1       B2<A2    A2-B2       
B1=A1    00               B2=A2    00           
OTHERS   C'HH'            OTHERS   C'MM'       


Code:
//STEP10  EXEC  PGM=SYNCTOOL                                         
//SYSOUT   DD  SYSOUT=*                                               
//IN       DD  DSN=INPUT.Dataset,DISP=SHR                         
//MID      DD  DSN=MID.Dataset,                             
//             DISP=(NEW,CATLG,DELETE),                               
//             DCB=(RECFM=FB,BLKSIZE=0),                             
//             UNIT=SYSDA,                                           
//             SPACE=(TRK,(100,50),RLSE)                             
//OUT      DD DSN=OUT.Dataset,                             
//             DISP=(NEW,CATLG,DELETE),                               
//             DCB=(RECFM=FB),                                       
//             UNIT=SYSDA,                                           
//             SPACE=(TRK,(100,50),RLSE)                             
//TOOLMSG  DD SYSOUT=*                                               
//SYSOUT   DD SYSOUT=*                                               
//DFSMSG   DD SYSOUT=*                                               
//TOOLIN   DD *                                                       
  SORT FROM(IN) TO(MID) USING(CTL1)                                   
  SELECT FROM(MID) TO(OUT) USING(CTL2)                               
/*                                                                   
//CTL1CNTL DD *                                                       
* CALCULATE HOUR DIFFERENCE HH                                       
  SORT FIELDS=COPY                                                   
  INCLUDE COND=(55,1,CH,EQ,C'2')                                     
  INREC IFTHEN=(WHEN=(48,2,ZD,GT,6,2,ZD),                             
                OVERLAY=(64:48,2,ZD,SUB,6,2,ZD,M11,LENGTH=2,66:C':')),
        IFTHEN=(WHEN=(48,2,ZD,EQ,6,2,ZD),                             
                OVERLAY=(64:C'00:'))                                 
/*                                                                   
//CTL2CNTL DD *                                                       
* CALCULATE SECONDS DIFFERENCE SS                                     
  SORT FIELDS=COPY                                                   
  INCLUDE COND=(55,1,CH,EQ,C'2')                                     
  INREC IFTHEN=(WHEN=(51,2,ZD,GT,9,2,ZD),                             
                OVERLAY=(67:51,2,ZD,SUB,9,2,ZD,M11,LENGTH=2)),       
        IFTHEN=(WHEN=(51,2,ZD,LT,9,2,ZD),                             
                OVERLAY=(67:9,2,ZD,SUB,51,2,ZD,M11,LENGTH=2)),       
        IFTHEN=(WHEN=(51,2,ZD,EQ,9,2,ZD),                             
                      OVERLAY=(64:C'00'))                             
/*   



The CTL1 and CTL2 work good individually, but they dont work when put as above

I am getting only the HOUR diff in the MID file.
Also I am not able to handle the below conditions,
B1<A1 (24-A1)+B1 - in hour calculation
OTHERS C'HH' and OTHERS C'SS'


Appreciate your help on this.
Back to top
View user's profile Send private message
Jasand

New User


Joined: 23 Jan 2009
Posts: 32
Location: Tamil nadu

PostPosted: Mon Apr 11, 2011 5:49 pm
Reply with quote

Please find below the SYSOUT message that I get..
Code:
CTL1CNTL :                                                                     
  SORT FIELDS=COPY                                                             
  INCLUDE COND=(55,1,CH,EQ,C'2')                                               
  INREC IFTHEN=(WHEN=(48,2,ZD,GT,6,2,ZD),                                     
                OVERLAY=(64:48,2,ZD,SUB,6,2,ZD,M11,LENGTH=2,66:C':')),         
        IFTHEN=(WHEN=(48,2,ZD,EQ,6,2,ZD),                                     
                OVERLAY=(64:C'00:'))                                           
PARMLIST :                                                                     
OPTION RESINV=0,ARESINV=0,MSGDDN=DFSMSG,SORTIN=IN,SORTOUT=MID,SORTDD=CTL1,DYNAL
OC                                                                             
WER428I  CALLER-PROVIDED IDENTIFIER IS "0001"                                 
WER108I  IN       : RECFM=FB   ; LRECL=    74; BLKSIZE= 27972                 
WER257I  INREC RECORD LENGTH =    74                                           
WER110I  MID      : RECFM=FB   ; LRECL=    74; BLKSIZE= 27972                 
WER055I  INSERT          0, DELETE          6                                 
WER449I  SYNCSORT GLOBAL DSM SUBSYSTEM ACTIVE                                 
WER054I  RCD IN         13, OUT          7                                     
WER169I  RELEASE 1.3 BATCH 0513 TPF LEVEL 2.2                                 
WER052I  END SYNCSORT - I072616N,STEP10,,DIAG=8A00,5140,A2AE,006E,C252,6CEB,22E
******************************* BOTTOM OF DATA ********************************


Let me know if I am not clear in stating the requirement.
Back to top
View user's profile Send private message
Jasand

New User


Joined: 23 Jan 2009
Posts: 32
Location: Tamil nadu

PostPosted: Thu Apr 21, 2011 11:07 am
Reply with quote

Hi All,

Got the output partially with the below code,

Code:
//STEP0100 EXEC PGM=SYNCTOOL                                           
//IN       DD DSN=XXX.SAMPLE,DISP=SHR                           
//MID      DD DSN=XXX.SAMPLE.MID,                               
//            DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,                     
//            SPACE=(CYL,(15,5),RLSE),                                 
//            DCB=(RECFM=FB)                                           
//OUT      DD DSN=XXX.SAMPLE.OUT,                               
//            DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,                     
//            SPACE=(CYL,(15,5),RLSE),                                 
//            DCB=(RECFM=FB)                                           
//TOOLMSG  DD SYSOUT=*                                                 
//SYSOUT   DD SYSOUT=*                                                 
//DFSMSG   DD SYSOUT=*                                                 
//TOOLIN   DD *                                                       
  SORT FROM(IN) TO(MID) USING(CTL1)                                   
  SORT FROM(MID) TO(OUT) USING(CTL2)                                   
//CTL1CNTL DD *                                                       
  SORT FIELDS=COPY                                                     
  INCLUDE COND=(55,1,CH,GE,C'2')                                       
* CALCULATE HOUR DIFFERENCE HH                                         
  INREC IFTHEN=(WHEN=(48,2,ZD,GT,6,2,ZD),                             
                OVERLAY=(64:48,2,ZD,SUB,6,2,ZD,M11,LENGTH=2,66:C':')),
        IFTHEN=(WHEN=(48,2,ZD,EQ,6,2,ZD),                             
                OVERLAY=(64:C'00:'))                                   
//CTL2CNTL DD *                                                       
  SORT FIELDS=COPY                                                     
  INCLUDE COND=(55,1,CH,GE,C'2')                                       
* CALCULATE SECONDS DIFFERENCE SS                                     
  INREC IFTHEN=(WHEN=(51,2,ZD,GT,9,2,ZD),                             
                OVERLAY=(67:51,2,ZD,SUB,9,2,ZD,M11,LENGTH=2)),         
        IFTHEN=(WHEN=(51,2,ZD,LT,9,2,ZD),                             
                OVERLAY=(67:9,2,ZD,SUB,51,2,ZD,M11,LENGTH=2)),         
        IFTHEN=(WHEN=(51,2,ZD,EQ,9,2,ZD),                             
                      OVERLAY=(64:C'00'))                             
/*           


Need to add one more condition int he HOUR calculation in CTL1
ie. (24-A1)+B1 when B1<A1
Can somebody help me out please..
Theo/p I get now is
Code:
AAAA 09:02 09:02 09:09 09:09 09:16 09:45 09:50 09:51  20110407 00:49
BBB  17:42 17:45 17:52 17:52 17:56 19:15 19:36 20:05  20110407 03:37
CCC  19:40 19:44 20:03 20:03 20:15 21:36 22:07 22:07  20110407 03:33
DDD  19:40 19:44 20:03 20:03 20:06 21:54 22:31 22:31  20110407 03:09
EEE  19:40 19:44 19:58 20:03 20:07 21:48 22:01 22:00  20110407 03:40
FFFF 22:00 22:05 22:16 22:41 22:52 23:50 00:14 00:05  20110407    05
GGG  23:16 23:19 23:40 23:40 23:43 -N/A- -N/A- 00:26  20110407    10
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Thu Apr 21, 2011 7:17 pm
Reply with quote

Jasand,

Looks like the sample data is very familiar to me icon_smile.gif
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Fri Apr 22, 2011 10:20 pm
Reply with quote

Jasand,

You might want to re-visit your requirement.
Code:
BBB  17:42 17:45 17:52 17:52 17:56 19:15 19:36 20:05  20110407 03:37
The difference in time here should be 20:05 - 17:42 = 02:23 ie. 2 hrs 23 mins. But your expected output says 03:37. icon_eek.gif
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Fri Apr 22, 2011 10:53 pm
Reply with quote

It appears that he's:
  1. Subtracting the rightmost quantity from the leftmost
  2. Subtracting hours and minutes as if they were completely unrelated
  3. Not using a needed sign in his answer

These errors are probably an indication of his lack of knowledge of SyncSort.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Apr 22, 2011 11:06 pm
Reply with quote

An easy to uderstand COBOL program would have take a lot less than 11 days to write.
Back to top
View user's profile Send private message
Jasand

New User


Joined: 23 Jan 2009
Posts: 32
Location: Tamil nadu

PostPosted: Mon Apr 25, 2011 9:54 am
Reply with quote

@ All..
Sorry.. Its my stupidity with the logic 'Subtracting hours and minutes as if they were completely unrelated' icon_sad.gif

Yes Arun.. the same sample data and a different requirement icon_smile.gif
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Mon Apr 25, 2011 12:07 pm
Reply with quote

The below Syncsort job should give you what I assume you're trying to achieve. The input/output files were assumed to be of FB/LRECL=74.
Code:
//STEP01A  EXEC PGM=SORT                                               
//SORTIN   DD  DSN= Input file  (FB/74)                               
//SYSOUT   DD  SYSOUT=*                                               
//SORTOUT  DD  DSN= Output file (FB/74)                               
//SYSIN    DD  *                                                       
  OPTION COPY                                                         
  INREC IFTHEN=(WHEN=INIT,                                             
    OVERLAY=(81:(06,2,ZD,MUL,+60),ADD,09,2,ZD,M11,LENGTH=4)),         
        IFTHEN=(WHEN=(48,2,ZD,LT,06,2,ZD),                             
    OVERLAY=(85:((48,2,ZD,ADD,+24),MUL,+60),ADD,51,2,ZD,M11,LENGTH=4)),
        IFTHEN=(WHEN=NONE,                                             
    OVERLAY=(85:(48,2,ZD,MUL,+60),ADD,51,2,ZD,M11,LENGTH=4))
         
  OUTREC IFOUTLEN=74,IFTHEN=(WHEN=INIT,                               
    OVERLAY=(89:85,4,ZD,SUB,81,4,ZD,M11,LENGTH=4,                     
             64:89,4,ZD,DIV,+60,M11,LENGTH=2,C':',                     
                89,4,ZD,MOD,+60,M11,LENGTH=2))                         
Input
Code:
AAAA 09:02 09:02 09:09 09:09 09:16 09:45 09:50 09:51  20110407
BBB  17:42 17:45 17:52 17:52 17:56 19:15 19:36 20:05  20110407
CCC  19:40 19:44 20:03 20:03 20:15 21:36 22:07 22:07  20110407
DDD  19:40 19:44 20:03 20:03 20:06 21:54 22:31 22:31  20110407
EEE  19:40 19:44 19:58 20:03 20:07 21:48 22:01 22:00  20110407
FFFF 22:00 22:05 22:16 22:41 22:52 23:50 00:14 00:05  20110407
GGG  23:16 23:19 23:40 23:40 23:43 -N/A- -N/A- 00:26  20110407
SORTOUT had
Code:
AAAA 09:02 09:02 09:09 09:09 09:16 09:45 09:50 09:51  20110407 00:49
BBB  17:42 17:45 17:52 17:52 17:56 19:15 19:36 20:05  20110407 02:23
CCC  19:40 19:44 20:03 20:03 20:15 21:36 22:07 22:07  20110407 02:27
DDD  19:40 19:44 20:03 20:03 20:06 21:54 22:31 22:31  20110407 02:51
EEE  19:40 19:44 19:58 20:03 20:07 21:48 22:01 22:00  20110407 02:20
FFFF 22:00 22:05 22:16 22:41 22:52 23:50 00:14 00:05  20110407 02:05
GGG  23:16 23:19 23:40 23:40 23:43 -N/A- -N/A- 00:26  20110407 01:10

PS. The above sort assumes that the time difference would always be less than 24 hours and hence might need changes if that does not hold true in your case.
Back to top
View user's profile Send private message
Jasand

New User


Joined: 23 Jan 2009
Posts: 32
Location: Tamil nadu

PostPosted: Mon Apr 25, 2011 12:39 pm
Reply with quote

Thank you Arun.. It works good.
the time difference would always be less than 24 hours and so it exactly matches for my requirement..
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Mon Apr 25, 2011 2:13 pm
Reply with quote

You're welcome. Glad that it helped. icon_smile.gif
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 -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts To get the the current time DFSORT/ICETOOL 13
No new posts RC query -Time column CA Products 3
No new posts C Compile time time stamps Java & MQSeries 10
No new posts how to calculate SUM value for VB fil... DFSORT/ICETOOL 1
No new posts Parallelization in CICS to reduce res... CICS 4
Search our Forums:

Back to Top