ABAP 创建客户

  CALL METHOD CMD_EI_API=>MAINTAIN_BAPI

FUNCTION Z_CS_RFC_OA002 .
*"----------------------------------------------------------------------
*"*"本地接口:
*"  EXPORTING
*"     VALUE(EX_TYPE) TYPE  CHAR1
*"     VALUE(EX_MSG) TYPE  STRING
*"     VALUE(EX_VALUE) TYPE  KUNNR
*"  TABLES
*"      IN_DATA STRUCTURE  ZSCS_002
*"----------------------------------------------------------------------
  DATA:G_LIN TYPE STRING.
  DATA:LV_FLG.
  DATA:G_PARNR TYPE PARNR..

  DATA:LS_MAIN       TYPE CMDS_EI_MAIN,
       LS_MAIN1      TYPE CMDS_EI_MAIN,
       LS_MAIN2      TYPE CMDS_EI_MAIN,
       LS_MESG       TYPE CVIS_MESSAGE,
       LS_MESG1      TYPE CVIS_MESSAGE,
       LT_MSG        TYPE BAPIRET2_T,
       LWA_MSG       TYPE BAPIRET2,
       LT_CUST       TYPE CMDS_EI_EXTERN_T,
       LWA_CUST      TYPE CMDS_EI_EXTERN,
       LWA_SALE      TYPE CMDS_EI_SALES,
       LT_SALE       TYPE CMDS_EI_SALES_T,
       LT_FUNCTIONS  TYPE CMDS_EI_FUNCTIONS_T,
       LWA_FUNCTIONS TYPE CMDS_EI_FUNCTIONS,
       LT_COMPANY    TYPE CMDS_EI_COMPANY_T,
       LT_TEXT       TYPE CVIS_EI_TEXT_T,
       LWA_TEXT      TYPE CVIS_EI_TEXT,
       LT_CONTENT    TYPE TLINE_TAB,
       LWA_CONTENT   TYPE TLINE,
       LWA_TAX       TYPE CMDS_EI_TAX_IND,
       LT_TAX        TYPE CMDS_EI_TAX_IND_T,
       LT_REMARK     TYPE CVIS_EI_REM_T,
       LWA_REMARK    TYPE CVIS_EI_REM,
       LT_TEL        TYPE CVIS_EI_TLX_T,
       LWA_TEL       TYPE CVIS_EI_TLX_STR,
       LT_FAX        TYPE CVIS_EI_FAX_T,
       LWA_FAX       TYPE CVIS_EI_FAX_STR,
       LT_MAIL       TYPE CVIS_EI_SMTP_T,
       LWA_MAIL      TYPE CVIS_EI_SMTP_STR,
       LT_TEL01      TYPE CVIS_EI_TTX_T,
       LWA_TEL01     TYPE CVIS_EI_TTX_STR,
       LT_CONTACT    TYPE CMDS_EI_CONTACTS_T,
       LWA_CONTACT   TYPE CMDS_EI_CONTACTS,
       LT_VERSION    TYPE CVI_EI_VERSION_TYPE1_T,
       LWA_VERSION   TYPE CVI_EI_VERSION_TYPE1,
       LT_PHONE      TYPE CVIS_EI_PHONE_T,
       LWA_PHONE     TYPE CVIS_EI_PHONE_STR,
       LT_PHONE1     TYPE CVIS_EI_PHONE_T,
       LWA_PHONE1    TYPE CVIS_EI_PHONE_STR,
       LWA_COMPANY   TYPE CMDS_EI_COMPANY,
       LT_GET        TYPE CMDS_EI_EXTERN_T,
       LWA_GET       TYPE CMDS_EI_EXTERN.

  CONSTANTS:CON_INSERT TYPE C VALUE ‘I‘,
            CON_UPDATE TYPE C VALUE ‘M‘.
*&---------------------------------------------------------------

*&S1.检查数据条目数
  G_LIN = LINES( IN_DATA[] ).
  IF G_LIN EQ 0.
    EX_TYPE = ‘E‘.
    EX_MSG = ‘没有数据!‘.
  ELSEIF G_LIN GT 30.
    EX_TYPE = ‘E‘.
    EX_MSG = ‘数据大于30条!‘.
  ENDIF.

  CHECK EX_TYPE NE ‘E‘.

  LOOP AT IN_DATA.
*&S2.1.主数据
    LWA_CUST-HEADER-OBJECT_TASK = ‘I‘.
    LWA_CUST-CENTRAL_DATA-CENTRAL-DATA-KTOKD = ‘Z001‘.  "客户帐户组
