You are on page 1of 4

2/10/2020 File Operation On Application Server (Delete~Upload~Download) - Code Gallery - Community Wiki

Welcome to the new version of SAP Community Wiki: Learn What's New? and what has changed.
Dashboard

File Operation On Application Server (Delete~Upload~Download)


Created by Unknown User (g1qdlz8), last modified by Former Member on Jun 04, 2013

Applies to:
This document applies to SAP ECC 6.0, SAP Netweaver 2004s. For more information, visit the ABAP homepage.

Summary
This program is used to perform file operation such as Delete\ upload\ download from application server. There is no standard transaction to delete file from application server. So this sample code can be useful when someone wants to delete a file from application server.

Author: Sourabh Batwara


Company: Cognizant Technology Solution
Submitted: 1st December 2010

Author Bio:
Sourabh Batwara is working in Cognizant technology solution as a SAP Consultant. He has 4.5 years of experience in SAP.

Description
While working with file interface we have to delete, upload or download files from application server. but for deletion, there is no standard transaction available in SAP. This program will help to delete file from application server.

Selection screen shots

Upload File:

Download File

Delete File

https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=491918437 1/4
2/10/2020 File Operation On Application Server (Delete~Upload~Download) - Code Gallery - Community Wiki

Program Code
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*-----------------------------------------------------------------------
* Program Name : ZSB_FILE_OPERATION
* Creation date : 01.12.2010
* Description : This Test program is used to perform file
* operation on application server such as delete/upload/download.
*-----------------------------------------------------------------------
REPORT zsb_file_operation.
*----------------------------------------------------------------------*
* DATA DECLEARATION *
*----------------------------------------------------------------------*
* boolean constants for function-parameters and other objects
TYPE-POOLS: esp1.
* Boolean values
TYPES: boolean TYPE esp1_boolean.
DATA: p_file(128), " File path
lv_ans, " Popup answer
lv_flag LIKE bapistdtyp-boolean.
CONSTANTS : c_yes TYPE c VALUE '1',
c_no TYPE c VALUE '0',
c_upload(4) TYPE c VALUE 'CG3Z',
c_dnload(4) TYPE c VALUE 'CG3Y',
c_x TYPE c VALUE 'X',
c_j TYPE c VALUE 'J',
c_n TYPE c VALUE 'N',
true TYPE boolean VALUE esp1_true.
*----------------------------------------------------------------------*
* SELECTION SCREEN *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : r_upload RADIOBUTTON GROUP rb1 USER-COMMAND del DEFAULT 'X', " Upload file
r_dnload RADIOBUTTON GROUP rb1, " Download file
r_delete RADIOBUTTON GROUP rb1. " Delete file
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: p_dir LIKE rlgrap-filename MODIF ID del, " Dir Path
p_file1 LIKE rlgrap-filename MODIF ID del. " Path name
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
PARAMETERS: p_local LIKE rcgfiletr-ftfront MODIF ID up, " Dir Path
p_path LIKE rcgfiletr-ftappl MODIF ID up, " Path name
p_over AS CHECKBOX MODIF ID up. " Overwrite
SELECTION-SCREEN END OF BLOCK b3.
SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.
PARAMETERS: p_path1 LIKE rcgfiletr-ftappl MODIF ID dn, " Path name
p_local1 LIKE rcgfiletr-ftfront MODIF ID dn, " Dir Path
p_over1 AS CHECKBOX MODIF ID dn.
SELECTION-SCREEN END OF BLOCK b4.
*----------------------------------------------------------------------*
* AT SELECTION SCREEN OUTPUT *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-group1 = 'DEL'.
IF r_delete = c_x.
screen-invisible = c_no .
screen-active = c_yes .
ELSE.
screen-invisible = c_yes .
screen-active = c_no .
ENDIF.
MODIFY SCREEN.
ENDIF.
IF screen-group1 = 'UP'.
IF r_upload = c_x.
screen-invisible = c_no .
screen-active = c_yes .
ELSE.
screen-invisible = c_yes .
screen-active = c_no .
ENDIF.
MODIFY SCREEN.
ENDIF.
IF screen-group1 = 'DN'.

https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=491918437 2/4
2/10/2020 File Operation On Application Server (Delete~Upload~Download) - Code Gallery - Community Wiki

IF r_dnload = c_x.
screen-invisible = c_no .
screen-active = c_yes .
ELSE.
screen-invisible = c_yes .
screen-active = c_no .
ENDIF.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
*----------------------------------------------------------------------*
* AT SELECTION SCREEN ON VALUE REQUEST *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_local.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_LOCAL'
IMPORTING
file_name = p_local.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_local1.


CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_LOCAL1'
IMPORTING
file_name = p_local1.
*----------------------------------------------------------------------*
* START OF SELECTION *
*----------------------------------------------------------------------*
START-OF-SELECTION.
IF r_upload = c_x.
PERFORM file_upload.
ELSEIF r_dnload = c_x.
PERFORM file_dnload.
ELSE.
PERFORM file_delete.
ENDIF.
*&---------------------------------------------------------------------*
*& Form FILE_UPLOAD
*&---------------------------------------------------------------------*
* Form to upload file from frontend to application server
*----------------------------------------------------------------------*
FORM file_upload .
CLEAR lv_flag.
IF p_over = c_x.
lv_flag = 1.
ENDIF.
CALL FUNCTION 'C13Z_FILE_UPLOAD_BINARY'
EXPORTING
i_file_front_end = p_local
i_file_appl = p_path
i_file_overwrite = lv_flag
EXCEPTIONS
fe_file_not_exists = 1
fe_file_read_error = 2
ap_no_authority = 3
ap_file_open_error = 4
ap_file_exists = 5.
CASE sy-subrc.
WHEN '0'.
MESSAGE s899(bd) WITH 'File uploaded successfully'.
WHEN '1'.
MESSAGE e899(bd) WITH 'File does not exist'.
WHEN '2'.
MESSAGE e899(bd) WITH 'Error in file reading'.
WHEN '3'.
MESSAGE e899(bd) WITH 'Authorization Error'.
WHEN '5'.
* file already exists, ask if file can be overwritten
CALL FUNCTION 'C14A_POPUP_ASK_FILE_OVERWRITE'
IMPORTING
e_flg_continue = lv_flag
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0 AND
lv_flag = true.
CALL FUNCTION 'C13Z_FILE_UPLOAD_BINARY'
EXPORTING
i_file_front_end = p_local
i_file_appl = p_path
i_file_overwrite = lv_flag.
IF sy-subrc IS INITIAL.
MESSAGE s899(bd) WITH 'File uploaded successfully'.
ENDIF.
ENDIF.
ENDCASE.
ENDFORM. " FILE_UPLOAD
*&---------------------------------------------------------------------*
*& Form FILE_DNLOAD
*&---------------------------------------------------------------------*
* Form to download the file from application server to frontend
*----------------------------------------------------------------------*
FORM file_dnload .
CLEAR lv_flag.
IF p_over1 = c_x.
lv_flag = 1.
ENDIF.
CALL FUNCTION 'C13Z_FILE_DOWNLOAD_BINARY'
EXPORTING
i_file_front_end = p_local1

https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=491918437 3/4
2/10/2020 File Operation On Application Server (Delete~Upload~Download) - Code Gallery - Community Wiki

i_file_appl = p_path1
i_file_overwrite = lv_flag
EXCEPTIONS
fe_file_open_error = 1
fe_file_exists = 2
ap_no_authority = 4.
CASE sy-subrc.
WHEN '0'.
MESSAGE s899(bd) WITH 'File downloaded successfully'.
WHEN '1'.
MESSAGE e899(bd) WITH 'Error while opening file'.
WHEN '2'.
* file already exists, ask if file can be overwritten
CALL FUNCTION 'C14A_POPUP_ASK_FILE_OVERWRITE'
IMPORTING
e_flg_continue = lv_flag
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0 AND
lv_flag = true.
CALL FUNCTION 'C13Z_FILE_DOWNLOAD_BINARY'
EXPORTING
i_file_front_end = p_local1
i_file_appl = p_path1
i_file_overwrite = lv_flag.
IF sy-subrc IS INITIAL.
MESSAGE s899(bd) WITH 'File downloaded successfully'.
ENDIF.
ENDIF.
WHEN '4'.
MESSAGE e899(bd) WITH 'Authorization Error'.
ENDCASE.
ENDFORM. " FILE_DNLOAD
*----------------------------------------------------------------------*
* Form FILE_DELETE *
*----------------------------------------------------------------------*
* Form to delete file from application server *
*----------------------------------------------------------------------*
FORM file_delete .
* File path
CONCATENATE p_dir p_file1 INTO p_file.
* Check file exists
OPEN DATASET p_file FOR INPUT IN BINARY MODE.
IF sy-subrc NE 0.
MESSAGE e899(bd) WITH p_file 'does not exist'.
EXIT.
ELSE.
* Popup window
CALL FUNCTION 'POPUP_CONTINUE_YES_NO'
EXPORTING
defaultoption = c_n
textline1 = p_file
titel = 'Are you sure to delete this file?'
IMPORTING
answer = lv_ans
EXCEPTIONS
OTHERS = 1.
ENDIF.
CLOSE DATASET p_file.
IF lv_ans EQ c_j.
* Delete file
DELETE DATASET p_file.
IF sy-subrc NE 0.
MESSAGE e899(bd) WITH 'Invalid file name' p_file.
ELSE.
CLOSE DATASET p_file.
MESSAGE s899(bd) WITH p_dir p_file1 'has been deleted'.
ENDIF.
ENDIF.
ENDFORM. " FILE_DELETE
No labels

Privacy Terms of Use Legal Disclosure Copyright Trademark Cookie Preferences

https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=491918437 4/4

You might also like