Upload / Download / Delete functionality of Application server Program.
*&---------------------------------------------------------------------* *& Report ZAPPLSERVER * *& * *&---------------------------------------------------------------------* *& * *& * *&---------------------------------------------------------------------* REPORT ZAPPLSERVER message-id FB. ************************************************************************ * Constants constants :c_mask(80) type c value ',.,..', " Mask c_file_type(10) type c value 'ASC', " File type c_mode(1) type c value 'L'. " Mode * Internal tables * data: begin of i_file occurs 0, field(3000) type c, end of i_file. data : v_msg(100), struct_file like i_file occurs 0. * Parameters parameters: p_fpath type draw-filep obligatory, p_lpath type localfile, p_upload as checkbox default 'X', p_dload as checkbox, p_delete as checkbox. ************************************************************************ * Check selection-screen entries * ************************************************************************ * At selection screen AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_lpath. PERFORM get_file CHANGING p_lpath. ************************************************************************ * Main * ************************************************************************ * Start of selection start-of-selection. if p_upload = 'X'. * Upload to app server perform upload_to_appserver. endif. if p_dload = 'X'. * Download to desktop perform download_to_desktop. endif. if p_delete = 'X'. * Delete file on app server delete dataset p_fpath. if sy-subrc = 0. message s000 with 'File deleted'. endif. endif. ************************************************************************ * OUTPUT of extracted data * ************************************************************************ * sort. * loop. * * endloop. ************************************************************************ * EVENTS DURING LISTPROCESSING * ************************************************************************ ************************************************************************ * EVENTS AT USER COMMAND ************************************************************************ *at line selection. *at user-command. ************************************************************************ * ROUTINES/FORM * ************************************************************************ *------------------------------------------------------------- * Set file path of local machine *------------------------------------------------------------- FORM get_file CHANGING file_out. DATA: l_filename TYPE localfile. "Local file for upload/download CALL FUNCTION 'WS_FILENAME_GET' EXPORTING mask = c_mask mode = c_mode IMPORTING filename = l_filename EXCEPTIONS inv_winsys = 01 no_batch = 02 selection_cancel = 03 selection_error = 04. p_lpath = l_filename. ENDFORM. *&---------------------------------------------------------------------* *& Form UPLOAD_TO_APPSERVER *&---------------------------------------------------------------------* * Upload local file to app server *----------------------------------------------------------------------* form upload_to_appserver . data: l_lpath type string. l_lpath = p_lpath. refresh i_file. clear i_file. CALL FUNCTION 'GUI_UPLOAD' EXPORTING FILENAME = l_lpath FILETYPE = c_file_type * HAS_FIELD_SEPARATOR = ' ' * HEADER_LENGTH = 0 * READ_BY_LINE = 'X' * DAT_MODE = 'X' * CODEPAGE = ' ' * IGNORE_CERR = ABAP_TRUE * REPLACEMENT = SPACE * CHECK_BOM = '#' * IMPORTING * FILELENGTH = * HEADER = TABLES DATA_TAB = i_file 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 OTHERS = 17. open dataset p_fpath for output in text mode encoding default message v_msg. if sy-subrc = 0. loop at i_file. " into struct_file. if not i_file is initial. transfer i_file to p_fpath. endif. endloop. else. message e000 with 'File cannot be opened for output'. endif. close dataset p_fpath. endform. " UPLOAD_TO_APPSERVER *&---------------------------------------------------------------------* *& Form DOWNLOAD_TO_DESKTOP *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* form download_to_desktop . open dataset p_fpath for input in text mode encoding default message v_msg. if sy-subrc = 0. refresh : i_file. do. read dataset p_fpath into i_file. if sy-subrc = 0. append i_file to i_file. else. exit. endif. enddo. else. message e000 with 'File cannot be opened'. endif. close dataset p_fpath. call function 'DOWNLOAD' exporting filename = p_lpath tables data_tab = i_file. endform. " DOWNLOAD_TO_DESKTOP