Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Function in Cobol?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I want to add a total line to a report. I can't figure out a good way to add minutes and seconds, because the copybook has the fields in alphanumeric format. My orignally thought was to convert all the time into seconds and work my way back into hours, minutes and seconds. The line is a total duration of transmission the format should be hh:mm:ss

Is there a simpler way to do this?
 
Hi,

I think you have the right idea about it. But be aware of a change of the day! Suppose the transmission starts at 23:50 and ends at 00:10...

Using DB2 SQL can help you perhaps.

Regards,

Crox



 
I was thinking there has to be a way to get this from the system. When the jcl finishes doesn't it display the elapsed time? Maybe the JCL could print this out at the end of the job or something.
 
We did something like this in a java class using only basic commands and logic. Basically we developed the logic using if/else if/else logic on a model that does nothing but add 1 unit to the lower number till two fields are equal. The counter kept track of the elapsed time. We were using dates and kept track of the days. This logic isnt that complicated, but it is time consuming to develop and test. On something like elapsed time you may want it down the 1/100th of a second.
Time is so simple because you know every time there are the same number of seconds in a minute. On a date the logic is much more complicated.
You never said what the time of a normal sownload is?
1 minute, one hour, 2 days?
 
ceh4702. If you are running under MVS, the elapsed time is already included in your Job Messages. If you want to include the elapsed time for the job in a report... the report would have to be produced AFTER the job has completed. Accessing the elapsed run time of a prior job step is possible, but very difficult, and you will need assistance from your MVS System Programmer.

The original poster has still not clarified exactly what s/he wants, and where it is coming from or going to.

Stephen J Spiro
Member, J4 COBOL Standards Committee
check it out at

stephenjspiro at hotmail.com
 
Again, looking this up in my trusty IBM VS COBOL II manual in our "Bookmanager" system:

You can do an ACCEPT command and get the current time into a designated field which I called CURRENT-TIME for this example. It goes like this:

ACCEPT CURRENT-TIME FROM TIME.

This will place the hour, minutes, seconds into an implied PIC 9(8) field CURRENT-TIME (you can choose a different name for your variable if you choose). I am assuming that you want the current time that the report is written/printed.

You can format the time in any way you wish once you get the 8 figures.

Hope this helps, Nina Too
 
Looking at your question, and wondering if you want the total time that it takes for your job to be run: assuming that it's a batch job with a JCL, and assuming that you can not get this figure from your job messages (it is included in the JCL report under MVS as Stephen Spiro has indicated):

In the first program, at the very beginning, do the ACCEPT [variable] FROM TIME command. Pass this information through all the programs which are run on the job. When you get to the last step in the job, at the last program being run, at the end, do another such ACCEPT command using a different variable. Then have the last program subtract the first time from the second time.

I'm not sure that you can subtract one time directly from another; you may have to convert them all into seconds, do the subtraction, then convert the result back into hours/minutes/seconds.

But if you can possibly get the elapsed time from the job report, use that.

Nina Too
 
Say Sa,

Enter the dialogue here; let us know if we're still on the right track. I think you want the time of each xaction and a total field for all xactions. Right/Wrong? Let us know.

Do as Crox suggested. Here's some p code:
Code:
05  wrk-start-time.
      10  wrk-s-hrs       pic 9(003) comp-3.
      10  wrk-s-mins      pic 9(003) comp-3.   
      10  wrk-s-secs      pic 9(005) comp-3. 

Do the same for wrk-end-time.
 
move start/end times to wrk-start/end at the elementary level, i.e. hrs, mins, secs
if start-time > end-time add 24 to wrk-s-hrs
compute wrk-xact-secs = (wrk-e-hrs - wrk-s-hrs)   * 3600
                      + (wrk-e-mins - wrk-s-mins) * 60 
                      + (wrk-e-secs - wrk-s-secs) 
add wrk-xact-secs    to  wrk-xact-tot

Later, when you're ready to print the totals, convert them to the form you need.

Regards, Jack.
 
First of all thank you all for your input, you're all great! To answer some questions.....
First: the picture of the field in question is
pic x(02) -- needing to do some calcs' I was moving it into a pic 9(02).
Second: I am taking the duration time( a specific field) for each record and converting them to seconds for the total duration of transmission, then dividing my way back to HH:MM:SS
This is a control report- I have to use some sort of a condition to select only successful records. I was trying to use EVALUATE return-code
WHEN success
**then my logic for moving and calcing the time fields
END-EVALUATE
 
NinaToo the idea of ACCEPTING the start time and end time and doing the calc was great. The problem lies in this....
Time of Transmission: Record one=3:34
Record two=3:43
(That is a differnce of nine seconds....)
Duration of Transmission: Record one: 00:59
(The duration of the first transmission is almost a full minute)

Thanx
Sa
 
I'm still a bit confused as to what information you actually wanted. Because if the transmission actually takes 9 seconds, then how can it take 59 seconds? Unless we're looking at two different transmissions.

Which is quite possible. I believe that you indicated that the transmission times are values passed to you by another program in a PIC X(02) field, which you changed to a PIC 9(02) field. What I was doing with the two ACCEPT's was to see how long the job actually takes to run. This might not be what you are looking for.

Let me know, OK? Nina Too
 
Thanks everyone for you help. It was a picture problem. The value success was being centered and I was checking it as being right justified.
That was why my evaluate statement wasn't working.

Thanks again
Sa
 
For those interested I have this type of time conversion as an example in the intrinsic function chapter of Sams Teach Yourself COBOL in 24 hours.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top