首页 > 其他分享 >S4 供应商主数据扩建公司代码,采购组织数据(CVI_EI_INBOUND_MAIN)

S4 供应商主数据扩建公司代码,采购组织数据(CVI_EI_INBOUND_MAIN)

时间:2024-08-26 10:53:11浏览次数:12  
标签:gt gs INBOUND data S4 file table EI type

参考:https://blog.csdn.net/DeveloperMrMeng/article/details/131331147

以模板数据为基础直接扩充对应的公司代码和采购组织数据:

 

report ZED1_TEST1.
tables:sscrfields.

data:gt_upload type alsmex_tabline occurs 0 with header line.
field-symbols:<fs_upload> like line of gt_upload.

data:begin of gs_table,
       light        type c,
       lifnr        type lifnr,   "供应商帐户号
       bukrs1       type bukrs,   "模板公司代码
       bukrs2       type bukrs,   "扩建公司代码
       ekorg1       type ekorg,   "模板采购组织
       ekorg2       type ekorg,   "扩建采购组织
       partner_guid type  bu_partner_guid,
       message      type string,  "消息
     end of gs_table.
data gt_table like table of gs_table.
field-symbols <table> like gs_table.

*alv
data: gt_fieldcat type slis_t_fieldcat_alv,
      ls_fieldcat like line of gt_fieldcat,   "WA APPEND TO FIELD CATALOG
      g_repid     type sy-repid,
      ls_layout   type slis_layout_alv.

***bapi
data:gs_data   type cvis_ei_extern,
     gt_data   type cvis_ei_extern_t,
     gt_return type   bapiretm.

data:lv_partner_guid type bu_partner_guid.  "供应商唯一id

data: gs_partner      type bus_ei_extern,       "业务合作伙伴的复杂外部接口
      gs_header       type bus_ei_header,       "抬头
      gs_central_data type bus_ei_central_data, "中心数据
      gs_common       type bus_ei_bupa_central. "中心数据->合作伙伴数据

data: gs_vendor          type vmds_ei_extern,  "供应商
      gs_header_vmd      type vmds_ei_header,  "供应商->数据抬头
      gs_company_data    type vmds_ei_vmd_company,     "供应商->公司代码
      gt_company         type vmds_ei_company_t,
      gs_company         type vmds_ei_company,
      gs_purchasing_data type vmds_ei_vmd_purchasing,  "供应商->采购组织
      gt_purchasing      type vmds_ei_purchasing_t,
      gs_purchasing      type vmds_ei_purchasing,
      gs_function_data   type vmds_ei_vmd_functions,  "供应商->采购组织-合作伙伴角色
      gt_functions       type vmds_ei_functions_t,     "合作伙伴角色
      gs_functions       type vmds_ei_functions.

constants:lc_parvw_pi type parvw value 'PI',
          lc_parvw_oa type parvw value 'OA',
          lc_parvw_vn type parvw value 'VN'.

data:gt_lfb1 type table of lfb1,
     gs_lfb1 type lfb1,
     gt_lfm1 type table of lfm1,
     gs_lfm1 type lfm1.


selection-screen function key 1. "应用工具栏增加按钮
selection-screen begin of block blk_001 with frame title text-001 . "选择文件路径
parameters:p_file like rlgrap-filename.
selection-screen end of block blk_001.

at selection-screen on value-request for p_file.
  perform frm_select_file.

initialization.
  sscrfields-functxt_01 = '模板下载'.
  sscrfields-ucomm      = 'FC01'.

at selection-screen.
  case sscrfields-ucomm.
    when 'ONLI'.
      perform frm_check_file_exist.
    when 'FC01'.
      perform frm_generate_template.
    when others.
  endcase.


start-of-selection.
  perform check_filename.
  perform frm_upload_data. " 导入文件数据
  perform frm_handle_data.

end-of-selection .
  perform f_alv_fieldcat.
  perform f_display.



form frm_handle_data.

