In the last issue, I provided two techniques for obtaining the system time, including milliseconds, one in RPG and one in CL. The RPG item was reprinted from NEWS/400 Tech Corner and used the QWCCVTDT API. Several readers pointed out – in what seemed like just a few milliseconds after I sent out the newsletter 🙂 – that the code below is a far simpler alternative:
D TimeStamp s z C Time TimeStamp
The thrust of the Tech Corner item was that having the system time in milliseconds gives you a unique identifier, which is not true, as you can easily execute the above code and obtain identical millisecond times.
The solution to finding a unique identifier is to use a Universal Unique Identifier (UUID), a 128-bit value that is guaranteed to be unique.
The solution to finding a unique identifier is to use a Universal Unique Identifier (UUID), a 128-bit value that is guaranteed to be unique. The following RPG IV template is for OS/400’s GENUUID() MI instruction, which generates a UUID:
H Option( *NoSrcStmt ) DftActGrp( *No ) ** D UUID_template Ds D UtBytPrv 10u 0 Inz( %Size( UUID_template )) D UtBytAvl 10u 0 D 8a Inz( *Allx'00' ) D UUID 16a ** D GenUuid Pr ExtProc('_GENUUID') D UUID_template * Value ** C Callp GenUuid( %Addr( UUID_template )) ** C Return
If you’re interested in a more technical explanation of UUIDs, check out http://www.ics.uci.edu/~ejw/authoring/uuid-guid/draft-leach-uuids-guids-01.txt.
The above RPG IV template was provided by Carsten Flensburg, and the UUID information was adapted from an answer by John Taylor. Thanks to Paul Nicolay, Daniel Ziobron, Frank Fajardo, and John Chadwick for gently reminding me that the Time opcode was the superior alternative.