on 2016 Apr 15 8:08 PM
Hi All,
I am working on one of the requirement for service confirmation where I need to change the business partner to different partner..Suppose while creating service confirmation it will default employee responsible to user business partner.(Like 0001) after that I need to change that partner to different partner number(0002).
I know we can achieve this using FM CRM_PARTNER_MAINTAIN_MULTI_OW.
But in my case the function module is returning sy-subrc 0 but business partner data is not getting updated even though i used commit statement after function module call.
My question while we change the business partner: Do we have to delete existing partner function and business partner entry and crate new one or can we replace the business partner directly..
Here is sample code which is not working..can anyone suggest me is their any thing wrong in the code. lt_partner_n is current business partner and
lt_partner_old contains business partner that needs to be replaced in lt_partner_n.
READ TABLE lt_partner_n INTO ls_partner_n WITH KEY partner_fct = '00000052'.
IF sy-subrc EQ 0.
*Modify executive service employee group partner and employee responsible partner
READ TABLE lt_partner_old INTO ls_partner_old WITH KEY ref_guid = iv_old_guid
partner_fct = '00000052'.
IF sy-subrc EQ 0.
* ls_partner_new-ref_guid = iv_new_guid.
* ls_partner_new-ref_kind = 'A'.
* ls_partner_new-ref_handle = ls_partner_old-ref_handle.
* ls_partner_new-kind_of_entry = ' ' . " created manually
* ls_partner_new-partner_fct = ls_partner_old-ref_partner_fct.
* ls_partner_new-no_type = 'BP'.
* ls_partner_new-display_type = 'BP'.
* ls_partner_new-partner_no = ls_partner_old-partner_no.
*
* INSERT ls_partner_new INTO TABLE lt_partner_new.
***Populate CT_INPUT_FIELDS names
*
* CLEAR : cs_input_fields."input_fields_t, input_fields_s.
* cs_input_fields-ref_handle = ls_partner_old-ref_handle.
* cs_input_fields-ref_guid = iv_new_guid.
* cs_input_fields-ref_kind = 'A'.
* cs_input_fields-objectname = 'PARTNER'.
* CONCATENATE l_v_handle_i ls_partner_new-partner_fct ls_partner_new-partner_no ls_partner_new-no_type
* ls_partner_new-display_type INTO cs_input_fields-logical_key.
** cs_input_fields-logical_key = '0001'.
*
* input_fields_s-fieldname = 'DISPLAY_TYPE'.
* INSERT input_fields_s INTO TABLE input_fields_t.
* input_fields_s-fieldname = 'KIND_OF_ENTRY'.
* INSERT input_fields_s INTO TABLE input_fields_t.
* input_fields_s-fieldname = 'MAINPARTNER'.
* INSERT input_fields_s INTO TABLE input_fields_t.
* input_fields_s-fieldname = 'NO_TYPE'.
* INSERT input_fields_s INTO TABLE input_fields_t.
* input_fields_s-fieldname = 'PARTNER_FCT'.
* INSERT input_fields_s INTO TABLE input_fields_t.
* input_fields_s-fieldname = 'PARTNER_NO'.
* INSERT input_fields_s INTO TABLE input_fields_t.
*
* cs_input_fields-field_names[] = input_fields_t.
* INSERT cs_input_fields INTO TABLE ct_input_fields.
*Replacing the existing partner
MOVE-CORRESPONDING ls_partner_n TO ls_partner_new.
ls_partner_new-partner_no = ls_partner_old-partner_no.
ls_partner_new-partner_fct = '00000052'.
ls_partner_new-ref_partner_no = ls_partner_old-partner_no.
ls_partner_new-partner_guid = ls_partner_old-partner_guid.
INSERT ls_partner_new INTO TABLE lt_partner_new.
lv_logical_key = ls_partner_n-ref_partner_handle .
lv_logical_key+4(8) = ls_partner_n-ref_partner_fct .
lv_logical_key+12(20) = ls_partner_old-partner_no.
lv_logical_key+32(2) = ls_partner_n-ref_no_type .
lv_logical_key+34(2) = ls_partner_n-ref_display_type .
cs_input_fields-ref_guid = iv_new_guid .
cs_input_fields-ref_kind = 'A'.
cs_input_fields-objectname = 'PARTNER'.
cs_input_fields-logical_key = lv_logical_key.
input_fields_s-fieldname = 'PARTNER_FCT'.
INSERT input_fields_s INTO TABLE input_fields_t.
cs_input_fields-field_names[] = input_fields_t.
INSERT cs_input_fields INTO TABLE ct_input_fields.
ENDIF.
ENDIF.
ENDIF.
CALL FUNCTION 'CRM_PARTNER_MAINTAIN_MULTI_OW'
EXPORTING
it_partner_com = lt_partner_new
iv_ref_guid = iv_new_guid
iv_ref_kind = 'A'
* IV_REF_HANDLE =
* IS_PARTNER_CONTROL =
* IV_EXTERNAL_CALL = FALSE
* IMPORTING
* ET_CREATED_PARTNERSET_GUID =
CHANGING
ct_input_fields = ct_input_fields
* CT_PARTNER_ATTRIBUTES_COM =
EXCEPTIONS
error_occurred = 1
OTHERS = 2.
IF sy-subrc EQ 0.
COMMIT WORK.
* Implement suitable error handling here
ENDIF.
*End of changes by lakkirsx
Hello,
It would be good to check from tcode level whether it is allowing to make changes in partner data . If yes then it should work with program too. Please register it for saving after the call for FM.
BR/Himayat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All,
I did all the above things..it's allowing to change at transaction level and i have used CRM_ORDER_SAVE and not populated the logical key.But the partner is not changing with new value..
Even i tried to use CRM_ORDER_MAINTAIN FM instead of CRM_PARTNER_MAINTAIN_MULTI_OW but no change.
here is sample code where we can give two confirmation number on selection screen.
I still didn't get what is the wrong I am doing here..
DATA: lv_guid_tab TYPE crmt_object_guid_tab,
lv_guid_h TYPE crmt_object_guid.
*Update business partner data in service confirmation
*Begin of changes by lakkirsx
*Read business partner data and update Executive service employee business partner
*With new partner
DATA:lt_partner_old TYPE crmt_partner_external_wrkt,
* lt_partner_new TYPE crmt_partner_external_wrkt,
ls_partner_old TYPE crmt_partner_external_wrk,
lt_partner_n TYPE crmt_partner_external_wrkt,
ls_partner_n TYPE crmt_partner_external_wrk,
* ls_partner_new TYPE crmt_partner_external_wrk,
lt_partner_new TYPE crmt_partner_comt,
ls_partner_new LIKE LINE OF lt_partner_new,
ct_input_fields TYPE crmt_input_field_tab,
cs_input_fields LIKE LINE OF ct_input_fields,
input_fields_t TYPE crmt_input_field_names_tab,
input_fields_s LIKE LINE OF input_fields_t ,
lv_logical_key(42) TYPE c,
l_v_handle_i TYPE crmt_handle VALUE 2,
iv_new_guid TYPE crmt_object_guid,
iv_old_guid TYPE crmt_object_guid.
PARAMETERS : iv_new TYPE crmt_object_guid,
iv_old TYPE crmt_object_guid.
iv_new_guid = iv_new.
iv_old_guid = iv_old.
CALL FUNCTION 'CRM_PARTNER_READ_OW'
EXPORTING
iv_ref_guid = iv_old_guid
iv_ref_kind = 'A'
IMPORTING
et_partner_wrk = lt_partner_old
EXCEPTIONS
error_occurred = 1
parameter_error = 2
entry_does_not_exist = 3
OTHERS = 4.
IF sy-subrc EQ 0.
CALL FUNCTION 'CRM_PARTNER_READ_OW'
EXPORTING
iv_ref_guid = iv_new_guid
iv_ref_kind = 'A'
IMPORTING
et_partner_wrk = lt_partner_n
EXCEPTIONS
error_occurred = 1
parameter_error = 2
entry_does_not_exist = 3
OTHERS = 4.
CALL FUNCTION 'CRM_ORDER_MAINTAIN'
EXPORTING
it_partner = lt_partner_new
it_active_switch = lt_active_switch
* IMPORTING
* ET_EXCEPTION =
CHANGING
* CT_ORDERADM_H =
* CT_ORDERADM_I =
ct_input_fields = ct_input_fields
* CV_LOG_HANDLE =
* CT_PARTNER_ATTRIBUTES =
* CT_DOC_FLOW =
EXCEPTIONS
error_occurred = 1
document_locked = 2
no_change_allowed = 3
no_authority = 4
OTHERS = 5.
IF sy-subrc EQ 0.
DATA: lt_objects_to_save TYPE crmt_object_guid_tab.
APPEND iv_new_guid TO lt_objects_to_save.
CALL FUNCTION 'CRM_ORDER_SAVE'
EXPORTING
it_objects_to_save = lt_objects_to_save
* IV_UPDATE_TASK_LOCAL = FALSE
* IV_SAVE_FRAME_LOG = FALSE
* IV_NO_BDOC_SEND = FALSE
* IT_ACTIVE_SWITCH =
* IMPORTING
* ET_SAVED_OBJECTS =
* ET_EXCEPTION =
* ET_OBJECTS_NOT_SAVED =
* CHANGING
* CV_LOG_HANDLE =
* CT_NOCHECK_BEFORE_SAVE =
* EXCEPTIONS
* DOCUMENT_NOT_SAVED = 1
* OTHERS = 2
.
IF sy-subrc EQ 0.
* Implement suitable error handling here
COMMIT WORK.
ENDIF.
Thanks,
Sapsar.
Hi Sar,
let's start from end:
1) If you really have this code, then uncomment the section starting with EXCEPTIONS. The way you have it, the sy-subrc does not reflect the fact that the call of FM CRM_ORDER_SAVE was succesfull or not. It will take some last value from within the FM's code and if this is not zero, then you will not commit work even the save was OK.
2) Fro my experience, I cannot confirm that you do not have to use the logical key. I always use it and I know that after upgrade from CRM 5.0 to 7.0, the structure slightly changed.
Regards,
Dawood.
Hi,
the fastest way to find out is if you put session breakpoint into FM CRM_ORDER_MAINTAIN, then go to transaction CRMD_ORDER, carry out the partner change operation (recommend to enter partner function and its number in single step to avoid server roundtrip) and there you will see exactly how to fill the interface.
Regards,
Dawood.
Hi Sar,
I am giving you a sample code. This should work for you.
DATA: ls_logical_key TYPE crmt_partner_logic_partner_key.
lv_ref_guid = guid of order.
lv_pfct = '00000052'.
* Read order to fetch existing partners
APPEND 'PARTNER' TO lt_req_obj.
APPEND lv_ref_guid TO lt_hdr_guid.
CALL FUNCTION 'CRM_ORDER_READ'
EXPORTING
it_header_guid = lt_hdr_guid
it_requested_objects = lt_req_obj
IMPORTING
et_partner = lt_partner_wrk
EXCEPTIONS
document_not_found = 1
error_occurred = 2
document_locked = 3
no_change_authority = 4
no_display_authority = 5
no_change_allowed = 6
OTHERS = 7.
CHECK sy-subrc EQ 0.
REFRESH lt_input_field_names.
ls_input_field_names-fieldname = 'DISPLAY_TYPE'.
INSERT ls_input_field_names INTO TABLE lt_input_field_names.
ls_input_field_names-fieldname = 'KIND_OF_ENTRY'.
INSERT ls_input_field_names INTO TABLE lt_input_field_names.
ls_input_field_names-fieldname = 'NO_TYPE'.
INSERT ls_input_field_names INTO TABLE lt_input_field_names.
ls_input_field_names-fieldname = 'PARTNER_FCT'.
INSERT ls_input_field_names INTO TABLE lt_input_field_names.
ls_input_field_names-fieldname = 'PARTNER_NO'.
INSERT ls_input_field_names INTO TABLE lt_input_field_names.
CLEAR: ls_partner_com, ls_logical_key, ls_input_fields, ls_partner_wrk, lv_ref_guid.
ls_input_fields-ref_kind = lv_ref_guid.
READ TABLE lt_partner_wrk INTO ls_partner_wrk
WITH KEY partner_fct = lv_pfct
ref_guid = lv_ref_guid
ref_kind = 'A'.
IF sy-subrc = 0.
MOVE-CORRESPONDING ls_partner_wrk TO ls_logical_key.
MOVE-CORRESPONDING ls_partner_wrk TO ls_partner_com.
ELSE.
ls_partner_com-ref_guid = lv_ref_guid.
ls_partner_com-display_type = 'BP'.
ls_partner_com-no_type = 'BP'.
ls_partner_com-partner_fct = lv_pfct.
ENDIF.
ls_partner_com-kind_of_entry = 'C'.
ls_partner_com-partner_no = new employee responsible.
INSERT ls_partner_com INTO TABLE lt_partner_com.
ls_input_fields-ref_guid = lv_ref_guid.
ls_input_fields-logical_key = ls_logical_key.
ls_input_fields-objectname = 'PARTNER'.
ls_input_fields-field_names = lt_input_field_names.
INSERT ls_input_fields INTO TABLE lt_input_fields.
CALL FUNCTION 'CRM_ORDER_MAINTAIN'
EXPORTING
it_partner = lt_partner_com
CHANGING
ct_input_fields = lt_input_fields
EXCEPTIONS
error_occurred = 1
document_locked = 2
no_change_allowed = 3
no_authority = 4
OTHERS = 5.
IF sy-subrc EQ 0.
CALL FUNCTION 'CRM_ORDER_SAVE'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
Hi Sar,
What Dawood has written is a must which you will have to do.
In addition to that, you may also should check if the partner procedure allows employee responsible to be changed. You can simply check that by changing the employee responsible manually in GUI.
Additional thing that you can do is not composing a logical key. This might not be required.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sar,
before deeper analyzing the code, you have to also save the change. Run function module CRM_ORDER_SAVE before the COMMIT statement.
Regards,
Dawood.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
31 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.