Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ILE/RPG : Creating a timestamp down to the millisecond?

1,111 views
Skip to first unread message

Stephen Smith

unread,
Oct 5, 2001, 5:32:40 AM10/5/01
to
Can anyone tell me how to obtain a timestamp down to the millisecond. At the
moment when i move the date and time in to the timestamp i get
2001-10-05-09.52.32.000000 . And no milliseconds.
Thanks
Stephen


Thomas Hauber

unread,
Oct 5, 2001, 12:15:10 PM10/5/01
to
I have copied this tip from the Club Tech iSeries Programming Tips
newsletter, dated 2/28/2001.

2. OBTAINING A UNIQUE IDENTIFIER ID
(A FOLLOW-UP TO "OBTAINING THE SYSTEM TIME IN MILLISECONDS")
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:

DTimeStamp 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 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.

Barbara Morris

unread,
Oct 5, 2001, 1:02:40 PM10/5/01
to
Try coding the timestamp directly in the result field of TIME. If
you're on a release that doesn't support that (it became available in
V3R7), try calling API QWCCVTDT.
0 new messages