ALV OO:颜色控制

news/2024/11/30 13:44:14/

1.信号灯

绿灯:3
黄灯:2
红灯:1
关键代码如下:
DATA: BEGIN OF gt_data OCCURS 0.INCLUDE STRUCTURE spfli.
DATA:   light TYPE c. " 显示信号灯的字段
DATA: END OF gt_data.LOOP AT gt_data." 为內表的信号灯字段赋值IF gt_data-carrid = 'AA'.gt_data-light = '1'.ELSEIF gt_data-carrid = 'AB'.gt_data-light = '2'.ELSE.gt_data-light = '3'.ENDIF.MODIFY gt_data TRANSPORTING light.
ENDLOOP.FORM set_layout CHANGING p_layout TYPE lvc_s_layo." 设置ALV布局p_layout-excp_fname = 'LIGHT'.
ENDFORM.
2.行颜色

关键代码如下:

DATA: BEGIN OF gt_data OCCURS 0.INCLUDE STRUCTURE spfli.
DATA:   linecolor(4) TYPE c. " 指定行颜色的字段
DATA: END OF gt_data.LOOP AT gt_data." 为行颜色字段赋值CASE gt_data-carrid.WHEN 'AA'.gt_data-linecolor = 'C400'.WHEN 'AB'.gt_data-linecolor = 'C500'.WHEN OTHERS.gt_data-linecolor = 'C600'.ENDCASE.MODIFY gt_data TRANSPORTING linecolor.
ENDLOOP.FORM set_layout CHANGING p_layout TYPE lvc_s_layo." 设置布局p_layout-info_fname = 'LINECOLOR'.
ENDFORM.

3.单元格颜色

关键代码如下:

DATA: BEGIN OF gt_data OCCURS 0.INCLUDE STRUCTURE spfli.
DATA:   cellcolor TYPE lvc_t_scol.
DATA: END OF gt_data.FORM set_cellcolor.DATA: lt_color    TYPE lvc_t_scol,ls_color    TYPE lvc_s_scol,ls_fieldcat TYPE lvc_s_fcat,l_index     TYPE i.LOOP AT gt_data.l_index = l_index + 1.CLEAR: lt_color[].LOOP AT gt_fieldcat INTO ls_fieldcat.CLEAR: ls_color.ls_color-fname = ls_fieldcat-fieldname.IF ls_color-fname EQ 'AIRPFROM'.CASE gt_data-airpfrom.WHEN 'ASP'.ls_color-color-col = 3. " ls_color-color是一结构,仍包含三个字段ls_color-color-int = 0.ls_color-color-inv = 0.WHEN 'GIG'.ls_color-color-col = 6.ls_color-color-int = 0.ls_color-color-inv = 0.WHEN OTHERS.ls_color-color-col = 5.ls_color-color-int = 0.ls_color-color-inv = 0.ENDCASE.INSERT ls_color INTO TABLE lt_color.ENDIF.ENDLOOP.CLEAR: gt_data-cellcolor[].INSERT LINES OF lt_color INTO TABLE gt_data-cellcolor.MODIFY gt_data INDEX l_index TRANSPORTING cellcolor.ENDLOOP.
ENDFORM.FORM set_layout CHANGING p_layout TYPE lvc_s_layo.p_layout-ctab_fname = 'CELLCOLOR'.
ENDFORM.
4.完整示例

c

(1). 创建100屏幕

PROCESS BEFORE OUTPUT.MODULE STATUS_0100.MODULE INIT_CON.PROCESS AFTER INPUT.MODULE USER_EXIT_0100 AT EXIT-COMMAND.

(2). 在100屏幕上面画自定义控件,命名为CUS01

(3). 程序代码

