zoukankan      html  css  js  c++  java
  • ALV报表模板

    最近在项目上不断的写报表,自己总结一套模板、框架,下载下来,然后每次新建报表上传,再实现一些方法,减少了一些不必要的重复体力劳动。

    如何使用:

    实现GET_DATA,完成取数逻辑;

    在INIT_FIELDCAT中定义了一个宏SET_FIELDCAT,用于设置表头,接受两个参数,第一个为字段名,第二个为表头显示的名字;

    需要自建一个名为Z_ALV_STATUS的GUI STATUS。

    *&---------------------------------------------------------------------*
    *& Report  ZALV_TEMPLATE
    *&
    *&---------------------------------------------------------------------*
    *程序名称:
    *程序名:
    *开发日期:
    *创建者:
    *申请者:
    *----------------------------------------------------------------------*
    *变更记录
    *
    *----------------------------------------------------------------------*
    
    REPORT  ZALV_TEMPLATE MESSAGE-ID ZCOMM.
    
    TYPE-POOLS:SLIS.
    
    TYPES:BEGIN OF TY_TAB,
      FIELDS TYPE C,  "显示字段
      END OF TY_TAB.
    
    DATA:IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
    G_LAYOUT TYPE SLIS_LAYOUT_ALV,
    G_REPID LIKE SY-REPID VALUE SY-REPID.
    
    DATA:IT_ITAB TYPE STANDARD TABLE OF TY_TAB.
    
    SELECTION-SCREEN BEGIN OF BLOCK BLK WITH FRAME TITLE TEXT-001.
    SELECTION-SCREEN END OF BLOCK BLK.
    
    INITIALIZATION.
    
    START-OF-SELECTION.
      PERFORM GET_DATA.
      IF IT_ITAB IS INITIAL.
        MESSAGE S000 DISPLAY LIKE 'E'.
      ELSE.
        PERFORM INIT_FIELDCAT.
        PERFORM INIT_LAYOUT.
        PERFORM OUTPUT.
      ENDIF.
    
    *&---------------------------------------------------------------------*
    *&      Form  GET_DATA
    *&---------------------------------------------------------------------*
    *       获取数据
    *----------------------------------------------------------------------*
    FORM GET_DATA.
    ENDFORM.                    "GET_DATA
    
    *&---------------------------------------------------------------------*
    *&      Form  INIT_FIELDCAT
    *&---------------------------------------------------------------------*
    *       初始化表头
    *----------------------------------------------------------------------*
    FORM INIT_FIELDCAT.
      DATA:LW_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
      DEFINE SET_FIELDCAT.
        CLEAR LW_FIELDCAT.
        LW_FIELDCAT-FIELDNAME = &1.
        LW_FIELDCAT-SELTEXT_S = &2.
        LW_FIELDCAT-SELTEXT_M = LW_FIELDCAT-SELTEXT_S.
        LW_FIELDCAT-SELTEXT_L = LW_FIELDCAT-SELTEXT_S.
        APPEND LW_FIELDCAT TO IT_FIELDCAT.
      END-OF-DEFINITION.
    ENDFORM.                    "INIT_FIELDCAT
    
    *&---------------------------------------------------------------------*
    *&      Form  INIT_LAYOUT
    *&---------------------------------------------------------------------*
    *       初始化布局
    *----------------------------------------------------------------------*
    FORM INIT_LAYOUT.
      G_LAYOUT-DETAIL_POPUP = 'X'.  "双击弹出明细窗口
      G_LAYOUT-F2CODE = '&ETA'.
      G_LAYOUT-ZEBRA = 'X'. "斑马线
    ENDFORM.                    "INIT_LAYOUT
    *&---------------------------------------------------------------------*
    *&      Form  OUTPUT
    *&---------------------------------------------------------------------*
    *       输出ALV
    *----------------------------------------------------------------------*
    FORM OUTPUT.
      G_REPID = SY-REPID.
    
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM       = G_REPID
          IS_LAYOUT                = G_LAYOUT
          IT_FIELDCAT              = IT_FIELDCAT[]
          I_SAVE                   = 'A'
          I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_SET'
          I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
        TABLES
          T_OUTTAB                 = IT_ITAB
        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.                    "OUTPUT
    *&---------------------------------------------------------------------*
    *&      Form  PF_STATUS_SET
    *&---------------------------------------------------------------------*
    *       设置GUI Status
    *----------------------------------------------------------------------*
    *      -->TR_EXTAB   text
    *----------------------------------------------------------------------*
    FORM PF_STATUS_SET USING TR_EXTAB TYPE SLIS_T_EXTAB.
      SET PF-STATUS 'Z_ALV_STATUS'.
    ENDFORM.                    "PF_STATUS_SET
    
    *&---------------------------------------------------------------------*
    *&      Form  USER_COMMAND
    *&---------------------------------------------------------------------*
    *       接受用户操作和命令
    *----------------------------------------------------------------------*
    *      -->UCOMM      text
    *      -->SELFIELD   text
    *----------------------------------------------------------------------*
    FORM USER_COMMAND USING UCOMM LIKE SY-UCOMM SELFIELD TYPE SLIS_SELFIELD.
    ENDFORM.                    "USER_COMMAND
    
  • 相关阅读:
    TWaver局部自动布局及嵌套Group处理
    如何在TWaver Flex中定制Tree的tooltip
    为TWaver HTML5的Tree组件增加鼠标滑过效果
    赛瓦软件参加2012中国国际信息通信展览会
    TWaver HTML5 on Microsoft Surface RT
    JTree实现文件树
    kd tree的优化查找算法BBF 【转】
    kd tree代码解析 【转】
    kd tree算法【转】
    基于OpenCV库的Gabor滤波器的实现
  • 原文地址:https://www.cnblogs.com/raychenfj/p/3076391.html
Copyright © 2011-2022 走看看