Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

This is my third post on practical uses of the ABAP Debugger Script you can find the first one at How to Create a Watchpoint for a Field Symbol in the ABAP Debugger and the second at Tracing a Program with the ABAP Debugger Script.

Sometimes programs can have complicated authorization checks and we may not have authorization to do certain things while testing. When this has happened to me in the past, I selected to create a break point on the ABAP command AUTHORITY-CHECK. When the program stopped, I stepped the program forward once and changed sy-subrc to 0, so that I could test the secured area. While this process works, it can also be time consuming if there are many authority checks scattered throughout. To speed up the process, you can use the debugger script and automate tricking the authority check.

To create the script, go to transaction SAS and click on the tab. Erase any code or comments that is currently in the script method. Now we need to add the command for moving the debugger forward one step. To do this, click on the and select the Debug Step option under the debugger control folder. The code for controlling the debugger will be copied to the script method. Copy the execute value (CL_TPDA_SCRIPT_DEBUGGER_CTRL=>DEBUG_STEP_OVER) to be passed as the P_COMMAND parameter. Remove the stars commenting out the try and catch block code.

Next, we want to add the code to change the value of sy-subrc to 0 so that the program thinks we passed the authority check. Place your cursor a couple of lines after the ENDTRY from the earlier command and click the button. Expand the folder titled "Variable Information" and then expand the folder titled "Change Variable Value" and select "Simple Variable or String". Set the P_NEW_VALUE parameter to '0' and the P_VARNAME parameter to 'sy-subrc' (both with single quotes). Now, remove the stars commenting out the try and catch block code.

Your script method should look like the below:

[abap]

  METHOD script.
*************************************************
* debugger commands (p_command):
* Step into(F5)   -> CL_TPDA_SCRIPT_DEBUGGER_CTRL=>DEBUG_STEP_INTO
* Execute(F6)     -> CL_TPDA_SCRIPT_DEBUGGER_CTRL=>DEBUG_STEP_OVER
* Return(F7)      -> CL_TPDA_SCRIPT_DEBUGGER_CTRL=>DEBUG_STEP_OUT
* Continue(F8)    -> CL_TPDA_SCRIPT_DEBUGGER_CTRL=>DEBUG_CONTINUE
*************************************************
****************************************************************
*Interface (CLASS = CL_TPDA_SCRIPT_DEBUGGER_CTRL / METHOD = DEBUG_STEP )
*Importing
*        REFERENCE( P_COMMAND ) TYPE I
****************************************************************

    TRY.
        CALL METHOD debugger_controller->debug_step
          EXPORTING
            p_command = cl_tpda_script_debugger_ctrl=>debug_step_over.
      CATCH cx_tpda_scr_rtctrl_status .
      CATCH cx_tpda_scr_rtctrl .
    ENDTRY.

****************************************************************
*Interface (CLASS = CL_TPDA_SCRIPT_DATA_DESCR / METHOD = CHANGE_VALUE )
*Importing
*        REFERENCE( P_NEW_VALUE ) TYPE STRING
*        REFERENCE( P_OFFSET ) TYPE I
*        REFERENCE( P_LENGTH ) TYPE I
*        REFERENCE( P_VARNAME ) TYPE STRING
****************************************************************

    TRY.
        CALL METHOD cl_tpda_script_data_descr=>change_value
          EXPORTING
            p_new_value = '0'
*           p_offset    = -1
*           p_length    = -1
            p_varname   = 'sy-subrc'.
      CATCH cx_tpda_varname .
      CATCH cx_tpda_scr_auth .
    ENDTRY.

  ENDMETHOD.                    "script

[/abap]

Now, uncheck the "Debugger Single Step" checkbox in the trigger selections and check the checkbox for "Breakpoint Reached" and click the pencil edit button as pictured below. Click the button to create a new break point and add one for the ABAP command "AUTHORITY-CHECK" and click the green checkmark button. This will make it so our script only runs when the debugger reaches the AUTHORITY-CHECK command.

You can now save your script. To run it, type /h in the transaction bar before running the program. Then click on the script tab in the debugger, click load script and enter your script. Lastly, click the button and that's it no more authority issues! Another use of this script is to change the sy-subrc value to 4 to test your program to see what happens when you do not have the proper authorization.

Stoplight image by Uwe Hermann @ flickr

Got any ideas of other things we could do with the debugger script? Leave them in the comments below!

18 Comments