Skip to content

Instantly share code, notes, and snippets.

@fleischr
Created September 17, 2022 02:48
Show Gist options
  • Save fleischr/f58de41bd03790f5a6008edea3c75e40 to your computer and use it in GitHub Desktop.
Save fleischr/f58de41bd03790f5a6008edea3c75e40 to your computer and use it in GitHub Desktop.
REPORT ztest_download.
"&-------------------------------------------------------------*
"& Declarations
"&-------------------------------------------------------------*
TYPES: BEGIN OF ty_pa0001,
pernr TYPE pa0001-pernr,
bukrs TYPE pa0001-bukrs,
werks TYPE pa0001-werks,
persg TYPE pa0001-persg,
ename TYPE pa0001-ename,
END OF ty_pa0001.
DATA:it_pa0001 TYPE STANDARD TABLE OF ty_pa0001.
DATA:wa_pa0001 TYPE ty_pa0001.
DATA:it_filetable TYPE filetable.
DATA ls_filetable LIKE LINE OF it_filetable.
DATA gv_rc TYPE i.
"&-------------------------------------------------------------*
"& Selection-screen
"&-------------------------------------------------------------*
PARAMETERS:
p_file TYPE string.
"&-------------------------------------------------------------*
"& At Selection-Screen
"&-------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Open file'
* default_extension =
* default_filename =
* file_filter =
* with_encoding =
* initial_directory =
* multiselection =
CHANGING
file_table = it_filetable
rc = gv_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.
* Implement suitable error handling here
ELSE.
READ TABLE it_filetable INTO ls_filetable INDEX 1.
p_file = ls_filetable-filename.
ENDIF.
"&-------------------------------------------------------------*
"& Start Of selection
"&-------------------------------------------------------------*
START-OF-SELECTION.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = p_file
filetype = 'ASC'
has_field_separator = 'X'
* header_length = 0
* read_by_line = 'X'
* dat_mode = SPACE
* codepage = SPACE
* ignore_cerr = ABAP_TRUE
* replacement = '#'
* virus_scan_profile =
* isdownload = SPACE
* IMPORTING
* filelength =
* header =
CHANGING
data_tab = it_pa0001
* isscanperformed = SPACE
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ELSE.
LOOP AT it_pa0001 INTO wa_pa0001.
WRITE:/ wa_pa0001.
ENDLOOP.
ENDIF.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment