Insert records on report.

Hi to all, I have a quick question. I’ve got a processing only report used to import data from an excel file. Before the data is imported it does some checks on the data. If there are errors in the imported data (overflow, etc) then I’m using the CurrReport.QUIT in order to close the report and no data is written to tables. So far so good. The problem is that I also have a custom table that is used to hold log lines about the errors occurred during the check of data processed. This table is displayed when the process finishes and shows to the user the errors. In the code of the report each time an error is found I do a: LogTable.INSERT but due to the CurrReport.QUIT the data is not committed into the table. I cannot use a the COMMIT command because it commits the excel data into the relevant tables which is not acceptable (because when errors are found no data should written in the database). I just want to write data ONLY into the log table when errors found. Any suggestions on that? I’ve tried several alternatives with no luck. [V] Thank you for your time.

Run through the data twice: 1 iteration: Datachecking and errorlogwriting - keep count of errors - if errors found skip part 2. 2 iteration: Read and insert the data.

Hi SV, Thanks for your reply. I thought about that solution but I was trying to void it because I’m dealing with large amount of data (10.000 - 50.000 records). If I run through the data twice I’ll face performance problems. But anyway if there is nothing better than that I’ll do it this way! :slight_smile:

You can speed up the process by inserting the data into a temporary table and then afterwards, if no errors were found, flush this into the “real” table.

I can’t use temporary tables because I’m using RecordRef… I want to make it generic in order to be able to import to any table. It’s getting complicated eh?

Why do you have to quit the report if you find bad data, can’t you skip that line make a note of it and carry on? At the end of the process only correct data has been entered and a new log of invalid data can be used to either manually enter it into Navision or be used to correct the source.

Hi Alex, Unfortunately the requirement is that even if a single error is found no data will be committed at all. That make sense because I’m dealing with large amount if data. Imagine what will happen if there are 30.000 records to import and 3.000 of them have errors. It will make it very hard then to find the 3.000 lines that have errors correct them, separate them from the rest lines (that were correct and are already in the table) in order to import them.

So you want to write the error log even though you have quit the report. Couldn’t you send the error log to another report, or to a (singleinstance?) codeunit, which then writes to the error log table after you quit you report? Alastair

Hi Alastair, I just found a solution that is not the best but it works and it is similar of what you wrote. I’m writing the error log into a file during the report processing. When the report quits I’m reading that log file and insert the lines into the log table. I usualy prefer efficient solutions and this is not… but it works so I can live with that for the time being. If someone comes up with a better option I’ll be glad to know.