Skip to Content

This information would be useful for removing the inconsistency between the CRM and BW Org.Structure mismatches.

Refer the below steps to remove this inconsistency,

Incorrect Org. Unit Assignment shown in BW compared to CRM.

Problem Statement:

Account (BP 1000XXXX) correct position (TEAM A) within the hierarchy in CRM, but in the BW file, its showed under ‘TEAM X’ which did not even existed in CRM Org Structure.

Verify the same using the below filter;

Table: BUT050

PARTNER2: 1000XXXX (Account)

RELTYP: BUR010

It will show 2 entries for the same. Ideally this should have one entry.

Example Screenshot;

/wp-content/uploads/2013/09/but050_288705.jpg

First checking for the below SAP Notes can be checked; 1527945, 1555418 and 1582647.

Later finally a Z report (ZHTTUM_REPAIR_BUT050_CRM) was created as below;

This can later be executed using se38. Post execution, the table BUT050 will have one value with RELTYP – BUR010.

ZHTTUM_REPAIR_BUT050_CRM

*&———————————————————————*

*& Report  ZHTTUM_REPAIR_BUT050_CRM

*&

*&———————————————————————*

*& remove inconsistent entries from BUT050 which still exist after employee

*& has moved to other org.unit:

*& – bp_org, bp_emp filled: remove single inconsistent entry

*& – bp_org, bp_emp empty: check all entries and remove inconsistent ones

*&———————————————————————*

REPORT  zhttum_repair_but050_crm.

TYPES: BEGIN OF bp_double_struct,

         bp        TYPE bu_partner,

         pernr     TYPE hrobjid,

         cp        TYPE hrobjid,

         bp_org    TYPE bu_partner,

         ambigous  TYPE flag,

         differing TYPE flag,

       END OF bp_double_struct.

PARAMETERS: bp_org  TYPE but050-partner1,

            bp_emp  TYPE but050-partner2.

PARAMETERS: lv_test TYPE flag DEFAULT ‘X’.

DATA: lt_but050         TYPE STANDARD TABLE OF but050,

      ls_but050         TYPE but050,

      lt_doubles        TYPE STANDARD TABLE OF but050,

      lt_delete_but052  TYPE STANDARD TABLE OF but052,

      ls_temp1          TYPE but050,

      lv_in_double_mode TYPE c,

      lv_partner        TYPE bu_partner,

      lt_doubles_bp     TYPE STANDARD TABLE OF bp_double_struct,

      ls_doubles_bp     TYPE bp_double_struct,

      lt_objext         TYPE STANDARD TABLE OF hrsobid,

      ls_objext         TYPE hrsobid,

      lt_object         TYPE hrtb_objkey,

      ls_object         TYPE hrobject,

      lt_p1001          TYPE STANDARD TABLE OF p1001,

      ls_p1001          TYPE p1001,

      lt_i1001          TYPE STANDARD TABLE OF hri1001,

      lv_plvar          TYPE plvar,

      lt_path           TYPE STANDARD TABLE OF t77aw,

      ls_path           TYPE t77aw,

      lv_wegid          TYPE wegid,

      ls_object_roots   TYPE hrrootob,

      lt_object_roots   TYPE STANDARD TABLE OF hrrootob,

      lt_sturc_result   TYPE STANDARD TABLE OF objec,

      lt_return         TYPE bapiret2_t,

      lv_counter        TYPE i.

FIELD-SYMBOLS: <ls_but050>           TYPE but050,

               <ls_bp_double_struct> TYPE bp_double_struct,

               <ls_hri1001>          TYPE hri1001,

               <ls_p1001>            TYPE p1001,

               <ls_objec>            TYPE objec.

END-OF-SELECTION.

********* INIZIALISATION

***********************************************

  CALL FUNCTION ‘RH_GET_ACTIVE_WF_PLVAR’

    IMPORTING

      act_plvar = lv_plvar

    EXCEPTIONS

      OTHERS    = 0.

********* PROCESSING

***************************************************

**get all BP-BP relationships

  IF bp_org IS INITIAL AND

     bp_emp IS INITIAL.

    SELECT * FROM but050

                  INTO TABLE lt_but050

                  WHERE reltyp = ‘BUR010’.

  ELSE.

    SELECT * FROM but050

                  INTO TABLE lt_but050

                  WHERE reltyp = ‘BUR010’

                    AND partner1 = bp_org

                    AND partner2 = bp_emp.

  ENDIF.

