[Progress Communities] [Progress OpenEdge ABL] Forum Post: RE: Double jeopardy when a NO-UNDO temp table violates a uniqueness constraint

Status
Not open for further replies.
D

dbeavon

Guest
Here is an extended variation of your example. Program "EntryProg.p" calls program "HelperProg.p". EntryProg BLOCK-LEVEL ON ERROR UNDO, THROW. define temp-table tt NO-UNDO field c1 as character field c2 as character index c1 as primary unique c1 . /* Buffer */ DEFINE BUFFER B1 FOR tt. /* ************************************************************************ */ /* Call the helper */ /* ************************************************************************ */ DO ON ERROR UNDO, THROW: RUN HelperProg.p (INPUT TABLE tt BIND). /* ********************************************************************* */ /* Catch and clean? */ /* ********************************************************************* */ catch err1 as Progress.Lang.Error : MESSAGE 'err 2...' VIEW-AS ALERT-BOX. /* EMPTY TEMP-TABLE tt.*/ delete tt. end. finally: MESSAGE 'done 2' VIEW-AS ALERT-BOX. end. END. /* ************************************************************************ */ /* Success */ /* ************************************************************************ */ MESSAGE 'success' VIEW-AS ALERT-BOX. HelperProg BLOCK-LEVEL ON ERROR UNDO, THROW. define temp-table tt_help NO-UNDO REFERENCE-ONLY field c1 as character field c2 as character index c1 as primary unique c1 . /* ************************************************************************ */ /* Params */ /* ************************************************************************ */ DEFINE INPUT PARAMETER TABLE FOR tt_help BIND. /* ************************************************************************ */ /* The work */ /* ************************************************************************ */ DO ON ERROR UNDO, THROW: DEFINE VARIABLE v_Loop AS INTEGER NO-UNDO. DO v_Loop = 0 TO 19: RELEASE tt_help. create tt_help. assign tt_help.c1 = STRING(v_Loop MODULO 10) tt_help.c2 = "1". END. /* catch err1 as Progress.Lang.Error : */ /* MESSAGE 'err...' VIEW-AS ALERT-BOX.*/ /* /* EMPTY TEMP-TABLE tt_help.*/ */ /* /* delete tt_help.*/ */ /* end. */ /* finally: */ /* MESSAGE 'done' VIEW-AS ALERT-BOX. */ /* end. */ END. This still behaves as yours did. I really don't like it. The outer program (EntryProg) is deleting the default tt buffer as part of the catch handler. It makes LOTS of scary assumptions about the problem that had been encountered in HelperProg. Eg. Assumptions That the particular error which was raised was related to a duplicate item constraint violation. That the default tt buffer is positioned properly etc. In other words, there is very poor encapsulation of the logic done by "HelperProg". And there is no separation of concerns between the two programs. In the very least it would be nice if "EntryProg" would be able to use the EMPTY TEMP-TABLE statement, rather than assuming the type of error and the positioning of the default buffer! Note in the code above that I do NOT wish for HelperProg to handle its own errors. Otherwise that would have been a much better place for your "delete tt" if it were absolutely necessary to make all the assumptions about the nature of the error.

Continue reading...
 
Status
Not open for further replies.
Top