|
The conversion program extracts the current TimeStamp value using op code TIME. As you all know this returns a TimeStamp value with seconds down to only three places while the format allows for six. The processing in this program can generate audit records at a rate which faster then the resolution of the TIME timestamp and resulted in "Duplicate Record" messages.
Yes, there are APIs that can do this. (see below for examples)However, I just want to point out that even if you get the time down to the microsecond, your program will stop working again when computers get faster. Eventually they'll be fast enough to generate two records within the same microsecond.
Personally I don't like writing code like this. That is, code that I know will fail eventually because I know that the premise behind it is flawed. The idea that a computer will write two records and they'll never be at the same time is not a logical or reasonable thing to do.
A work around using a save timestamp value last used and a check to see if the current timestamp gets around the problem.
That's not really a workaround... two copies of the program, or this program and another program both adding records at the same time would still fail using this logic.
A better idea is to monitor for the duplicate record error, and then re-retrieve the time and try again. As long as every program that writes to the file uses that logic, the problem will be "solved" (though, it'll be solved by slowing the program down!)
A much better alternative, assuming that what you really want is a unique ID, and not a timestamp... is to use the GENUUID MI builtin to get a guaranteed unique ID. Or to use an incrementing number. Or to have SQL generate a unique number for you. Don't use a timestamp as a unique number -- timestamps are not unique.
My question - is there a method by which I can extract the timestamp value to its full definition value?
Yes. Using embedded SQL: D wrkTimeStamp S Z Inz( *loval ) C/exec sql C+ set :wrkTimeStamp = current timestamp C/end-exec If you don't have SQL, use the gettimeofday() API: H DFTACTGRP(*NO) D GetMicroTime PR Z D ts s Z c eval ts = GetMicroTime() c dsply ts c eval *inlr = *on P GetMicroTime B D GetMicroTime PI Z D CEEUTCO PR D hours 10I 0 D minutes 10I 0 D seconds 8F D gettimeofday PR 10I 0 extproc('gettimeofday') D time * value D timezone * value D timeval ds D tv_sec 10I 0 D tv_usec 10I 0 D RetVal s Z inz(z'1970-01-01-00.00.00') D hours s 10I 0 D mins s 10I 0 D FSecs s 8F D Secs s 20P 0 c callp CEEUTCO(hours: mins: FSecs) c eval Secs = FSecs c callp gettimeofday(%addr(timeval): *NULL) c adddur Secs:*S RetVal c adddur tv_sec:*S RetVal c adddur tv_usec:*MS RetVal c Return RetVal P EFinally, there's a system value QDATETIME (not sure which release this first appeared in... it might've been V5R3, but not sure.) You can retrieve this value to get time to the microsecond.
So, that's 3 different ways. :)
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.