* build up lt_doubles and lt_doubles_bp

* lt_doubles contains all but050 of BPemps having multiple relations

* lt_doubles_bp is a list of all BPemps having multiple relations

  IF bp_org IS INITIAL AND

     bp_emp IS INITIAL.

    SORT lt_but050 BY partner2.

    LOOP AT lt_but050 ASSIGNING <ls_but050>.

      IF lv_partner EQ <ls_but050>-partner2.

        IF lv_in_double_mode IS INITIAL.

          APPEND ls_temp1 TO lt_doubles.

          ls_doubles_bp-bp = <ls_but050>-partner2.

          APPEND ls_doubles_bp TO lt_doubles_bp.

        ENDIF.

        APPEND <ls_but050> TO lt_doubles.

        lv_in_double_mode = ‘X’.

      ELSE.

        lv_partner = <ls_but050>-partner2.

        ls_temp1 = <ls_but050>.

        CLEAR lv_in_double_mode.

      ENDIF.

    ENDLOOP.

  ELSE.

    READ TABLE lt_but050 ASSIGNING <ls_but050> INDEX 1.

    IF sy-subrc EQ 0.

      ls_doubles_bp-bp = <ls_but050>-partner2.

      APPEND ls_doubles_bp TO lt_doubles_bp.

      APPEND <ls_but050> TO lt_doubles.

    ENDIF.

  ENDIF.

* build up lt_objext from BPemps

  ls_objext-plvar = lv_plvar.

  ls_objext-otype = ‘BP’.

  LOOP AT lt_doubles_bp ASSIGNING <ls_bp_double_struct>.

    ls_objext-sobid = <ls_bp_double_struct>-bp.

    COLLECT ls_objext INTO lt_objext.

  ENDLOOP.

* read corresponding CPs

  IF NOT lt_objext IS INITIAL.

    CALL FUNCTION ‘RH_READ_INFTY_1001_EXT’

      EXPORTING

        authority       = space

        with_stru_auth  = space

        istat           = ‘1’

        extend          = ‘X’

        subty           = ‘A207’

        begda           = sy-datum

        endda           = sy-datum

        sort            = ‘ ‘

        with_ev_for_int = ‘ ‘

        with_ev_for_ext = ‘ ‘

        adata           = ‘ ‘

      TABLES

        i1001           = lt_i1001

        OBJECTS         = lt_objext

      EXCEPTIONS

        nothing_found   = 1

        wrong_condition = 2

        OTHERS          = 3.

  ENDIF.

* put CP number to lt_doubles_bp

  SORT lt_doubles_bp BY bp.

  LOOP AT lt_i1001 ASSIGNING <ls_hri1001>.

    READ TABLE lt_doubles_bp WITH KEY bp = <ls_hri1001>-objid

                             ASSIGNING <ls_bp_double_struct>

                             BINARY SEARCH.

    IF sy-subrc EQ 0.

      <ls_bp_double_struct>-cp = <ls_hri1001>-sobid.

    ENDIF.

  ENDLOOP.

* build up lt_path for CP -> S -> O -> BP

* CP -> S

  ls_path-wegnr = ‘1’.

  ls_path-otype = ‘CP’.

  ls_path-rsign = ‘B’.

  ls_path-relat = ‘008’.

  ls_path-priox = ‘*’.

  ls_path-sclas = ‘S’.

  ls_path-skipf = ‘X’.

  APPEND ls_path TO lt_path.

* S -> O

  ls_path-wegnr = ‘2’.

  ls_path-otype = ‘S’.

  ls_path-rsign = ‘A’.

  ls_path-relat = ‘003’.

  ls_path-priox = ‘*’.

  ls_path-sclas = ‘O’.

  ls_path-skipf = ‘X’.

  APPEND ls_path TO lt_path.

* O -> BP

  ls_path-wegnr = ‘3’.

  ls_path-otype = ‘O’.

  ls_path-rsign = ‘B’.

  ls_path-relat = ‘207’.

  ls_path-priox = ‘*’.

  ls_path-sclas = ‘BP’.

  ls_path-skipf = ”.

  APPEND ls_path TO lt_path.

* build path

  CALL FUNCTION ‘PATH_BUILD’

    IMPORTING

      path_id = lv_wegid

    TABLES

      77aw    = lt_path.

