当前位置:编程学习 > 网站相关 >>

SAP ABAP OALV单元格颜色设置

OALV单元格颜色设置

效果如下:

 

完整代码:

*&---------------------------------------------------------------------*
*& Report  ZTEST04
*&
*&---------------------------------------------------------------------*
*&  by cmh
*&  定义单元格颜色
*&---------------------------------------------------------------------*

REPORT  ZTEST04.
TYPES: BEGIN OF ilist_s ,
      name1(10),
      name2(10),
      name3(10),
      name4(10),
 END OF ilist_s.
DATA: ilist TYPE STANDARD TABLE OF ilist_s  WITH HEADER LINE .

DATA: BEGIN OF list OCCURS 0.
        INCLUDE STRUCTURE ilist .
DATA: rowcolor(4) TYPE c ,            "
      cellcolors TYPE lvc_t_scol ,    "单元格颜色
      cellstyles TYPE lvc_t_styl ,    "单元格样式
      celltext   TYPE alv_t_dtv .
DATA: END OF list.

DATA: ok_code LIKE sy-ucomm.
DATA: l_valid(1) TYPE c.

DATA: go_grid             TYPE REF TO cl_gui_alv_grid.

DATA: gt_fieldcat TYPE lvc_t_fcat,
      gs_fieldcat TYPE lvc_s_fcat,
      sla         TYPE lvc_s_layo.

DATA: ls_fieldcat TYPE lvc_s_fcat.
DATA ls_style TYPE lvc_s_styl .
DATA ls_cellcolor TYPE lvc_s_scol .
DATA ls_celltext     TYPE alv_s_dtv .
*---------------------------------------------------------------------*
*       CLASS lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS handle_button_click
      FOR EVENT button_click OF cl_gui_alv_grid
      IMPORTING es_col_id
                es_row_no.
ENDCLASS.                    "lcl_event_receiver DEFINITION*---------------------------------------------------------------------*
*       CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
  METHOD handle_button_click.
    PERFORM test USING es_col_id
                       es_row_no.
  ENDMETHOD.                                                "handle_f4
ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION
DATA: event_receiver TYPE REF TO lcl_event_receiver.
DATA: ii TYPE i .

START-OF-SELECTION.
  PERFORM frm_fieldcat.
  PERFORM frm_getdata.
  PERFORM frm_layout.
  PERFORM frm_display.

 

 

*&---------------------------------------------------------------------*
*&      Form  test
*&---------------------------------------------------------------------*
FORM test  USING    p_es_col_id TYPE lvc_s_col
                    p_es_row_no TYPE lvc_s_roid.
  MESSAGE i899(fi) WITH p_es_col_id-fieldname p_es_row_no-row_id .
ENDFORM.                    " test
*&---------------------------------------------------------------------*
*&      Form  FRM_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_FIELDCAT .

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname     = 'NAME1'.
  ls_fieldcat-scrtext_l     = 'TITLE1'.
  APPEND ls_fieldcat TO  gt_fieldcat.
  CLEAR ls_fieldcat.

  ls_fieldcat-fieldname     = 'NAME2'.
  ls_fieldcat-scrtext_l     = 'TITLE2'.
*    ls_fieldcat-emphasize = 'C610'.
  APPEND ls_fieldcat TO  gt_fieldcat.
  CLEAR ls_fieldcat.

  ls_fieldcat-fieldname     = 'NAME3'.
  ls_fieldcat-scrtext_l     = 'TITLE3'.
  APPEND ls_fieldcat TO  gt_fieldcat.

  CLEAR ls_fieldcat.

  ls_fieldcat-fieldname     = 'NAME4'.
  ls_fieldcat-scrtext_l     = 'TITLE4'.
  APPEND ls_fieldcat TO  gt_fieldcat.

ENDFORM.                    " FRM_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  FRM_GETDATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_GETDATA .

  list-name1 = 'A1'.
  list-name2 = 'B'.
  ls_cellcolor-fname = 'NAME1' .
  ls_cellcolor-color-col = '5' .
  ls_cellcolor-color-int = '1' .
  ls_cellcolor-color-inv = '1' .
  APPEND ls_cellcolor TO list-cellcolors .
&nbs

补充:Web开发 , 其他 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,