当前位置:网站首页>Abap:ooalv realizes the function of adding, deleting, modifying and checking

Abap:ooalv realizes the function of adding, deleting, modifying and checking

2022-07-04 06:05:00 SAP. start a solo run

We need to be in ALV Operation in , Such as routine addition, deletion, modification and inspection , It's time to be in OOALV Achieve in :


*&**********************************************************************
*&  Report  The program name   ZSY_QM_061
*&**********************************************************************
*&
*&  author :     
*&  Completion date : ***
*&  describe :    
*&**********************************************************************
*&  Version number   date      author      Modify description 
*&**********************************************************************
*& 
*&**********************************************************************
REPORT zsy_qm_061.
*&---------------------------------------------------------------------*
*& define include
*&---------------------------------------------------------------------*
*INCLUDE zsy_qm_061_top.
*INCLUDE zsy_qm_061_f01.
TABLES:zsy_d_qm61_ppap.
TYPE-POOLS:slis.
DATA:BEGIN OF gt_item OCCURS 0,
       werks     TYPE zsy_d_qm61_ppap-werks,    " factory 
       matnr     TYPE zsy_d_qm61_ppap-matnr,    " Material number 
       maktx     TYPE makt-maktx,             " Material description 
       lifnr     TYPE zsy_d_qm61_ppap-lifnr,    " Account number of supplier or creditor 
       name_org1 TYPE but000-name_org1,    " Supplier description 
       zcjr      TYPE zsy_d_qm61_ppap-zcjr,    " founder 
       zcjrq     TYPE zsy_d_qm61_ppap-zcjrq,    " Date of creation 
       zxgr      TYPE zsy_d_qm61_ppap-zxgr,    " Modifier 
       zxgrq     TYPE zsy_d_qm61_ppap-zxgrq,    " modification date 
       zzt       TYPE zsy_d_qm61_ppap-zzt,    " state 
       dd_handle TYPE char10,
       modify    TYPE lvc_t_styl,
       newid     TYPE i,
       del       TYPE char1,
       update    TYPE char1,
       add       TYPE char1,
     END OF gt_item.
DATA:gs_item LIKE LINE OF gt_item.
DATA:gt_upd LIKE TABLE OF gt_item.
DATA:gt_del LIKE TABLE OF gt_item.
DATA:gs_del LIKE LINE OF gt_del.
DATA: gv_newid   TYPE i.
DATA: ok_code LIKE sy-ucomm.
DATA lt_drop_down TYPE lvc_t_drop.
DATA ls_drop_down TYPE lvc_s_drop.
DATA:
  gt_ddval TYPE lvc_t_drop,
  gw_ddval TYPE lvc_s_drop.
DATA gs_stb TYPE lvc_s_stbl.
DATA:
  wa_fieldcat TYPE lvc_s_fcat, " Used for definition ALV Column field related type data , structure 
  gs_layout   TYPE lvc_s_layo,
  go_alv      TYPE REF TO cl_gui_alv_grid,
  gt_fieldcat TYPE lvc_t_fcat,
  g_toolbar   TYPE ui_functions,
  gs_con      TYPE REF TO cl_gui_custom_container.
DATA: gt_events TYPE slis_t_event,
      gw_events TYPE slis_alv_event.
CONSTANTS c_status_form TYPE slis_formname VALUE 'PF_STATUS_SET'. " Character , Function constant 
CONSTANTS c_command_form TYPE slis_formname VALUE 'USER_COMMAND'. " Character , Function constant 
DATA: grid TYPE REF TO cl_gui_alv_grid.
DATA: g_pos TYPE i." be used for alv The last order of the field directory 
DATA  g_edit TYPE char1.  " Edit state flag.
gs_stb-row = 'X'."  Stable refresh based on rows 
gs_stb-col = 'X'."  Based on column stable refresh 
CLASS gcl_event_handler DEFINITION.
  PUBLIC SECTION.
    METHODS:
      handle_user_command   FOR EVENT user_command OF cl_gui_alv_grid
        IMPORTING
          e_ucomm,

*      handle_data_changed   FOR EVENT data_changed_finished  OF cl_gui_alv_grid
*       IMPORTING
*          er_good_cells,
      handle_data_changed   FOR EVENT data_changed  OF cl_gui_alv_grid
        IMPORTING
          er_data_changed,

      handle_hotspot_click  FOR EVENT hotspot_click OF cl_gui_alv_grid
        IMPORTING
          e_row_id
          e_column_id
          es_row_no.

