%DIFF Issue Utilizing Milliseconds

Discussions relating to writing software in ILE RPG (RPG IV). This includes both fixed and free format RPG.
Post Reply
bbunney
Posts: 45
Joined: Wed Jul 06, 2022 7:52 pm

%DIFF Issue Utilizing Milliseconds

Post by bbunney »

I have a program that needs to calculate the amount of seconds for the Data Queue Wait time. The program runs queries every 3 minutes and takes directives through the data queue so the processing time needed to process those directives is subtracted from the Data Queue Wait Time so that the queries will run on time. I know to get seconds from milliseconds you divide the milliseconds by 1000 but that doesn't work here. The difference between the timestamps is 7.1 seconds. In order to arrive at that value, the program has to divide the milliseconds value by 1,000,000. Why? I don't use seconds because it rounds down and I only want it to round down if the tenths are less than .4.

I would also like some tips on how to format the code here even though I put it inside the code block but Scott says it is messy and hard to read. Thanks!

Code: Select all

Dcl-S l_milliSeconds   Packed(15:5); 
Dcl-S l_seconds        Packed(15:5); 

G_DIRENDTIME = '2024-02-03-16.44.33.512000'
G_DIRSTARTTIME = '2024-02-03-16.44.26.412000'

l_milliSeconds = %Diff(g_dirEndTime:g_dirStartTime:*MSECONDS);
l_seconds = l_milliSeconds / 1000;                            

L_MILLISECONDS = 0007100000.00000
L_SECONDS = 0000007100.00000
jonboy49
Posts: 206
Joined: Wed Jul 28, 2021 8:18 pm

Re: %DIFF Issue Utilizing Milliseconds

Post by jonboy49 »

You appear to be confusing milliseconds and microseconds.

%Diff using *MSECONDS gives _microseconds_ not milliseconds.

So dividing by 1,000,000 is correct.

Two other points.

First - if you want seconds then why not ask %Diff for seconds to begin with? If you want decimals of seconds you can specify the accuracy you require. From the manual "If the third operand is *SECONDS or *S, and both of the operands are timestamps, you can specify a fourth parameter indicating the number of fractional seconds to return. You can specify a value between 0 and 12. This represents the number of decimal positions in the returned number of seconds."

Second: Use integers when appropriate. In your original code there is no point in defining milliseconds as 15,5 - it should just be (say) an int(10).

As to formatting the code. It is formatted in your example. By using the code tags you preserve leading and embedded spaces - so if you indent within a code block it is preserved.
Like this:

Code: Select all

No indentation
   Three space indent
   And again
      Six spaces      with    big    gaps
without the tag that data looks like this:

No indentation
Three space indent
And again
Six spaces with big gaps
Post Reply