修改某个appointment已经存在的opportunity relation-阿里云开发者社区

开发者社区> 开发者小助手-bz6> 正文

修改某个appointment已经存在的opportunity relation

简介: 修改某个appointment已经存在的opportunity relation
+关注继续查看

This question is asked by ERCO. They need to develop a BAdI implementation where the document history relationship connecting the modified opportunity and its related appointment could be changed. In order to achieve this they need to figure out how to modify document history by ABAP code. See example below:


执行report之后:

image.png

REPORT zappointment_overwrite_opp.

PARAMETERS: oppid   TYPE crmd_orderadm_h-object_id OBLIGATORY DEFAULT '1424',

           opptype TYPE crmd_orderadm_h-process_type OBLIGATORY DEFAULT 'OPPT'.

INCLUDE: crm_object_names_con,

           crm_object_types_con,

           crm_object_kinds_con,

           crm_mode_con.

DATA: ls_docflow        TYPE crmt_doc_flow_com,

     ct_doc_flow       TYPE crmt_doc_flow_comt,

     ls_link           TYPE LINE OF crmt_doc_flow_extdt,

     lv_opp_guid       TYPE crmd_orderadm_h-guid,

     lv_app_guid       LIKE lv_opp_guid,

     ct_input_fields   TYPE crmt_input_field_tab,

     cs_input          LIKE LINE OF ct_input_fields,

     cs_field          LIKE LINE OF cs_input-field_names,

     lv_opp_id         TYPE crmd_orderadm_h-object_id,

     lv_opp_type       TYPE crmd_orderadm_h-process_type,

     lt_save           TYPE crmt_object_guid_tab,

     lt_not_saved      LIKE lt_save,

     lt_header         TYPE crmt_object_guid_tab,

     lt_doc_flow       TYPE crmt_doc_flow_wrkt,

     ls_doc_flow       LIKE LINE OF lt_doc_flow,

     lt_save_exception TYPE crmt_exception_t,

     lt_exception      TYPE crmt_exception_t.

START-OF-SELECTION.

* Jerry comment: replace this appointment guid with your own one.

* One relation will be created. Relation source: the appointment of this guid

*   Relation target: the opportunity specified in this report

*

 lv_app_guid = '3440B5B172DE1ED590B1C3A05B175D6A'.

 PERFORM delete_existing_rel USING lv_app_guid.

 PERFORM add_new_rel USING lv_app_guid.

FORM add_new_rel USING iv_opp_guid TYPE crmd_orderadm_h-guid.

 lv_opp_id = oppid.

 lv_opp_type = opptype.

 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

   EXPORTING

     input  = lv_opp_id

   IMPORTING

     output = lv_opp_id.

 SELECT SINGLE guid INTO lv_opp_guid FROM crmd_orderadm_h

   WHERE object_id EQ lv_opp_id AND process_type = lv_opp_type.

 ASSERT sy-subrc = 0.

 CLEAR: ls_docflow, ls_link, ct_doc_flow,ct_input_fields.

 ls_docflow-ref_kind = 'A'.

 ls_docflow-ref_guid = lv_app_guid.

 ls_link-objkey_a        = lv_opp_guid.

 ls_link-objtype_a       = gc_object_type-opportunity."'BUS2000111'.

 ls_link-objkey_b        = lv_app_guid.

 ls_link-objtype_b       = gc_object_type-businessactivity. "'BUS2000126'.

 ls_link-brel_kind       = 'A'.

 ls_link-brel_mode       = 'A'.

 ls_link-reltype         = 'VONA'.

 APPEND ls_link TO ls_docflow-doc_link.

 INSERT ls_docflow INTO TABLE ct_doc_flow.

 CLEAR: cs_input-field_names.

 cs_field = 'OBJKEY_A'.

 INSERT cs_field INTO TABLE cs_input-field_names.

 cs_field-fieldname = 'OBJTYPE_A'.

 INSERT cs_field INTO TABLE cs_input-field_names.

 cs_field-fieldname = 'OBJKEY_B'.

 INSERT cs_field INTO TABLE cs_input-field_names.

 cs_field-fieldname = 'OBJTYPE_B'.

 INSERT cs_field INTO TABLE cs_input-field_names.

 cs_field-fieldname = 'BREL_KIND'.

 INSERT cs_field INTO TABLE cs_input-field_names.

 cs_field-fieldname = 'RELTYPE'.

 INSERT cs_field INTO TABLE cs_input-field_names.

 cs_field-fieldname = 'RELATIONID'.

 INSERT cs_field INTO TABLE cs_input-field_names.

 cs_input-ref_guid    = lv_app_guid.

 cs_input-ref_kind    = gc_object_ref_kind-orderadm_h.

 cs_input-objectname  = gc_object_name-doc_flow.

 INSERT cs_input INTO TABLE ct_input_fields.

 CALL FUNCTION 'CRM_ORDER_MAINTAIN'

   IMPORTING

     et_exception      = lt_exception

   CHANGING

     ct_input_fields   = ct_input_fields

     ct_doc_flow       = ct_doc_flow

   EXCEPTIONS

     error_occurred    = 1

     document_locked   = 2

     no_change_allowed = 3

     no_authority      = 4.

 WRITE: / sy-subrc.

 APPEND lv_app_guid TO lt_save.

 CALL FUNCTION 'CRM_ORDER_SAVE'

   EXPORTING

     it_objects_to_save   = lt_save

   IMPORTING

     et_objects_not_saved = lt_not_saved

     et_exception         = lt_save_exception

   EXCEPTIONS

     document_not_saved   = 1.

 WRITE: / sy-subrc.

 COMMIT WORK AND WAIT.

