SAP会计凭证批导



report zfi005.

*----------------------------------------------------------------------*
数据库表声明
*----------------------------------------------------------------------*
tables sscrfields."选择屏幕控件定义
*----------------------------------------------------------------------*
声明类型
*----------------------------------------------------------------------*
*&---文件上载/file upload
typesbegin of ty_upload,
         number     type text20,                                      序号
         comp_code  type bapiache09-comp_code,                        公司代码
         pstng_date type bapiache09-pstng_date,                       过账日期
         doc_date   type bapiache09-doc_date,                         凭证日期
         doc_type   type bapiache09-doc_type,                         凭证类型
         currency   type bapiaccr09-currency ,                        货币
         kursf      type bapiaccr09-exch_rate,                        汇率
         ref_doc_no type bapiache09-ref_doc_no,                       参照
         numpg      type char03,                                      页数
         header_txt type bapiache09-header_txt,                       凭证抬头文本
         buzei      type buzei,                                       行项目
         bschl      type bschl,                                       过账码
         gl_account type bapiacap09-gl_account ,                      总账科目
         customer   type bapiacar09-customer ,                        客户编号
         vendor_no  type bapiacap09-vendor_no ,                       供应商编号
         umskz      type bseg-umskz ,                                 特别总账标识
         asset_no   type bapiacgl09-asset_no ,                        资产号
         anln2      type anla-anln2,                                  资产子编号
         anbwa      type bseg-anbwa,                                  事物类型
         wrbtr      type bseg-wrbtr,                                  交易货币金额
         dmbtr      type bseg-dmbtr,                                  本位币金额
         dmbe2      type bseg-dmbe2,                                  本位币2金额
         gsber      type bseg-gsber,                                  业务范围
         kkber      type bseg-kkber,                                  信用控制范围
         costcenter type bapiacgl09-costcenter ,                      成本中心
         orderid    type bapiacgl09-orderid ,                         订单(统计型内部订单)
         pernr      type bseg-pernr,                                  人员编号
         zuonr      type bapiacgl09-alloc_nmbr,                       分配
         item_text  type bapiacgl09-item_text ,                       文本(凭证行文本)
         xnegp      type bseg-xnegp ,                                 反记账
         menge      type bseg-menge,                                  数量
         meins      type bseg-meins,                                  单位
         xref1      type bseg-xref1 ,                                 参考代码1
         xref2      type bseg-xref2 ,                                 参考代码2
         xref3      type bseg-xref3 ,                                 参考代码3
         zfbdt      type bseg-zfbdt ,                                 基限日期(汇票到期日)
         zterm      type bseg-zterm,                                  付款条件
         rstgr      type bseg-rstgr,                                  原因代码
         vbund      type bseg-vbund,                                  贸易伙伴
         "获利能力段
         kndnr      type kunde_pa,                                    客户
         artnr      type artnr,                                       生产
         fkart      type fkart,                                       开票类型
         kaufn      type kdauf,                                       销售订单
         kdpos      type kdpos,                                       销售订单项目
         rkaufnr    type aufnr,                                       订单
         werks      type werks_d,                                     工厂
         fkber      type fkber,                                       功能范围
         segment    type fb_segment,                                  
         vkorg      type vkorg,                                       销售机构
         vtweg      type vtweg,                                       分销渠道
         spart      type spart,                                       产品组
         pspnr      type ps_psp_pnr,                                  " WBS 要素
         copa_kostl type copa_kostl,                                  成本中心
         kstrg      type kstrg,                                       成本对象
         prctr      type prctr,                                       利润中心
         pprctr     type pprctr,                                      伙伴 PC
         budget_pd  type bseg-budget_pd,                              预算期间
         zlsch      type bseg-zlsch,                                  付款方式
         zzcoalr    type bseg-zzcoalr,                                辅助核算科目

         kmmakl     type matkl,                                       物料组
         kmvkbu     type vkbur,                                       销售办事处
         kmvkgr     type vkgrp,                                       销售组

