Behavoir of Batch Processing

ta5
ta5 Member Posts: 1,164
Hi
I have a strange behavoir with a report.
Lets use a table called x with a primary key (int) named pk. The report should copy some or all records in table x.
If I write some code on "OnAfterGetRecord" the result is a kind of endless loop, since the newly inserted records are visible to the processing loop. I have a workaround (use a temp variable of the table) and copy them to a normal record variable. Anyway, this looks a bit strange to me. :? Last and not least I'm interested how commited und uncommited changes are visible (to the connection that has changed the data) in reports and codeunits.

Comments on this are very welcome.
Thomas

Comments

  • Arhontis
    Arhontis Member Posts: 667
    You can perfrom that kind of implementation three ways:

    1. by using a temp table and perform the insertions and at the end of the report to move them into the real rec

    2. By using another variable of the same type to insert/modify the recs without the primary variable that you use in the loop to know about it. I think I have done it a couple of times, but in cu... Don't know if it will work in a report. Try it and tell me...

    3. by distinct filter the NOT new recs in your record with a field like (new rec) and insert the recs with "new rec"=true and at the end of the report to modify those recs as "new rec"=false. (not a good way) :-#

    Of course the second way (if it works) is the best and then the 1st is next...

    As for the commited or uncommited changes they are visible to the client that loops, but if an error occurs they are rolled back... That is why you must be carefull when batch modifing or inserting recs with loops to exclude the recs you insert or modify to avoid endless loops...

    I hope I helped a bit...
  • kine
    kine Member Posts: 12,562
    Uncommited changes are visible within same transaction. And the behaviour is different between Native DB and MS SQL DB.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ta5
    ta5 Member Posts: 1,164
    Thanks for the info!

    @Kine: Do you have more info and/or links to this?
    @Arhontis: Actually I have already used a different var than the data item of the report. So the 2. idea does not seem to work. I was also very surprised...I would be interesting whether you can reproduce that.
  • Arhontis
    Arhontis Member Posts: 667
    You are right, as for inserting recs the use of a second var is not correct, I checked some of my old code and I have used it for modifing only...
  • kine
    kine Member Posts: 12,562
    I have no links for you, but the main difference is between locking method of both systems. Native is using optimistic locking (versioning) and table locking and MS SQL is using table/page/record locking. And all differences are based on this...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.