添加页眉Top of page和页脚End of Page
作者:互联网
本文介绍如何在SALV中添加页眉(Top of page)和页脚(End of page)。
页眉和页脚可以通过类cl_salv_form_layout_grid ,cl_salv_form_label,cl_salv_form_layout_flow创建,具体方法如下:
1,创建cl_salv_form_layout_grid ,cl_salv_form_label,cl_salv_form_layout_flow 的类引用
2,用到的方法
create_label :指定label的位置,行和列
create_flow :指定flow的位置,行和列
set_text :设定label中的文本
create_text :设定flow中的文本
set_end_of_list :显示页脚设置
set_end_of_list_print :打印页脚设置
set_top_of_list :显示页眉设置
set_top_of_list_print :打印页眉设置
在SALV教程1-创建简单SALV中的代码基础上添加两个方法set_top_of_page, set_end_of_page
UML图如下:
完整代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | *&---------------------------------------------------------------------* *& 一个简单的通过类CL_SALV_TABLE生成SALV的例子 *&---------------------------------------------------------------------* REPORT z_salv_3. * *----------------------------------------------------------------------* * CLASS lcl_report DEFINITION *----------------------------------------------------------------------* CLASS lcl_report DEFINITION. * PUBLIC SECTION. * * 定义SALV输出内表 TYPES: BEGIN OF ty_vbak, vbeln TYPE vbak-vbeln, erdat TYPE erdat, auart TYPE auart, kunnr TYPE kunnr, END OF ty_vbak. * DATA: t_vbak TYPE STANDARD TABLE OF ty_vbak. * * ALV reference DATA: o_alv TYPE REF TO cl_salv_table. * METHODS: * 抽取数据 get_data, * * 生成输出内容 generate_output. * *$*$*.....CODE_ADD_1 - Begin..................................1..*$*$* * * 定义private method来设定SALV不同特性 PRIVATE SECTION. METHODS: set_pf_status CHANGING co_alv TYPE REF TO cl_salv_table. * 设置 Top of page METHODS: set_top_of_page CHANGING co_alv TYPE REF TO cl_salv_table. * * 设置 End of page METHODS: set_end_of_page CHANGING co_alv TYPE REF TO cl_salv_table. *$*$*.....CODE_ADD_1 - End....................................1..*$*$* ENDCLASS. "lcl_report DEFINITION *----------------------------------------------------------------------* * CLASS lcl_report IMPLEMENTATION *----------------------------------------------------------------------* * 类实现 CLASS lcl_report IMPLEMENTATION. * METHOD get_data. * 抽取数据 SELECT vbeln erdat auart kunnr INTO TABLE t_vbak FROM vbak UP TO 20 ROWS. * ENDMETHOD. "get_data *....................................................................... METHOD generate_output. * New ALV instance * We are calling the static Factory method which will give back * the ALV object reference. * * exception class DATA: lx_msg TYPE REF TO cx_salv_msg. TRY. cl_salv_table=>factory( IMPORTING r_salv_table = o_alv CHANGING t_table = t_vbak ). CATCH cx_salv_msg INTO lx_msg. ENDTRY. * *$*$*.....CODE_ADD_2 - Begin..................................2..*$*$* * * In this area we will call the methods which will set the * different properties to the ALV * 调用status设置方法 CALL METHOD set_pf_status CHANGING co_alv = o_alv. * 调用 top of page 方法 CALL METHOD me->set_top_of_page CHANGING co_alv = o_alv. * * 调用 End of Page 方法 CALL METHOD me->set_end_of_page CHANGING co_alv = o_alv. *$*$*.....CODE_ADD_2 - End....................................2..*$*$* * * * 调用Display方法将数据输出到屏幕上 o_alv->display( ). * ENDMETHOD. "generate_output * *$*$*.....CODE_ADD_3 - Begin..................................3..*$*$* * * In this area we will implement the methods which are defined in * the class definition * status设置方法实现 METHOD set_pf_status. DATA: lo_functions TYPE REF TO cl_salv_functions_list. * 设置默认的标准状态栏 lo_functions = co_alv->get_functions( ). lo_functions->set_default( abap_true ). ENDMETHOD. METHOD set_top_of_page. * DATA: lo_header TYPE REF TO cl_salv_form_layout_grid, lo_h_label TYPE REF TO cl_salv_form_label, lo_h_flow TYPE REF TO cl_salv_form_layout_flow. * * header object CREATE OBJECT lo_header. * * 通过Row 和 column字段定位在top of page的文本输出位置 * * 粗体 lo_h_label = lo_header->create_label( row = 1 column = 1 ). lo_h_label->set_text( 'Header in Bold' ). * * information in tabular format lo_h_flow = lo_header->create_flow( row = 2 column = 1 ). lo_h_flow->create_text( text = 'This is text of flow' ). * lo_h_flow = lo_header->create_flow( row = 3 column = 1 ). lo_h_flow->create_text( text = 'Number of Records in the output' ). * lo_h_flow = lo_header->create_flow( row = 3 column = 2 ). lo_h_flow->create_text( text = '20' ). * * 页眉显示 co_alv->set_top_of_list( lo_header ). * * 页眉打印 co_alv->set_top_of_list_print( lo_header ). ENDMETHOD. "set_top_of_page * METHOD set_end_of_page. * DATA: lo_footer TYPE REF TO cl_salv_form_layout_grid, lo_f_label TYPE REF TO cl_salv_form_label, lo_f_flow TYPE REF TO cl_salv_form_layout_flow. * 通过Row 和 column字段定位在end of page的文本输出位置 * footer object CREATE OBJECT lo_footer. * * 粗体 lo_f_label = lo_footer->create_label( row = 1 column = 1 ). lo_f_label->set_text( 'Footer .. here it goes' ). * * tabular information lo_f_flow = lo_footer->create_flow( row = 2 column = 1 ). lo_f_flow->create_text( text = 'This is text of flow in footer' ). * lo_f_flow = lo_footer->create_flow( row = 3 column = 1 ). lo_f_flow->create_text( text = 'Footer number' ). * lo_f_flow = lo_footer->create_flow( row = 3 column = 2 ). lo_f_flow->create_text( text = 1 ). * * 页脚显示 co_alv->set_end_of_list( lo_footer ). * * 页脚打印 co_alv->set_end_of_list_print( lo_footer ). * ENDMETHOD. "set_end_of_page *$*$*.....CODE_ADD_3 - End....................................3..*$*$* * ENDCLASS. "lcl_report IMPLEMENTATION START-OF-SELECTION. DATA: lo_report TYPE REF TO lcl_report. CREATE OBJECT lo_report. * 抽取数据 lo_report->get_data( ). * 生成SALV lo_report->generate_output( ). |
运行结果如下:
以上。
标签:set,End,页脚,lo,cl,flow,页眉,text,salv 来源: https://www.cnblogs.com/lvdong18847870057/p/12548638.html