Skip to Content
Technical Articles
Author's profile photo joseph pamisetti

How to Find CDS Views Based on source table provided to ABAP Executable Program

This blog is for anyone who is developing CDS views, they can check CDS views already available in the system based on source tables provided to executable ABAP Program.

Based on the findings, CDS view already available can be utilized instead of developing new CDS views.

When many developers are working, we will create lot of duplicate  objects for the same purpose –

It will be helpful  in effective resource utilization .

Avoid SAP system creating  lot of duplicate objects that will cause more memory usage and system performance.

This program is written in ABAP 7.5 and will be helpful in writing new way of coding .

 

  1. Create executable program using Tcode SE38

2. Code as shown below in screen shots

Pathway-> Eclipse Source Code Library

Below is the source code

REPORT ZCDS_VIEW.
***Begin of Selection Screen
PARAMETERS: p_table TYPE vibastab.
***End of Selection Screen

***Begin of Data declaration
TYPES: BEGIN OF ty_cdsview,
                table       TYPE vibastab,
                cdsview(40) TYPE c,
       END OF   ty_cdsview,
                lt_cdsview  TYPE STANDARD TABLE OF ty_cdsview
                            WITH DEFAULT KEY.
***End of Data declaration

***To get the View name based on the table
SELECT viewname,as4local,objpos,as4vers,tabname FROM dd27s
                                                INTO TABLE @DATA(lt_dd27s)
                                                WHERE tabname = @p_table.

IF lt_dd27s[] IS NOT INITIAL.
  SELECT * FROM acm_ddlstbviw_1r INTO TABLE @DATA(lt_cds)
                                 FOR ALL ENTRIES IN @lt_dd27s
                                 WHERE  view_name = @lt_dd27s-viewname.

  DATA(lt_cdsview1) = VALUE lt_cdsview( FOR ls_dd27s  IN  lt_dd27s
                      FOR ls_cds IN lt_cds FROM line_index( lt_cds[ view_name = ls_dd27s-viewname ] )
                      WHERE ( view_name = ls_dd27s-viewname )
                      LET ls_final      = VALUE ty_cdsview(
                          table         = ls_dd27s-tabname
                          cdsview       = ls_cds-ddls_name )
                      IN ( CORRESPONDING #( BASE ( ls_final ) ls_dd27s ) ) ).
ENDIF.


***Unique records based table and View
data(list_of_cdsviews) = value lt_cdsview( FOR GROUPS gr1 of ls_cdsview1  in lt_cdsview1
                                   GROUP BY ( table   = ls_cdsview1-table
                                              cdsview = ls_cdsview1-cdsview
                                              count  = group size ) ASCENDING
                                              ( table = gr1-table
                                                cdsview = gr1-cdsview ) ).

DATA(lv_count) = lines( list_of_cdsviews ).
WRITE:/ 'no.of records:', lv_count.
***Display the data
cl_demo_output=>display_data( list_of_cdsviews ).

Conclusion –

This ABAP program will be helpful to avoid creating duplicate CDS views with same functionality and purpose

This coding show new way of writing ABAP code

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Jelena Perfiljeva
      Jelena Perfiljeva

      Sorry, I just couldn't pass this opportunity to point out the irony that there are like 10 blog posts already on this subject. If only there was some kind of program to check for duplicates. 🙂 To avoid, you know, Internet memory usage and system performance. Oh wait. 🙂

      How to Find the Table/CDS Views Name by giving field Name in SAP ECC and SAP S/4 HANA - I think this one pretty much nailed it, ALV FM is bad but otherwise seems like a more robust program. Might want to take a look.

      How to find CDS Views by just knowing the Field name in SAP ECC and SAP S/4 HANA? This one has links to further posts going back to 2019

      These are just the top link in the handy-dandy Internet duplicate checker thingy.

      Best regards.

      Author's profile photo joseph pamisetti
      joseph pamisetti
      Blog Post Author

      Thank you Jelena for sharing me more information and I didn't use any FM for ALV and it is SAP standard class CL_DEMO_OUTPUT