Strange Behavior on dates subtraction

Hello there again.
Do you guys could shed a light on this issue I’m facing? I know how to solve, but I can’t understand why it is happening.

this is part of the program.

1 #DAYS (N5) 
1 #MAX (N5)
1 #far (d)
#DT := D'2021-06-28'
  #DAYS := #DT - DT-VALID /* (d) this is the valid date on the billings.
    #MAX := #DAYS
    #FAR := DT-VALID
  IF #DAYS GT 9999
    WRITE 'above 9999 =' #DAYS

this is the result: 8210 19990105

so far, ok.

The issue is that the version that is in production has #days defined as (n4). And I’m receiving 1320 (numeric value truncated)

You see that the oldest value for date I’ve got here is 1999-01-05. It doesn’t go over 9999 days. The if block is never used…
I know I could just go and increase the N4 to N5 in production and here we go, but I need to understand why 8210 doesn’t fit in a N4 in this case.

As always, thanks in advance,

First, I think you meant error number 1305. 1320 refers to the VAL function.

Second, check your file for null date values. #DT - 0 = 738333, a 6-digit result.

1 Like

Maybe an intermediate result is too big.

Hi Ralph. Thank you as always. First yes, you are right. I confused the errors, it’s a 1305.
About the null, as you can see, when I define it as a N5, there is no problem and there should be if it was the case of returning a 6-digit to a N5. Also, if there was a null value, I believe the if block would be used and would display the value, because it would be bigger than 9999 days, but it doesn’t happen. That’s why I’m confused.

I found out the issue. The database is very large and it makes difficult to find because the date is not a descriptor, but I managed to put an ‘on error’, forcing it to show me what was coming in.
after 1h running, I found out that one of the valid-dt is set on 2122-01-22 which is another issue, but clearly explains how the value became so big.
the if block is testing for GT 9999, but not LT -9999.

initially i was afraid of something that could be hidden and using space of the numbers, because i’m not calculating over N dates, but D dates.


This will be the statement failing on the NAT1305, so your IF statement won’t be executed. Unless you can guarantee valid dates, #DAYS must be defined as N6 or P6. If your Natural parameters have set MAXYEAR to 9999, then #DAYS should be defined as N7 or P7.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.