Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command Wait in COBOL?

Tags:

cobol

gnucobol

Is there a kind of "Wait" function in COBOL? I wrote a calculator, and to make it more 50s, i Print " Computing." "Computing.." ecc For example:

                   DISPLAY "SECONDO NUMERO"
                   ACCEPT B
                   COMPUTE C= A * B
                          DISPLAY "Computing"
                          DISPLAY "Computing."
                          DISPLAY "Computing.."
                          DISPLAY "Computing..."
                          DISPLAY "Computing...."
                          DISPLAY "Computing....."
                          DISPLAY "Computing......"
                          DISPLAY A "x" B " FA..."
                          DISPLAY C

Now, is there a way to make a little delay (half a second) on COBOL where I put the "Computing" piece? I created a github repo (https://github.com/aIDserse/Super-utility-Submachine-COBOL-CALCULATOR) to this project, look at it (refer to version 1.3) for the complete code (and maybye spread it hahah). Thx!!!

like image 302
aIDserse Avatar asked Dec 22 '22 18:12

aIDserse


2 Answers

There is a statement for sleeping in standard COBOL, but only with COBOL 202x:

           CONTINUE AFTER arithmetic-expression SECONDS

As this standard is in the committee draft state it is hard to find an implementation, but as you've asked for GnuCOBOL - GnuCOBOL 3.1 already implements it.

Other than this there are some dialect specific library routines that can be used, like CALL "C$SLEEP" originating from ACUCOBOL-GT (also implemented with GnuCOBOL, but be aware that pre 3.1-versions only use the non-decimal part, so "0.9" will sleep zero seconds).

For OpenCOBOL/GnuCOBOL you can call the CBL_OC_NANOSLEEP/CBL_GC_NANOSLEEP library routines.

For any COBOL environment that can call native routines you have variants of CALL "sleep".

As mentioned by Rick Smith Many COBOL implementations also implement a callable SYSTEM where you may use something like a ping localhost with a timeout, but whatever you call may not be available (or the process running the COBOL environment has no access to it).

Stephen Gennard mentioned a very common extension:

           ACCEPT something WITH TIMEOUT

which has a "beware" that different environments use a different scale (some seconds, some milliseconds). This has the pro/con that the user can "break" out by pressing a key (normally a function key); and the additional issue that it may only work in "graphical" environments.

Anton's answer highlights the IBM library routine CEE3DLY.

like image 199
Simon Sobisch Avatar answered Jan 08 '23 10:01

Simon Sobisch


There's no wait statement in any ISO Standard COBOL.

However, if you got built in system routines available either C$SLEEP (for seconds) or CBL_GC_NANOSLEEP (for nanoseconds) should do the trick.

Example (sleeps for half a second):

call "CBL_GC_NANOSLEEP" using "500000000" end-call

For IBM's Enterprise COBOL (LE enabled) the CEE3DLY routine is most suitable (there are also other legacy routines available).

like image 32
Anton Avatar answered Jan 08 '23 11:01

Anton