CDS Part 21 – CDS View Finder Tool

2
15493
How to find CDS View?

The other day we were asked to create a simple tool which will help all to find the CDS View based on the tables they are hitting or the name of the view. The idea was to check if there are any CDS already provided by SAP or already created by some other team members so that there is no repetition of efforts. We know we can try to do the same using where-used list. But the where-used list returns too many information.

Let us see how our tool looks like.

Let us try to find, how may CDS Views uses sales order header table VBAK as the base.

In our system, there are 160 CDS Views which uses sales order header table VBAK.

Let us see the CDS names. The standard view identification helps in SAP Analytic Cloud developments.

When we click the CDS View, it takes to Data Dictionary T-Code SE11.

Announcement

We are starting a new Instructor-Led Paid Training on Advanced ABAP CDS with SAP Fiori Elements. This will be 1 hour daily on working days from 7:30 AM to 8:30 AM IST starting 15th of June 2020. Please register using this link and we will share more details soon.

Our team is using this simple tool extensively. It helps us to find all the standard and custom CDS Views for any given table or just table name description. And our functional and technical team members are really finding it useful and happy about it. 🙂

We have developed this tool to be used only in our Development system. So, we have taken the liberty to not follow all naming conventions and it is not quality review ready. But, it does the work we were expecting for.

The three tables which do the trick are – DDLDEPENDENCY (DD: Objects in a DDL Source), DD25T (Short Texts for Views and Lock Objects) and DD26S (Base tables and foreign key relationships for a view).

If you are not too picky about the quality of the test programs, you may copy the below code snippet and use this CDS Finder Tool in your development system.

REPORT ZSAPYARD_CDS_FINDER.

TABLES: ddldependency,dd25t,dd26s.

DATA: gt_25t TYPE  STANDARD TABLE OF dd25t,
      gs_25t TYPE dd25t.

CONSTANTS: gc_true  TYPE sap_bool VALUE 'X',
           gc_false TYPE sap_bool VALUE ' '.

* Deferred Class Definition
CLASS lcl_handle_events DEFINITION DEFERRED.

DATA: gt_outtab TYPE STANDARD TABLE OF alv_t_t2.
DATA: gr_table   TYPE REF TO cl_salv_table.
DATA: gr_container TYPE REF TO cl_gui_custom_container.

*...  object for handling the events of cl_salv_table
DATA: gr_events TYPE REF TO lcl_handle_events.
DATA: g_okcode TYPE syucomm.
DATA: it_bdcdata TYPE bdcdata OCCURS 0 WITH HEADER LINE      .
DATA:wa_bdcdata TYPE bdcdata .

* Event Handler Class Definition
CLASS lcl_handle_events DEFINITION.
  PUBLIC SECTION.
    METHODS:
      on_link_click FOR EVENT link_click OF cl_salv_events_table
        IMPORTING row column.
ENDCLASS .

* Event Handler Class Implementation
CLASS lcl_handle_events IMPLEMENTATION.

* On Click Method
  METHOD on_link_click.

    READ TABLE gt_25t INTO DATA(ls_25t) INDEX row.

    PERFORM bdc_dynpro      USING 'SAPLSD_ENTRY' '1000'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'RSRD1-TBMA_VAL'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=WB_DISPLAY'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=WB_DISPLAY'.
    PERFORM bdc_field       USING 'RSRD1-TBMA'
                                  'X'.
    PERFORM bdc_field       USING 'RSRD1-TBMA_VAL'
                                  ls_25t-viewname.
*   Navigate to Data Dictionary
    CALL TRANSACTION 'SE11' USING it_bdcdata
                                  MODE 'E'
                                  UPDATE 'A' .

    CLEAR:it_bdcdata,it_bdcdata[].

  ENDMETHOD.

ENDCLASS.

* Selection Screen
SELECT-OPTIONS: s_view FOR dd25t-ddtext NO INTERVALS ,
                s_tab  FOR dd26s-tabname NO INTERVALS.
* At Selection Screen
AT SELECTION-SCREEN.

* Start of Selection
START-OF-SELECTION.

* Pull the data from the db tables
  SELECT
  a~viewname,
  ddtext,
  objecttype
    FROM dd25t AS a INNER JOIN ddldependency AS b
    ON a~viewname = b~objectname
    INNER JOIN dd26s AS c
    ON a~viewname = c~viewname
    INTO TABLE @DATA(lt_final)
    WHERE a~ddlanguage = 'E' AND
          a~ddtext IN @s_view AND
          c~tabname IN @s_tab.

  LOOP AT lt_final INTO DATA(ls_final).
    MOVE-CORRESPONDING ls_final TO gs_25t .
    APPEND gs_25t TO gt_25t.
    CLEAR:gs_25t.
  ENDLOOP.

  SORT gt_25t BY viewname ASCENDING.

  DELETE ADJACENT DUPLICATES FROM gt_25t COMPARING viewname.

  DESCRIBE TABLE  gt_25t LINES DATA(l_tabix).

  DATA: l_count TYPE c LENGTH 7.
  l_count = l_tabix.

  CONCATENATE 'Total no. of CDS found' l_count INTO DATA(msg).
  MESSAGE msg TYPE 'I'.

* Call Factory Method
  CALL METHOD cl_salv_table=>factory
    IMPORTING
      r_salv_table = gr_table
    CHANGING
      t_table      = gt_25t[].

  DATA: lr_columns TYPE REF TO cl_salv_columns_table,
        lr_column  TYPE REF TO cl_salv_column_table.

  lr_columns = gr_table->get_columns( ).
  lr_columns->set_optimize( gc_true ).

  lr_column ?= lr_columns->get_column( 'VIEWNAME' ).
  lr_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
  lr_column->set_icon( if_salv_c_bool_sap=>true ).
  lr_column->set_long_text( 'VIEWNAME' ).

  DATA: lr_events TYPE REF TO cl_salv_events_table.

  lr_events = gr_table->get_event( ).

  CREATE OBJECT gr_events.

* Set Handler
  SET HANDLER gr_events->on_link_click FOR lr_events.

* Display ALV
  gr_table->display( ).

*---------------------------------------------------
* form for bdc dynpro
*---------------------------------------------------
FORM bdc_dynpro USING program
                      dynpro.
  CLEAR it_bdcdata.
  wa_bdcdata-program = program.
  wa_bdcdata-dynpro = dynpro.
  wa_bdcdata-dynbegin = 'X'.
  APPEND wa_bdcdata TO it_bdcdata.
  CLEAR:wa_bdcdata.

ENDFORM.                    "bdc_dynpro
*---------------------------------------------------
*        form for bdc field
*---------------------------------------------------
FORM bdc_field  USING fnam
                      fval.
  CLEAR it_bdcdata.
  wa_bdcdata-fnam = fnam.
  wa_bdcdata-fval = fval.
  APPEND wa_bdcdata TO it_bdcdata.
  CLEAR:wa_bdcdata.
ENDFORM.                    "bdc_field

Hope you will find this tool useful. It might not be as robust as you expect, but it does the search for you.

Please follow our LinkedIn Page, LinkedIn Group, Facebook Page, Twitter and Instagram.

Save our number +1-646-727-9273 and send us a Whatsapp message ‘LEARN’ to be part of our Learning Community.

Free Step by Step Core Data Services Exercises

Step by Step Virtual Data Model – VDM Tutorials

2 COMMENTS

  1. Very Nice Blog.. it really helps to found CDS View that are related to any table…

    I am actually looking that kind of stuff…

    Thanks a lot!!!

LEAVE A REPLY

Please enter your comment!
Please enter your name here