Problem in Delete Function when Concurrent users Posting

sujatharaoosujatharaoo Member Posts: 57
Hi,

In a Transfer Order Shipment Posting routine, the values are posted to GLEntry,Item Ledger Entry, and Posted Transfer order shipment Table. After posting the values Transfer Order Shipment table has to be deleted. For this requirement Coding written as follow..

"Posted Br.TransferHeader".INIT;
"Posted Br.TransferHeader".TRANSFERFIELDS("Br.TransferHeader");
"Posted Br.TransferHeader".INSERT;
"Br.TransferLine".Reset;
"Br.TransferLine".SETRANGE("Br.TransferLine".Type,"Br.TransferHeader".Type);
"Br.TransferLine".SETRANGE("Br.TransferLine"."Document No","Br.TransferHeader".No);
IF "Br.TransferLine".FIND('-') THEN
REPEAT
"Posted Br.TransferLine".INIT;
"Posted Br.TransferLine".TRANSFERFIELDS("Br.TransferLine");
"Posted Br.TransferLine"."Posting Date" := "Br.TransferHeader"."Posting Date";
"Posted Br.TransferLine".INSERT;
UNTIL "Br.TransferLine".NEXT = 0;

"Br.TransferLine".DELETEALL;
"Br.TransferHeader".DELETE;

When Concurrent users are Posting, the Posted Transfer order Shipment is also getting deleted..
How to change the code, to avoid these deletion when concurrent users are posting? Can any one Suggest me? :)

Thanx In Advance
Regards,
Sujatha.N

Comments

  • DenSterDenSter Member Posts: 8,304
    Stuff doesn't just automatically get deleted from tables just because multiple users are posting at the same time. Something is going on that perhaps those records don't get created in the first place. I'm thinking maybe a COMMIT statement somewhere, at a time between where the original docs are deleted but before the posted records are created. Try to discover the pattern and investigate the code from there.
  • sujatharaoosujatharaoo Member Posts: 57
    Thanx for the suggestion. I have checked the code there is no commit statement has been used in the codeunit.

    Now we have modified the code as:

    "Posted Br.TransferHeader".INIT;
    "Posted Br.TransferHeader".TRANSFERFIELD("Br.TransferHeader");

    "Br.TransferLine".RESET;
    "Br.TransferLine".SETRANGE"Br.TransferLine".Type,"Br.TransferHeader".Type);
    "Br.TransferLine".SETRANGE("Br.TransferLine"."Document No","Br.TransferHeader".No);
    IF "Br.TransferLine".FIND('-') THEN BEGIN
    REPEAT
    "Posted Br.TransferLine".INIT;
    "Posted Br.TransferLine".TRANSFERFIELDS("Br.TransferLine");
    "Posted Br.TransferLine".INSERT;
    "Br.TransferLine".DELETE;
    UNTIL "Br.TransferLine".NEXT = 0;
    END;
    "Posted Br.TransferHeader".INSERT;
    "Br.TransferHeader".DELETE;

    Can u suggest me whether this modifid code will resolve the problem.

    Thanx in Advance
    Regards,
    Sujatha.N
  • garakgarak Member Posts: 3,263
    "Br.TransferLine".RESET;
    "Br.TransferLine".SETRANGE"Br.TransferLine".Type,"Br.TransferHeader".Type);
    "Br.TransferLine".SETRANGE("Br.TransferLine"."Document No","Br.TransferHeader".No);
    IF "Br.TransferLine".FIND('-') THEN BEGIN
    REPEAT
    "Posted Br.TransferLine".INIT;
    "Posted Br.TransferLine".TRANSFERFIELDS("Br.TransferLine");
    "Posted Br.TransferLine".INSERT;
    "Br.TransferLine".DELETE;
    UNTIL "Br.TransferLine".NEXT = 0;
    END;

    Doesn't delete the Rec that you use for a loop. If you are under native and you delete the actual "Br.TransferLine", then the next=0 will find no next and stop looping. so use a separate instance for deleting like:
    "Br.TransferLine".SETRANGE"Br.TransferLine".Type,"Br.TransferHeader".Type);
       "Br.TransferLine".SETRANGE("Br.TransferLine"."Document No","Br.TransferHeader".No);
        IF "Br.TransferLine".FIND('-') THEN BEGIN
         REPEAT
           "BrTransferLineToDelete" := "Br.TransferLine";  //or a get with the PK field values
    
         "Posted Br.TransferLine".INIT;
         "Posted Br.TransferLine".TRANSFERFIELDS("Br.TransferLine");
         "Posted Br.TransferLine".INSERT;
         //"Br.TransferLine".DELETE; //this we comment out
         "BrTransferLineToDelete".delete;
         UNTIL "Br.TransferLine".NEXT = 0;
         END;
    
    Do you make it right, it works too!
  • sujatharaoosujatharaoo Member Posts: 57
    Hi Garak,

    Thanx.. Let me try out this..
    Regards,
    Sujatha.N
  • gerdhuebnergerdhuebner Member Posts: 155
    When Concurrent users are Posting, the Posted Transfer order Shipment is also getting deleted..

    Well, from a logical point of view there are only 3 possibilities, when a record is "getting deleted":

    1.) In the code there is something like "Posted Br.TransferHeader".DELETE (or DELETEALL)
    2.) The "Posted Br.TransferHeader" has never been inserted (as DenSter pointed out) - in your case, this would mean that there are COMMITs in the posting routines before the INSERT (to be sure that there are no commits you have to check this with the client monitor!) but in your code, the posted record is inserted before the unposted one is deleted, so if there would occur an error or a "broken transaction" during posting, the unposted record should not have been deleted, too, and could be posted again... - and, if an error occurs, the user is notified (and perhaps can remember) that something has gone wrong, when he is later ashtonished that the posted record cannot be found.
    3.) One or another user deletes the record manually.

    My suggestion is that you verify, that 3.) is not possible.

    By the way, it is not critical to delete a looping record within the loop, because the NEXT statement (in my experience) works as if the record is still "alive".
Sign In or Register to comment.