ENDFORM.

FORM delete_existing_rel USING iv_app_guid TYPE crmd_orderadm_h-guid.

 APPEND iv_app_guid TO lt_header.

 CALL FUNCTION 'CRM_ORDER_READ'

   EXPORTING

     it_header_guid = lt_header

   IMPORTING

     et_doc_flow    = lt_doc_flow.

 IF lt_doc_flow IS INITIAL.

   WRITE: / 'no relation to delete.'.

   RETURN.

 ENDIF.

 ls_docflow-ref_kind = 'A'.

 ls_docflow-ref_guid = iv_app_guid.

* Jerry comment: for test purpose, one appointment has only one relationship of Opportunity,

* thus use INDEX 1

 READ TABLE lt_doc_flow INTO ls_doc_flow INDEX 1.

 ls_link-objkey_a        = ls_doc_flow-objkey_a.

 ls_link-objtype_a       = gc_object_type-opportunity."'BUS2000111'.

 ls_link-objkey_b        = ls_doc_flow-objkey_b.

 ls_link-objtype_b       = gc_object_type-businessactivity. "'BUS2000126'.

 ls_link-brel_kind       = 'A'.

 ls_link-brel_mode       = 'D'. " deletion

* Jerry: this line below is essential!! It points out which exactly relation should be deleted

 ls_link-relationid      = ls_doc_flow-relationid.

 ls_link-reltype         = 'VONA'.

 APPEND ls_link TO ls_docflow-doc_link.

 INSERT ls_docflow INTO TABLE ct_doc_flow.

 CLEAR: cs_input-field_names.

 cs_field = 'DOC_LINK'.

 INSERT cs_field INTO TABLE cs_input-field_names.

 cs_input-ref_guid    = lv_app_guid.

 cs_input-ref_kind    = gc_object_ref_kind-orderadm_h.

 cs_input-objectname  = gc_object_name-doc_flow.

 INSERT cs_input INTO TABLE ct_input_fields.

 CALL FUNCTION 'CRM_ORDER_MAINTAIN'

   IMPORTING

     et_exception      = lt_exception

   CHANGING

     ct_input_fields   = ct_input_fields

     ct_doc_flow       = ct_doc_flow

   EXCEPTIONS

     error_occurred    = 1

     document_locked   = 2

     no_change_allowed = 3

     no_authority      = 4.

 ASSERT sy-subrc = 0.

ENDFORM.

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
阿里云服务器怎么设置密码?怎么停机?怎么重启服务器?
如果在创建实例时没有设置密码,或者密码丢失,您可以在控制台上重新设置实例的登录密码。本文仅描述如何在 ECS 管理控制台上修改实例登录密码。
9496 0
[转]读取并修改App.config文件
1. 向项目添加app.config文件: 右击项目名称,选择“添加”→“添加新建项”,在出现的“添加新项”对话框中,选择“添加应用程序配置文件”;如果项目以前没有配置文件,则默认的文件名称为“app.config”,单击“确定”。
638 0
【Mybatis】Mybatis generator自动生成插件如何修改Mapper.xml 的命名空间namespace
【Mybatis】Mybatis generator自动生成插件如何修改Mapper.xml 的命名空间namespace
6 0
阿里云服务器端口号设置
阿里云服务器初级使用者可能面临的问题之一. 使用tomcat或者其他服务器软件设置端口号后,比如 一些不是默认的, mysql的 3306, mssql的1433,有时候打不开网页, 原因是没有在ecs安全组去设置这个端口号. 解决: 点击ecs下网络和安全下的安全组 在弹出的安全组中,如果没有就新建安全组,然后点击配置规则 最后如上图点击添加...或快速创建.   have fun!  将编程看作是一门艺术,而不单单是个技术。
10843 0
阿里云服务器如何登录?阿里云服务器的三种登录方法
购买阿里云ECS云服务器后如何登录?场景不同,阿里云优惠总结大概有三种登录方式: 登录到ECS云服务器控制台 在ECS云服务器控制台用户可以更改密码、更换系.
13186 0
SAP PP使用ECR去修改BOM主数据(一)
SAP PP使用ECR去修改BOM主数据(一)
6 0
1853
文章
0
问答
来源圈子
更多
+ 订阅
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载