How to avoid empty files in dataport

I’m writing a dataport which exports some records. In the “OnPreDataItem”-function I set the dataport-filter by using SETFILTER(…). If there are no records, I quit the dataport. This dataport is automaticcally called every 30 minutes. The dataport works fine: BUT: In some case case there are no records to export, but the file is still created (0 KB). Is there any possibility to avoid this? I tried setting the filter in other event-functions, but the problem remains the same: once I call the dataport, a file is created (even if there are no records). Any help?

Why not check before you call the dataport if there are any records to export, and if not then don’t call it. Another way would be to check the filesize and if this is 0, then delete the file (there are build commands for this), but then again this can not be done from within the dataport, unless you point the dataport to some other file before deletion. Or you might use the built in commands for direct file access file.open, file.write etc. which provide you with a bit more control. Regards

Hi Allan, Thanks for your answer. I’m using the “check filesize”-solution you mentioned. Checking the record-count before the dataport is also a proper solution, but then I have to set a filter BEFORE I call the dataport, and IN the dataport (double code). I thought there could be a more neat solution. Unfortunately, there isn’t any I think. Thanks anyway!