Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Program to call the Where used list for all objects in a target package?

0 Kudos

Hello all,

As the title suggests, i'm trying to develop a program that gets a package name as an input and does a where-used search for every object in that package. Afterwards i want it to display the objects that are not used anywhere. Here is my approach:

Unfortunately this always results in an empty table as output, is my logic incorrect? METHOD get_unused_objects.

    DATA: found_check TYPE STANDARD TABLE OF rsfindlst,
          itab        TYPE TABLE OF string.
    SELECT *
     FROM tadir
     INTO TABLE @DATA(package_tab)
     WHERE devclass = @i_packagename. "To get the objects from the exact package i need

    LOOP AT package_tab ASSIGNING FIELD-SYMBOL(<fs>). "To convert it to strings, otherwise it doesn't          "                                                      work with the FM
      APPEND <fs>-obj_name TO itab.
    ENDLOOP.

    LOOP AT package_tab ASSIGNING FIELD-SYMBOL(<object>).
      CALL FUNCTION 'RS_EU_CROSSREF' 
        EXPORTING
          i_find_obj_cls           = 'CLAS'
          no_dialog                = 'X'
        TABLES
          o_founds                 = found_check
          i_findstrings            = itab
        EXCEPTIONS
          batch                    = 1
          batchjob_error           = 2
          illegal_object           = 3
          not_executed             = 4
          not_found                = 5
          no_cross_for_this_object = 6
          object_not_exist         = 7
          wrong_type               = 8
          OTHERS                   = 9.
      CASE sy-subrc.
        WHEN 1.
          cl_demo_output=>display( 'Some exception' ).
        WHEN 2.
          "Another exception and so on.
      ENDCASE.
      IF found_check IS INITIAL.                "If the FM finds no usage for the object
        APPEND <object> TO unused_objects_tab.  "Append it to a table i'll return later
      ELSE.
        CLEAR found_check. "If the FM finds usage, clear the check and continue.
        CONTINUE.
      ENDIF.
    ENDLOOP.
    r_objects_tab = unused_objects_tab.
  ENDMETHOD.
6 REPLIES 6

lenastodal
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Radoslav,

Thank you for visiting SAP Community to get answers to your questions. I am here to help you to get the most out of it.

First of all, I recommend that you familiarize yourself with https://community.sap.com/resources/questions-and-answers (if you haven't done so already), as it provides tips for preparing questions that draw responses from our members.

Please also make sure you're using all appropriate tags, so the right experts can find your question. Overall, the more details you provide, the more likely it is that members will be able to assist you. Should you wish, you can revise your question by selecting Actions, then Edit (although once someone answers your question, you'll lose the ability to edit the question - but if that happens, you can leave more details in a comment).

Finally, if you're hoping to connect with readers, please consider adding a picture to your profile. Here's how you do it: https://www.youtube.com/watch?v=F5JdUbyjfMA&list=PLpQebylHrdh5s3gwy-h6RtymfDpoz3vDS. By personalizing your profile with a photo of you, you encourage readers to respond.

Best,
Lena (SAP Community Moderator)


Join or subscribe to SAP Community Groups to stay up-to-date, including SAP TechEd Group.

mateuszadamus
Active Contributor
0 Kudos

Hello underfree22

First of all you're executing the Where-Used search for all of the objects found, for every object you have found. This is far from optimal.

    LOOP AT package_tab ASSIGNING FIELD-SYMBOL(<fs>). "To convert it to strings, otherwise it doesn't          "                                                      work with the FM
      APPEND <fs>-obj_name TO itab.
    ENDLOOP.

    LOOP AT package_tab ASSIGNING FIELD-SYMBOL(<object>). " <-- per each object
      CALL FUNCTION 'RS_EU_CROSSREF' 
        EXPORTING
          i_find_obj_cls           = 'CLAS'
          no_dialog                = 'X'
        TABLES
          o_founds                 = found_check
          i_findstrings            = itab " <-- all found objects

Second, you're looking for classes only.

i_find_obj_cls           = 'CLAS'

After reading objects from the package, you should read more information about them, to be precise - their type, and then use this information in the I_FIND_OBJ_CLS parameter. E.g.:

  • ABAP OO Class - CLAS
  • ABAP Program - REPS
  • ABAP Function - FUNC

Kind regards,

Mateusz

Sandra_Rossi
Active Contributor
0 Kudos

You have to indicate which types of objects you are interested in. The types are defined in the type group SWBM (SE11).

TYPES tt_scope_object_cls TYPE TABLE OF euobj-id.

DATA(lt_scope_object_cls) = VALUE tt_scope_object_cls( 
    ( swbm_c_type_prg_source )
    ( swbm_c_type_cls_object_type )
    ( swbm_c_type_cls_mtd_impl ) ).
CALL FUNCTION 'RS_EU_CROSSREF'
    ...
    TABLES
      ...
      i_scope_object_cls       = lt_scope_object_cls
      ...

Sandra_Rossi
Active Contributor
0 Kudos

I guess that your question comes after answer by michael.piesche in this yesterday question.

michael_piesche
Active Contributor
0 Kudos

1) Minimal input parameter usage for RS_EU_CROSSREF

In your case, when using the FM 'RS_EU_CROSSREF', you will at least have to pass the name(s) of the object as well as the Object Type (Object Class) of the object(s) you are wanting to do a where-used-list search for (every other parameter is optional). You cannot do a simultaneous search for different object types at once. In most cases it should be i_find_obj_cls = TADIR-OBJECT and itab contains an entry for TADIR-OBJ_NAME.

  • i_find_obj_cls = TADIR-OBJECT
  • itab contains an entry for TADIR-OBJ_NAME

2) Limits regarding available where-used-list based on object type

Using the FM 'RS_EU_CROSSREF' doesnt work for all object types, e.g. you cannot look for Function Groups FUGR, RFC Services SRFC, and many more. In general, they have to be available table EUOBJ.

3) Where-Used-List on Function Modules

When looking for Function Modules, those cannot be found directly in TADIR, but can found through the Function Group FUGR in TADIR and combining it with a select on TFDIR, whereas the TADIR-OBJ_NAME of the Function Group needs to be translated into the programm name (PNAME) for the TFDIR entry, which includes the SAPL prefix before the actual name (but after a namespace):

  • TADIR-OBJECT = FUGR
    TADIR-OBJ_NAME = ZMYFUGR
  • TFDIR-PNAME = SAPLZMYFUGR
    TFDIR-FUNCNAME = zmyfunctionnames
  • TADIR-OBJECT = FUGR
    TADIR-OBJ_NAME = /NAMESP/MYFUGR
  • TFDIR-PNAME = /NAMESP/SAPLMYFUGR
    TFDIR-FUNCNAME = /NAMESP/myfunctionnames

michael_piesche
Active Contributor
0 Kudos

underfree22, are you able to solve your problem or are same/other issues still occurring?