ABAP-OOAVL 模板程序

REPORT ytest_zj001.

*&---------------------------------------------------------------------*
*&INCLUDE
*&---------------------------------------------------------------------*
INCLUDE ytest_zj001_c01.
INCLUDE ytest_zj001_top.
INCLUDE ytest_zj001_s01.
INCLUDE ytest_zj001_f01.
INCLUDE ytest_zj001_o01.
INCLUDE ytest_zj001_i01.
*&---------------------------------------------------------------------*
*&START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  PERFORM frm_get_data.
*&---------------------------------------------------------------------*
*&END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.
  CALL SCREEN 100.

INCLUDE ytest_zj001_c01

*&---------------------------------------------------------------------*
*&事件类定义
*&---------------------------------------------------------------------*

CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
ENDCLASS.

*&---------------------------------------------------------------------*
*&事件类实现
*&---------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
ENDCLASS.

INCLUDE ytest_zj001_top.

TABLES:sflight.
*&---------------------------------------------------------------------*
*&全局表
*&---------------------------------------------------------------------*
DATA:gt_data TYPE TABLE OF sflight.

*&---------------------------------------------------------------------*
*&全局变量
*&---------------------------------------------------------------------*
DATA:gv_ok_code TYPE sy-ucomm,
     ok_code    TYPE sy-ucomm,
     gv_col     TYPE i.
*&---------------------------------------------------------------------*
*&ALV全局变量
*&---------------------------------------------------------------------*
DATA:go_grid      TYPE REF TO cl_gui_alv_grid,
     go_docking   TYPE REF TO cl_gui_docking_container,
     gs_layout    TYPE lvc_s_layo,
     gt_fieldcat  TYPE lvc_t_fcat,
     gs_fieldcat  TYPE lvc_s_fcat,
     gt_exclude   TYPE ui_functions.
DATA:gs_variant TYPE disvariant.
*&---------------------------------------------------------------------* *&宏 *&---------------------------------------------------------------------* DEFINE fieldcat_add. CLEAR gs_fieldcat. gv_col = gv_col + 1. gs_fieldcat-col_pos = gv_col. "列的显示位置 gs_fieldcat-fieldname = &1. "表字段 gs_fieldcat-reptext = &2. "列标题 gs_fieldcat-outputlen = &3. "输出长度 gs_fieldcat-no_zero = &4. "为输出隐藏零 gs_fieldcat-decimals = &5. "小数位数 gs_fieldcat-just = &6. "输出格式(L:靠左,C:居中,R:靠右) gs_fieldcat-hotspot = &7. "是否单点 gs_fieldcat-ref_table = &8. "参考表 gs_fieldcat-ref_field = &9. "参考字段 * gs_fieldcat-convexit = &10. "转换例程 * gs_fieldcat-edit = &11. "这一列设为可编辑状态 APPEND gs_fieldcat TO gt_fieldcat. END-OF-DEFINITION.

INCLUDE ytest_zj001_s01.

SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE TEXT-001.
  PARAMETERS:p_carrid TYPE sflight-carrid.
SELECTION-SCREEN END OF BLOCK blk1.

INCLUDE ytest_zj001_f01.

*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_data .

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_build_fcat
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_build_fcat .
  CLEAR:gv_col,gs_fieldcat,gt_fieldcat.
  gv_col = 1.
  fieldcat_add: 'CARRID' '航线代码' '5' '' '' 'L' '' '' '',
                'CONNID' '航班连接编号' '8' '' '' 'L' '' '' '',
                'FLDATE' '航班日期' '10' '' '' 'C' '' '' '',
                'PRICE' '航空运费' '10' '' '' 'R' '' 'SFLIGHT' 'PRICE' ,
                'CURRENCY' '货币' '5' '' '' 'C' '' 'SFLIGHT' 'CURRENCY'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_set_layout
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_set_layout .
  CLEAR: gs_layout.
  gs_layout-zebra = 'X'.
  gs_layout-cwidth_opt = 'X'.
  gs_layout-sel_mode = 'A'.

  CLEAR:gs_variant.
  gs_variant-report = sy-repid.
