Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

最近做的另外一个问题啊。也比较有意思的一个,是说BUPA_DEL的Inconsistence。
比方说,建立一个BP, 然后把这个BP作为Sold to party assign给一个IBASE, 之后,

把这个sold to party 从IBASE删除,追后用Tr-cd:BUPA_DEL去删除这个BP,但是有的

情况下,这个BP删不掉,这是因为在table ADRV里有Inconsistence。

如果碰到这样的问题,请打NOTE 1278759, 通过这个note, 可以确保以后不发生问题,

但是对于已经出现这样问题的BP, 大家需要执行一个报告去将他们修正。我把报告写

在这里边,大家可以参考。

*&---------------------------------------------------------------------*
*& Report  ZREPAIR_ADR_WHEREUSED
*&
*&---------------------------------------------------------------------*
*& SAP Note: 1278759
*&
*& Report to fix BP' that are failing in replication. This report is used
*& to delete unwanted entries in ADRV table in CRM system.
*&
*&---------------------------------------------------------------------*

REPORT  ZREPAIR_ADR_WHEREUSED.

include com_partner.
TABLES: crmd_partner.

SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME.
PARAMETERS:     SIMULATE AS CHECKBOX DEFAULT 'X'.
PARAMETERS:     PROG(1).
SELECTION-SCREEN END OF BLOCK BL1.

DATA: lt_partner         LIKE TABLE OF crmd_partner,
      lt_adrv            LIKE TABLE OF ADRV,
      lt_adrvp           LIKE TABLE OF ADRVP,
      ls_adrv            type adrv,
      ls_adrvp           type adrvp,
      ls_partner         type crmd_partner,
      lv_partner_guid    type BU_PARTNER_GUID,
      ls_but020          type but020,
      ls_but000          type but000,
      lv_addr_nr         type ad_addrnum,
      lv_addr_origin     type crmt_addr_origin,
      lv_guid_set        type crmt_object_guid,
      lv_appl_key        type AD_APPLKEY,
      lv_guid            type string,
      lv_subrc1          like sy-subrc,
      lv_subrc2          like sy-subrc,
      partner_number(10).
DATA:
  cursor1 type CURSOR,
  p_size type i.

