*&---------------------------------------------------------------------*
*& Report ZMM_TEXT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZMMR_TEXT4 NO STANDARD PAGE HEADING
                 MESSAGE-ID 00 LINE-SIZE 177 LINE-COUNT 200.

TABLES:tstc,marc,mara,d010tab.

DATA:BEGIN OF alv_data occurs 0,
  master LIKE d010tab-master,"程式名称
  tcode LIKE tstc-tcode," tcode
  tabname LIKE d010tab-tabname," 表格名称
  structure(1),"通透表
  data(1),"是否存在数据
END OF alv_data.

DATA:BEGIN OF get_table occurs 0 ,
tabname TYPE string,"表名
tabclass LIKE dd02vv-tabclass,"表格类型
END OF get_table.

DATA: gs_layout TYPE slis_layout_alv,
          gt_fieldcat TYPE slis_t_fieldcat_alv ,"with header line.
          wa_fieldcat TYPE slis_fieldcat_alv.
************************************************************************
* Includes Module
************************************************************************

************************************************************************
* Selection Screen
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-b01.
PARAMETERS:p_master LIKE d010tab-master.
*                    p_code LIKE tstc-tcode ,
*                    p_table LIKE d010tab-tabname .
SELECTION-SCREEN END OF BLOCK b1.


************************************************************************
* Initialization
************************************************************************
INITIALIZATION.

************************************************************************
* At Selection Screen
************************************************************************
AT SELECTION-SCREEN.

************************************************************************
* At Selection Screen Output
************************************************************************
AT SELECTION-SCREEN OUTPUT.

************************************************************************
* Report Format
************************************************************************
TOP-OF-PAGE.

END-OF-PAGE.
************************************************************************
* Main Process
************************************************************************
START-OF-SELECTION.
     PERFORM get_data.
     PERFORM get_col.
     PERFORM alv_show.
END-OF-SELECTION.

FORM get_data.
  DATA: l_index LIKE sy-tabix,
            l_num TYPE i.
  gs_layout-colwidth_optimize = 'X'.

*--------> remark 代码不能 inner join 未找到相应的原因  拆分以下sql如下
*    SELECT  tcode FROM tstc
**     inner JOIN d010tab ON d010tab~master = tstc~pgmna "程式名称
*      INTO CORRESPONDING FIELDS OF TABLE alv_data
*      WHERE "d010tab~master EQ p_master AND
**             tstc~pgmna EQ p_master
**             PGMNA EQ p_master AND
*             tcode EQ p_code.
**          AND tcode EQ p_code
**          AND tabname EQ p_table.
*--------> end remark

    SELECT * FROM d010tab
      INNER JOIN tstc ON tstc~pgmna EQ d010tab~master "程式名称
      INTO CORRESPONDING FIELDS OF TABLE alv_data
      WHERE master EQ p_master.

  IF sy-subrc <> 0.
        SELECT * FROM d010tab
        INTO CORRESPONDING FIELDS OF TABLE alv_data
        WHERE master EQ p_master.
  ENDIF.

  SORT alv_data by tabname.
  DELETE ADJACENT DUPLICATES FROM alv_data COMPARING tabname.
  LOOP AT alv_data.
    l_index = sy-tabix.

    CLEAR:get_table.

    SELECT SINGLE dd02vv~tabname
                dd02vv~tabclass
        FROM dd02vv
        INNER JOIN dd02l ON  dd02l~tabname EQ dd02vv~tabname
*        INNER JOIN dd03l ON dd03l~tabname EQ dd02vv~tabname
        INTO  get_table
        WHERE "dd02vv~tabclass IN ('TRANSP','CLUSTER','POOL') AND "透明表
                    dd02vv~contflag NE 'L' AND " 存储时资料的表格,空传送
                    dd02vv~as4local NOT IN (  'N','T' ) AND " 未启用,临时版本
                    dd02vv~tabname EQ alv_data-tabname AND
                    is_gtt NE 'X' ." X全局临时表 N 没有全局临时表

     IF get_table-tabclass EQ 'TRANSP' OR
         get_table-tabclass EQ 'CLUSTER' OR
         get_table-tabclass EQ 'POOL' .
         alv_data-structure = 'Y'. " 为通透表
         CLEAR:l_num.
          SELECT COUNT(*) INTO l_num
                UP TO 1 ROWS
                FROM (get_table-tabname).
          IF sy-subrc = 0.
              alv_data-data = 'Y'."存在数据
          ELSE.
              alv_data-data = 'N'."没有数据
          ENDIF.
     ELSEIF get_table-tabclass IS NOT INITIAL.
       alv_data-structure = 'N'. "结构
       alv_data-data = 'N'. "没有数据
     ELSE.
        DELETE alv_data INDEX l_index.
        CONTINUE.
     ENDIF.
    MODIFY alv_data INDEX l_index.
  ENDLOOP.

    SORT alv_data by structure DESCENDING data DESCENDING.
ENDFORM.
FORM GET_COL.
  DATA: l_repid TYPE sy-repid,
            l_inclname TYPE trdir-name,
            l_idx LIKE sy-tabix.

  CLEAR: gt_fieldcat[], wa_fieldcat.

    l_repid = l_inclname = sy-cprog.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
      EXPORTING
        I_PROGRAM_NAME         = L_REPID
        I_INTERNAL_TABNAME     = 'ALV_DATA'
        I_INCLNAME             = L_INCLNAME
      CHANGING
        CT_FIELDCAT            = GT_FIELDCAT
      EXCEPTIONS
        INCONSISTENT_INTERFACE = 1
        PROGRAM_ERROR          = 2
        OTHERS                 = 3.

   LOOP AT gt_fieldcat INTO wa_fieldcat.
      l_idx = sy-tabix.
        CASE wa_fieldcat-fieldname.
         WHEN 'STRUCTURE'.
            wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
            wa_fieldcat-seltext_l = '是否为通透表'.
            wa_fieldcat-ddictxt = 'S'.
          WHEN 'DATA'.
            wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
            wa_fieldcat-seltext_l = '是否有数据'.
            wa_fieldcat-ddictxt = 'S'.
*          WHEN 'LIST_NUM'.
*            wa_fieldcat-no_out = 'X'.    " NO_OUT 不显示
        ENDCASE.
*      CLEAR wa_fieldcat-key.
      MODIFY gt_fieldcat FROM wa_fieldcat INDEX l_idx.
    ENDLOOP.
ENDFORM.

  FORM ALV_SHOW.

      DATA: LS_LAYOUT TYPE SLIS_LAYOUT_ALV.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
            EXPORTING
                I_CALLBACK_PROGRAM = SY-REPID
                IS_LAYOUT                   = GS_LAYOUT
                IT_FIELDCAT                  = GT_FIELDCAT[]
                 I_SAVE                         = 'A'
               TABLES
                   T_OUTTAB                   = ALV_DATA
                EXCEPTIONS
                  PROGRAM_ERROR      = 1
                OTHERS                     = 2.
ENDFORM.

直接输入程式名称执行

 

 执行结果如下,有通透表和结构,透明表有检查是否存在数据

 

 如有bug请告知作者.或有更好的方法也请分享给广大网友.废话不多说,赶快下载试试吧!

posted on 2019-12-05 17:36  淡淡-祥  阅读(480)  评论(0编辑  收藏  举报