Friday, 27 November 2020

How to find the Views/CDS Views that stores multiple Field values? That’s what ABAPER and Functional does :) in WRICEFF development

Introduction

After working with SAP for more than 15 years and travelling across the Globe for SAP Projects one issue I always use to have how can I keep track of all the SAP Tables/Views associated with different Modules. If you are working as a SAP ABAP Consultant you need to keep the name of tables/views in your Fingertips. Sometimes this you know from other Experts and sometimes you have to dig it out.

After exploring I found a very easy way to know the Tables that contains all the four fields or Data Element in the same Views and has data in it.

SAP is just like an ocean and every droplet is like one SAP View. This is one of the first program I create in any Project.

Solution

Go to SE38-> Create a Program and Paste this Code.

*&---------------------------------------------------------------------*

*& Report ZST11_GET_TABLE

*&---------------------------------------------------------------------*

*&

*&---------------------------------------------------------------------*

REPORT ZST11_GET_TABLE2.

*&---------------------------------------------------------------------*

*& Report  ZTEST_PO_CHANGE

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

TABLES: DD04T,

        SWWWIHEAD,

        VBKPF,

        RBKP,

        CDHDR,

        CDPOS,

        DD03L,

        DD41V,

        T685T,

        VBPA,

        TPART,

        KONVC,

        BOOLE,

        EKKO.

DATA:DREF TYPE REF TO DATA.

FIELD-SYMBOLS:<TABLE> TYPE STANDARD TABLE.

TYPE-POOLS: SLIS, ICON.

* Internal Tables

TYPES: BEGIN OF T_IALV,

         TABNAME    TYPE DD03L-TABNAME,

         DDLNAME    TYPE DDLDEPENDENCY-DDLNAME,

         OBJECTNAME TYPE DDLDEPENDENCY-OBJECTNAME,

         FIELD1     TYPE DD03L-FIELDNAME,

         FIELD2     TYPE DD03L-FIELDNAME,

         FIELD3     TYPE DD03L-FIELDNAME,

         FIELD4     TYPE DD03L-FIELDNAME,

       END OF T_IALV .

DATA: IALV   TYPE STANDARD TABLE OF T_IALV,

      WA_ALV TYPE T_IALV.

DATA: ALV_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

      ALV_GRID      TYPE REF TO CL_GUI_ALV_GRID,

      OK_CODE       LIKE SY-UCOMM,

      FIELDCAT      TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.

SELECT-OPTIONS: S_FIELD1 FOR DD03L-FIELDNAME NO-EXTENSION,

*s_crdat for /opt/vim_1head-ARCHIVE_DATE,

S_FIELD2 FOR DD03L-FIELDNAME NO-EXTENSION,

S_FIELD3 FOR DD03L-FIELDNAME NO-EXTENSION,

S_FIELD4 FOR DD03L-FIELDNAME NO-EXTENSION,

S_EXC FOR BOOLE-BOOLE.

FIELD-SYMBOLS:<FS-TAB13> TYPE MANDT.

DATA:WA_DD1      TYPE DD03L,

     WA_DD2      TYPE DD03L,

     WA_DD3      TYPE DD03L,

     WA_DD4      TYPE DD03L,

     LV_TAB      TYPE DD03L-TABNAME,

     WA_DD_FINAL TYPE DD03L.

IF S_EXC-LOW IS NOT INITIAL.

*  LV_TAB = 'ARUN%'.

ENDIF.

IF S_FIELD1-LOW IS NOT INITIAL.

  SELECT C~DDLNAME, C~OBJECTNAME, P~TABNAME, P~FIELDNAME, P~ROLLNAME

    FROM ( DDLDEPENDENCY AS C

         INNER JOIN DD03L AS P ON P~TABNAME  = C~OBJECTNAME

                              AND P~AS4LOCAL = C~STATE )

    WHERE P~FIELDNAME = @S_FIELD1-LOW

    AND P~TABNAME NOT LIKE @LV_TAB

       INTO TABLE @DATA(ITAB13).

ENDIF.

IF S_FIELD2-LOW IS NOT INITIAL.

  SELECT C~DDLNAME, C~OBJECTNAME, P~TABNAME, P~FIELDNAME, P~ROLLNAME

  FROM ( DDLDEPENDENCY AS C

       INNER JOIN DD03L AS P ON P~TABNAME  = C~OBJECTNAME

                            AND P~AS4LOCAL = C~STATE )

*                              AND p~cityto   = @cityto )

*         INNER JOIN dd09l AS f ON f~tabname = p~tabname )

  WHERE P~FIELDNAME = @S_FIELD2-LOW

    AND P~TABNAME NOT LIKE @LV_TAB

     INTO TABLE @DATA(ITAB14).

