ABAP 屏幕容器ALV显示
抬头:************************************OO ALV属性声明及定义***************DATA: gcl_alv TYPE REF TO cl_gui_alv_grid.*存放字段目录的内表DATA gt_fieldcat TYPE lvc_t_fcat.*存放字段目录的结构DATA gs_fcat TYPE lv
抬头:
************************************OO ALV属性声明及定义***************
DATA: gcl_alv TYPE REF TO cl_gui_alv_grid.
*存放字段目录的内表
DATA gt_fieldcat TYPE lvc_t_fcat.
*存放字段目录的结构
DATA gs_fcat TYPE lvc_s_fcat.
*布局结构
DATA gs_layout TYPE lvc_s_layo.
*超链接
"DATA gt_hyperlink TYPE lvc_t_hype.
*排序表
"DATA gt_sort TYPE lvc_t_sort.
*设置过滤表
"DATA gt_filter TYPE lvc_t_filt.
"排除标准按钮内表
DATA gt_excluding TYPE ui_functions.
DEFINE add_field.
gs_fcat-tabname = &2.
gs_fcat-fieldname = &1.
gs_fcat-coltext = &4.
gs_fcat-outputlen = &3.
if gs_fcat-fieldname = 'MATNR'.
gs_fcat-hotspot = 'X'.
endif.
if gs_fcat-fieldname = 'COMPETITOR_LISTING_PRICE'
or gs_fcat-fieldname = 'COMPETITOR_DEAL_PRICE'.
* gs_fcat-edit = 'X'.
gs_fcat-decimals = 2.
"gs_fcat-ref_table = 'T001'.
"gs_fcat-ref_field = 'WAERS'.
endif.
append gs_fcat to gt_fieldcat.
clear: gs_fcat.
END-OF-DEFINITION.
*类定义
*----------------------------------------------------------------------*
* CLASS LCL_EVENT_HANDLER DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
*热点点击控制
handle_hotspot_click
FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id e_column_id ."es_row_no.
PRIVATE SECTION.
ENDCLASS. "lcl_event_handler DEFINITION
*类实现
CLASS lcl_event_handler IMPLEMENTATION.
*--HANDLE HOTSPOT CLICK
METHOD handle_hotspot_click.
PERFORM handle_hotspot_click USING e_row_id e_column_id." es_row_no.
ENDMETHOD. "HANDLE_HOTSPOT_CLICK
ENDCLASS. "lcl_event_handler IMPLEMENTATION
DATA gr_event_handler TYPE REF TO lcl_event_handler.
FORM:
FORM frm_display_alv .
IF gcl_alv IS INITIAL.
CREATE OBJECT: gcl_container"屏幕容器,下面不用默认屏幕则需要在屏幕画自定义控件
EXPORTING
container_name = 'ALV_COMM'.
CREATE OBJECT gcl_alv"容器实例
EXPORTING
i_parent = gcl_container.
CALL METHOD gcl_alv->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
CALL METHOD gcl_alv->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
*准备获取字段目录,主要针对每个字段
PERFORM frm_prepare_fieldcat." CHANGING gt_fieldcat.
*准备设置布局,整体布局
PERFORM frm_prepare_layout CHANGING gs_layout.
*排除不需要的标准按钮
PERFORM frm_exclude_toolbar CHANGING gt_excluding.
*显示ALV
CALL METHOD gcl_alv->set_table_for_first_display
EXPORTING
* I_BUFFER_ACTIVE = 'X'"静态调用,每次相同字段目录可设为X,可加速显示ALV
* I_CONSISTENCY_CHECK =
* i_structure_name = 'SFLIGHT'"若无字段目录,则必须设置此选项
* is_variant = gs_variant
i_save = 'A'"X全局,U特定,A两者变式,SPACE均不可保存
i_default = 'X'"是否可定义默认布局
is_layout = gs_layout
* IS_PRINT ="打印内表
* IT_SPECIAL_GROUPS ="字段目录设置了SP_GROUP被分组在一起的内表
it_toolbar_excluding = gt_excluding
* it_hyperlink = gt_hyperlink
CHANGING
it_outtab = it_tab_alv[]"显示内表最好和字段目录一样结构
it_fieldcatalog = gt_fieldcat
"it_sort = gt_sort"排序
"it_filter = gt_filter"过滤
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
PERFORM frm_register_events.
ELSE .
*----刷新ALV
CALL METHOD gcl_alv->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
EXCEPTIONS
finished = 1
OTHERS = 2 .
" IF sy-subrc <> 0.
*--异常处理
" ENDIF.
ENDIF .
ENDFORM. " FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*& Form FRM_MODIFY_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
" FRM_MODIFY_ALV
*&---------------------------------------------------------------------*
*& Form FRM_PREPARE_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_FIELDCAT text
*----------------------------------------------------------------------*
FORM frm_prepare_fieldcat ." CHANGING p_gt_fieldcat TYPE lvc_t_fcat.
add_field:
'SPART' 'IT_TAB_ALV' 8 '业务单元',
'MATNR' 'IT_TAB_ALV' 20 '我司商品编码',
'MAKTX' 'IT_TAB_ALV' 25 '我司商品描述',
'CITY_CODE' 'IT_TAB_ALV' 12 '我司城市编码',
'CITY_NAME' 'IT_TAB_ALV' 20 '我司城市名称',
'COMPETITOR_NAME' 'IT_TAB_ALV' 10 '竞争对手名称',
'ZCITY_NAME' 'IT_TAB_ALV' 20 '竞争对手城市名称',
'COMPETITOR_LISTING_PRICE' 'IT_TAB_ALV' 10 '挂牌价价格',
'COMPETITOR_DEAL_PRICE' 'IT_TAB_ALV' 10 '购物车价格',
'AVAILABLE' 'IT_TAB_ALV' 8 '对手是否有货',
'ISBN_NO' 'IT_TAB_ALV' 18 'ISBN编码',
'CATCH_DATE' 'IT_TAB_ALV' 10 '抓取日期',
'CMMDTY_TIME' 'IT_TAB_ALV' 8 '抓取时间',
'BGAUTHOR' 'IT_TAB_ALV' 12 '修改者'.
ENDFORM. " FRM_PREPARE_FIELDCAT
*&---------------------------------------------------------------------*
*& Form FRM_PREPARE_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GS_LAYOUT text
*----------------------------------------------------------------------*
FORM frm_prepare_layout CHANGING ps_layout TYPE lvc_s_layo.
ps_layout-zebra = 'X'.
ENDFORM. " FRM_PREPARE_LAYOUT
*&---------------------------------------------------------------------*
*& Form FRM_REGISTER_EVENTS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_register_events .
*--为事件句柄创建实例
CREATE OBJECT gr_event_handler.
*--注册实例方法到ALV GRID 事件
" SET HANDLER gr_event_handler->handle_double_click FOR gcl_alv.
SET HANDLER gr_event_handler->handle_hotspot_click FOR gcl_alv.
ENDFORM. " FRM_REGISTER_EVENTS
*&---------------------------------------------------------------------*
*& Form FRM_EXCLUDE_TOOLBAR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_EXCLUDING text
*----------------------------------------------------------------------*
FORM frm_exclude_toolbar CHANGING pt_exclude TYPE ui_functions.
DATA ls_exclude TYPE ui_func.
ls_exclude = cl_gui_alv_grid=>mc_fc_maximum.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_minimum .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_subtot .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_sum .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_average .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_sum .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_subtot .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_print .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row .
APPEND ls_exclude TO pt_exclude.
ENDFORM. " FRM_EXCLUDE_TOOLBAR
更多推荐
所有评论(0)