REPORT ztest_sy09.DATA: BEGIN OF gt_data OCCURS 0.INCLUDE STRUCTURE spfli.
DATA:   light        TYPE c,linecolor(4) TYPE c,cellcolor    TYPE lvc_t_scol.
DATA: END OF gt_data.DATA: g_con01 TYPE REF TO cl_gui_custom_container.DATA: g_grid01 TYPE REF TO cl_gui_alv_grid.DATA: gs_fieldcat TYPE lvc_s_fcat.
DATA: gt_fieldcat TYPE lvc_t_fcat.CONSTANTS: g_cus01 TYPE scrfname VALUE 'CUS01'.START-OF-SELECTION.PERFORM get_data.CALL SCREEN 100.*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text 获取数据
*----------------------------------------------------------------------*
FORM get_data.SELECT *INTO CORRESPONDING FIELDS OF TABLE gt_dataUP TO 30 ROWSFROM spfli.ENDFORM. "GET_DATA*&---------------------------------------------------------------------*
*& Form set_light
*&---------------------------------------------------------------------*
* text 信号灯字段赋值
*----------------------------------------------------------------------*
FORM set_light.LOOP AT gt_data.CASE gt_data-carrid.WHEN 'AA'.gt_data-light = '1'. " 红灯WHEN 'AB'.gt_data-light = '2'. " 黄灯WHEN OTHERS.gt_data-light = '3'. " 绿灯ENDCASE.MODIFY gt_data TRANSPORTING light linecolor.ENDLOOP.ENDFORM. "set_light*&---------------------------------------------------------------------*
*& Form set_linecolor
*&---------------------------------------------------------------------*
* text 行颜色字段赋值
*----------------------------------------------------------------------*
FORM set_linecolor.LOOP AT gt_data.CASE gt_data-carrid.WHEN 'AA'.gt_data-linecolor = 'C400'.WHEN 'AB'.gt_data-linecolor = 'C500'.ENDCASE.MODIFY gt_data TRANSPORTING linecolor.ENDLOOP.
ENDFORM. "set_linecolor*&---------------------------------------------------------------------*
*& Form set_cellcolor
*&---------------------------------------------------------------------*
* text 单元格颜色字段赋值
*----------------------------------------------------------------------*
FORM set_cellcolor.DATA: lt_color    TYPE lvc_t_scol,ls_color    TYPE lvc_s_scol,ls_fieldcat TYPE lvc_s_fcat,l_index     TYPE i.LOOP AT gt_data.l_index = l_index + 1.CHECK gt_data-carrid = 'AC'." 只处理AC行的单元格CLEAR: lt_color[].LOOP AT gt_fieldcat INTO ls_fieldcat.CLEAR: ls_color.ls_color-fname = ls_fieldcat-fieldname.IF ls_color-fname EQ 'AIRPFROM'.CASE gt_data-airpfrom.WHEN 'ASP'.ls_color-color-col = 3.ls_color-color-int = 0.ls_color-color-inv = 0.WHEN 'GIG'.ls_color-color-col = 6.ls_color-color-int = 0.ls_color-color-inv = 0.ENDCASE.INSERT ls_color INTO TABLE lt_color.ENDIF.ENDLOOP.CLEAR: gt_data-cellcolor[].INSERT LINES OF lt_color INTO TABLE gt_data-cellcolor.MODIFY gt_data INDEX l_index TRANSPORTING cellcolor.ENDLOOP.
ENDFORM. "SET_cellcolor*&---------------------------------------------------------------------*
*& Form SET_FIELDCAT
*&---------------------------------------------------------------------*
* text ALV显示字段文本
*----------------------------------------------------------------------*
FORM set_fieldcat.CLEAR: gt_fieldcat[],gs_fieldcat.DEFINE macro_fieldcat.CLEAR gs_fieldcat.gs_fieldcat-fieldname = &1.gs_fieldcat-coltext = &2.APPEND gs_fieldcat TO gt_fieldcat.END-OF-DEFINITION.macro_fieldcat 'CARRID' '航线代码'.macro_fieldcat 'CONNID' '航班连接Id'.macro_fieldcat 'COUNTRYFR' '起飞国家'.macro_fieldcat 'CITYFROM' '起飞城市'.macro_fieldcat 'AIRPFROM' '起飞机场'.macro_fieldcat 'COUNTRYTO' '目标国家'.macro_fieldcat 'CITYTO' '目标城市'.macro_fieldcat 'AIRPTO' '目标机场'.macro_fieldcat 'FLTIME' '航班时间'.macro_fieldcat 'DEPTIME' '启程时间'.macro_fieldcat 'ARRTIME' '到达时间'.macro_fieldcat 'DISTANCE' '距离'.ENDFORM. "SET_FIELDCAT*&---------------------------------------------------------------------*
*& Form SET_LAYOUT
*&---------------------------------------------------------------------*
* text 布局
*----------------------------------------------------------------------*
* -->P_LAYOUT text
*----------------------------------------------------------------------*
FORM set_layout CHANGING p_layout TYPE lvc_s_layo.p_layout-excp_fname = 'LIGHT'.p_layout-info_fname = 'LINECOLOR'.p_layout-ctab_fname = 'CELLCOLOR'.
ENDFORM. "SET_LAYOUT*&---------------------------------------------------------------------*
*& Module INIT_CON OUTPUT
*&---------------------------------------------------------------------*
* text 创建ALV
*----------------------------------------------------------------------*
MODULE init_con OUTPUT.DATA: ls_layout TYPE lvc_s_layo.IF g_con01 IS INITIAL.PERFORM set_fieldcat.PERFORM set_light.PERFORM set_linecolor.PERFORM set_cellcolor.PERFORM set_layout CHANGING ls_layout." 创建SAP容器实例CREATE OBJECT g_con01EXPORTINGcontainer_name              = g_cus01 " 自定义控件名称EXCEPTIONScntl_error                  = 1cntl_system_error           = 2create_error                = 3lifetime_error              = 4lifetime_dynpro_dynpro_link = 5OTHERS                      = 6.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF." 创建GRID实例CREATE OBJECT g_grid01EXPORTINGi_parent          = g_con01EXCEPTIONSerror_cntl_create = 1error_cntl_init   = 2error_cntl_link   = 3error_dp_create   = 4OTHERS            = 5.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF." 调用ALV 显示方法CALL METHOD g_grid01->set_table_for_first_displayEXPORTING
*       i_structure_name              = 'SPFLI' " 参照表结构字段显示is_layout                     = ls_layout " 布局CHANGINGit_fieldcatalog               = gt_fieldcat " 显示字段it_outtab                     = gt_data[]EXCEPTIONSinvalid_parameter_combination = 1program_error                 = 2too_many_lines                = 3OTHERS                        = 4.IF sy-subrc <> 0.
* Implement suitable error handling hereENDIF.ENDIF.ENDMODULE. " INIT_CON OUTPUT*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text 工具条
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.SET PF-STATUS 'STATUS_BAR'.ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_EXIT_0100 INPUT
*&---------------------------------------------------------------------*
* text 取消事件
*----------------------------------------------------------------------*
MODULE user_exit_0100 INPUT.LEAVE TO SCREEN 0.
ENDMODULE. " USER_EXIT_0100 INPUT

