如何使用程式碼修改SAP CRM One Order CUMULAT_H物件的值
In Logic of CRMD_CUMULAT_H I learned the fact that gross weight of an order is calculated based on all its line item. Recently in my project I have the requirement to modify the gross weight of an order directly via ABAP code.
I check the importing parameter of FM and don’t find the corresponding parameter for CUMULAT_H.
After research I have written the below report:
REPORT zchange_cumulat_h.PARAMETERS: quantity TYPE int4 OBLIGATORY DEFAULT 1,
item TYPE crmd_orderadm_i-number_int OBLIGATORY DEFAULT 20,
srvo_id TYPE crmd_orderadm_h-object_id OBLIGATORY DEFAULT '5700000242'.CONSTANTS: cv_sales_item TYPE crmt_subobject_category_db VALUE 'BUS2000131'.DATA: lv_srvo_guid TYPE crmd_orderadm_h-guid,
lt_to_save TYPE crmt_object_guid_tab,
lt_saved TYPE crmt_return_objects,
lv_schedule_guid TYPE crmt_object_guid,
lt_schedule_line TYPE crmt_schedlin_i_comt,
lt_schedule_detail TYPE crmt_schedlin_extdt,
ls_schedule_detail LIKE LINE OF lt_schedule_detail,
ls_schedule_line LIKE LINE OF lt_schedule_line,
lt_changed_fields TYPE crmt_input_field_tab,
ls_changed_fields LIKE LINE OF lt_changed_fields,
lt_orderadm_i TYPE TABLE OF crmd_orderadm_i.START-OF-SELECTION.SELECT SINGLE * INTO @DATA(ls_header) FROM crmd_orderadm_h WHERE object_id = @srvo_id.CHECK sy-subrc = 0.SELECT SINGLE * INTO @DATA(ls_cum_h) FROM crmd_cumulat_h WHERE guid = @ls_header-guid.CHECK sy-subrc = 0.lv_srvo_guid = ls_header-guid.WRITE:/ 'Old gross weight', ls_cum_h-gross_weight COLOR COL_GROUP.PERFORM print_gross_weight_detail.SELECT * INTO TABLE lt_orderadm_i FROM crmd_orderadm_i WHERE header = lv_srvo_guid AND object_type = cv_sales_item.CHECK sy-subrc = 0.READ TABLE lt_orderadm_i ASSIGNING FIELD-SYMBOL(<sales_item>) with key number_int = item.IF sy-subrc <> 0.
WRITE:/ 'Cannot find line item for item id:', item.
RETURN.ENDIF.SELECT SINGLE guid INTO lv_schedule_guid FROM crmd_schedlin WHERE item_guid = <sales_item>-guid.CHECK lv_schedule_guid IS NOT INITIAL.ls_schedule_line-ref_guid = <sales_item>-guid.ls_schedule_detail-guid = ls_schedule_detail-logical_key = lv_schedule_guid.ls_schedule_detail-item_guid = <sales_item>-guid.ls_schedule_detail-mode = 'B'.ls_schedule_detail-quantity = quantity.APPEND ls_schedule_detail TO ls_schedule_line-schedlines.APPEND ls_schedule_line TO lt_schedule_line.ls_changed_fields-ref_guid = <sales_item>-guid.ls_changed_fields-ref_kind = 'B'.ls_changed_fields-objectname = 'SCHEDLIN'.ls_changed_fields-logical_key = lv_schedule_guid.APPEND 'QUANTITY' TO ls_changed_fields-field_names.APPEND ls_changed_fields TO lt_changed_fields.CALL FUNCTION 'CRM_ORDER_MAINTAIN'
EXPORTING
it_schedlin_i = lt_schedule_line
CHANGING
ct_input_fields = lt_changed_fields
EXCEPTIONS
error_occurred = 1
document_locked = 2
no_change_allowed = 3
no_authority = 4.IF sy-subrc <> 0.
WRITE: / 'error during quantity change'.
RETURN.ENDIF.APPEND lv_srvo_guid TO lt_to_save.CALL FUNCTION 'CRM_ORDER_SAVE'
EXPORTING
it_objects_to_save = lt_to_save
iv_update_task_local = abap_true
IMPORTING
et_saved_objects = lt_saved
EXCEPTIONS
document_not_saved = 1.IF sy-subrc <> 0.
WRITE:/ 'Save failed'.
RETURN.ENDIF.COMMIT WORK AND WAIT.SELECT SINGLE * INTO ls_cum_h FROM crmd_cumulat_h WHERE guid = ls_header-guid.CHECK sy-subrc = 0.WRITE: / 'New Gross weight after change:' COLOR COL_NEGATIVE, ls_cum_h-gross_weight.PERFORM print_gross_weight_detail.FORM print_gross_weight_detail.
DATA: lt_product TYPE TABLE OF crmd_product_i,
lt_item TYPE TABLE OF crmd_orderadm_i.
SELECT * INTO TABLE lt_item FROM crmd_orderadm_i where header = lv_srvo_guid.
CHECK lt_item IS NOT INITIAL.
SELECT * INTO TABLE lt_product FROM crmd_product_i FOR ALL ENTRIES IN lt_item
WHERE guid = lt_item-guid.
LOOP AT lt_item ASSIGNING FIELD-SYMBOL(<item>).
WRITE: / 'Item id:' COLOR COL_POSITIVE, <item>-number_int COLOR COL_HEADING.
READ TABLE lt_product ASSIGNING FIELD-SYMBOL(<prod>) WITH KEY guid = <item>-guid.
CHECK sy-subrc = 0.
WRITE: / 'Item Gross Weight:' COLOR COL_POSITIVE, <prod>-gross_weight COLOR COL_GROUP.
ENDLOOP.ENDFORM.
How to use this report
Once executed, it will print out the detail of header gross weight before and after change. Why the header gross weight update is triggered by the change of SCHEDLIN?
(1) As could be found from callstack below, the update of gross weight is done in event callback CRM_CUMULAT_H_UPD_BUFFER_EC. Check event registration table CRMC_EVENT_CALL, and we can know this FM is registered against event TRIGGER_FUNCTION with attribute CUMULAT_H_CALC.
It is CRM_CUMULAT_H_UPD_COLLECT_EC which raises this event, see below screenshot:
So which function will trigger the call of CRM_CUMULAT_H_UPD_COLLECT_EC?
(2) Check CRMC_EVENT_CALL again, there are 11 possibilities.
Double check in the runtime, it is FM CRM_PRODUCT_I_PUBLISH_OW where the event AFTER_CHANGE on object PRODUCT_I is raised.
(3) Check further via callstack, CRM_PRODUCT_I_A_CHANGE_QUAN_EC will call CRM_PRODUCT_I_PUBLISH_OW. Query CRM_PRODUCT_I_A_CHANGE_QUAN_EC against CRMC_EVENT_CALL, and we get to the answer finally:
The event AFTER_CHANGE_ORDER_QTY on object SCHEDLIN_I will in the end trigger the update on CUMULAT_H.
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2713955/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 使用程式碼修改SAP CRM附件的屬性
- SAP CRM One Order的事件序號產生器制事件
- 我在德國做SAP CRM One Order redesign工作的心得
- SAP Commerce(原Hybris)的訂單處理框架和SAP CRM One Order框架框架
- SAP CRM One Order跟蹤和日誌工具CRMD_TRACE_SET
- SAP CRM One order裡user status和system status的mapping邏輯APP
- 如何使用程式碼的方式刪除 SAP CRM 訂單 Text 資料
- SAP CRM One Order header資料庫表幾個和時間戳相關的欄位Header資料庫時間戳
- 如何使用程式碼建立和讀取 SAP CRM 訂單的 Text 資料
- 使用ABAP程式碼給SAP CRM Business object建立附件AttachmentObject
- 使用ABAP程式碼提交SAP CRM Survey調查問卷
- 兩種使用程式碼獲得SAP CRM product sales status的辦法
- 如何使用ABAP程式碼建立SAP Product CategoryGo
- odoo One2many 給值程式碼 備忘Odoo
- 使用 ABAP 程式碼刪除指定 SAP CRM 系統裡 Opportunity 訂單的文字Unity
- 如何監聽SAP CRM BOR事件事件
- SAP CRM user引數CRM_UI_PROFILE是在哪行ABAP程式碼裡讀取的UI
- 使用ABAP程式碼建立S/4HANA裡的Sales Order
- SAP CRM系統排名?SAP CRM辦公系統怎麼選?什麼是使用者口碑最好的SAP CRM系統?
- SAP CRM如何建立支援Web Service的word模板Web
- SAP CRM如何建立支援Web Service的PDF模板Web
- 值物件如何共享物件
- 如何利用BAPI SD_SALESDOCUMENT_CHANGE修改Sales Order的欄位API
- 如何修改 SAP UI5 框架的原始碼實現,以及使用本地部署的 SAP UI5 SDK 試讀版UI框架原始碼
- stms傳輸批量請求和修改sap標準程式程式碼
- SAP MM Purchase Order History CategoryGo
- 微信小程式中如何使用setData修改陣列或物件中的某一引數微信小程式陣列物件
- SAP CRM WebClient UI,如何快速定位到丟擲錯誤訊息的那一行程式碼WebclientUI行程
- 如何修改SAP ABAP webdynpro的背景色Web
- 程式碼中使用DataView物件----建立DataView物件View物件
- mysql如何修改root使用者的密碼MySql密碼
- 如何讓你的SAP CRM應用支援附件上傳
- 物件導向One物件
- 智雲通CRM:如何判斷專案的價值?
- 使用SAP CRM中介軟體從ERP下載plant到CRM
- vue物件拷貝,解決由於引用賦值修改原物件的方法Vue物件賦值
- 如何使用Go語言寫出物件導向風格的程式碼Go物件
- TypeScript如何實現DDD的值物件?TypeScript物件