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

Time comparision in COBOL......


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
poshabrar

New User


Joined: 10 Jul 2006
Posts: 23

PostPosted: Sun Nov 23, 2008 5:47 pm
Reply with quote

I have two(A1,A2) varibles which hold HH:MM:SS data. I want to compare these variables IF(A1>A2)...

How to do this with minimal coding.

I already implemented the logic of moving HH:MM:SS into another variable and compare it as an integer HHMMSS.

Please suggest me if this can be done in any other way.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Sun Nov 23, 2008 9:13 pm
Reply with quote

If one of the HHMMSS occurred on a different day and greater than one day apart, this will be impossible to determine.

Do you have the associated date with these HHMMSS values?

At the very least, you need to convert them to seconds and then compare.

What if you had an HHMMSS of 105745 and another of 110310? Simple subtraction will not give you the answer without first converting or an HHMMSS of 235803 and 000724 (next day)?

Take a look at the LE Callable Service routine "CEESECS", which (amongst others) requires a date/time parm and will convert and return each of these to seconds.

As another idea (but also requires the associated date), use FUNCTION INTEGER-OF-DATE (or INTEGER-OF-DAY if date-format is julian) to calculate the lilian-days of each date. Then multiply this result by 86400 (number of seconds in a day), followed by converting the HHMMSS to seconds (HH * 3600, MM * 60 and SS as-is). Add these calculated seconds to each seconds-in-a-day result and then compare.

HTH....

Bill
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Sun Nov 23, 2008 9:24 pm
Reply with quote

I'd code it as follows:
Code:
 01  a1  pic  x(8).
*             hh:mm:ss
 01  a2  pic  x(8).
*             hh:mm:ss
     if a1 > a2
         display 'a1 > a2'
     else
         if a1 < a2
             display 'a1 < a2'
         else
             display 'a1 = a2'
         end-if
     end-if
     .
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Sun Nov 23, 2008 9:25 pm
Reply with quote

...assuming both times are in the same day, of course.
Back to top
View user's profile Send private message
poshabrar

New User


Joined: 10 Jul 2006
Posts: 23

PostPosted: Mon Nov 24, 2008 9:32 pm
Reply with quote

Thanks a lot Tary... Didn't even think that this would be so easy.... This simple if comparision works fine as I needed.



icon_biggrin.gif icon_biggrin.gif icon_biggrin.gif icon_biggrin.gif icon_biggrin.gif icon_biggrin.gif icon_biggrin.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 -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top