ENDFORM. *&---------------------------------------------------------------------* *& Form exclude_tb_functions *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> GT_EXCLUDE *& --> PERFORM *& --> DISP_ALV *&---------------------------------------------------------------------* FORM exclude_tb_functions TABLES 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_sort_asc. * APPEND ls_exclude TO pt_exclude. * ls_exclude = cl_gui_alv_grid=>mc_fc_sort_dsc . * APPEND ls_exclude TO pt_exclude. * ls_exclude = cl_gui_alv_grid=>mc_fc_find . * APPEND ls_exclude TO pt_exclude. * ls_exclude = cl_gui_alv_grid=>mc_fc_filter . * 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_print_prev . * APPEND ls_exclude TO pt_exclude. * ls_exclude = cl_gui_alv_grid=>mc_mb_export . * APPEND ls_exclude TO pt_exclude. * ls_exclude = cl_gui_alv_grid=>mc_fc_graph . * APPEND ls_exclude TO pt_exclude. * ls_exclude = cl_gui_alv_grid=>mc_mb_view . * APPEND ls_exclude TO pt_exclude. * ls_exclude = cl_gui_alv_grid=>mc_fc_detail . * APPEND ls_exclude TO pt_exclude. * ls_exclude = cl_gui_alv_grid=>mc_fc_help . * APPEND ls_exclude TO pt_exclude. * ls_exclude = cl_gui_alv_grid=>mc_fc_info . * APPEND ls_exclude TO pt_exclude. * ls_exclude = cl_gui_alv_grid=>mc_mb_variant. * APPEND ls_exclude TO pt_exclude. ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row. 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_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_move_row. 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. ENDFORM. *&---------------------------------------------------------------------* *& Form disp_alv *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM disp_alv . DATA:lo_event TYPE REF TO lcl_event_receiver. FIELD-SYMBOLS: <lfs_tab> TYPE STANDARD TABLE. ASSIGN gt_data TO <lfs_tab>. CHECK <lfs_tab> IS ASSIGNED. CREATE OBJECT go_docking EXPORTING repid = sy-repid dynnr = sy-dynnr side = cl_gui_docking_container=>dock_at_bottom "dock_at_top extension = 500 EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5 OTHERS = 6. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. CREATE OBJECT go_grid EXPORTING i_parent = go_docking EXCEPTIONS error_cntl_create = 1 error_cntl_init = 2 error_cntl_link = 3 error_dp_create = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. CALL METHOD go_grid->set_table_for_first_display EXPORTING i_save = 'A' is_layout = gs_layout it_toolbar_excluding = gt_exclude
      is_variant                    = gs_variant
CHANGING it_outtab = <lfs_tab> it_fieldcatalog = gt_fieldcat EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. CREATE OBJECT lo_event. * SET HANDLER cl_event_receiver=>handle_hotspot_click * "alv_event_receiver=>handle_double_click * FOR ALL INSTANCES. ENDFORM. FORM frm_refresh_alv USING po_grid TYPE REF TO cl_gui_alv_grid. DATA:ls_stable TYPE lvc_s_stbl. ls_stable-row = 'X'." 基于行的稳定刷新 ls_stable-col = 'X'." 基于列稳定刷新 "重新设置布局 CALL METHOD po_grid->set_frontend_layout EXPORTING is_layout = gs_layout. CALL METHOD po_grid->refresh_table_display EXPORTING is_stable = ls_stable EXCEPTIONS finished = 1 OTHERS = 2. ENDFORM.

INCLUDE ytest_zj001_o01.

*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS '0100'.
  SET TITLEBAR '0100'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module INIT_ALV OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE init_alv OUTPUT.
  IF go_docking IS NOT BOUND.
    "创建ALV结构
    PERFORM frm_build_fcat.
    "设置ALV输出格式及变式
    PERFORM frm_set_layout.
    PERFORM exclude_tb_functions  TABLES gt_exclude.
    "显示ALV数据
    PERFORM disp_alv.
  ELSE.
    PERFORM frm_refresh_alv USING go_grid.
  ENDIF.
ENDMODULE.

 

INCLUDE ytest_zj001_i01.

*&---------------------------------------------------------------------*
*&      Module  EXIT  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE exit INPUT.
  CLEAR:gv_ok_code.
  gv_ok_code = ok_code.
  CLEAR:ok_code.
  CASE gv_ok_code.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE.

 

posted @ 2022-08-04 09:52  阿胖的阿多  阅读(53)  评论(0编辑  收藏  举报