* Check 供应商 exist
  select partner,partner_guid,bu_group into table @data(lt_guid) from but000 for all entries in @gt_table where partner = @gt_table-lifnr.
  sort lt_guid by partner.

  loop at gt_table assigning <table>.
    read table lt_guid into data(ls_guid) with key partner = <table>-lifnr.
    if sy-subrc = 0.
      <table>-partner_guid = ls_guid-partner_guid.
    else.
      <table>-message = '供应商不存在'.
      <table>-light = '1'.
    endif.
  endloop.

  read table gt_table transporting no fields with key light = '1'.
  if sy-subrc = 0.
    return.
  endif.

*模板 供应商对应的公司代码数据
  select * into table gt_lfb1 from lfb1 for all entries in gt_table where lifnr = gt_table-lifnr and bukrs = gt_table-bukrs1.
  sort gt_lfb1 by lifnr bukrs.
*模板 供应商对应的采购组织数据
  select * into table gt_lfm1 from lfm1 for all entries in gt_table where lifnr = gt_table-lifnr and ekorg = gt_table-ekorg1.
  sort gt_lfm1 by lifnr ekorg.

  loop at gt_table assigning <table>.
    clear:gs_header,gs_partner,gs_vendor,gs_lfb1,gs_company,gt_company,gs_company_data,
          gs_purchasing,gt_functions,gs_function_data,gs_purchasing,gt_purchasing,gs_purchasing_data,
          gs_vendor,gs_data,gt_data,gt_return.

* Basic data part.
    gs_header-object_task = 'U'.
    gs_header-object_instance-bpartner = <table>-lifnr.
    read table lt_guid into ls_guid with key partner = <table>-lifnr .
    gs_header-object_instance-bpartnerguid = ls_guid-partner_guid.
    gs_partner-header = gs_header.

    gs_common-data-bp_control-category = '2'.  "BUT000-TYPE业务伙伴类别:1人员  2组织   3组
    gs_common-data-bp_control-grouping = ls_guid-bu_group.  "BUT000-BU_GROUP业务伙伴分组
    gs_central_data-common = gs_common.
    gs_partner-central_data = gs_central_data.

* Vendor data part
    gs_header_vmd-object_task = 'U'.
    gs_header_vmd-object_instance-lifnr = <table>-lifnr.
    gs_vendor-header = gs_header_vmd.

*******扩充公司代码数据
    if <table>-bukrs1 <> ''.
      read table gt_lfb1 into gs_lfb1 with key lifnr = <table>-lifnr bukrs = <table>-bukrs1 binary search.
      if sy-subrc = 0.
        gs_company-task = 'I'.  "I:新增(扩展) 'U':修改
        gs_company-data_key-bukrs = <table>-bukrs2.              "公司代码

        if gs_lfb1-akont is not initial.
          gs_company-data-akont  = gs_lfb1-akont.               "总帐中的统驭科目
          gs_company-datax-akont = 'X'.
        endif.
        if gs_lfb1-zuawa is not initial.
          gs_company-data-zuawa  = gs_lfb1-zuawa.               "根据分配号排序代码
          gs_company-datax-zuawa = 'X'.
        endif.
        if gs_lfb1-fdgrv is not initial.
          gs_company-data-fdgrv  = gs_lfb1-fdgrv.               "计划组
          gs_company-datax-fdgrv = 'X'.
        endif.
        if gs_lfb1-zterm is not initial.
          gs_company-data-zterm  = gs_lfb1-zterm.               "收付条件代码
          gs_company-datax-zterm =  'X'.
        endif.
        append gs_company to gt_company.

        gs_company_data-company = gt_company. "公司代码数据
      else.
        <table>-light = '1'.
        <table>-message = '供应商对应的模板公司代码数据不存在!'.
        continue.
      endif.
    endif.

