供应商主数据批导
【摘要】 实现效果图 核心 BAPI创建:BAPI_BUPA_CREATE_FROM_DATA删除:函数模块 BUP_BUPA_MASS_DELETE 源代码DATA: BEGIN OF gt_alv OCCURS 0, sel TYPE c, " 选择 icon_a TYPE char10, ...
实现效果图
核心 BAPI
创建:BAPI_BUPA_CREATE_FROM_DATA
删除:函数模块 BUP_BUPA_MASS_DELETE
源代码
DATA: BEGIN OF gt_alv OCCURS 0,
sel TYPE c, " 选择
icon_a TYPE char10, " 供应商信息指示灯
remark_a TYPE char255, " 供应商备注(返回的消息)
icon_b TYPE char10, " 银行信息指示灯
remark_b TYPE char255, " 银行备注(返回的消息)
iban(30), " IBAN
partner(10), " 供应商代码 -- 业务伙伴编码
bu_group(4), " BP01 -- 保留,业务伙伴分组(供应商账户组)
ekorg(4), " 采购组织
webre(1), " 基于收货的发票验证
lebre TYPE lfm1-lebre, " 基于服务的开盘校验,默认勾选
bukrs(4), " 公司代码
bu_sort1(20), " 检索项:测试客户-wtx
akont(10), " 统驭科目
name_org1(40), " 供应商名称(英文)
street(60), " 地址:街道名称
city1(40), " 城市:杭州
land1(3), " 国家:CN 中国
post_code1(10), " 邮政编码:311107
langu(2), " 语言:ZH 中文
tel_number(30), " 电话:0571-86397805 -- 保留
fax_number(30), " 传真 -- 保留
verkf(30), " 供应商联系人 -- 保留
job(20), " 岗位 -- 新增
smtp_addr(241), " E-mail -- 保留
bank_land(3), " 银行国家 -- 保留
bnkey TYPE t005-bnkey, " 银行代码的名称,1位数字
bankl(15), " 银行代码 -- 保留
swift(60), " SWIFT CODE/BIC -- 新增
bank_no(40), " 银行账号 -- 保留,银行账户号码
koinh(60), " 账户持有人 -- 保留,银行账户名称
bank_name(60), " 银行名称 -- 保留
provz(20), " 银行省份 -- 新增
provz1(20), " 银行城市 -- 新增
brnch, " 分行 -- 新增
waers(5), " 币种:CNY 中国人民币;-- 保留,订单货币
zterm2(4), " 默认付款条件 -- 保留,付款条款
END OF gt_alv.
DATA: gs_alv LIKE LINE OF gt_alv,
g_function_key TYPE smp_dyntxt. " 功能按钮
DATA: g_partner TYPE bu_partner. "业务伙伴编号
DATA: l_bpartner TYPE bapibus1006_head-bpartner, "业务伙伴编码
l_partn_cat TYPE bapibus1006_head-partn_cat, "业务伙伴类别
l_partn_grp TYPE bapibus1006_head-partn_grp, "业务伙伴分组
ls_central TYPE bapibus1006_central, "一般 BP 数据,
ls_central_person TYPE bapibus1006_central_person, " 个人数据的
ls_central_organ TYPE bapibus1006_central_organ, "组织数据的 BAPI 结构
ls_address TYPE bapibus1006_address, "地址数据的 BAPI 结构
ls_bapibus1006_industrysector TYPE bapibus1006_industrysector,
ls_bapibus1006_bankdetail TYPE bapibus1006_bankdetail, " 银行数据的 BAPI 结构
wa_customer TYPE cmds_ei_extern,
lt_master_data TYPE vmds_ei_main,
ls_master_data TYPE vmds_ei_extern,
ls_company TYPE vmds_ei_company,
ls_purchasing TYPE vmds_ei_purchasing,
ls_functions TYPE vmds_ei_functions,
wa_customers TYPE cmds_ei_main,
wa_correct TYPE cmds_ei_main,
wa_defective TYPE cmds_ei_main,
wa_mes_correct TYPE cvis_message,
wa_mes_error TYPE cvis_message,
l1 TYPE vmds_ei_main,
l2 TYPE cvis_message,
l3 TYPE vmds_ei_main,
l4 TYPE cvis_message,
l5 TYPE cvis_message,
lt_bapiadtel LIKE bapiadtel OCCURS 0 WITH HEADER LINE, "电话号码的 BAPI 结构(办公地址服务)
lt_bapiadfax LIKE bapiadfax OCCURS 0 WITH HEADER LINE, "传真号码的 BAPI 结构(办公地址服务)
lt_bapiadsmtp LIKE bapiadsmtp OCCURS 0 WITH HEADER LINE, "电子邮件地址的 BAPI 结构(办公地址服务)
lt_guid LIKE bus000___i OCCURS 0 WITH HEADER LINE, "CBP: 一般数据和状态信息
lt_custo LIKE bus000_eew OCCURS 0 WITH HEADER LINE, "SAP BP: 传输用于 CI 包括 BP 扩展的结构
lt_return1 LIKE bapiret2 OCCURS 0 WITH HEADER LINE, "返回参数
lt_return2 LIKE bapiret2 OCCURS 0 WITH HEADER LINE, "返回参数
lt_return3 LIKE bapiret2 OCCURS 0 WITH HEADER LINE, "返回参数
lt_return4 LIKE bapiret2 OCCURS 0 WITH HEADER LINE, "返回参数
lt_return5 LIKE bapiret2 OCCURS 0 WITH HEADER LINE, "返回参数
lt_fknvi LIKE fknvi OCCURS 0 WITH HEADER LINE,
lt_fknvp LIKE fknvp OCCURS 0 WITH HEADER LINE.
DATA : l_customer TYPE kunnr,
l_vendor TYPE lifnr.
DATA: l_msg1(255) TYPE c, "返回消息
l_msg1_1(255) TYPE c, "返回消息
l_msg2(255) TYPE c, "返回消息
l_msg3(255) TYPE c, "返回消息
l_msg4(255) TYPE c, "返回消息
l_msg5(255) TYPE c, "返回消息
l_msgl4(255) TYPE c, "返回消息
l_msgl5(255) TYPE c, "返回消息
l_grid TYPE REF TO cl_gui_alv_grid.
*----------------------------------------------------------------------*
* 选择屏幕 SELECTION-SCREEN *
*----------------------------------------------------------------------*
SELECTION-SCREEN FUNCTION KEY 1.
SELECTION-SCREEN BEGIN OF BLOCK blk02 WITH FRAME TITLE TEXT-005.
PARAMETERS p_file LIKE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK blk02.
SELECTION-SCREEN BEGIN OF BLOCK blk03 WITH FRAME TITLE TEXT-006.
SELECTION-SCREEN:
COMMENT /2(75) t2.
SELECTION-SCREEN END OF BLOCK blk03.
*----------------------------------------------------------------------*
* 屏幕初始化,设置图标和文本 INITIALIZATION *
*----------------------------------------------------------------------*
INITIALIZATION.
* 工具栏添加下载模板按钮
CLEAR g_function_key.
g_function_key-icon_id = icon_read_file.
IF sy-langu EQ '1'.
g_function_key-icon_text = '供应商导入模版下载'.
g_function_key-quickinfo = '供应商导入模版下载'.
ELSE.
g_function_key-icon_text = 'Supplier Import Template Download'.
g_function_key-quickinfo = 'Supplier Import Template Download'.
ENDIF.
sscrfields-functxt_01 = g_function_key.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN OUTPUT *
*----------------------------------------------------------------------*
* 显示注释
AT SELECTION-SCREEN OUTPUT.
IF sy-langu EQ '1'.
MOVE '1、请严格按照模板要求填写数据' TO t2.
ELSE.
MOVE '1. Please fill in the data strictly in accordance with the template requirements' TO t2.
ENDIF.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
* 下载数据导入模板
IF sscrfields-ucomm = 'FC01'.
PERFORM frm_excel_down.
sscrfields-ucomm = ''.
ENDIF.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN ON VALUE-REQUEST *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
* 选择文件搜索帮助
PERFORM frm_set_file_f4 USING p_file.
*----------------------------------------------------------------------*
* START-OF-SELECTION *
*----------------------------------------------------------------------*
START-OF-SELECTION.
" 文件必输校验
PERFORM frm_file_obligatory.
" 批量导入数据
PERFORM frm_upload_data.
" 默认数据生成
PERFORM frm_data_generate.
*----------------------------------------------------------------------*
* END-OF-SELECTION *
*----------------------------------------------------------------------*
END-OF-SELECTION.
* ALV显示
PERFORM frm_display_data.
*&---------------------------------------------------------------------*
*& Form FRM_SET_STATUS
*&---------------------------------------------------------------------*
* 设定状态栏
*----------------------------------------------------------------------*
FORM frm_set_status USING extab TYPE slis_t_extab.
"SET PF-STATUS 'S1000'.
SET PF-STATUS 'ZSTANDARD_FULLSCREEN'.
ENDFORM. " FRM_SET_STATUS
*&---------------------------------------------------------------------*
*& Form FRM_USER_COMMAND
*&---------------------------------------------------------------------*
* 命令按钮
*----------------------------------------------------------------------*
* -->I_UCOMM 命令按钮
* -->I_SELFIELD 选择值
*----------------------------------------------------------------------*
FORM frm_user_command USING i_ucomm LIKE sy-ucomm
i_selfield TYPE slis_selfield.
CASE i_ucomm.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'IMPORT'.
PERFORM frm_data_import. "供应商创建及扩展
WHEN OTHERS.
ENDCASE.
ENDFORM. " FRM_USER_COMMAND
*----------------------------------------------------------------------*
***INCLUDE ZMMRP0004_DISPLAY.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_display_data .
* alv相关变量定义
DATA:lt_fcat TYPE lvc_t_fcat,
ls_layo TYPE lvc_s_layo.
* FIELDCAT字段填充
CLEAR lt_fcat[].
PERFORM frm_fill_fcat TABLES lt_fcat.
* 布局设置
CLEAR ls_layo.
ls_layo-zebra = 'X'. "斑马线
ls_layo-cwidth_opt = 'X'. "最优宽
ls_layo-box_fname = 'SEL'. "选择模式
* ALV显示数据
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
is_layout_lvc = ls_layo
i_callback_pf_status_set = 'FRM_SET_STATUS'
i_callback_user_command = 'FRM_USER_COMMAND'
it_fieldcat_lvc = lt_fcat[]
i_save = 'A'
TABLES
t_outtab = gt_alv[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
* 数据显示失败
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_FILL_FCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LT_FCAT text
*----------------------------------------------------------------------*
FORM frm_fill_fcat TABLES t_fcat TYPE lvc_t_fcat.
"局部变量的定义
DATA ls_fcat TYPE lvc_s_fcat.
DEFINE m_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = &1.
ls_fcat-coltext = &2.
ls_fcat-outputlen = &3.
ls_fcat-no_zero = &4.
IF ls_fcat-fieldname = 'ICON_A'.
ls_fcat-icon = 'X'.
ENDIF.
APPEND ls_fcat TO t_fcat.
END-OF-DEFINITION.
m_fieldcat 'ICON_A ' '供应商信息指示灯 ' '' ''.
m_fieldcat 'REMARK_A ' '供应商信息备注 ' '' ''.
m_fieldcat 'ICON_B ' '银行指信息示灯 ' '' ''.
m_fieldcat 'REMARK_B ' '银行信息备注 ' '' ''.
m_fieldcat 'BU_GROUP ' '业务伙伴分组 ' '' ''.
m_fieldcat 'BU_SORT1 ' '搜索词 ' '' ''.
m_fieldcat 'AKONT ' '统驭科目 ' '' ''.
m_fieldcat 'NAME_ORG1 ' '供应商名称 (英文) ' '' ''.
m_fieldcat 'PARTNER ' '供应商代码 ' '' ''.
m_fieldcat 'PARTN_CAT' '供应商账户组 ' '' ''.
m_fieldcat 'EKORG ' '采购组织 ' '' ''.
m_fieldcat 'BUKRS ' '公司代码 ' '' ''.
m_fieldcat 'STREET ' '街道 ' '' ''.
m_fieldcat 'CITY1 ' '城市 ' '' ''.
m_fieldcat 'LAND1 ' '国家 ' '' ''.
m_fieldcat 'POST_CODE1' '邮政编码 ' '' ''.
m_fieldcat 'LANGU ' '语言 ' '' ''.
m_fieldcat 'TEL_NUMBER' '电话 ' '' ''.
* m_fieldcat 'MOB_NUMBER' '移动电话 ' '' ''.
m_fieldcat 'FAX_NUMBER' '传真 ' '' ''.
m_fieldcat 'VERKF ' '供应商联系人 ' '' ''.
m_fieldcat 'JOB ' '岗位 ' '' ''.
m_fieldcat 'SMTP_ADDR ' 'E-mail ' '' ''.
m_fieldcat 'IBAN ' 'IBAN ' '' ''.
m_fieldcat 'BANK_LAND ' '银行国家 ' '' ''.
m_fieldcat 'BANKL ' '银行代码 ' '' ''.
m_fieldcat 'SWIFT ' 'SWIFT CODE/BIC ' '' ''.
m_fieldcat 'BANK_NO ' '银行账号 ' '' ''.
m_fieldcat 'KOINH ' '银行账户名称 ' '' ''.
m_fieldcat 'BANK_NAME ' '银行名称 ' '' ''.
m_fieldcat 'PROVZ1 ' '银行城市 ' '' ''.
m_fieldcat 'BRNCH ' '分行 ' '' ''.
m_fieldcat 'WAERS ' '币种 ' '' ''.
m_fieldcat 'ZTERM2 ' '默认付款条件 ' '' ''.
m_fieldcat 'PROVZ ' '银行省份 ' '' ''.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DATA_IMPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_data_import .
DATA:zcheck TYPE char1.
CLEAR zcheck.
PERFORM frm_check_data CHANGING zcheck.
CHECK zcheck <> 'X'.
DATA: lv_partner TYPE but000-partner,
l_grid TYPE REF TO cl_gui_alv_grid.
LOOP AT gt_alv INTO gs_alv WHERE sel = 'X'.
CLEAR lv_partner.
SELECT SINGLE partner FROM but000 INTO lv_partner WHERE name_org1 = gs_alv-name_org1.
IF sy-subrc = 0.
CONCATENATE '该业务伙伴已存在,编号为' lv_partner INTO gs_alv-remark_a.
gs_alv-icon_a = icon_red_light.
MODIFY gt_alv FROM gs_alv.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' "获取alv
IMPORTING
e_grid = l_grid.
CALL METHOD l_grid->check_changed_data. "获取alv改变值
CALL METHOD l_grid->refresh_table_display. "刷新ALV界面
CONTINUE.
ELSE. " 如果供应商不存在,则创建供应商
PERFORM frm_bp01. "普通供应商
ENDIF.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_BP01
*&---------------------------------------------------------------------*
* 创建 BP 主数据
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_bp01 .
**----------------------------------------------------------------------*
" *->先传入供应商数据
CLEAR:ls_central.
ls_central-searchterm1 = gs_alv-bu_sort1. " 搜索词 SEARCHTERM1
CLEAR:ls_central_organ.
ls_central_organ-name1 = gs_alv-name_org1. "供应商名称
CLEAR ls_address.
ls_address-street = gs_alv-street. "街道
ls_address-postl_cod1 = gs_alv-post_code1."邮编
ls_address-city = gs_alv-city1. "城市
ls_address-country = gs_alv-land1. "国家
DATA: lv_langu TYPE t002t-sptxt.
SELECT SINGLE sprsl FROM t002t INTO gs_alv-langu WHERE sptxt = gs_alv-langu..
CALL FUNCTION 'CONVERSION_EXIT_ISOLA_INPUT'
EXPORTING
input = gs_alv-langu
IMPORTING
output = ls_address-langu "语言
EXCEPTIONS
unknown_language = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
CLEAR:l_bpartner,l_partn_cat,l_partn_grp.
l_bpartner = gs_alv-partner. "业务伙伴号--普通供应商
l_partn_cat = '2'. "业务伙伴类型
l_partn_grp = gs_alv-bu_group. "业务伙伴分组
CLEAR:lt_bapiadtel,lt_bapiadtel[].
CLEAR:lt_bapiadfax,lt_bapiadfax[].
CLEAR:lt_bapiadsmtp,lt_bapiadsmtp[].
lt_bapiadtel-country = ls_address-country.
lt_bapiadtel-std_no = 'X'.
lt_bapiadtel-telephone = gs_alv-tel_number. "电话
APPEND lt_bapiadtel.
CLEAR:lt_bapiadfax.
lt_bapiadfax-country = ls_address-country.
lt_bapiadfax-std_no = 'X'.
lt_bapiadfax-fax = gs_alv-fax_number. "传真
APPEND lt_bapiadfax.
CLEAR lt_bapiadsmtp.
lt_bapiadsmtp-std_no = 'X'.
lt_bapiadsmtp-e_mail = gs_alv-smtp_addr. "E-mail
APPEND lt_bapiadsmtp.
" *-> 创建BAPI
CLEAR: lt_return1, lt_return1[].
CALL FUNCTION 'BAPI_BUPA_CREATE_FROM_DATA'
EXPORTING
businesspartnerextern = l_bpartner
partnercategory = l_partn_cat
partnergroup = l_partn_grp
centraldata = ls_central
centraldataperson = ls_central_person
centraldataorganization = ls_central_organ
* CENTRALDATAGROUP =
addressdata = ls_address
* DUPLICATE_MESSAGE_TYPE =
* ACCEPT_ERROR = ' '
IMPORTING
businesspartner = l_bpartner
TABLES
telefondata = lt_bapiadtel
faxdata = lt_bapiadfax
* TELETEXDATA =
* TELEXDATA =
e_maildata = lt_bapiadsmtp
* RMLADDRESSDATA =
* X400ADDRESSDATA =
* RFCADDRESSDATA =
* PRTADDRESSDATA =
* SSFADDRESSDATA =
* URIADDRESSDATA =
* PAGADDRESSDATA =
* ADDRESSNOTES =
* COMMUNICATIONNOTES =
* COMMUNICATIONUSAGE =
* TELEFONDATANONADDRESS =
* FAXDATANONADDRESS =
* TELETEXDATANONADDRESS =
* TELEXDATANONADDRESS =
* E_MAILDATANONADDRESS =
* RMLADDRESSDATANONADDRESS =
* X400ADDRESSDATANONADDRESS =
* RFCADDRESSDATANONADDRESS =
* PRTADDRESSDATANONADDRESS =
* SSFADDRESSDATANONADDRESS =
* URIADDRESSDATANONADDRESS =
* PAGADDRESSDATANONADDRESS =
* COMMUNICATIONNOTESNONADDRESS =
* COMMUNICATIONUSAGENONADDRESS =
return = lt_return1
* ADDRESSDUPLICATES =
.
CLEAR l_msg1.
LOOP AT lt_return1 WHERE type = 'E' OR type = 'A'. " OR TYPE = 'W'.
CONCATENATE lt_return1-message l_msg1 INTO l_msg1 SEPARATED BY ';'.
CONDENSE l_msg1.
ENDLOOP.
" 只有供应商创建成功了,才能扩展其他数据
IF l_msg1 = ''.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' "commit--信息提交
EXPORTING
wait = 'X'. "地址信息提交
CLEAR l_msg1_1.
CONCATENATE '业务伙伴地址信息创建成功,编号为' l_bpartner INTO l_msg1_1.
CONDENSE l_msg1_1.
CLEAR:lt_bapiadtel[], lt_bapiadtel, lt_bapiadtel, lt_bapiadtel[], lt_bapiadfax, lt_bapiadfax[], lt_bapiadsmtp, lt_bapiadsmtp[].
" *-> 银行明细追加
DATA lv_bankl TYPE bnka-bankl.
CLEAR lv_bankl.
SELECT SINGLE bnkey FROM t005 INTO gs_alv-bnkey WHERE land1 = gs_alv-land1.
* SELECT SINGLE bankl FROM bnka INTO lv_bankl WHERE bankl = gs_alv-bankl.
IF gs_alv-bank_no NE '' AND gs_alv-bnkey EQ '3'. " 自动创建银行代码
* IF gs_alv-bank_no NE ''. " 自动创建银行代码
"创建银行代码
DATA: lv_bank_ctry LIKE bapi1011_key-bank_ctry,
lt_bank_address LIKE bapi1011_address OCCURS 0 WITH HEADER LINE,
lt_return_bk LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
l_msg_bk(255) TYPE c,
bankkey LIKE ls_bapibus1006_bankdetail-bank_key.
lv_bank_ctry = gs_alv-land1. " 银行国家
lt_bank_address-bank_name = gs_alv-bank_name. " 银行名称
APPEND lt_bank_address.
CLEAR: lt_return_bk,lt_return_bk[],bankkey.
CALL FUNCTION 'BAPI_BANK_CREATE'
EXPORTING
bank_ctry = lv_bank_ctry
* bank_key = 'INTERN1' " 内部给号银行无需传入银行代码
* bank_internal_bank = '1'
bank_address = lt_bank_address
* BANK_METHOD =
* BANK_FORMATTING =
* BANK_ADDRESS1 =
* I_XUPDATE = 'X'
* I_CHECK_BEFORE_SAVE =
* BANK_IBAN_RULE =
* BANK_B2B_SUPPORTED =
* BANK_COR1_SUPPORTED =
* BANK_R_TRANSACTION_SUPPORTED =
IMPORTING
return = lt_return_bk
* BANKCOUNTRY =
bankkey = bankkey.
CLEAR l_msg_bk. "20160721新增
LOOP AT lt_return_bk WHERE type = 'E' OR type = 'A'. " OR TYPE = 'W'.
CONCATENATE lt_return_bk-message l_msg_bk INTO l_msg_bk SEPARATED BY ';'.
CONDENSE l_msg_bk.
ENDLOOP.
IF l_msg_bk = '' OR l_msg_bk IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' "commit--信息提交
EXPORTING
wait = 'X'. "银行创建提交
ls_bapibus1006_bankdetail-bank_key = bankkey.
* ls_bapibus1006_bankdetail-bank_key = '2780040001'. " 测试
ENDIF.
* ENDIF.
ls_bapibus1006_bankdetail-bank_ctry = gs_alv-land1. "银行国家
ls_bapibus1006_bankdetail-accountholder = gs_alv-koinh. "账户持有人
ls_bapibus1006_bankdetail-bank_acct = gs_alv-bank_no+0(11). "银行账户
ls_bapibus1006_bankdetail-bankaccountname = gs_alv-bank_name. "账户名称
ls_bapibus1006_bankdetail-iban = gs_alv-iban. " IBAN(国际银行帐号)
CLEAR: lt_return2, lt_return2[].
CALL FUNCTION 'BAPI_BUPA_BANKDETAIL_ADD'
EXPORTING
businesspartner = l_bpartner
* BANKDETAILID =
bankdetaildata = ls_bapibus1006_bankdetail
* IMPORTING
* BANKDETAILIDOUT =
TABLES
return = lt_return2.
CLEAR l_msg2. "20160721新增
LOOP AT lt_return2 WHERE type = 'E' OR type = 'A'. " OR TYPE = 'W'.
CONCATENATE lt_return2-message l_msg2 INTO l_msg2 SEPARATED BY ';'. "银行信息创建不成功
CONDENSE l_msg2.
ENDLOOP.
IF l_msg2 = ''. "20160721新增
*** IF LT_RETURN2[] IS INITIAL. "20160721注销
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'. "银行信息提交(即银行信息创建成功)
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
ENDIF.
ELSE.
CLEAR l_msg2.
l_msg2 = '银行代码为外部给号,银行信息需要用户手动创建'.
ENDIF.
***********************************************************************************************************************
*---------------------------供应商扩展开始---------------------------------*
* 财务数据部分
CLEAR: lt_return4,lt_return4[].
CALL FUNCTION 'BAPI_BUPA_ROLE_ADD_2'
EXPORTING
businesspartner = l_bpartner
businesspartnerrolecategory = 'FLVN00'
* ALL_BUSINESSPARTNERROLES = ' '
businesspartnerrole = 'FLVN00'
* DIFFERENTIATIONTYPEVALUE =
* VALIDFROMDATE =
* VALIDUNTILDATE = '99991231'
TABLES
return = lt_return4.
CLEAR l_msg4. "20160721新增
LOOP AT lt_return4 WHERE type = 'E' OR type = 'A'. " OR TYPE = 'W'.
CONCATENATE lt_return4-message l_msg4 INTO l_msg4 SEPARATED BY ';'.
CONDENSE l_msg4.
ENDLOOP.
IF l_msg4 = ''.
*** IF LT_RETURN4[] IS INITIAL. "20160721注销
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' "角色信息提交(即角色创建成功)
EXPORTING
wait = 'X'.
"PERFORM FRM_GET_VEN_FROM_PATCD USING L_BPARTNER CHANGING L_VENDOR. "根据业务伙伴号抓取供应商号
l_vendor = l_bpartner.
CLEAR: ls_master_data,ls_company,lt_master_data.
ls_master_data-header-object_task = 'M'.
ls_master_data-header-object_instance-lifnr = l_vendor.
DATA:lv_ktokk1 TYPE tbc001-ktokk.
CLEAR lv_ktokk1.
SELECT SINGLE ktokk FROM tbc001 INTO lv_ktokk1 WHERE bu_group = l_partn_grp.
ls_master_data-central_data-central-data-ktokk = lv_ktokk1. "供应商帐户组
ls_master_data-central_data-central-datax-ktokk = 'X'. "供应商帐户组
ls_master_data-central_data-address-postal-data-name = gs_alv-name_org1. "名称1
ls_master_data-central_data-address-postal-data-sort1 = gs_alv-bu_sort1. "属性(SAP为搜索项 1)
ls_master_data-central_data-address-postal-data-street = gs_alv-street. "街道/门牌号
ls_master_data-central_data-address-postal-data-postl_cod1 = gs_alv-post_code1. "邮政编码
ls_master_data-central_data-address-postal-data-city = gs_alv-city1. "城市
ls_master_data-central_data-address-postal-data-country = gs_alv-land1. "国家
CALL FUNCTION 'CONVERSION_EXIT_ISOLA_INPUT'
EXPORTING
input = gs_alv-langu
IMPORTING
output = ls_master_data-central_data-address-postal-data-langu "语言
EXCEPTIONS
unknown_language = 1
OTHERS = 2.
ls_master_data-central_data-address-postal-datax-name = 'X'. "名称1
ls_master_data-central_data-address-postal-datax-sort1 = 'X'. "属性(SAP为搜索项 1)
ls_master_data-central_data-address-postal-datax-street = 'X'. "街道/门牌号
ls_master_data-central_data-address-postal-datax-postl_cod1 = 'X'. "邮政编码
ls_master_data-central_data-address-postal-datax-city = 'X'. "城市
ls_master_data-central_data-address-postal-datax-country = 'X'. "国家
* ls_master_data-central_data-address-postal-datax-region = 'X'. "地区
ls_master_data-central_data-address-postal-datax-langu = 'X'. "语言
* LS_MASTER_DATA-COMPANY_DATA-COMPANY = ''. "COMPANY关联类型即LS_COMPANY的关联类型
CLEAR gs_bukrs.
LOOP AT gt_bukrs INTO gs_bukrs.
ls_company-task = 'M'.
ls_company-data_key-bukrs = gs_bukrs-bukrs. "公司代码
ls_company-data-akont = gs_alv-akont. "统驭科目
ls_company-datax-akont = 'X'.
ls_company-data-zterm = gs_alv-zterm2. "付款条件
ls_company-datax-zterm = 'X'.
APPEND ls_company TO ls_master_data-company_data-company.
APPEND ls_master_data TO lt_master_data-vendors[].
ENDLOOP.
vmd_ei_api=>initialize( ).
CALL METHOD vmd_ei_api=>maintain_bapi "VMD_EI_API=>MAINTAIN_DIRECT_INPUT
EXPORTING
is_master_data = lt_master_data
IMPORTING
es_master_data_correct = l1
es_message_correct = l2
es_master_data_defective = l3
es_message_defective = l4.
IF l4-is_error = ''.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
DATA ls_l4 LIKE LINE OF l4-messages.
LOOP AT l4-messages INTO ls_l4 WHERE type = 'E' OR type = 'A'.
CONCATENATE l_msgl4 ls_l4-message INTO l_msgl4 SEPARATED BY ';'.
CONDENSE l_msgl4.
ENDLOOP.
ENDIF.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
IF gs_alv-bu_group <> 'BP03'.
* 采购数据部分
CLEAR: lt_return5,lt_return5[].
CALL FUNCTION 'BAPI_BUPA_ROLE_ADD_2'
EXPORTING
businesspartner = l_bpartner
businesspartnerrolecategory = 'FLVN01'
* ALL_BUSINESSPARTNERROLES = ' '
businesspartnerrole = 'FLVN01'
* DIFFERENTIATIONTYPEVALUE =
* VALIDFROMDATE =
* VALIDUNTILDATE = '99991231'
TABLES
return = lt_return5.
CLEAR l_msg5. "20160721新增
LOOP AT lt_return5 WHERE type = 'E' OR type = 'A'. " OR TYPE = 'W'.
CONCATENATE lt_return5-message l_msg5 INTO l_msg4 SEPARATED BY ';'.
CONDENSE l_msg5.
ENDLOOP.
IF l_msg5 = ''.
*** IF LT_RETURN5[] IS INITIAL. "20160721注销
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' "角色信息提交(即角色创建成功)
EXPORTING
wait = 'X'.
"PERFORM FRM_GET_VEN_FROM_PATCD USING L_BPARTNER CHANGING L_VENDOR. "根据业务伙伴号抓取供应商号
l_vendor = l_bpartner.
FREE: ls_master_data,ls_purchasing,lt_master_data.
ls_master_data-header-object_task = 'M'.
ls_master_data-header-object_instance-lifnr = l_vendor.
DATA:lv_ktokk2 TYPE tbc001-ktokk.
CLEAR lv_ktokk2.
SELECT SINGLE ktokk FROM tbc001 INTO lv_ktokk2 WHERE bu_group = l_partn_grp.
ls_master_data-central_data-central-data-ktokk = lv_ktokk2. "供应商帐户组
ls_master_data-central_data-central-datax-ktokk = 'X'. "供应商帐户组
* LS_MASTER_DATA-PURCHASING_DATA-PURCHASING = ''. "PURCHASING关联类型即LS_PURCHASING的关联类型
LOOP AT gt_ekorg INTO gs_ekorg. " 采购组织扩展
CLEAR: ls_purchasing,ls_master_data-purchasing_data-purchasing.
"LS_PURCHASING-TASK = 'M'.
ls_purchasing-task = 'I'.
ls_purchasing-data_key-ekorg = gs_ekorg-ekorg. "采购组织
ls_purchasing-data-waers = gs_alv-waers. "币种
ls_purchasing-datax-waers = 'X'.
ls_purchasing-data-zterm = gs_alv-zterm2. "付款条件
ls_purchasing-datax-zterm = 'X'.
ls_purchasing-data-verkf = gs_alv-verkf. "供应商联系人
ls_purchasing-datax-verkf = 'X'.
ls_purchasing-data-webre = 'X'. "基于收货的发票校验
ls_purchasing-datax-webre = 'X'.
ls_purchasing-data-lebre = 'X'. " 2021.12.13 基于服务的开盘校验
ls_purchasing-datax-lebre = 'X'.
ls_functions-task = 'M'.
ls_functions-data_key-parvw = 'BA'.
APPEND ls_functions TO ls_purchasing-functions-functions.
ls_functions-data_key-parvw = 'LF'.
APPEND ls_functions TO ls_purchasing-functions-functions.
ls_functions-data_key-parvw = 'RS'.
APPEND ls_functions TO ls_purchasing-functions-functions.
APPEND ls_purchasing TO ls_master_data-purchasing_data-purchasing.
APPEND ls_master_data TO lt_master_data-vendors[].
ENDLOOP.
vmd_ei_api=>initialize( ).
CALL METHOD vmd_ei_api=>maintain_bapi "VMD_EI_API=>MAINTAIN_DIRECT_INPUT
EXPORTING
iv_collect_messages = 'X'
is_master_data = lt_master_data
IMPORTING
es_master_data_correct = l1
es_message_correct = l2
es_master_data_defective = l3
es_message_defective = l5.
IF l5-is_error = ''.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
DATA ls_l5 LIKE LINE OF l5-messages.
LOOP AT l5-messages INTO ls_l5 WHERE type = 'E' OR type = 'A'.
CONCATENATE l_msgl5 ls_l5-message INTO l_msgl5 SEPARATED BY ';'.
CONDENSE l_msgl5.
ENDLOOP.
ENDIF.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
ENDIF.
ENDIF.
*---------------------------供应商扩展结束---------------------------------*
IF l_msg1 = '' AND l_msg4 = '' AND l_msg5 = '' AND l4-messages[] IS INITIAL AND l5-messages[] IS INITIAL.
CONCATENATE '业务伙伴创建成功,编号为' l_bpartner INTO gs_alv-remark_a.
CONDENSE gs_alv-remark_a.
gs_alv-icon_a = icon_green_light.
gs_alv-partner = l_bpartner.
MODIFY gt_alv FROM gs_alv TRANSPORTING icon_a remark_a
WHERE name_org1 = gs_alv-name_org1 AND bu_sort1 = gs_alv-bu_sort1 AND bukrs = gs_alv-bukrs AND ekorg = gs_alv-ekorg.
ELSE.
CONCATENATE l_msg1_1 l_msgl4 l_msgl5 l_msg4 INTO gs_alv-remark_a.
CONDENSE gs_alv-remark_a.
gs_alv-icon_a = icon_red_light.
MODIFY gt_alv FROM gs_alv TRANSPORTING icon_a remark_a
WHERE name_org1 = gs_alv-name_org1 AND bu_sort1 = gs_alv-bu_sort1 AND bukrs = gs_alv-bukrs AND ekorg = gs_alv-ekorg.
ENDIF.
IF l_msg2 = '' .
CONCATENATE '银行信息创建成功,银行账户' gs_alv-bank_no INTO gs_alv-remark_b.
CONDENSE gs_alv-remark_b.
gs_alv-icon_b = icon_green_light.
MODIFY gt_alv FROM gs_alv TRANSPORTING icon_b remark_b
WHERE name_org1 = gs_alv-name_org1 AND bu_sort1 = gs_alv-bu_sort1 AND bukrs = gs_alv-bukrs AND ekorg = gs_alv-ekorg.
ELSE.
" 银行错误信息分开
gs_alv-remark_b = l_msg2.
gs_alv-icon_b = icon_red_light.
MODIFY gt_alv FROM gs_alv TRANSPORTING icon_b remark_b
WHERE name_org1 = gs_alv-name_org1 AND bu_sort1 = gs_alv-bu_sort1 AND bukrs = gs_alv-bukrs AND ekorg = gs_alv-ekorg.
ENDIF.
ELSE.
*- 消息
gs_alv-remark_a = l_msg1.
gs_alv-icon_a = icon_red_light.
MODIFY gt_alv FROM gs_alv TRANSPORTING icon_a remark_a
WHERE name_org1 = gs_alv-name_org1 AND bu_sort1 = gs_alv-bu_sort1 AND bukrs = gs_alv-bukrs AND ekorg = gs_alv-ekorg.
ENDIF.
* 获取alv
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_grid.
* 获取alv改变值
CALL METHOD l_grid->check_changed_data.
* 刷新ALV界面
CALL METHOD l_grid->refresh_table_display.
ENDFORM.
*----------------------------------------------------------------------*
***INCLUDE ZMMRP0005_EXCEL.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_EXCEL_DOWN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_excel_down .
* 相关变量定义
DATA:lo_objdata LIKE wwwdatatab,
lo_mime LIKE w3mime,
lc_filename TYPE string VALUE '供应商批导模版.xlsx',
lc_fullpath TYPE string VALUE 'D:\',
lc_path TYPE string VALUE 'D:\',
ls_destination LIKE rlgrap-filename,
ls_objnam TYPE string,
l_rc LIKE sy-subrc,
ls_errtxt TYPE string,
l_objid TYPE wwwdatatab-objid,
l_dest LIKE sapb-sappfad.
* 模版上传的对象名
l_objid = 'ZMMRP0005'.
* 模板下载路径名
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = '模板下载'
default_extension = 'XLSX'
default_file_name = lc_filename
CHANGING
filename = lc_filename
path = lc_path
fullpath = lc_fullpath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
invalid_default_file_name = 4
OTHERS = 5.
* 没有选择路径
IF lc_fullpath = ''.
IF sy-langu = '1'.
MESSAGE '请选择正确的路径!' TYPE 'E'.
RETURN.
ELSE.
MESSAGE 'Please select the correct path!' TYPE 'E'.
RETURN.
ENDIF.
ELSE.
*- 路径名
l_dest = lc_fullpath.
SELECT SINGLE
relid "IMPORT/EXPORT 记录中的区域
objid "SAP WWW 网关对象名
FROM wwwdata
INTO CORRESPONDING FIELDS OF lo_objdata
WHERE srtf2 = 0
AND relid = 'MI'
AND objid = l_objid.
IF sy-subrc <> 0 OR lo_objdata-objid IS INITIAL.
IF sy-langu = '1'.
MESSAGE '没有获得模板数据' TYPE 'E'.
ELSE.
MESSAGE 'Cannot open exel' TYPE 'E'.
ENDIF.
ENDIF.
ls_destination = l_dest.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
key = lo_objdata
destination = ls_destination
IMPORTING
rc = l_rc.
IF l_rc <> 0.
IF sy-langu = '1'.
MESSAGE '模板下载失败' TYPE 'E'.
ELSE.
MESSAGE 'Template download failed' TYPE 'E'.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SET_FILE_F4
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_FILE text
*----------------------------------------------------------------------*
FORM frm_set_file_f4 USING i_file TYPE rlgrap-filename.
* 局部变量-文件名定义
DATA l_filename TYPE rlgrap-filename.
CLEAR l_filename.
* 选择文件搜索帮助
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_path = i_file
mask = ',*.xlsx,*.XLSX,*.xls,*.XLS.'
mode = '0'
title = TEXT-002
IMPORTING
filename = l_filename
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
* 如果选择了文件
IF sy-subrc = 0 AND l_filename IS NOT INITIAL.
p_file = l_filename.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_FILE_OBLIGATORY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_file_obligatory .
* 文件必输校验
IF p_file IS INITIAL.
IF sy-langu EQ '1'.
MESSAGE '请选择导入的文件' TYPE 'S' DISPLAY LIKE 'E'.
ELSE.
MESSAGE 'Please select the file to be imported' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_UPLOAD_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_upload_data .
" 局部变量的定义
" 参照类型有标准的调整为ZALSMEX_TABLINE_LINE。
DATA: lt_excel TYPE TABLE OF alsmex_tabline WITH HEADER LINE.
DATA: ls_excel TYPE alsmex_tabline.
CLEAR gt_alv.
" 选择文件后做后续处理
CHECK p_file IS NOT INITIAL.
" 把文件的数据变成内表
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = 1
i_begin_row = 2
i_end_col = 24
i_end_row = 65536
* sheet_name = 'BP客户供应商数据初始化' " 基本视图
TABLES
intern = lt_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
" 处理内表数据
CLEAR ls_excel.
LOOP AT lt_excel INTO ls_excel.
CASE ls_excel-col. " 获取每一列的值
WHEN 1.
gs_alv-bu_group = ls_excel-value. " 分组
WHEN 2.
gs_alv-bu_sort1 = ls_excel-value. " 搜索词
* WHEN 2.
* gs_alv-akont = ls_excel-value. " 统驭科目
WHEN 3.
gs_alv-iban = ls_excel-value. " IBAN
WHEN 4.
gs_alv-name_org1 = ls_excel-value. " 供应商名称(英文)
WHEN 5.
gs_alv-street = ls_excel-value. " 街道
WHEN 6.
gs_alv-city1 = ls_excel-value. " 城市
WHEN 7.
gs_alv-land1 = ls_excel-value. " 国家
WHEN 8.
gs_alv-post_code1 = ls_excel-value. " 邮政编码
WHEN 9.
gs_alv-langu = ls_excel-value. " 语言
WHEN 10.
gs_alv-tel_number = ls_excel-value. " 电话
WHEN 11.
gs_alv-fax_number = ls_excel-value. " 传真
WHEN 12.
gs_alv-verkf = ls_excel-value. " 联系人
WHEN 13.
gs_alv-job = ls_excel-value. " 岗位, 可以留空
WHEN 14.
gs_alv-smtp_addr = ls_excel-value. " Email
WHEN 15.
gs_alv-swift = ls_excel-value. " SWIFT CODE/BIC
WHEN 16.
gs_alv-bank_no = ls_excel-value. " 银行账户号码
WHEN 17.
gs_alv-koinh = ls_excel-value. " 银行账户名称
WHEN 18.
gs_alv-bank_name = ls_excel-value. " 银行名称
WHEN 19.
gs_alv-provz = ls_excel-value. " 银行省份
WHEN 20.
gs_alv-provz1 = ls_excel-value. " 银行城市
WHEN 21.
gs_alv-brnch = ls_excel-value. " 分行
WHEN 22.
gs_alv-waers = ls_excel-value. " 订单货币
WHEN 23.
gs_alv-zterm2 = ls_excel-value. " 付款条款
WHEN OTHERS.
ENDCASE.
" gs_alv-bu_group = 'V002'. " 注释,之前说默认V002,现在自己填
gs_alv-bank_land = gs_alv-land1. " 银行国家等于国家
gs_alv-akont = '2202020100'. " 统驭科目默认2202020100
AT END OF row.
APPEND gs_alv TO gt_alv.
CLEAR gs_alv.
ENDAT.
ENDLOOP.
CLEAR lt_excel.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CHECK_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_check_data CHANGING zcheck.
CLEAR zcheck.
LOOP AT gt_alv.
IF gt_alv-bank_no IS NOT INITIAL. " 如果银行账户号码不为空
" 要求账户持有人、银行名称、银行省份,银行城市不能为空,并自动生成银行账户号码
IF gt_alv-koinh IS INITIAL OR gt_alv-bank_name IS INITIAL.
* OR gt_alv-provz IS INITIAL OR gt_alv-provz1 IS INITIAL.
gt_alv-icon_b = icon_red_light.
gt_alv-remark_b = '银行数据不完整,请检查银行信息是否完整!'.
MODIFY gt_alv.
zcheck = 'X'.
ENDIF.
ENDIF.
ENDLOOP.
" 获取ALV
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_grid.
" 获取ALV改变值
CALL METHOD l_grid->check_changed_data.
" 刷新ALV界面
CALL METHOD l_grid->refresh_table_display.
ENDFORM.
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)