修改某个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之前:

clipboard1

执行report之后:

clipboard2

实现源代码:

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.

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

展开阅读全文

Git 实用技巧

11-24
这几年越来越多的开发团队使用了Git,掌握Git的使用已经越来越重要,已经是一个开发者必备的一项技能;但很多人在刚开始学习Git的时候会遇到很多疑问,比如之前使用过SVN的开发者想不通Git提交代码为什么需要先commit然后再去push,而不是一条命令一次性搞定; 更多的开发者对Git已经入门,不过在遇到一些代码冲突、需要恢复Git代码时候就不知所措,这个时候哪些对 Git掌握得比较好的少数人,就像团队中的神一样,在队友遇到 Git 相关的问题的时候用各种流利的操作来帮助队友于水火。 我去年刚加入新团队,发现一些同事对Git的常规操作没太大问题,但对Git的理解还是比较生疏,比如说分支和分支之间的关联关系、合并代码时候的冲突解决、提交代码前未拉取新代码导致冲突问题的处理等,我在协助处理这些问题的时候也记录各种问题的解决办法,希望整理后通过教程帮助到更多对Git操作进阶的开发者。 本期教程学习方法分为“掌握基础——稳步进阶——熟悉协作”三个层次。从掌握基础的 Git的推送和拉取开始,以案例进行演示,分析每一个步骤的操作方式和原理,从理解Git 工具的操作到学会代码存储结构、演示不同场景下Git遇到问题的不同处理方案。循序渐进让同学们掌握Git工具在团队协作中的整体协作流程。 在教程中会通过大量案例进行分析,案例会模拟在工作中遇到的问题,从最基础的代码提交和拉取、代码冲突解决、代码仓库的数据维护、Git服务端搭建等。为了让同学们容易理解,对Git简单易懂,文章中详细记录了详细的操作步骤,提供大量演示截图和解析。在教程的最后部分,会从提升团队整体效率的角度对Git工具进行讲解,包括规范操作、Gitlab的搭建、钩子事件的应用等。 为了让同学们可以利用碎片化时间来灵活学习,在教程文章中大程度降低了上下文的依赖,让大家可以在工作之余进行学习与实战,并同时掌握里面涉及的Git不常见操作的相关知识,理解Git工具在工作遇到的问题解决思路和方法,相信一定会对大家的前端技能进阶大有帮助。
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值