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: 

File Upload

Former Member
0 Kudos

Hi Experts,

I have a BAPI and use GUI_UPLOAD FM to upload a file.But when I call this BAPI from a JAVA system, I facing a error because of GUI UPLOAD.So could you please suggest me ways other than GUI UPLOAD to upload a file(The uploading File can be of any type like ppt,doc,etc...).

Regards,

Arun.

6 REPLIES 6

Former Member
0 Kudos

Hi Arun,

GUI_UPLOAD FM can only be used in online mode. In background mode this FM fail because of the system tries to access to the local system (PC) and it is not accesible.

You can read the file using the following sentences:

1.- open dataset (filename)

2.-

do.

read dataset (filename) into (structure).

if sy-subrc = 0.

append (structure) to (table)

else.

exit. "End of file.

3.- close dataset (filename).

The file must be in the aplication server.

Regards,

Pepe

0 Kudos

Hi,

Thanks for your quick reply.I am not using this function module GUI UPLOAD in a Background environment.I using this FM GUI UPLOAD in a BAPI and this BAPI is called from a external system.Because of non availability of SAP GUI in the external system we are facing a problem when we use GUI UPLOAD.So could you please suggest me ways other that GUI UPLOAD to upload a file.Thanks.

Regards,

Arun

0 Kudos

Try to use the sentences OPEN DATASET / READ DATASET / CLOSE DATASET instead of GUI_UPLOAD.

The result is the same, an internal table with the file content.

open dataset '/dir/aa.txt' in text mode encoding default. "Or binary mode

if sy-subrc = 0.

do.

read dataset '/dir/aa.txt' into w_structure.

if sy-subrc = 0.

append w_structure to w_table.

else.

exit.

endif.

enddo.

close dataset '/dir/aa.txt' .

endif.

In table w_table you have the file content, as with GUI_UPLOAD FM.

Differences between both, GUI_UPLOAD read file for local server (PC) and DATASET read file from aplication server (SAP SERVER). If you call the FM from another system, the program can't acces to the local PC.

Former Member
0 Kudos

Hi ,

Use class CL_GUI_FRONTEND_SERVICES in that GUI_UPLOAD Method is there

regards,

Raghava Channooru.

Former Member
0 Kudos

Hi Arun,

Please use FM 'WS_UPLOAD' .

eg: PARAMETERS: F_FILE LIKE RLGRAP-FILENAME.

PERFORM UPLOAD_FILE.

CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
      FILENAME                = F_FILE
      FILETYPE                = 'DAT'
    TABLES
      DATA_TAB                = INT_MAT
    EXCEPTIONS
      FILE_OPEN_ERROR         = 1
      FILE_WRITE_ERROR        = 2
      INVALID_FILESIZE        = 3
      INVALID_TYPE            = 4
      NO_BATCH                = 5
      UNKNOWN_ERROR           = 6
      INVALID_TABLE_WIDTH     = 7
      GUI_REFUSE_FILETRANSFER = 8
      CUSTOMER_ERROR          = 9
      OTHERS                  = 10.

  IF SY-SUBRC = 0.
    FORMAT COLOR COL_GROUP.
    WRITE:/ 'Data Upload Successfully from your local harddisk'.
    SKIP.
  ENDIF.

Regards

Karthik

Subhankar
Active Contributor
0 Kudos

Hi,

The uploading File can be of any type like ppt,doc,etc...).

GUI_UPLOAD can not upload .doc or .PPT files. For these file you can use OLE You can save the file as .txt and try it.

BR

Subhankar

Edited by: Subhankar Garani on Apr 12, 2010 2:39 PM