ENDIF.

IF S_FIELD3-LOW IS NOT INITIAL.

  SELECT C~DDLNAME, C~OBJECTNAME, P~TABNAME, P~FIELDNAME, P~ROLLNAME

  FROM ( DDLDEPENDENCY AS C

       INNER JOIN DD03L AS P ON P~TABNAME  = C~OBJECTNAME

                            AND P~AS4LOCAL = C~STATE )

  WHERE P~FIELDNAME = @S_FIELD3-LOW

    AND P~TABNAME NOT LIKE @LV_TAB

     INTO TABLE @DATA(ITAB15).

ENDIF.

IF S_FIELD4-LOW IS NOT INITIAL.

  SELECT C~DDLNAME, C~OBJECTNAME, P~TABNAME, P~FIELDNAME, P~ROLLNAME

  FROM ( DDLDEPENDENCY AS C

       INNER JOIN DD03L AS P ON P~TABNAME  = C~OBJECTNAME

                            AND P~AS4LOCAL = C~STATE )

*                              AND p~cityto   = @cityto )

*         INNER JOIN dd09l AS f ON f~tabname = p~tabname )

  WHERE P~FIELDNAME = @S_FIELD4-LOW

    AND P~TABNAME NOT LIKE @LV_TAB

     INTO TABLE @DATA(ITAB16).

ENDIF.

SORT ITAB13 BY TABNAME.

DELETE ADJACENT DUPLICATES FROM ITAB13 COMPARING TABNAME..

SORT ITAB14 BY TABNAME.

DELETE ADJACENT DUPLICATES FROM ITAB14 COMPARING TABNAME..

SORT ITAB15 BY TABNAME.

DELETE ADJACENT DUPLICATES FROM ITAB15 COMPARING TABNAME..

SORT ITAB16 BY TABNAME.

DELETE ADJACENT DUPLICATES FROM ITAB16 COMPARING TABNAME.

IF S_FIELD1-LOW IS NOT INITIAL.

  LOOP AT ITAB13 INTO DATA(WA_TAB133).

    IF ITAB14[] IS NOT INITIAL.

      READ TABLE ITAB14  INTO DATA(WA_TAB134) WITH KEY DDLNAME = WA_TAB133-DDLNAME.

      IF SY-SUBRC = 0.

        IF ITAB15[] IS NOT INITIAL.

          READ TABLE ITAB15  INTO DATA(WA_TAB135) WITH KEY DDLNAME = WA_TAB133-DDLNAME."tabname = wa_tab133-tabname.

          IF SY-SUBRC = 0.

            IF ITAB16[] IS NOT INITIAL.

              READ TABLE ITAB16  INTO DATA(WA_TAB136) WITH KEY DDLNAME = WA_TAB133-DDLNAME."tabname = wa_tab133-tabname.

              IF SY-SUBRC = 0.

                WA_ALV-TABNAME =  WA_TAB134-TABNAME.

                WA_ALV-OBJECTNAME =  WA_TAB134-OBJECTNAME.

                WA_ALV-DDLNAME =  WA_TAB134-DDLNAME.

                WA_ALV-FIELD1 =  S_FIELD1-LOW.

                WA_ALV-FIELD2 =  S_FIELD2-LOW.

                WA_ALV-FIELD3 =  S_FIELD3-LOW.

                WA_ALV-FIELD4 =  S_FIELD4-LOW.

                APPEND WA_ALV TO IALV.

                CLEAR WA_ALV.

              ELSE.

                WA_ALV-TABNAME =  WA_TAB134-TABNAME.

                WA_ALV-OBJECTNAME =  WA_TAB134-OBJECTNAME.

                WA_ALV-DDLNAME =  WA_TAB134-DDLNAME.

                WA_ALV-FIELD1 =  S_FIELD1-LOW.

                WA_ALV-FIELD2 =  S_FIELD2-LOW.

                WA_ALV-FIELD3 =  S_FIELD3-LOW.

                APPEND WA_ALV TO IALV.

                CLEAR WA_ALV.

              ENDIF.

            ELSE.

              WA_ALV-OBJECTNAME =  WA_TAB134-OBJECTNAME.

              WA_ALV-DDLNAME =  WA_TAB134-DDLNAME.

              WA_ALV-FIELD1 =  S_FIELD1-LOW.

              WA_ALV-FIELD2 =  S_FIELD2-LOW.

              WA_ALV-FIELD3 =  S_FIELD3-LOW.

              APPEND WA_ALV TO IALV.

              CLEAR WA_ALV.

            ENDIF.

          ELSE.

            WA_ALV-TABNAME =  WA_TAB134-TABNAME.

            WA_ALV-OBJECTNAME =  WA_TAB134-OBJECTNAME.

            WA_ALV-DDLNAME =  WA_TAB134-DDLNAME.

            WA_ALV-FIELD1 =  S_FIELD1-LOW.

            WA_ALV-FIELD2 =  S_FIELD2-LOW.

            APPEND WA_ALV TO IALV.

            CLEAR WA_ALV.

          ENDIF.

        ELSE.

          WA_ALV-TABNAME =  WA_TAB134-TABNAME.

          WA_ALV-OBJECTNAME =  WA_TAB134-OBJECTNAME.

          WA_ALV-DDLNAME =  WA_TAB134-DDLNAME.

          WA_ALV-FIELD1 =  S_FIELD1-LOW.

          WA_ALV-FIELD2 =  S_FIELD2-LOW.

          APPEND WA_ALV TO IALV.

          CLEAR WA_TAB134.

          CLEAR WA_ALV.

        ENDIF.

      ENDIF.

    ENDIF.

  ENDLOOP.

