zoukankan      html  css  js  c++  java
  • ALV报表——ALV颜色设置(三)

    目录

    一、行用Layout相关属性设置

    代码:

    REPORT ZMMRTEST.
    ***********************************************************************
    * Tables Definitions
    ************************************************************************
    TABLES:marc.
    ************************************************************************
    * Data Definitions
    ************************************************************************
    TYPES: BEGIN OF  ty_data,
      linecolor(4) TYPE c,           "行颜色
      matnr LIKE mara-matnr,     "物料
      maktx LIKE makt-maktx,     "物料说明
    END OF ty_data.
    
    DATA: gt_data TYPE TABLE OF ty_data,
          gt_makt LIKE TABLE OF makt,
          wa_data LIKE LINE OF gt_data,
          wa_makt LIKE LINE OF gt_makt.
    
    TYPE-POOLS slis.
    DATA: gs_layout TYPE slis_layout_alv,
              gt_fieldcat TYPE slis_t_fieldcat_alv,
              wa_fieldcat TYPE  slis_fieldcat_alv.
    
    ************************************************************************
    * Includes Module
    ************************************************************************
    ************************************************************************
    * Selection Screen
    ************************************************************************
    PARAMETERS: p_werks LIKE marc-werks DEFAULT '2000' OBLIGATORY.
    SELECT-OPTIONS: s_matnr FOR marc-matnr.
    
    ************************************************************************
    * 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 display_data.
    END-OF-SELECTION.
    
    *&---------------------------------------------------------------------*
    *&      Form  GET_DATA
    *&---------------------------------------------------------------------*
    FORM get_data .
    
      DATA: l_index LIKE sy-tabix.
    
      SELECT marc~matnr makt~maktx
                INTO CORRESPONDING FIELDS OF TABLE gt_data
                FROM marc
                INNER JOIN makt ON makt~matnr = marc~matnr
                WHERE marc~matnr IN s_matnr
                AND marc~werks EQ p_werks
                AND makt~spras = sy-langu.
    
      SORT: gt_data BY matnr.
    
      LOOP AT gt_data INTO wa_data.
        l_index = sy-tabix.
    
        IF l_index MOD 2 = 0.
          wa_data-linecolor = 'C310'.         "设置颜色的值
        ENDIF.
    
        MODIFY gt_data FROM wa_data INDEX l_index.
      ENDLOOP.
    ENDFORM.                    " GET_DATA
    
    *&---------------------------------------------------------------------*
    *&      Form  DISPLAY_DATA
    *&---------------------------------------------------------------------*
    FORM display_data.
    
      "栏位最适宽度
      gs_layout-colwidth_optimize = 'X'.
    
      "指定数据输出内表中哪列存储的是颜色
      gs_layout-info_fieldname = 'LINECOLOR'.
    
      PERFORM set_fieldcat.
    
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program   = sy-repid
          is_layout                  = gs_layout
          it_fieldcat                 = gt_fieldcat[]
    *      i_callback_pf_status_set     = 'alv_pf_status'   " 触发事件调用子程序
    *      i_callback_user_command  = 'alv_user_command'   " 鼠标事件操作子程序
          i_save                           = 'A'
        TABLES
          t_outtab                   =  gt_data
        EXCEPTIONS
          program_error        = 1
          OTHERS                  = 2.
    
    ENDFORM.                    " DISPLAY_DATA
    
    *&---------------------------------------------------------------------*
    *&      Form  SET_FIELDCAT
    *&---------------------------------------------------------------------*
    FORM set_fieldcat.
    
      DEFINE fieldcat.
        wa_fieldcat-fieldname = &1.  "对应内表字段名
        wa_fieldcat-seltext_l = &2.       "输出列文本
        APPEND wa_fieldcat TO gt_fieldcat.CLEAR wa_fieldcat.
      END-OF-DEFINITION.
    
      fieldcat 'MATNR' '物料'.
      fieldcat 'MAKTX' '物料说明'.
    ENDFORM.                   " SET_FIELDCAT
    View Code

    运行效果:

     二、列:用FILEDCAT相关属性设置

    代码:

    REPORT ZMMRTEST.
    ***********************************************************************
    * Tables Definitions
    ************************************************************************
    TABLES:marc.
    ************************************************************************
    * Data Definitions
    ************************************************************************
    TYPES: BEGIN OF  ty_data,
      matnr LIKE mara-matnr,     "物料
      maktx LIKE makt-maktx,     "物料说明
    END OF ty_data.
    
    DATA: gt_data TYPE TABLE OF ty_data,
          gt_makt LIKE TABLE OF makt,
          wa_data LIKE LINE OF gt_data,
          wa_makt LIKE LINE OF gt_makt.
    
    TYPE-POOLS slis.
    DATA: gs_layout TYPE slis_layout_alv,
              gt_fieldcat TYPE slis_t_fieldcat_alv,
              wa_fieldcat TYPE  slis_fieldcat_alv.
    
    ************************************************************************
    * Includes Module
    ************************************************************************
    ************************************************************************
    * Selection Screen
    ************************************************************************
    PARAMETERS: p_werks LIKE marc-werks DEFAULT '2000' OBLIGATORY.
    SELECT-OPTIONS: s_matnr FOR marc-matnr.
    
    ************************************************************************
    * 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 display_data.
    END-OF-SELECTION.
    
    *&---------------------------------------------------------------------*
    *&      Form  GET_DATA
    *&---------------------------------------------------------------------*
    FORM get_data .
    
      SELECT marc~matnr makt~maktx
                INTO CORRESPONDING FIELDS OF TABLE gt_data
                FROM marc
                INNER JOIN makt ON makt~matnr = marc~matnr
                WHERE marc~matnr IN s_matnr
                AND marc~werks EQ p_werks
                AND makt~spras = sy-langu.
    
      SORT: gt_data BY matnr.
    
    ENDFORM.                    " GET_DATA
    
    *&---------------------------------------------------------------------*
    *&      Form  DISPLAY_DATA
    *&---------------------------------------------------------------------*
    FORM display_data.
    
      "栏位最适宽度
      gs_layout-colwidth_optimize = 'X'.
    
      PERFORM set_fieldcat.
    
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program   = sy-repid
          is_layout                  = gs_layout
          it_fieldcat                 = gt_fieldcat[]
    *      i_callback_pf_status_set     = 'alv_pf_status'   " 触发事件调用子程序
    *      i_callback_user_command  = 'alv_user_command'   " 鼠标事件操作子程序
          i_save                           = 'A'
        TABLES
          t_outtab                   =  gt_data
        EXCEPTIONS
          program_error        = 1
          OTHERS                  = 2.
    
    ENDFORM.                    " DISPLAY_DATA
    
    *&---------------------------------------------------------------------*
    *&      Form  SET_FIELDCAT
    *&---------------------------------------------------------------------*
    FORM set_fieldcat.
    
      DEFINE fieldcat.
        wa_fieldcat-fieldname = &1.  "对应内表字段名
        wa_fieldcat-seltext_l = &2.       "输出列文本
        wa_fieldcat-emphasize = &3.   "栏位的颜色
        APPEND wa_fieldcat TO gt_fieldcat.CLEAR wa_fieldcat.
      END-OF-DEFINITION.
    
      fieldcat 'MATNR' '物料' 'C310'.
      fieldcat 'MAKTX' '物料说明' ''.
    ENDFORM.                   " SET_FIELDCAT
    View Code

    运行效果:

    三、单元格

    REPORT ZMMRTEST.
    ***********************************************************************
    * Tables Definitions
    ************************************************************************
    TABLES:marc.
    ************************************************************************
    * Data Definitions
    ************************************************************************
    TYPES: BEGIN OF  ty_data,
      matnr LIKE mara-matnr,     "物料
      maktx LIKE makt-maktx,     "物料说明
      color TYPE lvc_t_scol, "单元格颜色
    END OF ty_data.
    
    DATA: gt_data TYPE TABLE OF ty_data,
          gt_makt LIKE TABLE OF makt,
          wa_data LIKE LINE OF gt_data,
          wa_makt LIKE LINE OF gt_makt.
    
    TYPE-POOLS slis.
    DATA: gs_layout TYPE slis_layout_alv,
              gt_fieldcat TYPE slis_t_fieldcat_alv,
              wa_fieldcat TYPE  slis_fieldcat_alv,
              wa_cellcolor TYPE lvc_s_scol. "ALV单元格颜色
    
    ************************************************************************
    * Includes Module
    ************************************************************************
    ************************************************************************
    * Selection Screen
    ************************************************************************
    PARAMETERS: p_werks LIKE marc-werks DEFAULT '2000' OBLIGATORY.
    SELECT-OPTIONS: s_matnr FOR marc-matnr.
    
    ************************************************************************
    * 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 display_data.
    END-OF-SELECTION.
    
    *&---------------------------------------------------------------------*
    *&      Form  GET_DATA
    *&---------------------------------------------------------------------*
    FORM get_data .
      DATA: l_index LIKE sy-tabix.
    
      SELECT marc~matnr makt~maktx
                INTO CORRESPONDING FIELDS OF TABLE gt_data
                FROM marc
                INNER JOIN makt ON makt~matnr = marc~matnr
                WHERE marc~matnr IN s_matnr
                AND marc~werks EQ p_werks
                AND makt~spras = sy-langu.
    
      SORT: gt_data BY matnr.
    
      LOOP AT gt_data INTO wa_data.
        l_index = sy-tabix.
    
        IF l_index MOD 2 = 0.
          wa_cellcolor-fname = 'MATNR'.
          wa_cellcolor-color-col = 6.
          wa_cellcolor-color-int = 1.
          wa_cellcolor-color-inv = 0.
          APPEND wa_cellcolor TO wa_data-color.
        ELSE.
          wa_cellcolor-fname = 'MAKTX'.
          wa_cellcolor-color-col = 5.
          wa_cellcolor-color-int = 1.
          wa_cellcolor-color-inv = 0.
          APPEND wa_cellcolor TO wa_data-color.
        ENDIF.
    
        MODIFY gt_data FROM wa_data INDEX l_index.
      ENDLOOP.
    ENDFORM.                    " GET_DATA
    
    *&---------------------------------------------------------------------*
    *&      Form  DISPLAY_DATA
    *&---------------------------------------------------------------------*
    FORM display_data.
    
      "栏位最适宽度
      gs_layout-colwidth_optimize = 'X'.
    
      "单元格颜色
      gs_layout-coltab_fieldname = 'COLOR'.
    
      PERFORM set_fieldcat.
    
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program   = sy-repid
          is_layout                  = gs_layout
          it_fieldcat                 = gt_fieldcat[]
    *      i_callback_pf_status_set     = 'alv_pf_status'   " 触发事件调用子程序
    *      i_callback_user_command  = 'alv_user_command'   " 鼠标事件操作子程序
          i_save                           = 'A'
        TABLES
          t_outtab                   =  gt_data
        EXCEPTIONS
          program_error        = 1
          OTHERS                  = 2.
    
    ENDFORM.                    " DISPLAY_DATA
    
    *&---------------------------------------------------------------------*
    *&      Form  SET_FIELDCAT
    *&---------------------------------------------------------------------*
    FORM set_fieldcat.
    
      DEFINE fieldcat.
        wa_fieldcat-fieldname = &1.  "对应内表字段名
        wa_fieldcat-seltext_l = &2.       "输出列文本
        APPEND wa_fieldcat TO gt_fieldcat.CLEAR wa_fieldcat.
      END-OF-DEFINITION.
    
      fieldcat 'MATNR' '物料' .
      fieldcat 'MAKTX' '物料说明' .
    ENDFORM.                   " SET_FIELDCAT
    View Code

    运行效果:

    四:附ALV的颜色代码

     

    木叶飞舞之处,火亦生生不息
  • 相关阅读:
    Perl 简介
    一定时间后延时变长问题
    CPAN常见问题集
    J2SE简介
    brian的Perl问题之万能指南
    清洁工 VS 亿万富翁
    关于VC中的"stdafx.h"
    Perl模式匹配
    wiki介绍
    生活中10大省钱小秘诀 白领一族"必备诀窍"
  • 原文地址:https://www.cnblogs.com/StephenAmell/p/8135442.html
Copyright © 2011-2022 走看看