Skip to Content

Hi, We often run into requirements where we need to find out if the particular common piece of logic (could be any exit/enhancement/ common logic), is called by a particular webdynpro or not, in such cases, we need to have a small re-usable logic which can make our life easy.

Approach

We will be reading system callstack and extracting all the class names came in the call. Post to that we will be querying WDY_WB_GENINFO database table which would give us the name of the component from the class (as how it is done in CL_WDY_WB_NAMING_SERVICE class ).

Code–>

FUNCTION ztest_find_web_dynpros_at_run.

*”———————————————————————-

*”*”Local Interface:

*”  EXPORTING

*”     REFERENCE(ET_MESSAGES) TYPE  BAPIRET2_T

*”  TABLES

*”      T_COMPONENTS STRUCTURE  WDY_MD_COMPONENT_KEY OPTIONAL

*”———————————————————————-

************************************************************************

*            T Y P E S   D E C L A R A T I O N                         *

************************************************************************

   TYPES: BEGIN OF lty_guid,

            guid TYPE c LENGTH 20,

          END OF lty_guid,

          ltt_guid TYPE STANDARD TABLE OF lty_guid.

************************************************************************

*            D A T A     D E C L A R A T I O N                         *

************************************************************************

*       Internal tables

   DATA: lt_abapcallstack TYPE abap_callstack,

         lt_guid          TYPE ltt_guid,

*       Field strings

         ls_message       TYPE bapiret2,

         ls_guid          TYPE lty_guid,

         ls_callstack     TYPE abap_callstack_line,

*       Variables

         lv_classname     TYPE c LENGTH 30

         .

************************************************************************

*            C O N S T A N T S                                         *

************************************************************************

   CONSTANTS: lc_method TYPE c LENGTH 12 VALUE ‘METHOD’,

              lc_equal  TYPE c LENGTH VALUE ‘=’,

              lc_e      TYPE symsgty     VALUE ‘E’.

************************************************************************

*            M A I N – P R O C E S S I N G                             *

************************************************************************

* Read ABAP call stack

   CALL FUNCTION ‘SYSTEM_CALLSTACK’

     IMPORTING

       callstack          = lt_abapcallstack

             .

* Remove anything else than methods

   DELETE lt_abapcallstack WHERE blocktype <> lc_method.

* Remove anything else than dynpro methods

   SORT lt_abapcallstack BY mainprogram.

   DELETE ADJACENT DUPLICATES FROM lt_abapcallstack COMPARING mainprogram.

* Error if callstack is blank

   IF lt_abapcallstack IS INITIAL.

     CLEAR ls_message.

     ls_messagetype    = lc_e.

     ls_messagemessage = text000.

     APPEND ls_message TO et_messages.

     CLEAR ls_message.

   ENDIF.

* Get GUID to find component

   CLEAR ls_callstack.

   LOOP AT lt_abapcallstack INTO ls_callstack.

*   Extract “/1BCWDY/0O2TIFC6GG2TN5IT9BOH==” from “/1BCWDY/0O2TIFC6GG2TN5IT9BOH==CP”

     CLEAR lv_classname.

     lv_classname = ls_callstackmainprogram+0(30).

*   Replace “=” with space

     REPLACE ALL OCCURRENCES OF lc_equal IN lv_classname WITH space.

     CONDENSE lv_classname NOGAPS.

*   Form guid

     CLEAR ls_guid.

     ls_guidguid = lv_classname+8(20).

     APPEND ls_guid TO lt_guid.

     CLEAR ls_callstack.

   ENDLOOP.

* At this point lt_guid must be filled hence no need to check again

   SELECT component_name

     INTO TABLE t_components

     FROM wdy_wb_geninfo

     FOR ALL ENTRIES IN lt_guid

     WHERE controller_name = space

       AND guid            = lt_guidguid.

   IF sysubrc IS NOT INITIAL.

*   Error if no components found

     CLEAR ls_message.

     ls_messagetype    = lc_e.

     ls_messagemessage = text000.

     APPEND ls_message TO et_messages.

     CLEAR ls_message.

   ENDIF.

ENDFUNCTION.

Result table

T_COMPONENTS will have all the webdynpro component names which were there in the call stack.

T_MESSAGES will have error message if no component is found.

Important

As we are reading the current call stack, we must make sure that DYNPRO call has happened in the same LUW only as a  new LUW always have its own separate call stack.

To report this post you need to login first.

1 Comment

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

Leave a Reply