*&sign
    LWA_CUST-CENTRAL_DATA-CENTRAL-DATAX-KTOKD = ‘X‘.
*LWA_CUST-CENTRAL_DATA-CENTRAL-DATAX-CIVVE = ‘X‘.
*&S2.2.地址数据
    LWA_CUST-CENTRAL_DATA-ADDRESS-TASK = ‘I‘.
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-TITLE   = ‘0003‘.        "关键字 ‘3‘公司
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-NAME    = ‘重庆火锅客户‘."客户名称
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-LANGU   = SY-LANGU.
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-COUNTRY = ‘CN‘.
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-STREET  = ‘重庆渝中区新华路123号‘.
*&sign
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-TITLE = ‘X‘.
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-NAME  = ‘X‘.
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-LANGU = ‘X‘.
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-COUNTRY = ‘X‘.
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-STREET  = ‘X‘.
*&S2.3电话
    CLEAR:LWA_PHONE.
    REFRESH LT_PHONE.
    LWA_PHONE-CONTACT-TASK = CON_INSERT.
    LWA_PHONE-CONTACT-DATA-TELEPHONE = ‘18866666666‘."电话号码 W_BASIS-TEL.
    LWA_PHONE-CONTACT-DATAX-TELEPHONE = ‘X‘.
    APPEND LWA_PHONE TO LT_PHONE.
    LWA_CUST-CENTRAL_DATA-ADDRESS-COMMUNICATION-PHONE-PHONE = LT_PHONE.
**S2.4联系人1
*CLEAR:G_PARNR.
*CALL FUNCTION ‘NUMBER_GET_NEXT‘
*  EXPORTING
*    NR_RANGE_NR             = ‘AP‘
*    OBJECT                  = ‘PARTNER‘
*    QUANTITY                = ‘1‘
*  IMPORTING
*    NUMBER                  = G_PARNR
*  EXCEPTIONS
*    INTERVAL_NOT_FOUND      = 1
*    NUMBER_RANGE_NOT_INTERN = 2
*    OBJECT_NOT_FOUND        = 3
*    QUANTITY_IS_0           = 4
*    QUANTITY_IS_NOT_1       = 5
*    INTERVAL_OVERFLOW       = 6
*    BUFFER_OVERFLOW         = 7
*    OTHERS                  = 8.
*LWA_CONTACT-TASK = ‘I‘.
*LWA_CONTACT-ADDRESS_TYPE_3-TASK = ‘I‘.
*LWA_CONTACT-DATA_KEY-PARNR = G_PARNR.
*LWA_CONTACT-ADDRESS_TYPE_3-POSTAL-DATA-FIRSTNAME  = ‘aa‘.
*LWA_CONTACT-ADDRESS_TYPE_3-POSTAL-DATA-LASTNAME   = ‘bb‘.
*LWA_CONTACT-ADDRESS_TYPE_3-POSTAL-DATAX-FIRSTNAME = ‘X‘.
*LWA_CONTACT-ADDRESS_TYPE_3-POSTAL-DATAX-LASTNAME  = ‘X‘.
*LWA_CONTACT-ADDRESS_TYPE_3-COMMUNICATION-PHONE-PHONE = LT_PHONE1.
*APPEND LWA_CONTACT TO LT_CONTACT.
*LWA_CUST-CENTRAL_DATA-CONTACT-CONTACTS = LT_CONTACT.
*&S2.5联系人电话
*lwa_phone1-contact-task = ‘I‘.
*lwa_phone1-contact-data-telephone = ‘89999888‘.
*lwa_phone1-contact-data-extension = ‘3434343‘.
*lwa_phone1-contact-datax-extension = ‘X‘.
*lwa_phone1-contact-datax-telephone = ‘X‘.
*APPEND lwa_phone1 TO lt_phone1.

*&get in_data.
    APPEND LWA_CUST TO LT_CUST.
    LS_MAIN-CUSTOMERS = LT_CUST."客户 (Tab.) 的复杂外部接口
*&S3.Create custmer
    CALL METHOD CMD_EI_API=>MAINTAIN_BAPI
      EXPORTING
*       IV_TEST_RUN              = P_TEST
        IV_COLLECT_MESSAGES      = ‘X‘
        IS_MASTER_DATA           = LS_MAIN
      IMPORTING
        ES_MASTER_DATA_CORRECT   = LS_MAIN1
        ES_MESSAGE_CORRECT       = LS_MESG1
        ES_MASTER_DATA_DEFECTIVE = LS_MAIN2
        ES_MESSAGE_DEFECTIVE     = LS_MESG.

