Variable TAKE BEST

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
robleer
Posts: 291
Joined: Wed Jul 14, 2010 7:01 pm

Variable TAKE BEST

Post by robleer »

Hi,

I need to run a query which have to show a few records. Sometimes 5, sometimes 7 a.s.o.. I never know how many it has to show, so this is variable.

I use the 'TAKE BEST' way and try to set a value to make the result variable.

Something like:

FIND ALL AnObject TAKE BEST SystemSettings.Counter

This does not work of course, but is there a cleverway to do this?

TIA, Rob
Using 8.7 Professional 3025 on MySQL/Windows
kklosson
Posts: 1649
Joined: Sun Nov 23, 2008 3:19 pm
Location: Virginia

Re: Variable TAKE BEST

Post by kklosson »

Maybe try the LIMIT option?

FIND Account WHERE Account.State = 'OPEN' AND Account.Balance > 1000 LIMIT 20,3
V8.8
MySQL, AWS EC2, S3
PDFtk Toolkit
robleer
Posts: 291
Joined: Wed Jul 14, 2010 7:01 pm

Re: Variable TAKE BEST

Post by robleer »

Nope, that does not work. Any other ideas how to achieve this?
Using 8.7 Professional 3025 on MySQL/Windows
kklosson
Posts: 1649
Joined: Sun Nov 23, 2008 3:19 pm
Location: Virginia

Re: Variable TAKE BEST

Post by kklosson »

Are the number to be returned limited enough that you can IF your way through it?

IF SomeChoice = 1 THEN
Query Take Best 1
ELSIF SomeChoice=2 THEN
Query Take Best 2
etc...
V8.8
MySQL, AWS EC2, S3
PDFtk Toolkit
robleer
Posts: 291
Joined: Wed Jul 14, 2010 7:01 pm

Re: Variable TAKE BEST

Post by robleer »

No, as I wrote, I never know in advance how many records I need.

So therefore it must be variable. Tnx Rob
Using 8.7 Professional 3025 on MySQL/Windows
kklosson
Posts: 1649
Joined: Sun Nov 23, 2008 3:19 pm
Location: Virginia

Re: Variable TAKE BEST

Post by kklosson »

I'm not sure why the LIMIT switch is a non-starter since the values can be expressions whereas TAKE BEST required a literal integer. From the documentation example:

If this construct is used after the FIND action, only the specified rows will be returned. The first parameter indicates the first row number to be returned (starting from 1) and the second parameter indicates the number of rows to be returned. For example:

FIND Account WHERE Account.State = 'OPEN' AND Account.Balance > 1000 LIMIT 20,3

So, your query might be:
FIND [myQueryString] LIMIT 1, [variable]

This should return the first X records of the query results, but I've never tried to implement the LIMIT switch.
V8.8
MySQL, AWS EC2, S3
PDFtk Toolkit
BobK
Posts: 552
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: Variable TAKE BEST

Post by BobK »

Take a look at the EXEC_STRING Action.

You can do something like
EXEC_STRING 'FIND ALL AnObject TAKE BEST ' + SystemSettings.Counter
Bob
robleer
Posts: 291
Joined: Wed Jul 14, 2010 7:01 pm

Re: Variable TAKE BEST

Post by robleer »

Hi Bob,

That does not work also, because I cannot do anything with the records found.

This is my example process:

FIND ALL AnObject //this BO contains 6 records

AnObject.TryNr=0 //set everything to zero

EXEC_STRING 'FIND ALL AnObject TAKE BEST ' + SystemSettings.Counter // this selects 3 records

AnObject.TryNr=1 //Sets the attrib ´TryNr´ of 3 records to 1

DISPLAY QryAnObjects // THIS SHOWS all 6 records and all 6 have TryNr=1 ??? Should be 3 with 0 and 3 with 1

Even if you replace 'EXEC_STRING 'FIND ALL AnObject TAKE BEST ' + SystemSettings.Counter' by a normal statement ´FIND ALL AnObject TAKE BEST 3´ it does not work. Looks like a TAKE BEST does not put 3 records in context, but puts all records in context??

Tia,

Rob
Using 8.7 Professional 3025 on MySQL/Windows
BLOMASKY
Posts: 1486
Joined: Wed Sep 30, 2015 10:08 pm
Location: Ocala FL

Re: Variable TAKE BEST

Post by BLOMASKY »

Can you get a sequence in the SQL table? (Can easily be done by a stored procedure). Then, you can have a filter like:
FIND BO WHERE BO.seq <= SessionVars.noRecs


Bruce
PointsWell
Posts: 1471
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: Variable TAKE BEST

Post by PointsWell »

robleer wrote: Sat Jun 01, 2024 4:02 pm Looks like a TAKE BEST does not put 3 records in context, but puts all records in context??
TAKE BEST isn’t working because your first process
robleer wrote: Sat Jun 01, 2024 4:02 pm This is my example process:

FIND ALL AnObject //this BO contains 6 records

AnObject.TryNr=0 //set everything to zero
Has brought every AnObject into context

To fix this you’d need to run
robleer wrote: Sat Jun 01, 2024 4:02 pm EXEC_STRING 'FIND ALL AnObject TAKE BEST ' + SystemSettings.Counter // this selects 3 records

AnObject.TryNr=1 //Sets the attrib ´TryNr´ of 3 records to 1

DISPLAY QryAnObjects // THIS SHOWS all 6 records and all 6 have TryNr=1 ??? Should be 3 with 0 and 3 with 1
As a sub process with zero input BOs

If you run a more refined search after a more general search in the same process, then the more general search will be the set of records that are in context.
Post Reply