当前位置: 代码迷 >> 综合 >> SAP-ABAP-OOALV方法实现程序源码,仅供参考
  详细解决方案

SAP-ABAP-OOALV方法实现程序源码,仅供参考

热度:38   发布时间:2023-12-13 04:26:55.0

下列程序为本人备忘使用,复制后无法直接使用,但也有参考意义,
OOALV重点如下
1.类参数定义 5-31行
2.类方法定义 66-79行
3.类方法实现 183-567行
4.ALV调用类 577-640 行

REPORT zqmf002.
"$. Region 定义DATA: ok_code LIKE sy-ucomm.CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA: event_receiver TYPE REF TO lcl_event_receiver.DATA GV_CCC TYPE C .DATA: gt_fieldcat TYPE lvc_t_fcat,gs_layout            TYPE lvc_s_layo,gt_select            TYPE lvc_t_cell,gs_select            TYPE lvc_s_cell,gs_variant           TYPE disvariant,gt_t_f4              TYPE lvc_t_f4,it_toolbar_excluding TYPE ui_functions.DATA: stbl TYPE lvc_s_stbl. "鼠标游标位置
DATA: et_filtered TYPE lvc_t_fidx.DATA alv_grid TYPE REF TO cl_gui_alv_grid. "后面要用到CL_GUI_ALV_GRID类中的方法
"SET_TABLE_FIRST_DISPLAY,这个方法基于实例存在,必须
"为这个类创建一个对象。在此处声明。
DATA gs_parent TYPE REF TO cl_gui_custom_container . "定义容器*DATA: gr_table TYPE REF TO cl_salv_table.
*DATA: lr_functions TYPE REF TO cl_salv_functions."$. Region 此处定义改为需要用到的定义
TABLES : lfa1 ,mara ,mseg ,syst , zmmzlkk02 , ztmm001 ,t001.TYPES : BEGIN OF ty_item ,zjbj TYPE c ,  "增加标记xgbj TYPE c .   "修改标记include structure zmmzlkk02.
TYPES END OF ty_item.
DATA gt_item TYPE TABLE OF ty_item .
DATA gs_item TYPE ty_item .
DATA gs_data TYPE zmmzlkk02 .DATA gv_zxh TYPE zmmzlkk02-zxh .RANGES S_USER FOR SY-uname .
TYPES : BEGIN OF TY_MBLNR ,MATNR TYPE MSEG-MATNR,CHARG TYPE MSEG-CHARG,MBLNR TYPE MSEG-MBLNR,
*        ZEILE  TYPE MSEG-ZEILE ,END OF TY_MBLNR .
DATA GT_MBLNR TYPE TABLE OF TY_MBLNR .
DATA GS_MBLNR TYPE TY_MBLNR ."$. Endregion 此处定义改为需要用到的定义*&---------------------------------------------------------------------*
*&       Class LCL_EVENT_RECEIVER
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.PUBLIC SECTION.METHODS:handle_onf4 FOR EVENT onf4 OF cl_gui_alv_gridIMPORTING e_fieldname es_row_no er_event_data,handle_double_click FOR EVENT double_click OF cl_gui_alv_gridIMPORTING e_row e_column es_row_no,handle_toolbar      FOR EVENT toolbar OF cl_gui_alv_gridIMPORTING e_object e_interactive,handle_user_command FOR EVENT user_command OF cl_gui_alv_gridIMPORTING e_ucomm,handle_data_changed FOR EVENT data_changed OF cl_gui_alv_gridIMPORTING er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm.
ENDCLASS. "LCL_EVENT_RECEIVER
"$. Endregion 定义"$. Region 选择屏幕SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001 .SELECT-OPTIONS : s_BUKRS FOR t001-BUKRS . "公司代码
SELECT-OPTIONS : s_lifnr FOR lfa1-lifnr . "供应商
SELECT-OPTIONS : s_matnr FOR mara-matnr . "物料编码
SELECT-OPTIONS : s_mblnr FOR mseg-mblnr . "物料凭证
SELECT-OPTIONS : s_charg FOR mseg-charg . "批次
SELECT-OPTIONS : s_zcpcs FOR ztmm001-zcpcs . "层数
SELECT-OPTIONS : s_zbudt FOR sy-datum . "日期
SELECT-OPTIONS : s_name1 FOR sy-uname . "用户SELECTION-SCREEN END OF BLOCK b1."$. Endregion 选择屏幕INITIALIZATION.stbl-row = 'X'.stbl-col = 'X'.AT SELECTION-SCREEN.S_LIFNR-SIGN   = 'E' .S_LIFNR-OPTION = 'EQ' .S_BUKRS-SIGN   = 'E' .S_BUKRS-OPTION = 'EQ' .SELECT bukrs , LIFNRFROM lfb1WHERE lifnr IN @s_lifnrAND   BUKRS IN @S_BUKRSINTO TABLE @DATA(gt_bukrs)  .LOOP AT gt_bukrs INTO DATA(gs_bukrs).AUTHORITY-CHECK OBJECT 'F_LFA1_BUK'ID 'BUKRS' FIELD gs_bukrs-BUKRSID 'ACTVT' FIELD '03'.IF sy-subrc <> 0.s_lifnr-LOW = gs_bukrs-LIFNR .APPEND s_lifnr .S_BUKRS-LOW = gs_bukrs-BUKRS .APPEND S_BUKRS .ENDIF.ENDLOOP.START-OF-SELECTION.PERFORM frm_get_data.CALL SCREEN 9000."$. Region FORM
MODULE status_9000 OUTPUT.SET PF-STATUS '9000'.SET TITLEBAR '9000'.DATA(gv_frist) = 'X' . "判断是不是第一次运行,自添加按钮需要刷新才能显示PERFORM frm_display_alv.IF gv_frist = 'X'.CALL METHOD alv_grid->refresh_table_display  "增加按钮需要刷新才会显示出来,否则无法显示。EXPORTINGis_stable = stbl.gv_frist = '0' ."判断是否为第一次,为第一次则刷新ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.CASE ok_code.WHEN 'BACK'.PERFORM FRM_EXIT_CHACK .IF GV_CCC = 'X'.refresh: gt_item.LEAVE TO SCREEN 0.ENDIF.WHEN 'SAVE'.PERFORM frm_save.WHEN 'EXIT'.PERFORM FRM_EXIT_CHACK .IF GV_CCC = 'X'.LEAVE PROGRAM.ENDIF.WHEN 'CANCEL'.PERFORM FRM_EXIT_CHACK .IF GV_CCC = 'X'.LEAVE TO SCREEN 0.ENDIF.ENDCASE.
ENDMODULE.*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.METHOD handle_data_changed.DATA: lv_ref TYPE c.CALL METHOD alv_grid->get_selected_cellsIMPORTINGet_cell = gt_select.LOOP AT GT_SELECT INTO DATA(GS_TEM).READ TABLE GT_ITEM INDEX GS_TEM-ROW_ID ASSIGNING FIELD-SYMBOL(<FS_TMP>) .IF <FS_TMP>-zjbj <> 'X' .<FS_TMP>-XGBJ = 'X' .ENDIF.ENDLOOP.CLEAR lv_ref.LOOP AT er_data_changed->mt_good_cells ASSIGNING FIELD-SYMBOL(<ls_good>).IF <ls_good>-FIELDNAME = 'MATNR'.READ TABLE gt_item ASSIGNING FIELD-SYMBOL(<fs_item>) INDEX <ls_good>-row_id.IF SY-SUBRC = 0.SELECT SINGLE MAKT~MATNR ,MAKT~MAKTX ,
*                        MSEG~CHARG ,ZTMM001~ZCPCSFROM MAKTLEFT JOIN ZTMM001 ON MAKT~MATNR = ZTMM001~MATNR AND MAKT~SPRAS = '1'
*            LEFT JOIN MSEG    ON MAKT~MATNR = ZTMM001~MATNR AND MAKT~SPRAS = '1'WHERE MAKT~MATNR = @<ls_good>-VALUEINTO @DATA(GS_MATNR).<fs_item>-MAKTX = GS_MATNR-MAKTX .<fs_item>-ZCPCS = GS_MATNR-ZCPCS .
*            <fs_item>-CHARG = GS_MATNR-CHARG .CLEAR : <fs_item>-MBLNR , <fs_item>-ZEILE , <fs_item>-VBELN .CLEAR : <fs_item>-POSNR , <fs_item>-CHARG .ENDIF.ELSEIF <ls_good>-FIELDNAME = 'ZGYS'.READ TABLE gt_item ASSIGNING <fs_item> INDEX <ls_good>-row_id.IF SY-SUBRC = 0.SELECT SINGLE LFA1~LIFNR  ,LFA1~NAME1FROM  LFA1WHERE LFA1~LIFNR = @<LS_GOOD>-VALUEINTO  @DATA(LS_LIFNR).<fs_item>-NAME1 = LS_LIFNR-NAME1 .ENDIF.ENDIF.ENDLOOP.
*    IF lv_ref = 'X'.CALL METHOD alv_grid->refresh_table_displayEXPORTINGis_stable = stbl.ENDMETHOD.METHOD handle_onf4.   "F4帮助handle_onf4DATA: ls_modi    TYPE lvc_s_modi,lt_ret_tab TYPE TABLE OF ddshretval.IF e_fieldname = 'MBLNR'.READ TABLE gt_item INDEX es_row_no-row_id ASSIGNING FIELD-SYMBOL(<fs_item>).
*      CHECK sy-subrc = 0.IF SY-SUBRC = 0.IF <fs_item>-MATNR IS INITIAL OR <fs_item>-CHARG IS INITIAL.MESSAGE '请先输入物料编码及物料对应批次' TYPE 'S' DISPLAY LIKE 'E' .ELSE.SELECT MSEG~MATNR ,MSEG~CHARG ,MSEG~MBLNRFROM MSEGWHERE MSEG~MATNR = @<FS_ITEM>-MATNRAND   MSEG~CHARG = @<FS_ITEM>-CHARGINTO TABLE @GT_MBLNR.CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'EXPORTINGretfield   = 'MBLNR'value_org  = 'S'TABLESvalue_tab  = GT_MBLNRreturn_tab = lt_ret_tab.IF sy-subrc = 0.READ TABLE lt_ret_tab INDEX 1 ASSIGNING FIELD-SYMBOL(<fs_ret>).IF sy-subrc = 0.<fs_item>-MBLNR = <fs_ret>-fieldval.READ TABLE GT_MBLNR ASSIGNING FIELD-SYMBOL(<fs_MATNR>)WITH KEY MBLNR = <fs_item>-MBLNR.<fs_item>-MBLNR = <fs_MATNR>-MBLNR.
*          <fs_item>-ZEILE = <fs_MATNR>-ZEILE.ENDIF.ENDIF.er_event_data->m_event_handled = 'X'.CALL METHOD alv_grid->refresh_table_displayEXPORTINGis_stable = stbl.ENDIF.ENDIF.ELSEIF e_fieldname = 'VBELN'.READ TABLE gt_item INDEX es_row_no-row_id ASSIGNING <fs_item>.
*         CHECK sy-subrc = 0.IF SY-SUBRC = 0.IF <fs_item>-MATNR IS INITIAL .MESSAGE '请先输入物料编码' TYPE 'S' DISPLAY LIKE 'E' .ELSE.SELECT VBAP~MATNR  ,
*                 VBAP~CHARG  ,VBAP~VBELN
*                    VBAP~POSNRFROM VBAPWHERE VBAP~MATNR = @<FS_ITEM>-MATNR
*            AND   VBAP~CHARG = @<FS_ITEM>-CHARGINTO TABLE @DATA(GT_VBELN).CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'EXPORTINGretfield   = 'VBELN'value_org  = 'S'TABLESvalue_tab  = GT_VBELNreturn_tab = lt_ret_tab.IF sy-subrc = 0.READ TABLE lt_ret_tab INDEX 1 ASSIGNING <fs_ret>.IF sy-subrc = 0.DATA LV_VBELN TYPE VBELN .CLEAR : LV_VBELN .LV_VBELN = <fs_ret>-fieldval .CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' "补齐前导零EXPORTINGINPUT  = LV_VBELNIMPORTINGOUTPUT = LV_VBELN.<fs_item>-VBELN = LV_VBELN.READ TABLE GT_VBELN ASSIGNING FIELD-SYMBOL(<fs_VBELN>)WITH KEY VBELN = <fs_item>-VBELN.
*             <fs_item>-POSNR = <fs_VBELN>-POSNR.ENDIF.ENDIF.er_event_data->m_event_handled = 'X'.CALL METHOD alv_grid->refresh_table_displayEXPORTINGis_stable = stbl.ENDIF.ENDIF.ELSEIF e_fieldname = 'CHARG'.READ TABLE gt_item INDEX es_row_no-row_id ASSIGNING <fs_item>.
*         CHECK sy-subrc = 0.IF SY-SUBRC = 0.IF <fs_item>-MATNR IS INITIAL.MESSAGE '请先输入物料编码' TYPE 'S' DISPLAY LIKE 'E' .ELSE.SELECT MCHA~MATNR  ,MCHA~CHARGFROM MCHAWHERE MCHA~MATNR = @<FS_ITEM>-MATNRINTO TABLE @DATA(GT_MCHA).CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'EXPORTINGretfield   = 'CHARG'value_org  = 'S'TABLESvalue_tab  = GT_MCHAreturn_tab = lt_ret_tab.IF sy-subrc = 0.READ TABLE lt_ret_tab INDEX 1 ASSIGNING <fs_ret>.IF sy-subrc = 0.<fs_item>-CHARG = <fs_ret>-fieldval.
*             READ TABLE GT_VBELN ASSIGNING FIELD-SYMBOL(<fs_VBELN>)
*               WITH KEY CHARG = <fs_item>-VBELN.
*             <fs_item>-POSNR = <fs_VBELN>-POSNR.ENDIF.ENDIF.er_event_data->m_event_handled = 'X'.CALL METHOD alv_grid->refresh_table_displayEXPORTINGis_stable = stbl.ENDIF.ENDIF.ELSEIF e_fieldname = 'ZMEINS'.READ TABLE gt_item INDEX es_row_no-row_id ASSIGNING <fs_item>.
*         CHECK sy-subrc = 0.IF SY-SUBRC = 0.
*           IF <fs_item>-MATNR IS INITIAL.
*             MESSAGE '请先输入物料编码' TYPE 'S' DISPLAY LIKE 'E' .
*           ELSE.SELECT T006A~MSEHI  ,T006A~MSEHLFROM T006AWHERE T006A~SPRAS = '1'INTO TABLE @DATA(GT_MSEHI).CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'EXPORTINGretfield   = 'MSEHI'value_org  = 'S'TABLESvalue_tab  = GT_MSEHIreturn_tab = lt_ret_tab.IF sy-subrc = 0.READ TABLE lt_ret_tab INDEX 1 ASSIGNING <fs_ret>.IF sy-subrc = 0.<fs_item>-ZMEINS = <fs_ret>-fieldval.
*             READ TABLE GT_VBELN ASSIGNING FIELD-SYMBOL(<fs_VBELN>)
*               WITH KEY CHARG = <fs_item>-VBELN.
*             <fs_item>-POSNR = <fs_VBELN>-POSNR.ENDIF.ENDIF.er_event_data->m_event_handled = 'X'.CALL METHOD alv_grid->refresh_table_displayEXPORTINGis_stable = stbl.
*           ENDIF.ENDIF.ELSEIF e_fieldname = 'ZBB'.READ TABLE gt_item INDEX es_row_no-row_id ASSIGNING <fs_item>.
*         CHECK sy-subrc = 0.IF SY-SUBRC = 0.
*           IF <fs_item>-MATNR IS INITIAL.
*             MESSAGE '请先输入物料编码' TYPE 'S' DISPLAY LIKE 'E' .
*           ELSE.SELECT TCURT~WAERS  ,TCURT~KTEXTFROM TCURTWHERE TCURT~SPRAS = '1'INTO TABLE @DATA(GT_TCURT).CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'EXPORTINGretfield   = 'WAERS'value_org  = 'S'TABLESvalue_tab  = GT_TCURTreturn_tab = lt_ret_tab.IF sy-subrc = 0.READ TABLE lt_ret_tab INDEX 1 ASSIGNING <fs_ret>.IF sy-subrc = 0.<fs_item>-ZBB = <fs_ret>-fieldval.
*             READ TABLE GT_VBELN ASSIGNING FIELD-SYMBOL(<fs_VBELN>)
*               WITH KEY CHARG = <fs_item>-VBELN.
*             <fs_item>-POSNR = <fs_VBELN>-POSNR.ENDIF.ENDIF.er_event_data->m_event_handled = 'X'.CALL METHOD alv_grid->refresh_table_displayEXPORTINGis_stable = stbl.
*           ENDIF.ENDIF.ENDIF.ENDMETHOD.                    "HANDLE_ONF4METHOD handle_toolbar.DATA: ls_toolbar        TYPE stb_button.CLEAR ls_toolbar.MOVE 3                  TO ls_toolbar-butn_type.      "分隔符APPEND ls_toolbar       TO e_object->mt_toolbar.CLEAR ls_toolbar.MOVE 'ADD'            TO ls_toolbar-function.        "功能码MOVE icon_insert_row  TO ls_toolbar-icon.      "图标MOVE '插入行'         TO ls_toolbar-quickinfo.MOVE '插入行'         TO ls_toolbar-text.                "显示名称MOVE ' '                TO ls_toolbar-disabled.APPEND ls_toolbar       TO e_object->mt_toolbar.CLEAR ls_toolbar.MOVE 'DEL'            TO ls_toolbar-function.        "功能码MOVE icon_delete_row  TO ls_toolbar-icon.      "图标MOVE '选择单元格删除当前行'         TO ls_toolbar-quickinfo.MOVE '删除行'         TO ls_toolbar-text.                "显示名称MOVE ' '                TO ls_toolbar-disabled.APPEND ls_toolbar       TO e_object->mt_toolbar.CLEAR ls_toolbar.ENDMETHOD.                    "HANDLE_TOOLBARMETHOD handle_user_command.CASE e_ucomm.WHEN 'ADD'.APPEND INITIAL LINE TO gt_item ASSIGNING FIELD-SYMBOL(<fs_item>) .<fs_item>-zbb =    'CNY' .<fs_item>-zmeins = 'M2'   .<fs_item>-zjbj = 'X'   .SELECT zxhFROM zmmzlkk02INTO TABLE @DATA(gt_zxh).SORT gt_zxh BY zxh .READ TABLE gt_zxh INTO DATA(gs_zxh) INDEX sy-tfill .gv_zxh = gs_zxh-zxh .LOOP AT gt_item ASSIGNING <fs_item> WHERE zjbj = 'X' .gv_zxh  = gv_zxh + 1 .<fs_item>-zxh  = gv_zxh  .ENDLOOP.<fs_item>-zxh = gv_zxh .CALL METHOD alv_grid->refresh_table_displayEXPORTINGis_stable = stbl.WHEN 'DEL' .CALL METHOD alv_grid->get_selected_cellsIMPORTINGet_cell = gt_select.LOOP AT gt_select INTO gs_select.READ TABLE gt_item INDEX gs_select-row_id INTO gs_item.
*                      DELETE  gt_item INDEX GS_SELECT-ROW_ID . "临时录入的数据删除内表即可DATA lv_answer TYPE c LENGTH 1 .CALL FUNCTION 'POPUP_TO_CONFIRM'  "弹出对话框EXPORTINGtitlebar       = '删除'
*             DIAGNOSE_OBJECT             = ' 'text_question  = '确认要删除此条数据???'text_button_1  = '确认'
*             ICON_BUTTON_1  = ' '
*             TEXT_BUTTON_2  = 'Nein'(002)
*             ICON_BUTTON_2  = ' '
*             DEFAULT_BUTTON = '1'
*             DISPLAY_CANCEL_BUTTON       = 'X'
*             USERDEFINED_F1_HELP         = ' '
*             START_COLUMN   = 25
*             START_ROW      = 6
*             POPUP_TYPE     =
*             IV_QUICKINFO_BUTTON_1       = ' '
*             IV_QUICKINFO_BUTTON_2       = ' 'IMPORTINGanswer         = lv_answer
*                         TABLES
*             PARAMETER      =EXCEPTIONStext_not_found = 1OTHERS         = 2.IF sy-subrc <> 0.
*           Implement suitable error handling hereENDIF.IF lv_answer = '1'.IF gs_item-zjbj IS  INITIAL.IF SY-UNAME IN S_USER.CLEAR gs_data .MOVE-CORRESPONDING gs_item TO  gs_data .DELETE  zmmzlkk02 FROM  gs_data .DELETE  gt_item   INDEX gs_select-row_id .MESSAGE '删除成功' TYPE 'S' .ELSE  .MESSAGE '保存后的数据只有指定用户允许删除' TYPE 'S' DISPLAY LIKE 'E' .ENDIF.ELSE .DELETE  gt_item   INDEX gs_select-row_id .MESSAGE '删除成功' TYPE 'S' .ENDIF.ELSE.EXIT.ENDIF.ENDLOOP.SELECT zxhFROM zmmzlkk02INTO TABLE @gt_zxh.IF gt_zxh IS NOT INITIAL.SORT gt_zxh BY zxh .READ TABLE gt_zxh INTO gs_zxh INDEX sy-tfill .gv_zxh = gs_zxh-zxh .LOOP AT gt_item ASSIGNING <fs_item> WHERE zjbj = 'X' .gv_zxh  = gv_zxh + 1 .<fs_item>-zxh  = gv_zxh  .ENDLOOP.ENDIF.
*        <FS_ITEM>-ZXH = GV_ZXH .CALL METHOD alv_grid->refresh_table_displayEXPORTINGis_stable = stbl.WHEN OTHERS .ENDCASE.ENDMETHOD.METHOD handle_double_click.
*    MESSAGE '双击事件触发' TYPE 'S'.ENDMETHOD.                    "HANDLE_DOUBLE_CLICKENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_display_alv .CLEAR: gt_fieldcat,gs_layout,it_toolbar_excluding.IF  alv_grid IS INITIAL.******实例化 容器CREATE OBJECT gs_parentEXPORTINGcontainer_name = 'ALV'. " 界面中的一个CUNSTOMER CONTROL控件 用于存放类对象。"使用这个控件把名称赋值给CONTAINER_NAME******将alv植入到容器中CREATE OBJECT alv_gridEXPORTINGi_parent = gs_parent.PERFORM prepare_field_catalog CHANGING gt_fieldcat.PERFORM prepare_layout        CHANGING gs_layout.PERFORM toolbar_excluding_item     CHANGING it_toolbar_excluding.CALL METHOD alv_grid->set_table_for_first_displayEXPORTINGis_variant           = gs_variantis_layout            = gs_layoutit_toolbar_excluding = it_toolbar_excludingi_save               = 'A'CHANGINGit_outtab            = gt_itemit_fieldcatalog      = gt_fieldcat.CREATE OBJECT event_receiver. "创建事件SET HANDLER event_receiver->handle_onf4         FOR alv_grid.SET HANDLER event_receiver->handle_toolbar      FOR alv_grid.SET HANDLER event_receiver->handle_user_command FOR alv_grid.SET HANDLER event_receiver->handle_double_click FOR alv_grid.SET HANDLER event_receiver->handle_data_changed FOR alv_grid.gt_t_f4 = VALUE #( BASE gt_t_f4 ( fieldname = 'MBLNR'  register = 'X' getbefore = 'X' chngeafter = 'X' ) ) .gt_t_f4 = VALUE #( BASE gt_t_f4 ( fieldname = 'VBELN'  register = 'X' getbefore = 'X' chngeafter = 'X' ) ) .gt_t_f4 = VALUE #( BASE gt_t_f4 ( fieldname = 'CHARG'  register = 'X' getbefore = 'X' chngeafter = 'X' ) ) .gt_t_f4 = VALUE #( BASE gt_t_f4 ( fieldname = 'ZMEINS'  register = 'X' getbefore = 'X' chngeafter = 'X' ) ) .gt_t_f4 = VALUE #( BASE gt_t_f4 ( fieldname = 'ZBB'  register = 'X' getbefore = 'X' chngeafter = 'X' ) ) .CALL METHOD alv_grid->register_f4_for_fieldsEXPORTINGit_f4 = gt_t_f4.CALL METHOD cl_gui_control=>set_focusEXPORTINGcontrol = alv_grid.CALL METHOD cl_gui_cfw=>flush.CALL METHOD alv_grid->register_edit_event "注册编辑事件,否则不会触发更新事件EXPORTINGi_event_id = cl_gui_alv_grid=>mc_evt_modified.*    CALL METHOD cl_gui_cfw=>dispatch.
*    CALL METHOD alv_grid->check_changed_data.ELSE.CALL METHOD alv_grid->refresh_table_displayEXPORTINGis_stable = stbl.ENDIF.
ENDFORM.*&---------------------------------------------------------------------*
*&      Form  PREPARE_FIELD_CATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_FIELDCAT  text
*----------------------------------------------------------------------*
FORM prepare_field_catalog CHANGING p_gt_fieldcat TYPE lvc_t_fcat.DATA ls_fcat TYPE lvc_s_fcat.DEFINE set_fcat.CLEAR ls_fcat.ls_fcat-fieldname = &1.ls_fcat-coltext   = &2.ls_fcat-key       = &3.ls_fcat-edit      = &4.
*    ls_fcat-ref_table = &5. "参考表ls_fcat-ref_field = &5. "参考字段ls_fcat-f4availabl = &6.   "F4帮助ls_fcat-no_zero = &7.   "前导零ls_fcat-checkbox = &8.   "复选框ls_fcat-OUTPUTLEN = &9.   "列的字符宽度
*    ls_fcat-f4availabl = &8.IF ls_fcat-fieldname = 'ZGYS'.ls_fcat-ref_table  = 'LFA1' .ENDIF.IF ls_fcat-fieldname = 'MATNR'.ls_fcat-ref_table  = 'MARA' .ENDIF.IF ls_fcat-fieldname = 'ZKKJE'.ls_fcat-ref_table  = 'ZMMZLKK02' .ENDIF.APPEND ls_fcat TO p_gt_fieldcat.END-OF-DEFINITION.
*  set_fcat 'ZXH'      '序号 '       ''    ''    ''       ''     'X'   ''    '03'  .
*  set_fcat 'BUKRS'    '公司代码'     ''    'X'   ''       ''     'X'   ''    '06'  .
*  set_fcat 'ZGYS'     '供应商 '     ''    'X'   'LIFNR'  'X'    'X'   ''    '06'  .
*  set_fcat 'NAME1'     '供应商名称'   ''   ''    ''        ''    ''    ''    '15'  .
*  set_fcat 'MATNR'    '物料编码 '    ''   'X'  'MATNR'   'X'    'X'   ''    '10'  .
*  set_fcat 'MAKTX'    '物料描述 '    ''   ''   ''         ''    ''    ''    '15'  .
*  set_fcat 'CHARG'    '批次 '        ''   'X'   ''       'X'    ''    ''    '8' .
*  set_fcat 'MBLNR'    '物料凭证'      ''   'X' 'MBLNR'    'X'    'X'  ''     '10'  .
*  set_fcat 'ZEILE'    '物料凭证行项目' ''   'X'  'MBLPO'    ''    'X'  ''     '6' .
*  set_fcat 'VBELN'    '销售凭证 '    ''   'X'  'VBELN'    'X'   'X'  ''     '10' .
*  set_fcat 'POSNR'    '销售凭证行项目' ''   'X'  'POSNR'   ''     'X'  ''     '6' .
*  set_fcat 'ZCPCS'    '层数 '        ''   ''    ''        ''    ''    ''     '2'  .
*  set_fcat 'ZMJ '    '数量 '        ''   'X'   ''       ''     ''    ''     '8'  .
*  set_fcat 'ZMEINS'   '单位 '        ''   'X'   ''       'X'     ''   ''     '3' .
*  set_fcat 'ZKKJE'    '扣款金额 '    ''   'X'   'ZKKJE'  ''      ''    ''    '8'  .
*  set_fcat 'ZBB '    '币别 '        ''   'X'   ''       'X'     ''   ''     '3'  .
*  set_fcat 'ZKKYY'    '扣款原因 '    ''   'X'   ''       ''      ''    ''    '20'  .
*  set_fcat 'ZISKK'    '是否扣款 '    ''   'X'   ''       ''      ''    'X'   '6' .
*  set_fcat 'ZBZ'       '备注 '       ''   'X'   ''       ''      ''    ''    '20'  .
*  set_fcat 'ZBUDAT'    '创建日期'     ''   ''    ''       ''      ''    ''    '8'  .
*  set_fcat 'ZPUTM_MKPF' '创建时间'    ''   ''    ''       ''      ''    ''    '8'   .
*  set_fcat 'ZUSNAM'    '创建人 '     ''   ''    ''      ''       ''    ''    '5'  .set_fcat 'ZXH'      '序号 '       ''    ''    ''       ''     'X'   ''    '04'  .set_fcat 'BUKRS'    '公司代码'     ''    'X'   ''       ''     'X'   ''    '08'  .set_fcat 'WERKS'    '工厂'         ''    'X'   ''       ''     'X'   ''    '08'  .set_fcat 'ZGYS'     '供应商 '     ''    'X'   'LIFNR'  'X'    'X'   ''    '08'  .set_fcat 'NAME1'     '供应商名称'   ''   ''    ''        ''    ''    ''    '15'  .set_fcat 'MATNR'    '物料编码 '    ''   'X'  'MATNR'   'X'    'X'   ''    '14'  .set_fcat 'MAKTX'    '物料描述 '    ''   ''   ''         ''    ''    ''    '15'  .set_fcat 'CHARG'    '批次 '        ''   'X'   ''       'X'    ''    ''    '10' .set_fcat 'MBLNR'    '物料凭证'      ''   'X' 'MBLNR'    'X'    'X'  ''     '10'  .set_fcat 'ZEILE'    '物料凭证行项目' ''   'X'  'MBLPO'    ''    'X'  ''     '6' .set_fcat 'VBELN'    '销售凭证 '    ''   'X'  'VBELN'    'X'   'X'  ''     '10' .set_fcat 'POSNR'    '销售凭证行项目' ''   'X'  'POSNR'   ''     'X'  ''     '6' .set_fcat 'ZCPCS'    '层数 '        ''   ''    ''        ''    ''    ''     '4'  .set_fcat 'ZMJ '    '数量 '        ''   'X'   ''       ''     ''    ''     '8'  .set_fcat 'ZMEINS'   '单位 '        ''   'X'   ''       'X'     ''   ''     '3' .set_fcat 'ZKKJE'    '扣款金额 '    ''   'X'   'ZKKJE'  ''      ''    ''    '8'  .set_fcat 'ZBB '    '币别 '        ''   'X'   ''       'X'     ''   ''     '3'  .set_fcat 'ZKKYY'    '扣款原因 '    ''   'X'   ''       ''      ''    ''    '20'  .set_fcat 'ZISKK'    '是否扣款 '    ''   'X'   ''       ''      ''    'X'   '8' .set_fcat 'ZBZ'     '备 注 '    ''   'X'   ''       ''      ''    ''    '255'  .set_fcat 'ZBUDAT'    '创建日期'     ''   ''    ''       ''      ''    ''    '10'  .set_fcat 'ZPUTM_MKPF' '创建时间'    ''   ''    ''       ''      ''    ''    '8'   .set_fcat 'ZUSNAM'    '创建人 '     ''   ''    ''      ''       ''    ''    '6'  .ENDFORM.*&---------------------------------------------------------------------*
*&      Form  PREPARE_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM prepare_layout CHANGING p_gs_layout TYPE lvc_s_layo.p_gs_layout-zebra = 'X'.
*  P_GS_LAYOUT-SEL_MODE = 'A'.p_gs_layout-cwidth_opt = 'X'.p_gs_layout-edit_mode = 'X'.
*  P_GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.
ENDFORM.FORM toolbar_excluding_item CHANGING pt_exclude TYPE ui_functions.DATA ls_exclude TYPE ui_func.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_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_copy.APPEND ls_exclude TO pt_exclude.ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_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_cut.APPEND ls_exclude TO pt_exclude.ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.APPEND ls_exclude TO pt_exclude.
ENDFORM.*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_data .PERFORM FRM_USER_APPEND .SELECTzmmzlkk02~zxh                    ,zmmzlkk02~zgys                   ,zmmzlkk02~BUKRS                  ,zmmzlkk02~name1                  ,zmmzlkk02~werks                  ,zmmzlkk02~matnr                  ,zmmzlkk02~maktx                  ,zmmzlkk02~mblnr                  ,zmmzlkk02~zeile                  ,zmmzlkk02~vbeln                  ,zmmzlkk02~posnr                  ,zmmzlkk02~charg                  ,zmmzlkk02~zcpcs                  ,zmmzlkk02~zmj                    ,zmmzlkk02~zmeins                 ,zmmzlkk02~zkkje                  ,zmmzlkk02~zbb                    ,zmmzlkk02~zkkyy                  ,zmmzlkk02~ziskk                  ,zmmzlkk02~zbz                    ,zmmzlkk02~zbudat                 ,zmmzlkk02~zputm_mkpf             ,zmmzlkk02~zusnamFROM   zmmzlkk02WHERE  zmmzlkk02~zgys   IN @s_lifnrAND    zmmzlkk02~matnr  IN @s_matnrAND    zmmzlkk02~mblnr  IN @s_mblnrAND    zmmzlkk02~charg  IN @s_chargAND    zmmzlkk02~zcpcs  IN @s_zcpcsAND    zmmzlkk02~zbudat IN @s_zbudtAND    zmmzlkk02~zusnam IN @s_name1AND    zmmzlkk02~BUKRS  IN @S_BUKRSINTO  CORRESPONDING FIELDS OF TABLE @gt_item.SORT gt_item by ZXH .ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SAVE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_save .PERFORM FRM_CHACK_DATA .DATA LV_CHAR TYPE C LENGTH 40 .CLEAR gs_item .LOOP AT gt_item INTO gs_item WHERE zjbj IS NOT INITIAL OR xgbj IS NOT INITIAL .IF gs_item-zjbj = 'X'.gs_item-zbudat      =  sy-datum .gs_item-zputm_mkpf  =  sy-uzeit .gs_item-zusnam      =  sy-uname .MOVE-CORRESPONDING gs_item TO gs_data .MODIFY zmmzlkk02 FROM gs_data .MESSAGE '保存成功' TYPE 'S' .ELSEIF gs_item-xgbj = 'X' .IF SY-UNAME IN S_USER .gs_item-zbudat      =  sy-datum .gs_item-zputm_mkpf  =  sy-uzeit .gs_item-zusnam      =  sy-uname .MOVE-CORRESPONDING gs_item TO gs_data .MODIFY zmmzlkk02 FROM gs_data .ELSE .MESSAGE '只有指定用户允许修改' TYPE  'S' DISPLAY LIKE 'E' .ENDIF.ENDIF.ENDLOOP.CLEAR gt_item .PERFORM frm_get_data .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHACK_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_CHACK_DATA .CLEAR : gs_item .LOOP AT gt_item INTO  gs_item WHERE zjbj IS NOT INITIAL OR xgbj IS NOT INITIAL.SELECT SINGLE BUKRS , LIFNRFROM LFb1INTO @DATA(LV_BUKRS)WHERE BUKRS = @gs_item-BUKRSAND   LIFNR = @GS_ITEM-ZGYS .IF LV_BUKRS IS INITIAL.MESSAGE '供应商不属于公司代码' && gs_item-BUKRS && ',请重新输入' TYPE 'E' .ENDIF.IF gs_item-ZGYS IS INITIAL.MESSAGE '序号' && gs_item-ZXH && '所在行供应商不能为空!!' TYPE 'E' DISPLAY LIKE 'E' .ELSEIF gs_item-matnr IS INITIAL.MESSAGE '序号' && gs_item-ZXH && '所在行物料编码不能为空!!' TYPE 'E' DISPLAY LIKE 'E' .ELSEIF gs_item-zkkje = '0'.MESSAGE '序号' && gs_item-ZXH && '所在行扣款金额不能为空!!' TYPE 'E' DISPLAY LIKE 'E' .ELSEIF gs_item-ZKKYY IS INITIAL .MESSAGE '序号' && gs_item-ZXH && '所在行扣款原因不能为空!!' TYPE 'E' DISPLAY LIKE 'E' .ENDIF.AUTHORITY-CHECK OBJECT 'F_LFA1_BUK'ID 'BUKRS' FIELD gs_item-BUKRSID 'ACTVT' FIELD '03'.IF sy-subrc <> 0.MESSAGE '您没有操作公司代码' &&  gs_item-BUKRS && '的权限'  TYPE 'E' DISPLAY LIKE 'E' .ENDIF.ENDLOOP.CALL METHOD alv_grid->refresh_table_displayEXPORTINGis_stable = stbl.ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_USER_APPEND
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_USER_APPEND .S_USER-SIGN   = 'I'  .S_USER-OPTION = 'EQ'  .S_USER-LOW    = '1101305'  .APPEND S_USER .S_USER-LOW    = '00018881' .APPEND S_USER .S_USER-LOW    = '1501020'  .APPEND S_USER .S_USER-LOW    = '1802018'  .APPEND S_USER .ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_EXIT_CHACK
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_EXIT_CHACK .LOOP AT gt_item INTO DATA(GS_QWE) WHERE zjbj IS NOT INITIAL OR xgbj IS NOT INITIAL .DATA(LV_EC) = 'X' .ENDLOOP.IF LV_EC = 'X'.DATA lv_answer TYPE c LENGTH 1 .CALL FUNCTION 'POPUP_TO_CONFIRM'  "弹出对话框EXPORTINGtitlebar       = '退出'
*       DIAGNOSE_OBJECT             = ' 'text_question  = '存在未保存数据,是否退出???'text_button_1  = '确认'
*       ICON_BUTTON_1  = ' '
*       TEXT_BUTTON_2  = 'Nein'(002)
*       ICON_BUTTON_2  = ' '
*       DEFAULT_BUTTON = '1'
*       DISPLAY_CANCEL_BUTTON       = 'X'
*       USERDEFINED_F1_HELP         = ' '
*       START_COLUMN   = 25
*       START_ROW      = 6
*       POPUP_TYPE     =
*       IV_QUICKINFO_BUTTON_1       = ' '
*       IV_QUICKINFO_BUTTON_2       = ' 'IMPORTINGanswer         = lv_answer
*                         TABLES
*       PARAMETER      =EXCEPTIONStext_not_found = 1OTHERS         = 2.IF sy-subrc <> 0.
*           Implement suitable error handling hereENDIF.IF lv_answer = '1'.GV_CCC = 'X' .ELSE .EXIT .ENDIF .ELSE .GV_CCC = 'X' .ENDIF.
ENDFORM.
  相关解决方案