其他分享
首页 > 其他分享> > ZTESTW_102

ZTESTW_102

作者:互联网

*&---------------------------------------------------------------------*
*&  Include           ZTESTW_102_TOP
*&---------------------------------------------------------------------*

TYPES:BEGIN OF ty_out,
        aufnr   TYPE afpo-aufnr,
        arbpl   TYPE crhd-arbpl,
        ktext   TYPE crtx-ktext,
        dgltp   TYPE afpo-dgltp,
        matnr   TYPE afpo-matnr,
        maktx   TYPE makt-maktx,
        psmng   TYPE afpo-psmng,
        wemng   TYPE afpo-wemng,
        matnr_s TYPE resb-matnr,
        maktx_s TYPE makt-maktx,
        bdmng   TYPE resb-bdmng,
        enmng   TYPE resb-enmng,
        labst   TYPE mard-labst,
        lgort   TYPE resb-lgort,
      END OF ty_out.
CLASS lcl_alv_event_receiver DEFINITION DEFERRED.
DATA:BEGIN OF gs_sel,
       dgltp TYPE afpo-dgltp,
       werks TYPE mseg-werks,
     END OF gs_sel.
DATA:
  gt_alv_field_cat     TYPE lvc_t_fcat,          "field for General ALV
  gt_toolbar_excluding TYPE ui_functions,        "Alv excluding toolbars
  gs_toolbar_excluding TYPE ui_func,             "WA of git_toolbar_excluding
  gs_alv_field_cat     TYPE lvc_s_fcat,          "WA of gt_alv_field_cat
  gs_layout            TYPE lvc_s_layo,          "Layout for alv
  gs_variant           TYPE disvariant,          "Layout (External Use)
  go_grid              TYPE REF TO cl_gui_alv_grid.
DATA: gc_event_receiver TYPE REF TO lcl_alv_event_receiver."Event handle for ooalv
DATA:gs_toolbar TYPE stb_button."alv button

*Set alv field
DEFINE set_alv_fieldcat.
  gs_alv_field_cat-fieldname = &1.
  gs_alv_field_cat-coltext   = &2.
  gs_alv_field_cat-rollname  = &3.
  gs_alv_field_cat-lzero     = space.
  gs_alv_field_cat-no_zero   = 'X'.
  APPEND gs_alv_field_cat TO gt_alv_field_cat.
  CLEAR gs_alv_field_cat.
END-OF-DEFINITION.
*&---------------------------------------------------------------------*
*&  Include           ZTESTW_102_CLS
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&  Include           ZTEST_001_C01
*&---------------------------------------------------------------------*
CLASS lcl_alv_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS:
      constructor IMPORTING i_flag TYPE i,
      handle_menu_button FOR EVENT menu_button OF cl_gui_alv_grid
        IMPORTING e_object e_ucomm,

      handle_toolbar
                    FOR EVENT toolbar OF cl_gui_alv_grid
        IMPORTING e_object e_interactive,
      handle_user_command
                    FOR EVENT after_user_command OF cl_gui_alv_grid
        IMPORTING e_ucomm e_saved e_not_processed,
      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,
      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_data_changed_finished FOR EVENT data_changed_finished OF cl_gui_alv_grid
        IMPORTING e_modified et_good_cells.


*      handle_top_of_page FOR EVENT top_of_page OF cl_gui_alv_grid IMPORTING e_dyndoc_id.
*  PRIVATE SECTION.
    DATA:lp_alv_flag TYPE i VALUE 1."Multiple ALV Will Use This Flag。
ENDCLASS.                    "LCL_ALV_EVENT_RECEIVER DEFINITION



*----------------------------------------------------------------------*
*       CLASS lcl_ALV_envent_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_alv_event_receiver IMPLEMENTATION.
  METHOD  constructor.
    lp_alv_flag = i_flag.
  ENDMETHOD.                    "constructor

  METHOD handle_menu_button.

  ENDMETHOD.                    "handle_menu_button
  METHOD handle_toolbar.
*    PERFORM frm_handle_toolbar USING e_object e_interactive.
  ENDMETHOD.                    "HANDLE_TOOLBAR_101

  METHOD handle_user_command.
*    PERFORM frm_handle_command USING e_ucomm e_saved e_not_processed.
  ENDMETHOD.                    "AFTER_USER_COMMAND

  METHOD handle_hotspot_click.

  ENDMETHOD.                    "HOTSPOT_CLICK

  METHOD handle_data_changed.

  ENDMETHOD.                    "data_changed

  METHOD    handle_data_changed_finished.

  ENDMETHOD.                    "handle_data_changed_finished


  METHOD handle_double_click.

  ENDMETHOD.                    "data_changed

