Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This command aborts a function and causes an error message to be displayed:

...

   ABORT      MSGTXT('Unable to locate system definition record')

Aborting with Dynamically Constructed Text

This subroutine dynamically constructs the error message that the ABORT command displays:

...

   SUBROUTINE NAME(ABORT) PARMS((#MSGTXT1 *RECEIVED) (#MSGTXT2 *RECEIVED) (#MSGTXT3 *RECEIVED))

...

 
DEFINE     FIELD(#MSGTXT1) TYPE(*CHAR) LENGTH(40) DECIMALS(0)

...

 
DEFINE     FIELD(#MSGTXT2) REFFLD(#MSGTXT1)

...

 
DEFINE     FIELD(#MSGTXT3) REFFLD(#MSGTXT1)

...

 
DEFINE     FIELD(#MSGDTA) TYPE(*CHAR) LENGTH(132) DECIMALS(0)

...

 
USE        BUILTIN(BCONCAT) WITH_ARGS(#MSGTXT1 #MSGTXT2 #MSGTXT3) TO_GET(#MSGDTA)

...

 
ABORT      MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)

...

 
ENDROUTINE

...

It may be used in fatal error situations like this:

...

   EXECUTE    SUBROUTINE(ABORT) WITH_PARMS('Employee' #EMPNO 'not found')

Or this:

...

   EXECUTE    SUBROUTINE(ABORT) WITH_PARMS(#DEPTMENT 'is invalid' *BLANKS)

Aborting with a Substituted Variable Message

...

Then, the abort is given as:

...

   DEFINE     FIELD(#SALRY_CAP) REFFLD(#SALARY) EDIT_CODE(3) DEFAULT(0)

...


REQUEST    FIELDS(#SALRY_CAP)

...


SELECT     FIELDS(#EMPNO #GIVENAME #SURNAME #SALARY) FROM_FILE(PSLMST)

...


IF         COND('#SALARY  > #SALRY_CAP')

...


ABORT      MSGID(MSG0001) MSGF(MYMSGF) MSGDTA(#EMPNO #GIVENAME #SURNAME #SALARY)

...


ENDIF    
ENDSELECT
MESSAGE    MSGTXT('All Employees are OK') TYPE(*WINDOW) LOCATE(*MIDDLE)

Aborting with a Multilingual Text

In multilingual applications, you sometimes need to issue fatal error messages that contain *MTXT variables as their message text. This subroutine shows a way of doing this.

...

   SUBROUTINE NAME(ABORT) PARMS((#MSGDTA *RECEIVED))

...


DEFINE     FIELD(#MSGDTA) TYPE(*CHAR) LENGTH(132) DECIMALS(0)

...


ABORT      MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)

...


ENDROUTINE

It may be used in fatal error situations like this:

...

   EXECUTE SUBROUTINE(ABORT) WITH_PARMS(*MTXTABORT_MESSAGE_1)

Or like this:

...

   EXECUTE    SUBROUTINE(ABORT) WITH_PARMS(*MTXTABORT_EMPTY_FILE)

Trapping an Abort

The execution of an ABORT command in a called function can be detected and trapped by the calling function in this way:

...

   CALL       PROCESS(*DIRECT) FUNCTION(MYFUNC) IF_ERROR(ERR)

...


RETURN   
ERR: MESSAGE    MSGTXT('MYFUNC has ended with in error') TYPE(*WINDOW)

...


RETURN

If the function MYFUNC fails, control is passed to the ERR label (note that the IF_ERROR parameter logic may be triggered for many reasons other than the execution of a ABORT command).