欢迎来到萧静默的博客

书山有路勤为径,学海无涯苦作舟。

员工客户及财务客户新建函数

有的公司在员工报销或者付银行利息时候需要建立客户,此时只需要扩展财务视图即可以,所以用不到很复杂的客户信息,一般只需要一个名称及一个科目就可以。

所以此时用了一个接口,让财务人员自己填好内容,自己触发程序自动创建。

做接口的话,结构如下:

 

 函数如下

FUNCTION ZFM_FINANCIAL_COUSTOMER.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(TT_INPUT) TYPE  ZTCUSTOMER OPTIONAL
*"  TABLES
*"      TT_RETURN STRUCTURE  BAPIRET1
*"----------------------------------------------------------------------
  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 RUN_ID TYPE I.

  CLEAR LS_BP_GENERAL.
  LS_BP_GENERAL-RUN_ID          = RUN_ID.
  IF TT_INPUT-GROUP = 'ZBP5'.
    LS_BP_GENERAL-GROUPING        = TT_INPUT-GROUP.
    LS_BP_GENERAL-TITLE_KEY       = '0003'."称谓
    LS_BP_GENERAL-CATEGORY        = '2'. "1-人员 2-组织 3-组
    LS_BP_GENERAL-OBJECT_TASK     = 'I'."I插入 U更新 M修改 D删除 C当前状态
    LS_BP_GENERAL-NAME1           = TT_INPUT-NAME_ORG1."名称
    LS_BP_GENERAL-SEARCHTERM1     = TT_INPUT-SORT1_TXT."搜索项
*    LS_BP_GENERAL-CORRESPONDLANGUAGE = 1.
  ENDIF.
  IF TT_INPUT-GROUP = 'ZBP6'.
    LS_BP_GENERAL-BPARTNER        = TT_INPUT-KUNNR.
*    LS_BP_GENERAL-GROUPING        = TT_INPUT-GROUP.
    LS_BP_GENERAL-TITLE_KEY       = '0002'."称谓
    LS_BP_GENERAL-CATEGORY        = '1'. "1-人员 2-组织 3-组  "ZFIRP031
    LS_BP_GENERAL-FIRSTNAME       = TT_INPUT-NAME_ORG1+0(1)."名称
    LS_BP_GENERAL-LASTNAME        = TT_INPUT-NAME_ORG1+1(2)."名称
    LS_BP_GENERAL-OBJECT_TASK     = 'I'."I插入 U更新 M修改 D删除 C当前状态
    LS_BP_GENERAL-SEARCHTERM1     = TT_INPUT-SORT1_TXT."搜索项
    LS_BP_GENERAL-CORRESPONDLANGUAGE = 1.
  ENDIF.
  APPEND LS_BP_GENERAL TO IT_BP_GENERAL.
  "地址数据
  LS_BP_ADDRESS-RUN_ID     = RUN_ID.
  LS_BP_ADDRESS-COUNTRY    = 'CN'."国家
*  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-POSTL_COD1 = TT_INPUT-PSTCD1."邮编
  APPEND LS_BP_ADDRESS TO IT_BP_ADDRESS.

  "客户
  LS_CUST_GENERAL-RUN_ID = RUN_ID.
  APPEND LS_CUST_GENERAL TO IT_CUST_GENERAL.
  "财务视图
  IF TT_INPUT-ZCOMPANY 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-ZCOMPANY CS '6000'.
    "财务视图数据
    CLEAR LS_CUST_COMPANY.
    LS_CUST_COMPANY-RUN_ID = RUN_ID.
    LS_CUST_COMPANY-BUKRS  = '6000'."公司代码
    LS_CUST_COMPANY-AKONT  = TT_INPUT-AKONT."统驭科目
    LS_CUST_COMPANY-TOGRU  = '6000'."容差组
    LS_CUST_COMPANY-ZTERM  = TT_INPUT-ZTERM1."付款条件
    APPEND LS_CUST_COMPANY TO IT_CUST_COMPANY.
  ENDIF.
  IF TT_INPUT-ZCOMPANY CS '8000'.
    "财务视图数据
    CLEAR LS_CUST_COMPANY.
    LS_CUST_COMPANY-RUN_ID = RUN_ID.
    LS_CUST_COMPANY-BUKRS  = '8000'."公司代码
    LS_CUST_COMPANY-AKONT  = TT_INPUT-AKONT."统驭科目
    LS_CUST_COMPANY-TOGRU  = '8000'."容差组
    LS_CUST_COMPANY-ZTERM  = TT_INPUT-ZTERM1."付款条件
    APPEND LS_CUST_COMPANY TO IT_CUST_COMPANY.
  ENDIF.
  IF TT_INPUT-ZCOMPANY CS '9000'.
    "财务视图数据
    CLEAR LS_CUST_COMPANY.
    LS_CUST_COMPANY-RUN_ID = RUN_ID.
    LS_CUST_COMPANY-BUKRS  = '9000'."公司代码
    LS_CUST_COMPANY-AKONT  = TT_INPUT-AKONT."统驭科目
    LS_CUST_COMPANY-TOGRU  = '9000'."容差组
    LS_CUST_COMPANY-ZTERM  = TT_INPUT-ZTERM1."付款条件
    APPEND LS_CUST_COMPANY TO IT_CUST_COMPANY.
  ENDIF.
  IF TT_INPUT-ZCOMPANY CS '7000'.
    "财务视图数据
    CLEAR LS_CUST_COMPANY.
    LS_CUST_COMPANY-RUN_ID = RUN_ID.
    LS_CUST_COMPANY-BUKRS  = '7000'."公司代码
    LS_CUST_COMPANY-AKONT  = TT_INPUT-AKONT."统驭科目
    LS_CUST_COMPANY-TOGRU  = '7000'."容差组
    LS_CUST_COMPANY-ZTERM  = TT_INPUT-ZTERM1."付款条件
    APPEND LS_CUST_COMPANY TO IT_CUST_COMPANY.
  ENDIF.
  IF TT_INPUT-ZCOMPANY CS '3000'.
    "财务视图数据
    CLEAR LS_CUST_COMPANY.
    LS_CUST_COMPANY-RUN_ID = RUN_ID.
    LS_CUST_COMPANY-BUKRS  = '3000'."公司代码
    LS_CUST_COMPANY-AKONT  = TT_INPUT-AKONT."统驭科目
    LS_CUST_COMPANY-TOGRU  = '3000'."容差组
    LS_CUST_COMPANY-ZTERM  = TT_INPUT-ZTERM1."付款条件
    APPEND LS_CUST_COMPANY TO IT_CUST_COMPANY.
  ENDIF.

*调用创建的方法
  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 = 'S'.
  IF SY-SUBRC = 0.
    TT_RETURN-TYPE = 'S'.
    TT_RETURN-ID = LS_RETURN-OBJECT_KEY.
    TT_RETURN-MESSAGE = |BP创建客户成功,编号:{ LS_RETURN-OBJECT_KEY } { LS_RETURN-MESSAGE } |.
    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.

稍微改改 可以直接使用。

客户全量新建的可以参考:https://www.cnblogs.com/BruceKing/p/15509261.html

posted @ 2022-09-07 13:33  萧静默  阅读(79)  评论(0编辑  收藏  举报