Skip to Content
author's profile photo Former Member
Former Member

CRM_ORDER_MAINTAIN

Hi Experts , I Need to use this BAPI CRM_ORDER_MAINTAIN but i don't have a program to use it can anyone help me togive me a solution ?? PLZ

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 03, 2014 at 02:24 PM


    Hi Akrem,

    Please find below code which we used in our project.

    CALL FUNCTION 'GUID_CREATE'
    IMPORTING
    ev_guid_32 = lv_header_guid.

    ls_orderadm_h-guid = lv_header_guid.
    ls_orderadm_h-process_type = gc_ztis.
    ls_orderadm_h-mode = 'A'.
    lv_vbeln = ls_crm_data-order.
    lv_date = ls_crm_data-zzcrid.
    APPEND ls_orderadm_h TO lt_orderadm_h.

    * Pass purchase order details
    ls_sales-ref_guid = lv_header_guid.
    ls_sales-ref_kind = 'A'.
    ls_sales-po_number_sold = ls_crm_data-po_number_sold.
    ls_sales-po_date_sold = ls_crm_data-po_date_sold.
    ls_sales-ref_kind = 'A'.
    APPEND ls_sales TO lt_sales.

    * Build input fields table
    ls_input_fields-ref_guid = lv_header_guid.
    ls_input_fields-ref_kind = 'A'.
    ls_input_fields-ref_handle = ' '.
    ls_input_fields-objectname = 'ORDERADM_H.

    ls_input_field_names-fieldname = 'MODE'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'PROCESS_TYPE.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    INSERT ls_input_fields INTO TABLE lt_input_fields.

    ls_input_fields-objectname = 'SALES'.
    ls_input_field_names-fieldname = 'PO_NUM_SOLD'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'PO_DATE_SOLD'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    ENDIF.

    lt_crmdata_tmp[] = it_crm_data[].
    DELETE lt_crmdata_tmp WHERE type NE 'I'.
    IF NOT lt_crmdata_tmp[] IS INITIAL.
    SELECT product_guid product_id FROM comm_product
    INTO TABLE lt_prod_guid
    FOR ALL ENTRIES IN lt_crmdata_tmp
    WHERE product_id = lt_crmdata_tmp-ecc_matnr.
    IF sy-subrc EQ 0.
    ENDIF.
    ENDIF.

    * Get item details
    LOOP AT it_crm_data INTO ls_crm_data WHERE type EQ 'I'.

    * Update product id
    CALL FUNCTION 'GUID_CREATE'
    IMPORTING
    ev_guid_32 = lv_item_guid.

    ls_input_fields-ref_guid = lv_item_guid.
    ls_input_fields-ref_kind = ' '.
    ls_input_fields-objectname = 'ORDERADM_I'.
    ls_input_field_names-fieldname = 'MODE'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'ORDERED_PROD'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'PARENT'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    CLEAR ls_input_fields.

    ls_orderadm_i-ordered_prod = ls_crm_data-product_id.
    ls_orderadm_i-guid = lv_item_guid.
    ls_orderadm_i-header = lv_header_guid.
    ls_orderadm_i-parent = lv_parent_guid.
    ls_orderadm_i-mode = 'A'.
    APPEND ls_orderadm_i TO lt_orderadm_i.
    CLEAR ls_orderadm_i.

    * update quantity
    CALL FUNCTION 'GUID_CREATE'
    IMPORTING
    ev_guid_32 = lv_qty_guid.

    ls_schedule-ref_guid = lv_item_guid.
    ls_schedlines-guid = lv_qty_guid.
    ls_schedlines-item_guid = lv_item_guid.
    ls_schedlines-logical_key = lv_qty_guid.
    IF NOT ls_crm_data-quantity IS INITIAL.
    ls_schedlines-quantity = ls_crm_data-quantity.
    ENDIF.
    ls_schedlines-mode = 'A'.
    INSERT ls_schedlines INTO TABLE ls_schedule-schedlines.
    INSERT ls_schedule INTO TABLE lt_schedule.
    CLEAR: ls_schedule, ls_schedlines.

    ls_input_fields-ref_kind = 'B'.
    ls_input_fields-ref_guid = lv_item_guid.
    ls_input_fields-objectname = 'SCHEDLIN'.
    ls_input_fields-logical_key = lv_qty_guid.
    ls_input_field_names-fieldname = 'QUANTITY'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    CLEAR ls_input_fields.

    IF ls_crm_data-product_id EQ 'INSTALLATION'.
    lv_parent_guid = lv_item_guid.
    ENDIF.

    ls_input_fields-ref_kind = 'B'.
    ls_input_fields-ref_guid = lv_item_guid.
    ls_input_fields-objectname = 'PRODUCT_I'.
    ls_input_field_names-fieldname = 'PROCESS_QTY_UNIT'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    CLEAR ls_input_fields.
    * UOM
    ls_product_i-ref_guid = lv_item_guid.
    ls_product_i-process_qty_unit = 'EA'.
    APPEND ls_product_i TO lt_product_i.
    CLEAR ls_product_i.
    * Default Accounting indicator to 'ZS'.
    ls_pricing-ref_guid = lv_item_guid.
    ls_pricing-ref_kind = 'B'. ls_pricing-ac_indicator = 'ZS'.
    APPEND ls_pricing TO lt_pricing.
    CLEAR ls_pricing.

    ls_input_fields-ref_kind = 'B'.

    ls_input_fields-objectname = 'PRICING'.
    ls_input_field_names-fieldname = 'AC_INDICATOR'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    * ENDIF.
    CLEAR: ls_input_fields, ls_crm_data.
    ENDLOOP.
    REFRESH: lt_crmdata_tmp.
    lt_crmdata_tmp[] = it_crm_data[].
    DELETE lt_crmdata_tmp WHERE type NE 'P'.
    SORT lt_crmdata_tmp BY partner_type.

    * Get partner guid for corresponding partner no's
    IF NOT lt_crmdata_tmp[] IS INITIAL.
    SELECT partner partner_guid FROM but000
    INTO TABLE lt_partner_guid
    FOR ALL ENTRIES IN lt_crmdata_tmp
    WHERE partner = lt_crmdata_tmp-partner_no.
    IF sy-subrc EQ 0.
    ENDIF.
    ENDIF.

    * Get partner data
    CLEAR ls_crm_data.
    LOOP AT lt_crmdata_tmp INTO ls_crm_data WHERE type EQ 'P'.
    ls_partner-partner_no = ls_crm_data-partner_no.
    ls_partner-ref_kind = 'A'.
    ls_partner-display_type = 'BP'.
    ls_partner-no_type = 'BP'.
    ls_partner-ref_guid = lv_header_guid.
    READ TABLE lt_partner_guid INTO ls_partner_guid
    WITH KEY partner_no = ls_partner-partner_no.
    IF sy-subrc EQ 0.
    ls_partner-partner_guid = ls_partner_guid-partner_guid.
    ENDIF.

    CASE ls_crm_data-partner_type.
    WHEN gc_01. "Sold to
    ls_partner-partner_fct = '00000001'.
    lv_logical_key = ls_partner-ref_partner_handle.
    lv_logical_key+4 = ls_partner-ref_partner_fct.
    lv_logical_key+12 = ls_partner-ref_partner_no.
    lv_logical_key+28 = ls_partner-ref_display_type.
    lv_logical_key+30 = ls_partner-ref_no_type.
    lv_soldto_guid = ls_partner-partner_no.
    ls_input_fields-logical_key = lv_logical_key.
    WHEN gc_55. "Ship to
    ls_partner-partner_fct = '00000055'.
    WHEN gc_03. "Bill to
    ls_partner-partner_fct = '00000003'.
    WHEN gc_04. "Payer
    ls_partner-partner_fct = '00000004'.
    WHEN gc_14. "Employee Responsible
    ls_partner-partner_fct = '00000014'.
    WHEN gc_15. "Contact
    ls_partner-partner_fct = '00000015'.
    ls_partner-ref_partner_handle = '0001'.
    SELECT SINGLE partner FROM but000 INTO ls_partner-partner_no
    WHERE partner_guid = ls_crm_data-contact_guid.
    IF sy-subrc EQ 0.
    ls_partner-partner_guid = ls_crm_data-contact_guid.
    ENDIF.
    ls_partner-relation_partner = lv_soldto_guid.
    ls_partner-mainpartner = 'X'.
    ls_partner-kind_of_entry = 'B'.
    ls_input_fields-logical_key = '0001'.
    ls_input_field_names-fieldname = 'RELATION_PARTNER'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    WHEN OTHERS.
    ENDCASE.
    APPEND ls_partner TO lt_partner.

    ls_input_fields-ref_kind = 'A'.
    ls_input_fields-ref_guid = lv_header_guid.
    ls_input_fields-objectname = 'PARTNER'.
    ls_input_field_names-fieldname = 'DISPLAY_TYPE'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'MAINPARTNER'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'NO_TYPE'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'PARTNER_FCT'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'PARTNER_NO'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.

    INSERT ls_input_fields INTO TABLE lt_input_fields.
    CLEAR: ls_input_fields.
    CLEAR: ls_partner, lv_logical_key, ls_crm_data.
    ENDLOOP.

    * Build doc Flow
    ls_doc_link-objkey_a = lv_header_guid.
    ls_doc_link-objtype_a = 'BUS2000116'.
    ls_doc_link-logsys_a = space.
    ls_doc_link-objkey_b = lv_vbeln.
    ls_doc_link-objtype_b = 'BUS2032'.
    CALL METHOD zcl_crm_utility_class=>get_erp_logical_system
    RECEIVING
    ev_logsys = ls_doc_link-logsys_b.

    CALL METHOD zcl_crm_utility_class=>get_own_logical_system
    RECEIVING
    ev_logsys = ls_doc_link-logsys_a.

    ls_doc_link-vona_kind = SPACE.
    ls_doc_link-reltype = 'VONA'.
    ls_doc_link-brel_kind = 'A'.
    ls_doc_link-date = sy-datum.

    INSERT ls_doc_link INTO TABLE ls_docflow-doc_link.
    ls_docflow-ref_guid = lv_header_guid.
    ls_docflow-ref_kind = 'A'.

    INSERT ls_docflow INTO TABLE lt_docflow.
    CLEAR ls_docflow.

    *-Changed fields:
    ls_input_field_names-fieldname = 'OBJKEY_A'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'OBJTYPE_A'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'OBJKEY_B' .

    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'OBJTYPE_B'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'VONA_KIND'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'LOGSYS_B'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'LOGSYS_A'.

    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'RELTYPE'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'BREL_KIND'.

    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'BREL_MODE'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    ls_input_field_names-fieldname = 'CREATED_AT_DATE'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.

    ls_input_fields-objectname = 'DOC_FLOW'.
    ls_input_fields-ref_guid = lv_header_guid.
    ls_input_fields-ref_kind = 'A'.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    CLEAR ls_input_fields.

    * Maintain ZZECC_SO in customer_i
    ls_customer_h-zzecc_so = lv_vbeln.
    ls_customer_h-ref_guid = lv_header_guid.
    * ls_customer_h-ref_kind = 'A'.
    ls_customer_h-mode = 'A'.
    APPEND ls_customer_h TO lt_customer_h.
    CLEAR ls_customer_h.
    ls_input_fields-ref_guid = lv_header_guid.
    ls_input_fields-ref_kind = 'A'.
    ls_input_fields-objectname = 'CUSTOMER_H'.
    ls_input_field_names-fieldname = 'ZZECC_SO'.
    INSERT ls_input_field_names INTO TABLE ls_input_fields-field_names.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    CLEAR ls_input_fields.

    CALL FUNCTION 'CRM_ORDER_MAINTAIN'
    EXPORTING
    it_sales = lt_sales
    it_pricing = lt_pricing
    * it_orgman = lt_orgman
    it_product_i = lt_product_i
    it_customer_h = lt_customer_h
    it_schedlin_i = lt_schedule
    it_partner = lt_partner
    IMPORTING
    et_exception = lt_exception
    CHANGING
    ct_orderadm_h = lt_orderadm_h
    ct_orderadm_i = lt_orderadm_i
    ct_input_fields = lt_input_fields
    ct_doc_flow = lt_docflow
    EXCEPTIONS
    error_occurred = 1
    document_locked = 2
    no_change_allowed = 3
    no_authority = 4
    OTHERS = 5.
    IF sy-subrc <> 0.
    * Implement suitable error handling here
    ENDIF.

    ls_objects_to_save = lv_header_guid.
    APPEND ls_objects_to_save TO lt_objects_to_save.
    CALL FUNCTION 'CRM_ORDER_SAVE'
    EXPORTING
    it_objects_to_save = lt_objects_to_save
    CHANGING
    cv_log_handle = lv_log_handle
    EXCEPTIONS
    document_not_saved = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
    * Implement suitable error handling here
    ELSE.
    REFRESH lt_input_fields.
    CLEAR ls_input_fields.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 03, 2014 at 11:56 AM

    Hi Akrem,

    Please search in SCN or in google.

    How to use SCN search

    Let me google that for you

    Best regards.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 03, 2014 at 06:23 PM

    There are numbers of examples on SCN how to use CRM_ORDER_MAINTAIN.

    Please use the search first before posting your query.

    The discussion is locked.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 03, 2014 at 02:17 PM

    Hi,

    If you want to update or create Document in CRM you can use CRM_ORDRER_MAINTAIN.

    For example if you want to update OPPORT_H field EXPECT_END then You have to use following code

    ls_input_field_name-fieldname = 'EXPECT_END'."field name
    ls_input_field_name-changeable = 'X'.
    INSERT ls_input_field_name INTO TABLE ls_input_field-field_names.
    ls_input_field-objectname = 'OPPORT_H'."object name
    ls_input_field-ref_guid = ls_followups-guid.
    ls_input_field-ref_kind = 'A'.
    INSERT ls_input_field INTO TABLE lt_input_fields.
    ls_opport_h-ref_guid = 'doc guid'
    ls_opport_h-ref_handle = '0001'.
    ls_opport_h-mode = 'B'." A- for create B- for change
    ls_opport_h-expect_end ='Value'.
    INSERT ls_opport_h INTO TABLE lt_opport_h.

    CALL FUNCTION 'CRM_ORDER_MAINTAIN'
    EXPORTING
    it_opport_h = it_opport_h
    CHANGING
    ct_input_fields = lt_input_fields
    EXCEPTIONS
    OTHERS = 99.
    IF SY-SUBRC IS INITIAL,
    ENDIF.

    Like this you can update any object fields.

    Mostly CRM_ORDER_MAINTAIN will be useful when you have more than one object(like CUSTOMER_H, OPPORT_H, ORDERADM_I etc) to update.

    Regards,

    Deepika.

    Add a comment
    10|10000 characters needed characters exceeded

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.