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: 

FTP_R3_TO_SERVER : Uploading binary file (.XLS)

sreehari_vpillai
Active Contributor
0 Kudos

Hi Experts,

Im using FTP_R3_TO_SERVER FM to upload an Excel file from the user desktop.

CALL METHOD cl_gui_frontend_services=>gui_upload
       EXPORTING
         filename                = g_file
       IMPORTING
         filelength               g_len
       CHANGING
          data_tab                g_data
       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 <> 0.
       message 'Error occured while uploading file' type 'S'.
       leave LIST-PROCESSING.
     ENDIF.


call function 'FTP_R3_TO_SERVER'
     exporting
       handle         = w_hdl
       fname          = wrk_file          "file path of destination system
       character_mode = ' '
       BLOB_LENGTH = BLOB_LEN
     tables
       blob =
g_data
     exceptions
       tcpip_error    = 1
       command_error  = 2
       data_error     = 3
       others         = 4.

How to find the BLOB_LEN ? Now the file is getting uploaded.. but only partial data is there.

Please help

5 REPLIES 5

former_member209120
Active Contributor
0 Kudos

Hi Sreehari,

Why you need to use FTP_R3_TO_SERVER to upload excel file?

You can use TEXT_CONVERT_XLS_TO_SAP or
alsm_excel_to_internal_table to upload excel file.

0 Kudos

Hi ramesh,

I m using FTP_R3_TO_SERVER because i am uploading file to FTP not to application server.

Using the same, i am able to upload a text file (In character mode). But when use binary file , it is not getting uploaded properly. File is getting created, but with junk data.

After all you can not use front end (OLE) function modules all the time. Bcoz, the file mat be .XLSX also.. letys think generic

Former Member
0 Kudos

Hi,

Use the following Code for Upload.

PARAMETERS : P_INFILE LIKE RLGRAP-FILENAME OBLIGATORY.

DATA: FNAME TYPE STRING.

DATA: GINT_EXCELFILE TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.

DATA:BEGIN OF GINT_RECORD OCCURS 0,

* data element: MATNR

        MATNR(018),

* data element: WERKS_D

        WERKS(004),

* data element: PLANTEXT

        KTEXT(040),

  END OF GINT_RECORD.

FIELD-SYMBOLS : <L_FS> .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_INFILE.

  PERFORM OPEN_FILE.

START-OF-SELECTION.

  DATA : LV_FNAME LIKE RLGRAP-FILENAME.

  LV_FNAME = FNAME.

  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

    EXPORTING

      FILENAME                = LV_FNAME

      I_BEGIN_COL             = 1

      I_BEGIN_ROW             = 1

      I_END_COL               = 100

      I_END_ROW               = 65536

    TABLES

      INTERN                  = GINT_EXCELFILE

    EXCEPTIONS

      INCONSISTENT_PARAMETERS = 1

      UPLOAD_OLE              = 2

      OTHERS                  = 3.

  BREAK-POINT.

  REFRESH GINT_RECORD.

  CLEAR GINT_RECORD.

  DATA : WRK_ROW TYPE I.

  CLEAR: WRK_ROW.

  DATA : WRK_TABIX LIKE SY-TABIX.

  WRK_ROW = 1.

  READ TABLE GINT_EXCELFILE WITH KEY ROW = WRK_ROW.

  IF SY-SUBRC = 0.

    WRK_TABIX = SY-TABIX.

    LOOP AT GINT_EXCELFILE FROM WRK_TABIX.

      ASSIGN COMPONENT GINT_EXCELFILE-COL

       OF STRUCTURE GINT_RECORD TO <L_FS>.

      MOVE GINT_EXCELFILE-VALUE TO <L_FS> .

      AT END OF ROW .

        APPEND GINT_RECORD.

        CLEAR GINT_RECORD.

      ENDAT.

    ENDLOOP .

  ENDIF.

break-point.

*&---------------------------------------------------------------------*

*&      Form  OPEN_FILE

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM OPEN_FILE .

* FUNCTION TO SELECT THE FILE FOR UPLOAD

  CALL FUNCTION 'WS_FILENAME_GET'

    EXPORTING

      DEF_FILENAME     = SPACE

      DEF_PATH         = P_INFILE

      MASK             = ',*.* ,*.*.'

      MODE             = 'O'

      TITLE            = TEXT-002

    IMPORTING

      FILENAME         = FNAME

    EXCEPTIONS

      INV_WINSYS       = 04

      NO_BATCH         = 08

      SELECTION_CANCEL = 12

      SELECTION_ERROR  = 16.

  P_INFILE = FNAME.

ENDFORM. " OPEN_FILE

Creat Excel with three fields(MATNR,WERKS,MAKTX) to upload.

Thanks,

Maruthamuthu Subramani

0 Kudos

Hi Maruthamuthu,

Thanks for the program. See , in his case you are converting the file to internal table. And then uploading it. What i am expecting is, to uplaod a binary file (of any format) to ftp location.

After uploading to ftp, ill read it with java (using jxl). SO, i need ito be as inary. can u suggest me how i can upload a binary file? (eg : .exe file). Lets make it more generic then

0 Kudos

Hi,

Kindly check Demo Program RSFTP007.

Check Below Link,

http://scn.sap.com/thread/3403084

Thanks,

Maruthamuthu Subramani