ENDCLASS.

CLASS gcl_event_handler IMPLEMENTATION.
  METHOD handle_hotspot_click.
*    PERFORM frm_hotspot_click.

  ENDMETHOD.

  METHOD handle_user_command.


    CASE e_ucomm.
      WHEN 'EDIT'.
        PERFORM frm_edit.
      WHEN 'ADD'.
        PERFORM frm_add.
      WHEN 'DEL'.
        PERFORM frm_del.
      WHEN 'SAVE'.
        PERFORM frm_save.
    ENDCASE.

  ENDMETHOD.                    "handle_user_command


  METHOD handle_data_changed.

    PERFORM frm_data_changed
      USING
        er_data_changed->mt_mod_cells.

*    PERFORM frm_data_changed
*      USING
*        et_good_cells.


  ENDMETHOD.


ENDCLASS.

DATA:
  go_event_receiver TYPE REF TO gcl_event_handler.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-s01.
  PARAMETERS: p_werks LIKE zsy_d_qm61_ppap-werks OBLIGATORY.  " factory 

  SELECT-OPTIONS: s_matnr FOR zsy_d_qm61_ppap-matnr,     " materiel 
                  s_lifnr FOR zsy_d_qm61_ppap-lifnr,     " supplier 
                  s_zzt FOR zsy_d_qm61_ppap-zzt.         " state 
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*
* INITIALIZATION
*----------------------------------------------------------------------*
INITIALIZATION.
  PERFORM frm_check_auth.  " Permission check 

*----------------------------------------------------------------------*
* AT SELECTION-SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.


*----------------------------------------------------------------------*
* AT SELECTION-SCREEN OUTPUT
*----------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.

*----------------------------------------------------------------------*
* AT SELECTION-SCREEN ON VALUE-REQUEST
*----------------------------------------------------------------------*
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_xxxx.


*&---------------------------------------------------------------------*
* START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  " get data 
  PERFORM frm_get_data.
*    PERFORM frm_prc_data.
* ALV  Set up 
  PERFORM f_fieldcat_build. " The second step is to set the field directory , That is, the display part of the report header 
  PERFORM frm_sub_get_down.
  PERFORM create_alv.
  PERFORM frm_ooalv_dis.

  CALL  SCREEN 0100.
*&---------------------------------------------------------------------*
* END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.
*    PERFORM frm_display.

*&---------------------------------------------------------------------*
*& Form frm_get_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_data .
  SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_item FROM zsy_d_qm61_ppap
       WHERE werks = p_werks AND matnr IN s_matnr AND lifnr IN s_lifnr AND zzt IN s_zzt.
  LOOP AT gt_item ASSIGNING FIELD-SYMBOL(<fs_item>).
    SELECT SINGLE maktx INTO <fs_item>-maktx FROM makt WHERE spras = '1' AND matnr = <fs_item>-matnr.  " Material description 
    SELECT SINGLE name_org1 INTO <fs_item>-name_org1 FROM but000 WHERE partner = <fs_item>-lifnr.      " Supplier description 
  ENDLOOP.
  gt_upd[] = gt_item[].
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_data_changed
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> ER_DATA_CHANGED_>MT_MOD_CELLS
*&---------------------------------------------------------------------*
FORM frm_data_changed  USING pt_mod_cells TYPE lvc_t_modi.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_edit
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_edit .  " modify 
  IF g_edit = 'X'.
    REFRESH gt_fieldcat.
    PERFORM f_input_fieldcat USING:
*---- Stored here ALV Fields to show  STR--------
      'WERKS' ' factory ' '' '' '' '',
      'MATNR' ' Material code ' '' '' '' '',
      'MAKTX' ' Material description ' '' '' '' '',
      'LIFNR' ' Supplier code ' '' '' '' '',
      'NAME_ORG1' ' Supplier description ' '' '' '' '',
      'ZCJR' ' founder ' '' '' '' '',
      'ZCJRQ' ' Date of creation ' '' '' '' '',
      'ZXGR' ' Modifier ' '' '' '' '',
      'ZXGRQ' ' modification date ' '' '' '' '',
      'ZXGR' ' Modifier ' ''  '' '' '',
      'ZZT' ' state ' ''  '' '' ''.
    CALL METHOD go_alv->set_frontend_fieldcatalog
      EXPORTING
        it_fieldcatalog = gt_fieldcat.

    CALL METHOD go_alv->refresh_table_display.

    g_edit = ''.
  ELSE.
    REFRESH gt_fieldcat.
    PERFORM f_input_fieldcat USING:
