找回密码
 立即注册
首页 业界区 业界 ABAP读取BP+客户+供应商数据的代码

ABAP读取BP+客户+供应商数据的代码

金娅鸣 前天 19:32
背景

在MM模块或MDG模块的开发中,经常出现BP客商批量下载或者分发的需求,对于选定的BP,有些ABAPer可能会通过ABAP SQL直接查询相关的表,但是这种方法需要开发者对后台表逻辑非常熟悉,且SQL数量相当大,不符合本人一直的简洁(偷懒)作风,采用几个简单的函数,只需要输入BP和客商编码,就能读取绝大多数的数据,相当哇噻。
相关函数

本文未读取BP联系人数据,大家可以通过where-used-list获取标准代码中对相关函数的具体用法
函数/类说明BUPA_OUTBOUND_GET_MAIN读取BP数据BUPA_OUTBOUND_GET_REL读取BP联系人数据VMD_EI_API_EXTRACT读取供应商数据CMD_EI_API_EXTRACT读取客户数据代码示例

类型&变量定义

点击查看代码
  1. types:begin of ty_bp_general,
  2.           bu_group   type string,
  3.           partner    type string,
  4.           bpext      type string,
  5.           mc_name1   type string,
  6.           name_org1  type string,
  7.           name_last  type string,
  8.           name_first type string,
  9.           taxtype    type string,
  10.           taxnumxl   type string,
  11.           idnumber   type string,
  12.           street     type string,
  13.           post_code1 type string,
  14.           city1      type string,
  15.           country    type string,
  16.           region     type string,
  17.           langu      type string,
  18.           tel_number type string,
  19.           mob_number type string,
  20.           fax_number type string,
  21.           smtp_addr  type string,
  22.           augrp      type string,
  23.           legal_org  type string,
  24.           found_dat  type string,
  25.           ind_sector type string,
  26.           name_co    type string,
  27.           city2      type string,
  28.           home_city  type string,
  29.         end of ty_bp_general,
  30.         begin of ty_bp_identification,
  31.           partner  type string,
  32.           type     type but0id-type,
  33.           idnumber type but0id-idnumber,
  34.         end of ty_bp_identification,
  35.         begin of ty_bp_role,
  36.           partner type string,
  37.           rltyp   type bu_partnerrole,
  38.         end of ty_bp_role,
  39.         begin of ty_bp_bank,
  40.           partner type string,
  41.           banks   type string,
  42.           bankl   type string,
  43.           banka          type string,
  44.           bankn          type string,
  45.           bkref          type string,
  46.           koinh          type string,
  47.           bkont   type string,
  48.         end of ty_bp_bank,
  49.         begin of ty_vendor_company,
  50.           lifnr type string,
  51.           bukrs type string,
  52.           akont type string,
  53.           zuawa type string,
  54.           qsrec type string,
  55.           frgrp type string,
  56.         end of ty_vendor_company,
  57.         begin of ty_vendor_porg,
  58.           lifnr type string,
  59.           ekorg type string,
  60.           verkf type string,
  61.           telf1 type string,
  62.           waers type string,
  63.           zterm type string,
  64.           kalsk type string,
  65.           kzaut type string,
  66.           webre type string,
  67.         end of ty_vendor_porg,
  68.         begin of ty_customer_company,
  69.           kunnr type string,
  70.           bukrs type string,
  71.           akont type string,
  72.           zuawa type string,
  73.           zterm type string,
  74.           zwels type string,
  75.           zgrup type string,
  76.         end of ty_customer_company,
  77.         begin of ty_customer_sorg,
  78.           kunnr          type string,
  79.           vkorg   type string,
  80.           vtweg          type string,
  81.           spart          type string,
  82.           vkbur          type string,
  83.           vkgrp          type string,
  84.           bzirk          type string,
  85.           kdgrp          type string,
  86.           waers          type string,
  87.           kalks          type string,
  88.           vsbed          type string,
  89.           vwerk  type string,
  90.           podkz          type string,
  91.           ktgrd          type string,
  92.           taxkd          type string,
  93.           inco1          type string,
  94.           inco2_l type string,
  95.           inco3_l        type string,
  96.           zterm          type string,
  97.           kkber          type string,
  98.           kvgr1          type string,
  99.           kvgr2   type string,
  100.         end of ty_customer_sorg.
  101.   data:mt_bp_general       type table of ty_bp_general,
  102.        mt_bp_id            type table of ty_bp_identification,
  103.        mt_bp_role          type table of ty_bp_role,
  104.        mt_bp_bank          type table of ty_bp_bank,
  105.        mt_vendor_company   type table of ty_vendor_company,
  106.        mt_vendor_porg      type table of ty_vendor_porg,
  107.        mt_customer_company type table of ty_customer_company,
  108.        mt_customer_sorg    type table of ty_customer_sorg.
