码迷,mamicode.com
首页 > 其他好文 > 详细

ABAP 创建客户

时间:2017-03-25 12:56:09      阅读:436      评论:0      收藏:0      [点我收藏+]

标签:art   title   update   color   str   rollback   cdata   other   refresh   

  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.

 

ABAP 创建客户

标签:art   title   update   color   str   rollback   cdata   other   refresh   

原文地址:http://www.cnblogs.com/rainysblog/p/6616813.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!