*******扩充采购组织数据
    if <table>-ekorg1 <> ''.
      read table gt_lfm1 into gs_lfm1 with key lifnr = <table>-lifnr ekorg = <table>-ekorg1 binary search.
      if sy-subrc = 0.
        gs_purchasing-task = 'I'.
        gs_purchasing-data_key-ekorg = <table>-ekorg2.          "Purchasing organization

        if gs_lfm1-waers is not initial.
          gs_purchasing-data-waers  = gs_lfm1-waers.           "订单货币
          gs_purchasing-datax-waers =  'X'.
        endif.
        if gs_lfm1-zterm is not initial.
          gs_purchasing-data-zterm  = gs_lfm1-zterm.           "收付条件代码
          gs_purchasing-datax-zterm =  'X'.
        endif.
        if gs_lfm1-webre is not initial.      "标识:基于收货的发票验证
          if gs_lfm1-webre = 'N'.
            gs_purchasing-data-webre  = space.
            gs_purchasing-datax-webre =  'X'.
          else.
            gs_purchasing-data-webre  = gs_lfm1-webre.
            gs_purchasing-datax-webre =  'X'.
          endif.
        endif.
        if gs_lfm1-ekgrp is not initial.                  "采购组
          gs_purchasing-data-ekgrp  = gs_lfm1-ekgrp.
          gs_purchasing-datax-ekgrp =  'X'.
        endif.

        gs_functions-task = 'I'.  "合作伙伴角色
        call function 'CONVERSION_EXIT_PARVW_INPUT'
          exporting
            input  = lc_parvw_pi
          importing
            output = gs_functions-data_key-parvw.
        append gs_functions to gt_functions.

        call function 'CONVERSION_EXIT_PARVW_INPUT'
          exporting
            input  = lc_parvw_oa
          importing
            output = gs_functions-data_key-parvw.
        append gs_functions to gt_functions.

        call function 'CONVERSION_EXIT_PARVW_INPUT'
          exporting
            input  = lc_parvw_vn
          importing
            output = gs_functions-data_key-parvw.
        append gs_functions to gt_functions.

        gs_function_data-functions = gt_functions.
        gs_purchasing-functions = gs_function_data.
        append gs_purchasing to gt_purchasing.
        gs_purchasing_data-purchasing = gt_purchasing.  "合作伙伴角色->采购组织

      else.
        <table>-light = '1'.
        <table>-message = '供应商对应的模板采购组织数据不存在!'.
        continue.
      endif.
    endif.

*数据合并
    gs_vendor-company_data = gs_company_data.
    gs_vendor-purchasing_data = gs_purchasing_data.

    gs_data-vendor = gs_vendor.
    gs_data-partner = gs_partner.
    append gs_data to gt_data.

    call function 'CVI_EI_INBOUND_MAIN'
      exporting
        i_data   = gt_data
      importing
        e_return = gt_return.
    loop at gt_return into data(gs_return).
      loop at gs_return-object_msg into data(gs_msg) where type ca 'EAX'.
        concatenate <table>-message gs_msg-message into <table>-message separated by '/'.
      endloop.
    endloop.

    if <table>-message is initial.
      call function 'BAPI_TRANSACTION_COMMIT'
        exporting
          wait = abap_true.
      <table>-light = '3'.
    else.
      call function 'BAPI_TRANSACTION_ROLLBACK' .
      <table>-light = '1'.
    endif.
  endloop.

endform.

form f4_help_for_filename  changing l_file type rlgrap-filename.
  data:
    l_file_import  type string,
    l_path_initial type string,
    lt_filetable   type filetable,
    lw_filetable   like line of lt_filetable,
    l_rc           type i.

  call method cl_gui_frontend_services=>file_open_dialog
    exporting
      file_filter             = 'EXCEL 文件 (*.XLS;*XLSX)|*.XLS;*.XLSX'
    changing
      file_table              = lt_filetable
      rc                      = l_rc
    exceptions
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      others                  = 5.
  if sy-subrc <> 0.
  endif.

  if l_rc > 0.
    read table lt_filetable into lw_filetable index 1.
    if sy-subrc = 0.
      l_file = lw_filetable-filename.
    endif.
  endif.
