通过调用方法XD02在XD02添加新电子邮件客户cmd_ei_api => maintain_bapi

时间:2019-04-04 11:03:27

标签: sap abap bapi

我需要从xls向XD02中的客户添加新的电子邮件地址。 没关系,但是,当我调用方法cmd_ei_api => maintain_bapi时 这确实改变了电子邮件,但是删除了XD02上的所有电子邮件,这不是我想要的,我想添加新的电子邮件并将其设置为默认值,但是我想保留旧的电子邮件。

我的代码:

FORM data_to_bapi.

  DATA: gs_correct         TYPE cmds_ei_main,
        gt_customers       TYPE cmds_ei_main,
        gs_address         TYPE bapiad1vl,
        gs_addressx        TYPE bapiad1vlx,
        gs_company_code_st TYPE cmds_ei_company,
        gs_company_code    TYPE cmds_ei_cmd_company,
        gt_smtp            TYPE cvis_ei_smtp_t,
        gs_smtp            LIKE LINE OF gt_smtp,
        gs_comm            TYPE cvis_ei_cvi_communication,
        gs_customers       TYPE cmds_ei_extern,
        gs_defective       TYPE cmds_ei_main,
        gs_msg_correct     TYPE cvis_message,
        gs_msg_error       TYPE cvis_message,
        iv_test_run        TYPE c.

  LOOP AT lt_data INTO wa_data.

    "Controlo
    gs_customers-header-object_instance-kunnr = wa_data-kunnr. "kunnr

    gs_customers-header-object_task = 'U'.            "Update this kunnr

    gs_smtp-contact-task            = 'I'.            " Insert New Email
    gs_smtp-contact-data-e_mail     = wa_data-email.  " New email
    gs_smtp-contact-datax-e_mail    = 'X'.

    APPEND gs_smtp TO gt_smtp.

    gs_comm-smtp-smtp = gt_smtp[].

    gs_customers-central_data-address-communication = gs_comm.
    gs_customers-central_data-address-task          = 'I'.   " Insert new communication

    APPEND gs_customers TO gt_customers-customers.

**********************************************************************
*                             CALL BAPI                              *
**********************************************************************

    CHECK gt_customers-customers IS NOT INITIAL.

    gv_collect_messages = abap_true.

    cmd_ei_api=>initialize( ).

    iv_test_run = ' '.

    CALL METHOD cmd_ei_api=>maintain_bapi
      EXPORTING
        iv_test_run              = iv_test_run
        iv_collect_messages      = gv_collect_messages
        is_master_data           = gt_customer
        " Master Data
      IMPORTING
        es_master_data_correct   = gs_correct
        es_message_correct       = gs_msg_correct
        es_master_data_defective = gs_defective
        es_message_defective     = gs_msg_error.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.

    CLEAR wa_data.

  ENDLOOP.

ENDFORM. "data_to_bapi

谢谢!

0 个答案:

没有答案