复制代码
读取BP

点击查看代码
  1. "读取BP信息
  2.     data:lt_partner_data type bus_ei_extern_t,
  3.          ls_fragment     type bus_ei_fragment,
  4.          lt_fragment     type bus_ei_fragment_t,
  5.          lt_idlist       type bus_ei_instance_t.
  6.     lt_idlist = value #(
  7.       for ls_bp in lt_business_partners
  8.       (
  9.         bpartner = ls_bp
  10.       )
  11.     ).
  12.     lt_fragment = value #(
  13.     ( 'BUP010')"中心数据
  14.     ( 'BUP020')"银行细目
  15.     ( 'BUP050')"标识号
  16.     ( 'BUP060')"行业
  17.     ( 'BUP080')"业务伙伴角色
  18.     ( 'BUP190')"税号
  19.     ( 'BUP210')"业务合作伙伴地址
  20.     ).
  21.     call function 'BUPA_OUTBOUND_GET_MAIN'
  22.       importing
  23.         et_bupa_extern = lt_partner_data
  24.       tables
  25.         it_idlist      = lt_idlist
  26.         it_fragments   = lt_fragment
  27.       exceptions
  28.         bp_not_found   = 1
  29.         others         = 2.
  30.     if sy-subrc <> 0.
  31. * Implement suitable error handling here
  32.     endif.
  33.     loop at lt_partner_data into data(ls_partner_data).
  34.       append initial line to mt_bp_general assigning field-symbol(<bp_general>).
  35.       <bp_general>-partner = ls_partner_data-header-object_instance-bpartner.
  36.       <bp_general>-bu_group = ls_partner_data-central_data-common-data-bp_control-grouping.
  37.       <bp_general>-bpext = ls_partner_data-central_data-common-data-bp_centraldata-partnerexternal.
  38.       data(bp_cate) = ls_partner_data-central_data-common-data-bp_control-category.
  39.       if bp_cate eq '1'.
  40.         <bp_general>-name_first = ls_partner_data-central_data-common-data-bp_person-firstname.
  41.         <bp_general>-name_last = ls_partner_data-central_data-common-data-bp_person-lastname.
  42.       elseif bp_cate eq '2'.
  43.         <bp_general>-name_org1 =  ls_partner_data-central_data-common-data-bp_organization-name1 && ls_partner_data-central_data-common-data-bp_organization-name2.
  44.       endif.
  45.       <bp_general>-augrp = ls_partner_data-central_data-common-data-bp_centraldata-authorizationgroup.
  46.       <bp_general>-legal_org = ls_partner_data-central_data-common-data-bp_organization-legalorg.
  47.       <bp_general>-ind_sector = ls_partner_data-central_data-common-data-bp_organization-industrysector.
  48.       <bp_general>-found_dat = ls_partner_data-central_data-common-data-bp_organization-foundationdate.
  49.       read table ls_partner_data-central_data-taxnumber-taxnumbers into data(bp_tax) index 1.
  50.       if sy-subrc eq 0.
  51.         <bp_general>-taxtype = bp_tax-data_key-taxtype.
  52.         <bp_general>-taxnumxl = cond #(
  53.         when bp_tax-data_key-taxnumber is not initial then bp_tax-data_key-taxnumber
  54.         else bp_tax-data_key-taxnumxl ).
  55.       endif.
  56.       loop at ls_partner_data-central_data-ident_number-ident_numbers into data(ls_bp_ident).
  57.         if ls_bp_ident-data_key-identificationcategory = 'FS0001'.
  58.           <bp_general>-idnumber = ls_bp_ident-data_key-identificationnumber.
  59.         else.
  60.           append initial line to mt_bp_id assigning field-symbol(<bp_ident>).
  61.           <bp_ident>-partner = <bp_general>-partner.
  62.           <bp_ident>-type  = ls_bp_ident-data_key-identificationcategory.
  63.           <bp_ident>-idnumber = ls_bp_ident-data_key-identificationnumber.
  64.         endif.
  65.       endloop.
  66.       loop at ls_partner_data-central_data-address-addresses into data(ls_bp_addr).
  67.         if line_exists( ls_bp_addr-data-addr_usage-addr_usages[ data_key-addresstype = 'XXDEFAULT' ] ).
  68.           <bp_general>-street = ls_bp_addr-data-postal-data-street.
  69.           <bp_general>-post_code1 = ls_bp_addr-data-postal-data-postl_cod1.
  70.           <bp_general>-city1 = ls_bp_addr-data-postal-data-city.
  71.           <bp_general>-country = ls_bp_addr-data-postal-data-country.
  72.           <bp_general>-region = ls_bp_addr-data-postal-data-region.
  73.           <bp_general>-langu = ls_bp_addr-data-postal-data-langu.
  74.           <bp_general>-name_co  = ls_bp_addr-data-postal-data-c_o_name.
  75.           <bp_general>-city2  = ls_bp_addr-data-postal-data-district.
  76.           <bp_general>-home_city  = ls_bp_addr-data-postal-data-home_city.
  77.           read table ls_bp_addr-data-communication-phone-phone into data(ls_telephone) with key contact-data-r_3_user = '1'.
  78.           if sy-subrc eq 0.
  79.             <bp_general>-tel_number = ls_telephone-contact-data-telephone.
  80.           endif.
  81.           read table ls_bp_addr-data-communication-phone-phone into data(ls_cellphone) with key contact-data-r_3_user = '3'.
  82.           if sy-subrc eq 0.
  83.             <bp_general>-mob_number = ls_cellphone-contact-data-telephone.
  84.           endif.
  85.           read table ls_bp_addr-data-communication-fax-fax into data(ls_bp_fax) index 1.
  86.           if sy-subrc eq 0.
  87.             <bp_general>-fax_number = ls_bp_fax-contact-data-fax.
  88.           endif.
  89.           read table ls_bp_addr-data-communication-smtp-smtp into data(ls_bp_smtp) index 1.
  90.           if sy-subrc eq 0.
  91.             <bp_general>-smtp_addr = ls_bp_smtp-contact-data-e_mail.
  92.           endif.
  93.           exit.
  94.         endif.
  95.       endloop.
  96.       loop at ls_partner_data-central_data-role-roles into data(ls_bp_role).
  97.         append initial line to mt_bp_role assigning field-symbol(<bp_role>).
  98.         <bp_role>-partner = <bp_general>-partner.
  99.         <bp_role>-rltyp = ls_bp_role-data_key.
  100.       endloop.
  101.       loop at ls_partner_data-central_data-bankdetail-bankdetails into data(ls_bp_bank).
  102.         append initial line to mt_bp_bank assigning field-symbol(<bp_bank>).
  103.         <bp_bank>-partner = <bp_general>-partner.
  104.         <bp_bank>-banks        = ls_bp_bank-data-bank_ctry.
  105.         <bp_bank>-bankl   = ls_bp_bank-data-bank_key.
  106.         <bp_bank>-bankn   = ls_bp_bank-data-bank_acct.
  107.         <bp_bank>-bkref   = ls_bp_bank-data-bank_ref.
  108.         <bp_bank>-koinh   = ls_bp_bank-data-accountholder.
  109.         <bp_bank>-bkont        = ls_bp_bank-data-ctrl_key.
  110.       endloop.
  111.     endloop.
