Microsoft KB Archive/63421

Calling DosGetDateTime to Code .01 Second Delay in OS/2 COBOL

PSS ID Number: Q63421 Article last modified on 06-29-1990

3.00 3.00a OS/2

Summary: In a Microsoft COBOL versions 3.00 and 3.00a protected mode program, you can code a delay that is precise to a hundredth of a second. This is accomplished by calling the OS/2 API function DosGetDateTime. On the first call, the current minute, second, and hundredth of a second are recorded. Then DosGetDateTime is called within a loop until the required amount of time has elapsed. This information applies to Microsoft COBOL Compiler versions 3.00 and 3.00a for MS OS/2.

More Information: OS/2 API functions can be directly called from COBOL 3.00 and 3.00a with CALL statements by prefixing their names with a double underscore (__) and linking with the PCOBOL.LIB and DOSCALLS.LIB libraries. For more information on calling OS/2 API functions from COBOL, see the file OS2API.DOC included with version 3.00a. For more information on DosGetDateTime, see Pages 522-523 of “Advanced OS/2 Programming” by Ray Duncan (Microsoft Press, 1989). The following program (DELAY.CBL), prompts you to enter the desired delay in seconds. It then sounds two beeps, marking the start and finish of the delay period. To compile and link the program, enter the following: pcobol delay; link /nop delay,,,pcobol doscalls;

Code Example
$SET ANS85 DATA DIVISION. WORKING-STORAGE SECTION. *  DosGetDateTime will return data here. 01 Buffer. 05 Hour          PIC 9(2) COMP-5. 05 Minute        PIC 9(2) COMP-5. 05 Second        PIC 9(2) COMP-5. 05 Hundredths    PIC 9(2) COMP-5. 05 TheDay        PIC 9(2) COMP-5. 05 Month         PIC 9(2) COMP-5. 05 Year          PIC 9(4) COMP-5. 05 TimeZone      PIC 9(4) COMP-5. 05 DayOfWeek     PIC 9(2) COMP-5. 01 Delay            PIC 9(2) COMP-5. 01 StartMinute      PIC 9(2) COMP-5. 01 StartSecond      PIC 9(2) COMP-5. 01 StartHundredths  PIC 9(2) COMP-5. PROCEDURE DIVISION. DISPLAY &quot;Enter delay in seconds (0 - 59): &quot;. ACCEPT Delay. *   Sound beep to start delay period and get the starting *   minute, second, and hundredth of second. CALL X&quot;E5&quot;. CALL &quot;__DosGetDateTime&quot; USING BY REFERENCE Buffer. MOVE Minute    TO StartMinute. MOVE Second    TO StartSecond. MOVE Hundredths TO StartHundredths. *   Stay in loop until enough seconds and hundredths of seconds *   have gone by. PERFORM UNTIL ((Second - StartSecond) = Delay) AND (Hundredths > = StartHundredths) CALL &quot;__DosGetDateTime&quot; USING BY REFERENCE Buffer *      If a new minute has occurred, seconds have flipped back *       to 0. Adding 60 seconds (1 minute) accounts for this. IF Minute NOT = StartMinute THEN COMPUTE Second = Second + 60 END-IF END-PERFORM. *   Sound beep to end delay period. CALL X&quot;E5&quot;. STOP RUN. Copyright Microsoft Corporation 1990.