[RP2.40] Filter

This forum is meant for questions and discussions about the X# language and tools
Post Reply
FFF
Posts: 1571
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

[RP2.40] Filter

Post by FFF »

Probably it's to hot:
Class MyVOForm
...
METHOD Print_AboRechnung_univ(cPNO := "" AS STRING) // cPNo is the id of a record to include
//calling a RP report
....
oReport:FilterExpression := i"Person.PNo = '{cPno}' "
...

So far, fine.
Now, i want instead to fill the FilterExpression with a series of cPnos.
I get these from a helper func which returns an array of string values, i.e. PNos.

How do i code this?
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
Chris
Posts: 4844
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: [RP2.40] Filter

Post by Chris »

Hi Karl,

What would the filter expression look like in this case, which array items would you use in them? All or some of them and how?

Would you need to do something like this:

Code: Select all

LOCAL aPnos AS ARRAY
FilterExpression := i"Person.PNo = '{aPnos[1]}' .AND. Person.FNo = '{aPnos[3]}' .AND. Person.CNo = '{aPnos[5]}'"
I think it's a bit of overkill to use interpolated strings for such complex expressions, maybe it would be more intuitive to use String.Format() instead, something like

Code: Select all

FilterExpression := String.Format("Person.PNo = '{0}' .AND. Person.FNo = '{1}' .AND. Person.CNo = '{2}' ", aPnos[1], aPnos[3], aPnos[5])
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
FFF
Posts: 1571
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Re: [RP2.40] Filter

Post by FFF »

Chris,
the content gets filled at runtime by a helper func collecting the values, storing them into the array.
As of now, the returned array may look like e.g.:

Code: Select all

aIncludedPNos{"0123","0256","0758"} 
If there's a smarter way to achieve this, i'd glad to hear about this...

EDIT: simpler spoken: i call from the app a report and have to provide the filterexpression. The report has a "base" filter, like "all records holding a membership". To this condition i have to add a list of record-ids, produced at runtime, which fullfill another condition.
Last edited by FFF on Tue Sep 10, 2024 3:02 pm, edited 1 time in total.
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
Chris
Posts: 4844
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: [RP2.40] Filter

Post by Chris »

Hi Karl,

And what would the filter expression look like exactly? As plain string I mean.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
FFF
Posts: 1571
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Re: [RP2.40] Filter

Post by FFF »

ATM, there's e.g.

Code: Select all

oReport:FilterExpression := i"(Person.Abo  .and. (Empty(Person.Masterno)  .or. Person.Pno ='0008')    .and. Person.Kat > '0'  .and. Person.Kat < '3'  .and. Person.Pno != '0237' .and. (Empty(Person.Abo_Bis) .or. (DToS(Person.Abo_Bis) > '20240701'))" //WORKS
.Abo is bool, indicating, the person holds an abonnement.

Now there are persons, for which .Abo is false, but they pay for other persons' abonnement.
So i collect the PNos of these "childs", to include the parent record into the filter.
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
Chris
Posts: 4844
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: [RP2.40] Filter

Post by Chris »

Hi Karl,

How about

"AScan( { "123","456", "789" } , Person.Pno) != 0 .and. ...."

to see if a pno is inside the array?

Of course you will need to construct the string array expression with code.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
FFF
Posts: 1571
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Re: [RP2.40] Filter

Post by FFF »

I sent to the report for testing:

Code: Select all

Var a := GetChildPNos() // {"0498", "0565"}
oReport:FilterExpression := i"(AScan(a, Person.Pno) != 0)"
At runtime i get: The following error was encountered while validating Section Expressions:
Invalid Filter expression: AScan(a, Person.Pno) != 0

Why?
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
robert
Posts: 4473
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: [RP2.40] Filter

Post by robert »

Karl,

'a' is a local variable. This variable is not accessible in a macro.
To solve this you can:
- make 'a' a global variable
- make 'a' a dynamic variable (public or private). You will have to enable support for memory variables in the compiler options for this.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
FFF
Posts: 1571
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Re: [RP2.40] Filter

Post by FFF »

Hi Robert,
thx, that did the trick - there are already some globals in the codebase, so this was the easiest way out.

Code: Select all

oReport:FilterExpression := i"AScan(a, Person.Pno) != 0"  // works fine.
But as you see in the "real" expression some postings below, i also have to regard things in the filter like "Person.Kat" etc. -
Edited, stupidity at keyboard...
tbc
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Post Reply