一个ALV(OO)的实例
個人感覺還是OO的方法較簡單容易理解。這個實例,包含了grid形式全屏顯示, list顯示 和 grid在容器里顯示的三種情況。
實例需要定義一個screen 0100 ,包含一個名為?‘CONTAINER’的容器。第一種情況下實現(xiàn)了頁眉頁腳的顯示,對列標題修改,選定行 列以及單元格。
Report??YY_ALV_TEST .
*變量定義
TYPES?ty_spfli?TYPE?spfli?OCCURS?0.
DATA:?gr_table?TYPE?REF?TO?cl_salv_table,
??????gr_funct?TYPE?REF?TO?cl_salv_functions,
??????gr_columns?type?ref?to?cl_salv_columns_table,
??????gr_column?type?ref?to?CL_SALV_COLUMN_table.
*選擇屏幕設計
SELECTION-SCREEN?BEGIN?OF?BLOCK?blk?WITH?FRAME.
PARAMETERS:?p_full?RADIOBUTTON?GROUP?gp,
????????????p_list?RADIOBUTTON?GROUP?gp,
????????????p_grid?RADIOBUTTON?GROUP?gp.
SELECTION-SCREEN?END?OF?BLOCK?blk.
*----------------------------------------------------------------------*
*???????CLASS?lcl_alv?DEFINITION
*----------------------------------------------------------------------*
*???????ALV操作類(定義)
*----------------------------------------------------------------------*
CLASS?lcl_alv?DEFINITION.
??PUBLIC?SECTION.
????METHODS:?getdata?????????"取得要顯示的數(shù)據(jù)
???????????????RETURNING?value(lt_tab)?TYPE?ty_spfli,
?????????????alv_full????????"全屏Grid列表處理方法
???????????????IMPORTING?value(lt_tab)?TYPE?ty_spfli,
?????????????alv_list????????"普通List處理方法
???????????????IMPORTING?value(lt_tab)?TYPE?ty_spfli,
?????????????alv_grid????????"在自定義屏幕上顯示的列表
???????????????IMPORTING?value(lt_tab)?TYPE?ty_spfli,
?????????????main.???????????"主方法
ENDCLASS.????????????????????"lcl_alv?DEFINITION
*----------------------------------------------------------------------*
*???????CLASS?lcl_alv?IMPLEMENTATION
*----------------------------------------------------------------------*
*???????ALV操作類(實現(xiàn))
*----------------------------------------------------------------------*
CLASS?lcl_alv?IMPLEMENTATION.
*取得要顯示的數(shù)據(jù)
??METHOD?getdata.
????SELECT?*?INTO?TABLE?lt_tab?FROM?spfli.
??ENDMETHOD.????????????????????"getdata
*輸出全屏網(wǎng)格列表的方法
??METHOD?alv_full.
????DATA:?lr_selections?TYPE?REF?TO?cl_salv_selections,
??????????lt_column?????TYPE?salv_t_column,
??????????lt_row????????TYPE?salv_t_row,
??????????lt_cell???????TYPE?salv_t_cell,
??????????ls_cell???????TYPE?salv_s_cell.
???DATA:??lr_grid???????TYPE?REF?TO?cl_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.
????"創(chuàng)建實例
????TRY.
????????cl_salv_table=>factory(
??????????IMPORTING
????????????r_salv_table?=?gr_table
??????????CHANGING
????????????t_table??????=?lt_tab
????????).
??????CATCH?cx_salv_msg.
????ENDTRY.
????"顯示列表
??gr_funct?=?gr_table->get_functions(?)."<<?此行和下一行用來顯示標題的功能按鈕
??gr_funct->set_all(?Abap_True?).???????">>
??gr_columns?=?gr_table->get_columns(?).
??gr_columns->set_optimize(?'X'?).
??gr_column??=?gr_columns->Get_Column(?'PERIOD'?).?"<<此行和下一行來隱藏'PERIOD'欄位
??gr_column->SET_VISIBLE(?abap_false?).????????????">>
??gr_column??=?gr_columns->Get_Column(?'DISTANCE'?).?"<<此行和下一行設置列標題顯示名
??gr_column->SET_LONG_TEXT('飛行距離'?).????????????">>
????"取得類CL_SALV_SELECTIONS的實例
????lr_selections?=?gr_table->get_selections(?).
????"設置選擇模式
????lr_selections->set_selection_mode(?if_salv_c_selection_mode=>row_column?).
????"選擇列
????APPEND?'FLTIME'?TO?lt_column.
????APPEND?'DISTANCE'?TO?lt_column.
????lr_selections->set_selected_columns(?lt_column?).
????"選擇行
????APPEND?3?TO?lt_row.
????APPEND?4?TO?lt_row.
?? lr_selections->set_selected_rows(?lt_row?).
????"選擇一個單元格
????ls_cell-row?=?7.
????ls_cell-columnname?=?'CITYFROM'.
????lr_selections->set_current_cell(?ls_cell?).
"頁眉頁腳
????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->set_screen_popup(
"??????start_column?=?1
"??????end_column???=?120
"??????start_line???=?1
"??????end_line?????=?20?).
??gr_table->display(?).
??ENDMETHOD.????????????????????"alv_ful
*輸出全屏普通列表的方法
??METHOD?alv_list.
?????DATA:??lr_display???TYPE?REF?TO?cl_salv_display_settings.
????"創(chuàng)建實例
????TRY.
????????cl_salv_table=>factory(
??????????EXPORTING
????????????list_display?=?'X'
??????????IMPORTING
????????????r_salv_table?=?gr_table
??????????CHANGING
????????????t_table??????=?lt_tab
????????).
??????CATCH?cx_salv_msg.
????ENDTRY.
????"顯示列表
????gr_funct?=?gr_table->get_functions(?).
????gr_funct->set_all(?'X'?).
????gr_columns?=?gr_table->get_columns(?).
????gr_columns->set_optimize(?'X'?).
????"設置ALV的顯示樣式
????lr_display?=?gr_table->get_display_settings(?).
????lr_display->set_striped_pattern(?'X'?).?"設置顏色間隔顯示
????lr_display->set_list_header(?'Elliott''s?ALV?Test'?).?"設置ALV的抬頭
????lr_display->set_horizontal_lines(?''?).??"設置水平線是否顯示
????lr_display->set_vertical_lines(?''?).????"設置垂直線是否顯示
????gr_table->display(?).
??ENDMETHOD.????????????????????"alv_list
*輸出在自定義屏幕上的列表
??METHOD?alv_grid.
????CALL?SCREEN?'0100'.
??ENDMETHOD.????????????????????"alv_grid
*主方法,整合數(shù)據(jù)
??METHOD?main.
????DATA:?lt_tab?TYPE?TABLE?OF?spfli.
????"取得要顯示的數(shù)據(jù)
????lt_tab?=?me->getdata(?).
????"判斷選擇屏幕的選擇條件調用不同的方法
????CASE?'X'.
??????WHEN?p_full.
????????me->alv_full(?lt_tab?).
??????WHEN?p_list.
????????me->alv_list(?lt_tab?).
??????WHEN?p_grid.
????????me->alv_grid(?lt_tab?).
????ENDCASE.
??ENDMETHOD.????????????????????"main
ENDCLASS.????????????????????"lcl_alv?IMPLEMENTATION
*----------------------------------------------------------------------*
*??MODULE?status_0100
*----------------------------------------------------------------------*
*??PBO?屏幕輸出前執(zhí)行
*----------------------------------------------------------------------*
MODULE?status_0100?OUTPUT.
??"定義變量
??DATA:?lr_container?TYPE?REF?TO?cl_gui_custom_container,
????????lr_alv2???????TYPE?REF?TO?lcl_alv,
????????lt_tab???????TYPE?TABLE?OF?spfli.
??"創(chuàng)建容器實例
??IF?cl_salv_table=>is_offline(?)?=?''.
????CREATE?OBJECT?lr_container
???????EXPORTING
?????????container_name?=?'CONTAINER'.
??ENDIF.
??"創(chuàng)建類LCL_ALV實例
??CREATE?OBJECT?lr_alv2.
??"取得列表數(shù)據(jù)
??lt_tab?=?lr_alv2->getdata(?).
??"創(chuàng)建ALV實例
??TRY.
??????cl_salv_table=>factory(
????????EXPORTING
??????????r_container????=?lr_container
??????????container_name?=?'CONTAINER'
????????IMPORTING
??????????r_salv_table???=?gr_table
????????CHANGING
??????????t_table????????=?lt_tab
??????).
????CATCH?cx_salv_msg.
??ENDTRY.
??"顯示ALV列表
??gr_funct?=?gr_table->get_functions(?).
??gr_funct->set_all(?Abap_True?).
??gr_columns?=?gr_table->get_columns(?).
??gr_columns->set_optimize(?'X'?).
??gr_table->display(?).
??"釋放內存
??FREE?lt_tab.
ENDMODULE.????????????????????"status_0100
*----------------------------------------------------------------------*
*??MODULE?user_command_0100
*----------------------------------------------------------------------*
*??PAI?屏幕輸出后的動作
*----------------------------------------------------------------------*
MODULE?user_command_0100?INPUT.
ENDMODULE.????????????????????"user_command_0100
*報表執(zhí)行
START-OF-SELECTION.
??DATA??lr_alv???TYPE?REF?TO?lcl_alv.
??CREATE?OBJECT?lr_alv.
??lr_alv->main(?).
總結
以上是生活随笔為你收集整理的一个ALV(OO)的实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Eclipse导出可执行JAR文件的方法
- 下一篇: HD 2955 Robberies(0-