hongleimi 发表于 2015-9-20 11:32:59

SAP 到出XLS

report z_test7.
data:gv_fname like rlgrap-filename," filename
gv_filename type string.

data:begin of gt_sflight_down_header occurs 0,
carrid(20),
fldate(20),
cityfrom(20),
cityto(20),
fltime(20),
price(20),
currency(20),
end of gt_sflight_down_header.
*define the download internal table

data:begin of gt_sflight_down occurs 0, "存放表体数据

carrid like sflight-carrid,
fldate like sflight-fldate,
cityfrom like spfli-cityfrom,
cityto like spfli-cityto,
fltime like spfli-fltime,
price like sflight-price,
currency like sflight-currency,
end of gt_sflight_down.

perform download.
"下面是要call的function:
*&---------------------------------------------------------------------*
*&      Formdownload
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form download .
clear gt_sflight_down_header[]. "必须要清空,否则会出现数据重复下载的情况

clear gt_sflight_down[].
*set the data header

gt_sflight_down_header-carrid = 'companyid'.
gt_sflight_down_header-fldate = 'flightdate'.
gt_sflight_down_header-cityfrom = 'origin'.
gt_sflight_down_header-cityto = 'destination'.
gt_sflight_down_header-fltime = 'flighttime'.
gt_sflight_down_header-price = 'cost'.
gt_sflight_down_header-currency = 'currency'.
append gt_sflight_down_header.
*set the main download data
*      loop at gt_sflight.
*
*      gt_sflight_down-carrid = gt_sflight-carrid.
*
*      gt_sflight_down-fldate = gt_sflight-fldate.
*
*      gt_sflight_down-cityfrom = gt_sflight-cityfrom.
*
*      gt_sflight_down-cityto = gt_sflight-cityto.
*
*      gt_sflight_down-fltime = gt_sflight-fltime.
*
*      gt_sflight_down-price = gt_sflight-price.
*
*      gt_sflight_down-currency = gt_sflight-currency.
*
*      append gt_sflight_down.
*
*      endloop.


gt_sflight_down-carrid = 1.
gt_sflight_down-fldate = 2.
gt_sflight_down-cityfrom = 3.
gt_sflight_down-cityto = 3.
gt_sflight_down-fltime = 3.
gt_sflight_down-price = 3.
gt_sflight_down-currency = 3.
append gt_sflight_down.


call function 'WS_FILENAME_GET'
exporting
mask             = ',*.xls,*.xlsx.'
mode             = 'S'
title            = 'choose the location'
importing
filename         = gv_fname
exceptions
inv_winsys       = 1
no_batch         = 2
selection_cancel = 3
selection_error= 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.
endif.



concatenate gv_fname '.xls' into gv_filename. "给返回的文件路径加上后缀名

call function 'GUI_DOWNLOAD' "第一次调用,先下载表头数据
    exporting
filename                = gv_filename
filetype                = 'ASC'
write_field_separator   = 'X'
tables
data_tab                = gt_sflight_down_header[]
exceptions
file_write_error      = 1
no_batch                = 2
gui_refuse_filetransfer = 3
invalid_type            = 4
no_authority            = 5
unknown_error         = 6
header_not_allowed      = 7
separator_not_allowed   = 8
filesize_not_allowed    = 9
header_too_long         = 10
dp_error_create         = 11
dp_error_send         = 12
dp_error_write          = 13
unknown_dp_error      = 14
access_denied         = 15
dp_out_of_memory      = 16
disk_full               = 17
dp_timeout            = 18
file_not_found          = 19
dataprovider_exception= 20
control_flush_error   = 21
others                  = 22.
*download the main data

call function 'GUI_DOWNLOAD' "第二次调用,下载表体数据
    exporting
filename                = gv_filename
filetype                ='ASC'
write_field_separator   = 'X'
append                  ='X' "指定下载模式为附加
    tables
data_tab                = gt_sflight_down[]
exceptions
file_write_error      = 1
no_batch                = 2
gui_refuse_filetransfer = 3
invalid_type            = 4
no_authority            = 5
unknown_error         = 6
header_not_allowed      = 7
separator_not_allowed   = 8
filesize_not_allowed    = 9
header_too_long         = 10
dp_error_create         = 11
dp_error_send         = 12
dp_error_write          = 13
unknown_dp_error      = 14
access_denied         = 15
dp_out_of_memory      = 16
disk_full               = 17
dp_timeout            = 18
file_not_found          = 19
dataprovider_exception= 20
control_flush_error   = 21
others                  = 22.
if sy-subrc = 0.
message i012(zeduc132_m).
endif.

endform.                  "" download
  
页: [1]
查看完整版本: SAP 到出XLS