For those interested...
It is not uncommon to use the timestamp as a unique (log) registration field.
Of course, any timestamp field has a limited accuracy!
The chances on duplicates is real and often high!
The standard 'FUNCTION CURRENT-TIME' is by no means sufficient.
This current timestamp is accurate only to one hundredth of a second, which is totally insufficient!
There are several alternatives!
For instance, use a database (like mainframe DB2 TIMESTAMP) and a locking mechanism.
This works but might drain the resources within a multi-user/multi-tasking system.
You may opt for a simple counter function with a locking mechanism that simply adds '1' to the last number given and return this new '+1' next unique number.
The code following is a simple and compact example of faking an incredible accurate timestamp.
Just copy, compile and try it by calling the subprogram as follows:
Code:
[COLOR=red]
05 myTIMESTAMP PIC X(30).
CALL TIMESTMP USING myTIMESTAMP
[/color]
Code:
IDENTIFICATION DIVISION.
PROGRAM-ID. TIMESTMP.
*---
* Faking(!) a more accurate timestamp!
*
* The guaranteed accuracy (in seconds) PER USER is:
* Inverse (100 * 100 * 999,999) / 2 = 1/4,999,995,000
*
* pseudoRandom3 actually is a static value for a
* given user-session! It consists partly of the
* unique address value of the TIMESTMP field.
*
* The changes on duplicates within a multi-user,
* multi-tasking environment is:
* (assuming the 'TIMESTMP' field is NOT defined as
* EXTERNAL!)
* Inverse (4,999,995,000 * 999,999) / 2 =
* 1/2,499,995,000,002,500
*
* Thus, duplicates are NOT impossible,
* but highly improbable!
*---
DATA DIVISION.
WORKING-STORAGE SECTION.
01 globalWorkFields GLOBAL.
05 PTR USAGE POINTER.
05 BIN REDEFINES PTR PIC 9(09) BINARY.
05 pseudoCount PIC 9(02) BINARY.
LINKAGE SECTION.
01 TIMESTMP.
05 PIC X(16).
05 pseudoRandom1 PIC 9(02).
05 pseudoRandom2 PIC V9(06).
05 pseudoRandom3 PIC 9(06).
PROCEDURE DIVISION USING TIMESTMP.
begin.
MOVE FUNCTION CURRENT-DATE TO TIMESTMP(1:16)
ADD 1 pseudoCount GIVING pseudoRandom1
pseudoCount
ADD ZERO FUNCTION RANDOM GIVING pseudoRandom2
CALL 'useTIMESTMPaddress' USING pseudoRandom3 TIMESTMP
GOBACK
.
IDENTIFICATION DIVISION.
PROGRAM-ID. useTIMESTMPaddress.
DATA DIVISION.
LINKAGE SECTION.
01 pseudoRandom3 PIC 9(08).
01 TIMESTMP PIC X(01).
PROCEDURE DIVISION USING pseudoRandom3
TIMESTMP.
begin.
SET PTR TO ADDRESS OF TIMESTMP
MOVE BIN TO pseudoRandom3
GOBACK
.
END PROGRAM useTIMESTMPaddress.
END PROGRAM TIMESTMP.