Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

How to let a COBOL program sleep 5 seconds
Hi, folks

Anybody can tell me how to let a COBOL program sleep 5 seconds? I am new to
COBOL. Sorry for the stupid question. :)


-William



Report this thread to moderator Post Follow-up to this message
Old Post
William Cai
09-10-04 08:55 PM


Re: How to let a COBOL program sleep 5 seconds
On 9 Sep 2004 20:24:23 -0700, "William  Cai" <caiwenliang@gmail.com>
wrote:

>Hi, list
>
>I am looking for the solution. Could anybody please tell me how to code
>instead of discussing if sleep is a Cobol standard function? Though
>your dicussion also helps me. :P
>
>Repeat my question.
>I wanna develop a COBOL program. The program will sleep several seconds
>according to user's input.

There are two kinds of sleep:

1. Run in a loop until n seconds have elapsed.
2. Tell the operating system to mark you asleep and wake you in n
seconds.

In human terms, 1. would not be called sleep, it would be called
wasting time. Unfortunately,  it is the best you can do in standard
Cobol.

working-storage section.
01  time-now.
10  hours                   pic  9(02).
10  minutes                 pic  9(02).
10  seconds                 pic  9(02).
10  hundredths              pic  9(02).
01  time-integer             pic  9(09).
01  wakeup-integer       pic  9(09).
linkage section.
01  sleep-duration        pic 9.

procedure division using sleep-duration.
perform read-clock
compute wakeup-integer = time-integer + (sleep-duration * 100)
perform read-clock until time-integer > wakeup-integer
goback.
read-clock.
accept time-now from time
compute time-integer =
((((hours * 60) + minutes) * 60) + seconds) * 100) + hundredths).

If your compiler supports Events or MultiThreading, find the Wait
function, have the program wait for an event that will never happen or
return an error in n seconds. That would be true sleep, type 2. above.

Report this thread to moderator Post Follow-up to this message
Old Post
Robert Wagner
09-10-04 08:55 PM


Re: How to let a COBOL program sleep 5 seconds
In article <x6qdnYOZU9SRkaPcRVn-pw@giganews.com>,
"JerryMouse" <nospam@bisusa.com> wrote:

> Richard wrote: 
>
> Ah, not exactly. Starting with Win98 (and all the NT variants, 2K, XP),
> Windows has preemptive multi-tasking and will interrupt a CPU bound job to
> give cycles to other applications.
>
>

And they might get it working correctly in time for Win 2008...


Report this thread to moderator Post Follow-up to this message
Old Post
Joe Zitzelberger
09-11-04 01:55 AM


Re: How to let a COBOL program sleep 5 seconds
On Tue, 7 Sep 2004 14:57:56 +0800, "William Cai"
<wenliang_cai@yahoo.com.cn> wrote:

>Update my question:
>
>I list my program as below. But whatever I input, the program will sleep fo
r
>a very long time. I am sure not if the program hangs. Anyone can help? Than
k
>you.
>
>       IDENTIFICATION DIVISION.
>       PROGRAM-ID. EXAM1.
>       ENVIRONMENT DIVISION.
>       DATA DIVISION.
>       WORKING-STORAGE SECTION.
>       77 SLEEP-SEC PIC 9.
>       PROCEDURE DIVISION.
>       S. DISPLAY 'THIS IS COBOL'.
>          DISPLAY 'PLEASE INPUT THE SECONDS FOR SLEEP'.
>          ACCEPT SLEEP-SEC.
>          DISPLAY 'WILL SLEEP ', SLEEP-SEC, ' SECONDS'.
>          CALL "sleep" USING SLEEP-SEC;
>          STOP RUN.
>
>"William Cai" <wenliang_cai@yahoo.com.cn> wrote in message
>news:chjjss$t76$1@mail.cn99.com...
>Hi, folks
>
>Anybody can tell me how to let a COBOL program sleep 5 seconds? I am new to
>COBOL. Sorry for the stupid question. :)

Sleep is not a *standard* Cobol function; is it a standard C function.
It appears you're calling the C function. If true, change sleep-sec to
binary pic 9(9)  and call using by value sleep-sec.

Report this thread to moderator Post Follow-up to this message
Old Post
Robert Wagner
09-11-04 08:55 AM


Re: How to let a COBOL program sleep 5 seconds
I use:

01 SLEEP-TIME           PIC 9(9)        COMP VALUE 500000.

(OS LINUX IN MY CASE, MF-COBOL)

ACCEPT SOME-NUM-FIELD AT 2479 WITH SIZE 1 AUTO TIMEOUT SLEEP-TIME.



William Cai wrote:

> Hi, folks
>
> Anybody can tell me how to let a COBOL program sleep 5 seconds? I am new
> to COBOL. Sorry for the stupid question. :)
>
>
> -William

--
Vaclav Snajdr

Report this thread to moderator Post Follow-up to this message
Old Post
Vaclav Snajdr
09-11-04 08:55 AM


Re: How to let a COBOL program sleep 5 seconds
On Tue, 7 Sep 2004 14:57:56 +0800, "William Cai"
<wenliang_cai@yahoo.com.cn> wrote:

