cancel
Showing results for 
Search instead for 
Did you mean: 

CRM_ORDER_MAINTAIN - in order_save BADI

Former Member
0 Kudos

Hi Experts,

I want to update my order. I have to add the account assignment group to my service order when the order is saved. How do I pass this value in the badi order_save. I want to use the function module crm_order_maintain. Can anyone please suggest how do I go about it.

Warm Regards,

Abdullah

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

To post changes to all you need is to call the API function CRM_ORDER_MAINTAIN, this API will trigger all the corresponding checks and will update the internal buffer. You will find a lot of importing parameters, this is because Order is a framework used by several CRM not only Activity.

To change the attribute EXTERN_ACT_ID you will need to maintain the importing attribute IT_ACTIVITY_H-EXTERN_ACT_ID, CT_INPUT_FIELDS in which you indicate with exact filed has changed and CT_ORDERADM_H or CT_ORDERADM_I depending if you update a header of item.

Finally you need to save these changes using function CRM_ORDER_SAVE and passing in IT_OBJECTS_TO_SAVE the list of object you want change.

regards,

Sharmila Brindha.M

Former Member
0 Kudos

Hi Experts,

I have specified CRM_ORDER_SAVE explicitly in the BADI after using CRM_ORDER_MAINTAIN and the program goes into an infinite loop.

How can I commit my values ?

Warm Regards,

Abdullah

Former Member
0 Kudos

The BAPI is called on saving the order. So if you do an order_save it is being called again. To persist your values you have to perform a BAPI_TRANSACTION_COMMIT.

Hope this helps,

Kai

Former Member
0 Kudos

Hi Experts,

The transaction commit function module does not commit the data. Any other suggestions are welcome. Actually my code is processed the first time the order is created only.

Warm Regards,

Abdullah

Former Member
0 Kudos

You can perform the task you want in four steps in the BAPI ORDER_SAVE:

1. get the order details there with fm CRM_ORDER_READ

2. change the values with CRM_ORDER_MAINTAIN

3. perform a CRM_ORDER_SAVE (take care of the parameter IT_OBJECTS_TO_SAVE) and

4. then a COMMIT with BAPI_COMMIT_DATA or similar like the BAPI_TRANSACTION_COMMIT.

It is important to take care parameters when saving, otherwise the data is not updating the objects for save.

If your code is still not working, a posting of the code would help because otherwise one can just guess.

Former Member
0 Kudos

Hi Experts,

This is how I code after I use CRM_ORDER_READ in the badi method change_before_update.


  select single *
    from zco003
    into wa_zco003
    where service_org_shor = v_sorg and
          process_type     = v_process_type.
  if sy-subrc = 0.

    iw_ac_assign-ref_guid = iv_guid.
    iw_ac_assign-ref_kind = 'A'.
    iw_ac_assign-ac_object_type = '01'.
    iw_ac_assign-ac_assignment = wa_zco003-aufnr.
    iw_ac_assign-ac_percentage = '0.00'.
    iw_ac_assign-mode = 'C'.
    append iw_ac_assign to it_ac_assign.

    cw_orderadm_h-guid = iv_guid.
    append cw_orderadm_h to ct_orderadm_h.

    cw_input_fields-ref_guid = iv_guid.
    cw_input_fields-ref_kind = 'A'.
    cw_input_fields-objectname = 'AC_ASSIGN'.

    cw_field_name-fieldname = 'AC_ASSIGNMENT'.
    cw_field_name-changeable = 'X'.
    append cw_field_name to ct_field_name.
    cw_field_name-fieldname = 'AC_OBJECT_TYPE'.
    cw_field_name-changeable = 'X'.
    append cw_field_name to ct_field_name.
    cw_field_name-fieldname = 'AC_PERCENTAGE'.
    cw_field_name-changeable = 'X'.
    append cw_field_name to ct_field_name.
    cw_field_name-fieldname = 'AC_TYPE_T'.
    cw_field_name-changeable = 'X'.
    append cw_field_name to ct_field_name.
    cw_field_name-fieldname = 'MODE'.
    cw_field_name-changeable = 'X'.
    append cw_field_name to ct_field_name.

    cw_input_fields-field_names[] = ct_field_name[].
    append cw_input_fields to ct_input_fields.

    loop at et_orderadm_i into ew_orderadm_i.
      clear cw_input_fields.
      cw_input_fields-ref_guid = ew_orderadm_i-guid.
      cw_input_fields-ref_kind = 'B'.
      cw_input_fields-objectname = 'AC_ASSIGN'.
      append cw_input_fields to ct_input_fields.
    endloop.

    clear cw_input_fields.
    cw_input_fields-ref_guid = iv_guid.
    cw_input_fields-ref_kind = 'A'.
    cw_input_fields-objectname = 'ORDERADM_H'.
    append cw_input_fields to ct_input_fields.

    loop at et_orderadm_i into ew_orderadm_i.
      cw_orderadm_i-guid = ew_orderadm_i-guid.
      append cw_orderadm_i to ct_orderadm_i.
      clear cw_orderadm_i.

    endloop.

    loop at et_orderadm_i into ew_orderadm_i.
      clear cw_input_fields.
      cw_input_fields-ref_guid = ew_orderadm_i-guid.
      cw_input_fields-ref_kind = 'B'.
      cw_input_fields-objectname = 'ORDERADM_I'.
      append cw_input_fields to ct_input_fields.
    endloop.

    call function 'CRM_ORDER_MAINTAIN'
     exporting
       it_ac_assign                  = it_ac_assign
     importing
       et_exception                  =  et_exception
     changing
*       ct_orderadm_h                 = ct_orderadm_h
*       ct_orderadm_i                 = ct_orderadm_i
       ct_input_fields               = ct_input_fields
       cv_log_handle                 = 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 <> 0.
* message id sy-msgid type sy-msgty number sy-msgno
*         with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      message 'error in updating' type 'e'.
    endif.

Can anyone please suggest what am I doing wrong

Regards,

Abdullah

Former Member
0 Kudos

In the BAPI at the end of the CRM_ORDER_MAINTAIN the commit functionality as discussed above is still missing - without the commit the changed data from the CRM_ORDER_MAINTAIN is not persisted and passed on to the internal save functions.

Regards, Kai

Former Member
0 Kudos

yeah, I failed to mention in my previous post. I am using


call function 'BAPI_TRANSACTION_COMMIT'
          .

after the function module CRM_ORDER_MAINTAIN

Warm Regards,

Abdullah

Former Member
0 Kudos

Hi,

1st step creat implementation for badi defination ORDER_SAVE and then in this implementation call FM : CRM_ORDER_READ by using this FM read all data which i replated to your service order or sales order .

make the cahnges in inernal table in which you are getting data from above FM...then update your changes in order using function module: CRM_ORDER_MAINTAIN while calling this FM carefully study all its importing and exporting parameters ..you can also use below FM :

CRM_APPT_MAINTAIN_SINGLE_OW: Maintain the Dates for a Service Contract (Start Date, End date, Date of Sale, Planned Contract Start Date etc). Donu2019t forget to pass the input_fields to be maintained.

Note: CRM_ORDER_SAVE function module must be called to save the changed contract explicitly after call to this function module.

CRM_STATUS_MAINTAIN_OW: Maintain the user status of Service Contracts. Donu2019t forget to pass the input_fields to be maintained.

Note: CRM_ORDER_SAVE function module must be called to save the changed contract explicitly after call to this function module.

If you want code for CRM_ORDER_MAINTAIN pls do reply. But i think its not a big deal !!!

Regards,

Amol Tambe.

SAP CRM technical Consultant.