Home | The Company | Publications | Products | Links | Tips | Jobs |
---|
Example of an Error RoutineUsing *ERROR-TA, USR0020N, and USR2010NBy Dieter W. StorrLast update: 30 June 2006 Question:How can I write a central error routine and including the long name of the error text?Answer:At first, all programs should have an ON ERROR statement, which uses *ERROR-TA and calling a central error routine, for example:(snip) 1440 * 1450 ON ERROR 1460 *ERROR-TA := 'NPPERROR' 1470 END-ERROR 1480 * (snip) When ON ERROR block entered for execution, program is interrupted and can only be resumed with RETRY. Exit ON ERROR block with FETCH, STOP, TERMINATE, RETRY, or ESCAPE ROUTINE. Each module of subroutine built with CALLNAT, PERFORM, or FETCH RETURN may contain an ON ERROR statement. If error occurs, Natural traces back to select first ON ERROR statement for processing; if none found, program terminates. Applicable system variables: *ERROR-NR and *ERROR-LINE. This system variable *ERROR-TA (A8) contains the name of the program, which is to receive control in the event of an error condition. When an error occurs, Natural will execute a STACK TOP DATA statement and place at the top of the stack the following information, which can be used as INPUT data by an error transaction: Error number (N4 if SG=OFF; N5 if SG=ON), Line number (N4), Status (A1), Program name (A8), Level (N2). If the Status is "L", the Line number will be "0". The Status may be one of the following:
Central Error Routine The central error routine, for example NPPERROR, receives the error information from the stack via *ERROR-TA by using the statement "INPUT ERR-NR ERR-LINE ERR-STAT ERR-PGM ERR-LVL." It can be used from online and batch and reads additional information with USR0020N (error text) and USR2010N (DB error information). * NAT-PAD Program Administration and Documentation * * NPPERROR: NAT-PAD Central Error Routine * * Input: ERR-NR ERR-LINE ERR-STAT ERR-PGM ERR-LVL * Subroutine: CALLNAT 'USR0020N' PARM-AREA RETURN-AREA * CALLNAT 'USR2010N' DB_ERR_STR * * Date Name Change and Enhancements * -------------------------------------------------------------------- * 10/31/1998 D.Storr data base information user exit USR0610N * DB_DBID and DB_FNR from B1 to B2 * 03/18/1999 D.Storr Back to B1 - Georg Schmitt SAG-DA: * For 2 byte DBID,FNR please use USR2010N. * 03/23/1999 D.Storr Changed USR0610N to USR2010N * * ------------------------(C) www.storrconsulting.com ---------- * DEFINE DATA LOCAL 1 ERR-NR (N4) 1 ERR-LINE (N4) 1 ERR-STAT (A1) 1 ERR-PGM (A8) 1 ERR-LVL (N2) 1 INFO (A78) * 1 PARM-AREA /* Parameters for CALLNAT 2 TYPE (A1) /* U or N ( User or NATURAL messages ) 2 APPLICATION (A8) /* Must not be blank for type = 'U' 2 #ERROR-NUMBER (N4) /* 1 thru 9999 2 LANG-CODE (A1) /* E,G,F,S,I,D and 1,2,3,4,5,6,7,8,9 allowed 2 RESPONSE (N4) /* Error during execution of USR0020N 1 RETURN-AREA /* Contains the message texts 2 S-FOUND (L) INIT Online Error Report
------------------------------------------------------------------------------ 17:03:52 *** N A T - P A D *** 2006-06-28 DIETER Error Report NATPAD NPMERROR The following error occurred in your application Program : STR-PAIN Line : 730 Error number: 1302 ------------------------------------------------------------------------------ Division by zero not permitted by parameter ZD=ON. ------------------------------------------------------------------------------ Status Type DBID FNR CMD Resp Subc ADD1 0000 0000 0000 0000 0000 Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12--- end term ------------------------------------------------------------------------------ Back to NATURAL Tips, Tricks, Techniques -- Overview |