endform.
form frm_select_file .
  data:lv_window_title type string,
       lv_file_filter  type string value 'Excel Files(*.xls;*.xlsx)|*.xls;*.xlsx|All Files(*.*)|*.*',
       lt_filetable    type filetable with header line,
       lv_rc           type i.
***选择文件
  lv_window_title  = '文件选择'(004).
  call method cl_gui_frontend_services=>file_open_dialog
    exporting
      window_title            = lv_window_title
*     default_extension       =
*     default_filename        =
      file_filter             = lv_file_filter
*     with_encoding           =
      initial_directory       = 'C:\'
*     multiselection          =
    changing
      file_table              = lt_filetable[]
      rc                      = lv_rc
*     user_action             =
*     file_encoding           =
    exceptions
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      others                  = 5.
  if sy-subrc = 0.
    read table lt_filetable index 1.
    if sy-subrc = 0.
      p_file = lt_filetable-filename.
    endif.
  endif.
endform.                    " FRM_SELECT_FILE
form frm_check_file_exist .
  data:lv_file   type string,
       lv_result type abap_bool.

  data:lv_name(255) type c,
       lv_path(255) type c.

  data:lv_lenth type i.

  check sy-ucomm = 'ONLI'.

  if p_file is initial.
    message '请输入文件路径' type 'E'.
  endif.

  lv_file = p_file.
  call method cl_gui_frontend_services=>file_exist
    exporting
      file                 = lv_file
    receiving
      result               = lv_result
    exceptions
      cntl_error           = 1
      error_no_gui         = 2
      wrong_parameter      = 3
      not_supported_by_gui = 4
      others               = 5.
  if sy-subrc <> 0.
    message '文件不存在' type 'E'.
  endif.

***检查文件格式
  call function 'TRINT_SPLIT_FILE_AND_PATH'
    exporting
      full_name     = p_file
    importing
      stripped_name = lv_name
      file_path     = lv_path
    exceptions
      x_error       = 1
      others        = 2.
  if sy-subrc = 0.
    lv_lenth = strlen( lv_name ).
    if lv_lenth > 4.
      lv_lenth = lv_lenth - 4.
    endif.
    lv_name = lv_name+lv_lenth.
    translate lv_name to upper case.
    if lv_name ne '.XLS' and lv_name ne 'XLSX'.
      message '文件不是EXCEL格式文件,请检查' type 'E'.
    endif.
  endif.
endform.                    " FRM_CHECK_FILE_EXIST
*&---------------------------------------------------------------------*
*&      Form  FRM_GENERATE_TEMPLATE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_generate_template .
  data:ls_object like wwwdatatab,
       lv_rc     type sy-subrc,
       lt_ft     type filetable,
       ls_ft     type file_table,
       lv_ua     type i.

  data:lwk_fn type rlgrap-filename.
  data:lv_objid type w3objid.

****查询模板
  lv_objid = 'ZED1_TEST1'.
  select single relid objid from wwwdata into corresponding fields of ls_object
    where relid = 'MI' and srtf2 = 0 and objid = lv_objid.                                  "smw0里对象名称
  if sy-subrc <> 0 or ls_object-objid = space .
    message s001(00) with '未知的Excel模板:ZED1_TEST1' display like 'E'. "未知的Excel模板:ZRPMM_0103
    exit.
  endif.

  call method cl_gui_frontend_services=>file_open_dialog
    exporting
      file_filter             = cl_gui_frontend_services=>filetype_excel
    changing
      file_table              = lt_ft
      rc                      = lv_rc
      user_action             = lv_ua
    exceptions
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      others                  = 5.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  else.
    check lv_ua = 0.
    read table lt_ft into ls_ft index 1.
    lwk_fn  = ls_ft-filename.