*---- Stored here ALV Fields to show  STR--------
   'WERKS' ' factory ' '' '' 'ZSY_D_QM61_PPAP' 'WERKS',
   'MATNR' ' Material code ' '' '' 'ZSY_D_QM61_PPAP' 'MATNR',
   'MAKTX' ' Material description ' '' '' 'MAKT' 'MAKTX',
   'LIFNR' ' Supplier code ' '' '' 'ZSY_D_QM61_PPAP' 'LIFNR',
   'NAME_ORG1' ' Supplier description ' '' '' 'BUT000' 'NAME_ORG1',
   'ZCJR' ' founder ' '' '' 'ZSY_D_QM61_PPAP' 'ZCJR',
   'ZCJRQ' ' Date of creation ' '' '' 'ZSY_D_QM61_PPAP' 'ZCJRQ',
   'ZXGR' ' Modifier ' '' '' 'ZSY_D_QM61_PPAP' 'ZXGR',
   'ZXGRQ' ' modification date ' '' '' 'ZSY_D_QM61_PPAP' 'ZXGRQ',
   'ZZT' ' state ' 'X'  '' 'ZSY_D_QM61_PPAP' 'ZZT'.

    CALL METHOD go_alv->set_frontend_fieldcatalog
      EXPORTING
        it_fieldcatalog = gt_fieldcat.

    CALL METHOD go_alv->refresh_table_display.
    g_edit = 'X'.
  ENDIF.
  CALL METHOD go_alv->refresh_table_display
    EXPORTING
      is_stable = gs_stb.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_add
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_add .  " newly added 
  CLEAR gs_item.
  gv_newid = gv_newid + 1.
  gs_item-newid = gv_newid.
  gs_item-zcjr = sy-uname.
  gs_item-zcjrq = sy-datum.
  gs_item-werks = p_werks.
  gs_item-add = 'X'.
  APPEND gs_item TO gt_item.
  REFRESH gt_fieldcat.
  PERFORM f_input_fieldcat USING:
*---- Stored here ALV Fields to show  STR--------
   'WERKS' ' factory ' '' '' 'ZSY_D_QM61_PPAP' 'WERKS',
   'MATNR' ' Material code ' 'X' '' 'ZSY_D_QM61_PPAP' 'MATNR',
   'MAKTX' ' Material description ' '' '' 'MAKT' 'MAKTX',
   'LIFNR' ' Supplier code ' 'X' '' 'ZSY_D_QM61_PPAP' 'LIFNR',
   'NAME_ORG1' ' Supplier description ' '' '' 'BUT000' 'NAME_ORG1',
   'ZCJR' ' founder ' '' '' 'ZSY_D_QM61_PPAP' 'ZCJR',
   'ZCJRQ' ' Date of creation ' '' '' 'ZSY_D_QM61_PPAP' 'ZCJRQ',
   'ZXGR' ' Modifier ' '' '' 'ZSY_D_QM61_PPAP' 'ZXGR',
   'ZXGRQ' ' modification date ' '' '' 'ZSY_D_QM61_PPAP' 'ZXGRQ',
   'ZZT' ' state ' 'X'  '' 'ZSY_D_QM61_PPAP' 'ZZT'.
  CALL METHOD go_alv->set_frontend_fieldcatalog
    EXPORTING
      it_fieldcatalog = gt_fieldcat.
  CALL METHOD go_alv->refresh_table_display
    EXPORTING
      is_stable = gs_stb.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_del
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_del .  " Delete 
  DATA lt_select TYPE lvc_t_row.
