On 17/01/2008, at 5:43 AM, GKern@xxxxxxxxxxxxxxxx wrote:

The infocenter states the following for %Diff:

"The result is rounded down, with any remainder discarded. For example, 61
minutes is equal to 1 hour, and 59 minutes is equal to 0 hours."

That only applies when asking for the duration in the next higher level. If the duration is actually 61 minutes but you specify *HOURS you'll get 1 as the result. If 59 minutes you'll get 0 as the result.

This behaviour is explained in the 'Date Operations' section of the ILE RPG Language Reference.


I have the following statement in a program where cur_time is 12:38:15 and
last_time is 11:38:15.


C IF %Diff (Cur_Time:Last_Time:*Minutes) >
60

Using the interpretation from the infocenter cited above, does that mean
that the %Diff would be 1 *Hour instead of 60 *Minutes?

No, because you requested the duration in *MINUTES. The result of this calculation given the times shown is 60.


The reason I ask is that for some reason the code that should execute
never does and therefore there must be something wrong with that condition
as coded

When in doubt write some test code to verify the behaviour:

H TIMFMT(*HMS)

D cur_time S T INZ(T'12:39:15')
D last_time S T INZ(T'11:38:15')

C IF %Diff(Cur_Time:Last_Time:*Minutes) > 60
C 'diff > 60' DSPLY
C ELSE
C 'diff <= 60' DSPLY
C ENDIF

C SETON LR

gives 'diff > 60' as the output. This is exactly as expected.

(and I don't know how to or if I can view the value of %Diff).

You can't view the result of %DIFF with this code. However %DIFF simply returns a numeric result so assign it to a variable and then you can examine it.

C EVAL RESULT = %Diff (Cur_Time:Last_Time:*Minutes)
C IF RESULT > 60

Note: In RPG there is no such thing as a 'duration data type' as stated by another responder. A duration is just a number and any RPG numeric data type is valid as long as it is large enough to hold the result.

Could it be that the compiler is rounding up to 1 hour and therefore
minutes is never greater than 60?

No.

Or (in other words) is >60 a valid value for use with *Minutes?

Yes.


Comments?

I suggest you read the section on Date Operations.

Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists

http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.