*&---------------------------------------------------------------------* *& Report Z_CHANGE_PGUID_002 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT z_change_pguid_002 . INCLUDE bbp_pd_con. TABLES: crmd_partner, but000. DATA: lt_relationships LIKE bapibus1006_relations OCCURS 0, lt_return LIKE bapiret2 OCCURS 0, cs_relationship LIKE bapibus1006_relations, iv_partner_guid TYPE bapibus1006_head-partnerguid. DATA: l_partner_org TYPE bu_partner, l_addr_num TYPE ad_addrnum, l_addresses_int LIKE bapibus1006_addresses_int OCCURS 0 WITH HEADER LINE, l_return LIKE bapiret2 OCCURS 0. DATA: lt_partner TYPE STANDARD TABLE OF bbp_pds_partner, lt_partner_c TYPE STANDARD TABLE OF bbp_pds_partner, wa_partner TYPE bbp_pds_partner, lt_but000 TYPE TABLE OF but000, newguid LIKE crmd_partner-guid, lt_guid TYPE bbpt_guid, lt_partner_guid TYPE bbpt_guid, lt_partner_collect TYPE STANDARD TABLE OF bbp_pds_partner. FIELD-SYMBOLS: TYPE bbp_guid_tab. TABLES: crmd_orderadm_h. * ID as select options SELECT-OPTIONS doc_num FOR crmd_orderadm_h-object_id OBLIGATORY. PARAMETERS: obj_type LIKE crmd_orderadm_h-object_type OBLIGATORY MATCHCODE OBJECT bbp_object_type_process, oldbp LIKE but000-partner OBLIGATORY, newbp LIKE but000-partner OBLIGATORY, p_test AS CHECKBOX DEFAULT 'X'. START-OF-SELECTION. * Check object validity IF obj_type EQ c_po OR obj_type EQ c_shop OR obj_type EQ c_grse OR obj_type EQ c_invoice OR obj_type EQ c_contract OR obj_type EQ c_biddingdoc. ELSE. WRITE: 'Object type', obj_type, 'not supported'. EXIT. ENDIF. * Call document selection SELECT guid FROM crmd_orderadm_h INTO TABLE lt_guid WHERE object_id IN doc_num AND object_type = obj_type. * Need to call BP GUID of newbp SELECT SINGLE partner_guid FROM but000 INTO newguid WHERE partner = newbp. IF sy-subrc NE 0. WRITE: 'Partner', newbp, 'does not exist'. EXIT. ENDIF. LOOP AT lt_guid ASSIGNING . * call Document data. CALL FUNCTION 'BBP_PROCDOC_GETDETAIL' EXPORTING i_guid = -guid i_object_type = obj_type TABLES e_partner = lt_partner. * Add change version partners PERFORM get_chgversion_partner TABLES lt_partner_c USING -guid. IF NOT lt_partner_c[] IS INITIAL. APPEND LINES OF lt_partner_c TO lt_partner. ENDIF. * Collect partners APPEND LINES OF lt_partner TO lt_partner_collect. ENDLOOP. LOOP AT lt_partner_collect INTO wa_partner WHERE partner_id = oldbp. IF p_test NE 'X'. READ TABLE lt_guid WITH KEY guid = wa_partner-p_guid TRANSPORTING NO FIELDS. IF sy-subrc EQ 0. UPDATE BBPD_PD_INDEX_H SET partner_no = newguid WHERE partner_guid = wa_partner-partner_guid. ELSE. UPDATE BBPD_PD_INDEX_I SET ipartner_no = newguid WHERE ipartner_guid = wa_partner-partner_guid. ENDIF. UPDATE crmd_partner SET partner_no = newguid WHERE partner_guid = wa_partner-partner_guid. * Change address number of CRMD_PARTNER, in order to update ADDR3_DATA. SELECT SINGLE persnumber FROM but000 INTO wa_partner-addr_no WHERE partner_guid = newguid. UPDATE crmd_partner SET addr_np = wa_partner-addr_no WHERE partner_guid = wa_partner-partner_guid. iv_partner_guid = newguid. * Get organization BP number for responsible requestor. CALL FUNCTION 'BUPA_RELATIONSHIPS_GET' EXPORTING businesspartnerguid = iv_partner_guid TABLES et_relationships = lt_relationships et_return = lt_return. READ TABLE lt_relationships INTO cs_relationship INDEX 1. l_partner_org = cs_relationship-partner1. * get address from BUT020 CALL FUNCTION 'BUPA_ADDRESSES_GET' EXPORTING iv_partner = l_partner_org IMPORTING ev_standard_addrnumber = l_addr_num TABLES et_addresses = l_addresses_int et_return = l_return. IF sy-subrc = 0. * Update addr_nr UPDATE crmd_partner SET addr_nr = l_addr_num WHERE partner_guid = wa_partner-partner_guid. * Write: Display result. WRITE: / wa_partner-partner_id, ' has been changed'. ELSE. WRITE: 'ERROR updating database'. ENDIF. COMMIT WORK AND WAIT. ELSE. WRITE: / 'Business partner', wa_partner-partner_id, ' will be updated in document'. ENDIF. ENDLOOP. IF sy-subrc NE 0. WRITE: 'No data found for DB update'. ENDIF. *&---------------------------------------------------------------------* *& Form get_chgversion_partner *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_LT_PARTNER_C text *----------------------------------------------------------------------* FORM get_chgversion_partner TABLES p_lt_partner_c STRUCTURE bbp_pds_partner "Bitte korrekten Namen für <...> einfügen. USING p_guid TYPE crmt_object_guid. DATA: lt_it_header_guids TYPE TABLE OF bbp_guid_tab, ls_it_header_guids LIKE LINE OF lt_it_header_guids, lt_et_pdlist TYPE TABLE OF bbp_pds_version_list_internal, ls_et_pdlist LIKE LINE OF lt_it_header_guids, ls_bbp_pds_header TYPE bbp_pds_header. ls_it_header_guids-guid = p_guid. APPEND ls_it_header_guids TO lt_it_header_guids. * get the actual change version CALL FUNCTION 'BBP_PROCDOC_GET_CHANGE_VERSION' TABLES it_header_guids = lt_it_header_guids et_pdlist = lt_et_pdlist. * we need the guid of the change version READ TABLE lt_et_pdlist INDEX 1 INTO ls_et_pdlist. IF sy-subrc = 0. * get the details of the change version CALL FUNCTION 'BBP_PROCDOC_GETDETAIL' EXPORTING i_guid = ls_et_pdlist-guid IMPORTING e_header = ls_bbp_pds_header TABLES e_partner = p_lt_partner_c. ENDIF. ENDFORM. " get_chgversion_partner