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

How to update BOL entity property value via ABAP code的更多相关文章
- mappedBy reference an unknown target entity property解决方法
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error ...
- org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.entity.annotations.House.district in
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.entity. ...
- Entity Framework Tutorial Basics(24):Update Single Entity
Update Existing Entity using DBContext in Disconnected Scenario: In this chapter, you will learn how ...
- org.hibernate.AnnotationException: mappedBy reference an unknown target entity property
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: xxxxxxx 原因是 ...
- EntityFramework 学习 一 Update Existing Entity using DBContext in Disconnected Scenario
using System; using System.Collections.Generic; public partial class Student { public Student() { th ...
- update the UI property cross thread
this.Invoke((MethodInvoker)delegate { txtResult.Text = sbd.ToString(); // runs on UI thread });
- Entity Framework应用:使用Code First模式管理事务
一.什么是事务 处理以数据为中心的应用时,另一个重要的话题是事务管理.ADO.NET为事务管理提供了一个非常干净和有效的API.因为EF运行在ADO.NET之上,所以EF可以使用ADO.NET的事务管 ...
- Entity Framework应用:使用Code First模式管理存储过程
在EF中使用存储过程和使用视图是很相似的,一般会使用Database对象上的两个方法:SqlQuery和ExecuteSqlCommand.为了从存储过程中读取很多数据行,我们只需要定义一个类,我们会 ...
- Entity Framework With Mysql 之Code First
Entity Framework 4.0现在也可以支持Mysql数据库了,这篇文章将向你展示如何用Code First的方式来实现. 1.首先新建一个项目,在项目中用NuGet添加如下引用: 2.在w ...
随机推荐
- plsql数据库异常---plsql 登录后,提示数据库字符集(AL32UTF8)和客户端字符集(ZHS16GBK)不一致
今天遇到这个问题网上搜了一下答案找到了 转贴 http://blog.csdn.net/lidew521/article/details/8546155 plsql 登录后提示: Database c ...
- Java ee 之 html/css样式复习
内容: 1,html/css样式 2,模拟简书注册登陆页面 *重点: 1,width:auto;height:auto; 2,background-image:url(Q5.png);left top ...
- React.js 小书 Lesson26 - 实战分析:评论功能(五)
作者:胡子大哈 原文链接:http://huziketang.com/books/react/lesson26 转载请注明出处,保留原文链接和作者信息. (本文未审核) 持久化评论 同样地,可以通过类 ...
- org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.jboss.resteasy.plug
之前做的项目是resteasy的上传,代码没有问题,断点都不进来呢. 我以为可以直接移植到SpringMVC,但是SpringMVC不支持MultipartFormDataInput , 用Multi ...
- Scrapy框架学习(三)Spider、Downloader Middleware、Spider Middleware、Item Pipeline的用法
Spider有以下属性: Spider属性 name 爬虫名称,定义Spider名字的字符串,必须是唯一的.常见的命名方法是以爬取网站的域名来命名,比如爬取baidu.com,那就将Spider的名字 ...
- MdiContainer
/// <summary> /// 显示form /// </summary> /// <param name="form">要显示的form& ...
- [转]Using MVC 6 And AngularJS 2 With .NET Core
本文转自:http://www.c-sharpcorner.com/article/using-mvc-6-and-angularjs-2-with-net-core/ CoreMVCAngular2 ...
- js 常用脚本
1.判断电话号码和手机号码 var tel = $("#tel").val(); if (isNotBlank($.trim(tel))) { //不为空的情况下判断符合手机号码标 ...
- Storm框架入门
1 Topology构成 和同样是计算框架的Mapreduce相比,Mapreduce集群上运行的是Job,而Storm集群上运行的是Topology.但是Job在运行结束之后会自行结束,Topolo ...
- VS编译完成后自动复制到远程机器
缘起 最近在调试网络通信,每次一有点小修改,都要将程序从开发机复制到测试机,不胜烦扰.既然我们程序猿,为什么要那么死板呢,能够用代码解决的问题,就不要用手去解决. 解决过程 复制 手工复制外有没有其他 ...