使用代码创建具有organization unit的opportunity

Created by Jerry Wang, last modified on Jun 11, 2015

执行report后打印出成功创建的opportunity id:

hard code 的sales org信息:

hard code的partner信息:

 

source code:

 

 

*&---------------------------------------------------------------------*

 

*& Report  ZPARTNER_DETERMINE_VIA_CODE

 

*&

 

*&---------------------------------------------------------------------*

 

*&

 

*&

 

*&---------------------------------------------------------------------*

 

REPORT zorder_create_with_organizatio.

 

 

DATA: lt_input_fields     TYPE  crmt_input_field_tab,

 

      ls_input_field      LIKE LINE OF lt_input_fields,

 

      ls_field_name       LIKE LINE OF ls_input_field-field_names,

 

      lv_guid             TYPE guid_16,

 

      lt_orderadm_h_com   TYPE crmt_orderadm_h_comt,

 

      ls_orderadm_h_com   LIKE LINE OF lt_orderadm_h_com,

 

      lt_partner          TYPE crmt_partner_comt,

 

      ls_partner          LIKE LINE OF lt_partner,

 

      ls_partner_control  TYPE crmt_partner_control,

 

      ls_com_structure    TYPE string,

 

      lv_selection_needed TYPE  crmt_boolean,

 

      lv_is_buying_center TYPE  abap_bool,

 

      lt_attributes_com   TYPE  crmt_partner_attribute_com_tab,

 

      lt_save             TYPE crmt_object_guid_tab,

 

      lt_saved            TYPE crmt_return_objects,

 

      ls_saved            LIKE LINE OF lt_saved,

 

      lt_org_man          TYPE crmt_orgman_comt,

 

      ls_org_man          LIKE LINE OF lt_org_man.

 

 

START-OF-SELECTION.

 

 

  "PERFORM call_bp_determ_api.

 

  CALL FUNCTION 'GUID_CREATE'

 

    IMPORTING

 

      ev_guid_16 = lv_guid.

 

 

  PERFORM call_order_maintain.

 

  PERFORM call_order_save.

 

 

FORM call_order_maintain.

 

  CLEAR: ls_orderadm_h_com, ls_input_field, lt_input_fields.

 

  ls_orderadm_h_com-guid = lv_guid.

 

  ls_orderadm_h_com-description = 'created by code on:' && sy-timlo.

 

  ls_orderadm_h_com-process_type = 'OPPT'.

 

  ls_orderadm_h_com-mode = 'A'.

 

  APPEND ls_orderadm_h_com TO lt_orderadm_h_com.

 

 

  " Hard code sales org

 

  ls_org_man-dis_channel = '01'.

 

  ls_org_man-division = '02'.

 

  ls_org_man-sales_orgr_ori = 'C'.

 

  ls_org_man-sales_org_resp = 'O 50000732'.

 

  ls_org_man-error_flag = 'X'.

 

  ls_org_man-mode = 'A'.

 

  ls_org_man-no_determination = 'X'.

 

  ls_org_man-ref_guid = lv_guid.

 

  ls_org_man-ref_kind = 'A'.

 

  APPEND ls_org_man TO lt_org_man.

 

 

  ls_input_field-ref_guid = lv_guid.

 

  ls_input_field-ref_kind = 'A'.

 

  ls_input_field-objectname = 'ORDERADM_H'.

 

 