*&S3.1get message
    LT_MSG = LS_MESG-MESSAGES.
    LT_GET[] = LS_MAIN1-CUSTOMERS.
*&S3.2.get return:
    LOOP AT LT_MSG INTO LWA_MSG WHERE TYPE = ‘E‘ OR TYPE = ‘A‘.
      EX_TYPE = ‘E‘.
      EX_MSG  = LWA_MSG-MESSAGE.
    ENDLOOP.
*&S3.3.成功commit work
    IF EX_TYPE NE ‘E‘.
      COMMIT WORK.
      READ TABLE LT_GET INTO LWA_GET INDEX 1.
*&S3.3Get custmer
      EX_VALUE = LWA_GET-HEADER-OBJECT_INSTANCE-KUNNR.
      IN_DATA-KUNNR = LWA_GET-HEADER-OBJECT_INSTANCE-KUNNR.
      EX_TYPE = ‘S‘.
      EX_MSG  = ‘新增客户成功!‘.
*&bdc 写联系人
      PERFORM BDC_DYNPRO      USING ‘SAPMF02D‘ ‘0101‘.
      PERFORM BDC_FIELD       USING ‘BDC_CURSOR‘
                                    ‘RF02D-D0360‘.
      PERFORM BDC_FIELD       USING ‘BDC_OKCODE‘
                                    ‘/00‘.
      PERFORM BDC_FIELD       USING ‘RF02D-KUNNR‘
                                    IN_DATA-KUNNR.
      PERFORM BDC_FIELD       USING ‘RF02D-D0360‘
                                    ‘X‘. "RECORD-D0360_002.
      PERFORM BDC_DYNPRO      USING ‘SAPMF02D‘ ‘0360‘.
      PERFORM BDC_FIELD       USING ‘BDC_CURSOR‘
                                    ‘KNVK-TELF1(01)‘.
      PERFORM BDC_FIELD       USING ‘BDC_OKCODE‘
                                    ‘=ENTR‘.
*      PERFORM BDC_FIELD       USING ‘KNVK-ANRED(01)‘
*                                    RECORD-ANRED_01_003.
*      PERFORM BDC_FIELD       USING ‘KNVK-NAMEV(01)‘
*                                    RECORD-NAMEV_01_004.
      PERFORM BDC_FIELD       USING ‘KNVK-NAME1(01)‘
                                    IN_DATA-NAME1."RECORD-NAME1_01_005.
      PERFORM BDC_FIELD       USING ‘KNVK-TELF1(01)‘
                                    IN_DATA-TELF1."RECORD-TELF1_01_006.
      PERFORM BDC_DYNPRO      USING ‘SAPMF02D‘ ‘0360‘.
      PERFORM BDC_FIELD       USING ‘BDC_CURSOR‘
                                    ‘KNVK-ABTNR(01)‘.
      PERFORM BDC_FIELD       USING ‘BDC_OKCODE‘
                                    ‘=ENTR‘.
      PERFORM BDC_FIELD       USING ‘KNVK-ABTNR(01)‘
                                    ‘=ENTR‘."RECORD-ABTNR_01_007.
      PERFORM BDC_DYNPRO      USING ‘SAPMF02D‘ ‘0360‘.
      PERFORM BDC_FIELD       USING ‘BDC_CURSOR‘
                                    ‘KNVK-NAMEV(01)‘.
      PERFORM BDC_FIELD       USING ‘BDC_OKCODE‘
                                    ‘=UPDA‘.
* PERFORM BDC_TRANSACTION USING ‘XD02‘.
      CALL TRANSACTION ‘XD02‘ USING BDCDATA  MODE ‘N‘ MESSAGES INTO IT_MESSAGE.
      CLEAR BDCDATA.
      WAIT UP TO 1 SECONDS.

      READ TABLE IT_MESSAGE WITH KEY MSGTYP = ‘E‘.
      IF SY-SUBRC EQ 0.
        EX_TYPE = ‘W‘.
        EX_MSG  = ‘供应商联系人信息创建失败!‘.
       ENDIF.
*&S3.4.error 则rollback.
    ELSE.
      ROLLBACK WORK.
    ENDIF.

  ENDLOOP.

ENDFUNCTION.
时间: 2024-10-05 08:14:41

