删除 BP 导致 CVI_VEND_LINK 表具有不一致的条目
【摘要】 问题描述在测试环境中发现一个 BP 数据填错了,然后也没法修复,因此想着如果去搜搜删除供应商,使用程序 BUPA_TEST_DELETE ,事务码:bupa_del(这个事务码已经被官方弃用了),这个程序能够把 BP 相关的数据进行删除,但是这个操作只会清空 BUT* 系列与 BP 相关的后台表。找到 202135 这个编号的业务伙伴,这个表在 BUT000 表是有一条后台记录的,演示如下...
问题描述
在测试环境中发现一个 BP 数据填错了,然后也没法修复,因此想着如果去搜搜删除供应商,
使用程序 BUPA_TEST_DELETE
,事务码:bupa_del
(这个事务码已经被官方弃用了),这个程序能够把 BP 相关的数据进行删除,但是这个操作只会清空 BUT*
系列与 BP 相关的后台表。
找到 202135
这个编号的业务伙伴,这个表在 BUT000
表是有一条后台记录的,演示如下:
BUT020
同样也有一条数据,如下:
然后我们执行 BUPA_DEL
事务码:
成功删除如下:
此时再回到 SE16N
已经查不到编号为 202135 的一条记录:
BUT020
也是一样被清空了。
但是对于供应商而言, CVI_VEND_LINK
表中存在条目,虽然 BUT000
表中不存在相应的合作伙伴条目。
就是因为这个问题,会导致如果重复使用这条编号新建 BP 的话会导致错误,所以我们需要将同步表中不一致的数据进行清除。
解决之道
创建报表 ZVENDOR_LINK_CHECK_REPORT
:
- 启动事务码
SE38
,输入报表名称ZVENDOR_LINK_CHECK_REPORT
,并创建 - 然后写入如下代码:
*&---------------------------------------------------------------------*
*& Report ZVENDOR_LINK_CHECK_REPORT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zvendor_link_check_report.
* Local type
TYPES: BEGIN OF lty_bp_vendor_ids,
partner_guid TYPE bu_partner_guid,
vendor TYPE lifnr,
del_flag TYPE boole-boole,
END OF lty_bp_vendor_ids.
* Local data declarations
DATA:
lv_msg TYPE char255,
* lv_lifnr type lfa1-lifnr,
lv_dbcnt TYPE char10,
* lv_partner_guid type but000-partner_guid,
db_vendor TYPE cursor,
ls_bp_vendor_ids TYPE lty_bp_vendor_ids,
lt_bp_vendor_ids TYPE TABLE OF lty_bp_vendor_ids,
ls_entries_to_delete LIKE cvi_vend_link,
lt_entries_to_delete LIKE TABLE OF ls_entries_to_delete.
TYPES: BEGIN OF ty_but000,
partner_guid TYPE bu_partner_guid,
END OF ty_but000.
DATA : lt_but000 TYPE STANDARD TABLE OF ty_but000.
TYPES: BEGIN OF ty_lfa1,
lifnr TYPE lifnr,
END OF ty_lfa1.
DATA : lt_lfa1 TYPE STANDARD TABLE OF ty_lfa1.
CONSTANTS: lc_x TYPE boole-boole VALUE 'X',
lc_pkg_size TYPE char5 VALUE '10000'.
PARAMETERS testmode TYPE boole_d AS CHECKBOX DEFAULT 'X'.
CLEAR: lv_msg,
lv_dbcnt,
ls_bp_vendor_ids,
ls_entries_to_delete.
REFRESH lt_entries_to_delete.
OPEN CURSOR db_vendor FOR
SELECT partner_guid vendor FROM cvi_vend_link.
DO.
CLEAR ls_bp_vendor_ids.
REFRESH lt_bp_vendor_ids.
REFRESH lt_but000.
REFRESH lt_lfa1.
FETCH NEXT CURSOR db_vendor INTO CORRESPONDING FIELDS OF TABLE lt_bp_vendor_ids
PACKAGE SIZE lc_pkg_size.
IF sy-subrc <> 0.
EXIT.
ELSE.
SELECT partner_guid FROM but000 INTO TABLE lt_but000 FOR ALL ENTRIES IN lt_bp_vendor_ids WHERE partner_guid = lt_bp_vendor_ids-partner_guid.
SORT lt_but000 BY partner_guid.
SELECT lifnr FROM lfa1 INTO TABLE lt_lfa1 FOR ALL ENTRIES IN lt_bp_vendor_ids WHERE lifnr = lt_bp_vendor_ids-vendor.
SORT lt_lfa1 BY lifnr.
LOOP AT lt_bp_vendor_ids INTO ls_bp_vendor_ids.
* clear lv_partner_guid.
* select single partner_guid FROM but000
* INTO lv_partner_guid
* WHERE partner_guid = ls_bp_vendor_ids-partner_guid.
READ TABLE lt_but000 WITH KEY partner_guid = ls_bp_vendor_ids-partner_guid TRANSPORTING NO FIELDS BINARY SEARCH.
IF sy-subrc <> 0.
ls_bp_vendor_ids-del_flag = lc_x.
ELSE.
* clear lv_lifnr.
* select single lifnr FROM lfa1
* INTO lv_lifnr
* WHERE lifnr = ls_bp_vendor_ids-vendor.
READ TABLE lt_lfa1 WITH KEY lifnr = ls_bp_vendor_ids-vendor TRANSPORTING NO FIELDS BINARY SEARCH.
IF sy-subrc <> 0.
ls_bp_vendor_ids-del_flag = lc_x.
ENDIF.
ENDIF.
IF ls_bp_vendor_ids-del_flag = lc_x.
CLEAR ls_entries_to_delete.
ls_entries_to_delete-partner_guid = ls_bp_vendor_ids-partner_guid.
ls_entries_to_delete-vendor = ls_bp_vendor_ids-vendor.
APPEND ls_entries_to_delete TO lt_entries_to_delete.
ENDIF.
ENDLOOP.
ENDIF.
ENDDO.
CLOSE CURSOR db_vendor.
IF testmode IS INITIAL.
IF lt_entries_to_delete IS NOT INITIAL.
DELETE cvi_vend_link FROM TABLE lt_entries_to_delete.
WRITE : 'Non Test Run Mode'.
lv_dbcnt = sy-dbcnt.
lv_msg = TEXT-002.
CONCATENATE lv_msg TEXT-003 INTO lv_msg SEPARATED BY space.
CONCATENATE lv_msg lv_dbcnt INTO lv_msg SEPARATED BY space.
COMMIT WORK.
WRITE TEXT-005.
NEW-LINE.
ULINE.
WRITE : 'Business partner GUID'.
WRITE :36 'Venor Number'.
LOOP AT lt_entries_to_delete INTO ls_entries_to_delete.
NEW-LINE.
WRITE: ls_entries_to_delete-partner_guid, space, ls_entries_to_delete-vendor.
CLEAR: ls_entries_to_delete.
ENDLOOP.
ELSE.
lv_msg = TEXT-001.
ENDIF.
WRITE lv_msg.
ELSE.
IF lt_entries_to_delete IS NOT INITIAL.
WRITE : 'Test Run Mode'.
WRITE TEXT-004.
NEW-LINE.
ULINE.
WRITE : 'Business partner GUID'.
WRITE :36 'Vendor Number'.
LOOP AT lt_entries_to_delete INTO ls_entries_to_delete.
NEW-LINE.
WRITE: ls_entries_to_delete-partner_guid, space, ls_entries_to_delete-vendor.
CLEAR: ls_entries_to_delete.
ENDLOOP.
ENDIF.
ENDIF.
- 转到菜单选项“转到 -> 文本元素 -> 文本符号”。添加以下文本符号:
- 001 The link table is already consistent. No changes were required.
- 002 The link table has been made consistent.
- 003 Number of records made consistent:
如图所示:
- 保存并激活文本符号
- 保存并激活报表,取消勾选测试模式
注意,这个报表程序会找出不一致的数据,本案例中的 202135
,然后进行后台数据清除,如下:
后注:如果你在删除这个 BP 之后,还需要使用这个编号,在后续创建 BP 之后还需要使用 FLBPC2 事务码将 BP 和供应商进行关联,这个后续再出一篇文章。
再来查询后台表已经查询 No values found
:
推荐阅读官方 Note:
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)