版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、OO ALV常用功能完整簡例(熱鍵單擊,雙擊,幫助,編輯,自定義工具條等)(2013-07-23 14:18:51)轉(zhuǎn)載標(biāo)簽: alvoo熱鍵跳轉(zhuǎn)ooalv分類: ALV OO ALV 常用功能簡介目錄OO ALV 常用功能簡介 一、所用類: 二、效果圖: 單擊 雙擊 F4幫助 編輯某單元格并校驗(yàn) 三、實(shí)現(xiàn)過程: 1、 創(chuàng)建一個屏幕9001,不需要畫任何控件2、 定義數(shù)據(jù): 3、 獲取顯示數(shù)據(jù): 4、 alv 顯示數(shù)據(jù): 一、所用類:cl_gui_alv_gridcl_gui_docking_container二、效果圖:
2、160; 執(zhí)行: 單擊 單擊航線單元格: 雙擊 雙擊連接號碼單元格: F4幫助 航班單元格上F4或點(diǎn)擊 后面的小按鈕 (本功能在設(shè)置字段樣式時實(shí)現(xiàn)DEFINE mac_fieldlog. "設(shè)置參考表和參考字段,為了提供搜索幫助 wa_fieldcatalog-ref_table
3、60; = &4. "參考表 wa_fieldcatalog-ref_field = &5. "參考字段
4、60; 編輯某單元格并校驗(yàn) 修改價格后隨便點(diǎn)擊某個按鈕或者雙擊某個字段,觸發(fā):handle_data_changed 三、實(shí)現(xiàn)過程:1、 創(chuàng)建一個屏幕9001,不需要畫2、 定義數(shù)據(jù):*&-*& ALV 全局變量*&-DATA: g_alv_grid TYPE REF TO cl_gui_alv_grid,"ALV控件
5、0; alv_ctner TYPE REF TO cl_gui_docking_container.DATA: wa_fieldcatalog TYPE lvc_s_fcat, "顯示數(shù)據(jù)列內(nèi)表工作區(qū)域 it_fieldcatalog TY
6、PE lvc_t_fcat. "顯示數(shù)據(jù)列內(nèi)表DATA: g_event TYPE REF TO alv_event_receiver.*&-*& 全局變量*&-DATA: BEGIN OF str_s
7、pfli, checkbox TYPE char1, "復(fù)選框 carrid TYPE
8、; sflight-carrid , "航線承運(yùn)人ID connid TYPE sflight-connid , "航班連接 Id
9、fldate TYPE sflight-fldate , "航班日期 price TYPE sflight-price , "航空運(yùn)費(fèi)
10、0; END OF str_spfli.DATA: g_it_show LIKE TABLE OF str_spfli WITH KEY checkbox carrid. g_wa_show LIKE str_spfli. 3、 獲取顯示數(shù)據(jù): &q
11、uot;獲取數(shù)據(jù) SELECT carrid connid fldate price FROM sflight INTO CORRESPONDING FIELDS&
12、#160;OF TABLE g_it_show.4、 alv 顯示數(shù)據(jù):PROCESS BEFORE OUTPUT. MODULE STATUS_9001. "alv 顯示數(shù)據(jù) MODULE MDL_ALV_SHOW.*&-module MDL_ALV_SHOW output.PERFORM zform_alv_show.endmodule. *
13、&- FORM zform_alv_show . DATA: l_style TYPE i, ls_layout TYPE lvc_s_layo,
14、; is_stable TYPE lvc_s_stbl, l_disvariant TYPE disvariant.* 屏幕初始化 IF alv_ctner IS INITIAL. CREATE OBJECT alv_ctner
15、160; EXPORTING repid = sy-repid dynnr
16、0; = '9001'* side
17、160; = cl_gui_docking_container=>dock_at_right ”ALV貼屏幕右邊,從屏幕右邊開始算寬度 side &
18、#160; = cl_gui_docking_container=>dock_at_left "ALV貼屏幕左邊,從左邊算屏幕寬度, extension
19、0; = 900 "屏幕寬度
20、160; style = cl_gui_control=>ws_child
21、; "可選參數(shù),設(shè)置ALV是否可用手動拖動大小 EXCEPTIONS cntl_error = 1
22、; cntl_system_error = 2 create_error = 3
23、160; lifetime_error = 4 lifetime_dynpro_dynpro_link = 5 OTHERS
24、; = 6. IF sy-subrc <> 0. MESSAGE s001(00) WITH '屏幕初始化失敗'.
25、; LEAVE LIST-PROCESSING. ENDIF.*添加自定義工具條 PERFORM frm_set_alv_toolbar.* CREATE OBJECT g_alv_grid EXPORTING i_pare
26、nt = alv_ctner.*構(gòu)建顯示字段樣式 PERFORM frm_build_fieldcat. "Set/Reset Ready for Input Status CALL METHOD g_alv_grid->set_ready_for_input EXPORTING
27、60; i_ready_for_input = 1.* layout 設(shè)定樣式 CLEAR ls_layout. ls_layout-cwidth_opt = 'X'. "優(yōu)化列寬 CLEAR l_disvarian
28、t. l_disvariant-report = sy-repid. "當(dāng)前程序* event 綁定事件 CREATE OBJECT g_event. "自定義工具條 SET HANDLER g_event->toolbar &
29、#160; FOR g_alv_grid. "數(shù)據(jù)修改事件 SET HANDLER g_event->handle_data_changed FOR g_alv_grid."單擊某一單元格事件 SET HANDLER g_event->handle_cell_click
30、60; FOR g_alv_grid."用戶點(diǎn)擊工具條上按鈕觸發(fā)的事件 SET HANDLER g_event->handle_user_command FOR g_alv_grid."雙擊某一單元格事件 SET HANDLER g_event->handle_double_click FOR g_alv_grid. "以下兩個方法達(dá)到的效果是:光標(biāo)離開
31、正在編輯的單元格時,就觸發(fā)了handle_data_changed "如果注釋掉以下兩個方法,則只有執(zhí)行下一操作時才會觸發(fā)handle_data_changed,比如點(diǎn)保存、刪除 CALL METHOD g_alv_grid->register_edit_event EXPORTING i_event_id = cl_gui_alv
32、_grid=>mc_evt_modified. CALL METHOD g_alv_grid->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_enter.* "顯示內(nèi)表數(shù)據(jù)
33、160; CALL METHOD g_alv_grid->set_table_for_first_display EXPORTING is_layout = ls_layout
34、 is_variant = l_disvariant it_toolbar_excluding = gt_tools CHANGING it_fieldcata
35、log = it_fieldcatalog it_outtab = g_it_show. ELSE. "沖銷設(shè)置tcode 為 RELOAD,防止因?yàn)樵瓉淼膖code影響程序執(zhí)
36、行 CALL METHOD cl_gui_cfw=>set_new_ok_code EXPORTING new_code = 'RELOAD'. "ALV 控制:刷新穩(wěn)定性 按行刷新,可選參數(shù) CLEAR&
37、#160;is_stable. is_stable-col = 'X'. "刷新 CALL METHOD g_alv_grid->refresh_table_display EXPORTING is_stable =
38、 is_stable i_soft_refresh = 'X'. "提交 CALL METHOD cl_gui_cfw=>flush. ENDIF.ENDFORM. &
39、#160; " ZFORM_ALV_SHOW 其中:添加工具條上常用按鈕FORM frm_set_alv_toolbar . REFRESH gt_tools."你也可以刪除標(biāo)準(zhǔn)的功能按鈕 DELETE e_object->mt_toolbar WHERE FUNCTION = '&DETAIL'. DELETE e_object
40、->mt_toolbar WHERE FUNCTION = '&REFRESH'. DELETE e_object->mt_toolbar WHERE FUNCTION = '&LOCAL&UNDO'. DELETE e_object->mt_toolbar WHERE FUNCTION = '&SORT_ASC'. DELETE e_object->mt_toolbar WHERE FUNCTION = '
41、;&SORT_DSC'. DELETE e_object->mt_toolbar WHERE FUNCTION = '&FIND'. DELETE e_object->mt_toolbar WHERE FUNCTION = '&FIND_MORE'. DELETE e_object->mt_toolbar WHERE FUNCTION = '&MB_FILTER'. DELETE e_o
42、bject->mt_toolbar WHERE FUNCTION = '&MB_SUM'. DELETE e_object->mt_toolbar WHERE FUNCTION = '&MB_SUBTOT'. DELETE e_object->mt_toolbar WHERE FUNCTION = '&MB_EXPORT'. DELETE e_object->mt_toolbar WHERE FUNCTION = '
43、;&MB_VARIANT'. DELETE e_object->mt_toolbar WHERE quickinfo = '插入行'. DELETE e_object->mt_toolbar WHERE quickinfo = '刪除行'. DELETE e_object->mt_toolbar WHERE quickinfo = '剪切'. DELETE e_object->mt_toolbar WHE
44、RE quickinfo = '復(fù)制文本'. DELETE e_object->mt_toolbar WHERE quickinfo = '插入總覽'. DELETE e_object->mt_toolbar WHERE quickinfo = '附加行'. DELETE e_object->mt_toolbar WHERE quickinfo = '復(fù)制行'. DELETE e_object->mt_t
45、oolbar WHERE quickinfo = '視圖'. DELETE e_object->mt_toolbar WHERE quickinfo = '顯示圖形'. DELETE e_object->mt_toolbar WHERE quickinfo = '撤銷'. DELETE e_object->mt_toolbar WHERE quickinfo = '明細(xì)'. DELETE e_object-&g
46、t;mt_toolbar WHERE quickinfo = '打印'. DELETE e_object->mt_toolbar WHERE quickinfo = '最終用戶文檔'. APPEND cl_gui_alv_grid=>mc_fc_check TO gt_tools. APPEND cl
47、_gui_alv_grid=>mc_fc_loc_cut TO gt_tools. APPEND cl_gui_alv_grid=>mc_fc_loc_copy TO gt_tools. APPEND cl_gui_alv_grid=>mc_fc_l
48、oc_copy_row TO gt_tools. APPEND cl_gui_alv_grid=>mc_fc_loc_delete_row TO gt_tools. APPEND cl_gui_alv_grid=>mc_fc_loc_insert_row TO gt_tools. APPEND cl
49、_gui_alv_grid=>mc_fc_loc_move_row TO gt_tools. APPEND cl_gui_alv_grid=>mc_fc_loc_paste TO gt_tools. APPEND cl_gui_alv_grid=>mc_fc_loc_paste_new_row TO
50、gt_tools. APPEND cl_gui_alv_grid=>mc_fc_sum TO gt_tools. APPEND cl_gui_alv_grid=>mc_fc_info
51、; TO gt_tools. APPEND cl_gui_alv_grid=>mc_fc_refresh TO gt_tools. APPEND cl_gui_alv_grid=>mc_fc_graph TO&
52、#160;gt_tools. APPEND cl_gui_alv_grid=>mc_fc_loc_append_row TO gt_tools. APPEND cl_gui_alv_grid=>mc_fc_loc_undo TO gt_tools.ENDFORM.
53、160; " FRM_SET_ALV_TOOLBAR 設(shè)置顯示字段和其參考字段DEFINE mac_fieldlog.* g_pos = g_pos + 1.
54、60; "第幾列* wa_fieldcatalog-col_pos = g_pos. "列 wa_fieldcatalog-fieldname
55、60; = &1. "字段名稱* wa_fieldcatalog-coltext = &2. &
56、quot;顯示名稱,跟reptext效果基本相同 wa_fieldcatalog-reptext = &2. wa_fieldcatalog-outputlen = &3. "顯示
57、長度 "設(shè)置參考表和參考字段,為了提供搜索幫助 wa_fieldcatalog-ref_table = &4. "參考表 wa_fieldcatalog-ref_field = &
58、amp;5. "參考字段 "設(shè)置復(fù)選框可編輯 if &1 eq 'CHECKBOX'. wa_fieldcatalog-checkbox = 'X'.
59、wa_fieldcatalog-edit = 'X'. endif. "設(shè)置 價格PRICE字段 可修改 if &1 eq 'PRICE'. wa_fieldcatalog-edit = 'X'. en
60、dif. "設(shè)置 航線承運(yùn)人字段 CARRID 為熱鍵 if &1 eq 'CARRID'. wa_fieldcatalog-hotspot = 'X'. endif. append wa_fieldcatalog to it_fieldcatalog. cl
61、ear wa_fieldcatalog.END-OF-DEFINITION. FORM frm_build_fieldcat .mac_fieldlog 'CHECKBOX' '選擇' '' ' ' ' '
62、.mac_fieldlog 'CARRID' '航線承運(yùn)人' '' 'SFLIGHT' 'CARRID'.mac_fieldlog 'CONNID' '航班數(shù)量' '' 'SFLIG
63、HT' 'CONNID' . mac_fieldlog 'FLDATE' '國家' '' 'SFLIGHT' 'FLDATE '. "最后兩個字段 參考表內(nèi)字段,可以作為幫助
64、;mac_fieldlog 'PRICE' '起飛城市' '' 'SFLIGHT' 'PRICE' .ENDFORM. " FRM_BUILD_FIELDCAT 事件的定義*-* CLASS AL
65、V_EVENT_RECEIVER DEFINITION*-CLASS alv_event_receiver DEFINITION. PUBLIC SECTION. "添加工具條 METHODS toolbar FOR EVENT toolb
66、ar OF cl_gui_alv_grid IMPORTING e_object e_interactive. "子都修改時觸發(fā) MET
67、HODS handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING er_data_changed. "某字段設(shè)置熱鍵后,單擊此單元格時觸發(fā) METHODS
68、0;handle_cell_click FOR EVENT hotspot_click OF cl_gui_alv_grid IMPORTING e_row_id e_column_id
69、; es_row_no. "雙擊時觸發(fā) METHODS handle_double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row
70、60; e_column es_row_no. "按F1時觸發(fā) METHODS handle_onf1 FOR EVENT onf1
71、60; OF cl_gui_alv_grid IMPORTING e_fieldname es_row_no er_event_data.
72、60;"當(dāng)用戶按屏幕上按鈕時觸發(fā) METHODS handle_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm. .ENDCLA
73、SS. "alv_event_receiver DEFINITION*&-*& Class (Implementation) ALV_EVENT_RECEIVER*&-*CLASS alv_event_receiver IMPLEMENTATI
74、ON. METHOD handle_data_changed. DATA: l_it_data TYPE lvc_t_modi, l_wa_data LIKE LINE OF&
75、#160;l_it_data. DATA: l_price_old TYPE string, l_price_new TYPE string, l_msg TYPE strin
76、g. l_it_data = er_data_changed->mt_mod_cells. LOOP AT er_data_changed->mt_mod_cells INTO l_wa_data WHERE fieldname = 'PRICE'. READ TABLE g_
77、it_show INTO g_wa_show INDEX l_wa_data-row_id. IF sy-subrc = 0. l_price_old = g_wa_show-price . l_price_new = l
78、_wa_data-value . IF l_price_old <> l_price_new. CONCATENATE '價格由' l_price_old '改為' l_price_new INTO l_msg.
79、0; MESSAGE l_msg TYPE 'I'. ENDIF. ENDIF. ENDLOOP. ENDMETHOD.
80、 "handle_data_changed METHOD toolbar. DATA: ls_toolbar TYPE stb_button. CLEAR ls_toolbar. MOVE 3
81、 TO ls_toolbar-butn_type. "分隔符 APPEND ls_toolbar TO e_object->mt_toolbar. CLEAR ls_toolbar. MOVE 'SEL_ALL
82、39; TO ls_toolbar-function. "添加兩個按鈕 全選 和 取消全選 MOVE icon_select_all TO ls_toolbar-icon. MOVE '全選'
83、; TO ls_toolbar-quickinfo. MOVE ' ' TO ls_toolbar-disabled. APPEND ls_toolbar TO
84、e_object->mt_toolbar. CLEAR ls_toolbar. MOVE 'CAN_ALL' TO ls_toolbar-function. MOVE icon_deselect_all TO ls_toolbar-icon.
85、0; MOVE '全部取消 ' TO ls_toolbar-quickinfo. MOVE ' ' TO ls_toolbar-di
86、sabled. APPEND ls_toolbar TO e_object->mt_toolbar. CLEAR ls_toolbar. MOVE 0 TO ls_too
87、lbar-butn_type. "按鈕 MOVE 'DELETE' TO ls_toolbar-function. &
88、#160; "功能碼 MOVE 'DELETE' TO ls_toolbar-text. "顯示名稱 MOVE icon_cancel&
89、#160; TO ls_toolbar-icon. "圖標(biāo) MOVE '刪除選中行' TO ls_toolbar-quickinfo.
90、; "鼠標(biāo)停留時的提示信息 MOVE ' ' TO ls_toolbar-disabled. "可
91、用 APPEND ls_toolbar TO e_object->mt_toolbar. ENDMETHOD. "toolbar METHOD handle_cell_click.
92、 "獲取單擊字段 DATA: l_msg TYPE string, l_wa_click LIKE LINE OF g_it_show, l_row
93、0; TYPE string, l_field TYPE string. l_row = es_row_no-row_id.
94、 "選中行 l_field = e_column_id. "選中的字段 READ TABLE g_it_
95、show INTO l_wa_click INDEX es_row_no-row_id. IF sy-subrc = 0. "得到所單擊值 CONCATENATE '您選中第' l_row '行,字段為:' l_field
96、39;,選中值為' l_wa_click-carrid INTO l_msg. MESSAGE l_msg TYPE 'I'. ENDIF. ENDMETHOD.
97、 "handle_cell_click METHOD handle_double_click. "獲取單擊字段 DATA: l_msg TYPE string, l_wa_click LIKE LINE
98、160;OF g_it_show, l_row TYPE string, l_field TYPE string. l_field
99、60; = e_column-fieldname. "選中行 l_row = es_row_no-row_id.
100、; "選中的字段 READ TABLE g_it_show INTO l_wa_click INDEX es_row_no-row_id . IF sy-subrc = 0. "得到所單擊值
101、; CONCATENATE '您選中第' l_row '行,字段為:' l_field ',選中值為:' INTO l_msg. CASE l_field. WHEN 'CONNID'. &
102、#160; CONCATENATE l_msg l_wa_click-connid INTO l_msg. MESSAGE l_msg TYPE 'I'. WHEN 'FLDATE'.
103、; CONCATENATE l_msg l_wa_click-fldate INTO l_msg. MESSAGE l_msg TYPE 'I'. ENDCASE. ENDIF.
104、0; ENDMETHOD. "handle_DOUBLE_CLICK METHOD handle_onf1. ENDMETHOD. &
105、#160; "handle_ONF1*&-&*&
106、160; *& HANDLE_USER_COMMAND &
107、#160; *
108、&-&* METHOD handle_user_command. REFRESH:lt_cols, lt_rows. CALL METHOD g_alv_grid->get_selected_rows IMPORTING et_index_rows
109、 = lt_rows. CALL METHOD g_alv_grid->get_selected_columns IMPORTING et_index_columns = lt_cols. CALL METHOD cl_gui_cfw=>flush.&
110、#160; CASE e_ucomm. WHEN 'SEL_ALL'. LOOP AT g_it_show INTO g_wa_show. g_wa_show-checkbox =
111、60;'X'. MODIFY g_it_show FROM g_wa_show. ENDLOOP. WHEN 'CAN_ALL'. LOOP
112、 AT g_it_show INTO g_wa_show. g_wa_show-checkbox = ' '. MODIFY g_it_show FROM g_wa_show.
113、 ENDLOOP. WHEN 'DELETE'. LOOP AT g_it_show INTO g_wa_show WHERE checkbox IS NOT INITIAL. DELETE TABLE g_it_show FROM g_wa_show. ENDLOOP. WHEN OTHERS.
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 《微波技術(shù)總結(jié)》課件
- 2022年浙江省嘉興市公開招聘警務(wù)輔助人員輔警筆試自考題2卷含答案
- 2023年黑龍江省鶴崗市公開招聘警務(wù)輔助人員輔警筆試自考題2卷含答案
- 2021年黑龍江省齊齊哈爾市公開招聘警務(wù)輔助人員輔警筆試自考題2卷含答案
- 2024年內(nèi)蒙古自治區(qū)烏海市公開招聘警務(wù)輔助人員輔警筆試自考題2卷含答案
- 《夢想學(xué)堂使用手冊》課件
- 經(jīng)典搞笑句子
- 英語請假條的格式
- 遼寧省本溪市(2024年-2025年小學(xué)六年級語文)統(tǒng)編版小升初模擬(上學(xué)期)試卷及答案
- 2025年電池化學(xué)品項(xiàng)目規(guī)劃申請報告模板
- GB 19272-2024室外健身器材的安全通用要求
- 2024版企業(yè)股權(quán)收購并購重組方案合同3篇
- 2024AIGC創(chuàng)新應(yīng)用洞察報告
- 統(tǒng)編版2024-2025學(xué)年三年級上冊語文期末情景試卷(含答案)
- 2024北京通州初三(上)期末數(shù)學(xué)試卷(含答案解析)
- 市場營銷習(xí)題庫(附參考答案)
- 2024年馬拉松比賽項(xiàng)目合作計劃書
- 2024年演出經(jīng)紀(jì)人資格《思想政治與法律基礎(chǔ)》考前必刷必練題庫500題(含真題、必會題)
- 苗圃購銷合同范本
- 《二十四節(jié)氣融入幼兒園教育活動的個案研究》
- 麻醉與舒適醫(yī)療
評論
0/150
提交評論