За изучением чужого кода наткнулся на полезный Include для работы с файлами и директориями. Имя ему - FP_UTILITIES. Для тех, у кого нет под рукой системы, чтобы ознакомиться с его содержимым, выкладываю ниже код
INCLUDE FP_UTILITIES.
*&---------------------------------------------------------------------*
*& Include FP_UTILITIES
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form value_help_for_destination
*&---------------------------------------------------------------------*
* Get an RFC destination from a dialog box to select from.
*----------------------------------------------------------------------*
* <--P_DEST destination
*----------------------------------------------------------------------*
FORM value_help_for_destination USING p_fieldname TYPE dynfnam.
"#EC CALLED
TYPES: BEGIN OF ty_disp,
rfcdest TYPE rfcdest,
ssl TYPE rfcsnc,
hostname TYPE icmhostnam,
port TYPE rfcsysid,
END OF ty_disp.
DATA: lt_dest TYPE STANDARD TABLE OF rfcdes WITH KEY rfcdest,
l_rfcdes TYPE rfcdes,
l_display TYPE rfcdisplay,
l_disp TYPE ty_disp.
STATICS l_dests TYPE STANDARD TABLE OF ty_disp WITH KEY rfcdest.
* Read all suitable RFC destinations from the database.
IF l_dests IS INITIAL.
SELECT rfcdest rfctype rfcoptions FROM rfcdes INTO TABLE lt_dest
WHERE rfctype = 'G' AND rfcoptions LIKE '%AdobeDocument%'
ORDER BY PRIMARY KEY. "#EC CI_GENBUFF
LOOP AT lt_dest INTO l_rfcdes.
CALL FUNCTION 'RFCDES2RFCDISPLAY'
EXPORTING
import_rfcdes = l_rfcdes
IMPORTING
export_rfcdisplay = l_display.
MOVE: l_display-rfcdest TO l_disp-rfcdest,
l_display-rfcsnc TO l_disp-ssl,
l_display-rfchost TO l_disp-hostname,
l_display-rfcsysid TO l_disp-port.
INSERT l_disp INTO TABLE l_dests.
ENDLOOP.
ENDIF.
* Show the value-help popup.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'RFCDEST'
dynpprog = sy-cprog
dynpnr = sy-dynnr
dynprofield = p_fieldname
value_org = 'S'
TABLES
value_tab = l_dests.
ENDFORM. "value_help_for_destination
*&---------------------------------------------------------------------*
*& Form value_help_for_file
*&---------------------------------------------------------------------*
* Get a local file name from a dialog box to select from.
*----------------------------------------------------------------------*
* -->P_EXTENSION extension
* <--P_FILENAME selected file name
*----------------------------------------------------------------------*
FORM value_help_for_file USING p_extension TYPE string
CHANGING p_filename TYPE localfile.
"#EC CALLED
DATA: l_filetable TYPE filetable,
l_status TYPE i.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
default_extension = p_extension
file_filter = cl_gui_frontend_services=>filetype_all
CHANGING
file_table = l_filetable
rc = l_status
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc IS INITIAL AND l_status > 0.
READ TABLE l_filetable INTO p_filename INDEX 1.
ENDIF.
ENDFORM. "value_help_for_file
*&---------------------------------------------------------------------*
*& Form value_help_for_output_file
*&---------------------------------------------------------------------*
* Get a local file name where to save data
* from a dialog box to select from.
*----------------------------------------------------------------------*
* -->P_EXTENSION extension
* <--P_FILENAME selected file name
*----------------------------------------------------------------------*
FORM value_help_for_output_file USING p_extension TYPE string
CHANGING p_filename TYPE localfile.
"#EC CALLED
DATA: l_filename TYPE string,
l_filename_dummy TYPE string.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
default_extension = p_extension
file_filter = cl_gui_frontend_services=>filetype_all
CHANGING
filename = l_filename_dummy
path = l_filename_dummy
fullpath = l_filename
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc IS INITIAL.
MOVE l_filename TO p_filename.
ENDIF.
ENDFORM. "value_help_for_output_file
*&--------------------------------------------------------------------*
*& Form load_file
*&--------------------------------------------------------------------*
* Load a file from the frontend.
*---------------------------------------------------------------------*
* -->P_FILENAME file name
* <--P_CONTENT content of the file
*---------------------------------------------------------------------*
FORM load_file USING p_filename TYPE localfile
CHANGING p_content TYPE xstring. "#EC CALLED
DATA: l_filename TYPE string,
l_rawtab TYPE STANDARD TABLE OF raw255,
l_len TYPE i.
MOVE p_filename TO l_filename.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = l_filename
filetype = 'BIN'
IMPORTING
filelength = l_len
CHANGING
data_tab = l_rawtab
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 IS NOT INITIAL.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = l_len
IMPORTING
buffer = p_content
TABLES
binary_tab = l_rawtab
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc IS NOT INITIAL.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. "load_file
*&---------------------------------------------------------------------*
*& Form download_file
*&---------------------------------------------------------------------*
* Download a file to the frontend.
*----------------------------------------------------------------------*
* -->P_DATA content to be downloaded
* -->P_FILE file name
*----------------------------------------------------------------------*
FORM download_file USING p_data TYPE xstring
p_file TYPE localfile. "#EC CALLED
DATA: l_len TYPE i,
l_tab TYPE tsfixml,
l_filename TYPE string.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = p_data
IMPORTING
output_length = l_len
TABLES
binary_tab = l_tab.
MOVE p_file TO l_filename.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = l_len
filename = l_filename
filetype = 'BIN'
CHANGING
data_tab = l_tab
EXCEPTIONS
OTHERS = 1.
IF sy-subrc IS INITIAL.
MESSAGE ID 'VER_MESSAGES' TYPE 'S' NUMBER '082' WITH p_file.
ELSE.
MESSAGE ID 'VER_MESSAGES' TYPE 'E' NUMBER '083'.
ENDIF.
ENDFORM. "download_file
*&---------------------------------------------------------------------*
*& Form error
*&---------------------------------------------------------------------*
* Show the error message.
*----------------------------------------------------------------------*
* -->P_EXCEPTION exception-class instance
*----------------------------------------------------------------------*
FORM error USING p_exception TYPE REF TO cx_fp_runtime. "#EC CALLED
DATA: l_type TYPE string,
l_errmsg TYPE string.
CASE cl_abap_classdescr=>get_class_name( p_exception ).
WHEN '\CLASS=CX_FP_RUNTIME_INTERNAL'. l_type = 'INTERNAL ERROR'.
WHEN '\CLASS=CX_FP_RUNTIME_SYSTEM'. l_type = 'SYSTEM ERROR'.
WHEN '\CLASS=CX_FP_RUNTIME_USAGE'. l_type = 'USAGE ERROR'.
ENDCASE.
l_errmsg = p_exception->get_short( ).
CONCATENATE l_type ':' l_errmsg INTO l_errmsg SEPARATED BY space.
MESSAGE l_errmsg TYPE 'E'.
ENDFORM. "error
Комментариев нет:
Отправить комментарий