ABAP中关于WS_DOWNLOAD的程序的知识点介绍

ABAP中关于WS_DOWNLOAD的程序的知识点介绍

*&---------------------------------------------------------------------*

*& Report ZZW_LOCAL_FILE_OPERATION1 *

*& *

*&---------------------------------------------------------------------*

*& *

*& *

*&---------------------------------------------------------------------*

REPORT ZZW_LOCAL_FILE_OPERATION1 .

tables: vbak , kna1 .

data: begin of z_sales occurs 10000,

kunnr like kna1-kunnr, "Customer number

name1 like kna1-name1, "Name

end of z_sales.

data: begin of t_colnames occurs 10,

name(15), "Column names for download

end of t_colnames.

selection-screen begin of block g2 with frame title text-001.

parameters: p_print radiobutton group l1, "View

p_down radiobutton group l1, "Download

p_file like rlgrap-filename default 'C:/TEMP/123.TXT'.

selection-screen end of block g2.

*----------------------------------------------------------------------*

* Selection Screen processing *

*----------------------------------------------------------------------*

at selection-screen on p_file.

* If download is checked, but no file name is entered, error

if p_down eq 'X' and p_file eq space.

message X004(SU) with 'Please enter file name for download.'.

endif.

*** Populate Itabs for download

* Column names

move 'Sold-to' to t_colnames-name.

append t_colnames.

move 'Name' to t_colnames-name.

append t_colnames.

* Data

*move kna1-kunnr to z_sales-kunnr.

*move kna1-name1 to z_sales-name1.

*append z_sales.

Select kunnr name1 into table z_sales

from kna1

where kunnr like 'Z%' .

* Call function module to download file

call function 'WS_DOWNLOAD'

exporting

filename = p_file

filetype = 'DAT'

* col_select = 'X'

tables

data_tab = z_sales

fieldnames = t_colnames

* EXCEPTIONS

* FILE_OPEN_ERROR = 1

* FILE_WRITE_ERROR = 2

* INVALID_FILESIZE = 3

* INVALID_TABLE_WIDTH = 4

* INVALID_TYPE = 5

* NO_BATCH = 6

* UNKNOWN_ERROR = 7

* GUI_REFUSE_FILETRANSFER = 8

* OTHERS = 9

.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

程序运行效果图:

ABAP中关于WS_DOWNLOAD的程序的知识点介绍