Enhancing any ABAP program (or Showing a pony in every short dump)

Objective

Manipulating the display of runtime errors (short dumps) for triggering support events, adding more useful information to the error screen, or for showing an ASCII pony in every short dump in the system.
Let’s go!

Understanding the short dump texts

With a simple test report we can cause a short dump:

message 'This is a runtime error' type 'X'.

Runtime error with short dump
Enabling debug (/h) and checking the call stack will show us that the short dump is being displayed by the function module DISPLAY_EXC_SCREEN:
Short dump call stack
Using a simple SQL trace with transaction ST05 shows us that the table SNAPT contains the descriptive text for this specific runtime error, and the form read_snapt in program SAPMS380 is responsible for that.
Contents of table SNAPT for runtime error MESSAGE_TYPE_X
Form read_snapt in include MS380F10

So all we need to do to show a pony in the short dump is adding a little enhancement implementation to the end of this form and adding our ASCII pony to the beggining of the generated text.

Enhancing any ABAP program (including basis ones)

If you try to create an enhancement anywhere in a basis program (in this case an implicit point), it says you can’t:

Object PROG MS380F10 is part of the central basis and therefore cannot be enhanced
Exceção da classe CX_ENH_CENTRAL_BASE_NOT_ENHAN

Debugging this message we find that the method CL_R3STANDARD_PERSISTENCE=>OBJ_IS_ENHANCEABLE is responsible for determining if an object is enhanceable or not. All you need to do to circumvent the check is to put a break-point at the beginning of this method and skipping to the end.
For practicity, we will enhance this very method to skip these checks, making every ABAP program freely enhanceable!

  • Step 1 – Add a break-point to the first instruction in the method.
  • Step 2 – Open up the enhancement mode and show the implicit enhancement options.
  • Step 3 – Try to create a new enhancement implementation in the Start point (beginning of the method).
  • Step 4 – When the debugger fires up, navigate to the end of the method (instruction ENDMETHOD) and select Go to statement. Then Continue.
  • Step 5 – Select Code mode. Give it a name and description. Pick a package (I recommend $TMP/Local Object).
    Creating an enhancement implementation in method OBJ_IS_ENHANCEABLE
    Picking the enhancement name and description
  • Step 6 – Skip the checks again a few times, repeating step 4.
  • Step 7 – Add a return statement to the implementation code. Activate.
ENHANCEMENT 1  Z_ANY_ENHANCEABLE.    "active version
  return.
ENDENHANCEMENT.
  • Step 8 – Skip the checks again a few more times, repeating step 4.

Done! Now any ABAP program can be enhanced at will.

Showing the ASCII pony in the short dumps

  • Step 1 – In program SAPMS380, navigate to the form read_snapt.
  • Step 2 – Open up the enhancements mode and show the implicit enhancement options.
  • Step 3 – Create an enhancement implementation in the End point of the read_snapt form (right before the end of the code). It will work now.
  • Step 4 – Add the ABAP code below. Activate.
  data: lt_pony like text_out[] with header line.

  define add_line.
    append &1 to lt_pony.
  end-of-definition.

  add_line:
    '                                 |\    /|',
    '                              ___| \,,/_/',
    '                           ---__/ \/    \',
    '                          __--/     (D)  \',
    '                          _ -/    (_      \',
    '                         // /       \_ / ==\',
    '   __-------------------/           / \_ O o)',
    '  /                                 /   \==/`',
    ' /                                 /',
    '||          )                   \_/\',
    '||         /              _      /  |',
    '| |      /--------      ___\    /\  :',
    '| /   __-  - _/   ------    |  |   \ \',
    ' |   -  -   /                | |     \ )',
    ' |  |   -  |                 | )     | |',
    '  | |    | |                 | |    | |',
    '  | |    < |                 | |   |_/',
    '  < |    /__\                <  \',
    '  /__\                       /___\',
    ' '.

  if ttype = 'W'. "// What happened?
    insert lines of lt_pony into text_out index 1.
  endif.

Next time someone sees a short dump they will see our friendly pony! It even works for seeing old errors in transaction ST22.
Friendly pony in the short dump screen

 

abapninja

A coder/dancer/actor/singer, usually in that order. Works as an SAP consultant/developer, and loves to tinker with software.