How to update BOL entity property value via ABAP code
Suppose I have one product with ID I042416 which could be found in CRM WebClient UI:
I would like to change its description from "i042416" to for example "Jerry test".
Here below is the ABAP code which uses CRM BOL API to achieve.
Execute the report, specify product ID and new description to be updated:
Execute the report, product description is updated:
Double confirm in UI to see updated description as expected:
The complete code could be found below:
REPORT PROD_UPDATE_TEST. PARAMETERS: prd_id TYPE string, des_val1 TYPE string, uom_val2 TYPE string, sta_val3 TYPE string, icg_val4 TYPE string, not_val5 TYPE string, dis_txt6 TYPE string. DATA: lo_core TYPE REF TO cl_crm_bol_core, lo_collection TYPE REF TO if_bol_entity_col, lo_root_entity TYPE REF TO cl_crm_bol_entity, lo_short_text TYPE REF TO cl_crm_bol_entity, lo_uom TYPE REF TO cl_crm_bol_entity, lo_stat TYPE REF TO cl_crm_bol_entity, lo_matb TYPE REF TO cl_crm_bol_entity, lo_note TYPE REF TO cl_crm_bol_entity, lo_dischain TYPE REF TO cl_crm_bol_entity, lo_dischaintxt TYPE REF TO cl_crm_bol_entity. DATA: lv_view_name TYPE crmt_view_name, lv_query_name TYPE crmt_ext_obj_name, lt_query_parameter TYPE crmt_name_value_pair_tab, ls_query_parameter LIKE LINE OF lt_query_parameter, lo_transaction TYPE REF TO if_bol_transaction_context, lv_success TYPE abap_bool, lv_changed TYPE abap_bool, lv_size TYPE I. * get the product lo_core = cl_crm_bol_core=>get_instance( ). lo_core->load_component_set( 'PROD_ALL' ). lo_transaction = lo_core->get_transaction( ). lv_query_name = 'ProdAdvancedSearchProducts'. ls_query_parameter-name = 'PRODUCT_ID'. ls_query_parameter-VALUE = prd_id. APPEND ls_query_parameter TO lt_query_parameter. lo_collection = lo_core->query( iv_query_name = lv_query_name it_query_params = lt_query_parameter iv_view_name = lv_view_name ). lv_size = lo_collection->IF_BOL_BO_COL~SIZE( ). WRITE:/ 'Product number found:' , lv_size. ASSERT lv_size = 1.lo_root_entity = lo_collection->get_first( ).IF des_val1 IS NOT INITIAL. * update product description lo_short_text = lo_root_entity->get_related_entity( 'ProductShortText' ). IF lo_short_text IS INITIAL. " HANDLING lo_short_text = lo_root_entity->CREATE_RELATED_ENTITY( IV_RELATION_NAME = 'ProductShortText' ). ENDIF. lo_short_text->set_property( iv_attr_name = 'SHORT_TEXT' iv_value = des_val1 ). lo_short_text->set_property( iv_attr_name = 'LANGU' iv_value = sy-langu ). ENDIF. IF uom_val2 IS NOT INITIAL. * update base unit lo_uom = lo_root_entity->get_related_entity( 'ProductUom' ). IF lo_uom IS INITIAL. " HANDLING lo_uom = lo_root_entity->CREATE_RELATED_ENTITY( IV_RELATION_NAME = 'ProductUom' ). ENDIF. lo_uom->set_property( iv_attr_name = 'UNIT' iv_value = uom_val2 ).ENDIF.IF sta_val3 IS NOT INITIAL. * update status lo_stat = lo_root_entity->get_related_entity( 'ProductStat' ). IF lo_stat IS INITIAL. lo_stat = lo_root_entity->CREATE_RELATED_ENTITY( IV_RELATION_NAME = 'ProductStat' ). ENDIF. lo_stat->set_property( iv_attr_name = 'STAT' iv_value = sta_val3 ).ENDIF.IF icg_val4 IS NOT INITIAL. * update item category group lo_matb = lo_root_entity->get_related_entity( 'ProductMatBasic' ). IF lo_matb IS INITIAL. lo_matb = lo_root_entity->CREATE_RELATED_ENTITY( IV_RELATION_NAME = 'ProductMatBasic' ). ENDIF. lo_matb->set_property( iv_attr_name = 'ITEM_CAT_GROUP' iv_value = icg_val4 ).ENDIF.IF not_val5 IS NOT INITIAL. * update notes lo_note = lo_root_entity->get_related_entity( 'ProductLongtext' ). IF lo_note IS INITIAL. lo_note = lo_root_entity->CREATE_RELATED_ENTITY( IV_RELATION_NAME = 'ProductLongtext' ). ENDIF. lo_note->set_property( iv_attr_name = 'CONC_LINES' iv_value = not_val5 ).ENDIF.IF dis_txt6 IS NOT INITIAL. * update sales area text lo_dischain = lo_root_entity->get_related_entity( 'ProductDistrChain' ). IF lo_dischain IS INITIAL. lo_dischain = lo_root_entity->CREATE_RELATED_ENTITY( IV_RELATION_NAME = 'ProductDistrChain' ). ENDIF. lo_dischaintxt = lo_dischain->GET_RELATED_ENTITY( 'ProductDcLongtext' ). IF lo_dischaintxt IS INITIAL. lo_dischaintxt = lo_dischain->CREATE_RELATED_ENTITY( IV_RELATION_NAME = 'ProductDcLongtext' ). ENDIF. lo_dischaintxt->set_property( iv_attr_name = 'CONC_LINES' iv_value = dis_txt6 ).ENDIF. * execute modification lo_core->modify( ). lv_changed = lo_transaction->check_save_needed( ). CHECK lv_changed EQ abap_true. lv_success = lo_transaction->save( ).IF lv_success = abap_true. lo_transaction->commit( ). WRITE:/ 'Product changed Successfully'.ELSE. lo_transaction->rollback( ).ENDIF.
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2284646/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [Javascript] How javascript read the property?JavaScript
- When should reread of cl_crm_bol_entity and $scope.$apply be called manuallyAPP
- How to link multiple docker-compose services via networkDocker
- SAP How to maintain missing enrties in TJ07 via customizingAI
- Warning: ORA-16792: configurable property value is inconsistent with member sett
- Source Code Reading for Vue 3: How does `hasChanged` work?Vue
- [Vue warn]: The data property "dialogVisible" is already declared as a prop. Use prop default valueVue
- 使用ABAP建立QR Code(二維碼)
- How to use VS Code to debug Next.js applications All In OneJSAPP
- Hive throws: WstxParsingException: Illegal character entity: expansion character (code 0x8)HiveException
- .NET Core學習筆記(9)——Entity Framework Core之Code First筆記Framework
- 如何找到ABAP裡被動態呼叫的update function moduleFunction
- 使用ABAP程式碼生成二維碼(QR Code)
- [原創] How to pull code when shared repo commit history has been changedMIT
- SAP ABAP CGLIB(Code Generation Library)的模擬實現CGLib
- ABAP Code Inspector 的一些高階功能分享
- SAP ABAP關鍵字語法圖和ABAP程式碼自動生成工具Code Composer
- AndroidStudio之自定義輸出包名報錯 Cannot set the value of read-only property 'outputFile' forAndroid
- ABAP Code Inspector那些隱藏的功能,您都知道嗎?
- 如何開啟 ABAP Update function module 和系統程式的除錯功能Function除錯
- 使用Visual Studio Code編寫和啟用ABAP程式碼 (上)
- 判斷ABAP程式碼是否處於update模式下執行的工具類模式
- 達夢資料庫啟動報code = -803 [Invalid ini config value]錯誤資料庫
- Entity Framework(1)Framework
- Dynamics CRM Error- Creating Entity with an invalid parent. Entity: EmailErrorAI
- SAP ABAP應用伺服器的HTTP響應狀態碼(Status Code)伺服器HTTP
- @property @synthesize @dynamic
- Property屬性
- Request: credentials property
- How to ssh
- SQL Injection via DNSSQLDNS
- SAP ABAP 方法呼叫裡傳值(Pass Value)和傳引用(Pass Reference)的區別試讀版
- vo bo dto pojo(entity)POJO
- 想在 Visual Studio Code 裡進行 ABAP 開發,需要安裝的擴充套件列表套件
- Oracle中的for update 和 for update nowaitOracleAI
- vue-property-decoratorVue
- 類的property特性
- Python @property 詳解Python