Java教程

ABAP-OOAVL 模板程序

本文主要是介绍ABAP-OOAVL 模板程序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

REPORT ytest_zj001.

*&---------------------------------------------------------------------*
*& Report YTEST_ZJ001
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
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.
  PERFORM get_data.

END-OF-SELECTION.
  CALL SCREEN 100.

INCLUDE ytest_zj001_c01

*&---------------------------------------------------------------------*
*& 包含               YTEST_ZJ001_C01
*&---------------------------------------------------------------------*

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

CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
ENDCLASS.

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

INCLUDE ytest_zj001_top.

*&---------------------------------------------------------------------*
*& 包含               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.

*&---------------------------------------------------------------------*
*&宏
*&---------------------------------------------------------------------*
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.

*&---------------------------------------------------------------------*
*& 包含               YTEST_ZJ001_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM get_data .
  SELECT *
  FROM sflight
  INTO TABLE gt_data
  WHERE carrid = p_carrid.
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'.
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.
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
    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->refresh_table_display
    EXPORTING
      is_stable = ls_stable
    EXCEPTIONS
      finished  = 1
      OTHERS    = 2.
ENDFORM.

INCLUDE ytest_zj001_o01.

*&---------------------------------------------------------------------*
*& 包含               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.

*&---------------------------------------------------------------------*
*& 包含               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 'CANCLE'.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE.

 

这篇关于ABAP-OOAVL 模板程序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!