Show TOC

Creating Interactive ScriptsLocate this document in the navigation structure

Definition

Technically, a script in the new ABAP debugger is a normal locally defined class in the debugging session.

You therefore are not limited to the method calls offered by the ABAP Debugging Interface in the Script Wizard tab. You can use almost any of the capabilities offered by ABAP that would usually be available to you.

The script below illustrates your freedom to use standard ABAP capabilities. It uses the standard POPUP_GET_VALUES function module to collect the name of a program.

If you set up the script to run whenever the break point 'ABAP Stack Change' is triggered, then the script will do the following:

  1. Ask once in its INIT method for the name of an ABAP program.

  2. Check at each ABAP Stack Change break point whether you are in the context of the program that you specified (the program has started or you have returned to it in the debugger)..

    The program name is supplied by the PROGRAM attribute of object ABAP_SOURCE. ABAP_SOURCE is instantiated by the scripting infrastructure, and provides descriptive access to the program that is being debugged. You can insert ABAP_SOURCE attributes and methods from the Source Code Information section of the Script Wizard.

  3. Stop execution and return control to you in the debugger if you have reached the program that you specified.

You can see the complete script with error handling in transaction SAS. In SAS, choose the Script Editor tab. Then use Load Script to view the script RSTPDA_SCRIPT_PROGRAM_REACHED.

You can turn on the breakpoint at ABAP stack change in the new ABAP debugger. Choose Start of the navigation path Breakpoints Next navigation step Breakpoint at Next navigation step Breakpoint at Stack Change / Other End of the navigation path.

*---------------------------------------------------------------------*
*       CLASS lcl_debugger_script DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_debugger_script DEFINITION INHERITING FROM  cl_tpda_script_class_super  .

  PUBLIC SECTION.
    METHODS: init    REDEFINITION,
             script  REDEFINITION,
             end     REDEFINITION.
  PRIVATE SECTION.
    DATA program TYPE sy-repid.

ENDCLASS.                    "lcl_debugger_script DEFINITION
*---------------------------------------------------------------------*
*       CLASS lcl_debugger_script IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_debugger_script IMPLEMENTATION.

  METHOD init.
    DATA:           l_dd03p_tab TYPE TABLE OF dd03p,
                    l_key       TYPE abap_keydescr,
                    l_fields    TYPE TABLE OF sval,
                    l_field     TYPE sval,
                    l_rc(1) TYPE c.

*(1) get oref name
    l_field-tabname   = 'TPDA_DYNP_SRC_INFO'.
    l_field-fieldname = 'PROGRAM'.
    l_field-fieldtext = 'Programm'(prg).
    l_field-value      =      space.
    l_field-field_obl = abap_true.
    APPEND l_field TO l_fields.

    CALL FUNCTION 'POPUP_GET_VALUES'
      EXPORTING
        popup_title     = 'Halte bei Programm'(hd1)
      IMPORTING
        returncode      = l_rc
      TABLES
        fields          = l_fields
      EXCEPTIONS
        error_in_fields = 1
        OTHERS          = 2.

    READ TABLE l_fields INTO l_field INDEX 1.
    program = l_field-value.

  ENDMETHOD.                    "init

  METHOD script.

* Get the name of the current program using 
* a standard Script Wizard function. Compare it
* to the program name collected from the user. 
* Break if the program names match.
    DATA l_program TYPE sy-repid.

    IF program = abap_source->program( ).
       me->break( ).
    ENDIF.
  ENDMETHOD.                    "script
ENDCLASS.                    "lcl_debugger_script IMPLEMENTATION