ABAP 创建客户的相关文章

ABAP 创建并调用WebService

一. 创建Webservice 有两种方式创建webservice,一种是在se80中使用wizard生成,另一种是直接在se37中给予function生成,具体操作如下: 1.se80中Create-->Enterprise Service/Web Service --> Web Servcie 维护service名,选择一个poit type(type point为一个功能点:如,Bapi中的Method,FunctionGroup中的一个function,一个function或者Mess

vmware ESXI 创建客户维护用户权限设置

针对云平台创建一个客户维护帐号,针对客户所属云主机进行权限设置,客户通过vCenter客户端登录或者web,方便客户远程维护.配置如下:1.创建用户:在vCenter服务器中创建一个用户.2.将客户机添加到客户帐号,以及权限分配.登录vmware esxi 选择客户机,点击权限.在权限页右击,点击添加权限 添加刚刚创建的用户针对用户的情况进行权限分配vCenter默认有下图这些权限,当然也可以手动创建自己的特性的权限分配,等下讲(vCenter用户配置).现在我们只是测试,给个管理员权限(管理员

ABAP 创建物料主数据

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA' *&---------------------------------------------------------------------* *& Report  ZMMPL001 *& *&---------------------------------------------------------------------* *& *& *&-----------

ABAP开发顾问必备:SAP ABAP开发技术总结

声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将追究法律责任!原文链接:http://www.cnblogs.com/jiangzhengjun/p/4260224.html 该文档是根据我过去多年学习文档与工作文档总结而成,项目开发过程中我都会参考此文档,主要ABAP很多细节上的东西不可能你记得很牢固,或者你记得一时,但过不了几天做别的项目就会

ABAP/4 技术总结 V3.0

SAP --ABAP/4 技术总结 V3.0 2014-10-14 --江正军 1.      基础... 1 1.1. 基本数据类型... 1 1.1.1.        P类型(压缩型)数据... 1 1.2.           TYPE.LIKE. 2 1.3.           DESCRIBE. 3 1.4.           字符串表达式... 3 1.5.           Data element.Domain. 4 1.6.           词典预定义类型与ABAP

cxf 创建动态webService

D:\developTools\apache-cxf-2.5.2\samples\wsdl_first_dynamic_client CXF 方法 cxf方法 serviceInfo.getBindings() BindingInfo--[BindingInfo http://schemas.xmlsoap.org/wsdl/soap/] serviceInfo.getDocumentation() WS_0917_05 package com.test; import java.beans.P

(转载)使用SQL-Server创建一个银行数据管理系统Ⅰ

首先,要创建一个完整的数据管理系统,不是一蹴而就的,一定要要一步一步的来,不断完善,最终方能达到自己想要的结果,所以我在这里也是一点一点分步来做的. 创建数据库,数据库属性在这里用的是默认(不推荐使用这种偷懒的做法) 1 --创建数据库,使用默认配置 2 create database 某银行客户管理系统 3 go 创建表,共四个,分别是:客户信息,银行卡信息,业务类型,交易记录 1 use 某银行客户管理系统 2 3 4 --创建业务类型表,包含业务编号,业务名称和业务描述 5 create

设计模式之6个创建模式

创建型模式概述 创建型模式(Creational Pattern)对类的实例化过程进行了抽象,能够将软件模块中对象的创建和对象的使用分离.为了使软件的结构更加清晰,外界对于这些对象只需要知道它们共同的接口,而不清楚其具体的实现细节,使整个系统的设计更加符合单一职责原则. 创建型模式概述 创建型模式在创建什么(What),由谁创建(Who),何时创建(When)等方面都为软件设计者提供了尽可能大的灵活性.创建型模式隐藏了类的实例的创建细节,通过隐藏对象如何被创建和组合在一起达到使整个系统独立的目的

Dynamics CRM 2015/2016/365 Web API:级联创建

级联创建,即为在创建主记录的同时,可以把与其相关联的新记录也一并进行创建.举个例子,我们在创建客户记录的后,一般需要在创建一个联系人记录,然后将联系人记录设置为该客户记录的主要联系人. 在上面这个例子中,如果我们用传统的方式去做,需要向服务器请求3次,才能完成,如果涉及的相关记录数据繁多,那么请求的次数也需要增加.但是如果我们使用Web API的级联创建功能,我们只需向服务器发起一次请求即可. 级联创建和普通创建的请求方式一致,唯一的区别在于怎么去构造要记录创建对象.我们继续使用上面这个例子,我