Page 1 of 1
[RP2.40] Filter
Posted: Sat Aug 31, 2024 7:23 pm
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?
Re: [RP2.40] Filter
Posted: Tue Sep 10, 2024 2:08 pm
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])
Re: [RP2.40] Filter
Posted: Tue Sep 10, 2024 2:25 pm
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.
Re: [RP2.40] Filter
Posted: Tue Sep 10, 2024 2:40 pm
by Chris
Hi Karl,
And what would the filter expression look like exactly? As plain string I mean.
Re: [RP2.40] Filter
Posted: Tue Sep 10, 2024 3:13 pm
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.
Re: [RP2.40] Filter
Posted: Tue Sep 10, 2024 3:33 pm
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.
Re: [RP2.40] Filter
Posted: Tue Sep 10, 2024 7:45 pm
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?
Re: [RP2.40] Filter
Posted: Tue Sep 10, 2024 7:52 pm
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
Re: [RP2.40] Filter
Posted: Tue Sep 10, 2024 8:38 pm
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