If you're writing a batch program, I haven't seen any built-in functionality that handles this.
In a CICS environment, it's easily done using the Interval Control facility.
In batch, you can play with COBOL's time/date function to delay something. Just grab the current time/date when the program starts running, then grab it again later. You can use it to delay ending the program etc until time/date 2 is more than 15 mins later than time/date 1, and so on.
"Timer services" are largely operating system dependent, as pointed by Crox. COBOL does have its own implementations. How timers are used depends on what your application design and requirements are.
Lets look at a couple of timer implementations and usages. Some of these solutions may not be available in all platforms.
There is the OPEN WITH TIME LIMITS statement in COBOL. You use this statement to attempt an I/O completion within a time frame that you specify. Creative usage: You can "hang" your program for a while on an I/O that you know will not complete before the time you set runs out.
You can use Dave's solution in a loop implementing a real clock controlled delay. For example, when your application requires a timing based on a real clock. However, you will need an assist from the operating system in order to go to "sleep" now and then, and avoid taxing the CPU.
Operating systems usually have a line-up of quite sophisticated timer services you can choose from. Your application dictates which one you choose.
If you make your own function, using start-date and start-time and compare it with the current-date and current-time, it can be very cpu-time consuming. That is why it is better to find an operating system utility to do this because those should not use (much) cpu-time.
But of course, you can make something in COBOL with such a functionality.
Also with the newer COBOL compilers, you can use expressions with the FUNCTION INTEGER-OF-DATE combined with time.
From the references to "batch" and "assembler" - I am taking a WILD guess that this *may* be an IBM mainframe environment. If so, then YES, there is a "built-in" (but little documented) solution.
If you do a call to the IBM provided ILBOWAT0 (first "O" is letter "O" - 2nd "0" is number "0" passing it a binary value representing seconds to "wait".
NOTE: This is a 24-bit routine. Therefore, you need to either call it from "below-the-line" - or call it dynamically from a program compiled with DATA(24).
***
If you are NOT on an IBM mainframe environment, let us know what your environment is - to get a specific solution.
On DOS you can use USER or C Libraries to call OS level calls. On windows you can call WIN32API. On Unix you can call functions from Shared Libraries of UNIX. In all cobol OS function calling mechanism is there.
On mainframes also you can call assembly routines from COBOL.
to get the exact answer you should always write the hardware and compiler version.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.