>Anybody can tell me how to let a COBOL program sleep 5 seconds? I am new to
>COBOL. Sorry for the stupid question. :)

If my suggested fix works, you might do one or both of the following:

1. Write a prototype of the sleep function in Cobol and put it at the
top of your program. It would have prevented the type mismatch.
Your instructor probably never saw a Cobol prototype. If your compiler
supports this feature (Micro Focus does), you'll get an A.

2. Tell your instructor he's not teaching Cobol when he has you call a
foreign function. You'll have the satisfaction of being right, even
though you'll get a C.

Report this thread to moderator Post Follow-up to this message
Old Post
Robert Wagner
09-11-04 08:55 AM


Re: How to let a COBOL program sleep 5 seconds
On Tue, 7 Sep 2004 14:29:25 -0500, "JerryMouse" <nospam@bisusa.com>
wrote:

>Ah, not exactly. Starting with Win98 (and all the NT variants, 2K, XP),
>Windows has preemptive multi-tasking and will interrupt a CPU bound job to
>give cycles to other applications.

Correction: starting with Win95.

http://www.microsoft.com/ntworkstat...95/techdiff.asp

Report this thread to moderator Post Follow-up to this message
Old Post
Robert Wagner
09-11-04 08:55 AM


Re: How to let a COBOL program sleep 5 seconds
To add to Frederico Fonseca's answer:

COBOL does not include a "sleep" function up to and including COBOL-85.

There might(!) be a COBOL intrinsic standard function that performs this
function (I don't know...check yourself).

There might(!) be a COBOL standard "sleep" function in the COBOL-2002
standard (or beyond). I don't know!

Assuming there is no standard "sleep" function then do the following:

1. Write a COBOL function (within OOCOBOL: a COBOL static function),
calling a system dependent(!) "sleep" routine.
2. Let your program call this (static) COBOL function when required.

This 2-phase call structure will accomplish the following:

It will prevent a massive recompile of many COBOL programmes in case you
have to change the environment or "sleep" routine.

Thus:

COBOL programs (many) -- calls -> COBOL "sleep" routine (independent) --
calls -> "sleep" routine (system dependent)

Notice that in the worst case scenario the system dependent "sleep"
routine must be replaced and maybe the COBOL "sleep" routine must be
modified (calling a different system dependent "sleep" routine name and/or
parameters).

There is, and will be, only one COBOL "sleep" routine.

The call structure relationship is thus as follows:
many COBOL programs calling 1 COBOL "sleep" routine calling 1 system
dependent "sleep" routine.

Using a construction as described as above makes your system more robust
and more adaptable for change.

I hope I was clear enough...regards, Wim Ahlers.

P.S. I don't care what the system dependent sleep routine looks like
(assembler, C++, LE routines (C), or whatever...).


Report this thread to moderator Post Follow-up to this message
Old Post
wahlers
09-11-04 08:55 PM


Re: How to let a COBOL program sleep 5 seconds
Although it is not very efficient from a CPU perspective (and not exact,
although many OS sleep's are not exact either), you could do something like:

....
WORKING-STORAGE SECTION.
01 THE-TIME.
03 THE-TIME-HH             PIC 99.
03 THE-TIME-MM            PIC 99.
03 THE-TIME-SS             PIC 99.
01 FIVE-SECONDS-LATER   PIC 99.
...
...
PROCEDURE DIVISION.
...
...
ACCEPT THE-TIME FROM TIME.
ADD THE-TIME-SS, 5 GIVING FIVE-SECONDS-LATER.
IF FIVE-SECONDS-LATER >= 60
SUBTRACT 60 FROM FIVE-SECONDS-LATER.
PERFORM UNTIL THE-TIME-SS = FIVE-SECONDS-LATER
ACCEPT THE-TIME FROM TIME
END-PERFORM.

I did this off the top of my head with no testing (and I don't use this
method in practice), so you may need to tweak....

(The reason this is not exact is ACCEPT FROM TIME could execute in the
middle of a second.)

"William Cai" <wenliang_cai@yahoo.com.cn> wrote in message
news:chjjss$t76$1@mail.cn99.com...
> Hi, folks
>
> Anybody can tell me how to let a COBOL program sleep 5 seconds? I am new
to
> COBOL. Sorry for the stupid question. :)
>
>
> -William
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
JJ
09-12-04 01:55 PM


Re: How to let a COBOL program sleep 5 seconds
What compiler and operating system are you running on?  I know how to do thi
s on
a few, but it is NOT portable across systems and compilers.

--
Bill Klein
wmklein <at> ix.netcom.com
"William Cai" <wenliang_cai@yahoo.com.cn> wrote in message
news:chjjss$t76$1@mail.cn99.com...
> Hi, folks
>
> Anybody can tell me how to let a COBOL program sleep 5 seconds? I am new t
o
> COBOL. Sorry for the stupid question. :)
>
>
> -William
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
William M. Klein
09-12-04 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Pages (3): [1] 2 3 »
Search this forum -> 
Post New Thread

Cobol archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:26 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.