参考:https://www.cnblogs.com/jiangzhengjun/archive/2004/01/13/4291344.html#_Toc411672653
1 REPORT ztest3 NO STANDARD PAGE HEADING. 2 TYPE-POOLS:slis. 3 TABLES:sflight. 4 5 DATA:BEGIN OF gt_itab OCCURS 0, 6 sel TYPE c, "用来做选择按钮列 7 light TYPE c, "红绿灯 8 checkbox TYPE c. "用作复选框列image055 9 INCLUDE STRUCTURE sflight. 10 DATA:END OF gt_itab. 11 12 DATA gt_fieldcat TYPE slis_t_fieldcat_alv. 13 DATA gs_fieldcat TYPE slis_fieldcat_alv. "表字段 14 DATA gs_layout TYPE slis_layout_alv. "布局 15 DATA: gt_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE. 16 17 18 SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. 19 SELECT-OPTIONS:s_carrid FOR sflight-carrid. "航线承运人ID 20 SELECT-OPTIONS:s_connid FOR sflight-connid. "航班连接 Id 21 SELECT-OPTIONS:s_fldate FOR sflight-fldate. "航班日期 22 SELECTION-SCREEN END OF BLOCK b1. 23 24 START-OF-SELECTION. 25 SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE gt_itab 26 WHERE carrid IN s_carrid 27 AND connid IN s_carrid 28 AND fldate IN s_carrid. 29 30 LOOP AT gt_itab. 31 IF gt_itab-price BETWEEN 0 AND 500. 32 gt_itab-light = '1'. 33 * gt_itab-checkbox = 'X'. 34 * gt_itab-sel = 'X'. 35 ELSEIF gt_itab-price BETWEEN 500 AND 800. 36 gt_itab-light = '2'. 37 ELSE. 38 gt_itab-light = '3'. 39 ENDIF. 40 MODIFY gt_itab. 41 ENDLOOP. 42 43 END-OF-SELECTION. 44 PERFORM set_layout. 45 PERFORM set_flildname. 46 * PERFORM set_sum. "是否需要进行分类合并、并进行小计 47 PERFORM result_alv. 48 49 50 *&---------------------------------------------------------------------* 51 *& Form set_sum 52 *&---------------------------------------------------------------------* 53 * text 54 *----------------------------------------------------------------------* 55 FORM set_sum. 56 gt_sort-spos = '1'."排序的顺序,如果根据多个字段来排时,决定哪个先排 57 gt_sort-fieldname = 'CONNID'. 58 gt_sort-up = 'X'. "升序(即gt_sort-up、gt_sort-down都没设置时),默认为升序 59 gt_sort-subtot = 'X'. "是否需要以此字段进行分类小计 60 APPEND gt_sort. 61 ENDFORM. " SET_LAYOUT 62 *&---------------------------------------------------------------------* 63 *& Form set_layout 64 *&---------------------------------------------------------------------* 65 * text 66 *----------------------------------------------------------------------* 67 FORM set_layout . 68 gs_layout-zebra = 'X'. 69 gs_layout-colwidth_optimize = 'X'. 70 gs_layout-cell_merge = 'X'. "内容能够复制到剪贴板 71 gs_layout-lights_fieldname = 'LIGHT'."指定灯列名 72 gs_layout-box_fieldname = 'CHECKBOX'."行多选择按钮设置 73 ENDFORM. " SET_LAYOUT 74 *&---------------------------------------------------------------------* 75 *& Form SET_FLILDNAME 76 *&---------------------------------------------------------------------* 77 * text 78 *----------------------------------------------------------------------* 79 * --> p1 text 80 * <-- p2 text 81 *----------------------------------------------------------------------* 82 FORM set_flildname . 83 CLEAR: gt_fieldcat,gs_fieldcat. 84 85 CLEAR: gs_fieldcat. 86 gs_fieldcat-fieldname = 'LIGHT'. 87 gs_fieldcat-seltext_m = '红绿灯'. 88 gs_fieldcat-icon = 'X'. "作为图标输出 89 APPEND gs_fieldcat TO gt_fieldcat. 90 91 92 CLEAR: gs_fieldcat. 93 gs_fieldcat-fieldname = 'CARRID'. 94 gs_fieldcat-seltext_m = '航线承运人ID'. 95 gs_fieldcat-key = 'X'. "主键字段 96 gs_fieldcat-hotspot = 'X'. "单击热点 97 APPEND gs_fieldcat TO gt_fieldcat. 98 99 CLEAR: gs_fieldcat. 100 gs_fieldcat-fieldname = 'CONNID'. 101 gs_fieldcat-seltext_m = '航班连接 Id'. 102 gs_fieldcat-key = 'X'. 103 gs_fieldcat-hotspot = 'X'. 104 APPEND gs_fieldcat TO gt_fieldcat. 105 106 CLEAR: gs_fieldcat. 107 gs_fieldcat-fieldname = 'FLDATE'. 108 gs_fieldcat-seltext_m = '航班日期'. 109 gs_fieldcat-key = 'X'. 110 gs_fieldcat-hotspot = 'X'. 111 APPEND gs_fieldcat TO gt_fieldcat. 112 113 CLEAR: gs_fieldcat. 114 gs_fieldcat-fieldname = 'PRICE'. 115 gs_fieldcat-seltext_m = '航空运费'. 116 gs_fieldcat-do_sum = 'X'. "总计 117 APPEND gs_fieldcat TO gt_fieldcat. 118 119 CLEAR: gs_fieldcat. 120 gs_fieldcat-fieldname = 'CURRENCY'. 121 gs_fieldcat-seltext_m = '航班的本地货币'. 122 APPEND gs_fieldcat TO gt_fieldcat. 123 124 CLEAR: gs_fieldcat. 125 gs_fieldcat-fieldname = 'SEATSMAX'. 126 gs_fieldcat-seltext_m = '最大容量'. 127 gs_fieldcat-edit = 'X'. "设置该字段可编辑 128 APPEND gs_fieldcat TO gt_fieldcat. 129 130 CLEAR: gs_fieldcat. 131 gs_fieldcat-fieldname = 'SEL'. 132 gs_fieldcat-seltext_l = '复选框'. 133 gs_fieldcat-checkbox = 'X'. 134 gs_fieldcat-edit = 'X'. 135 APPEND gs_fieldcat TO gt_fieldcat. 136 ENDFORM. " SET_FLILDNAME 137 *&---------------------------------------------------------------------* 138 *& Form RESULT_ALV 139 *&---------------------------------------------------------------------* 140 * text 141 *----------------------------------------------------------------------* 142 * --> p1 text 143 * <-- p2 text 144 *----------------------------------------------------------------------* 145 FORM result_alv . 146 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 147 EXPORTING 148 i_callback_program = sy-repid 149 i_callback_html_top_of_page = 'TOP_OF_PAGE' 150 i_grid_title = 'ALV报表功能模板' 151 is_layout = gs_layout 152 it_fieldcat = gt_fieldcat 153 it_sort = gt_sort[] 154 i_callback_user_command = 'USER_COMMAND' 155 TABLES 156 t_outtab = gt_itab 157 EXCEPTIONS 158 program_error = 1 159 OTHERS = 2. 160 ENDFORM. " RESULT_ALV 161 162 *&---------------------------------------------------------------------* 163 *& Form user_command 164 *&---------------------------------------------------------------------* 165 * 1.单击。双击热点 166 * 单击:需设置gs_fieldcat-hotspot = 'X'. 167 * 2.单元格数据修改后同步(即立即触发DATA_CHANGED事件)输出内表 168 *----------------------------------------------------------------------* 169 * -->UCOMM text 170 * -->SELFIELD text 171 *----------------------------------------------------------------------* 172 FORM user_command USING ucomm LIKE sy-ucomm selfield TYPE slis_selfield. 173 DATA str TYPE string. 174 CLEAR str. 175 selfield-refresh = 'X'. 176 177 MESSAGE i001(00) WITH '热点触发事务码:' ucomm. "1.单击。双击热点 178 179 * IF ucomm = 'SAVE'. "2.单元格数据 180 * PERFORM frm_update. "可以写更新代码 181 * ENDIF. 182 ENDFORM. "user_command 183 184 *&---------------------------------------------------------------------* 185 *& Form top_of_page 186 *&---------------------------------------------------------------------* 187 * text 188 *----------------------------------------------------------------------* 189 * -->R_DDOC text 190 *----------------------------------------------------------------------* 191 FORM top_of_page USING r_ddoc TYPE REF TO cl_dd_document. 192 DATA: text TYPE sdydo_text_element. 193 CALL METHOD r_ddoc->initialize_document. 194 CALL METHOD r_ddoc->add_text"控制输出字体为粗体 195 EXPORTING 196 text = '行状态图标含义' 197 sap_emphasis = 'STRONG'. 198 199 DEFINE write_inf. 200 call method r_ddoc->new_line."换行 201 call method r_ddoc->add_icon"输出图标 202 exporting 203 sap_icon = &1. 204 call method r_ddoc->add_text"输出文本 205 exporting 206 text = &2. 207 END-OF-DEFINITION. 208 209 write_inf 'ICON_GREEN_LIGHT' ':价格过高'."表头输出的图标及类型 210 write_inf 'ICON_RED_LIGHT' ':实惠'. 211 ENDFORM. "top_of_page