Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
poshabrar

New User

Joined: 10 Jul 2006
Posts: 23

 Posted: Sun Nov 23, 2008 5:47 pm    Post subject: Time comparision in COBOL...... 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.

Bill O'Boyle

CICS Moderator

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

 Posted: Sun Nov 23, 2008 9:13 pm    Post subject: Re: Time comparision in COBOL...... 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
Terry Heinze

JCL Moderator

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

Posted: Sun Nov 23, 2008 9:24 pm    Post subject:

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      .
Terry Heinze

JCL Moderator

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

 Posted: Sun Nov 23, 2008 9:25 pm    Post subject: ...assuming both times are in the same day, of course.
poshabrar

New User

Joined: 10 Jul 2006
Posts: 23

 Posted: Mon Nov 24, 2008 9:32 pm    Post subject: Reply to: Time comparision in COBOL...... Thanks a lot Tary... Didn't even think that this would be so easy.... This simple if comparision works fine as I needed.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Linkage editor is part of COBOL, z/OS... ankit.jain COBOL Programming 4 Fri Apr 20, 2018 4:17 pm Difference between EQUAL and EQUAL TO... jithinraghavan COBOL Programming 3 Thu Apr 19, 2018 2:22 am Call COBOL or PLI with a click from w... vaibhav gs All Other Mainframe Topics 1 Mon Apr 16, 2018 7:29 pm COBOL MVS options BiswajitDG COBOL Programming 8 Fri Apr 06, 2018 12:35 am How syntax check at Bind time is diff... Poha Eater DB2 5 Wed Mar 21, 2018 9:16 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us