目录
问题:物料名称重名,影响正常下单等等... ...
处理方式:
1 通过abap脚本找出重复的数据
2 分析重复原因
3 出具解决方案
?
*&---------------------------------------------------------------------*
*& Report ZMM030
*&---------------------------------------------------------------------*
*& 事务代码:ZMM030 *
*& 程序名称:ZMM030 物料去重排查 *
*& 请 求 号: *
*& 程序目的: *
*& 创 建 人:TerryZhong *
*& 设计时间: *
*& 程序类型: ABAP/4 程序 ,数据转换 *
*& 输入文件: *
*& 输出文件: *
*& 描 述: *
*&---------------------------------------------------------------------*
*---------------------------------------------------------------------------------------------------------------------*
*** Modification LOG *
*---------------------------------------------------------------------------------------------------------------------*
*Date | Userid | Reason | Request No | Description of Change *
*
*---------------------------------------------------------------------------------------------------------------------*
REPORT zmm030.
INCLUDE zmm030_top.
INCLUDE zmm030_sel.
INCLUDE zmm030_frm.
INCLUDE zmm030_pbo.
INCLUDE zmm030_pai.
INITIALIZATION.
AT SELECTION-SCREEN.
START-OF-SELECTION.
PERFORM get_data.
PERFORM set_catalog.
PERFORM display_alv.
*&---------------------------------------------------------------------*
*& Form display_alv
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM display_alv .
DATA: ls_layout TYPE lvc_s_layo.
IF gt_data IS NOT INITIAL.
ls_layout-zebra = 'X'.
ls_layout-cwidth_opt = 'X'.
* 调用ALV function
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid "这里是调用这个ALV的程序名
i_callback_pf_status_set = 'PF_STATUS' "设置ALV状态栏的函数
i_callback_user_command = 'USER_COMMAND' "获取用户事件的函数
is_layout_lvc = ls_layout "显示的布局
it_fieldcat_lvc = gt_fieldcat_lvc "设置显示的字段以及字段的功能
i_save = 'A'
TABLES
t_outtab = gt_data
EXCEPTIONS
program_error = 1.
IF sy-subrc <> 0.
MESSAGE '报表生成异常,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
ELSE.
* 这个消息用来显示我们是不是获取到了数据,自己用的时候把这个硬代码换成你需要的TEXT-XXX.
MESSAGE '没有获取到数据,请重新检索!' TYPE 'S' DISPLAY LIKE 'E'.
LEAVE TO LIST-PROCESSING.
EXIT.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& 包含 ZFICO042_TOP
*&---------------------------------------------------------------------*
TYPES: BEGIN OF gy_data,
matnr TYPE mara-matnr, "物料号
maktx TYPE makt-maktx, "物料描述
zwlcms TYPE mara-zwlcms, "物料长描述(原来状态)
zwlcms2 TYPE mara-zwlcms, "物料长描述(去空格处理后的状态)
times TYPE i, "重复次数
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
name_text TYPE adrp-name_text,
fd_staff_no TYPE zmm_matnr-fd_staff_no,
fd_name TYPE zmm_matnr-fd_name,
doc_create_time TYPE zmm_matnr-doc_create_time,
END OF gy_data.
DATA gt_data TYPE TABLE OF gy_data.
DATA gs_data TYPE gy_data.
DATA: gt_fieldcat_lvc TYPE lvc_t_fcat, "ALV:定义一个先显示字段的表
gs_fieldcat_lvc LIKE LINE OF gt_fieldcat_lvc. "ALV
TABLES:rbkp,rseg,acdoca,mara.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: so_matn FOR mara-matnr . "物料号
SELECT-OPTIONS: so_zwl FOR mara-zwlcms . "物料长描述
SELECTION-SCREEN END OF BLOCK b1.
*&---------------------------------------------------------------------*
*& 包含 ZZFICO43_FRM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM get_data .
SELECT mara~matnr ,mara~zwlcms,mara~ersda , mara~ernam INTO CORRESPONDING FIELDS OF TABLE @gt_data FROM mara
where mara~matnr in @so_matn
and mara~zwlcms in @so_zwl
.
IF gt_data IS NOT INITIAL.
SELECT usr21~persnumber ,usr21~addrnumber,usr21~bname ,adrp~name_text INTO TABLE @DATA(lt_usr)
FROM usr21 INNER JOIN adrp ON adrp~persnumber = usr21~persnumber
FOR ALL ENTRIES IN @gt_data
WHERE usr21~bname = @gt_data-ernam.
SORT lt_usr BY bname.
SELECT * INTO TABLE @DATA(lt_zmatnr) FROM zmm_matnr FOR ALL ENTRIES IN @gt_data WHERE zmm_matnr~fd_material_coding = @gt_data-matnr.
SORT lt_zmatnr BY fd_material_coding.
ENDIF.
LOOP AT gt_data ASSIGNING FIELD-SYMBOL(<fs1>).
<fs1>-zwlcms2 = <fs1>-zwlcms.
REPLACE ALL OCCURRENCES OF '*' IN <fs1>-zwlcms2 WITH '-'.
REPLACE ALL OCCURRENCES OF '/' IN <fs1>-zwlcms2 WITH '-'.
CONDENSE <fs1>-zwlcms2 NO-GAPS.
ENDLOOP.
DATA(lt_temp) = gt_data.
SORT lt_temp BY zwlcms2.
DATA: lv_i TYPE i.
LOOP AT gt_data ASSIGNING FIELD-SYMBOL(<fs2>).
READ TABLE lt_temp INTO DATA(ls1) WITH KEY zwlcms2 = <fs2>-zwlcms2 BINARY SEARCH.
IF sy-subrc = 0.
lv_i = sy-tabix.
ENDIF.
LOOP AT lt_temp INTO DATA(ls_temp) FROM lv_i.
IF ls_temp-zwlcms2 EQ <fs2>-zwlcms2.
<fs2>-times = <fs2>-times + 1.
ELSE.
EXIT.
ENDIF.
ENDLOOP.
READ TABLE lt_usr INTO DATA(ls_usr) WITH KEY bname = <fs2>-ernam BINARY SEARCH.
IF sy-subrc = 0.
<fs2>-name_text = ls_usr-name_text.
ENDIF.
READ TABLE lt_zmatnr INTO DATA(ls_zmatnr) WITH KEY fd_material_coding = <fs2>-matnr BINARY SEARCH.
IF sy-subrc = 0.
<fs2>-doc_create_time = ls_zmatnr-doc_create_time.
<fs2>-fd_name = ls_zmatnr-fd_name.
<fs2>-fd_staff_no = ls_zmatnr-fd_staff_no.
ENDIF.
ENDLOOP.
SORT gt_data BY zwlcms2 times .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form set_catalog
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM set_catalog .
DATA:lv_position TYPE i VALUE 1.
CLEAR: lv_position.
lv_position = lv_position + 1.
DEFINE df_fieldcat.
CLEAR gs_fieldcat_lvc.
gs_fieldcat_lvc-col_pos = lv_position."ALV 控制: 输出列
gs_fieldcat_lvc-scrtext_m = &1."中字段标签
gs_fieldcat_lvc-fieldname = &2."ALV 控制: 内部表字段的字段名称
gs_fieldcat_lvc-no_zero = &3."ALV 控制: 为输出隐藏零
gs_fieldcat_lvc-checkbox = &4."ALV 控制: 作为复选框输出
gs_fieldcat_lvc-edit = &5."设置可编辑模式
gs_fieldcat_lvc-outputlen = &6."输出长度
gs_fieldcat_lvc-ref_table = &7.
gs_fieldcat_lvc-ref_field = &8.
gs_fieldcat_lvc-datatype = &9.
APPEND gs_fieldcat_lvc TO gt_fieldcat_lvc.
ADD 1 TO lv_position.
END-OF-DEFINITION.
df_fieldcat:
'物料号' 'MATNR' 'X' '' '' '' '' '' '',
"'物料描述' 'MAKTX' 'X' '' '' '' '' '' '',
'物料长描述(原来状态)' 'ZWLCMS' 'X' '' '' '' '' '' '',
'物料长描述(去空格处理后的状态)' 'ZWLCMS2' 'X' '' '' '' '' '' '',
'可能重复次数' 'TIMES' 'X' '' '' '' '' '' '',
'SAP创建日期' 'ERSDA' 'X' '' '' '' '' '' '',
'SAP创建人' 'ERNAM' 'X' '' '' '' '' '' '',
'SAP创建人姓名' 'NAME_TEXT' 'X' '' '' '' '' '' '',
'OA创建日期' 'DOC_CREATE_TIME' 'X' '' '' '' '' '' '',
'OA创建人' 'FD_STAFF_NO' 'X' '' '' '' '' '' '',
'OA创建人姓名' 'FD_NAME' 'X' '' '' '' '' '' ''
.
ENDFORM.
*&---------------------------------------------------------------------*
*& 包含 ZFICO042_PBO
*&---------------------------------------------------------------------*
FORM pf_status USING lt_extab TYPE slis_t_extab.
REFRESH:lt_extab[]. CLEAR:lt_extab.
SET TITLEBAR 'ZSTATUS_TITLE'.
"说明:需要显示的按钮进行注释
* APPEND 'ZSAVE' TO lt_extab.
SET PF-STATUS 'ZSTATUS_001' EXCLUDING lt_extab.
ENDFORM.
*&---------------------------------------------------------------------*
*& 包含 ZFICO042_PAI
*&---------------------------------------------------------------------*
FORM user_command USING i_ucomm TYPE sy-ucomm
i_wa_selfield TYPE slis_selfield.
DATA:gwa_edit TYPE lvc_s_styl,
git_edit TYPE lvc_t_styl.
DATA lv_length TYPE num10.
DATA lr_grid TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = lr_grid.
CALL METHOD lr_grid->check_changed_data.
CALL METHOD lr_grid->refresh_table_display.
i_wa_selfield-refresh = 'X'.
CASE i_ucomm.
WHEN 'ZSAVE'.
WHEN OTHERS.
ENDCASE.
ENDFORM.
REPLACE ALL OCCURRENCES OF '*' IN <fs1>-zwlcms2 WITH '-'.
REPLACE ALL OCCURRENCES OF '/' IN <fs1>-zwlcms2 WITH '-'.
CONDENSE <fs1>-zwlcms2 NO-GAPS. " 去所有空格的替换
LOOP AT gt_data ASSIGNING FIELD-SYMBOL(<fs2>).
READ TABLE lt_temp INTO DATA(ls1) WITH KEY zwlcms2 = <fs2>-zwlcms2 BINARY SEARCH.
IF sy-subrc = 0.
lv_i = sy-tabix.
ENDIF.
LOOP AT lt_temp INTO DATA(ls_temp) FROM lv_i.
IF ls_temp-zwlcms2 EQ <fs2>-zwlcms2.
<fs2>-times = <fs2>-times + 1.
ELSE.
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.