4,990 pts.
 AS400 RPG – last three digits of microseconds always zero!
We noticed in a couple of programs where we were using timestamps that the rightmost three positions are consistently zero and never otherwise. I have tested this with even just a simple ILE RPG program that dsplys a %char(%timestamp()); and still only get zeros for the last three digits. However...pulling a microsecond(current timestamp) in an interactive SQL session provides a value which has all six digits being used. So, is this a limitation of RPG? Is there something else I am missing? Is anyone else using microseconds at all in RPG that can vouch for this ever using the last three digits? Thanks in advance!!

Software/Hardware used:
ASKED: May 15, 2009  2:43 PM
UPDATED: January 9, 2011  4:56 PM

Answer Wiki:
Hi, It's a RPGILE limitation and it's always zero. Do you really need this 3 digits? I think you can get it with APIs or C functions. Regards, Wilson -------------------------------- <pre> C/exec sql C+ set :test = current_timestamp C/end-exec </pre> or in /FREE <pre> exec sql set :test = current_timestamp; </pre> will set the program field TEST equal to a full timestamp (e.g. '2009-05-18-10.55.25.250256') Kevin C. "BigKat" Ketzler ////////////////////////////////////////////////////// Hi, I was looking and found gettimeofday() to get time and Qp0zCvtToMITime() to convert it to timestamp. Regards, Wilson
Last Wiki Answer Submitted:  May 18, 2009  3:25 pm  by  BigKat   7,175 pts.
All Answer Wiki Contributors:  BigKat   7,175 pts. , WilsonAlano   2,385 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Wilson, thanks for the verification of what we suspected.

Yes, it would be nice to get the whole 6 because the timestamp is being used in an audit trail. We want to be able to look at the audit trail and sort it by the timestamp to see the exact sequence of events recorded. But, with the speed of the events that take place, nearly all of them happen within the exact same time according to the timestamp. I figured that the remaining three digits may make enough difference to help.

I had not considered an API, but I’ll see if I can dig up one that gets me the data. I’ll post whatever I find here for the benefit of others.

 4,990 pts.

 

I couldn’t find an API, and no one installed the C compiler, so I just ended up just using embedded SQL to do:

/exec sql
select microsecond(current timestamp) into :tmpfield from sysibm/sysdummy1;

I also created a small SQLRPGLE program that could be called by other programs to return this value. Hope this helps someone else who stumbles onto this limitation!

 4,990 pts.

 

Great, BigKat! Thanks!! I knew there must’ve been a simpler way in SQL… ^_^

 4,990 pts.

 

Wilson,

Can I use Qp0zCvtToMITime in RPG w/o using C at all? If so, that would be cool. But, the only examples I saw just now for that API were in C. :(

Thanks!

 4,990 pts.

 

Hi,

Yes you can call this APIs from RPGILE and you just need to know haw to pass parameters to this APIs. Just take a look to this page :

Regards,
Wilson

 2,385 pts.