ENDIF.

DELETE ADJACENT DUPLICATES FROM IALV COMPARING ALL FIELDS.

PERFORM GET_FIELDCATALOG.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

  EXPORTING

    I_CALLBACK_PROGRAM = SY-REPID

*   is_layout          = w_layout

    IT_FIELDCAT        = FIELDCAT[]

*   it_events          = i_events

  TABLES

    T_OUTTAB           = IALV

  EXCEPTIONS

    PROGRAM_ERROR      = 1

    OTHERS             = 2.

IF SY-SUBRC <> 0.

ENDIF.

FORM GET_FIELDCATALOG.

  CLEAR: FIELDCAT.

  FIELDCAT-SELTEXT_M    = 'Tablename'.

  FIELDCAT-FIELDNAME  = 'TABNAME'.

  FIELDCAT-OUTPUTLEN  = '15'.

  APPEND FIELDCAT TO FIELDCAT.

  CLEAR: FIELDCAT.

  FIELDCAT-SELTEXT_M    = 'DDLNAME'.

  FIELDCAT-FIELDNAME  = 'DDLNAME'.

  FIELDCAT-OUTPUTLEN  = '20'.

  APPEND FIELDCAT TO FIELDCAT.

  CLEAR: FIELDCAT.

  FIELDCAT-SELTEXT_M    = 'OBJECTNAME'.

  FIELDCAT-FIELDNAME  = 'OBJECTNAME'.

  FIELDCAT-OUTPUTLEN  = '20'.

  APPEND FIELDCAT TO FIELDCAT.

  CLEAR: FIELDCAT.

  FIELDCAT-SELTEXT_M   = 'Field1'.

  FIELDCAT-FIELDNAME  = 'FIELD1'.

  FIELDCAT-OUTPUTLEN  = '12'.

  APPEND FIELDCAT TO FIELDCAT.

  CLEAR: FIELDCAT.

  FIELDCAT-SELTEXT_M   = 'Field2'.

  FIELDCAT-FIELDNAME  = 'FIELD2'.

  FIELDCAT-OUTPUTLEN  = '12'.

  APPEND FIELDCAT TO FIELDCAT.

  CLEAR: FIELDCAT.

  FIELDCAT-SELTEXT_M   = 'Field3'.

  FIELDCAT-FIELDNAME  = 'FIELD3'.

  FIELDCAT-OUTPUTLEN  = '12'.

  APPEND FIELDCAT TO FIELDCAT.

  CLEAR: FIELDCAT.

  FIELDCAT-SELTEXT_M    = 'Field4'.

  FIELDCAT-FIELDNAME  = 'FIELD4'.

  FIELDCAT-OUTPUTLEN  = '12'.

  APPEND FIELDCAT TO FIELDCAT.

ENDFORM.

Here is the Execution. Just to let you know I have Excluded the Table Beginning with ‘/’. If you want to add it just tweak the code.

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Career, SAP ABAP Exam Prep

In the Below example I am looking for tables with these 4 fields/Data Element. EBELN EBELP MATNR and BELNR

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Career, SAP ABAP Exam Prep

Here is the Output

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Career, SAP ABAP Exam Prep

Now we will verify the below entry in SE16

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Career, SAP ABAP Exam Prep

SE16->CDS_IV_ITEMS_P

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Career, SAP ABAP Exam Prep

Below is the highlighted fields in the View. Now we execute

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Career, SAP ABAP Exam Prep

Here is the Result.

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Career, SAP ABAP Exam Prep

No comments:

Post a Comment