Quantcast
Channel: ABAP Development
Viewing all articles
Browse latest Browse all 948

View Database Index for Given Table

$
0
0

Below program use to view Database Index of Table


REPORT  ZTABLE_IND.

TYPE-POOLS : slis.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: c1(20) type c OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b1.

DATA : fieldcatalog          TYPE slis_t_fieldcat_alv WITH HEADER LINE,    " For Field Catalog
        gd_layout             TYPE slis_layout_alv,                         " For Alv Layout
        gt_sort               TYPE slis_t_sortinfo_alv,                     " For Sorting
        gt_events             TYPE slis_t_event,                            " For Events
        gt_list_top_of_page   TYPE slis_t_listheader,                       " For Top of Page
        heading               TYPE slis_t_listheader,                       " For headings in Top of Page
        g_save(1)             TYPE c,                                       " For displaying variants
        g_exit(1)             TYPE c,
        g_variant             TYPE disvariant,
        gx_variant            TYPE disvariant,
        it_sort               TYPE slis_t_sortinfo_alv,
        x_sort                TYPE slis_sortinfo_alv,
        print                 TYPE slis_print_alv,                          " For Printing
        m_title               TYPE lvc_title VALUE 'ALV FOR TABLE INDEX'.

DATA: BEGIN OF wa,
         tbname(20) type  c ,
         indname(20) type  c ,
         colname(20) type  c ,
         colpos(2)   type  n ,
        END OF wa.

TYPES : BEGIN OF ty_wa,
         tbname(20) type  c ,
         indname(20) type  c ,
         colname(20) type  c ,
         colpos(2)   type  n ,
        END OF ty_wa.

DATA : it_wa TYPE STANDARD TABLE OF ty_wa WITH HEADER LINE.


START-OF-SELECTION.

IF g_save EQ space.
     PERFORM initialise_variant.
   ENDIF.


PERFORM get_data.

IF it_wa IS INITIAL.

     MESSAGE 'No Data Found!!!' TYPE 'S'.
     LEAVE TO CURRENT TRANSACTION.

   ENDIF.

PERFORM f_layout.
PERFORM display.

FORM loop_output.
   it_wa-tbname  = wa-tbname.
   it_wa-indname = wa-indname.
   it_wa-colname = wa-colname.
   it_wa-colpos  = wa-colpos.
   APPEND it_wa.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  INITIALISE_VARIANT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form INITIALISE_VARIANT .
g_save = 'A'.
   CLEAR g_variant.

   g_variant-report = sy-repid.
   gx_variant = g_variant.

   CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
     EXPORTING
       i_save     = g_save
     CHANGING
       cs_variant = gx_variant
     EXCEPTIONS
       not_found  = 2.
endform.                    " INITIALISE_VARIANT

*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form GET_DATA .

EXEC SQL PERFORMING loop_output .
select TABLE_NAME,INDEX_NAME , column_name , column_position into :wa
     from user_ind_columns   where table_name = :c1
ENDEXEC.

sort it_wa by indname colpos.
endform.                    " GET_DATA

*&---------------------------------------------------------------------*
*&      Form  F_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form F_LAYOUT .
   CLEAR gd_layout.
   gd_layout-detail_popup         = 'X'.
   gd_layout-zebra                = 'X'.
   gd_layout-no_vline             = ' '.
   gd_layout-colwidth_optimize    = 'X'.
endform.                    " F_LAYOUT

*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form DISPLAY .
   fieldcatalog-fieldname   = 'TBNAME'.
   fieldcatalog-tabname     = 'IT_WA'.
   fieldcatalog-seltext_m   = 'Table Name'.
   fieldcatalog-key         = 'X'.
   fieldcatalog-just        = 'L'.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.

   fieldcatalog-fieldname   = 'INDNAME'.
   fieldcatalog-tabname     = 'IT_WA'.
   fieldcatalog-seltext_m   = 'Index'.
   fieldcatalog-key         = 'X'.
   fieldcatalog-just        = 'L'.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.

   fieldcatalog-fieldname   = 'COLNAME'.
   fieldcatalog-tabname     = 'IT_WA'.
   fieldcatalog-seltext_m   = 'Column Name'.
   fieldcatalog-key         = 'X'.
   fieldcatalog-just        = 'L'.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.

   fieldcatalog-fieldname   = 'COLPOS'.
   fieldcatalog-tabname     = 'IT_WA'.
   fieldcatalog-seltext_m   = 'Column Position'.
   fieldcatalog-key         = 'X'.
   fieldcatalog-just        = 'L'.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.

   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
       i_callback_program     = sy-repid
*      i_callback_top_of_page = 'TOP_OF_PAGE'      "See Form of top_of_page
       i_grid_title     = m_title
       is_layout              = gd_layout
       it_fieldcat            = fieldcatalog[]
*      it_sort                = it_sort
*      it_events              = gt_events[]
       i_default              = 'X'
       i_save                 = g_save
     TABLES
       t_outtab               = it_wa
     EXCEPTIONS
       program_error          = 1
       OTHERS                 = 2.
   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.
endform.                    " DISPLAY


Viewing all articles
Browse latest Browse all 948

Trending Articles