Skip to Content
Author's profile photo Faisal Altaf

Get Name of Tables used in T-Code

A few days back I got a requirement to add the names of the tables at the top of every custom program (as comments). It was hard to first get the name of the program using T-Code and for every program check the used tables names, so I tried to develop an application to get table names giving the T-Code as input or on the other hand after providing the table name get the T-Codes where this table is being used. I have successfully completed this one.

In the screen shot bellow I am giving the T-Code SP01 and SP02 and it is showing the tables. After click on the table name or description it will open the table same for T-Code.

Selection Screen

image

Output

image

Create a new program using T-Code SE38 copy past bellow code and save it after activation it will be ready to work with

Code

Assigned tags

      12 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member
      Asak Faisal,
      Thanks for posting this blog; really it's facinating and interesting. Hats off!
      Author's profile photo Former Member
      Former Member
      To be honest, adding a list of tables used into the header of a program is not the best idea.
      Transacftion SE80 will display all the associated dictionary entries for a given program, so why bloat the program header with this needless information. Just goto SE90 to see the program behind the transaction, then edit the program via se80.

      The only use for such a program might be to create a cross program map to identify all the programs that access tables. We once did this manually for all Z programs as a prerequisite for an upgrade and to help in resolving lengthy table locking issues.  

      Author's profile photo Former Member
      Former Member
      Its maybe strange to add them in the header but it’s nice Idea.
      I may need it in future.
      Author's profile photo Alexey Telitsyn
      Alexey Telitsyn
      it was nice for me to see old fashion ABAP's style. Useful tooling, thanks.
      Author's profile photo Former Member
      Former Member
      Will this show all Custom table usind in user exit and BADIs , don't think so.

      Best way to find is SQL trace.

      Author's profile photo Former Member
      Former Member
      Nice effort, but this check is already available in the ABAP Code Inspector via class CL_CI_TABNAMES_PUBLIC.
      Author's profile photo Former Member
      Former Member
      Thanks for the blog.  Recently we faced the same problem to identify the tables used.
      Author's profile photo Former Member
      Former Member
      Hi,
        For a particular T-Code, for ex: VA01  many programs are used.
      Is there any way to know the program name also where the tables are used.

      Author's profile photo Former Member
      Former Member
      Hi,

      the code is very usefull but tables used in module functions are not shown.

      The following code show tables used in module funcions (group function) in a transaction.

      SELECT tstct~tcode tstct~ttext d010tab~tabname dd02l~tabclass
      dd02t~ddtext
          INTO CORRESPONDING FIELDS OF TABLE it_detail

          FROM tstc INNER JOIN tstct    ON ( tstc~tcode = tstct~tcode )
                    INNER JOIN cross    ON ( tstc~pgmna = cross~include )
                    INNER JOIN tfdir    ON ( cross~name = tfdir~funcname )
                    INNER JOIN d010tab  ON ( tfdir~pname = d010tab~master )
                    INNER JOIN dd02l    ON ( d010tab~tabname = dd02l~tabname )
                    INNER JOIN dd02t    ON ( dd02l~tabname = dd02t~tabname )

          WHERE
           tstct~sprsl       EQ 'S' AND
            dd02l~as4local    EQ 'A'
            AND dd02l~as4vers     EQ '0000'
            AND dd02l~tabclass    EQ 'TRANSP'
            AND dd02l~tabclass    IN sottable
            AND dd02t~ddlanguage  EQ 'S'
            AND tstct~tcode       IN sotcode
            AND tstct~ttext       IN sotext
            AND d010tab~tabname   IN sotname
            AND dd02t~ddtext      IN soddtext.

      Author's profile photo Deep B
      Deep B

      Dear Faisal Altaf  ,

      I very much like your contribution :

      Get Name of Tables used in T-Code

      But please explain me one thing that why I am unable to get the list of tables/output after entering the

      TCODE  : FMRP_RW_BUDCON  : Budget Consumption Report  .

      It is saying sorry DATA not  found for  Given Criteria .

      So please explain me this issue  . 

      Regards

      Deep

      Author's profile photo Deep B
      Deep B

      Hi Faisal Altaf  ,

      Please tell me about this issue  .

      Author's profile photo Former Member
      Former Member

      REPORT zfsl_table_used_tcode NO STANDARD PAGE HEADING.

      TABLES: d010tab, dd02l, tstc, tstct, dd02t.

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

      *                          Types Defined                               *

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

      TYPES: BEGIN OF ty_detail,

               tcode   LIKE tstct-tcode,

               ttext   LIKE tstct-ttext,

               tabname LIKE d010tab-tabname,

               ddtext  LIKE dd02t-ddtext,

             END OF ty_detail.

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

      *            Declaration of Internal Tables & Variables                *

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

      DATA: it_detail TYPE STANDARD TABLE OF ty_detail WITH HEADER LINE,

             wa_detail LIKE LINE OF it_detail,       cursor_field(30).

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

      *                      SELECTION SCREEN                                *

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

      SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001 NO INTERVALS.

      SELECT-OPTIONS: sotcode  FOR tstct-tcode      NO INTERVALS MEMORY ID aaa,

      sotext   FOR tstct-ttext      NO INTERVALS,

      sotname  FOR d010tab-tabname  NO INTERVALS,

      soddtext FOR dd02t-ddtext     NO INTERVALS.

      SELECTION-SCREEN END OF BLOCK a.

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

      *                         AT SELECTION-SCREEN                          *

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

      AT SELECTION-SCREEN.

         IF sotcode[] IS INITIAL AND sotext[] IS INITIAL AND sotname[] IS INITIAL AND soddtext[] IS INITIAL.

           MESSAGE 'You must select minimum one option' TYPE 'E'.

         ENDIF.

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

      *                        START-OF-SELECTION                            *

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

      START-OF-SELECTION.

         SELECT tstct~tcode tstct~ttext d010tab~tabname dd02t~ddtext

           INTO CORRESPONDING FIELDS OF TABLE it_detail

           FROM tstc INNER JOIN tstct

           ON ( tstc~tcode = tstct~tcode )

           INNER JOIN d010tab  ON ( tstc~pgmna = d010tab~master )

           INNER JOIN dd02l    ON ( d010tab~tabname = dd02l~tabname )

           INNER JOIN dd02t    ON ( dd02l~tabname = dd02t~tabname )

           WHERE tstct~sprsl       EQ 'E'

           AND dd02l~as4local    EQ 'A'

           AND dd02l~as4vers     EQ '0000'

           AND dd02l~tabclass    EQ 'TRANSP'

           AND dd02t~ddlanguage  EQ 'E'

           AND tstct~tcode       IN sotcode

           AND tstct~ttext       IN sotext

           AND d010tab~tabname   IN sotname

           AND dd02t~ddtext      IN soddtext.

         IF sy-subrc EQ 0.

           SORT: it_detail BY tcode tabname.

           WRITE1(149) sy-uline,             /1(1)   '|',

                   3(20)   'Transaction Code'  CENTERED COLOR 1,

                   24(1)   '|',

                   26(36'Transaction Text'  CENTERED COLOR 1,

                   63(1)   '|',

                   65(20'Table Name'        CENTERED COLOR 1,

                   86(1)   '|',

                   88(60'Table Description' CENTERED COLOR 1,

                   149(1'|',             /1(149) sy-uline.

           LOOP AT it_detail INTO wa_detail.

             WRITE/1(1)   '|',

                      3(20)   wa_detail-tcode    HOTSPOT ON,

                      24(1)   '|',

                      26(36wa_detail-ttext    HOTSPOT ON,

                      63(1)   '|',

                      65(20wa_detail-tabname  HOTSPOT ON,

                      86(1)   '|',

                      88(60wa_detail-ddtext   HOTSPOT ON,

                      149(1'|'.

             HIDE: wa_detail.

           ENDLOOP.

           WRITE/1(149) sy-uline.

         ELSE.

           MESSAGE: 'Sorry, DATA not found for Given Criteria' TYPE 'S'.

         ENDIF.

      AT LINE-SELECTION.

         GET CURSOR FIELD cursor_field.

         CASE cursor_field.

           WHEN 'WA_DETAIL-TCODE' OR 'WA_DETAIL-TTEXT'.

             PERFORM show_transaction USING wa_detail-tcode.

           WHEN 'WA_DETAIL-TABNAME' OR 'WA_DETAIL-DDTEXT'.

             PERFORM show_table USING wa_detail-tabname.

           WHEN OTHERS.

         ENDCASE.

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

      *&      Form  show_table

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

      *       text

      *----------------------------------------------------------------------*

      *      -->TABLE_NAME text

      *----------------------------------------------------------------------*

      FORM show_table USING table_name.

         CALL FUNCTION 'RS_DD_TABL_EDIT'

           EXPORTING

             objname              = table_name

             edit_mode            = 'S'

           EXCEPTIONS

             object_not_found     = 1

             object_not_specified = 2

             permission_failure   = 3

             not_executed         = 4

             OTHERS               = 5.

         IF sy-subrc NE 0.

           MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

         ENDIF.

      ENDFORM.

      "show_table

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

      *&      Form  show_transaction

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

      *       text

      *----------------------------------------------------------------------*

      *      -->FIELD_VALUE  text

      *----------------------------------------------------------------------*

      FORM show_transaction USING tcode_in.

         DATA: tcode LIKE tstc-tcode.   tcode = tcode_in.

         CALL FUNCTION 'RS_TRANSACTION_SHOW'

           EXPORTING

             objectname       = tcode

             monitor_activate = ' '

           EXCEPTIONS

             object_not_found = 1

             OTHERS           = 2.

         IF sy-subrc NE 0.

           MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

         ENDIF.

      ENDFORM.

      "show_transaction