CASE PROG.
  WHEN 'A'.

    p_size = 50000.
    open cursor cursor1 for select * from crmd_partner WHERE
                          ADDR_ORIGIN eq 'B'.

    DO.
      clear lt_partner.
      fetch next cursor cursor1 into table lt_partner
          package size p_size.
      IF SY-SUBRC <> 0.
        CLOSE CURSOR CURSOR1.
        EXIT.
      ENDIF.
      LOOP AT lt_partner INTO ls_partner.
        CLEAR: lv_partner_guid,
               partner_number,
               ls_but020,
               ls_but000,
               lt_adrv,
               lt_adrvp,
               ls_adrvp,
               ls_adrv,
               lv_appl_key,
               lv_subrc1,
               lv_subrc2.
        lv_partner_guid = ls_partner-PARTNER_NO.
        call function 'COM_PARTNER_CONVERT_GUID_TO_NO'
          EXPORTING
            IV_PARTNER_GUID        = lv_partner_guid
          IMPORTING
            EV_PARTNER             = partner_number
          EXCEPTIONS
            PARTNER_DOES_NOT_EXIST = 1
            OTHERS                 = 2.
        IF sy-subrc = 0.
          select single *  from but020 into ls_but020 where PARTNER = partner_number
                                                        and ADDRNUMBER = ls_partner-addr_nr.
          lv_subrc1 = sy-subrc.
          select single * from but000 into ls_but000 where PARTNER = partner_number
                                                       and PERSNUMBER = ls_partner-addr_np.
          lv_subrc2 = sy-subrc.
          IF ( lv_subrc1 = 0 AND NOT ls_but020-ADDRNUMBER IS INITIAL ) OR
             ( lv_subrc2 = 0 AND NOT ls_but000-persnumber IS INITIAL ).
            ls_partner-ADDR_ORIGIN = 'A'.
            MOVE ls_partner-guid to lv_guid.
            CONCATENATE sy-mandt lv_guid INTO lv_appl_key.
          ELSE.
            CONTINUE.
          ENDIF.
          IF simulate = 'X'.
            write: 'SIMULATION MODE', /,/.
            write: 'Incorrect partner ', partner_number, ' has invalid addr_origin', /.
            IF ls_partner-addr_np IS INITIAL.
              SELECT * FROM ADRV INTO TABLE lt_adrv
                          WHERE addrnumber = ls_partner-addr_nr
                            AND appl_table = 'CRMPARTNER'
                            AND appl_field = 'ADDR_NR'
                            AND APPL_KEY   =  lv_appl_key.
              IF sy-subrc = 0.
                LOOP AT lt_adrv INTO ls_adrv.
                  WRITE: 'The following where used list will be deleted:'.
                  WRITE: 'Table: ADRV,', 'ADDRNUMBER:', ls_adrv-addrnumber, ',', 'APPL_KEY', ls_adrv-appl_key.
                  WRITE: 'Partner function in the transaction: ', ls_partner-partner_fct, /.
                ENDLOOP.
              ENDIF.
            ELSEIF NOT ls_partner-addr_np IS INITIAL.
              SELECT * FROM ADRVP INTO TABLE lt_adrvp
                          WHERE persnumber = ls_partner-addr_np
                            AND appl_table = 'CRMPARTNER'
                            AND appl_field = 'ADDR_NP'
                            AND APPL_KEY   =  lv_appl_key.
              IF sy-subrc = 0.
                LOOP AT lt_adrvp INTO ls_adrvp.
                  WRITE: 'The following where used list will be deleted:'.
                  WRITE: 'Table: ADRVP,', 'ADDRNUMBER:', ls_partner-addr_nr, 'PERSNUMBER:', ls_adrvp-persnumber, ',', 'APPL_KEY', ls_adrvp-appl_key.
                  WRITE: 'Partner function in the transaction: ', ls_partner-partner_fct, /.
                ENDLOOP.
              ENDIF.
            ENDIF.
            ULINE.
          ELSEIF simulate = space.
            MODIFY crmd_partner FROM ls_partner.
            IF ls_partner-addr_np IS INITIAL.
              SELECT * FROM ADRV INTO TABLE lt_adrv
                          WHERE addrnumber = ls_partner-addr_nr
                            AND appl_table = 'CRMPARTNER'
                            AND appl_field = 'ADDR_NR'.
              IF sy-subrc = 0.
                LOOP AT lt_adrv INTO ls_adrv.
                  DELETE adrv from ls_adrv.
                ENDLOOP.
              ENDIF.
            ELSEIF NOT ls_partner-addr_np IS INITIAL.
              SELECT * FROM ADRVP INTO TABLE lt_adrvp
                          WHERE persnumber = ls_partner-addr_np
                            AND appl_table = 'CRMPARTNER'
                            AND appl_field = 'ADDR_NP'.
              IF sy-subrc = 0.
                LOOP AT lt_adrvp INTO ls_adrvp.
                  DELETE adrvp from ls_adrvp.
                ENDLOOP.
              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDDO.

  WHEN 'B'.

    p_size = 10000.
    open cursor cursor1 for select * from ADRV
                        WHERE APPL_TABLE = 'CRMPARTNER'
                          AND APPL_FIELD = 'ADDR_NR'.

    DO.
      clear lt_adrv.
      fetch next cursor cursor1 into table lt_adrv
          package size p_size.
      IF SY-SUBRC <> 0.
        CLOSE CURSOR CURSOR1.
        EXIT.
      ENDIF.
      LOOP AT lt_adrv INTO ls_adrv.
        CLEAR: lv_addr_nr,
               lt_partner,
               lv_guid_set,
               ls_partner.
        lv_addr_nr  = ls_adrv-addrnumber.
        lv_guid_set = ls_adrv-appl_key+3.
        SELECT * FROM CRMD_PARTNER INTO TABLE lt_partner
              WHERE GUID    = lv_guid_set
                AND ADDR_NR = lv_addr_nr.
        LOOP AT lt_partner INTO ls_partner
             WHERE ADDR_ORIGIN = 'B'.
        ENDLOOP.
        IF sy-subrc <> 0.
          IF simulate = 'X'.
            WRITE: 'Following ADRV entry to be deleted:'.
            WRITE: 'ADDRNUMBER: ',lv_addr_nr, 'CONSNUMBER: ', ls_adrv-consnumber, 'APPL_KEY: ', ls_adrv-appl_key.
            SKIP.
          ELSEIF simulate = space.
            DELETE adrv from ls_adrv.
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDDO.

ENDCASE.

IF SIMULATE = space.
  COMMIT WORK AND WAIT.
ENDIF.

  • No labels