class ZCL_GUI_BACKEND_SERVICES
definition public
final
create public .
public section.
importing
value(FILE) type STRING
returning
value(RESULT) type ABAP_BOOL
exceptions
WRONG_PARAMETER
NO_AUTHORITY
SOURCE_NOT_EXISTS .
importing
value(FILE) type STRING
returning
value(FILE_SIZE) type INT4
exceptions
WRONG_PARAMETER
NO_AUTHORITY .
importing
value(I_FILE) type STRING
value(ACTIVITY) type CHAR20
returning
value(RC) type SYST-SUBRC
exceptions
NO_PERMISSION .
returning
value(SEP) type CHAR01 .
importing
!FILE type STRING
exporting
!FILESIZE type I
returning
value(DATA) type SOLIX_TAB
exceptions
NO_PERMISSION
OPEN_FAILED
READ_ERROR
PATH_ERROR .
importing
!FILE type STRING
!I_FILE_OVERWRITE type ABAP_BOOL default ' '
!I_FILE_SIZE type I default 0
exceptions
NO_PERMISSION
OPEN_FAILED
AP_FILE_EXISTS
CLOSE_FAILED
WRITE_FAILED .
importing
!FILE type STRING
exceptions
NO_PERMISSION
FAILURE .
importing
value(I_PATH) type STRING
!I_MASK type STRING default '*'
returning
value(DIRLIST) type ZCSTT_EPSFILI
exceptions
WRONG_PARAMETER
INVALID_EPS_SUBDIR
SAPGPARAM_FAILED
BUILD_DIRECTORY_FAILED
NO_AUTHORIZATION
READ_DIRECTORY_FAILED
TOO_MANY_READ_ERRORS
EMPTY_DIRECTORY_LIST .
importing
!FILE type STRING
exporting
!PATH type STRING
!FILE_WITH_EXT type STRING .
importing
value(I_FILE) type STRING optional
value(I_LANGU) type SY-LANGU default SY-LANGU
exporting
!E_ERROR_TAB type BAPIRET2_TAB
changing
!I_TEXTDATA_TAB type STANDARD TABLE
exceptions
NO_PERMISSION
OPEN_FAILED .
importing
value(I_FILE) type STRING optional
value(I_FILE_OVERWRITE) type XFELD optional
value(I_LANGU) type SY-LANGU default SY-LANGU
exporting
!E_ERROR_TAB type BAPIRET2_TAB
changing
!I_TEXTDATA_TAB type STANDARD TABLE
exceptions
NO_PERMISSION
OPEN_FAILED
AP_FILE_EXISTS .
importing
value(I_ALIAS) type C
returning
value(O_PATH) type STRING
exceptions
NOT_FOUND .
importing
!I_SOURCE type STRING
!I_DEST type STRING
exceptions
SOURCE_NOT_EXISTS
NO_PERMISSION
OPEN_FAILED
AP_FILE_EXISTS
CLOSE_FAILED
WRITE_FAILED
READ_ERROR
PATH_ERROR .
importing
!I_SOURCE type STRING
!I_DEST type STRING
exceptions
SOURCE_NOT_EXISTS
NO_PERMISSION
OPEN_FAILED
AP_FILE_EXISTS
CLOSE_FAILED
WRITE_FAILED
READ_ERROR
PATH_ERROR .
importing
!I_FILE type STRING
value(I_SEP) type CHAR01 optional
changing
!I_TEXTDATA_TAB type STANDARD TABLE
exceptions
ERROR_OPENING_FILE .
exceptions
NOT_ALLOWED
NO_OS_COMMANDS_ALLOWED .
protected section.
private section.
constants LG_MAX_LEN
type I
value 255 ##NO_TEXT
.
CLASS ZCL_GUI_BACKEND_SERVICES
IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>CHECK_AUTHORITY
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_FILE TYPE STRING
* | [--->] ACTIVITY TYPE CHAR20
* | [<-()] RC TYPE SYST-SUBRC
* | [EXC!] NO_PERMISSION
* +--------------------------------------------------------------------------------------</SIGNATURE>
* CONSTANTS:
* SABC_ACT_READ(4) VALUE 'READ',
* SABC_ACT_WRITE(5) VALUE 'WRITE',
* SABC_ACT_READ_WITH_FILTER(16) VALUE 'READ_WITH_FILTER',
* SABC_ACT_WRITE_WITH_FILTER(17) VALUE 'WRITE_WITH_FILTER',
* SABC_ACT_DELETE(6) VALUE 'DELETE',
* SABC_ACT_INIT(4) VALUE 'INIT',
* SABC_ACT_ACCEPT(6) VALUE 'ACCEPT',
* SABC_ACT_CALL(4) VALUE 'CALL'.
data l_file
type AUTHB
-FILENAME
. l_file = i_file.
* check the authority for file
CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
EXPORTING
* PROGRAM =
activity = activity
filename = l_file
EXCEPTIONS
no_authority = 1
activity_unknown = 2
OTHERS = 3.
rc = sy-subrc.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>CHECK_AUTHORITY_SYSCMD
* +-------------------------------------------------------------------------------------------------+
* | [EXC!] NOT_ALLOWED
* | [EXC!] NO_OS_COMMANDS_ALLOWED
* +--------------------------------------------------------------------------------------</SIGNATURE>
method CHECK_AUTHORITY_SYSCMD
. *data: TCODE type TSTC-TCODE,
* USER(6),
* CMD(254), "Max length = 254 Bytes
* CMD_NR TYPE I,
* CMD_LINE TYPE I,
*
* RESULT(255) OCCURS 100 WITH HEADER LINE, "No max length
*
* BEGIN OF LIST OCCURS 100,
* NR TYPE I,
* LINE(255),
* END OF LIST,
* HOME(60),
* opsysgroup like opsystem-filesys,
* CD_PATH(60),
* lCD_PATH(60).
* Authority check
CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
EXPORTING
TCODE = 'SM69'
EXCEPTIONS
OK = 0
NOT_OK = 2
OTHERS = 3.
AUTHRC = SY-SUBRC.
CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
EXPORTING
TCODE = 'SM49'
EXCEPTIONS
OK = 0
NOT_OK = 2
OTHERS = 3.
AUTHRC = SY-SUBRC.
ID 'ACTVT' FIELD '01'.
AUTHRC = SY-SUBRC.
ID 'COMMAND' FIELD 'RSBDCOS0'
ID 'OPSYSTEM' FIELD SY-OPSYS
ID 'HOST' FIELD SY-HOST.
AUTHRC = SY-SUBRC.
* Are OS Commands allowed?
CALL 'C_SAPGPARAM' ID 'NAME' FIELD 'rdisp/call_system' "#ec notext
ID 'VALUE' FIELD rdisp_call_system.
IF rdisp_call_system
NE '1'. raise NO_OS_COMMANDS_ALLOWED
.
*data RESULT(255) OCCURS 100 WITH HEADER LINE. "No max length
*
*"data RESULT type TABLE OF char255 WITH HEADER LINE.
*
*data CMD(254). "Max length = 254 Bytes
*
*cmd = 'ls'.
*
*
*
*"data result type table of char255.
** Execute command
* REFRESH RESULT.
* CALL 'SYSTEM' ID 'COMMAND' FIELD CMD
* ID 'TAB' FIELD RESULT-*SYS*.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>DIRECTORY_GET_ALIAS_PATH
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_ALIAS TYPE C
* | [<-()] O_PATH TYPE STRING
* | [EXC!] NOT_FOUND
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD DIRECTORY_GET_ALIAS_PATH
.
DATA dir_trans
TYPE text255
. DATA l_alias
TYPE text255
.
* Get Path on server from alias
l_alias = i_alias.
CALL FUNCTION 'RSPO_R_SAPGPARAM'
EXPORTING
name = l_alias
IMPORTING
value = dir_trans
EXCEPTIONS
error = 1
OTHERS = 2.
SELECT SINGLE dirname
FROM user_dir
INTO dir_trans
WHERE aliass
EQ l_alias
.
o_path = dir_trans.
o_path = dir_trans.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>DIRECTORY_LIST
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_PATH TYPE STRING
* | [--->] I_MASK TYPE STRING (default ='*')
* | [<-()] DIRLIST TYPE ZCSTT_EPSFILI
* | [EXC!] WRONG_PARAMETER
* | [EXC!] INVALID_EPS_SUBDIR
* | [EXC!] SAPGPARAM_FAILED
* | [EXC!] BUILD_DIRECTORY_FAILED
* | [EXC!] NO_AUTHORIZATION
* | [EXC!] READ_DIRECTORY_FAILED
* | [EXC!] TOO_MANY_READ_ERRORS
* | [EXC!] EMPTY_DIRECTORY_LIST
* +--------------------------------------------------------------------------------------</SIGNATURE>
DATA l_dir
TYPE epsf
-epsdirnam
. DATA l_filemask
TYPE epsf
-epsfilnam
.
* check parameter, wild characters not allowed
IF i_path
IS INITIAL OR i_path
CA '*<>|"'.
l_dir = i_path.
l_filemask = i_mask.
CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
EXPORTING
dir_name = l_dir
file_mask = l_filemask
dir_list = dirlist
EXCEPTIONS
invalid_eps_subdir = 1
sapgparam_failed = 2
build_directory_failed = 3
no_authorization = 4
read_directory_failed = 5
too_many_read_errors = 6
empty_directory_list = 7
OTHERS = 8.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_APPEND_TEXT
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_FILE TYPE STRING(optional)
* | [--->] I_LANGU TYPE SY-LANGU (default =SY-LANGU)
* | [<---] E_ERROR_TAB TYPE BAPIRET2_TAB
* | [<-->] I_TEXTDATA_TAB TYPE STANDARD TABLE
* | [EXC!] NO_PERMISSION
* | [EXC!] OPEN_FAILED
* +--------------------------------------------------------------------------------------</SIGNATURE>
* local data -----------------------------------------------------------
DATA l_filename
TYPE authb
-filename
. DATA ls_ret
TYPE bapiret2
.
* function body --------------------------------------------------------
* init
l_filename = i_file.
* check the authority for file
CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
EXPORTING
activity = sabc_act_write
* Authority Check allows right now only 60 Character
filename = l_filename(60)
EXCEPTIONS
no_authority = 1
activity_unknown = 2
OTHERS = 3.
SET LOCALE LANGUAGE i_langu.
* open dataset for writing
OPEN DATASET i_file WITH WINDOWS LINEFEED FOR APPENDING IN TEXT MODE
ENCODING NON-UNICODE.
IF NOT sy
-subrc
IS INITIAL.
LOOP AT i_textdata_tab
ASSIGNING <t
>.
* write data in file
* conversion erortable does not exist
CATCH cx_sy_codepage_converter_init cx_sy_conversion_codepage
.
* MESSAGE S003(EHSBM_LS).
* Fehler bei der Konvertierung der sprachabhƤngigen Daten
ls_ret-type = 'W'.
ls_ret-id = 'EHSBM_LS'.
ls_ret-number = 003.
* MESSAGE S137(C$) with I_TEXTDATA_TAB.
ls_ret-type = 'W'.
ls_ret-id = 'C$'.
ls_ret-number = 137.
ls_ret-message_v1 = <t>.
* close the dataset
CLOSE DATASET i_file.
SET LOCALE LANGUAGE space.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_COPY
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_SOURCE TYPE STRING
* | [--->] I_DEST TYPE STRING
* | [EXC!] SOURCE_NOT_EXISTS
* | [EXC!] NO_PERMISSION
* | [EXC!] OPEN_FAILED
* | [EXC!] AP_FILE_EXISTS
* | [EXC!] CLOSE_FAILED
* | [EXC!] WRITE_FAILED
* | [EXC!] READ_ERROR
* | [EXC!] PATH_ERROR
* +--------------------------------------------------------------------------------------</SIGNATURE>
DATA t_data
TYPE solix_tab
.
l_exist = zcl_gui_backend_services=>file_exist( i_source ).
CALL METHOD zcl_gui_backend_services=>file_read_bin
EXPORTING
file = i_source
IMPORTING
filesize = l_filesize
RECEIVING
EXCEPTIONS
no_permission = 1
open_failed = 2
read_error = 3
path_error = 4
OTHERS = 5.
CALL METHOD zcl_gui_backend_services=>file_write_bin
EXPORTING
file = i_dest
i_file_overwrite = 'X'
i_file_size = l_filesize
EXCEPTIONS
no_permission = 1
open_failed = 2
ap_file_exists = 3
close_failed = 4
write_failed = 5
OTHERS = 6.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_DELETE
* +-------------------------------------------------------------------------------------------------+
* | [--->] FILE TYPE STRING
* | [EXC!] NO_PERMISSION
* | [EXC!] FAILURE
* +--------------------------------------------------------------------------------------</SIGNATURE>
"DATA i_file TYPE rcgiedial-iefile.
rc = zcl_gui_backend_services=>check_authority( i_file = file activity = 'DELETE' ).
"i_file = file.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_EXIST
* +-------------------------------------------------------------------------------------------------+
* | [--->] FILE TYPE STRING
* | [<-()] RESULT TYPE ABAP_BOOL
* | [EXC!] WRONG_PARAMETER
* | [EXC!] NO_AUTHORITY
* | [EXC!] SOURCE_NOT_EXISTS
* +--------------------------------------------------------------------------------------</SIGNATURE>
DATA l_file
TYPE rlgrap
-filename
. DATA l_dir
TYPE epsf
-epsdirnam
. DATA l_filemask
TYPE epsf
-epsfilnam
. DATA:it_dirlist
TYPE STANDARD TABLE OF epsfili
. DATA long_filename
TYPE dbmsgora
-filename
. DATA pure_filename
TYPE sdbah
-actid
. DATA pure_extension
TYPE sdbad
-funct
. DATA full_file
TYPE dbmsgora
-filename
.
* check parameter, wild characters not allowed
IF file
IS INITIAL OR file
CA '*<>|"'.
rc = zcl_gui_backend_services=>check_authority( i_file = file activity = 'READ' ).
* long_filename = file.
* CALL FUNCTION 'SPLIT_FILENAME'
* EXPORTING
* long_filename = long_filename
* IMPORTING
* pure_filename = pure_filename
* pure_extension = pure_extension.
*
* CONCATENATE pure_filename '.' pure_extension INTO full_file.
*
* l_dir = file.
* REPLACE ALL OCCURRENCES OF full_file IN l_dir WITH ''.
* l_filemask = full_file.
DATA l_dir_s
TYPE string. DATA l_filemask_s
TYPE string.
CALL METHOD zcl_gui_backend_services=>split_filename
EXPORTING
file = file
IMPORTING
path = l_dir_s
file_with_ext = l_filemask_s.
l_dir = l_dir_s.
l_filemask = l_filemask_s.
CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
EXPORTING
dir_name = l_dir
file_mask = l_filemask
dir_list = it_dirlist[]
EXCEPTIONS
invalid_eps_subdir = 1
sapgparam_failed = 2
build_directory_failed = 3
no_authorization = 4
read_directory_failed = 5
too_many_read_errors = 6
empty_directory_list = 7
OTHERS = 8.
result = abap_false.
IF it_dirlist
[] IS INITIAL. result = abap_false.
READ TABLE it_dirlist TRANSPORTING NO FIELDS WITH KEY name = l_filemask.
result = abap_true.
result = abap_false.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_GET_SIZE
* +-------------------------------------------------------------------------------------------------+
* | [--->] FILE TYPE STRING
* | [<-()] FILE_SIZE TYPE INT4
* | [EXC!] WRONG_PARAMETER
* | [EXC!] NO_AUTHORITY
* +--------------------------------------------------------------------------------------</SIGNATURE>
DATA l_file
TYPE rlgrap
-filename
. DATA l_dir
TYPE epsf
-epsdirnam
. DATA l_filemask
TYPE epsf
-epsfilnam
. DATA:it_dirlist
TYPE STANDARD TABLE OF epsfili
. DATA:ls_dirlist
TYPE epsfili
. DATA long_filename
TYPE dbmsgora
-filename
. DATA pure_filename
TYPE sdbah
-actid
. DATA pure_extension
TYPE sdbad
-funct
. DATA full_file
TYPE dbmsgora
-filename
.
* check parameter, wild characters not allowed
IF file
IS INITIAL OR file
CA '*<>|"'.
rc = zcl_gui_backend_services=>check_authority( i_file = file activity = 'READ' ).
DATA l_dir_s
TYPE string. DATA l_filemask_s
TYPE string.
CALL METHOD zcl_gui_backend_services=>split_filename
EXPORTING
file = file
IMPORTING
path = l_dir_s
file_with_ext = l_filemask_s.
l_dir = l_dir_s.
l_filemask = l_filemask_s.
CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
EXPORTING
dir_name = l_dir
file_mask = l_filemask
dir_list = it_dirlist[]
EXCEPTIONS
invalid_eps_subdir = 1
sapgparam_failed = 2
build_directory_failed = 3
no_authorization = 4
read_directory_failed = 5
too_many_read_errors = 6
empty_directory_list = 7
OTHERS = 8.
READ TABLE it_dirlist INTO ls_dirlist WITH KEY name = l_filemask.
file_size = ls_dirlist-size.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_MOVE
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_SOURCE TYPE STRING
* | [--->] I_DEST TYPE STRING
* | [EXC!] SOURCE_NOT_EXISTS
* | [EXC!] NO_PERMISSION
* | [EXC!] OPEN_FAILED
* | [EXC!] AP_FILE_EXISTS
* | [EXC!] CLOSE_FAILED
* | [EXC!] WRITE_FAILED
* | [EXC!] READ_ERROR
* | [EXC!] PATH_ERROR
* +--------------------------------------------------------------------------------------</SIGNATURE>
DATA t_data
TYPE solix_tab
.
l_exist = zcl_gui_backend_services=>file_exist( i_source ).
CALL METHOD zcl_gui_backend_services=>file_read_bin
EXPORTING
file = i_source
IMPORTING
filesize = l_filesize
RECEIVING
EXCEPTIONS
no_permission = 1
open_failed = 2
read_error = 3
path_error = 4
OTHERS = 5.
CALL METHOD zcl_gui_backend_services=>file_write_bin
EXPORTING
file = i_dest
i_file_overwrite = 'X'
i_file_size = l_filesize
EXCEPTIONS
no_permission = 1
open_failed = 2
ap_file_exists = 3
close_failed = 4
write_failed = 5
OTHERS = 6.
CALL METHOD zcl_gui_backend_services=>file_delete
EXPORTING
file = i_source
EXCEPTIONS
no_permission = 1
OTHERS = 2.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_READ_BIN
* +-------------------------------------------------------------------------------------------------+
* | [--->] FILE TYPE STRING
* | [<---] FILESIZE TYPE I
* | [<-()] DATA TYPE SOLIX_TAB
* | [EXC!] NO_PERMISSION
* | [EXC!] OPEN_FAILED
* | [EXC!] READ_ERROR
* | [EXC!] PATH_ERROR
* +--------------------------------------------------------------------------------------</SIGNATURE>
* lokal data -----------------------------------------------------------
DATA l_len
LIKE sy
-tabix
. DATA l_subrc
LIKE sy
-subrc
. DATA i_file
TYPE char200
. DATA e_file_size
TYPE char200
.
rc = zcl_gui_backend_services=>check_authority( i_file = file activity = 'READ' ).
** read the raw-file from the appl.server
CATCH SYSTEM
-EXCEPTIONS open_dataset_no_authority
= 1 dataset_too_many_files = 2
OTHERS = 4.
i_file = file.
OPEN DATASET i_file FOR INPUT IN BINARY MODE.
l_subrc = sy-subrc.
l_subrc <> 0.
CATCH SYSTEM
-EXCEPTIONS dataset_read_error
= 11 OTHERS = 12.
READ DATASET i_file INTO ls_data LENGTH l_len.
e_file_size = e_file_size + l_len.
e_file_size = e_file_size + l_len.
DESCRIBE TABLE data LINES e_lines
. filesize = e_file_size.
CATCH SYSTEM
-EXCEPTIONS dataset_cant_close
= 1 OTHERS = 4.
CLOSE DATASET i_file.
IF NOT sy
-subrc
IS INITIAL. * but there wasn't any error at the reading of the data
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_READ_TEXT
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_FILE TYPE STRING
* | [--->] I_SEP TYPE CHAR01(optional)
* | [<-->] I_TEXTDATA_TAB TYPE STANDARD TABLE
* | [EXC!] ERROR_OPENING_FILE
* +--------------------------------------------------------------------------------------</SIGNATURE>
DATA t_split
TYPE tab512
.
DATA lt TYPE TABLE OF tab512
.
<ls> TYPE tab512,
<dyn_rec> TYPE any,
<dyn_field> TYPE any.
*------------------------------------------------------------------------------*
* read the file from the application server
*------------------------------------------------------------------------------*
OPEN DATASET i_file WITH WINDOWS LINEFEED FOR INPUT IN TEXT MODE ENCODING DEFAULT.
RAISE error_opening_file
. READ DATASET i_file INTO l_line.
IF NOT l_line
IS INITIAL. APPEND l_line
TO i_textdata_tab
.
SPLIT l_line
AT i_sep
INTO TABLE lt. APPEND INITIAL LINE TO i_textdata_tab
. READ TABLE i_textdata_tab ASSIGNING <dyn_rec> INDEX sy-tabix.
l_idx = sy-tabix.
ASSIGN COMPONENT l_idx
OF STRUCTURE <dyn_rec
> TO <dyn_field
>. <dyn_field> = ls-wa.
CLOSE DATASET i_file.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_WRITE_BIN
* +-------------------------------------------------------------------------------------------------+
* | [--->] DATA TYPE SOLIX_TAB
* | [--->] FILE TYPE STRING
* | [--->] I_FILE_OVERWRITE TYPE ABAP_BOOL (default =' ')
* | [--->] I_FILE_SIZE TYPE I (default =0)
* | [EXC!] NO_PERMISSION
* | [EXC!] OPEN_FAILED
* | [EXC!] AP_FILE_EXISTS
* | [EXC!] CLOSE_FAILED
* | [EXC!] WRITE_FAILED
* +--------------------------------------------------------------------------------------</SIGNATURE>
DATA l_all_lines_len
TYPE i
. DATA l_subrc
LIKE sy
-subrc
.
DATA e_file_size
TYPE char200
. DATA i_file
TYPE char200
.
rc = zcl_gui_backend_services=>check_authority( i_file = file activity = 'WRITE' ).
rc = zcl_gui_backend_services=>check_authority( i_file = file activity = 'DELETE' ).
i_file = file.
* check if file exists if we arn't allowed to overwrite file
IF i_file_overwrite
= ' '. " apap_FALSE'.
CATCH SYSTEM
-EXCEPTIONS open_dataset_no_authority
= 1 dataset_too_many_files = 2
OTHERS = 4.
OPEN DATASET i_file FOR INPUT IN BINARY MODE.
l_subrc = sy-subrc.
* nothing
CATCH SYSTEM
-EXCEPTIONS OTHERS = 4. CLOSE DATASET i_file.
CATCH SYSTEM
-EXCEPTIONS OTHERS = 4. CLOSE DATASET i_file.
* open dataset for writing
OPEN DATASET i_file FOR OUTPUT IN BINARY MODE.
IF NOT sy
-subrc
IS INITIAL.
l_len = lg_max_len.
* last line is shorter perhaps
l_all_lines_len = lg_max_len * ( i_lines - 1 ).
l_diff_len = i_file_size - l_all_lines_len.
l_len = l_diff_len.
* write data in file
CATCH SYSTEM
-EXCEPTIONS dataset_write_error
= 1 OTHERS = 4.
TRANSFER ls_data
TO i_file
LENGTH l_len
.
IF NOT sy
-subrc
IS INITIAL.
* close the dataset
CATCH SYSTEM
-EXCEPTIONS dataset_cant_close
= 1 OTHERS = 4.
CLOSE DATASET i_file.
IF NOT sy
-subrc
IS INITIAL.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>FILE_WRITE_TEXT
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_FILE TYPE STRING(optional)
* | [--->] I_FILE_OVERWRITE TYPE XFELD(optional)
* | [--->] I_LANGU TYPE SY-LANGU (default =SY-LANGU)
* | [<---] E_ERROR_TAB TYPE BAPIRET2_TAB
* | [<-->] I_TEXTDATA_TAB TYPE STANDARD TABLE
* | [EXC!] NO_PERMISSION
* | [EXC!] OPEN_FAILED
* | [EXC!] AP_FILE_EXISTS
* +--------------------------------------------------------------------------------------</SIGNATURE>
* local data -----------------------------------------------------------
DATA l_filename
TYPE authb
-filename
. DATA ls_ret
TYPE bapiret2
.
* function body --------------------------------------------------------
* init
l_filename = i_file.
* check the authority for file
CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
EXPORTING
activity = sabc_act_write
* Authority Check allows right now only 60 Character
filename = l_filename(60)
EXCEPTIONS
no_authority = 1
activity_unknown = 2
OTHERS = 3.
* check if file exists if we arn't allowed to overwrite file
IF i_file_overwrite
IS INITIAL. OPEN DATASET i_file FOR INPUT IN TEXT MODE
ENCODING NON-UNICODE.
CLOSE DATASET i_file.
CLOSE DATASET i_file.
SET LOCALE LANGUAGE i_langu.
* open dataset for writing
OPEN DATASET i_file WITH WINDOWS LINEFEED FOR OUTPUT IN TEXT MODE
ENCODING NON-UNICODE.
IF NOT sy
-subrc
IS INITIAL.
LOOP AT i_textdata_tab
ASSIGNING <t
>.
* write data in file
* conversion erortable does not exist
CATCH cx_sy_codepage_converter_init cx_sy_conversion_codepage
.
* MESSAGE S003(EHSBM_LS).
* Fehler bei der Konvertierung der sprachabhƤngigen Daten
ls_ret-type = 'W'.
ls_ret-id = 'EHSBM_LS'.
ls_ret-number = 003.
* MESSAGE S137(C$) with I_TEXTDATA_TAB.
ls_ret-type = 'W'.
ls_ret-id = 'C$'.
ls_ret-number = 137.
ls_ret-message_v1 = <t>.
* close the dataset
CLOSE DATASET i_file.
SET LOCALE LANGUAGE space.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>GET_FILE_SEPARATOR
* +-------------------------------------------------------------------------------------------------+
* | [<-()] SEP TYPE CHAR01
* +--------------------------------------------------------------------------------------</SIGNATURE>
*
** Ermittle Trenner
* IF sy-opsys CS 'WINDOWS'.
** Windows NT/2000
* sep = '\'.
* ELSE.
** UNIX
* sep = '/'.
* ENDIF.
data l_VALUE
TYPE TEXT255
. CALL FUNCTION 'RSPO_R_SAPGPARAM'
EXPORTING
name = 'DIR_SEP'
IMPORTING
VALUE = l_VALUE
EXCEPTIONS
ERROR = 1
OTHERS = 2
.
* Implement suitable error handling here
sep = l_value.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_GUI_BACKEND_SERVICES=>SPLIT_FILENAME
* +-------------------------------------------------------------------------------------------------+
* | [--->] FILE TYPE STRING
* | [<---] PATH TYPE STRING
* | [<---] FILE_WITH_EXT TYPE STRING
* +--------------------------------------------------------------------------------------</SIGNATURE>
DATA long_filename
TYPE dbmsgora
-filename
. DATA pure_filename
TYPE sdbah
-actid
. DATA pure_extension
TYPE sdbad
-funct
. DATA full_file
TYPE dbmsgora
-filename
.
long_filename = file.
path = file.
CALL FUNCTION 'SPLIT_FILENAME'
EXPORTING
long_filename = long_filename
IMPORTING
pure_filename = pure_filename
pure_extension = pure_extension.
CONCATENATE pure_filename
'.' pure_extension
INTO full_file
.
file_with_ext = full_file.
REPLACE ALL OCCURRENCES
OF full_file
IN path
WITH ''.