* build up lt_object_roots

  ls_object_roots-otype = ‘CP’.

  LOOP AT lt_doubles_bp ASSIGNING <ls_bp_double_struct>

                        WHERE NOT cp IS INITIAL.

    ls_object_roots-objid = <ls_bp_double_struct>-cp.

    APPEND ls_object_roots TO lt_object_roots.

  ENDLOOP.

* get BPs in role org.-unit

  IF NOT lt_object_roots IS INITIAL.

    CALL FUNCTION ‘RH_STRUC_GET_MULTIPLE_ROOTS’

      EXPORTING

        act_wegid       = lv_wegid

        act_int_flag    = ‘X’

        act_plvar       = lv_plvar

        authority_check = space

      TABLES

        root_objects    = lt_object_roots

        result_objec    = lt_sturc_result

      EXCEPTIONS

        no_plvar_found  = 1

        no_entry_found  = 2

        path_not_found  = 3

        root_not_found  = 4

        OTHERS          = 5.

  ENDIF.

* get org. assignment, compare with BP-BP relationship;

* remove correct assignment from lt_doubles.

  SORT lt_doubles_bp BY cp.

  SORT lt_doubles BY partner2 partner1.

  LOOP AT lt_sturc_result ASSIGNING <ls_objec>.

    CASE <ls_objec>-otype.

      WHEN ‘CP’.

        lv_counter = 0.

        READ TABLE lt_doubles_bp WITH KEY cp = <ls_objec>-objid

                                 ASSIGNING <ls_bp_double_struct>

                                 BINARY SEARCH.

        IF sy-subrc NE 0.

          UNASSIGN <ls_bp_double_struct>.

        ENDIF.

      WHEN ‘BP’.

        IF <ls_bp_double_struct> IS ASSIGNED.

*         remove correct BP-BP rel. from lt_doubles[]

          READ TABLE lt_doubles WITH KEY partner2 = <ls_bp_double_struct>-bp

                                         partner1 = <ls_objec>-realo

                                ASSIGNING <ls_but050>

                                BINARY SEARCH.

          IF sy-subrc EQ 0.

            DELETE TABLE lt_doubles FROM <ls_but050>.

          ENDIF.

        ENDIF.

    ENDCASE.

  ENDLOOP.

********* OUTPUT ***************************************************

  DESCRIBE TABLE lt_doubles LINES lv_counter.

  IF lv_test EQ ‘X’.

    WRITE: / ‘test run, no data will be changed’.

    WRITE: /.

    WRITE: /.

    IF lv_counter GT 0.

      WRITE: / ‘The following BP relationships will be deleted:’.

    ELSE.

      WRITE: / ‘No inconsistent BP-BP relationships found’.

    ENDIF.

    WRITE: /.

    LOOP AT lt_doubles ASSIGNING <ls_but050>.

      WRITE: / <ls_but050>.

    ENDLOOP.

  ELSE.

    WRITE: / ‘no test run, data will be changed’.

    WRITE: /.

    WRITE: /.

******* MODIFY DATABASE **********************************************

    lv_counter = 0.

    LOOP AT lt_doubles ASSIGNING <ls_but050>.

      CLEAR lt_return[].

      lv_counter = lv_counter + 1.

      IF lv_counter = 1.

        WRITE: / ‘The following BP-BP relationships have been deleted:’.

        WRITE: /.

      ENDIF.

      CALL FUNCTION ‘BUPR_EMPLO_DELETE’

        EXPORTING

          iv_partner   = <ls_but050>-partner1

          iv_employee  = <ls_but050>-partner2

          iv_date_from = <ls_but050>-date_from

          iv_date_to   = <ls_but050>-date_to

        TABLES

          et_return   = lt_return.

      DELETE lt_return WHERE type <> ‘E’

                         AND type <> ‘A’

                         AND type <> ‘X’.

      IF lt_return[] IS INITIAL.

        WRITE: / <ls_but050>.

        CALL FUNCTION ‘BUPA_CENTRAL_EXPL_SAVE_HR’.

        CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’.

      ELSE.

        CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.

      ENDIF.

    ENDLOOP.

    IF sy-subrc NE 0.

      WRITE: / ‘No inconsistent BP-BP relationships found’.

    ENDIF.

  ENDIF.

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply