Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Excel file open in SFTP server unreadable

siongchao_ng
Contributor
0 Kudos

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.
9 REPLIES 9

michael_piesche
Active Contributor
0 Kudos

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).

  • If it is already unreadable in AL11, all your information about SFTP is unneccessary, and you need to evaluate your ZCL_EXCEL* classes.
  • If it is readable in AL11, than you need to address the issue to your basis team and they need to evaluate the way they copy the file from SAP application server to SFTP server.

siongchao_ng
Contributor
0 Kudos

HI Michael,

From AL11 it is readable with CG3Y. It is not readable when it moved over to SFTP.

Sandra_Rossi
Active Contributor

If it's a SFTP question, then provide the SFTP details. Please replace the ABAP Development tag with one corresponding more to SFTP.

Sandra_Rossi
Active Contributor

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.

FredericGirod
Active Contributor
0 Kudos
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 ?

mateuszadamus
Active Contributor

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.


Kind regards,
Mateusz

former_member1716
Active Contributor
0 Kudos

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!

0 Kudos

Based on lack of details in the question, I wonder how you can deduce that it's "due to absence of sufficient privileges/permission"...

0 Kudos

That's Simple sandra.rossi :), i came across similar issue during an file interface using SFTP.

Regards!