Conditional filtering in C/AL

Hello,

Firstly apologies if I am in the wrong forum first time posting!

I have a dilemma with how a dataport is currently running which I am hoping someone might be able to help me with.

Currently when I user wants to export daily price information a dataport runs which collects all the relevant pricing info from table “FDR Fund Price” providing that the “Prices Authorised” field is set to TRUE. However we recently added two new funds which will not be authorised at the time the dataport runs to extract the info. This is causing the code to fail with the error “All prices must be authorised”.

I think that the problem is in this filter:

“FDR Fund Price”.SETFILTER(“Prices Authorised”,’= YES’)

But what I need to be able to do is select all the relevant price info that is authorised with the exception of the two new funds. Essentially a conditional filter.

I was toying with the idea of something along the lines of:

IF

“FDR Fund Code”.“Fund Code” <> ‘AH%’

THEN

BEGIN

“FDR Fund Price”.SETFILTER(“Prices Authorised”,’= YES’)

END;

Obviously this isn’t correct syntactically and most certainly logically so my question is has anyone encountered this type of issue and if so would you be able to point me in the right direction.

Any help would be gratefully received.

Kind regards,

Neil

So you have 3 funds.

from what I gather you had 1 fund so a single filter of authorized = yes worked for you.

It appears now you need to add a second condition.

Does your dataport currently use the CurrDataport.SKIP; function?

Where when your conditions don’t exist it skips that record and moves to the next.

Not seeing your data or dataport code it’s hard to see what exact change is needed.

Try some tests.