* sorted table

 

  ls_field_name-fieldname = 'DESCRIPTION'.

 

  APPEND ls_field_name TO ls_input_field-field_names.

 

  ls_field_name-fieldname = 'MODE'.

 

  APPEND ls_field_name TO ls_input_field-field_names.

 

  ls_field_name-fieldname = 'PROCESS_TYPE'.

 

  APPEND ls_field_name TO ls_input_field-field_names.

 

 

  APPEND ls_input_field TO lt_input_fields.

 

 

  CLEAR: ls_input_field.

 

  ls_input_field-ref_guid = lv_guid.

 

  ls_input_field-ref_kind = 'A'.

 

  ls_input_field-objectname = 'PARTNER'.

 

 

  CLEAR: ls_field_name.

 

  ls_field_name-fieldname = 'DISPLAY_TYPE'.

 

  APPEND ls_field_name TO ls_input_field-field_names.

 

 

  ls_field_name-fieldname = 'KIND_OF_ENTRY'.

 

  APPEND ls_field_name TO ls_input_field-field_names.

 

 

  ls_field_name-fieldname = 'NO_TYPE'.

 

  APPEND ls_field_name TO ls_input_field-field_names.

 

 

  ls_field_name-fieldname = 'PARTNER_FCT'.

 

  APPEND ls_field_name TO ls_input_field-field_names.

 

 

  ls_field_name-fieldname = 'PARTNER_NO'.

 

  APPEND ls_field_name TO ls_input_field-field_names.

 

 

  ls_input_field-ref_handle = '0000000000'.

 

  ls_input_field-logical_key = '0000'.

 

  APPEND ls_input_field TO lt_input_fields.

 

 

* input field for Org management

 

  CLEAR: ls_input_field,ls_field_name.

 

  ls_field_name-fieldname = 'DIS_CHANNEL'.

 

  APPEND ls_field_name TO ls_input_field-field_names.

 

 

  ls_field_name-fieldname = 'DIVISION'.

 

  APPEND ls_field_name TO ls_input_field-field_names.

 

 

  ls_field_name-fieldname = 'NO_DETERMINATION'.

 

  APPEND ls_field_name TO ls_input_field-field_names.

 

 

  ls_field_name-fieldname = 'SALES_ORGR_ORI'.

 

  APPEND ls_field_name TO ls_input_field-field_names.

 

 

  ls_field_name-fieldname = 'SALES_ORG_RESP'.

 

  APPEND ls_field_name TO ls_input_field-field_names.

 

 

  ls_input_field-ref_guid = lv_guid.

 

  ls_input_field-ref_kind = 'A'.

 

  ls_input_field-objectname = 'ORGMAN'.

 

 

  INSERT ls_input_field INTO TABLE lt_input_fields.

 

 

  ls_partner-ref_guid = lv_guid.

 

  ls_partner-ref_kind = 'A'.

 

  ls_partner-kind_of_entry = 'C'.

 

  ls_partner-partner_fct = '00000021'. "sales prospect

 

  ls_partner-partner_no = '0004031140'.

 

  ls_partner-display_type = 'BP'.

 

  ls_partner-no_type = 'BP'.

 

  APPEND ls_partner TO lt_partner.

 

 

  CALL FUNCTION 'CRM_ORDER_MAINTAIN'

 

    EXPORTING

 

      it_partner      = lt_partner

 

      it_orgman       = lt_org_man

 

    CHANGING

 

      ct_orderadm_h   = lt_orderadm_h_com

 

      ct_input_fields = lt_input_fields

 

    EXCEPTIONS

 

      OTHERS          = 99.

 

 

  IF sy-subrc = 0.

 

    WRITE:/ 'Order maintain function is done successfully.'.

 

  ENDIF.

 

ENDFORM.

 

 

FORM call_order_save.

 

  INSERT lv_guid INTO TABLE lt_save.

 

 

  CALL FUNCTION 'CRM_ORDER_SAVE'

 

    EXPORTING

 

      it_objects_to_save   = lt_save

 

      iv_update_task_local = abap_true

 

      iv_no_bdoc_send      = abap_true

 

    IMPORTING

 

      et_saved_objects     = lt_saved

 

    EXCEPTIONS

 

      document_not_saved   = 1.

 

 

  IF sy-subrc <> 0.

 

    WRITE: / 'Opportunity created failed'.

 

  ELSE.

 

    READ TABLE lt_saved INTO ls_saved INDEX 1.

 

    WRITE: / 'Opportunity created successfully, id: ' , ls_saved-object_id.

 

 

  ENDIF.

 

 

  COMMIT WORK AND WAIT.

 

 

ENDFORM.

 


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

-

01-01
-
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值