Error when using CALCDATE

I use a report in which I like to filter Sales Headers on a field fDatValidUntil, which is a date field. In the OnPreReport, I wrote: gDatreference := CALCDATE(’<-6M>’, WORKDATE); gDatReference is a variable of type Date. To get a result of all Sales Headers with a fDatValidUntil before the gDatReference, in the OnPreDataItem I wrote: “Sales Header”.SETFILTER(“Sales Header”.fDatValidUntil, ‘< gDatReference’); I receive an error ‘gDatReference’ is not a valid date’. However, when debugging, the variable actually shows the right value: “23-07-05” What am I doing wrong?

Hi Michiel, I think your SETFILTER is wrong. Try “Sales Header”.SETFILTER(“Sales Header”.fDatValidUntil, ‘<%1’, gDatReference);

Hi Daniel, Works fine. Thanks! I’m not entirely shure why this does the trick, but I guess it has to do with ‘isolating’ the gDatReference as a date variable from the ‘<’ sign, hasn’t it?

Hello Michiel,

quote:

but I guess it has to do with ‘isolating’ the gDatReference as a date variable from the ‘<’ sign,

Yes and no… the ‘< gDatReference’ is considered plain text and therefore the part “gDatReference” is not replaced with the actual date of the variable. Have a look at the C/SID Online Help, there you can find a couple of good examples of extensive use of these placeholders. Saludos Nils

single quotes define literal strings, so by including your variable name inside the quotes, you define it as a literal filter criterium. The %1 is Navision’s syntax to replace it with what comes after it (see also the STRSUBSTNO function). You can also do ‘<’ + YourVariable.