*&---用来显示消息的字段
         belnr      type bseg-belnr,                                  会计凭证编号
         gjahr      type bseg-gjahr,                                  财年
         bukrs      type bseg-bukrs,                                  公司代码
         msg        type string,                                      返回消息
         msg_belnr  type string,                                      返回凭证号
         light      type c length 4,                                  消息指示灯
         type       type c length 1,                                  消息类型
*         slbox,
*         newbw      TYPE bwasl,                                       " 事物类型   模板已将该字段删除该字段在该程序中已无用
       end of ty_upload,

       begin of ty_criteria_field,
         name type fieldname,
       end of ty_criteria_field.

*&---------------------------------------------------------------------*
*& globle/全局变量声明
*&---------------------------------------------------------------------*
*&---接收上传数据的内表和工作区

data:
  gt_upload         type standard table of ty_upload,
  gt_criteria_field type table of ty_criteria_field,
  gt_t001           type sorted table of t001 with unique key bukrs,
  gt_finsc_001a     type sorted table of finsc_001a with unique key bukrs curtype.
datags_upload type ty_upload.
datagt_upload_add type standard table of ty_upload.
datag_flag.
datagt_bak type standard table of ty_upload.
field-symbols<fs_upload> type ty_upload.

*&---ALV参数

datagt_fieldcat type lvc_t_fcat.
datags_layout type lvc_s_layo.

datagt_tbsl type table of tbsl,
      gs_tbsl type tbsl.

datag_re.

*&---------------------------------------------------------------------*
*& 宏声明
*&---------------------------------------------------------------------*
define build_fieldcat.
  CLEAR ls_fieldcat.

  ls_fieldcat-fieldname &1.
  ls_fieldcat-coltext   &2.
*  ls_fieldcat-outputlen = &3.

 "读取定义的长度和小数位
  READ TABLE lr_struct->components INTO ls_components
     
WITH KEY name &1.
   IF sy-subrc 0.
     ls_fieldcat-inttype   ls_components-type_kind.
     ls_fieldcat-outputlen ls_components-length.
     ls_fieldcat-decimals  ls_components-decimals.
   ENDIF.

  IF ls_fieldcat-fieldname 'GL_ACCOUNT' OR
     ls_fieldcat-fieldname 'CUSTOMER' OR
     ls_fieldcat-fieldname 'VENDOR_NO' OR
     ls_fieldcat-fieldname 'COSTCENTER' OR
     ls_fieldcat-fieldname 'ORDERID' OR
     ls_fieldcat-fieldname 'VBUND' OR
     ls_fieldcat-fieldname 'ASSET_NO' OR
     ls_fieldcat-fieldname 'ANLN2' OR
     ls_fieldcat-fieldname 'KNDNR' OR
     ls_fieldcat-fieldname 'KAUFN' OR
     ls_fieldcat-fieldname 'RKAUFNR' OR
     ls_fieldcat-fieldname 'COPA_KOSTL' OR
     ls_fieldcat-fieldname 'PRCTR' OR
     ls_fieldcat-fieldname 'PPRCTR' OR
     ls_fieldcat-fieldname 'MSG_BELNR'.
     ls_fieldcat-convexit 'ALPHA'.
  ENDIF.

  IF ls_fieldcat-fieldname 'MEINS'.
    ls_fieldcat-convexit 'CUNIT'.
  ENDIF.

  IF ls_fieldcat-fieldname 'ARTNR'.
    ls_fieldcat-convexit 'MATN1'.
  ENDIF.

  IF ls_fieldcat-fieldname 'MSG' OR
     ls_fieldcat-fieldname 'LIGHT' OR
     ls_fieldcat-fieldname 'MSG_BELNR' OR
     ls_fieldcat-fieldname 'TYPE'.
    ls_fieldcat-key  'X'.
  ENDIF.
  APPEND ls_fieldcat TO gt_fieldcat.

end-of-definition.
define  fill_ftpost.
  clear ls_ftpost.
  ls_ftpost-stype &1.
  ls_ftpost-count &2.
  ls_ftpost-fnam  &3.
  ls_ftpost-fval  &4.
  condense ls_ftpost-fval no-gaps.
  append ls_ftpost to lt_ftpost.