If (FDR Fund Code".“Fund Code” = ‘whatever’) & (“Prices authorized” = NO) then

Currdataport.Skip;

Something like this will filter your original fund but leave alone the other funds that don;t match the criteria.

Good Luck.

http://msdn.microsoft.com/en-us/library/dd339042.aspx

Thank you for the swift response Savatage I will give that a try!

Many thanks!!

Neil

Welcome to DUG!!!

Lets try Savatage answer and let us know if any help required …

Thank you for the warm welcome Amol! :slight_smile:

I tried Savatage’s suggestion but it gave me a boolean error which I was uncertain how to resolve. For ease of reference I’ve copied all the code with comments so you can better see what I am trying to achieve and possibly advise me how best I can proceed. Always many many thanks in advance for your help.

///////////////////////////////////////////////////////////////////////////////////////////

// This code checks to see if the UCITS file export check box is ticked. If it is then the

// the BuildUCITSFile job is called and otherwise the Ashburton file is created.

///////////////////////////////////////////////////////////////////////////////////////////

IF

UCITS_File_Check

THEN

BEGIN

OpenMethod := 2; // 1=adOpenKeyset; 2=adOpenDynamic; 3= adOpenStatic

LockMethod := 3; // 1=dLockreadonly; 2=adLockPessimistic; 3=adLockOptimistic; 4=adLockBatchOptimistic

CREATE(ADOConn);

// build connection string…

ConnStr := ‘Driver={SQL Server};Server=MYSERVER;Database=NAVISION;Trusted_Connection=yes’;

// now connect to sqlserver database…

ADOConn.Open(ConnStr);

// build sql string…

SQLstring := STRSUBSTNO(‘EXEC msdb…sp_start_job ‘‘BuildUCITSDailyPrices’’’);

// run the dts job to export our file into sqlserver…

ADOConn.Execute(SQLstring);

ADOConn.Close;

// clear connection…

CLEAR(ADOConn);

MESSAGE(‘UCITS File preview completed’)

END

ELSE

BEGIN

CLEARALL;

////////////////////////////////////////////////////////////////////

// the following statement resets any previously defined filters…

////////////////////////////////////////////////////////////////////

“FDR Fund Price”.SETRANGE(“Prices Authorised”);

“FDR Fund Price”.SETRANGE(“Dealing Date”);

/////////////////////////////////////////////////////////////////////////////////////////////////

// first obtain the total count of the dataset based on entries for TODAYS date …

// im passing the CURRENTDATETIME value to the DT2DATE built-in which strips out the time portion

// in order for me to be able to use a clean date comparison later…

/////////////////////////////////////////////////////////////////////////////////////////////////

// testdate := 161008D;

// “FDR Fund Price”.SETFILTER(“Dealing Date”, ‘= %1’,testdate);

“FDR Fund Price”.SETFILTER(“Dealing Date”, ‘= %1’,DT2DATE(CURRENTDATETIME));

dataport_record_count := “FDR Fund Price”.COUNT;

IF

dataport_record_count = 0

THEN

ERROR(‘ERROR - No records to export for todays date’);

///////////////////////////////////////////////////////////

// now set a table filter to delimit the returned count…

///////////////////////////////////////////////////////////

//Here is the problem part I think what I need to do is exclude funds that begin “AH%” from the filter so the code will select the old funds as normal and ignore these //new funds which are handled by a separate process

“FDR Fund Price”.SETFILTER(“Prices Authorised”,’= YES’);

/////////////////////////////////////////////////////////////////////

// now retrieve count for only the prices that have been verified…

/////////////////////////////////////////////////////////////////////

verified_count := “FDR Fund Price”.COUNT;

IF

dataport_record_count = verified_count

THEN

BEGIN

// MESSAGE(‘all records have been verified : ok to export file’);

////////////////////////////////////////////////////////////////////////////////////////////////////

// First generate the output txt file for subsequent export…

/////////////////////////////////////////////////////////////////////////

// the following dataport statement contains a “FALSE” statement

// this is to suppress the display of the request form…

// interestingly, if you select “no” from the dataport properties

// for displaying the request form, it still gets displayed…

/////////////////////////////////////////////////////////////////////////

//ADOConn Automation ‘Microsoft ActiveX Data Objects 2.7 Library’.Connection

//DbConnection := Automation ‘Microsoft ActiveX Data Objects 2.7 Library’.Connection

//ADOrs Automation ‘Microsoft ActiveX Data Objects 2.7 Library’.Recordset

//ConnStr Text : 200

//AnzCount Text 30

//OpenMethod Integer

//LockMethod Integer

//Name Text

//Str Text 200

///////////////////////////////////////////////////////////////////////////////////////////////////////

// now create odbc connection, and perform export…

// Test ODBC-Connector

OpenMethod := 2; // 1=adOpenKeyset; 2=adOpenDynamic; 3= adOpenStatic

LockMethod := 3; // 1=dLockreadonly; 2=adLockPessimistic; 3=adLockOptimistic; 4=adLockBatchOptimistic

CREATE(ADOConn);

// build connection string…

ConnStr := ‘Driver={SQL Server};Server=Ashsrv08;Database=LocalUtility;Trusted_Connection=yes’;

// now connect to sqlserver database…

ADOConn.Open(ConnStr);

// build sql string…

SQLstring := STRSUBSTNO(‘EXEC msdb…sp_start_job ‘‘BuildNavisionFundpric2’’’);

// run the dts job to export our file into sqlserver…

ADOConn.Execute(SQLstring);

////////////////////////////////////////////////////////////////////////////////

//the following “SLEEP” statement gives enough time for the ftp dts launched prior to finish

//before the dataport attempts the import.

//without it, what happens is that the code tries to

//open the file PRIOR to the ftp dts completing, clearly a problem…

/////////////////////////////////////////////////////////////////////////////////

SLEEP(4000);

// disconnect from database…

ADOConn.Close;

// clear connection…

CLEAR(ADOConn);

// first dataport run builds FULL prices file including internals

DATAPORT.RUN(50055,FALSE);

SLEEP(4000);

// second dataport run builds the distribution prices file (minus internal prices)

DATAPORT.RUN(50049,FALSE);

MESSAGE(‘Preview prices files successfully generated…’);

END

ELSE

MESSAGE(‘ERROR : all prices have to be authorised before export allowed’);

END;