ENDCLASS. "gc_event_receiver IMPLEMENTATION
*&---------------------------------------------------------------------*
*&  Include           ZTESTW_102_SEL
*&---------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: s_dgltp FOR gs_sel-dgltp OBLIGATORY.
PARAMETERS: p_werks TYPE werks_d OBLIGATORY.
SELECTION-SCREEN END OF BLOCK bk1.
*&---------------------------------------------------------------------*
*&  Include           ZTESTW_102_FRM
*&---------------------------------------------------------------------*

FORM frm_get_data.
  SELECT a~aufnr,
    a~dgltp,
    a~matnr,
    a~psmng,
    a~wemng,
    b~plnnr
    INTO TABLE @DATA(lt_afpo)
    FROM afpo AS a
    INNER JOIN afko AS b ON a~aufnr = b~aufnr
    WHERE a~dgltp IN @s_dgltp
    AND a~dwerk =  @p_werks
    AND a~posnr = 1.

  IF lt_afpo IS NOT INITIAL.
    SELECT
      plnnr,
      arbid
      INTO TABLE @DATA(lt_afvc)
      FROM afvc
      FOR ALL ENTRIES IN @lt_afpo
      WHERE plnnr = @lt_afpo-plnnr.

    IF lt_afvc IS NOT INITIAL .
      SELECT objid,
             arbpl
        INTO TABLE @DATA(lt_crhd)
        FROM crhd
        FOR ALL ENTRIES IN @lt_afvc
        WHERE objid = @lt_afvc-arbid.

      SELECT objid,
        ktext
        INTO TABLE @DATA(lt_crtx)
        FROM crtx
        FOR ALL ENTRIES IN @lt_afvc
        WHERE objid = @lt_afvc-arbid.
    ENDIF.

    SELECT matnr,
           maktx
      INTO TABLE @DATA(lt_makt)
      FROM makt
      FOR ALL ENTRIES IN @lt_afpo
      WHERE matnr = @lt_afpo-matnr.


    SELECT aufnr,
           matnr,
           bdmng,
           enmng,
           lgort
*           menge
      INTO TABLE @DATA(lt_resb)
      FROM resb
      FOR ALL ENTRIES IN @lt_afpo
      WHERE aufnr = @lt_afpo-aufnr.

    IF lt_resb IS NOT INITIAL.
      SELECT matnr,
             maktx
        INTO TABLE @DATA(lt_makt1)
        FROM makt
        FOR ALL ENTRIES IN @lt_resb
        WHERE matnr = @lt_resb-matnr.
    ENDIF.
  ENDIF.
ENDFORM.


FORM frm_handle_toolbar USING i_object TYPE REF TO cl_alv_event_toolbar_set i_interactive TYPE char01.
  CLEAR: gs_toolbar.
  gs_toolbar-butn_type = 3.
  APPEND gs_toolbar TO i_object->mt_toolbar.

  CLEAR: gs_toolbar.
  gs_toolbar-function = 'DISP'.
  gs_toolbar-icon = icon_display.
  gs_toolbar-quickinfo = '显示'.
  gs_toolbar-butn_type = 0.
  gs_toolbar-disabled = ''.
  gs_toolbar-text = '显示'.
  APPEND gs_toolbar TO i_object->mt_toolbar.

  CLEAR: gs_toolbar.
  gs_toolbar-butn_type = 3.
  APPEND gs_toolbar TO i_object->mt_toolbar.

  CLEAR: gs_toolbar.
  gs_toolbar-function = 'EDIT'.
  gs_toolbar-icon = icon_change .
  gs_toolbar-quickinfo = '编辑'.
  gs_toolbar-butn_type = 0.
  gs_toolbar-disabled = ''.
  gs_toolbar-text = '编辑'.
  APPEND gs_toolbar TO i_object->mt_toolbar.
  CLEAR: gs_toolbar. gs_toolbar-butn_type = 3.
ENDFORM.

FORM frm_handle_command USING i_ucomm TYPE sy-ucomm
                               i_saved TYPE char01
                       i_not_processed TYPE char01.
  CASE i_ucomm.
    WHEN 'DISP'.

    WHEN 'EDIT'.

    WHEN 'READ'.

    WHEN OTHERS.
  ENDCASE.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  frm_create_alv_grid