*  DATA ls_del LIKE LINE OF gt_del.

  CALL METHOD go_alv->get_selected_rows
    IMPORTING
      et_index_rows = lt_select.

  LOOP AT lt_select INTO DATA(ls_select).
    READ TABLE gt_item INTO gs_item INDEX ls_select-index.
    IF sy-subrc = 0.
      MOVE-CORRESPONDING gs_item TO gs_del.
      gs_del-del = 'X'.
      APPEND gs_del TO gt_del.
      CLEAR gs_del.
    ENDIF.
    DELETE gt_item INDEX ls_select-index.
  ENDLOOP.
  CALL METHOD go_alv->refresh_table_display
    EXPORTING
      is_stable = gs_stb.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_save
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_save .
  DATA:lt_add LIKE TABLE OF zsy_d_qm61_ppap,
       ls_add LIKE LINE OF lt_add.
  DATA:lt_update LIKE TABLE OF zsy_d_qm61_ppap,
       ls_update LIKE LINE OF lt_update.
  DATA:lt_delete LIKE TABLE OF zsy_d_qm61_ppap,
       ls_delete LIKE LINE OF lt_delete.
  DATA ls_stb TYPE lvc_s_stbl.
  CALL METHOD go_alv->if_cached_prop~set_prop
    EXPORTING
      propname           = 'GridModified'
      propvalue          = '1'
    EXCEPTIONS
      prop_not_found     = 1
      invalid_name       = 2
      error_set_property = 3
      OTHERS             = 4.
  IF sy-subrc <> 0.
*       Implement suitable error handling here
  ENDIF.
  CALL METHOD go_alv->check_changed_data
*        IMPORTING
*          E_VALID   =
*        CHANGING
*          C_REFRESH = 'X'
    .
  " newly added   modify 
  SORT gt_upd BY werks matnr lifnr.
  LOOP AT gt_item ASSIGNING FIELD-SYMBOL(<fs_item>).
    IF <fs_item>-add IS INITIAL.  " Modify the operating 
      READ TABLE gt_upd INTO DATA(gs_upd) WITH KEY werks = <fs_item>-werks matnr = <fs_item>-matnr lifnr = <fs_item>-lifnr BINARY SEARCH.
      IF sy-subrc = 0 AND gs_upd-zzt <> <fs_item>-zzt.
        <fs_item>-zxgr = sy-uname.
        <fs_item>-zxgrq = sy-datum.
      ENDIF.
    ENDIF.
    SELECT SINGLE maktx INTO <fs_item>-maktx FROM makt WHERE spras = '1' AND matnr = <fs_item>-matnr.  " Material description 
    SELECT SINGLE name_org1 INTO <fs_item>-name_org1 FROM but000 WHERE partner = <fs_item>-lifnr.      " Supplier description 
    MOVE-CORRESPONDING <fs_item> TO ls_add.
    APPEND ls_add TO lt_add.
    CLEAR ls_add.
  ENDLOOP.
  " Delete 
  LOOP AT gt_del INTO gs_del.
    IF gs_del-del IS NOT INITIAL.
      MOVE-CORRESPONDING gs_del TO ls_delete.
      APPEND ls_delete TO lt_delete.
    ENDIF.
    CLEAR:ls_delete,gs_del.
  ENDLOOP.
  IF lt_add[] IS NOT INITIAL.
    MODIFY zsy_d_qm61_ppap FROM TABLE lt_add.  " newly added , change 
  ENDIF.
  IF lt_delete[] IS NOT INITIAL.
    DELETE zsy_d_qm61_ppap FROM TABLE lt_delete.  " Delete 
  ENDIF.
*  IF lt_update[] IS NOT INITIAL.
*    MODIFY zsy_d_qm61_ppap FROM TABLE lt_update.  " change 
*  ENDIF.
  COMMIT WORK AND WAIT.
  IF sy-subrc = 0.
    MESSAGE ' Data saved ' TYPE 'S'.
  ELSE.
    MESSAGE ' Data not saved ' TYPE 'E'.
  ENDIF.
  CALL METHOD go_alv->refresh_table_display
    EXPORTING
      is_stable = gs_stb.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form frm_check_auth
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_check_auth .
  AUTHORITY-CHECK OBJECT 'ZQM06_WERK'
          ID 'WERKS' FIELD p_werks.
  IF sy-subrc <> 0.
    MESSAGE e036(zsy_qm_dev) WITH p_werks.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form f_fieldcat_build
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM f_fieldcat_build .
**- ALV Format setting 
  gs_layout-zebra           = 'X'.    " Set up Grid Line color transformation display 
*  gs_layout-cwidth_opt      = 'X'.    " Set up Grid The width of the field column is automatically adapted 
*  gs_layout-edit            = ''.
*  gs_layout-stylefname  = 'ALV_CELLTAB'.
*  gs_layout-ctab_fname  = 'CELLCOLOR'.
  gs_layout-stylefname = 'MODIFY'.
