CRM_ORDER_MAINTAIN 修改订单简单示例

转载来自SCN:

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.

 

 

  1. include crm_object_names_con.   
  2.   data:   
  3.   lt_opport_h        type crmt_opport_h_comt,   
  4.   ls_opport_h        type line of crmt_opport_h_comt,   
  5.   lt_orderadm_h      type  crmt_orderadm_h_comt,   
  6.   ls_orderadm_h      type  crmt_orderadm_h_com,   
  7. *Other important things   
  8.    lt_input_fields    type  crmt_input_field_tab,   
  9.    ls_input_fields    type  crmt_input_field,   
  10.    lt_nametab         type  crmt_input_field_names_tab,   
  11.    ls_nametab         type  crmt_input_field_names,   
  12.    lt_save_guid       type  crmt_object_guid_tab,   
  13.    ls_save_guid       type  crmt_object_guid,   
  14.    lt_saved_objects   type  crmt_return_objects,   
  15.    ls_saved_objects   type  crmt_return_objects_struc,   
  16.    lv_lin             type   i,   
  17.    lv_order_object_id type  crmt_object_id,   
  18.    lv_order_object_guid  type  crmt_object_guid32.   
  19. * 1. Update the description of the opportunity   
  20. clear: ls_nametab, lt_nametab[],   
  21.           ls_input_fields.   
  22.     ls_orderadm_h-description                = ‘this is the new description’.   
  23.     ls_nametab                               = 'DESCRIPTION'.   
  24.     append ls_nametab to lt_nametab.   
  25. *** for help on how to change a CHAR32 to a RAW16 see my CRM_ORDER_READ blog ***   
  26.     ls_orderadm_h-guid                    = ‘this is the GUID type RAW16’.   
  27.     append ls_orderadm_h to lt_orderadm_h.   
  28.     ls_input_fields-ref_kind = 'A'.    
  29.     ls_input_fields-ref_guid = ‘this is the GUID again, in RAW16’.    
  30.     ls_input_fields-objectname = 'ORDERADM_H'.   
  31.     ls_input_fields-field_names[] = lt_nametab[].   
  32.     insert ls_input_fields into table lt_input_fields.   
  33. * 2. Update the opportunity data in opport_h table – update the current phase and end date   
  34.   clear: ls_nametab, lt_nametab[], ls_input_fields.   
  35.     ls_opport_h-curr_phase                 = ‘code for new sales stage’.   
  36.     ls_nametab               = 'CURR_PHASE'.   
  37.     append ls_nametab to lt_nametab.   
  38.     ls_opport_h-expect_end                  = ‘new date for expected end date’.   
  39.     ls_nametab              = 'EXPECT_END'.   
  40.     append ls_nametab to lt_nametab.   
  41. ls_opport_h-ref_guid                    = ‘this is the GUID again, in RAW16’.   
  42.     append ls_opport_h to lt_opport_h.   
  43.     ls_input_fields-ref_guid        = ‘this is the GUID again, in RAW16’.   
  44.     ls_input_fields-ref_kind        = 'A'.   
  45.     ls_input_fields-objectname      = 'OPPORT_H'.   
  46.     ls_input_fields-field_names[]   = lt_nametab[].   
  47.     insert ls_input_fields into table lt_input_fields.   
  48. * 3. DONE, call CRM_ORDER_MAINTAIN on this information   
  49. call function 'CRM_ORDER_MAINTAIN'   
  50.       exporting   
  51.         it_opport_h       = lt_opport_h   
  52.       importing   
  53.         et_exception      = lt_exception1   
  54.       changing   
  55.         ct_orderadm_h     = lt_orderadm_h   
  56.         ct_input_fields   = lt_input_fields   
  57.       exceptions   
  58.         error_occurred    = 1   
  59.         document_locked   = 2   
  60.         no_change_allowed = 3   
  61.         no_authority      = 4   
  62.         others            = 5.   
  63.     case sy-subrc.   
  64.       when 0.   
  65.         ls_save_guid = iv_guid.   
  66.         append ls_save_guid to lt_save_guid.   
  67. endcase.   
  68. * 4. SAVE the changes (all updates must be saved and committed before they change in CRM)   
  69.     call function 'CRM_ORDER_SAVE'   
  70.       exporting   
  71.         it_objects_to_save = lt_save_guid   
  72.       importing   
  73.         et_saved_objects   = lt_saved_objects   
  74.       exceptions   
  75.         document_not_saved = 1   
  76.         others             = 2.   
  77.     case sy-subrc.   
  78.       when '0'.   
  79.         clear lv_lin.   
  80.         describe table lt_saved_objects lines lv_lin.   
  81.         if lv_lin = 1.   
  82.           read table lt_saved_objects into ls_saved_objects index 1.   
  83.           lv_order_object_guid = ls_saved_objects-guid.   
  84.           lv_order_object_id   = ls_saved_objects-object_id.   
  85. * 5. Call the function to COMMIT the changes to CRM.   
  86.           call function 'BAPI_TRANSACTION_COMMIT'.   
  87.         endif.   
  88.     endcase.   
  89. *DONE, your opportunity has now been updated.  

 

你可能感兴趣的:(CRM_ORDER_MAINTAIN 修改订单简单示例)