这个功能是来自ST05的,我们通过ST05去trace之后的结果,通过双击表名可以进入这个SQL的语句分析,同时还有这个表的一些介绍,可以查看这个表的所有索引。而我通过debugST05里面的这个功能,把具体的功能单独拿出来,这样我们以后在查找索引的时候,就可以比较方便了:
核心代码部分是:
核心是一个FM:SACC_DDIC_INFO_SHOW 在参数直接输入表名即可。运行完就可以得到上面那个图了。如果需要显示所有的index field,就还需要显示,这个时候就需要另一个FM:SACC_DDIC_INFO_READ
具体的显示的代码部分参考下面的 PERFORM WRITE_ALL_INDEX_FIELDS USING GS_SCREEN-TABLE.
附上完整代码(直接copy使用):
*&---------------------------------------------------------------------*
*& Report Z_DEMO_SQL_ANALYSIS
*&
*&---------------------------------------------------------------------*
*& Version 1: it can show all the index field of the table 2014/5/27
*& Version 2:
*& Version 3:
*& Version 4:
*&---------------------------------------------------------------------*
REPORT Z_DEMO_SQL_ANALYSIS.
*----------------------------------------------------------------------*
*- Database Tables for get the table data -*
*----------------------------------------------------------------------*
TYPES: BEGIN OF TY_SCREEN,
TABLE LIKE DCOBJDEF-NAME,
END OF TY_SCREEN.
DATA: BEGIN OF dd03p_all OCCURS 100.
INCLUDE STRUCTURE dd03p.
DATA: END OF dd03p_all.
DATA: BEGIN OF dd12v_all OCCURS 50.
INCLUDE STRUCTURE dd12v.
DATA: END OF dd12v_all.
DATA: BEGIN OF dd26v_tab OCCURS 10.
INCLUDE STRUCTURE dd26v.
DATA: END OF dd26v_tab.
DATA: BEGIN OF DD17V_TAB OCCURS 10.
INCLUDE STRUCTURE DD17V.
DATA: END OF DD17V_TAB.
DATA: BEGIN OF dd17v_all OCCURS 50.
INCLUDE STRUCTURE dd17v.
DATA: END OF dd17v_all.
*----------------------------------------------------------------------*
*- Global Data for get the table data -*
*----------------------------------------------------------------------*
DATA: hierarchie TYPE sacc_tab_hier.
DATA: table_ex TYPE sacc_ddic_info.
DATA: GETSTATE LIKE DCOBJDEF-STATE VALUE 'A',
GOTSTATE LIKE DCOBJDEF-STATE.
DATA: toggle TYPE i.
DATA: GS_SCREEN TYPE TY_SCREEN.
DATA: OK_CODE TYPE SY-UCOMM.
*----------------------------------------------------------------------*
*- Selection Screen -*
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1.
PARAMETERS: P_NAME LIKE DCOBJDEF-NAME.
SELECTION-SCREEN END OF BLOCK B1.
*----------------------------------------------------------------------*
*- start-of-selection *
*----------------------------------------------------------------------*
START-OF-SELECTION.
CALL FUNCTION 'SACC_DDIC_INFO_SHOW'
EXPORTING
NAME = P_NAME.
SET PF-STATUS 'INDEX_1001'.
*----------------------------------------------------------------------*
*- AT USER-COMMAND *
*----------------------------------------------------------------------*
AT USER-COMMAND.
CASE SY-UCOMM.
WHEN 'NEW'.
CALL SCREEN 1001.
"CALL SCREEN 1001 STARTING AT 10 5.
WHEN 'IALL'.
PERFORM WRITE_ALL_INDEX_FIELDS USING P_NAME.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
WHEN 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
*&---------------------------------------------------------------------*
*& Module PAI_1001 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE PAI_1001 INPUT.
ENDMODULE. " PAI_1001 INPUT
*&---------------------------------------------------------------------*
*& Module PBO_1001 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE PBO_1001 OUTPUT.
SET PF-STATUS 'PF_1001'.
ENDMODULE. " PBO_1001 OUTPUT
*&---------------------------------------------------------------------*
*& Module EXIT INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE EXIT INPUT.
LEAVE TO SCREEN 0.
ENDMODULE. " EXIT INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_1001 INPUT.
DATA:l_ok_code TYPE sy-ucomm.
l_ok_code = OK_CODE.
CLEAR ok_code.
CASE l_ok_code.
WHEN 'RUN'.
CALL FUNCTION 'SACC_DDIC_INFO_SHOW'
EXPORTING
NAME = GS_SCREEN-TABLE.
P_NAME = GS_SCREEN-TABLE.
SET PF-STATUS 'INDEX_1001'.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
WHEN 'CANCEL'.
LEAVE PROGRAM.
WHEN 'IALL'.
PERFORM WRITE_ALL_INDEX_FIELDS USING GS_SCREEN-TABLE.
WHEN 'NEW'.
CALL SCREEN 1001.
"CALL SCREEN 1001 STARTING AT 10 5.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form WRITE_INDEX_FIELDS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_TABLE_EX_TABNAME text
* -->P_SPACE text
* -->P_PRIKEY text
*----------------------------------------------------------------------*
FORM WRITE_INDEX_FIELDS USING tabname indname iflag.
DATA: toggle TYPE i.
* Initialisieren
toggle = 0.
FORMAT INTENSIFIED OFF.
IF iflag = 'X'.
* Felder des Sekundärindex ausgeben
LOOP AT dd17v_all WHERE sqltab = tabname
AND indexname = indname.
FORMAT COLOR COL_NORMAL INTENSIFIED = toggle.
toggle = 1 - toggle.
WRITE: / sy-vline, (30) dd17v_all-fieldname.
WRITE: sy-vline, (04) dd17v_all-position.
WRITE: sy-vline, (04) dd17v_all-descflag.
WRITE AT sacc_lindx sy-vline.
ENDLOOP.
WRITE AT /(sacc_lindx) sy-uline.
ENDIF.
IF iflag = 'P'.
* Felder des Primärschlüssels ausgeben
LOOP AT dd03p_all WHERE tabname = tabname
AND keyflag = 'X'.
FORMAT COLOR COL_NORMAL INTENSIFIED = toggle.
toggle = 1 - toggle.
WRITE: / sy-vline, (30) dd03p_all-fieldname.
WRITE: sy-vline, (04) dd03p_all-position.
WRITE: sy-vline.
WRITE AT sacc_lindx sy-vline.
ENDLOOP.
WRITE: AT /(sacc_lindx) sy-uline.
ENDIF.
ENDFORM. " WRITE_INDEX_FIELDS
*&---------------------------------------------------------------------*
*& Form WRITE_ALL_INDEX_FIELDS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM WRITE_ALL_INDEX_FIELDS USING P_NAME1.
REFRESH DD03P_ALL.
REFRESH DD12V_ALL.
REFRESH DD17V_TAB.
REFRESH DD26V_TAB.
CALL FUNCTION 'SACC_DDIC_INFO_READ'
EXPORTING
NAME = P_NAME1
IMPORTING
TABLE_EX = TABLE_EX
TABLES
HIERARCHIE = HIERARCHIE
DD03P_ALL = DD03P_ALL
DD12V_ALL = DD12V_ALL
DD26V_TAB = DD26V_TAB
EXCEPTIONS
ERROR_NO_ACTIVE = 1
ERROR_READ_NAMETAB = 2
ERROR_READ_VIEW = 3
ERROR_READ_TABL = 4
ERROR_READ_INDEX = 5
OTHERS = 6.
IF SY-SUBRC = 0.
DATA: prikey(1) VALUE 'P', "#EC NOTEXT
seckey(1) VALUE 'X'. "#EC NOTEXT
DATA: line_size TYPE i.
IF TABLE_EX-TABCLASS = 'POOL' "#EC NOTEXT
OR TABLE_EX-TABCLASS = 'DBPOOL' "#EC NOTEXT
OR TABLE_EX-TABCLASS = 'CLUSTER'. "#EC NOTEXT
ELSE.
REFRESH DD17V_ALL.
LOOP AT DD26V_TAB.
CALL FUNCTION 'DD_TBIX_GET'
EXPORTING
GET_STATE = GETSTATE
INDEXNAME = '*' "#EC NOTEXT
LANGU = SY-LANGU
TABL_NAME = DD26V_TAB-TABNAME
WITHTEXT = 'X' "#EC NOTEXT
IMPORTING
GOT_STATE = GOTSTATE
TABLES
DD17V_TAB_A = DD17V_TAB
EXCEPTIONS
ILLEGAL_VALUE = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
"Nothing
ENDIF.
IF GOTSTATE = 'A'. "#EC NOTEXT
APPEND LINES OF DD17V_TAB TO DD17V_ALL.
ENDIF.
ENDLOOP.
SORT DD17V_ALL BY SQLTAB INDEXNAME POSITION.
ENDIF.
line_size = sacc_lindx + 5.
NEW-PAGE LINE-SIZE line_size.
IF table_ex-tabclass EQ 'VIEW'.
LOOP AT dd26v_tab.
* Primarykey
FORMAT COLOR COL_GROUP INTENSIFIED ON.
WRITE: / sy-vline, dd26v_tab-tabname, (15) text-178.
* write at SACC_lindx sy-vline.
WRITE: AT /(sacc_lindx) sy-uline.
PERFORM write_index_fields USING dd26v_tab-tabname space prikey.
* Sekundaer-Indizes zur akt. Tabelle des Views
LOOP AT dd12v_all WHERE sqltab = dd26v_tab-tabname.
FORMAT COLOR COL_GROUP INTENSIFIED OFF.
WRITE: / sy-vline, dd12v_all-sqltab, dd12v_all-indexname,
dd12v_all-ddtext.
* write: at (SACC_lindx) sy-vline, dd12v_all-ddtext.
WRITE AT (sacc_lindx) sy-uline.
PERFORM write_index_fields USING dd26v_tab-tabname
dd12v_all-indexname seckey.
ENDLOOP.
ENDLOOP.
ELSE. "Objekt ist kein View
* Primarykey
FORMAT COLOR COL_GROUP INTENSIFIED OFF.
WRITE: / sy-vline, table_ex-tabname, (15) text-178.
* write at SACC_lindx sy-vline.
WRITE: AT /(sacc_lindx) sy-uline.
PERFORM write_index_fields USING table_ex-tabname space prikey.
LOOP AT dd12v_all.
FORMAT COLOR COL_GROUP INTENSIFIED OFF.
WRITE: / sy-vline, dd12v_all-sqltab, dd12v_all-indexname,
dd12v_all-ddtext.
* write: at SACC_lindx sy-vline, dd12v_all-ddtext.
WRITE AT (sacc_lindx) sy-uline.
PERFORM write_index_fields USING dd12v_all-sqltab
dd12v_all-indexname seckey.
ENDLOOP.
ENDIF.
ENDIF.
ENDFORM.