Skip to main content

Problem:

How can COBOL access the system time?  How can I write a program that will display a clock showing the system time, in real time, for the purpose of checking the system time's accuracy?

Resolution:

Following is a complete COBOL program (not a fragment).  It will compile as written:

000001 01 time-ws pic 9(08) value zeroes.

000002 01 filler redefines time-ws.

000003 05 ws-hours pic 99.

000004 05 ws-minutes pic 99.

000005 05 ws-seconds pic 99.

000006 05 ws-hundredths pic 99.

000007  01 count-ws pic 9(8) value 0.

000008

000009 procedure division.

000010 loop-top.

000011  accept time-ws from time

000012  display ws-hours   at 0303

000013          ":"        at 0305

000014          ws-minutes at 0306

000015          ":"        at 0308

000016          ws-seconds at 0309

000017  end-display

000018  go to loop-top.

Old KB# 2141