Skip to Content

Creating Custom BSP Error Handling

As you know whenever an error occurs on BSP the following standard BSP Error page is displayed to the user. In most cases displaying end user to this page is not convinient. Yet, It gives information about the dump but, also gives information to the end user which she/he totally confused.


Assigning custom error pages in SICF is also a solution. However at that time we may loose the details of the dump. Depending on the level of dump, we can access the details via transaction ST22 or SM21. However, in most cases error is not logged in anywhere. In ST22 we  can access error details easily. In SM21, It’s not as easy as in ST22. We had to parse the error logs. This is very hard and time consuming.

What happens when a BSP error occurs?

Before coming to solution, I want to explain a little about what happens when a BSP error occurs.

Anytime a dump happens REPORT_ERROR static method of CL_HTTP_EXT_BSP is called:

* Error exception: customer does not want our technical complex error page,
* but wants to specify own rendering to be used. We look in table bsperrhandler
* for a matching entry onto a string class=>method. If we find such a string,
* we call this method blind. We do not protect against errors here, so that if
* there should be a problem, a new exception should be handled by the kernel.
* This new method must have exactly the same signature as this method here, and
* should contain similar code to (at a minimum) the method report_error_html.
* A customer can consider the handling of non HTML user againsts as well, but
* this is probably seldomly required.
  FIELD-SYMBOLS: <bsperrhandler> TYPE bsperrhandler.
  DATA:           bsperrhandler  TYPE TABLE OF bsperrhandler.
  DATA:           url            TYPE string.
  url = server->request->get_header_field( if_http_header_fields_sap=>path_translated ).
  SELECT * FROM bsperrhandler INTO TABLE bsperrhandler ORDER BY sort_key.
  IF sy-subrc = 0 AND lines( bsperrhandler ) > 0.
    LOOP AT bsperrhandler ASSIGNING <bsperrhandler>.
      CHECK url CP <bsperrhandler>-url.
      TRANSLATE <bsperrhandler>-err_class  TO UPPER CASE. "#EC SYNTCHAR
      TRANSLATE <bsperrhandler>-err_method TO UPPER CASE. "#EC SYNTCHAR
      CALL METHOD (<bsperrhandler>-err_class)=>(<bsperrhandler>-err_method)
          EXPORTING server = server exception = exception.
* code *****************************************************************
  data: l_accept type string.
  l_accept = server->request->get_header_field( 'accept' ). "#EC NOTEXT
  if l_accept cs '*/*'.                  "#EC NOTEXT understands HTML
    report_error_html( server    = server
                       exception = exception ).
  elseif l_accept cs 'text/vnd.wap.wml'. "#EC NOTEXT understands WML
    report_error_wml( server    = server
                      exception = exception ).
    report_error_plain( server    = server
                        exception = exception ).

REPORT_ERROR method first searchs if any custom error handler methods exists for given URL or not. To do it, it searchs in BSPERRHANDLER table. If any error handler does not exist, it calls standard error reporting method REPORT_ERROR_HTML, REPORT_ERROR_PLAIN, REPORT_ERROR_WML depending on request header.  If it finds custom error handling record in BSPERRHANDLER, It calls Errorhandling method which is defined BSPERRHANDLER.

Custom BSP Error Handling Method

As it’s seen, to add custom error handling method, we just need to add record in BSPERRHANDLER table.

  1. Create error handling class and error handling method
  2. Add related record to BSPERRHANDLER

Error Handling Class and Method

Error handling class is just an ordinary ABAP Class. In my example I have created Z_CL_ERRORHANDLER.

Second step is defining error handling method. Error Handling method must have the same input parameters with CL_HTTP_EXT_BSP=>REPORT_ERROR:

EXCEPTION Importing Type Ref To CX_ROOT

We can do anything we want in our error handler method. In my example I have created a log table and saved error details in the table.

  CALL method cl_http_ext_bsp=>REPORT_ERROR_HTML
    exception = exception
    server = server.
 "You can write and call your own method
      EXCEPTION =     exception
      SERVER    =    server

The last step is to define errorhandler in BSPERRHANDLER table. To do it so, we need to add the following record

Field Value Description
SORT_KEY 1 unique sort order
URL * The url where error handling method will be applied. It accept wildwards. You can write individual page e.g. mypage.bsp or /myservice*

Now anytime error occurs our error handling method will be called instead of standard error handling method

You must be Logged on to comment or reply to a post.
    • Hello,

      I am not webdynpro expert but It may also work for webdynpros since they are hosted on ICF, the same logic can be applied to webdynpros.