复制代码
读取客户

点击查看代码
  1. data: ls_customer_in  type cmds_ei_main,
  2.           ls_customer_out type cmds_ei_main.
  3.     ls_customer_in-customers = value #(
  4.     for ls_bp in lt_business_partners
  5.     (
  6.       header-object_task = 'M'
  7.       header-object_instance-kunnr = ls_bp
  8.     )
  9.     ).
  10.     try.
  11.         "Extract Customers w/ performance optimization
  12.         cvi_cl_process_info=>set_process(
  13.           exporting
  14.             iv_process = 'MDG'
  15.             ).
  16.         cmd_ei_api_extract=>get_data(
  17.         exporting
  18.           is_master_data = ls_customer_in
  19.         importing
  20.           es_master_data = ls_customer_out
  21.         exceptions
  22.           others         = 1 ).
  23.         cvi_cl_process_info=>clear_process( ).
  24.       catch cx_sy_dyn_call_illegal_method cx_sy_dyn_call_param_missing
  25.         cx_sy_dyn_call_parameter_conv cx_sy_dyn_call_parameter_error.
  26.         "Extract Customers w/o performance optimization
  27.         cmd_ei_api_extract=>get_data(
  28.         exporting
  29.           is_master_data = ls_customer_in
  30.         importing
  31.           es_master_data = ls_customer_out
  32.         exceptions
  33.           others         = 1 ).
  34.     endtry.
  35.     loop at ls_customer_out-customers into data(ls_customer).
  36.       loop at ls_customer-company_data-company into  data(ls_customer_company).
  37.         append initial line to mt_customer_company assigning field-symbol(<customer_company>).
  38.         <customer_company>-kunnr  = ls_customer-header-object_instance-kunnr.
  39.         <customer_company>-bukrs  = ls_customer_company-data_key-bukrs.
  40.         <customer_company>-akont  = ls_customer_company-data-akont.
  41.         <customer_company>-zuawa  = ls_customer_company-data-zuawa.
  42.         <customer_company>-zterm  = ls_customer_company-data-zterm.
  43.         <customer_company>-zwels  = ls_customer_company-data-zwels.
  44.         <customer_company>-zgrup  = ls_customer_company-data-zgrup.
  45.       endloop.
  46.       loop at ls_customer-sales_data-sales into data(ls_customer_sales).
  47.         append initial line to mt_customer_sorg assigning field-symbol(<customer_sorg>).
  48.         <customer_sorg>-kunnr         = ls_customer-header-object_instance-kunnr.
  49.         <customer_sorg>-vkorg        = ls_customer_sales-data_key-vkorg.
  50.         <customer_sorg>-vtweg   = ls_customer_sales-data_key-vtweg.
  51.         <customer_sorg>-spart   = ls_customer_sales-data_key-spart.
  52.         <customer_sorg>-vkbur   = ls_customer_sales-data-vkbur.
  53.         <customer_sorg>-vkgrp   = ls_customer_sales-data-vkgrp.
  54.         <customer_sorg>-bzirk   = ls_customer_sales-data-bzirk.
  55.         <customer_sorg>-kdgrp   = ls_customer_sales-data-kdgrp.
  56.         <customer_sorg>-waers   = ls_customer_sales-data-waers.
  57.         <customer_sorg>-kalks   = ls_customer_sales-data-kalks.
  58.         <customer_sorg>-vsbed   = ls_customer_sales-data-vsbed.
  59.         <customer_sorg>-vwerk   = ls_customer_sales-data-vwerk.
  60.         <customer_sorg>-podkz   = ls_customer_sales-data-podkz.
  61.         <customer_sorg>-ktgrd   = ls_customer_sales-data-ktgrd.
  62. "        <customer_sorg>-taxkd   = ls_customer_sales-data-taxkd.
  63.         <customer_sorg>-inco1   = ls_customer_sales-data-inco1.
  64.         <customer_sorg>-inco2_l   = ls_customer_sales-data-inco2_l.
  65.         <customer_sorg>-inco3_l   = ls_customer_sales-data-inco3_l.
  66.         <customer_sorg>-zterm   = ls_customer_sales-data-zterm.
  67.         <customer_sorg>-kkber   = ls_customer_sales-data-kkber.
  68.         <customer_sorg>-kvgr1   = ls_customer_sales-data-kvgr1.
  69.         <customer_sorg>-kvgr2   = ls_customer_sales-data-kvgr2.
  70.       endloop.
  71.     endloop.