***下载模板
    call function 'DOWNLOAD_WEB_OBJECT'
      exporting
        key         = ls_object
        destination = lwk_fn
      importing
        rc          = lv_rc.
    if lv_rc <> 0.
      message s001(00) display like 'E'. "下载模板失败!
      exit.
    endif.
  endif.
endform.                    " FRM_GENERATE_TEMPLATE
form frm_upload_data.
  data:lv_no(10) type c value '1000000000'.

  define mcr_add_zero.
    if &1 is NOT INITIAL.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input         = &1
     IMPORTING
       OUTPUT        = &1.
    endif.
  end-of-definition.

  call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    exporting
      filename                = p_file
      i_begin_col             = '1'
      i_begin_row             = '2'
      i_end_col               = '7'
      i_end_row               = '9999'
    tables
      intern                  = gt_upload[]
    exceptions
      inconsistent_parameters = 1
      upload_ole              = 2
      others                  = 3.
  if sy-subrc <> 0.
* Implement suitable error handling here
  endif.

  if gt_upload[] is initial.
    message '上传文档为空' type 'I'.
    exit.
  endif.

  loop at gt_upload assigning <fs_upload>.
    translate <fs_upload>-value to upper case.
    case <fs_upload>-col.
      when '0001'.
        gs_table-lifnr = <fs_upload>-value.
        gs_table-lifnr = |{ gs_table-lifnr alpha = in }|.
      when '0002'.
        gs_table-bukrs1 = <fs_upload>-value.
      when '0003'.
        gs_table-bukrs2  = <fs_upload>-value.
      when '0004'.
        gs_table-ekorg1 = <fs_upload>-value.
      when '0005'.
        gs_table-ekorg2 = <fs_upload>-value.
      when others.
    endcase.
    at end of row.
      append gs_table to gt_table.
      clear gs_table.
    endat.
  endloop.
***check上传的数据

endform.                    " FRM_UPLOAD_DATA
form check_filename .
  data: l_s1 type string,
        l_s2 type string.

  split p_file at '.' into l_s1 l_s2.
  translate l_s2 to upper case.
  if l_s2 <> 'XLS' and l_s2 <> 'XLSX'.
    message '文件格式不对!' type 'E'.
    stop.
  endif.
endform.

form f_alv_fieldcat .
  define append_alv_cat.
    CLEAR ls_fieldcat.
    ls_fieldcat-fieldname    = &1.
    ls_fieldcat-reptext_ddic = &2.
    APPEND ls_fieldcat TO gt_fieldcat.
  end-of-definition.

  append_alv_cat: 'LIGHT' '红绿灯',
                  'LIFNR' '供应商',
                  'BUKRS1' '模板公司代码',
                  'EKORG1' '模板公司代码',
                  'BUKRS2' '扩建公司代码',
                  'EKORG2' '扩建采购组织',
                  'MESSAGE' '错误说明'.

  ls_layout-zebra     = 'X'.     "斑马线
  ls_layout-lights_fieldname  = 'LIGHT'."指定灯列名
  ls_layout-colwidth_optimize = 'X'.
endform.
*&---------------------------------------------------------------------*
*&      Form  F_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form f_display .
  call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      i_background_id    = 'ALV_BACKGROUND'
      is_layout          = ls_layout
      i_callback_program = g_repid
      it_fieldcat        = gt_fieldcat
    tables
      t_outtab           = gt_table
    exceptions
      program_error      = 1
      others             = 2.
endform.

 

标签:gt,gs,INBOUND,data,S4,file,table,EI,type
From: https://www.cnblogs.com/freeandeasy/p/18380571

