SAP BP创建客户
具体不解释了 个性比较强 不一定有参考价值
METHOD ZII_SI_OA2SAP_BP_CUSTOMER_IN_N~SI_OA2SAP_BP_CUSTOMER_IN_NEW. DATA:L_INPUT TYPE ZDT_BP_CUSTOMER_REQ_NEW_BP_CUS. DATA:L_OUTPUT TYPE ZDT_BP_CUSTOMER_RES_NEW_BP_CUS. DATA:LT_INPUT TYPE STANDARD TABLE OF ZBP001, WA_INPUT TYPE ZBP001. DATA:LT_RETURN TYPE STANDARD TABLE OF BAPIRET1 . DATA:LT_ZTSD017 TYPE STANDARD TABLE OF ZTSD017, WA_ZTSD017 TYPE ZTSD017. DATA:L_ERROR TYPE REF TO CX_SY_OPEN_SQL_DB. DATA:LEN TYPE INT4. DATA:YKHJL TYPE STRING. DATA:YKHZL TYPE STRING. SELECT * INTO TABLE @DATA(LT_TAX) FROM DFKKBPTAXNUM. SELECT * INTO TABLE @DATA(LT_KNA1) FROM KNA1. "PI传入数据赋值到函数传入参数 LOOP AT INPUT-MT_BP_CUSTOMER_REQ_NEW-BP_CUSTOMER_REQ INTO DATA(WA_IN). MOVE-CORRESPONDING WA_IN TO WA_INPUT. "校验税号 IF WA_INPUT-TAXNUMXL IS NOT INITIAL. READ TABLE LT_TAX INTO DATA(LS_TAXNUM) WITH KEY TAXNUM = WA_INPUT-TAXNUMXL. IF SY-SUBRC = 0 . L_OUTPUT-ZTYPE = 'E'. L_OUTPUT-MSG = '税号已存在,请核实'. * APPEND L_OUTPUT TO OUTPUT-MT_BP_CUSTOMER_RES-BP_CUSTOMER_RES. EXIT. ENDIF. ENDIF. "校验名称 IF WA_INPUT-NAME_ORG1 IS NOT INITIAL. READ TABLE LT_KNA1 INTO DATA(LS_NAME1) WITH KEY NAME1 = WA_INPUT-NAME_ORG1. IF SY-SUBRC = 0 . L_OUTPUT-ZTYPE = 'E'. L_OUTPUT-MSG = '客户名称已存在,请核实'. * APPEND L_OUTPUT TO OUTPUT-MT_BP_CUSTOMER_RES-BP_CUSTOMER_RES. EXIT. ENDIF. ENDIF. "定义常量 WA_INPUT-TITLE_MEDI = '0003'. LEN = STRLEN( WA_IN-BANKN ) - 18. IF LEN > 0. WA_INPUT-BANK_REF = WA_IN-BANKN+18(LEN)."银行账号18位后的放参考明细 ENDIF. * SHIFT WA_INPUT-BANKN BY STRLEN( WA_IN-BANKN ) - 18 PLACES LEFT. "定义街道地址 IF STRLEN( WA_IN-STREET ) <= 60. WA_INPUT-STREET = WA_IN-STREET. ELSE. WA_INPUT-STREET = WA_IN-STREET+0(60). DATA(LEN1) = STRLEN( WA_IN-STREET ) - 60. IF 0 < LEN1 AND LEN1 <= 40. WA_INPUT-STR_SUPPL2 = WA_IN-STREET+60(LEN1). ELSE. WA_INPUT-STR_SUPPL2 = WA_IN-STREET+60(40). DATA(LEN2) = STRLEN( WA_IN-STREET ) - 100. IF 0 < LEN2 AND LEN2 <= 40. WA_INPUT-STR_SUPPL1 = WA_IN-STREET+100(LEN2). ELSE. WA_INPUT-STR_SUPPL1 = WA_IN-STREET+100(40). ENDIF. ENDIF. ENDIF. "定义收货地址 IF STRLEN( WA_IN-STR_SUPPL3 ) <= 40. WA_INPUT-STR_SUPPL3 = WA_IN-STR_SUPPL3. ELSE. WA_INPUT-STR_SUPPL3 = WA_IN-STR_SUPPL3+0(40). DATA(LEN3) = STRLEN( WA_IN-STR_SUPPL3 ) - 40. IF 0 < LEN3 AND LEN3 <= 40. WA_INPUT-LOCATION = WA_IN-STR_SUPPL3+40(LEN3). ELSE. WA_INPUT-LOCATION = WA_IN-STR_SUPPL3+40(40). DATA(LEN4) = STRLEN( WA_IN-STR_SUPPL3 ) - 80. IF 0 < LEN4 AND LEN4 <= 40. WA_INPUT-DISTRICT = WA_IN-STR_SUPPL3+80(LEN4). ELSE. WA_INPUT-DISTRICT = WA_IN-STR_SUPPL3+80(40). ENDIF. ENDIF. ENDIF. WA_INPUT-COMM_NOTES = '公司电话'. WA_INPUT-KALKS = '1'. WA_INPUT-VSBED = '01'. WA_INPUT-GROUP = WA_INPUT-GROUP+0(4). WA_INPUT-BZIRK = WA_INPUT-BZIRK+0(4). WA_INPUT-KTGRD = WA_INPUT-KTGRD+0(2). IF WA_INPUT-GROUP = 'ZBP2'. WA_INPUT-TAXKD = '0'. ELSE. WA_INPUT-TAXKD = '1'. ENDIF. "如果助理和经理是一个人的话,实质是分不清的 "客户经理编号 YKHJL = WA_INPUT-KTONR. SELECT SINGLE CUSTOMER_CONT FROM CVI_CUST_CT_LINK INNER JOIN BUT000 ON BUT000~PARTNER_GUID = CVI_CUST_CT_LINK~PERSON_GUID INTO @DATA(LS_PARTNER) WHERE BUT000~NAME_LAST = @WA_INPUT-KTONR. WA_INPUT-KTONR = LS_PARTNER. "客户助理编号 YKHZL = WA_INPUT-KTONR1. SELECT SINGLE CUSTOMER_CONT FROM CVI_CUST_CT_LINK INNER JOIN BUT000 ON BUT000~PARTNER_GUID = CVI_CUST_CT_LINK~PERSON_GUID INTO @DATA(LS_PARTNER1) WHERE BUT000~NAME_LAST = @WA_INPUT-KTONR1. WA_INPUT-KTONR1 = LS_PARTNER1. WA_INPUT-CREDIT_SGMNT = 'C001'. WA_INPUT-VKORG = '6000'. WA_INPUT-BUKRS = '6000'. WA_INPUT-TOGRU = '6000'. APPEND WA_INPUT TO LT_INPUT. WA_INPUT-VKORG = '8000'. WA_INPUT-BUKRS = '8000'. WA_INPUT-TOGRU = '8000'. APPEND WA_INPUT TO LT_INPUT. WA_INPUT-VKORG = '9000'. WA_INPUT-BUKRS = '9000'. WA_INPUT-TOGRU = '9000'. APPEND WA_INPUT TO LT_INPUT. * CLEAR: WA_IN, WA_INPUT. CALL FUNCTION 'Y_TEST_FM_BP004' TABLES TT_INPUT = LT_INPUT TT_RETURN = LT_RETURN. LOOP AT LT_RETURN INTO DATA(LS_RETURN). L_OUTPUT-KUNNR = LS_RETURN-ID. SHIFT L_OUTPUT-KUNNR LEFT DELETING LEADING '0'. L_OUTPUT-ZTYPE = LS_RETURN-TYPE. L_OUTPUT-MSG = LS_RETURN-MESSAGE. IF LS_RETURN-TYPE = 'S'. "将管理区域写入ZTSD017 WA_ZTSD017-KUNNR = LS_RETURN-ID. "要保持有前导零 不然影响几个报表 WA_ZTSD017-NAME1 = WA_IN-NAME_ORG1. WA_ZTSD017-ZGLQY = WA_IN-ZGLQY. WA_ZTSD017-ZKHTEL = WA_IN-TEL_NUMBER1. WA_ZTSD017-ZKHLXR = WA_IN-REMARK3. "查找客户助理及客户经理名字 * SELECT SINGLE * BUT000~PARTNER * FROM KNVP * LEFT JOIN CVI_CUST_CT_LINK ON KNVP~PARNR = CVI_CUST_CT_LINK~CUSTOMER_CONT * LEFT JOIN BUT000 ON BUT000~PARTNER_GUID = CVI_CUST_CT_LINK~PERSON_GUID * INTO @DATA(LS_PARTNER1) * WHERE KNVP~KUNNR EQ @L_OUTPUT-KUNNR * AND KNVP~VKORG EQ '8000' * AND KNVP~PARVW = 'ZS'."销售经理 * SELECT SINGLE KNA1~NAME1 FROM KNA1 INTO @WA_ZTSD017-ZKHJL WHERE KUNNR = @LS_PARTNER1. WA_ZTSD017-ZKHJL = YKHJL. SELECT SINGLE ZTSD017B~ZTEL FROM ZTSD017B INTO @WA_ZTSD017-ZJLTEL WHERE ZUSER = @WA_ZTSD017-ZKHJL. * SELECT SINGLE * BUT000~PARTNER * FROM KNVP * LEFT JOIN CVI_CUST_CT_LINK ON KNVP~PARNR = CVI_CUST_CT_LINK~CUSTOMER_CONT * LEFT JOIN BUT000 ON BUT000~PARTNER_GUID = CVI_CUST_CT_LINK~PERSON_GUID * INTO @DATA(LS_PARTNER2) * WHERE KNVP~KUNNR EQ @L_OUTPUT-KUNNR * AND KNVP~VKORG EQ '8000' * AND KNVP~PARVW = 'ZA'."销售助理 * SELECT SINGLE KNA1~NAME1 FROM KNA1 INTO @WA_ZTSD017-ZHCLXR WHERE KUNNR = @LS_PARTNER2. WA_ZTSD017-ZHCLXR = YKHZL. SELECT SINGLE ZTSD017B~ZTEL FROM ZTSD017B INTO @WA_ZTSD017-ZHCTEL WHERE ZUSER = @WA_ZTSD017-ZHCLXR. APPEND WA_ZTSD017 TO LT_ZTSD017. TRY . MODIFY ZTSD017 FROM TABLE LT_ZTSD017. IF SY-SUBRC = 0. COMMIT WORK. ENDIF. CATCH CX_SY_OPEN_SQL_DB INTO L_ERROR . ROLLBACK WORK. ENDTRY. ENDIF. ENDLOOP. ENDLOOP. APPEND L_OUTPUT TO OUTPUT-MT_BP_CUSTOMER_RES_NEW-BP_CUSTOMER_RES. ENDMETHOD.
FUNCTION Y_TEST_FM_BP004. *"---------------------------------------------------------------------- *"*"本地接口: *" TABLES *" TT_INPUT STRUCTURE ZBP001 *" TT_RETURN STRUCTURE BAPIRET1 *"---------------------------------------------------------------------- PERFORM FM_CLEAR. RUN_ID = RUN_ID + 10. LOOP AT TT_INPUT. CLEAR LS_BP_GENERAL. LS_BP_GENERAL-RUN_ID = RUN_ID. LS_BP_GENERAL-GROUPING = TT_INPUT-GROUP. LS_BP_GENERAL-CATEGORY = '2'. LS_BP_GENERAL-OBJECT_TASK = 'I'. LS_BP_GENERAL-NAME1 = TT_INPUT-NAME_ORG1."名称 LS_BP_GENERAL-SEARCHTERM1 = TT_INPUT-SORT1_TXT."搜索项 LS_BP_GENERAL-TITLE_KEY = TT_INPUT-TITLE_MEDI."称谓 APPEND LS_BP_GENERAL TO IT_BP_GENERAL. "地址数据 LS_BP_ADDRESS-RUN_ID = RUN_ID. LS_BP_ADDRESS-COUNTRY = TT_INPUT-LAND1."国家 LS_BP_ADDRESS-CITY = TT_INPUT-CITY1."城市 LS_BP_ADDRESS-REGION = TT_INPUT-REGION."地区 LS_BP_ADDRESS-LANGU = '1'. LS_BP_ADDRESS-STREET = TT_INPUT-STREET."街道 LS_BP_ADDRESS-STR_SUPPL2 = TT_INPUT-STR_SUPPL2."街道 LS_BP_ADDRESS-STR_SUPPL1 = TT_INPUT-STR_SUPPL1."街道 LS_BP_ADDRESS-STR_SUPPL3 = TT_INPUT-STR_SUPPL3."送货地址 LS_BP_ADDRESS-LOCATION = TT_INPUT-LOCATION."送货地址 LS_BP_ADDRESS-DISTRICT = TT_INPUT-DISTRICT."送货地址 LS_BP_ADDRESS-POSTL_COD1 = TT_INPUT-PSTCD1."邮编 APPEND LS_BP_ADDRESS TO IT_BP_ADDRESS. "银行信息 IF TT_INPUT-BANKN IS NOT INITIAL. LS_BP_BANK_DETAILS-RUN_ID = RUN_ID. LS_BP_BANK_DETAILS-BANK_CTRY = 'CN'. LS_BP_BANK_DETAILS-BANK_KEY = TT_INPUT-BANKL."银行代码 LS_BP_BANK_DETAILS-BANKACCOUNTNAME = TT_INPUT-BKDSC."银行名称 LS_BP_BANK_DETAILS-BANK_ACCT = TT_INPUT-BANKN."银行账户 LS_BP_BANK_DETAILS-BANK_REF = TT_INPUT-BANK_REF."参考 LS_BP_BANK_DETAILS-ACCOUNTHOLDER = ''. LS_BP_BANK_DETAILS-DATA_KEY = '0001'. APPEND LS_BP_BANK_DETAILS TO IT_BP_BANK_DETAILS. ENDIF. "通信----电话 * IF TT_INPUT-TLNMBR1 IS NOT INITIAL. CLEAR LS_BP_ADDRESS_TELENO. LS_BP_ADDRESS_TELENO-RUN_ID = RUN_ID. LS_BP_ADDRESS_TELENO-COUNTRY = 'CN'. LS_BP_ADDRESS_TELENO-TELEPHONE = TT_INPUT-TLNMBR1."公司电话号码 LS_BP_ADDRESS_TELENO-CONSNUMBER = '001'. APPEND LS_BP_ADDRESS_TELENO TO IT_BP_ADDRESS_TELENO. CLEAR LS_BP_ADDRESS_TELENO_REMARKS. LS_BP_ADDRESS_TELENO_REMARKS-RUN_ID = RUN_ID. LS_BP_ADDRESS_TELENO_REMARKS-COMM_NOTES = '公司电话'."注释 LS_BP_ADDRESS_TELENO_REMARKS-LANGU = SY-LANGU. LS_BP_ADDRESS_TELENO_REMARKS-CONSNUMBER = '001'. APPEND LS_BP_ADDRESS_TELENO_REMARKS TO IT_BP_ADDRESS_TELENO_REMARKS. "通信----移动电话 CLEAR LS_BP_ADDRESS_TELENO. LS_BP_ADDRESS_TELENO-RUN_ID = RUN_ID. LS_BP_ADDRESS_TELENO-COUNTRY = 'CN'. LS_BP_ADDRESS_TELENO-TELEPHONE = TT_INPUT-TEL_NUMBER1." LS_BP_ADDRESS_TELENO-R_3_USER = '3'. LS_BP_ADDRESS_TELENO-CONSNUMBER = '002'. APPEND LS_BP_ADDRESS_TELENO TO IT_BP_ADDRESS_TELENO. CLEAR LS_BP_ADDRESS_TELENO_REMARKS. LS_BP_ADDRESS_TELENO_REMARKS-RUN_ID = RUN_ID. LS_BP_ADDRESS_TELENO_REMARKS-COMM_NOTES = |{ TT_INPUT-REMARK3 }|."注释 LS_BP_ADDRESS_TELENO_REMARKS-LANGU = SY-LANGU. LS_BP_ADDRESS_TELENO_REMARKS-CONSNUMBER = '002'. APPEND LS_BP_ADDRESS_TELENO_REMARKS TO IT_BP_ADDRESS_TELENO_REMARKS. FAXNOTE = |{ TT_INPUT-REMARK2 }|."传真注释 CLEAR:LS_BP_ADDRESS_FAXNO. LS_BP_ADDRESS_FAXNO-RUN_ID = RUN_ID. LS_BP_ADDRESS_FAXNO-COUNTRY = 'CN'. LS_BP_ADDRESS_FAXNO-FAX = TT_INPUT-TEL_NUMBER. LS_BP_ADDRESS_FAXNO-CONSNUMBER = '001'. APPEND LS_BP_ADDRESS_FAXNO TO IT_BP_ADDRESS_FAXNO. * ENDIF. IF TT_INPUT-TAXNUMXL IS NOT INITIAL. "税号信息 CLEAR LS_BP_TAX_NUMBER. LS_BP_TAX_NUMBER-RUN_ID = RUN_ID. LS_BP_TAX_NUMBER-TAXTYPE = 'CN0'. LS_BP_TAX_NUMBER-TAXNUMBER = TT_INPUT-TAXNUMXL. APPEND LS_BP_TAX_NUMBER TO IT_BP_TAX_NUMBER. ENDIF. CLEAR TT_INPUT. EXIT. ENDLOOP. "扩充数据 LOOP AT TT_INPUT. IF TT_INPUT-SKUNNR IS NOT INITIAL . "分支机构客户编码 BUSINESSPARTNER2 = TT_INPUT-SKUNNR. BUSINESSPARTNER2 = |{ BUSINESSPARTNER2 ALPHA = IN }|. ENDIF. IF TT_INPUT-MKUNNR IS NOT INITIAL . "母公司客户编码 BUSINESSPARTNER3 = TT_INPUT-MKUNNR. BUSINESSPARTNER3 = |{ BUSINESSPARTNER3 ALPHA = IN }|. ENDIF. IF TT_INPUT-MKUNNR IS NOT INITIAL . "母公司构客户编码 BUSINESSPARTNER3 = TT_INPUT-MKUNNR. BUSINESSPARTNER3 = |{ BUSINESSPARTNER3 ALPHA = IN }|. ENDIF. "客户 LS_CUST_GENERAL-RUN_ID = RUN_ID. APPEND LS_CUST_GENERAL TO IT_CUST_GENERAL. "财务视图 IF TT_INPUT-BUKRS IS NOT INITIAL. CLEAR LS_BP_ROLE. LS_BP_ROLE-RUN_ID = RUN_ID. LS_BP_ROLE-DATA_KEY = 'FLCU00'. LS_BP_ROLE-ROLECATEGORY = 'FLCU00'. APPEND LS_BP_ROLE TO IT_BP_ROLE. ENDIF. "销售视图 IF TT_INPUT-VKORG IS NOT INITIAL AND IT_CUST_TAX_INDICATOR IS INITIAL. CLEAR LS_BP_ROLE. LS_BP_ROLE-RUN_ID = RUN_ID. LS_BP_ROLE-DATA_KEY = 'FLCU01'. LS_BP_ROLE-ROLECATEGORY = 'FLCU01'. APPEND LS_BP_ROLE TO IT_BP_ROLE. "销项税 CLEAR LS_CUST_TAX_INDICATOR. LS_CUST_TAX_INDICATOR-RUN_ID = RUN_ID. LS_CUST_TAX_INDICATOR-TAXKD = TT_INPUT-TAXKD. LS_CUST_TAX_INDICATOR-TATYP = 'MWST'. LS_CUST_TAX_INDICATOR-ALAND = 'CN'. APPEND LS_CUST_TAX_INDICATOR TO IT_CUST_TAX_INDICATOR. ENDIF. "信贷视图 IF TT_INPUT-CREDIT_SGMNT IS NOT INITIAL. CREDIT_ADD = 'X'. LS_BP_ROLE-RUN_ID = RUN_ID. LS_BP_ROLE-DATA_KEY = 'UKM000'. LS_BP_ROLE-ROLECATEGORY = 'UKM000'. APPEND LS_BP_ROLE TO IT_BP_ROLE. "获取信贷视图数据 CREDIT_SGMNT = TT_INPUT-CREDIT_SGMNT."信用段 RISK_CLASS = TT_INPUT-RISK_CLASS."风险类 CHECK_RULE = TT_INPUT-CHECK_RULE."检查规则 CREDIT_LIMIT = TT_INPUT-CREDIT_LIMIT."额度 ENDIF. "财务视图数据 IF TT_INPUT-BUKRS IS NOT INITIAL. CLEAR LS_CUST_COMPANY. LS_CUST_COMPANY-RUN_ID = RUN_ID. LS_CUST_COMPANY-BUKRS = TT_INPUT-BUKRS."公司代码 LS_CUST_COMPANY-AKONT = TT_INPUT-AKONT."统驭科目 LS_CUST_COMPANY-TOGRU = TT_INPUT-TOGRU."容差组 LS_CUST_COMPANY-ZTERM = TT_INPUT-ZTERM1."付款条件 APPEND LS_CUST_COMPANY TO IT_CUST_COMPANY. ENDIF. "销售视图数据 IF TT_INPUT-VKORG IS NOT INITIAL. CLEAR LS_CUST_SALES. LS_CUST_SALES-RUN_ID = RUN_ID. LS_CUST_SALES-VKORG = TT_INPUT-VKORG."销售组织 LS_CUST_SALES-VTWEG = '00'. "分销渠道 LS_CUST_SALES-SPART = '00'. "分部 LS_CUST_SALES-BZIRK = TT_INPUT-BZIRK."销售区域 LS_CUST_SALES-WAERS = TT_INPUT-WAERS. LS_CUST_SALES-VSBED = TT_INPUT-VSBED."装运条件 LS_CUST_SALES-KTGRD = TT_INPUT-KTGRD."客户的账户分配组 LS_CUST_SALES-ZTERM = TT_INPUT-ZTERM."付款条件 LS_CUST_SALES-KALKS = TT_INPUT-KALKS . APPEND LS_CUST_SALES TO IT_CUST_SALES. "合作伙伴功能 CLEAR LS_CUST_SALES_FUNCTIONS. LS_CUST_SALES_FUNCTIONS-RUN_ID = RUN_ID. LS_CUST_SALES_FUNCTIONS-PARVW = 'AG'. LS_CUST_SALES_FUNCTIONS-VKORG = TT_INPUT-VKORG. LS_CUST_SALES_FUNCTIONS-VTWEG = '00'. LS_CUST_SALES_FUNCTIONS-SPART = '00'. LS_CUST_SALES_FUNCTIONS-DEFPA = ''. APPEND LS_CUST_SALES_FUNCTIONS TO IT_CUST_SALES_FUNCTIONS. CLEAR LS_CUST_SALES_FUNCTIONS. LS_CUST_SALES_FUNCTIONS-RUN_ID = RUN_ID. LS_CUST_SALES_FUNCTIONS-PARVW = 'RE'. LS_CUST_SALES_FUNCTIONS-VKORG = TT_INPUT-VKORG. LS_CUST_SALES_FUNCTIONS-VTWEG = '00'. LS_CUST_SALES_FUNCTIONS-SPART = '00'. LS_CUST_SALES_FUNCTIONS-DEFPA = ''. APPEND LS_CUST_SALES_FUNCTIONS TO IT_CUST_SALES_FUNCTIONS. CLEAR LS_CUST_SALES_FUNCTIONS. LS_CUST_SALES_FUNCTIONS-RUN_ID = RUN_ID. LS_CUST_SALES_FUNCTIONS-PARVW = 'RG'. LS_CUST_SALES_FUNCTIONS-VKORG = TT_INPUT-VKORG. LS_CUST_SALES_FUNCTIONS-VTWEG = '00'. LS_CUST_SALES_FUNCTIONS-SPART = '00'. LS_CUST_SALES_FUNCTIONS-DEFPA = ''. APPEND LS_CUST_SALES_FUNCTIONS TO IT_CUST_SALES_FUNCTIONS. CLEAR LS_CUST_SALES_FUNCTIONS. LS_CUST_SALES_FUNCTIONS-RUN_ID = RUN_ID. LS_CUST_SALES_FUNCTIONS-PARVW = 'WE'. LS_CUST_SALES_FUNCTIONS-VKORG = TT_INPUT-VKORG. LS_CUST_SALES_FUNCTIONS-VTWEG = '00'. LS_CUST_SALES_FUNCTIONS-SPART = '00'. LS_CUST_SALES_FUNCTIONS-DEFPA = ''. APPEND LS_CUST_SALES_FUNCTIONS TO IT_CUST_SALES_FUNCTIONS. "自定义功能 IF TT_INPUT-KTONR1 IS NOT INITIAL . CLEAR LS_CUST_SALES_FUNCTIONS. LS_CUST_SALES_FUNCTIONS-RUN_ID = RUN_ID. LS_CUST_SALES_FUNCTIONS-PARVW = 'ZA'."销售助理 LS_CUST_SALES_FUNCTIONS-VKORG = TT_INPUT-VKORG. LS_CUST_SALES_FUNCTIONS-VTWEG = '00'. LS_CUST_SALES_FUNCTIONS-SPART = '00'. LS_CUST_SALES_FUNCTIONS-DEFPA = ''. LS_CUST_SALES_FUNCTIONS-PARTNER = TT_INPUT-KTONR1."销售助理ID APPEND LS_CUST_SALES_FUNCTIONS TO IT_CUST_SALES_FUNCTIONS. ENDIF. IF TT_INPUT-KTONR IS NOT INITIAL . CLEAR LS_CUST_SALES_FUNCTIONS. LS_CUST_SALES_FUNCTIONS-RUN_ID = RUN_ID. LS_CUST_SALES_FUNCTIONS-PARVW = 'ZS'."客户经理 LS_CUST_SALES_FUNCTIONS-VKORG = TT_INPUT-VKORG. LS_CUST_SALES_FUNCTIONS-VTWEG = '00'. LS_CUST_SALES_FUNCTIONS-SPART = '00'. LS_CUST_SALES_FUNCTIONS-DEFPA = ''. LS_CUST_SALES_FUNCTIONS-PARTNER = TT_INPUT-KTONR ."客户经理ID APPEND LS_CUST_SALES_FUNCTIONS TO IT_CUST_SALES_FUNCTIONS. ENDIF. ENDIF. ENDLOOP. *调用创建的方法 SORT IT_BP_ROLE BY RUN_ID DATA_KEY. DELETE ADJACENT DUPLICATES FROM IT_BP_ROLE COMPARING RUN_ID DATA_KEY. REFRESH:CT_RETURN. CALL FUNCTION 'RFC_CVI_EI_INBOUND_MAIN' TABLES IT_BP_GENERAL = IT_BP_GENERAL IT_BP_ROLE = IT_BP_ROLE IT_BP_BANK_DETAILS = IT_BP_BANK_DETAILS IT_BP_TAX_NUMBER = IT_BP_TAX_NUMBER IT_BP_ADDRESS = IT_BP_ADDRESS IT_BP_ADDRESS_TELENO = IT_BP_ADDRESS_TELENO IT_BP_ADDRESS_TELENO_REMARKS = IT_BP_ADDRESS_TELENO_REMARKS IT_BP_ADDRESS_FAXNO = IT_BP_ADDRESS_FAXNO IT_BP_RELATIONS = IT_BP_RELATIONS IT_CUST_GENERAL = IT_CUST_GENERAL IT_CUST_COMPANY = IT_CUST_COMPANY IT_CUST_SALES = IT_CUST_SALES IT_CUST_SALES_FUNCTIONS = IT_CUST_SALES_FUNCTIONS IT_CUST_TAX_INDICATOR = IT_CUST_TAX_INDICATOR CT_RETURN = CT_RETURN. REFRESH:IT_BP_GENERAL,IT_BP_ROLE,IT_BP_BANK_DETAILS,IT_BP_TAX_NUMBER, IT_BP_ADDRESS,IT_BP_ADDRESS_TELENO,IT_BP_ADDRESS_TELENO_REMARKS, IT_BP_ADDRESS_FAXNO,IT_BP_RELATIONS,IT_CUST_GENERAL,IT_CUST_COMPANY, IT_CUST_SALES,IT_CUST_SALES_FUNCTIONS,IT_CUST_TAX_INDICATOR. * READ TABLE CT_RETURN INTO DATA(LS_RETURN) WITH KEY TYPE = 'E'. READ TABLE CT_RETURN INTO DATA(LS_RETURN) WITH KEY TYPE = 'S'. IF SY-SUBRC = 0. * TT_RETURN-ZTYPE = 'S'. * TT_RETURN-ID = LS_RETURN-OBJECT_KEY. * TT_RETURN-ZTYPE = MESSAGE. "添加信贷数据 ---实际没啥用 以后研究 IF CREDIT_ADD IS NOT INITIAL. PERFORM FRM_CUST_CREDIT_ADD USING LS_RETURN-OBJECT_KEY"客户编号 CREDIT_SGMNT "信用段 RISK_CLASS "风险类 CHECK_RULE "检查规则 CREDIT_LIMIT. "额度 CLEAR: CREDIT_SGMNT,"信用段 RISK_CLASS,"风险类 CHECK_RULE,"检查规则 CREDIT_LIMIT."额度 CLEAR CREDIT_ADD. ENDIF. "添加分支机构关系视图 IF BUSINESSPARTNER2 IS NOT INITIAL. CLEAR RELATIONSHIP_ADD_MSG. PERFORM FRM_RELATIONSHIP_ADD USING LS_RETURN-OBJECT_KEY BUSINESSPARTNER2."分支机构放后面 CLEAR BUSINESSPARTNER2. ENDIF. "添加母公司关系视图 IF BUSINESSPARTNER3 IS NOT INITIAL. CLEAR RELATIONSHIP_ADD_MSG. PERFORM FRM_RELATIONSHIP_ADD_M USING BUSINESSPARTNER3 LS_RETURN-OBJECT_KEY."母公司放前面 CLEAR BUSINESSPARTNER3. ENDIF. "录屏增加收货联系人 IF FAXNOTE IS NOT INITIAL. PERFORM BDC_ADD_FAXNOTE USING LS_RETURN-OBJECT_KEY FAXNOTE."客户编号 ENDIF. TT_RETURN-TYPE = 'S'. TT_RETURN-ID = LS_RETURN-OBJECT_KEY. TT_RETURN-MESSAGE = |BP创建客户成功,编号:{ LS_RETURN-OBJECT_KEY } { LS_RETURN-MESSAGE } { RELATIONSHIP_ADD_MSG } { RELATIONSHIP_ADD_M_MSG }|. APPEND TT_RETURN. CLEAR:TT_RETURN. ELSE. TT_RETURN-TYPE = 'E'. TT_RETURN-ID = LS_RETURN-OBJECT_KEY. LOOP AT CT_RETURN INTO DATA(GS_RE) WHERE TYPE = 'E'. TT_RETURN-MESSAGE = TT_RETURN-MESSAGE && GS_RE-MESSAGE. ENDLOOP. APPEND TT_RETURN. CLEAR:TT_RETURN. ENDIF. ENDFUNCTION.
*----------------------------------------------------------------------* ***INCLUDE LZKING004F01. *----------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form FM_CLEAR *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM FM_CLEAR . REFRESH: IT_BP_ROLE, IT_BP_GENERAL, CT_RETURN, "客户关系 IT_BP_RELATIONS, "银行信息 IT_BP_BANK_DETAILS, "税码 IT_BP_TAX_NUMBER, "客户数据 IT_CUST_GENERAL, "客户公司代码 IT_CUST_COMPANY, "销售与分销 IT_CUST_SALES, "合作伙伴功能 IT_CUST_SALES_FUNCTIONS, "销项税 IT_CUST_TAX_INDICATOR, "地址 IT_BP_ADDRESS, IT_BP_ADDRESS_TELENO, IT_BP_ADDRESS_FAXNO, IT_BP_ADDRESS_TELENO_REMARKS. ENDFORM. *&---------------------------------------------------------------------* *& Form BDC_ADD_FAXNOTE *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* * -->P_LS_RETURN_OBJECT_KEY text * -->P_FAXNOTE text *&---------------------------------------------------------------------* FORM BDC_ADD_FAXNOTE USING P_LS_RETURN_OBJECT_KEY P_FAXNOTE. REFRESH ITAB_BDCTAB[]. CLEAR ITAB_BDCTAB[]. * "录屏实现自定义字段创建 PERFORM BDC_DYNPRO USING 'SAPMF02D' '0101'. PERFORM BDC_FIELD USING 'BDC_CURSOR' 'USE_ZAV'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'. PERFORM BDC_FIELD USING 'RF02D-KUNNR' P_LS_RETURN_OBJECT_KEY. PERFORM BDC_FIELD USING 'RF02D-D0110' 'X'. PERFORM BDC_FIELD USING 'USE_ZAV' 'X'. PERFORM BDC_DYNPRO USING 'SAPMF02D' '0111'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '=$MFA'. PERFORM BDC_FIELD USING 'BDC_CURSOR' 'SZA1_D0100-TITLE_MEDI'. PERFORM BDC_DYNPRO USING 'SAPLSZA6' '0300'. PERFORM BDC_FIELD USING 'BDC_CURSOR' 'ADFAX-REMARK(01)'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '=CONT'. PERFORM BDC_FIELD USING 'ADFAX-REMARK(01)' P_FAXNOTE. PERFORM BDC_DYNPRO USING 'SAPMF02D' '0111'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '=UPDA'. PERFORM BDC_FIELD USING 'BDC_CURSOR' 'SZA1_D0100-TITLE_MEDI'. CALL TRANSACTION 'XD02' USING ITAB_BDCTAB MODE P_MODE UPDATE P_UPDA MESSAGES INTO MESSTAB. READ TABLE MESSTAB WITH KEY MSGTYP = 'E'. IF SY-SUBRC EQ 0. MESSAGE '增加收货人失败' TYPE 'E'. EXIT. ELSE. * MESSAGE '修改成功' TYPE 'S'. ENDIF. ENDFORM. FORM BDC_DYNPRO USING NAME VALUE. CLEAR ITAB_BDCTAB. ITAB_BDCTAB-PROGRAM = NAME. ITAB_BDCTAB-DYNPRO = VALUE. ITAB_BDCTAB-DYNBEGIN = 'X'. APPEND ITAB_BDCTAB. ENDFORM. "BDC_DYNPRO *&---------------------------------------------------------------------* *& FORM BDC_FIELD *&---------------------------------------------------------------------* FORM BDC_FIELD USING NAME VALUE. CLEAR ITAB_BDCTAB. ITAB_BDCTAB-FNAM = NAME. ITAB_BDCTAB-FVAL = VALUE. APPEND ITAB_BDCTAB. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_CUST_CREDIT_ADD *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* * -->P_LS_RETURN_OBJECT_KEY text * -->P_CREDIT_SGMNT text * -->P_RISK_CLASS text * -->P_CHECK_RULE text * -->P_CREDIT_LIMIT text *&---------------------------------------------------------------------* FORM FRM_CUST_CREDIT_ADD USING PARTNERID TYPE ANY CREDIT_SGMNT TYPE ANY RISK_CLASS TYPE ANY CHECK_RULE TYPE ANY CREDIT_LIMIT TYPE ANY. DATA: IO_FACADE TYPE REF TO CL_UKM_FACADE, IO_BUPA_FACTORY TYPE REF TO CL_UKM_BUPA_FACTORY, IO_PARTNER TYPE REF TO CL_UKM_BUSINESS_PARTNER, IO_ACCOUNT TYPE REF TO CL_UKM_ACCOUNT, LW_BP_CREDIT_SGM TYPE UKM_S_BP_CMS_SGM. DATA: LWA_UKM_S_BP_CMS TYPE UKM_S_BP_CMS. DATA: LV_PARTNER TYPE BU_PARTNER, LV_CREDIT_SGMNT TYPE UKM_CREDIT_SGMNT. DATA C_RETURN TYPE UKM_T_MONITOR_RETURN. LV_PARTNER = PARTNERID."客户代码 * 创建'MAINTAIN'对象 IO_FACADE = CL_UKM_FACADE=>CREATE( I_ACTIVITY = CL_UKM_CNST_EVENTING=>BP_MAINTENANCE ). IO_BUPA_FACTORY = IO_FACADE->GET_BUPA_FACTORY( ). LV_CREDIT_SGMNT = CREDIT_SGMNT."信用段 IO_PARTNER = IO_BUPA_FACTORY->GET_BUSINESS_PARTNER( LV_PARTNER ). IO_PARTNER->GET_BP_CMS( IMPORTING ES_BP_CMS = LWA_UKM_S_BP_CMS ). LWA_UKM_S_BP_CMS-RISK_CLASS = RISK_CLASS. "风险类 LWA_UKM_S_BP_CMS-CHECK_RULE = CHECK_RULE. "检查规则 LWA_UKM_S_BP_CMS-LIMIT_RULE = 'B2B-EXIST'. IO_PARTNER->SET_BP_CMS( LWA_UKM_S_BP_CMS ). CALL METHOD IO_BUPA_FACTORY->GET_CREDIT_ACCOUNT EXPORTING I_PARTNER = LV_PARTNER I_CREDIT_SGMNT = LV_CREDIT_SGMNT RECEIVING RO_CREDIT_ACCOUNT = IO_ACCOUNT. IO_ACCOUNT->GET_BP_CMS_SGM( IMPORTING ES_BP_CMS_SGM = LW_BP_CREDIT_SGM ). LW_BP_CREDIT_SGM-CREDIT_LIMIT = CREDIT_LIMIT."信用额度 IO_ACCOUNT->SET_BP_CMS_SGM( EXPORTING IS_BP_CMS_SGM = LW_BP_CREDIT_SGM ). IO_BUPA_FACTORY->SAVE_ALL( EXPORTING I_UPD_TASK = ABAP_FALSE RECEIVING ET_RETURN = C_RETURN ). * LOOP AT C_RETURN INTO DATA(LS). * WRITE: / LS-MSGTY ,LS-MESSAGE. * ENDLOOP. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_RELATIONSHIP_ADD *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* * -->P_LS_RETURN_OBJECT_KEY text * -->P_BUSINESSPARTNER2 text *&---------------------------------------------------------------------* FORM FRM_RELATIONSHIP_ADD USING BUSINESSPARTNER1 TYPE ANY BUSINESSPARTNER2 TYPE ANY. DATA RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE. DATA COMMIT_FLAG(1). CLEAR COMMIT_FLAG. DATA RELATIONSHIPCATEGORY TYPE BUT050-RELTYP. "添加分支机构关系 DATA L_BUSINESSPARTNER1 TYPE BAPIBUS1006_HEAD-BPARTNER. DATA L_BUSINESSPARTNER2 TYPE BAPIBUS1006_HEAD-BPARTNER. CLEAR: L_BUSINESSPARTNER1,L_BUSINESSPARTNER2,RELATIONSHIPCATEGORY,RETURN. L_BUSINESSPARTNER1 = BUSINESSPARTNER1. L_BUSINESSPARTNER2 = BUSINESSPARTNER2. L_BUSINESSPARTNER1 = |{ L_BUSINESSPARTNER1 ALPHA = IN }|. L_BUSINESSPARTNER2 = |{ L_BUSINESSPARTNER2 ALPHA = IN }|. RELATIONSHIPCATEGORY = 'FSB002'. CALL FUNCTION 'BAPI_BUPR_RELATIONSHIP_CREATE' EXPORTING BUSINESSPARTNER1 = L_BUSINESSPARTNER1 BUSINESSPARTNER2 = L_BUSINESSPARTNER2 RELATIONSHIPCATEGORY = RELATIONSHIPCATEGORY * RELATIONSHIPTYPE = * VALIDFROMDATE = SY-DATLO * VALIDUNTILDATE = '99991231' * DIFFERENTIATIONTYPEVALUE = * XDFREL = TABLES RETURN = RETURN. LOOP AT RETURN INTO DATA(WA) WHERE TYPE = 'E'. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' * IMPORTING * RETURN = . COMMIT_FLAG = 'X'. RELATIONSHIP_ADD_MSG = |添加关系类别FFSB002失败:{ WA-MESSAGE }|. EXIT. ENDLOOP. IF COMMIT_FLAG NE 'X'. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING WAIT = 'X' * IMPORTING * RETURN = . ENDIF. ENDFORM. FORM FRM_RELATIONSHIP_ADD_M USING BUSINESSPARTNER1 TYPE ANY BUSINESSPARTNER2 TYPE ANY. DATA RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE. DATA COMMIT_FLAG(1). CLEAR COMMIT_FLAG. DATA RELATIONSHIPCATEGORY TYPE BUT050-RELTYP. "添加母公司关系 DATA L_BUSINESSPARTNER1 TYPE BAPIBUS1006_HEAD-BPARTNER. DATA L_BUSINESSPARTNER2 TYPE BAPIBUS1006_HEAD-BPARTNER. CLEAR: L_BUSINESSPARTNER1,L_BUSINESSPARTNER2,RELATIONSHIPCATEGORY,RETURN. L_BUSINESSPARTNER1 = BUSINESSPARTNER1. L_BUSINESSPARTNER2 = BUSINESSPARTNER2. L_BUSINESSPARTNER1 = |{ L_BUSINESSPARTNER1 ALPHA = IN }|. L_BUSINESSPARTNER2 = |{ L_BUSINESSPARTNER2 ALPHA = IN }|. RELATIONSHIPCATEGORY = 'FSB002'. CALL FUNCTION 'BAPI_BUPR_RELATIONSHIP_CREATE' EXPORTING BUSINESSPARTNER1 = L_BUSINESSPARTNER1 BUSINESSPARTNER2 = L_BUSINESSPARTNER2 RELATIONSHIPCATEGORY = RELATIONSHIPCATEGORY * RELATIONSHIPTYPE = * VALIDFROMDATE = SY-DATLO * VALIDUNTILDATE = '99991231' * DIFFERENTIATIONTYPEVALUE = * XDFREL = TABLES RETURN = RETURN. LOOP AT RETURN INTO DATA(WA) WHERE TYPE = 'E'. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. COMMIT_FLAG = 'X'. RELATIONSHIP_ADD_M_MSG = |添加关系类别FFSB002失败:{ WA-MESSAGE }|. EXIT. ENDLOOP. IF COMMIT_FLAG NE 'X'. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING WAIT = 'X'. ENDIF. ENDFORM.
FUNCTION-POOL ZKING004 . "MESSAGE-ID ... *RFC_CVI_EI_INBOUND_MAIN. DATA: IT_BP_ROLE TYPE TABLE OF CVIS_BP_ROLE, LS_BP_ROLE TYPE CVIS_BP_ROLE, IT_BP_GENERAL TYPE TABLE OF CVIS_BP_GENERAL, LS_BP_GENERAL TYPE CVIS_BP_GENERAL, CT_RETURN TYPE TABLE OF CVIS_BP_RETURN, "客户关系 IT_BP_RELATIONS TYPE TABLE OF CVIS_BP_RELATION, LS_BP_RELATIONS TYPE CVIS_BP_RELATION, "银行信息 IT_BP_BANK_DETAILS TYPE TABLE OF CVIS_BP_BANK_DETAILS, LS_BP_BANK_DETAILS TYPE CVIS_BP_BANK_DETAILS, "税码 IT_BP_TAX_NUMBER TYPE TABLE OF CVIS_BP_TAX_NUMBER, LS_BP_TAX_NUMBER TYPE CVIS_BP_TAX_NUMBER, "客户数据 IT_CUST_GENERAL TYPE TABLE OF CVIS_CUSTOMER_GENERAL, LS_CUST_GENERAL TYPE CVIS_CUSTOMER_GENERAL, "客户公司代码 IT_CUST_COMPANY TYPE TABLE OF CVIS_CUSTOMER_COMPANY, LS_CUST_COMPANY TYPE CVIS_CUSTOMER_COMPANY, "销售与分销 IT_CUST_SALES TYPE TABLE OF CVIS_CUSTOMER_SALES, LS_CUST_SALES TYPE CVIS_CUSTOMER_SALES, "合作伙伴功能 IT_CUST_SALES_FUNCTIONS TYPE TABLE OF CVIS_CUSTOMER_SALES_FUNC, LS_CUST_SALES_FUNCTIONS TYPE CVIS_CUSTOMER_SALES_FUNC, "销项税 IT_CUST_TAX_INDICATOR TYPE TABLE OF CVIS_CUSTOMER_TAX_INDICATOR, LS_CUST_TAX_INDICATOR TYPE CVIS_CUSTOMER_TAX_INDICATOR, "地址 IT_BP_ADDRESS TYPE TABLE OF CVIS_BP_ADDRESS, LS_BP_ADDRESS TYPE CVIS_BP_ADDRESS, IT_BP_ADDRESS_TELENO TYPE TABLE OF CVIS_BP_ADDRESS_TELENO, LS_BP_ADDRESS_TELENO TYPE CVIS_BP_ADDRESS_TELENO, IT_BP_ADDRESS_FAXNO TYPE TABLE OF CVIS_BP_ADDRESS_FAXNO, LS_BP_ADDRESS_FAXNO TYPE CVIS_BP_ADDRESS_FAXNO, IT_BP_ADDRESS_TELENO_REMARKS TYPE TABLE OF CVIS_ADDRESS_TELNO_REMARKS, LS_BP_ADDRESS_TELENO_REMARKS TYPE CVIS_ADDRESS_TELNO_REMARKS. "填充数据 DATA: CREDIT_SGMNT TYPE STRING, "信用段 RISK_CLASS TYPE STRING, "风险类 CHECK_RULE TYPE STRING, "检查规则 CREDIT_LIMIT TYPE STRING. "额度 DATA BUSINESSPARTNER2 TYPE BAPIBUS1006_HEAD-BPARTNER."分支机构编码 DATA BUSINESSPARTNER3 TYPE BAPIBUS1006_HEAD-BPARTNER."母公司机构编码 DATA RELATIONSHIP_ADD_MSG TYPE STRING. DATA RELATIONSHIP_ADD_M_MSG TYPE STRING. DATA:FAXNOTE TYPE STRING. DATA RUN_ID TYPE I. DATA CREDIT_ADD TYPE STRING. DATA:GV_ERROR_TEXT TYPE STRING. DATA:ITAB_BDCTAB TYPE TABLE OF BDCDATA WITH HEADER LINE. DATA:P_MODE TYPE CHAR1 VALUE 'N', P_UPDA TYPE CHAR1 VALUE 'L'. DATA BEGIN OF MESSTAB OCCURS 10. INCLUDE STRUCTURE BDCMSGCOLL. DATA END OF MESSTAB.