raiserror

raiserror displays a user-defined error or local variable message on the user’s screen and sets a system flag to record the fact that an error has occurred.

As with print, the local variable must be declared within the same batch or procedure in which it is used. The message can be up to 255 characters long.

The syntax for raiserror is:

raiserror error_number 
     [{format_string | @local_variable}] [, arg_list]
     [extended_value  = extended_value  [{, 
     extended_value  = extended_value}...]]

The error_number is placed in the global variable error@@, which stores the error number most recently generated by SAP ASE. Error numbers for user-defined error messages must be greater than 17,000. If the error_number is between 17,000 and 19,999, and format_string is missing or empty (“ ”), SAP ASE retrieves error message text from the sysmessages table in the master database. These error messages are used chiefly by system procedures.

The length of the format_string alone is limited to 255 bytes; the maximum output length of format_string plus all arguments is 512 bytes. Local variables used for raiserror messages must be char or varchar. The format_string or variable is optional; if you do not include one, SAP ASE uses the message corresponding to the error_number from sysusermessages in the default language. As with print, you can substitute variables or constants defined by arg_list in the format_string.

You can define extended error data for use by an Open Client application (when you include extended_values with raiserror). For more information about extended error data, see your Open Client documentation or the Reference Manual: Commands.

Use raiserror instead of print when you want to store an error number in error@@. This example uses raiserror in the procedure named findrules:

raiserror 99999 "You must give a user name"

The severity level of all user-defined error messages is 16, which indicates that the user has made a nonfatal mistake.