相关文章

  • NS4150C 3.0W 单声道 D类音频功率放大器
    1特性●工作电压范围:3.0V~5.0V●输出功率:2.8W(5V/4Ω,THD=10%)●0.1%THD(0.5W/3.6V)●高达88%的效率●高PSRR:-80dB(217Hz)●无需滤波器Class-D结构●优异的全带宽EMI抑制能力●优异的“上电,掉电”噪声抑制●低静态电流:4mA(3.6V电源、Noload)●过......
  • Minimum Steiner Tree 题解
    原题,详见P10723。几乎相同,我们只需要以一个需要选择的点为根,遍历子树看看有没有出现需要选择的点,然后直接去删除即可,可以看我的博客。但是我们也可以换一种做法,用类似拓扑排序的算法。先找到所有只连一条边且没有被选择的点,然后放进队列,接着依次取出队头遍历与它相连的点,同时记......
  • Neo-GNNs: Neighborhood Overlap-aware Graph Neural Networks for Link Prediction
    目录概符号说明MotivationNeo-GNN代码Neo-GNNs:Neighborhoodoverlap-awaregraphneuralnetworksforlinkprediction.NeurIPS,2021.概一种计算上相对高效的,同时利用结构信息和特征信息的链接预测模型.符号说明\(\mathcal{G}=(\mathcal{V},\mathcal{E})\),gra......
  • 开发日志:表单解析 LeipiFormDesign
    PHP版本:https://gitee.com/yxkj_2/LeipiFormDesigner/blob/LeipiFormDesigner/Formdesign4_1/php/Formdesign.class.phpjs版本: varleipiFormDesign={/*执行控件*/exec:function(method){ue.execCommand(method);},......
  • 马克斯CMS4.0原创电影模板-自动采集-简洁蓝色模板-带手机wap模板-特色功能一应俱全202
    马克斯CMS4.0原创电影模板-自动采集-简洁蓝色模板-带手机wap模板-特色功能一应俱全2024电影模板马克斯CMS4.0原创电影模板源码介绍马克斯CMS4.0是一款专为电影网站设计的内容管理系统,提供了丰富的功能和灵活的定制选项。该系统支持自动采集功能,能够自动从互联网上抓取最......
  • ABC 368D Minimum Steiner Tree
    题意给你一颗由N个点组成的树,指定K个节点,求包含这K个节点的最小子树的大小思路考虑正难则反,我们从开始的树当中剪掉那些没有任何指定点的子树,剩下来的子树就是最小的、能包含所有指定节点的子树。关于剪去这个操作,就是dfs一旦遇到以当前节点为根的子树没有任何指定点时,就停止df......
  • HeidiSQL中一些简单mysql语句的含义(二)
    一、排序#根据年龄进行降序排序select*fromstudentorderbyagedesc;#根据年龄进行升序排序select*fromstudentorderbyageasc;#给字段起别名,as可以省略selectnoas编号,nameas姓名,ageas年龄fromstudentorderbyageasc;#查找前五条select*fr......
  • Ros2 Moveit2 编译安装报错解决方案 - By not providing "Findgz_sim_vendor.cmake" i
    moveit_resources---stderr:gz_ros2_controlCMakeErroratCMakeLists.txt:27(find_package):Bynotproviding"Findgz_sim_vendor.cmake"inCMAKE_MODULE_PATHthisprojecthasaskedCMaketofindapackageconfigurationfileprovidedby"gz......
  • 零基础国产GD32单片机编程入门(一)GD32单片机GPIO输出Keil5工程创建含源码
    文章目录一.概要二.GD32单片机GPIO内部结构图三.GD32单片机GPIO输入输出信号流向四.GD32单片机GPIO引脚的复用以及重映射五.从零开始创建一个GD32F103C8T6单片机GPIO输出驱动LED灯例程六.工程源代码下载七.小结一.概要GPIO(generalporposeintputoutput):单片机通......
  • 基于nodejs+vueIT企业绩效核算平台[程序+论文+开题]-计算机毕业设计
    本系统(程序+源码+数据库+调试部署+开发环境)带文档lw万字以上,文末可获取源码系统程序文件列表开题报告内容研究背景在当今竞争激烈的IT行业中,企业的持续发展离不开高效的管理体系与科学的绩效评估机制。随着企业规模的扩大和业务复杂度的提升,传统的手工或简单的电子表格绩......