Skip to Content
-2

Excel file open in SFTP server unreadable

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.
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Aug 03, 2020 at 08:34 AM

    Siong Chao 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!


    scn.png (13.2 kB)
    Add a comment
    10|10000 characters needed characters exceeded