• 00 alv抬头等


    *&---------------------------------------------------------------------*
    *& Report  ZHJ_TEST06
    *&
    *&---------------------------------------------------------------------*
    *&
    *&
    *&---------------------------------------------------------------------*
    
    REPORT zhj_test06.
    *变量定义==============================================================
    DATA:BEGIN OF it_itab OCCURS 0.
    DATA : light(4) TYPE c.
            INCLUDE STRUCTURE makt."sflight.
    DATA:    text(4) TYPE c.
    DATA:END OF it_itab.
    
    "定义一个容器类
    DATA: wcl_container TYPE REF TO cl_gui_custom_container,
    
    "定义alv--grid对象
          wcl_alv       TYPE REF TO cl_gui_alv_grid ,
          gt_fieldcat   TYPE        lvc_t_fcat,
    
    "这个表存放标题栏不显示的图标功能码
          ex_fcode      TYPE        ui_functions,
    "layout
          gs_layout     TYPE        lvc_s_layo.
    
    
    
    DATA : container_head TYPE REF TO cl_gui_custom_container ,
     cl_viewer TYPE REF TO cl_gui_html_viewer ,
     cl_doc TYPE REF TO cl_dd_document .
    DATA : l_abck TYPE sdydo_key VALUE space .
    DATA : msg TYPE sdydo_text_element .
    
    
    
    
    
    
    
    
    
    
    
    
    *----------------------------------------------------------------------*
    *       class lcl_event_receiver definition
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS lcl_event_receiver DEFINITION.
    
      PUBLIC SECTION.
        METHODS:
    *--在alv的工具条上增加新的按钮
          handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
                             IMPORTING e_object
                                       e_interactive,
    *--实现用户命令
          handle_user_command
            FOR EVENT user_command OF cl_gui_alv_grid
              IMPORTING e_ucomm,
    
    *--热点点击控制
        handle_hotspot_click
          FOR EVENT hotspot_click OF cl_gui_alv_grid
          IMPORTING e_row_id e_column_id es_row_no,
    
    *--用户双击事件
        handle_double_click
          FOR EVENT double_click OF cl_gui_alv_grid
          IMPORTING e_row e_column es_row_no,
    
    *--覆盖标准的功能.
        handle_before_user_command
          FOR EVENT before_user_command OF cl_gui_alv_grid
          IMPORTING e_ucomm,
    
    *--覆盖标准的功能.
        handle_data_changed
          FOR EVENT data_changed OF cl_gui_alv_grid
          IMPORTING er_data_changed
                    e_onf4 e_onf4_before
                    e_onf4_after
                    e_ucomm,
    ********页眉
        handle_top_page
            FOR EVENT top_of_page OF cl_gui_alv_grid
            IMPORTING e_dyndoc_id
                  table_index .
    *        IMPORTing .
    ENDCLASS.                    "lcl_event_receiver DEFINITION
    
    START-OF-SELECTION.
      PERFORM get_data."向内表写数据
      PERFORM set_fieldcat."设置FIELDCAT
      PERFORM set_layout."设置layout
      PERFORM set_ex_fcode."设置隐藏工具栏按钮
      CALL SCREEN 100."需要在屏幕里画一个container
    
    *&---------------------------------------------------------------------*
    *&      form  get_data
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM get_data .
    
      REFRESH it_itab.CLEAR it_itab.
      SELECT *
        INTO CORRESPONDING FIELDS OF TABLE it_itab
        UP TO 50 ROWS
        FROM makt.
      IF sy-subrc NE 0.
    *    MESSAGE e000 WITH '没有数据选择!'.
      ENDIF.
    
    ENDFORM.                    " GET_DATA
    
    *&---------------------------------------------------------------------*
    *&      form  set_fieldcat
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM set_fieldcat .
    
    *  这个函数只能读取标准结构体的fieldcat
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
    *     i_buffer_active        =
          i_structure_name       = 'MAKT'
          i_client_never_display = 'X'
    *     i_bypassing_buffer     =
    *     i_internal_tabname     =
        CHANGING
          ct_fieldcat            = gt_fieldcat
        EXCEPTIONS
          inconsistent_interface = 1
          program_error          = 2
          OTHERS                 = 3.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    
      DATA gs_fieldcat LIKE LINE OF gt_fieldcat.
      gs_fieldcat-fieldname = 'LIGHT'.
      gs_fieldcat-scrtext_l = '标志'.
    *  gs_fieldcat-CHECKBOX  = 'X'.
      INSERT gs_fieldcat INTO gt_fieldcat INDEX 1.
    
      CLEAR gs_fieldcat.
      gs_fieldcat-col_pos   = 15.
      gs_fieldcat-fieldname = 'TEXT'.
      gs_fieldcat-scrtext_l = '文本'.
      gs_fieldcat-edit      = 'X'.
      APPEND gs_fieldcat TO gt_fieldcat.
    
    ENDFORM.                    " SET_FIELDCAT
    *&---------------------------------------------------------------------*
    *&      form  output_display
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM output_display .
      CALL METHOD wcl_alv->set_table_for_first_display
        EXPORTING
          i_save                        = 'A'
          is_layout                     = gs_layout
          it_toolbar_excluding          = ex_fcode
        CHANGING
          it_outtab                     = it_itab[]
          it_fieldcatalog               = gt_fieldcat
        EXCEPTIONS
          invalid_parameter_combination = 1
          program_error                 = 2
          too_many_lines                = 3
          OTHERS                        = 4.
    
      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 cl_doc .
    
      CALL METHOD wcl_alv->list_processing_events
        EXPORTING
          i_event_name = 'TOP_OF_PAGE'
          i_dyndoc_id  = cl_doc.
    ENDFORM.                    " OUTPUT_DISPLAY
    *&---------------------------------------------------------------------*
    *&      module  status_0100  output
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'GUI_STATUS'.
    *  set titlebar 'xxx'.
      IF wcl_alv IS INITIAL.
    
        CREATE OBJECT: wcl_container
          EXPORTING
            container_name = 'ALV_CON'.
    
        CREATE OBJECT container_head
          EXPORTING
            container_name = 'HON_CONT'.
    
        CREATE OBJECT wcl_alv
          EXPORTING
            i_parent = wcl_container.
    
    
    
    *   create and set event
        DATA event_receiver TYPE REF TO lcl_event_receiver.
        CREATE OBJECT event_receiver.
        SET HANDLER event_receiver->handle_toolbar FOR wcl_alv.
        SET HANDLER event_receiver->handle_top_page FOR wcl_alv .
        SET HANDLER event_receiver->handle_user_command FOR wcl_alv.
        SET HANDLER event_receiver->handle_hotspot_click FOR wcl_alv.
        SET HANDLER event_receiver->handle_double_click FOR wcl_alv.
        SET HANDLER event_receiver->handle_before_user_command FOR wcl_alv.
        SET HANDLER event_receiver->handle_data_changed FOR wcl_alv.
    
        PERFORM output_display.
    
    *   set interaction
        CALL METHOD wcl_alv->set_toolbar_interactive.
    *   注册更新时间
        CALL METHOD wcl_alv->register_edit_event
          EXPORTING
            i_event_id = wcl_alv->mc_evt_enter.
    
    
      ENDIF.
    
    
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *&      module  user_command_0100  input
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE user_command_0100 INPUT.
    
      CASE sy-ucomm.
        WHEN '&F03' OR '&F12'.
          LEAVE TO SCREEN 0.
        WHEN '&F15'.
          LEAVE PROGRAM.
        WHEN 'SAVE'.
          DATA lt_selected_rows TYPE lvc_t_roid.
          CALL METHOD wcl_alv->get_selected_rows
            IMPORTING
              et_row_no = lt_selected_rows.
    *      MESSAGE i003 WITH 'USER_COMMAND_0100 event'.
        WHEN OTHERS.
      ENDCASE.
    
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *&      form  set_layout
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM set_layout .
    
      gs_layout-zebra     = 'X'."条纹格式输出
    *  gs_layout-edit      = 'X'."可编辑状态
      gs_layout-smalltitle  = 'X'."小标题
    *  gs_layout-no_hgridln ='X'."隐藏水平网格线
    *  gs_layout-no_vgridln = 'X'."隐藏垂直网格线
    *  gs_layout-no_headers = 'X'."隐藏列抬头
    *  gs_layout-no_merging  = 'X'."禁用单元格合并
      gs_layout-cwidth_opt  = 'X'."优化列宽度
    *  gs_layout-no_f4       = 'X'."没有F4按键功能
    *  gs_layout-no_rowmark     = 'X'."禁用行选择
    *  gs_layout-no_toolbar    = 'X'."隐藏工具栏
      gs_layout-grid_title    = 'ALV实例'."标题栏
    *  gs_layout-sgl_clk_hd      = 'X'."单击列标题按升序排列
    *  gs_layout-no_totline     = 'X'."不要输出总计行
      gs_layout-keyhot      = 'X'."关键列作为热
    *  gs_layout-info_fname  = 'TEXT'."带有简单行彩色代码的字段名称
    *  gs_layout-ctab_fname  = 'TEXT'."带有复杂单元格颜色编码的字段名称
    
      gs_layout-sel_mode  = 'C'.
    *  gs_layout-box_fname  = 'CHX'.
    
      DATA:l_fielfcat TYPE LINE OF lvc_t_fcat.
      LOOP AT gt_fieldcat INTO l_fielfcat.
        CASE l_fielfcat-fieldname.
          WHEN 'MATNR'.
    *        fcat_100-ref_table  = 'T001W'.
    *        fcat_100-ref_field  = 'WERKS'.
    *        fcat_100-outputlen  = '10'.
            l_fielfcat-edit  = 'X'.
          WHEN OTHERS.
    *      WHEN 'HSDAT' OR 'ERSDA' OR 'VFDAT'.
    *        fcat_100-outputlen  = '10'.
    *        FCAT_100-NO_ZERO    = 'X'.
        ENDCASE.
        MODIFY gt_fieldcat FROM l_fielfcat.
        CLEAR  l_fielfcat.
      ENDLOOP.
    
    
    ENDFORM.                    " SET_LAYOUT
    *&---------------------------------------------------------------------*
    *&      form  set_ex_fcode
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM set_ex_fcode .
      REFRESH ex_fcode.CLEAR ex_fcode.
      DATA:ls_fcode     TYPE ui_func.
    
      ls_fcode = cl_gui_alv_grid=>mc_fc_info.
      APPEND ls_fcode TO ex_fcode.
      ls_fcode = cl_gui_alv_grid=>mc_fc_loc_append_row.
      APPEND ls_fcode TO ex_fcode.
      ls_fcode = cl_gui_alv_grid=>mc_fc_loc_insert_row.
      APPEND ls_fcode TO ex_fcode.
      ls_fcode = cl_gui_alv_grid=>mc_fc_loc_delete_row.
      APPEND ls_fcode TO ex_fcode.
      ls_fcode = cl_gui_alv_grid=>mc_fc_loc_copy_row.
      APPEND ls_fcode TO ex_fcode.
      ls_fcode = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
      APPEND ls_fcode TO ex_fcode.
    
    ENDFORM.                    " SET_EX_FCODE
    *&---------------------------------------------------------------------*
    *&       class (implementation)  lcl_event_receiver
    *&---------------------------------------------------------------------*
    *        text
    *----------------------------------------------------------------------*
    CLASS lcl_event_receiver IMPLEMENTATION.
    
    *-- handle toolbar
      METHOD handle_toolbar.
        PERFORM handle_toolbar USING e_object e_interactive.
      ENDMETHOD.                    "handle_toolbar
    
    *-- handdle user_command
      METHOD handle_user_command.
        PERFORM handle_user_commmand CHANGING e_ucomm.
      ENDMETHOD.                   "Handle user command
    
    *-- 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
    
    *--handle_double_click
      METHOD handle_double_click.
        PERFORM handle_double_click USING e_row e_column es_row_no.
      ENDMETHOD.                  "HANDLE_DOUBLE_CLICK
    
    *--before_user_command
      METHOD handle_before_user_command.
        PERFORM handle_before_user_command USING e_ucomm.
      ENDMETHOD.                "BEFORE_USER_COMMAND
    
    *--before_user_command
      METHOD handle_data_changed.
        PERFORM handle_data_changed USING er_data_changed.
      ENDMETHOD.                "BEFORE_USER_COMMAND
    
    *--before_user_command
      METHOD handle_top_page.
    *  CREATE OBJECT CL_DOC .
        CALL METHOD cl_doc->initialize_document .
    
        CALL METHOD cl_doc->add_text
          EXPORTING
            text      = 'qwertyuioplkjhgfdsa'
            sap_style = 'HEADING'.
    
        IF msg IS NOT INITIAL .
          CALL METHOD cl_doc->new_line .
          CALL METHOD cl_doc->add_text
            EXPORTING
              text         = msg
              sap_emphasis = ''.
          CLEAR msg .
        ENDIF.
        IF cl_viewer IS INITIAL .
          CREATE OBJECT cl_viewer
            EXPORTING
              parent = container_head.
        ENDIF.
    
        CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
          EXPORTING
            document       = cl_doc
            bottom         = l_abck
    *     IMPORTING
    *       LENGTH         =
                  .
    
        CALL METHOD cl_doc->merge_document .
        CALL METHOD cl_doc->set_document_background
          EXPORTING
            picture_id = space.
    
        cl_doc->html_control = cl_viewer .
    
        CALL METHOD cl_doc->display_document
          EXPORTING
            reuse_control = 'X'
            parent        = container_head.
    
    *ENDFORM.                    " FRM_TOP_OF_PAGE
    
      ENDMETHOD.                "BEFORE_USER_COMMAND
    
    ENDCLASS.               "LCL_EVENT_RECEIVER
    *&---------------------------------------------------------------------*
    *&      form  handle_toolbar
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->p_e_object  text
    *      -->p_e_interactive  text
    *----------------------------------------------------------------------*
    FORM handle_toolbar USING p_e_object
                                    TYPE REF TO cl_alv_event_toolbar_set
                              p_e_interactive.
    
      DATA: utoolbar TYPE stb_button.
      CLEAR utoolbar.
      utoolbar-function = 'TEST'.
      utoolbar-butn_type = 0.
      utoolbar-icon  = icon_color.
      utoolbar-quickinfo = 'TEST BUTTON'.
      APPEND utoolbar TO p_e_object->mt_toolbar.
      CLEAR utoolbar.
    
    ENDFORM.                    " HANDLE_TOOLBAR
    *&---------------------------------------------------------------------*
    *&      form  handle_user_commmand
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM handle_user_commmand CHANGING e_ucomm.
      CASE e_ucomm.
        WHEN 'SHOW'.
          MESSAGE 'handle user command event' TYPE 'S'.
        WHEN 'TEST'.
          MESSAGE '你点击了color按钮' TYPE 'I'.
        WHEN 'BACK'.
          LEAVE TO SCREEN 0.
        WHEN OTHERS.
          MESSAGE 'OTHERS'  TYPE 'I'.
      ENDCASE.
    ENDFORM.                    " HANDLE_USER_COMMMAND
    *&---------------------------------------------------------------------*
    *&      form  handle_hotspot_click
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->p_e_row_id  text
    *      -->p_e_column_id  text
    *      -->p_es_row_no  text
    *----------------------------------------------------------------------*
    FORM handle_hotspot_click  USING    p_e_row_id
                                        p_e_column_id
                                        p_es_row_no.
    
      DATA:l_s TYPE string.
      CONCATENATE '你点击了' p_e_row_id p_e_column_id INTO l_s.
      MESSAGE l_s  TYPE 'I'. "p_e_row_id p_e_column_id .
    
    ENDFORM.                    " HANDLE_HOTSPOT_CLICK
    *&---------------------------------------------------------------------*
    *&      form  handle_double_click
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->p_e_row_id  text
    *      -->p_e_column_id  text
    *      -->p_es_row_no  text
    *----------------------------------------------------------------------*
    FORM handle_double_click  USING    p_e_row_id
                                       p_e_column_id
                                       p_es_row_no.
    
      MESSAGE '双击事件'  TYPE 'I'.
    
    ENDFORM.                    " HANDLE_DOUBLE_CLICK
    *&---------------------------------------------------------------------*
    *&      form  handle_before_user_command
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->p_e_ucomm  text
    *----------------------------------------------------------------------*
    FORM handle_before_user_command  USING    p_e_ucomm.
      DATA:l_s TYPE string.
      CONCATENATE '按钮的功能码为' p_e_ucomm INTO l_s.
      MESSAGE  l_s  TYPE 'I'.
    
    ENDFORM.                    " HANDLE_BEFORE_USER_COMMAND
    
    *&---------------------------------------------------------------------*
    *&      Form  HANDLE_DATA_CHANGED_FINISHED
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_E_UCOMM  text
    *----------------------------------------------------------------------*
    FORM handle_data_changed USING p_er_data_changed
                                   TYPE REF TO cl_alv_changed_data_protocol.
    
    * 如果更新的reason字段长度小于10为则提示用户填入字符数不能低于10
      DATA: mod_data    TYPE lvc_t_modi,
            wa_mod_data TYPE lvc_s_modi.
    
      mod_data = p_er_data_changed->mt_mod_cells.
      LOOP AT mod_data INTO wa_mod_data WHERE fieldname = 'TEXT'.
        IF strlen( wa_mod_data-value ) < 2.
          CALL METHOD p_er_data_changed->add_protocol_entry
            EXPORTING
              i_msgid     = '00'
              i_msgty     = 'E'
              i_msgno     = '001'
              i_msgv1     = '长度必须大于2 '
              i_fieldname = wa_mod_data-fieldname.
    
    *     如果长度小于2,则将字段内容更新为长都无法确定
          CLEAR wa_mod_data-value.
          CALL METHOD p_er_data_changed->modify_cell
            EXPORTING
              i_row_id    = wa_mod_data-row_id
              i_fieldname = wa_mod_data-fieldname
              i_value     = wa_mod_data-value.
        ENDIF.
      ENDLOOP.
    
    ENDFORM.                    " HANDLE_DATA_CHANGED_FINISHED
  • 相关阅读:
    Objective-C系列总结之基础知识
    OC自动释放池autoreleasepool介绍
    OC导入框架方式#import、@import的区别
    OC源文件扩展名
    安装好MySQL后就开始学习如何后台创建自己的数据库吧!
    如何修改Eclipse中的快捷键
    安装MySQL的详细步骤
    Eclipse运行错误:Failed to load the JNI shared library的解决办法
    导航栏返回带的数据
    flutter Container
  • 原文地址:https://www.cnblogs.com/huangjianisgood/p/3232026.html
Copyright © 2020-2023  润新知