*&---------------------------------------------------------------------*
*       text create alv grid
*----------------------------------------------------------------------*
*      -->T_OUTTAB             text  data to show
*      -->I_GUI_CUS_CONTAINER  text gui container
*      -->I_ALV_CONTROL        text alv object
*      -->I_IT_FIELD           text alv field
*      -->I_FLAG               text derector when there is more than on alv
*----------------------------------------------------------------------*
FORM frm_create_alv_grid TABLES t_outtab TYPE STANDARD TABLE
                         USING
                                 i_alv_control       TYPE REF TO cl_gui_alv_grid
                                 i_it_field          TYPE  lvc_t_fcat
                                 i_flag              TYPE i.
  DATA:lwa_stable    TYPE lvc_s_stbl.

  CLEAR: gs_variant,gc_event_receiver.
  gs_variant-report = sy-repid.
  IF i_alv_control IS  INITIAL.
    CREATE OBJECT i_alv_control
      EXPORTING
        i_parent = cl_gui_container=>default_screen.


    CREATE OBJECT gc_event_receiver
      EXPORTING
        i_flag = i_flag.

    SET HANDLER gc_event_receiver->handle_toolbar       FOR i_alv_control.
    SET HANDLER gc_event_receiver->handle_menu_button   FOR i_alv_control.
    SET HANDLER gc_event_receiver->handle_user_command  FOR i_alv_control.
    SET HANDLER gc_event_receiver->handle_hotspot_click FOR i_alv_control.
    SET HANDLER gc_event_receiver->handle_double_click  FOR i_alv_control.
    SET HANDLER gc_event_receiver->handle_data_changed  FOR i_alv_control.
    SET HANDLER gc_event_receiver->handle_data_changed_finished  FOR i_alv_control.
*    SET HANDLER gc_event_receiver->handle_top_of_page   FOR i_alv_control.


    CALL METHOD i_alv_control->register_edit_event
      EXPORTING
        i_event_id = cl_gui_alv_grid=>mc_evt_modified
      EXCEPTIONS
        error      = 1
        OTHERS     = 2.

    CALL METHOD i_alv_control->register_edit_event
      EXPORTING
        i_event_id = cl_gui_alv_grid=>mc_evt_enter
      EXCEPTIONS
        error      = 1
        OTHERS     = 2.


    CALL METHOD i_alv_control->set_table_for_first_display
      EXPORTING
        i_buffer_active               = 'X'
        i_bypassing_buffer            = 'X'
        i_save                        = 'A'
        i_default                     = space
        is_layout                     = gs_layout
        is_variant                    = gs_variant
        it_toolbar_excluding          = gt_toolbar_excluding
      CHANGING
        it_outtab                     = t_outtab[]
        it_fieldcatalog               = i_it_field
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        OTHERS                        = 4.


  ELSE.
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'RELOAD'.

    CLEAR lwa_stable.
    lwa_stable-col = abap_true.
    CALL METHOD i_alv_control->refresh_table_display
      EXPORTING
        is_stable = lwa_stable.
*        i_soft_refresh = gco_true.
    CALL METHOD cl_gui_cfw=>flush.
  ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  refresh_alv
*&---------------------------------------------------------------------*
*       text refresh alv list
*----------------------------------------------------------------------*
*      -->I_ALV_CONTROL  text alv object
*      -->P_ROW          text row of alv grid
*----------------------------------------------------------------------*
FORM refresh_alv USING i_alv_control TYPE REF TO cl_gui_alv_grid
                                                 p_row.

  DATA: ls_stable TYPE lvc_s_stbl.
  IF NOT i_alv_control IS INITIAL.
    ls_stable-row = 'X'.
    ls_stable-col = 'X'.
    CALL METHOD i_alv_control->refresh_table_display
      EXPORTING
        is_stable = ls_stable.
*        i_soft_refresh = 'X'.
    CALL METHOD cl_gui_cfw=>flush.
  ENDIF.
ENDFORM.                    "refresh_alv

FORM frm_set_layout.
  gs_layout-sel_mode = 'D'.
ENDFORM.
*&---------------------------------------------------------------------*
*&  Include           ZTESTW_102_PBO
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  INIT_100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE init_100 OUTPUT.
*  PERFORM frm_set_field.
*  PERFORM frm_set_layout.
*
*  PERFORM frm_create_alv_grid  TABLES gt_out
*                               USING  go_grid
*                                      gt_alv_field_cat
*                                       1.
ENDMODULE.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS_100'.
*  SET TITLEBAR 'xxx'.
ENDMODULE.
*&---------------------------------------------------------------------*
*&  Include           ZTESTW_102_PAI
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Module  EXIT  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE exit INPUT.
  LEAVE TO SCREEN 0.
ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

ENDMODULE.

 

标签:gs,&---------------------------------------------------------------------,al
来源: https://www.cnblogs.com/JackeyLove/p/14432473.html