5

I am the beginner for progress 4GL language and I'd like to know about the difference between NO-UNDO and NO-ERROR in progress 4gl language.

Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
Thiru
  • 231
  • 6
  • 20

1 Answers1

7

NO-ERROR

No error supresses errors in the runtime and hands the responsibility for those error and their handing to you, the developer.

/* 
In this example we do basically the same thing twice, once with no-error and once without. 
Without no-error the program will exit and the last message box will not be shown.
*/
DEFINE TEMP-TABLE tt NO-UNDO
    FIELD a AS INTEGER.

CREATE tt.
ASSIGN tt.a = INTEGER("HELLO") NO-ERROR.
IF ERROR-STATUS:ERROR THEN DO:
    MESSAGE "There was an error" VIEW-AS ALERT-BOX ERROR.
    /* You will be left with a tt-record with 0 as field value */
END.


MESSAGE "After no-error" VIEW-AS ALERT-BOX.

CREATE tt.
ASSIGN tt.a = INTEGER("GOODBYE").

MESSAGE "After error" VIEW-AS ALERT-BOX.

NO-UNDO

No-undo removes undo handling. This is usually the default preferred behavior unless you need temp-tables, variables etc to utilize undo-handling. A very basic example below.

Unless you really need undo handling it better be avoided. It might effect performance, local disk writes etc. It also limit the length of character variables etc.

Note: changed from "default" to "preferred behavior" as this is a better description

DEFINE VARIABLE cTxt1 AS CHARACTER NO-UNDO.
DEFINE VARIABLE cTxt2 AS CHARACTER.

DO TRANSACTION:

    ASSIGN 
        cTxt1 = "HELLO"
        cTxt2 = "GOODBYE".

    MESSAGE "Do you want to undo?"
        VIEW-AS ALERT-BOX 
        BUTTONS YES-NO
        UPDATE lAnswer AS LOGICAL.

    IF lAnswer THEN 
        UNDO, RETRY.        

 END.

 DISPLAY cTxt1 cTxt2.
Jensd
  • 7,886
  • 2
  • 28
  • 37
  • 4
    To clarify a bit... NO-UNDO is not the default as in "don't type anything and you will get NO-UNDO behaviour". It is the "default" in the sense that it is almost universally added to variable and temp-table definitions because it is the behavior that most programmers usually want. A missing NO-UNDO is almost always a sign of a lazy programmer that made a mistake. That mistake may not be obviously harmful and it the bad effects may not be easily noticed. – Tom Bascom Aug 07 '18 at 15:37
  • 1
    @TomBascom I agree 100% – Jensd Aug 07 '18 at 15:38
  • Wha is DYNAMIC-FUNCTION in progress 4gl?..pls explain with small program – Thiru Dec 07 '18 at 09:43
  • 1
    @Thirumalai Post a real question instead. This is not the correct place... – Jensd Dec 07 '18 at 09:43
  • It seems like if progress can make something more work and / or over complicated, especially if it flies in the face of what everyone else is doing in the industry, they'll do it. – Mike Cheel Jan 20 '20 at 16:42