08-03-2020 3:24 AM
Hi all,
I am using somewhat the following ABAP codes to transfer excel file to AL11 in binary format.
My Basis will be the one doing some basis script to move the file from AL11 to a SFTP server.
Problem: when i open file in SFTP server it is coming like unreadable format.
Anyone have any ideas?
REPORT zdemo_excel25.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_excel_writer TYPE REF TO zif_excel_writer,
lo_worksheet TYPE REF TO zcl_excel_worksheet,
lo_exception TYPE REF TO cx_root.
DATA: lv_file TYPE xstring.
CONSTANTS: lv_file_name TYPE string VALUE '25_HelloWorld.xlsx'.
DATA: lv_default_file_name TYPE string.
DATA: lv_error TYPE string.
CALL FUNCTION 'FILE_GET_NAME_USING_PATH'
EXPORTING
logical_path = 'LOCAL_TEMPORARY_FILES' " Logical path'
file_name = lv_file_name " File name
IMPORTING
file_name_with_path = lv_default_file_name. " File name with path
" Creates active sheet
CREATE OBJECT lo_excel.
" Get active sheet
lo_worksheet = lo_excel->get_active_worksheet( ).
lo_worksheet->set_title( ip_title = 'Sheet1' ).
lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Hello world' ).
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
lv_file = lo_excel_writer->write_file( lo_excel ).
TRY.
OPEN DATASET lv_default_file_name FOR OUTPUT IN BINARY MODE.
TRANSFER lv_file TO lv_default_file_name.
CLOSE DATASET lv_default_file_name.
CATCH cx_root INTO lo_exception.
lv_error = lo_exception->get_text( ).
MESSAGE lv_error TYPE 'I'.
ENDTRY.
08-03-2020 5:04 AM
Can you clarify, whether the file in AL11 is definitly readable by an application that supports xlsx? e.g download the file from AL11 with Trx. CG3Y (or if in CRM system, use FM ARCHIVFILE_SERVER_TO_CLIENT).
08-03-2020 5:37 AM
HI Michael,
From AL11 it is readable with CG3Y. It is not readable when it moved over to SFTP.
08-03-2020 7:33 AM
If it's a SFTP question, then provide the SFTP details. Please replace the ABAP Development tag with one corresponding more to SFTP.
08-03-2020 7:35 AM
The following code of the OP works well, the whole XSTRING variable is written to the file, no need to loop:
DATA lv_file TYPE xstring.
...
lv_file = lo_excel_writer->write_file( lo_excel ).
...
OPEN DATASET lv_default_file_name FOR OUTPUT IN BINARY MODE.
TRANSFER lv_file TO lv_default_file_name.
CLOSE DATASET lv_default_file_name.
08-03-2020 8:10 AM
TRY.
OPEN DATASET lv_default_file_name FOR OUTPUT IN BINARY MODE.
* TRANSFER lv_file TO lv_default_file_name.
TRANSFER lv_default_file_name to lv_file.
CLOSE DATASET lv_default_file_name.
CATCH cx_root INTO lo_exception.
lv_error = lo_exception->get_text( ).
MESSAGE lv_error TYPE 'I'.
ENDTRY.
Transfer is no in the wrong direction ?
08-03-2020 8:17 AM
Hello Frederic,
In one of the comments under the question there is information that file is readable from AL11 but not from SFTP. This would imply that the file is correctly written to the application server but incorrectly transferred via SFTP.
08-03-2020 9:34 AM
siongchao.ng,
This issue happens with SFTP due to absence of sufficient privileges/permission for the file that is being placed, you should proceed further with below steps in sequence:
1) With the help of your BASIS team create an external command name with Linux as the operating system.
2) The operating system command name must be CHMOD.
3) Apply the required parameter values (777 is given for Full access on the file), you can discuss with the BASIS team more on this.
3) once the external command is created, you have to integrate the command with your file path.
4) In your ABAP program once the the file path is opened using OPEN DATA SET, call the function module SXPG_COMMAND_EXECUTE to apply the required permission which is created via the external command. Below screen shot for reference. Here Command name will hold the command created in SM69, additional parameters will hold the path that has been opened in the previous step.
5) In the above call if the status is not equal to E then the permissions are applied successfully.
6) After the file is places with these permissions, you can ask the basis team to move the files from Al11 to SFTP and try accessing the files from SFTP.
7) This would help you in accessing the files.
Regards!
08-03-2020 11:11 AM
Based on lack of details in the question, I wonder how you can deduce that it's "due to absence of sufficient privileges/permission"...
08-03-2020 12:08 PM
That's Simple sandra.rossi :), i came across similar issue during an file interface using SFTP.
Regards!