`
JerryWang_SAP
  • 浏览: 1032275 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论

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的原创文章,请关注公众号"汪子熙":

 
0
0
分享到:
评论

相关推荐

    SAP_BOL_查询创建修改

    - `lv_related_entity->set_property(iv_attr_name='LANGU', iv_value='1')`:由于存在语言属性,必须设置语言属性。否则事务将不会被提交。 7. **事务提交** - `lv_transaction = lv_bol_core->get_transaction...

    SAP_BOL_Browser

    【SAP_BOL_Browser】是一个专门用于探索和理解SAP Business Object Library (BOL) 架构的工具。在SAP系统中,BOL是数据模型的核心部分,它定义了业务对象及其相互关系,为应用程序提供数据访问和操作的接口。通过SAP...

    Bol.com 爬虫

    【Bol.com 爬虫】是一个用于抓取荷兰知名电商平台bol.com上产品信息的程序。这个爬虫项目的核心目标是收集bol.com上的商品列表,包括但不限于商品名称、价格、描述、评分等关键数据,以便进行数据分析或者建立自己的...

    FM与BOL在处理BP

    "FM"指的是Function Module(功能模块),它是SAP ABAP编程中的一个基本元素,用于实现特定的业务逻辑。而"BOL"代表Business Object Library(业务对象库),它是一个面向对象的框架,用于构建SAP的应用程序。 标题...

    Python库 | python-bol-api-latest-0.8.1b0.tar.gz

    在本例中,我们关注的是`python-bol-api-latest-0.8.1b0.tar.gz`,这是一个针对Python的库,特别用于后端开发。下面将详细解释这个库以及与其相关的知识点。 首先,`bol-api`很可能是“Basic Object Layer API”...

    开源项目-schollz-bol.zip

    开源项目-schollz-bol.zip,Command-line and web journal that stays synchronized and encrypted across devices

    block new record

    3. **引用类型**:如 `lr_result TYPE REF TO if_bol_bo_col, lr_valuenode TYPE REF TO cl_bsp_wd_value_node` 等,表示对象的引用,它们不是实际的对象实例,而是指向对象实例的指针。 4. **对象获取**:`lr_comp...

    BoL_Scripts:从脚本

    《BoL_Scripts:从脚本到编程的艺术》 在IT行业中,脚本语言扮演着至关重要的角色,尤其是在自动化任务、游戏开发、网络服务等领域。本文将深入探讨以Lua为基础的"BoL_Scripts"项目,揭示其在编程实践中的应用与精髓...

    微软内部资料-SQL性能优化5

    Each index row in node pages contains an index key (or set of keys for a composite index) and a pointer to a page at the next level for which the first key value is the same as the key value in the ...

    EXECL 提取字符

    Dim bol As Boolean n = Len(text) For i = 1 To n tempchar = Mid(text, i, 1) bol = Asc(tempchar) If bol = True Then tempname = tempname & tempchar End If Next i If tempname = 0 Then tempname = "N/A" ...

    BoL-Launcher_Server:服务器端应用程序到 BOL Launcher

    《BoL-Launcher_Server: 服务器端程序详解与应用》 在当今信息化社会,服务器端应用程序扮演着至关重要的角色,它们是构建大型分布式系统的基础。"BoL-Launcher_Server"作为一个专为BOL Launcher设计的服务器端程序...

    Boel - App voor bol.com-crx插件

    搜索bol.com是唯一提供了从BOL .com产品非常简单的镀Chrome扩展搜索。 BOL.com拥有广泛的450万产品,是荷兰最大的网上商店之一。 各种项目,如荷兰和国际书籍,CD,DVD,软件,游戏,电子设备,家用设备和玩具,并...

    Python库 | python-bol-retailer-api-0.4.2.tar.gz

    《Python库:深入解析python-bol-retailer-api》 在Python的世界里,库扮演着至关重要的角色,它们为开发者提供了丰富的功能,简化了代码编写,提高了开发效率。今天我们要探讨的是名为`python-bol-retailer-api`的...

    Rekeningopvuller voor Bol.com-crx插件

    Vul je rekening op met de de handige Rekeningopvuller voor Bol.com Kom je enkele centen tekort om te genieten van gratis verzending? Vul je rekening op met de de handige Rekeningopvuller voor Bol.com...

    PyPI 官网下载 | python-bol-api-latest-0.9.1.tar.gz

    《PyPI官网下载:python-bol-api-latest-0.9.1.tar.gz——Python后端开发中的关键库解析》 PyPI(Python Package Index)是Python开发者们最重要的资源库,它提供了大量的开源Python库,使得开发工作变得更加便捷。...

    SqlServer2K5_BOL_Jan2009_zh-CHT

    SQL2005数据库软件在网上很难找到,因此我找了很久才下载到,欢迎大家使用!

    BOL数字IP网络广播产品手册.pptx

    BOL数字IP网络广播产品手册.pptx

Global site tag (gtag.js) - Google Analytics