In a previous blog http://scn.sap.com/community/crm/blog/2013/02/07/crmorderread-simple-example-for-those-new-to-crm-an... I gave a very simple example of how to use CRM_ORDER_MAINTAIN to create a new order.
This blog will show you how to UPDATE an order in CRM using ABAP.
I’ve tried to make this as simple as possible but while including the most important (useful) information.
In this example I will only update the orderadm and opport (opportunity) tables.
include crm_object_names_con.
data:
lt_opport_h type crmt_opport_h_comt,
ls_opport_h type line of crmt_opport_h_comt,
lt_orderadm_h type crmt_orderadm_h_comt,
ls_orderadm_h type crmt_orderadm_h_com,
*Other important things
lt_input_fields type crmt_input_field_tab,
ls_input_fields type crmt_input_field,
lt_nametab type crmt_input_field_names_tab,
ls_nametab type crmt_input_field_names,
lt_save_guid type crmt_object_guid_tab,
ls_save_guid type crmt_object_guid,
lt_saved_objects type crmt_return_objects,
ls_saved_objects type crmt_return_objects_struc,
lv_lin type i,
lv_order_object_id type crmt_object_id,
lv_order_object_guid type crmt_object_guid32.
* 1. Update the description of the opportunity
clear: ls_nametab, lt_nametab[],
ls_input_fields.
ls_orderadm_h-description = ‘this is the new description’.
ls_nametab = 'DESCRIPTION'.
append ls_nametab to lt_nametab.
*** for help on how to change a CHAR32 to a RAW16 see my CRM_ORDER_READ blog ***
ls_orderadm_h-guid = ‘this is the GUID type RAW16’.
append ls_orderadm_h to lt_orderadm_h.
ls_input_fields-ref_kind = 'A'.
ls_input_fields-ref_guid = ‘this is the GUID again, in RAW16’.
ls_input_fields-objectname = 'ORDERADM_H'.
ls_input_fields-field_names[] = lt_nametab[].
insert ls_input_fields into table lt_input_fields.
* 2. Update the opportunity data in opport_h table – update the current phase and end date
clear: ls_nametab, lt_nametab[], ls_input_fields.
ls_opport_h-curr_phase = ‘code for new sales stage’.
ls_nametab = 'CURR_PHASE'.
append ls_nametab to lt_nametab.
ls_opport_h-expect_end = ‘new date for expected end date’.
ls_nametab = 'EXPECT_END'.
append ls_nametab to lt_nametab.
ls_opport_h-ref_guid = ‘this is the GUID again, in RAW16’.
append ls_opport_h to lt_opport_h.
ls_input_fields-ref_guid = ‘this is the GUID again, in RAW16’.
ls_input_fields-ref_kind = 'A'.
ls_input_fields-objectname = 'OPPORT_H'.
ls_input_fields-field_names[] = lt_nametab[].
insert ls_input_fields into table lt_input_fields.
* 3. DONE, call CRM_ORDER_MAINTAIN on this information
call function 'CRM_ORDER_MAINTAIN'
exporting
it_opport_h = lt_opport_h
importing
et_exception = lt_exception1
changing
ct_orderadm_h = lt_orderadm_h
ct_input_fields = lt_input_fields
exceptions
error_occurred = 1
document_locked = 2
no_change_allowed = 3
no_authority = 4
others = 5.
case sy-subrc.
when 0.
ls_save_guid = iv_guid.
append ls_save_guid to lt_save_guid.
endcase.
* 4. SAVE the changes (all updates must be saved and committed before they change in CRM)
call function 'CRM_ORDER_SAVE'
exporting
it_objects_to_save = lt_save_guid
importing
et_saved_objects = lt_saved_objects
exceptions
document_not_saved = 1
others = 2.
case sy-subrc.
when '0'.
clear lv_lin.
describe table lt_saved_objects lines lv_lin.
if lv_lin = 1.
read table lt_saved_objects into ls_saved_objects index 1.
lv_order_object_guid = ls_saved_objects-guid.
lv_order_object_id = ls_saved_objects-object_id.
* 5. Call the function to COMMIT the changes to CRM.
call function 'BAPI_TRANSACTION_COMMIT'.
endif.
endcase.
*DONE, your opportunity has now been updated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |