Question incomprehensible behavior

fjpomares

New Member
Hello.

I have develope a procedure to do massive changes in data base. This is like that:
Code:
[SIZE=2]FOR EACH aljarafe.Permisos WHERE aljarafe.Permisos.UsrId <> '' AND aljarafe.Permisos.UsrId <> ? EXCLUSIVE-LOCK:
 
      aljarafe.Permisos.UsrId = ttusuarios.usunew.
 
End.[/SIZE]
 
[SIZE=2] 
FOR EACH tribu.AccGenUsu WHERE tribu.AccGenUsu.UsuId <> '' AND tribu.AccGenUsu.UsuId <> ? EXCLUSIVE-LOCK:
 
     tribu.AccGenUsu.UsuId = ttusuarios.usunew.
 
End.
 
 
 
FOR EACH tribu.WebPermisos WHERE tribu.WebPermisos.Usuario <> '' AND tribu.WebPermisos.Usuario <> ? EXCLUSIVE-LOCK:
 
     tribu.WebPermisos.Usuario = ttusuarios.usunew.
 
End.[/SIZE]

If in a iteration of a FOR EACH a record is locked for another user appear the message 2624 asking for cancel o wait.

If I press cancel , this launch a STOP condition and it start at the begining of the procedure and execute all FOR EACH another time. This is so because the block is the whole procedure, but If I include the ON STOP condition in the FOR EACH:

FOR EACH tribu.AccGenUsu WHERE tribu.AccGenUsu.UsuId <> '' AND tribu.AccGenUsu.UsuId <> ? EXCLUSIVE-LOCK ON STOP UNDO, RETRY:
tribu.AccGenUsu.UsuId = ttusuarios.usunew.
End.


Does this prevent that the procedure run another time from the begining?

I try it, but it does not behave like I expect.

What is it wrong?

Progress OE V10
Windows Systems

Thanks.
 

Cecil

19+ years progress programming and still learning.
Try this out. I know it's not perfect but since the code is to be used as data fix.

Code:
BUFFER Permisos       FOR aljarafe.Permisos.
BUFFER UpdatePermisos FOR aljarafe.Permisos.

FOR EACH  aljarafe.Permisos NO-LOCK
    WHERE aljarafe.Permisos.UsrId <> ''
      AND aljarafe.Permisos.UsrId <> ?:
    FIND UpdatePermisos Exclusive-lock
        WHERE ROWID(UpdatePermisos) EQ ROWID(aljarafe.Permisos)
        No-error.
       
    IF AVAILABLE UpdatePermisos THEN
    DO:
   
        ASSIGN
            UpdatePermisos.UsrId = ttusuarios.usunew.
                   
    END.
End.
 

RealHeavyDude

Well-Known Member
The default behavior of a stop condition is that it bails out completely and starts with the first procedure in the session.

From my point of view you have several options:
  1. Wait and hope that the lock on the record is released by whoever holds it before you reach the lock timeout ( usually 30 minutes ).
  2. Additionally check whether the record is locked ( if locked ... ) and handle locked records appropriately.
  3. Catch the stop condition and handle it appropriately.
Catch stop condition:
Code:
my-block:
do on error undo my-block, leave my-block
   on stop undo my-block, retry my-block:
 
  /* STOP Condition trapped */
  if retry then do:
    /* Your stuff */
  end.
 
  catch anyError as Progress.Lang.Error:
    /* Your stuff */
    delete object anyError.
  end catch.
 
end.

Heavy Regards, RealHeavyDude.
 
  • Like
Reactions: rzr
Top