*  Main field directory parameters .
  CLEAR g_pos.
  PERFORM f_input_fieldcat USING:
*---- Stored here ALV Fields to show  STR--------
   'WERKS' ' factory ' 'X' '' 'ZSY_D_QM61_PPAP' 'WERKS',
   'MATNR' ' Material code ' 'X' '' 'ZSY_D_QM61_PPAP' 'MATNR',
   'MAKTX' ' Material description ' 'X' '' 'MAKT' 'MAKTX',
   'LIFNR' ' Supplier code ' 'X' '' 'ZSY_D_QM61_PPAP' 'LIFNR',
   'NAME_ORG1' ' Supplier description ' 'X' '' 'BUT000' 'NAME_ORG1',
   'ZCJR' ' founder ' 'X' '' 'ZSY_D_QM61_PPAP' 'ZCJR',
   'ZCJRQ' ' Date of creation ' 'X' '' 'ZSY_D_QM61_PPAP' 'ZCJRQ',
   'ZXGR' ' Modifier ' 'X' '' 'ZSY_D_QM61_PPAP' 'ZXGR',
   'ZXGRQ' ' modification date ' 'X' '' 'ZSY_D_QM61_PPAP' 'ZXGRQ',
   'ZZT' ' state ' 'X'  '' 'ZSY_D_QM61_PPAP' 'ZZT'.
*---- Stored here ALV Fields to show  END--------
  g_edit = 'X'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form f_input_fieldcat
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> P_
*&      --> P_
*&      --> P_
*&      --> P_
*&      --> P_
*&      --> P_
*&---------------------------------------------------------------------*
FORM f_input_fieldcat USING VALUE(p_field)
                              VALUE(p_name)
                              VALUE(p_edit)
                              VALUE(p_drdn)
                              VALUE(p_table)
                              VALUE(p_ref).
*  Common fields , use USING Subroutine transfer 

  g_pos = g_pos + 1.
  wa_fieldcat-col_pos = g_pos. " Output column position 
  wa_fieldcat-fieldname = p_field. " Field name , Capital must be written. 
  wa_fieldcat-coltext = p_name. " Field title 
  wa_fieldcat-edit = p_edit . " Set cells editable 
  wa_fieldcat-drdn_field = p_drdn.
  wa_fieldcat-outputlen = '10'.
  wa_fieldcat-ref_table = p_table.
  wa_fieldcat-ref_field = p_ref.
*  IF  wa_fieldcat-fieldname = 'ZDYMB'.
*    wa_fieldcat-outputlen = '20'.
*  ENDIF.

  APPEND wa_fieldcat TO gt_fieldcat.
  CLEAR wa_fieldcat.


ENDFORM. "F_INPUT_FIELDCAT
*&---------------------------------------------------------------------*
*& Form frm_sub_get_down
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_sub_get_down .
  DATA: l_spras TYPE lvc_s_drop-value,
        l_count TYPE i.
  DATA ls_modify TYPE lvc_s_styl.
  LOOP AT gt_item ASSIGNING FIELD-SYMBOL(<fs_item>).
    l_count += 1.
    <fs_item>-dd_handle = l_count.
