Skip to Content

Not able to update customer_i and Customer_h using CRM_ORDER_MAINTAIN

Hi all,

I am using CRM_ORDER_MAINTAIN to update crm_customer_i and crm_customer_h. its only update header information and not updating item level information, Here is the code snippet.

DATA: lv_header_guid TYPE crmt_object_guid,
lt_requested_obj TYPE crmt_object_name_tab,
lv_order_guid TYPE crmt_object_guid,
ls_requested_obj TYPE crmt_object_name,
* ls_customer_i TYPE crmt_customer_i_wrk,
lt_header_guid TYPE crmt_object_guid_tab,
ls_header_guid TYPE crmt_object_guid,
lt_orderadm_i TYPE crmt_orderadm_i_wrkt,
lt_orderadm_i_tmp TYPE crmt_orderadm_i_wrkt,
lt_pricing_i TYPE crmt_pricing_i_wrkt,
lt_customer_i TYPE crmt_customer_i_wrkt,
lt_pricing TYPE crmt_pricing_wrkt,
lt_customer_h TYPE crmt_customer_h_wrkt,
log_heandle TYPE balloghndl,
lt_product_i TYPE crmt_product_i_wrkt,
currency TYPE crmt_currency,
process_qty_unit TYPE crmt_process_qty_unit,
override_price TYPE /abccust/retail_price,
process_qty_num TYPE crmt_process_qty_num,
lv_acqcost TYPE char20,
lv_qty TYPE char10,
lv_to_con TYPE kwert,
lv_to_ncon TYPE kwert,
lv_to_net TYPE kwert,
llt_customer_h TYPE crmt_customer_h_comt,
ls_customer_h TYPE crmt_customer_h_com,
llt_customer_i TYPE crmt_customer_i_comt,
ls_customer_i TYPE crmt_customer_i_com,
lv_unitprice TYPE char35,
ct_input_fields TYPE crmt_input_field_tab,
ls_input_fields TYPE crmt_input_field,
lt_input_field_nam TYPE crmt_input_field_names_tab,
ls_input_field_nam TYPE crmt_input_field_names,
et_exception TYPE crmt_exception_t,
obj_save TYPE crmt_object_guid_tab.

CONSTANTS : lc_customer_i TYPE crmt_object_name VALUE 'CUSTOMER_I',
lc_customer_h TYPE crmt_object_name VALUE 'CUSTOMER_H',
lc_orderadm_i TYPE crmt_object_name VALUE 'ORDERADM_I',
lc_pricing TYPE crmt_object_name VALUE 'PRICING',
lc_pricing_i TYPE crmt_object_name VALUE 'PRICING_I',
lc_product_i TYPE crmt_object_name VALUE 'PRODUCT_I',
lc_sep TYPE c VALUE '/',
lc_space TYPE c VALUE ' '.

FIELD-SYMBOLS:
<fs_orderadmi_i> TYPE crmt_orderadm_i_wrk,
<fs_header_guid> TYPE crmt_object_guid,
<fs_product_i> TYPE crmt_product_i_wrk,
<fs_pricing> TYPE crmt_pricing_wrk,
<fs_customer_i> TYPE crmt_customer_i_wrk,
<fs_pricing_i> TYPE crmt_pricing_i_wrk.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE t1 .
PARAMETERS:p_objid TYPE crmt_object_id.
SELECTION-SCREEN END OF BLOCK b1.

INITIALIZATION.


*---> Requesting only Customer custom item information
ls_requested_obj = lc_customer_i.
INSERT ls_requested_obj INTO TABLE lt_requested_obj.
CLEAR ls_requested_obj.

ls_requested_obj = lc_customer_h.
INSERT ls_requested_obj INTO TABLE lt_requested_obj.
CLEAR ls_requested_obj.

ls_requested_obj = lc_orderadm_i.
INSERT ls_requested_obj INTO TABLE lt_requested_obj.
CLEAR ls_requested_obj.

ls_requested_obj = lc_pricing.
INSERT ls_requested_obj INTO TABLE lt_requested_obj.
CLEAR ls_requested_obj.