复制代码
读取供应商

点击查看代码
  1. data:ls_supplier_in  type vmds_ei_main,
  2.          ls_supplier_out type  vmds_ei_main.
  3.     ls_supplier_in-vendors = value #(
  4.     for ls_bp in lt_business_partners
  5.     (
  6.       header-object_task = 'M'
  7.       header-object_instance-lifnr = ls_bp
  8.     )
  9.     ).
  10.     try.
  11.         "Extract Customers w/ performance optimization
  12.         cvi_cl_process_info=>set_process(
  13.         exporting
  14.           iv_process = 'MDG'
  15.           ).
  16.         vmd_ei_api_extract=>get_data(
  17.         exporting
  18.           is_master_data = ls_supplier_in
  19.         importing
  20.           es_master_data = ls_supplier_out
  21.         exceptions
  22.           others         = 1 ).
  23.         cvi_cl_process_info=>clear_process( )..
  24.       catch cx_sy_dyn_call_illegal_method cx_sy_dyn_call_param_missing
  25.         cx_sy_dyn_call_parameter_conv cx_sy_dyn_call_parameter_error.
  26.         "Extract Customers w/o performance optimization
  27.         vmd_ei_api_extract=>get_data(
  28.         exporting
  29.           is_master_data = ls_supplier_in
  30.         importing
  31.           es_master_data = ls_supplier_out
  32.         exceptions
  33.           others         = 1 ).
  34.     endtry.
  35.     loop at ls_supplier_out-vendors into data(ls_vendor).
  36.       loop at ls_vendor-company_data-company into data(ls_vendor_company) .
  37.         append initial line to mt_vendor_company assigning field-symbol(<vendor_company>).
  38.         <vendor_company>-lifnr = ls_vendor-header-object_instance-lifnr.
  39.         <vendor_company>-bukrs = ls_vendor_company-data_key-bukrs.
  40.         <vendor_company>-akont = ls_vendor_company-data-akont.
  41.         <vendor_company>-zuawa = ls_vendor_company-data-zuawa.
  42.         <vendor_company>-qsrec = ls_vendor_company-data-qsrec.
  43.         <vendor_company>-frgrp = ls_vendor_company-data-frgrp.
  44.       endloop.
  45.       loop at ls_vendor-purchasing_data-purchasing into data(ls_vendor_porg).
  46.         append initial line to mt_vendor_porg assigning field-symbol(<vendor_porg>).
  47.         <vendor_porg>-lifnr = ls_vendor-header-object_instance-lifnr.
  48.         <vendor_porg>-ekorg = ls_vendor_porg-data_key-ekorg.
  49.         <vendor_porg>-verkf = ls_vendor_porg-data-verkf.
  50.         <vendor_porg>-telf1 = ls_vendor_porg-data-telf1.
  51.         <vendor_porg>-waers = ls_vendor_porg-data-waers.
  52.         <vendor_porg>-zterm = ls_vendor_porg-data-zterm.
  53.         <vendor_porg>-kalsk = ls_vendor_porg-data-kalsk.
  54.         <vendor_porg>-kzaut = ls_vendor_porg-data-kzaut.
  55.         <vendor_porg>-webre = ls_vendor_porg-data-webre.
  56.       endloop.
  57.     endloop.
复制代码
来源:豆瓜网用户自行投稿发布,如果侵权,请联系站长删除

相关推荐

您需要登录后才可以回帖 登录 | 立即注册