OO实现ALV TABLE 十:ALV的页眉页脚
除了可以通過類CL_SALV_EVENTS_TABLE的事件設置ALV的頁眉頁腳之外,還可以通過類CL_SALV_TABLE的方法SET_TOP_OF_LIST,SET_TOP_OF_LIST_PRINT,
SET_END_OF_LIST,SET_END_OF_LIST_PRINT這四個方法。頁眉頁腳的顯示可以設置顯示和打印時不一樣,打印時的頁眉頁腳通過方法SET_TOP_OF_LIST_PRINT和SET_END_OF_LIST_PRINT。
1.?????? 聲明設置頁眉頁腳所需要的Layout的實例和變量。
DATA: lr_grid??????TYPE REF TO cl_salv_form_layout_grid,
??????lr_grid2????? TYPE REF TOcl_salv_form_layout_grid,
?????? lr_text?????? TYPE REF TO cl_salv_form_text,
??????lr_action???? TYPE REF TOcl_salv_form_action_info,
?????? lr_header???? TYPE REF TO cl_salv_form_header_info,
?? lr_label????? TYPE REF TO cl_salv_form_label.
2.??????添加頁眉頁腳所需要的文本到Layout里。
??lr_header =lr_grid->create_header_information(
????? row = 1
????? column = 1
????? text = 'Header Information'
??? ).
??? lr_label = lr_grid->create_label(
????? row = 2
????? column = 1
????? text = 'Label'
??? ).
??? lr_action =lr_grid->create_action_information(
????? row = 3
????? column = 1
????? text = 'Action Information'
??? ).
??? lr_text = lr_grid->create_text(
????? text = 'text'
????? row = 4
????? column = 1
??? ).
??? gr_table->set_top_of_list( lr_grid ).
??? lr_text = lr_grid2->create_text(
????? text = 'end of page'
????? row = 1
????? column = 1
??? ).
3.?????? 使用方法SET_TOP_OF_LIST設置頁眉
gr_table->set_top_of_list( lr_grid ).
下面是效果圖
?
下面是程序的所有代碼:
REPORT? y_xin_002.
?
*變量定義
TYPES: BEGIN OF gs_spfli,
??????? mandt?????? TYPE spfli-mandt,
??????? carrid????? TYPE spfli-carrid,
??????? connid????? TYPE spfli-connid,
??? ????countryfr??TYPE spfli-countryfr,
??????? cityfrom??? TYPE spfli-cityfrom,
??????? airpfrom??? TYPE spfli-airpfrom,
??????? countryto?? TYPE spfli-countryto,
??????? cityto????? TYPE spfli-cityto,
??????? airpto????? TYPE spfli-airpto,
??????? fltime?????TYPE spfli-fltime,
??????? deptime???? TYPE spfli-deptime,
??????? arrtime???? TYPE spfli-arrtime,
??????? distance??? TYPE spfli-distance,
??????? distid????? TYPE spfli-distid,
??????? fltype????? TYPE spfli-fltype,
??????? period????? TYPE spfli-period,
END OF gs_spfli.
TYPES? ty_spfli TYPE gs_spfli OCCURS 0.
?
*----------------------------------------------------------------------*
*?????? CLASS lcl_alv DEFINITION
*----------------------------------------------------------------------*
*?????? ALV操作類(定義)
*----------------------------------------------------------------------*
CLASS lcl_alv DEFINITION.
? PUBLIC SECTION.
??? METHODS: getdata?????????????? "取得要顯示的數據
?????????????? RETURNING value(lt_tab) TYPEty_spfli,
???????????? alv_full????????????? "全屏Grid列表處理方法
?????????????? IMPORTING value(lt_tab) TYPEty_spfli.
? PRIVATE SECTION.
??? DATA: gr_table TYPE REF TO cl_salv_table.
ENDCLASS.??????????????????? "lcl_alv DEFINITION
?
*----------------------------------------------------------------------*
*?????? CLASS lcl_alv IMPLEMENTATION
*----------------------------------------------------------------------*
*?????? ALV操作類(實現)
*----------------------------------------------------------------------*
CLASS lcl_alvIMPLEMENTATION.
*取得要顯示的數據
? METHOD getdata.
??? SELECT * INTO CORRESPONDING FIELDS OF TABLElt_tab FROM spfli.
? ENDMETHOD.??????????????????? "getdata
?
*輸出全屏網格列表的方法
? METHOD alv_full.
??? DATA: lr_functions? TYPE REF TO cl_salv_functions_list,
????????? lr_grid?????? TYPE REF TOcl_salv_form_layout_grid,
????????? lr_grid2????? TYPE REF TO cl_salv_form_layout_grid,
????????? lr_text?????? TYPE REF TO cl_salv_form_text,
????????? lr_action???? TYPE REF TO cl_salv_form_action_info,
????????? lr_header???? TYPE REF TO cl_salv_form_header_info,
??? ??????lr_label????? TYPE REF TO cl_salv_form_label.
?
??? "創建實例
??? TRY.
??????? cl_salv_table=>factory(
????????? IMPORTING
??????????? r_salv_table = gr_table
????????? CHANGING
??????????? t_table????? = lt_tab
??????? ).
????? CATCH cx_salv_msg.
??? ENDTRY.
??? "ALV標準功能
??? lr_functions = gr_table->get_functions().
??? lr_functions->set_all( 'X' ).
??? "頁眉頁腳
??? CREATE OBJECT: lr_grid,lr_grid2.
??? lr_header =lr_grid->create_header_information(
????? row = 1
????? column = 1
????? text = 'Header Information'
??? ).
??? lr_label = lr_grid->create_label(
????? row = 2
????? column = 1
????? text = 'Label'
??? ).
??? lr_action =lr_grid->create_action_information(
????? row = 3
????? column = 1
????? text = 'Action Information'
??? ).
??? lr_text = lr_grid->create_text(
????? text = 'text'
????? row = 4
????? column = 1
??? ).
??? gr_table->set_top_of_list( lr_grid ).
??? lr_text = lr_grid2->create_text(
????? text = 'end of page'
????? row = 1
????? column = 1
??? ).
??? gr_table->set_end_of_list( lr_grid2 ).
??? "顯示列表
??? gr_table->display( ).
? ENDMETHOD.??????????????????? "alv_full
ENDCLASS.??????????????????? "lcl_alvIMPLEMENTATION
?
*&---------------------------------------------------------------------*
*&????? Form?f_main
*&---------------------------------------------------------------------*
*?????? 整合數據,執行
*----------------------------------------------------------------------*
FORM f_main.
? DATA: lt_tab TYPE ty_spfli,
??????? lr_alv TYPE REF TO lcl_alv.
?
? CREATE OBJECT lr_alv.
?
? "取得要顯示的數據
? lt_tab = lr_alv->getdata( ).
?
? lr_alv->alv_full( lt_tab ).
ENDFORM.??????????????????? "f_main
?
*執行動作
START-OF-SELECTION.
? PERFORM f_main.總結
以上是生活随笔為你收集整理的OO实现ALV TABLE 十:ALV的页眉页脚的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OO实现ALV TABLE 十一:ALV
- 下一篇: OO实现ALV TABLE 九:ALV的