ls_requested_obj = lc_pricing_i.
INSERT ls_requested_obj INTO TABLE lt_requested_obj.
CLEAR ls_requested_obj.

ls_requested_obj = lc_product_i.
INSERT ls_requested_obj INTO TABLE lt_requested_obj.
CLEAR ls_requested_obj.

START-OF-SELECTION.

CALL FUNCTION 'CRM_HEADER_OBJ_ID_GET_GUID'
EXPORTING
iv_obj_id = p_objid
IMPORTING
ev_guid = lv_header_guid
EXCEPTIONS
error_occurred = 1
OTHERS = 2.


* INSERT lv_header_guid INTO lt_header_guid.
APPEND lv_header_guid TO lt_header_guid.

CALL FUNCTION 'CRM_ORDER_READ'
EXPORTING
it_header_guid = lt_header_guid
it_requested_objects = lt_requested_obj
IMPORTING
et_orderadm_i = lt_orderadm_i
et_customer_h = lt_customer_h
et_pricing = lt_pricing
et_customer_i = lt_customer_i
et_pricing_i = lt_pricing_i
et_product_i = lt_product_i
CHANGING
cv_log_handle = log_heandle.


LOOP AT lt_header_guid ASSIGNING <fs_header_guid>.

CLEAR:currency,
lv_to_net,
lv_to_con,
lv_to_ncon.

lt_orderadm_i_tmp[] = lt_orderadm_i[].
DELETE lt_orderadm_i_tmp WHERE header <> <fs_header_guid>.

READ TABLE lt_pricing ASSIGNING <fs_pricing>
WITH KEY ref_guid = <fs_header_guid>.

IF sy-subrc IS INITIAL.
currency = <fs_pricing>-currency.
ENDIF.

LOOP AT lt_orderadm_i_tmp ASSIGNING <fs_orderadmi_i>.

READ TABLE lt_product_i ASSIGNING <fs_product_i>
WITH KEY guid = <fs_orderadmi_i>-guid.
IF sy-subrc IS INITIAL.
process_qty_unit = <fs_product_i>-process_qty_unit.
process_qty_num = <fs_product_i>-process_qty_num.
ENDIF.


READ TABLE lt_pricing_i ASSIGNING <fs_pricing_i> WITH KEY
guid = <fs_orderadmi_i>-guid.
IF sy-subrc EQ 0.
override_price = <fs_pricing_i>-subtotal1.
ENDIF.

READ TABLE lt_customer_i ASSIGNING <fs_customer_i>
WITH KEY guid = <fs_orderadmi_i>-guid.
IF sy-subrc IS INITIAL.

lv_acqcost = <fs_customer_i>-zzcustomer_i0227.
lv_qty = process_qty_num.
CONDENSE: lv_acqcost,
lv_qty.

IF <fs_customer_i>-zzcustomer_i0219 IS NOT INITIAL.
lv_to_con = lv_to_con + <fs_customer_i>-zzcustomer_i0227.
ELSE.
lv_to_ncon = lv_to_ncon + <fs_customer_i>-zzcustomer_i0227.
ENDIF.

CONCATENATE lv_acqcost
currency
lc_sep
lv_qty
process_qty_unit
INTO lv_unitprice "<fs_customer_i>-zzcustomer_i1102
SEPARATED BY space.

ls_customer_i-zzcustomer_i1102 = lv_unitprice.
ls_customer_i-zzcustomer_i1101 = override_price.
ls_customer_i-ref_guid = <fs_orderadmi_i>-guid.
ls_customer_i-ref_handle = '1'.
* ls_customer_i-mode = 'B'.
APPEND ls_customer_i TO llt_customer_i.

ls_input_field_nam-fieldname ='ZZCUSTOMER_I1101'.
CLEAR:ls_input_field_nam-changeable.
APPEND ls_input_field_nam TO lt_input_field_nam.
CLEAR:ls_input_field_nam.

