REPORT zupl_presentation_to_appl.
* Local data ----------------------------------------------------------
DATA: l_filelength TYPE i.
types : begin of ty_dt_tab,
txt(4096) TYPE c,
end of ty_dt_tab.
DATA : lt_input TYPE ty_dt_tab OCCURS 0,
wa_input TYPE ty_dt_tab.
DATA: l_filename TYPE string.
DATA: l_auth_filename LIKE authb-filename,
e_flg_open_error TYPE boolean,
e_os_message TYPE c,
success(1),
lv_string TYPE string.
FIELD-SYMBOLS : type ty_dt_tab.
CONSTANTS:
sabc_act_read(4) VALUE 'READ',
sabc_act_write(5) VALUE 'WRITE'.
CONSTANTS: lc_fileformat_ascii LIKE rlgrap-filetype
VALUE 'ASC'.
CONSTANTS: lc_fileformat_binary LIKE rlgrap-filetype
VALUE 'BIN'.
PARAMETERS : frnt_end TYPE rcgfiletr-ftfront, "Front end path
appl_ser TYPE rcgfiletr-ftappl, "Application server path
overwrit TYPE c AS CHECKBOX. "Overwrite
START-OF-SELECTION.
* Function body -------------------------------------------------------
* init
e_flg_open_error = ' '.
CLEAR: e_os_message,success.
l_filename = frnt_end.
* check the authority to write the file to the application server
l_auth_filename = appl_ser.
CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
EXPORTING
* PROGRAM =
activity = sabc_act_write
filename = l_auth_filename
EXCEPTIONS
no_authority = 1
activity_unknown = 2
OTHERS = 3.
IF NOT sy-subrc IS INITIAL.
CASE sy-subrc.
WHEN 1.
STOP.
** no auhtority
* RAISE ap_no_authority.
WHEN OTHERS.
STOP.
* RAISE ap_file_open_error.
ENDCASE.
ENDIF.
TRY.
* open the file on the application server for reading to check if the
* file exists on the application server
OPEN DATASET appl_ser FOR INPUT MESSAGE e_os_message
IN TEXT MODE ENCODING NON-UNICODE.
IF sy-subrc IS INITIAL.
IF overwrit = ' '.
CLOSE DATASET appl_ser.
STOP.
ENDIF.
ENDIF.
CLOSE DATASET appl_ser.
* catch exceptions
CATCH cx_root.
BREAK-POINT.
EXIT.
ENDTRY.
* open dataset for writing
OPEN DATASET appl_ser FOR OUTPUT MESSAGE e_os_message
IN TEXT MODE ENCODING NON-UNICODE.
IF NOT sy-subrc IS INITIAL.
* e_flg_open_error = true.
STOP.
ELSE.
lv_string = frnt_end.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = lv_string
filetype = 'ASC'
has_field_separator = ' '
* IMPORTING
* filelength =
* header =
CHANGING
data_tab = lt_input
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.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
stop.
ENDIF.
* write the file to the application server
LOOP AT lt_input ASSIGNING .
TRANSFER TO appl_ser.
* transfer has no exceptions
* if not sy-subrc is initial.
* raise ap_file_write_error.
* endif.
success = 'X'.
ENDLOOP.
* close the dataset
CLOSE DATASET appl_ser.
ENDIF.
IF success = 'X'.
CLEAR success .
MESSAGE 'successfully uploaded.' TYPE 'S'.
ENDIF.
Thanks & Regards,