report zfi005.
*----------------------------------------------------------------------*
* 数据库表声明
*----------------------------------------------------------------------*
tables sscrfields."选择屏幕控件定义
*----------------------------------------------------------------------*
* 声明类型
*----------------------------------------------------------------------*
*&---文件上载/file upload
types: begin 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.
data: gs_upload type ty_upload.
data: gt_upload_add type standard table of ty_upload.
data: g_flag.
data: gt_bak type standard table of ty_upload.
field-symbols: <fs_upload> type ty_upload.
*&---ALV参数
data: gt_fieldcat type lvc_t_fcat.
data: gs_layout type lvc_s_layo.
data: gt_tbsl type table of tbsl,
gs_tbsl type tbsl.
data: g_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.
parameters: p_up radiobutton group grp1 default 'X' user-command create, "EXCEL导入
p_down radiobutton group grp1. "EXCEL下载
parameters: p_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.
data: l_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 .
data: lv_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.
clear: gt_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
SAP会计凭证批导
最新推荐文章于 2024-03-19 17:18:22 发布