• 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
    
  • 相关阅读:
    【转载】nio介绍+原理+传统IO原理+与传统IO区别+案例
    【Ubuntu】制作执行脚本 | 打包一串命令顺序执行
    Ubuntu 使用教程集锦
    【转载】自定义地图数据瓦片化请求的一种实现方案
    【转载】ROS机器人程序设计 | 期末知识点大总结
    【转载】三维重建(三)相机参数标定与光束平差法(Bundle Adjustment)
    【阅读笔记】《大话数据挖掘》定义和功能
    【转载】C++对象成员与构造函数
    【转载】IP地址和子网划分学习笔记之《子网掩码详解》
    STM32的启动过程一
  • 原文地址:https://www.cnblogs.com/raychenfj/p/3076391.html
Copyright © 2020-2023  润新知