end-of-definition.
*&---------------------------------------------------------------------*
*& selection screen/选择屏幕
*&---------------------------------------------------------------------*
selection-screen begin of block blk1 with frame title text-001.
  parametersp_up   radiobutton group grp1 default 'X' user-command create"EXCEL导入
              p_down radiobutton group grp1.                "EXCEL下载
  parametersp_file type rlgrap-filename modif id m4."文件名
selection-screen end of block blk1.
*--------------------------------------------------------------------*
* initialization/选择屏幕前初始化
*--------------------------------------------------------------------*
initialization.
*&---初始化变量
  perform initializtion.

*&---------------------------------------------------------------------*
*& at selection-screen/选择屏幕开始                                    *
*&---------------------------------------------------------------------*
at selection-screen.

*&---文件路径搜索帮助
at selection-screen on value-request for p_file.

  datal_filename like rlgrap-filename.

  call function 'WS_FILENAME_GET'
    exporting
*     DEF_FILENAME     = ',*.XLSX,*.XLSX;,*.XLS,*.XLS;'
*     DEF_PATH         = ' '
      mask             ',Excel file,*.xls;*.xlsx;'  "
      mode             'O'
*     TITLE            = ' '
    importing
      filename         l_filename
*     RC               =
    exceptions
      inv_winsys       1
      no_batch         2
      selection_cancel 3
      selection_error  4
      others           5.
  if sy-subrc 0.
    p_file l_filename.
  endif.

*
*  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
*    CHANGING
*      file_name = p_file.

*&---屏幕动态显示隐藏设置
at selection-screen output.

*&---------------------------------------------------------------------*
*& start-of-selection/开始选择屏幕
*&---------------------------------------------------------------------*
start-of-selection.

  if p_up abap_true .
*&---检查文件格式
    perform frm_check_filename.
*&---上载数据
    perform frm_get_data_from_file.
*&---ALV 展示(file data VS itab data check
    perform get_tbsl_data.
    perform frm_alv_show.
*&---EXCEL模板下载
  elseif p_down abap_true .
    perform frm_download.
  endif.

*&---------------------------------------------------------------------*
*& end-of-selection/结束选择屏幕(程序结束处理,输出等)               *
*&---------------------------------------------------------------------*
end-of-selection.
*&---------------------------------------------------------------------*
*&      form  check_filename
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_check_filename .

  datalv_s1 type string,
        lv_s2 type string.

  split p_file at '.' into lv_s1 lv_s2.
  translate lv_s2 to upper case.
  if p_file is initial.
    message  text-013 type 'S' display like 'W'"请输入数据路径!
    leave list-processing.
  endif.

endform" CHECK_FILENAME
*&---------------------------------------------------------------------*
*&      form  get_data_from_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_get_data_from_file .
  data:
*    lt_return TYPE bapiret2_t,
*    ls_return TYPE LINE OF bapiret2_t,
    l_string type string,
    ls_path  type rlgrap-filename.

  field-symbols<fs>.

  data:l_filename type rlgrap-filename,
       l_endrow   type i.

  data:itab type table of zsalsmex_tabline2 with header line.

  cleargt_upload.

  if p_file is initial .
    message text-012  type 'E'"'文件路径不存在'
  endif.

*  ls_path = p_file.
  l_filename p_file.
  l_endrow   900000.

  call function 'ZALSM_EXCEL_TO_INTERNAL_TABLE'
    exporting
      filename                l_filename
      i_begin_col             
1
      i_begin_row             2
      i_end_col               59
      i_end_row               l_endrow
    
tables
      intern                  itab
    
exceptions
      inconsistent_parameters 1
      upload_ole              2
      others                  3.
  if sy-subrc <> 0.
  endif.

  if itab[] is not initial.
    loop at itab.
      on change of itab-row.
        if sy-tabix ne 1.
          append gs_upload to gt_upload.
          clear  gs_upload.
        endif.
      endon.

      try.
          assign component itab-c

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT养家和SAP养家

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值