主要解决禁用MM02 事务码后,用户需要更改物料主数据,所做的customer transaction.
*&---------------------------------------------------------------------* *& Report Z_MCFE_UPDATE *& test pgm *&---------------------------------------------------------------------* *& Created by Ken Zong for Custom MCFE transaction in 04/26/2019 *& No tr *&---------------------------------------------------------------------* REPORT Z_MCFE_UPDATE_DEMON. TYPE-POOLS: slis. *&---------------------------------------------------------------------* *& Type define *&---------------------------------------------------------------------* TYPES: BEGIN OF ty_show, matnr TYPE char18, meinh TYPE marm-meinh, xfhdw TYPE marm-xfhdw, atnam TYPE char30, atwrt TYPE smeinh_ws-atwrt, END OF ty_show, tt_show TYPE TABLE OF ty_show, BEGIN OF ty_check_type, matnr TYPE char18, mtart TYPE char4, mbrsh TYPE char1, END OF ty_check_type. DATA: * ALV DEFINIE gt_fieldcat TYPE lvc_t_fcat, gs_fieldcat TYPE lvc_s_fcat, gs_layout TYPE lvc_s_layo, i_grid_settings TYPE lvc_s_glay, gv_matnr LIKE mara-matnr, gv_return TYPE bool, gv_flag_succ TYPE bool, gs_info_show TYPE ty_show, gt_info_show TYPE TABLE OF ty_show, gt_meinh TYPE TABLE OF smeinh, gt_return TYPE TABLE OF bapireturn1 WITH HEADER LINE, gt_message TYPE TABLE OF matmess, gt_meinh_ws TYPE TABLE OF smeinh_ws, gt_meinh_ws_upd TYPE TABLE OF smeinh_wsupd, gt_meinh_ws_updx TYPE TABLE OF smeinh_wsupdx, gt_headdata TYPE bapimathead. *&---------------------------------------------------------------------* *& SELECTION-SCREEN *&---------------------------------------------------------------------* SELECTION-SCREEN: BEGIN OF BLOCK bl01 WITH FRAME TITLE text-001. PARAMETERS: p_matnr TYPE char18 OBLIGATORY. *PARAMETERS: p_check TYPE char1 AS CHECKBOX. SELECTION-SCREEN: END OF BLOCK bl01. *&---------------------------------------------------------------------* *& INITIALIZATION. *&---------------------------------------------------------------------* INITIALIZATION. CLEAR: gt_fieldcat, gs_fieldcat, gs_layout, i_grid_settings, gv_matnr, gs_info_show, gt_info_show, gt_meinh, gt_return, gt_message, gt_meinh_ws, gt_meinh_ws_upd, gt_meinh_ws_updx, gt_headdata. *&---------------------------------------------------------------------* *& START-OF-SELECTION. *&---------------------------------------------------------------------* START-OF-SELECTION. PERFORM CHECK_MATNR_TYPE. * Erroe handle IF gv_return = abap_true. MESSAGE 'please input correct Material Number which material type is MCFE !' TYPE 'E'. ENDIF. PERFORM GET_MIAN_INFO. * Error handle IF gv_return = abap_true.. MESSAGE 'Have issue when try to get data for Populating Additional' TYPE 'E'. ENDIF. * Handle user command FORM ALV_USER_COMMAND USING P_UCOMM LIKE SY-UCOMM P_SELFIELD TYPE SLIS_SELFIELD. DATA: lt_out LIKE TABLE OF CABN. CLEAR lt_out. CASE P_UCOMM. WHEN 'E'. LEAVE PROGRAM. WHEN 'ENDE'. * MESSAGE 'No chanes' TYPE 'I'. LEAVE PROGRAM. WHEN 'ECAN'. * MESSAGE 'No chanes' TYPE 'I'. LEAVE PROGRAM. WHEN 'SPOS'. LOOP AT gt_info_show INTO gs_info_show. CALL FUNCTION 'CLSE_SELECT_CABN_VIA_NAME' EXPORTING CHARACTERISTIC = gs_info_show-atnam TABLES T_CABN = lt_out EXCEPTIONS NO_ENTRY_FOUND = 1 OTHERS = 2 . IF SY-SUBRC <> 0. MESSAGE 'please input correct Characteristic Name ' TYPE 'I'. ENDIF. PERFORM CALL_BAPI_HANDLE. ENDLOOP. * Update successfully CHECK gv_flag_succ = abap_true. MESSAGE:'Material has been updated successfully.' TYPE 'I'. LEAVE PROGRAM. WHEN OTHERS. ENDCASE. ENDFORM. *&---------------------------------------------------------------------* *& END-OF-SELECTION. *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form CHECK_MATNR_TYPE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM CHECK_MATNR_TYPE . DATA ls_check_type TYPE ty_check_type. CLEAR ls_check_type. * Change format CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = p_matnr IMPORTING output = gv_matnr. * Get info from MARA and check the material type SELECT SINGLE matnr mtart mbrsh FROM mara INTO CORRESPONDING FIELDS OF ls_check_type WHERE matnr = gv_matnr AND mtart = 'MCFE'. * Error handle IF sy-subrc <> 0. gv_return = abap_true. RETURN. ENDIF. * Used for call Bapi gt_headdata-material = ls_check_type-matnr. gt_headdata-matl_type = ls_check_type-mtart. gt_headdata-ind_sector = ls_check_type-mbrsh. ENDFORM. " CHECK_MATNR_TYPE *&---------------------------------------------------------------------* *& Form GET_MIAN_INFO *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM GET_MIAN_INFO . DATA: ls_temp TYPE ty_show, lt_class LIKE TABLE OF sclass , lt_clobjdat LIKE TABLE OF clobjdat, ls_clobjdat TYPE clobjdat. FIELD-SYMBOLS: <fs_temp> TYPE SMEINH_WSUPD. CLEAR: ls_temp, lt_class, lt_clobjdat, ls_clobjdat. UNASSIGN <fs_temp>. * Get all data for Populating Additional data CALL FUNCTION 'VBWS_UOM_READ_WITH_MATNR' EXPORTING I_MATNR = p_matnr TABLES E_MEINH_WS = gt_meinh_ws E_MEINH = gt_meinh E_MESSAGE = gt_message e_meinh_ws_upd = gt_meinh_ws_upd e_meinh_ws_updx = gt_meinh_ws_updx E_RETURN = gt_return EXCEPTIONS ERROR = 1 OTHERS = 2 . IF SY-SUBRC <> 0 AND gt_meinh_ws_upd IS NOT INITIAL. * Implement suitable error handling here gv_return = abap_true. RETURN. ENDIF. * Create for alv LOOP AT gt_meinh_ws_upd ASSIGNING <fs_temp>. ls_temp-matnr = p_matnr. ls_temp-meinh = <fs_temp>-wsmei. ls_temp-xfhdw = <fs_temp>-xfhdw. ls_temp-atnam = <fs_temp>-atnam. ls_temp-atwrt = <fs_temp>-atwrt. APPEND ls_temp to gt_info_show. CLEAR ls_temp. ENDLOOP. PERFORM ALV_SHOW. ENDFORM. " GET_MIAN_INFO *&---------------------------------------------------------------------* *& Form ALV_SHOW *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_LT_INFO_MARM text *----------------------------------------------------------------------* FORM ALV_SHOW. gs_fieldcat-fieldname = 'MATNR'."FIELDNAME gs_fieldcat-coltext = 'Material Number'. gs_fieldcat-outputlen = '15'. APPEND gs_fieldcat TO gt_fieldcat. CLEAR gs_fieldcat. gs_fieldcat-fieldname = 'MEINH'."FIELDNAME gs_fieldcat-coltext = 'Alternative Unit of Measure for Stockkeeping Unit'. gs_fieldcat-outputlen = '20'. APPEND gs_fieldcat TO gt_fieldcat. CLEAR gs_fieldcat. gs_fieldcat-fieldname = 'XFHDW'."FIELDNAME gs_fieldcat-coltext = 'Leading batch-specific unit of measure'. gs_fieldcat-outputlen = '2'. * IF p_check = abap_true. gs_fieldcat-edit = abap_true. * ENDIF. APPEND gs_fieldcat TO gt_fieldcat. CLEAR gs_fieldcat. gs_fieldcat-fieldname = 'ATNAM'."FIELDNAME gs_fieldcat-coltext = 'Characteristic Name'. gs_fieldcat-outputlen = '50'. * IF p_check = abap_true. gs_fieldcat-edit = abap_true. * ENDIF. APPEND gs_fieldcat TO gt_fieldcat. CLEAR gs_fieldcat. gs_fieldcat-fieldname = 'ATWRT'."FIELDNAME gs_fieldcat-coltext = 'Conversion value'. gs_fieldcat-outputlen = '20'. * IF p_check = abap_true. gs_fieldcat-edit = abap_true. * ENDIF. APPEND gs_fieldcat TO gt_fieldcat. * Set Layout gs_layout-cwidth_opt = 'X'. gs_layout-zebra = 'X'. gs_layout-sel_mode = 'D'. i_grid_settings-edt_cll_cb = 'X'. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING I_CALLBACK_PROGRAM = sy-repid IS_LAYOUT_LVC = gs_layout i_callback_pf_status_set = 'F_SET_STATUS' IT_FIELDCAT_LVC = gt_fieldcat I_CALLBACK_USER_COMMAND = 'ALV_USER_COMMAND' I_GRID_SETTINGS = i_grid_settings TABLES T_OUTTAB = gt_info_show EXCEPTIONS PROGRAM_ERROR = 1 OTHERS = 2 . IF SY-SUBRC <> 0. * Implement suitable error handling here MESSAGE 'Have issue when try to display data' TYPE 'E'. ENDIF. ENDFORM. " ALV_SHOW *&---------------------------------------------------------------------* *& Form CALL_BAPI_HANDLE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM CALL_BAPI_HANDLE . DATA: return TYPE bapiret2, lv_flag_up TYPE bool, lv_err TYPE string. FIELD-SYMBOLS: <fs_meinh_ws_upd> TYPE SMEINH_WSUPD, <fs_info_show> TYPE ty_show. CLEAR: gt_return, return, lv_flag_up, lv_err. UNASSIGN: <fs_meinh_ws_upd>, <fs_info_show>. * Handle the changing LOOP AT gt_meinh_ws_upd ASSIGNING <fs_meinh_ws_upd>. LOOP AT gt_info_show ASSIGNING <fs_info_show>. "A.UOM IF <fs_meinh_ws_upd>-wsmei <> <fs_info_show>-meinh. <fs_meinh_ws_upd>-wsmei = <fs_info_show>-meinh. lv_flag_up = abap_true. ENDIF. "Char assignment IF <fs_meinh_ws_upd>-atnam <> <fs_info_show>-atnam. <fs_meinh_ws_upd>-atnam = <fs_info_show>-atnam. lv_flag_up = abap_true. ENDIF. "Conversion value IF <fs_meinh_ws_upd>-atwrt <> <fs_info_show>-atwrt. <fs_meinh_ws_upd>-atwrt = <fs_info_show>-atwrt. lv_flag_up = abap_true. ENDIF. "Leading Unit IF <fs_meinh_ws_upd>-xfhdw <> <fs_info_show>-xfhdw. <fs_meinh_ws_upd>-xfhdw = <fs_info_show>-xfhdw. lv_flag_up = abap_true. ENDIF. ENDLOOP. ENDLOOP. IF lv_flag_up <> abap_true . MESSAGE 'You have not do any changes...' TYPE 'I'. RETURN. ENDIF. * Update Populating Additional data in Material master record CALL FUNCTION 'VBWS_UOM_MAINTAIN_DARK' EXPORTING I_MATNR = p_matnr i_user = sy-uname i_buffer_refresh = 'X' i_no_update = ' ' TABLES E_MEINH_WS = gt_meinh_ws E_MEINH = gt_meinh E_MESSAGE = gt_message I_meinh_ws_upd = gt_meinh_ws_upd I_meinh_ws_updx = gt_meinh_ws_updx E_RETURN = gt_return EXCEPTIONS ERROR = 1 OTHERS = 2 . IF SY-SUBRC <> 0. * Implement suitable error handling here ENDIF. LOOP AT gt_return . IF gt_return-type <> 'E'. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. gv_flag_succ = abap_true. ELSE. lv_err = gt_return-message. gv_flag_succ = abap_false. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. MESSAGE e000(/DSD/OC) WITH lv_err. LEAVE PROGRAM. ENDIF. ENDLOOP. ENDFORM. " CALL_BAPI_OBJCL