ls_input_field_nam-fieldname ='ZZCUSTOMER_I1102'.
CLEAR:ls_input_field_nam-changeable.
APPEND ls_input_field_nam TO lt_input_field_nam.
CLEAR:ls_input_field_nam.


ls_input_fields-ref_guid = <fs_orderadmi_i>-guid.
ls_input_fields-ref_kind = 'B'.
ls_input_fields-objectname = lc_customer_i.
ls_input_fields-field_names = lt_input_field_nam.

APPEND ls_input_fields TO ct_input_fields.

CLEAR:ls_input_fields,
ls_customer_i,
lv_acqcost,
process_qty_unit,
process_qty_num,
override_price,
lv_acqcost,
lv_qty,
lv_unitprice.

REFRESH:lt_input_field_nam.

ENDIF.

ENDLOOP.

lv_to_net = lv_to_con + lv_to_ncon.

ls_customer_h-zzcustomer_h1001 = lv_to_con.
ls_customer_h-zzcustomer_h1002 = lv_to_ncon.
ls_customer_h-zzcustomer_h1003 = lv_to_net.
ls_customer_h-ref_guid = <fs_header_guid>.

APPEND ls_customer_h TO llt_customer_h.

ls_input_field_nam-fieldname = 'ZZCUSTOMER_H1001'.
CLEAR:ls_input_field_nam-changeable.
APPEND ls_input_field_nam TO lt_input_field_nam.
CLEAR:ls_input_field_nam.

ls_input_field_nam-fieldname = 'ZZCUSTOMER_H1002'.
CLEAR:ls_input_field_nam-changeable.
APPEND ls_input_field_nam TO lt_input_field_nam.
CLEAR:ls_input_field_nam.

ls_input_field_nam-fieldname = 'ZZCUSTOMER_H1003'.
CLEAR:ls_input_field_nam-changeable.
APPEND ls_input_field_nam TO lt_input_field_nam.
CLEAR:ls_input_field_nam.


ls_input_fields-ref_guid = <fs_header_guid>.
ls_input_fields-ref_kind = 'A'.
ls_input_fields-objectname = lc_customer_h.
ls_input_fields-field_names = lt_input_field_nam.

INSERT ls_input_fields INTO ct_input_fields INDEX 1.

CALL FUNCTION 'CRM_ORDER_MAINTAIN'
EXPORTING
it_customer_h = llt_customer_h
it_customer_i = llt_customer_i
IMPORTING
et_exception = et_exception
CHANGING
ct_input_fields = ct_input_fields
EXCEPTIONS
error_occurred = 1
document_locked = 2
no_change_allowed = 3
no_authority = 4
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

APPEND <fs_header_guid> TO obj_save.

CALL FUNCTION 'CRM_ORDER_SAVE'
EXPORTING
it_objects_to_save = obj_save
EXCEPTIONS
document_not_saved = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
.

CALL FUNCTION 'CRM_ORDER_INITIALIZE'
EXPORTING
it_guids_to_init = obj_save
iv_initialize_whole_buffer = 'X'
* IV_INIT_FRAME_LOG =
* IV_LOG_HANDLE =
* IV_KEEP_LOCK = FALSE
* IMPORTING
* ET_INITIALIZED_OBJECTS =
* EXCEPTIONS
* ERROR_OCCURRED = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
WRITE:/ 'The changes are committed ' .
WAIT UP TO 5 SECONDS.

ENDLOOP.

Thanks ,

NJ

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Jul 04, 2012 at 05:56 PM

    Hi Nikhilesh,

    Code seems to be fine.

    Remove ls_customer_i-ref_handle = '1'. form the code and try.

    Regards,

    Nithish

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Nikhilesh Jonwal

      Hi Nikhilesh,

      It looks strange . Place a breakpoint in FM CRM_CUSTOMER_I_MAINTAIN_OW and check how its behaving when both item and header are passed to CRM_ORDER_MAINTAIN. If can cannot figure out anything helpful, then use CRM_CUSTOMER_I_MAINTAIN_OW after CRM_ORDER_MAINTAIN with only header in it.

      Regards,

      Nithish

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.