注:  (1). 参考资料:《SAP ABAP开发从入门到精通》 作者:金圣俊; 译者:张钟淑; 机械工业出版社;

          (2). 如有疏漏之处,还请不吝赐教!


http://www.ppmy.cn/news/749236.html

相关文章

计算机网络思科参考答案--IP 编址考试

请参见图示。 管理员必须向路由器 A 网络中的所有成员发送一条消息。 那么网络 172.16.16.0/22 的广播地址是什么&#xff1f; 172.16.23.255172.16.255.255172.16.16.255172.16.20.255 172.16.19.255 请参见图示。 思考一下 10.16.10.0/24 网络范围内已经使用了的地址和必须保…

微信小程序:QQ音乐API接口变更后访问被禁止,出现403页面的解决办法

问题描述: 在使用QQ音乐API接口获取音乐的时候&#xff0c;微信后台请求成功&#xff0c;但是出现403禁止访问页面&#xff0c;导致无法播放音乐。 解决办法 一、首先进行QQ音乐官网抓包分析 对RequestURL进行分析&#xff0c;得知每首歌曲音乐源的“VKey"都不同&#…

性能压测工具wrk

wrk支持mac和linux&#xff0c;不支持windows windows&#xff1a; 解决&#xff1a;使用docker 执行1&#xff1a;docker pull williamyeh/wrk 执行2&#xff1a;winpty docker run -it --rm williamyeh/wrk -t12 -c400 -d30s http://news.baidu.com/ 参考&#xff1a;性能…

IAR “Error[e104]: Failed to fit all segments into specified ranges”问题处理

0. 软件环境简介 0.1 集成开发环境&#xff1a; IAR Embedded Workbench for MSP430 IDEV7.10.1 IAR Embedded Workbench sharedcomponents V8.0.4.4801 1. 问题描述 一天&#xff0c;我用相同代码&#xff0c;相同版本IAR&#xff0c;重建一个工程&#xff0c;在编译软…

ELAU MC-4/11/10/400 C600/10/1/1/1/00 电动车辆供电设备(交流充电器)中的引导线通信

ELAU MC-4/11/10/400 C600/10/1/1/1/00 电动车辆供电设备(交流充电器)中的引导线通信 ish 070/60011/0/0/00/0/00/01/00-ELAU AG-伺服电机1.55A 6000RPM 680VDC ish 070/60022/0/1/00/0/10/00/01-ELAU AG-伺服电机2.7安培680伏直流电0.2安培24伏直流电2.2纳米 MC-4/10/50/400 -…

施耐德控制器维修伺服驱动器维修C400A8

施耐德控制器维修伺服驱动器维修C400A8 施耐德ELAU控制器维修C400/A8/1/1/1/00施耐德伺服驱动器维修 施耐德驱动器维修 施耐德控制器维修 施耐德伺服器维修 施耐德PLC控制器维修 ELAU伺服ELAU伺服驱动器维修控制器常见维修故障&#xff1a;短路&#xff0c;模块损坏&#xf…

Python Flask Web 高并发实现

Flask超高并发&#xff0c;Flask多进程gevent &#xff0c;Flask非gunicorn gevent多进程 1. flask gevent multiprocess wsgi简介 常常大家都是用gunicorn来解决flask后端部署并发的问题&#xff0c; 然而觉得自启多进程是为更优雅的高并发方式。这样就不需要gunicorn了。…

hc04模块使用手册

产品介绍 HC-04 蓝牙串口通信模块是新一代的基于 SPP&BLE5.0 蓝牙协议的双模数传模块。 无线工作频段为 2.4GHz ISM&#xff0c;调制方式是 GFSK。模块最大发射功率为 6dBm&#xff0c;接收灵 敏度为-92dBm。 模块采用邮票孔封装方式&#xff0c;可贴片焊接&#xff0c;模块…