*    ls_modify-fieldname = 'WERKS'.
*    ls_modify-style = cl_gui_alv_grid=>mc_style_disabled.
*    APPEND ls_modify TO <fs_item>-modify.
    <fs_item>-modify = VALUE #( style = cl_gui_alv_grid=>mc_style_disabled
                                 (  fieldname = 'WERKS')
                                 (  fieldname = 'MATNR')
                                 (  fieldname = 'MAKTX')
                                 (  fieldname = 'LIFNR')
                                 (  fieldname = 'NAME_ORG1')
                                 (  fieldname = 'ZCJR')
                                 (  fieldname = 'ZCJRQ')
                                 (  fieldname = 'ZXGR')
                                 (  fieldname = 'ZXGRQ')
                                   ).
  ENDLOOP.
  PERFORM frm_toolbar.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_toolbar
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_toolbar .
  REFRESH g_toolbar.
  PERFORM append_alv_exclude_functions TABLES g_toolbar  USING:
               cl_gui_alv_grid=>mc_fc_reprep            ,
               cl_gui_alv_grid=>mc_fc_check             ,
               cl_gui_alv_grid=>mc_mb_export            ,
               cl_gui_alv_grid=>mc_fc_detail            ,
               cl_gui_alv_grid=>mc_fc_refresh           ,
               cl_gui_alv_grid=>mc_fc_graph             ,
               cl_gui_alv_grid=>mc_fc_loc_undo          ,
               cl_gui_alv_grid=>mc_fc_loc_delete_row    ,
               cl_gui_alv_grid=>mc_fc_loc_insert_row    ,
               cl_gui_alv_grid=>mc_fc_loc_copy_row      ,
               cl_gui_alv_grid=>mc_fc_loc_cut           ,
               cl_gui_alv_grid=>mc_fc_loc_append_row    ,
               cl_gui_alv_grid=>mc_fc_loc_paste_new_row ,
               cl_gui_alv_grid=>mc_fc_info              ,
               cl_gui_alv_grid=>mc_fc_loc_copy          ,
               cl_gui_alv_grid=>mc_fc_loc_paste         ,
               cl_gui_alv_grid=>mc_fc_print             ,
               cl_gui_alv_grid=>mc_mb_sum               ,
               cl_gui_alv_grid=>mc_mb_view              ,
               cl_gui_alv_grid=>mc_fc_current_variant   ,
               cl_gui_alv_grid=>mc_fc_save_variant      ,
               cl_gui_alv_grid=>mc_fc_load_variant      ,
               cl_gui_alv_grid=>mc_fc_maintain_variant  ,
               cl_gui_alv_grid=>mc_fc_deselect_all      ,
               cl_gui_alv_grid=>mc_fc_select_all        .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form append_alv_exclude_functions
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> G_TOOLBAR
*&      --> CL_GUI_ALV_GRID=>MC_FC_REPREP
*&---------------------------------------------------------------------*
FORM append_alv_exclude_functions TABLES pt_exclude TYPE ui_functions
                                    USING  p_value    TYPE ui_func.
  APPEND p_value TO pt_exclude.
ENDFORM.                    " APPEND_ALV_EXCLUDE_FUNCTIONS
*&---------------------------------------------------------------------*
*& Form create_alv
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM create_alv .
  CREATE OBJECT gs_con
    EXPORTING
      container_name = 'GC_CON'.

  CREATE OBJECT go_alv
    EXPORTING
      i_parent = gs_con.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_ooalv_dis
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_ooalv_dis .
  DATA selfield TYPE slis_selfield.
  CALL METHOD go_alv->register_edit_event
    EXPORTING
      i_event_id = cl_gui_alv_grid=>mc_evt_modified.
*      i_event_id = cl_gui_alv_grid=>mc_evt_enter.
*  EXCEPTIONS
*    error      = 1
*    others     = 2
  .
  IF go_event_receiver IS INITIAL.
    CREATE OBJECT go_event_receiver.
    SET HANDLER go_event_receiver->handle_user_command  FOR go_alv.
    SET HANDLER go_event_receiver->handle_data_changed  FOR go_alv.
  ENDIF.
  CALL METHOD go_alv->set_drop_down_table
    EXPORTING
      it_drop_down = gt_ddval.
  SORT gt_item BY werks matnr lifnr.
  CALL METHOD go_alv->set_table_for_first_display
    EXPORTING
      it_toolbar_excluding          = g_toolbar
      is_layout                     = gs_layout
    CHANGING
      it_outtab                     = gt_item[]
      it_fieldcatalog               = gt_fieldcat
*     it_sort                       =
*     it_filter                     =
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS                        = 4.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'S001'.
* SET TITLEBAR 'xxx'.
ENDMODULE.

MODULE user_command_0100 INPUT.

  CASE ok_code.
    WHEN  'BACK' OR 'CANCEL'.
*      CLEAR: gt_item.
      LEAVE TO SCREEN 0.
    WHEN 'EDIT'.
      PERFORM frm_edit.
    WHEN 'ADD'.
      PERFORM frm_add.
    WHEN 'DEL'.
      PERFORM frm_del.
    WHEN 'EXIT'.
      LEAVE PROGRAM.
    WHEN 'SAVE'.
      PERFORM frm_save.
  ENDCASE.


ENDMODULE.

The effect is as follows :
 Insert picture description here

原网站

版权声明
本文为[SAP. start a solo run]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207040601209306.html