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

How to upload file from different location into SAP?

15 REPLIES 15

Mohamed_Mukhtar
Active Contributor
0 Kudos

hi ,

From Presentation Server , we can use FM GUI_UPLOAD.

From Application Server , use

1.Open dataset

2.Read dataset

3.close dataset

regards.

Former Member
0 Kudos

Hi,

Use LSMW for uploading data from legacy system to SAP.

Check the following link for steps to create LSMW

http://www.sap-img.com/general/lsmw-steps-for-data-migration.htm

Regards,

Ramya

Former Member
0 Kudos

Hi,

File from Presentaion Server

call method cl_gui_frontend_services=>gui_upload

exporting

filename = l_fname

filetype = 'ASC'

  • has_field_separator = 'X'

header_length = 0

importing

filelength = filelength

changing

data_tab = lt_input[]

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

others = 17.

File from Application Server

Data : p_file type rlgrap-filename.

open dataset p_file for input in text mode encoding default.

if sy-subrc = 0.

do.

read dataset p_file into ls_input-wa_string.

if sy-subrc eq 0.

append ls_input to lt_input.

else.

exit.

endif.

enddo.

endif.

close dataset p_file.

Former Member
0 Kudos

Hi

Presentation server:
pARAMETERS:
p_file LIKE dxfields-longpath OBLIGATORY.

DATA:
w_downld TYPE string,                  " File name
w_file LIKE dxfields-location,         " File location


CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
    IMPORTING
      o_path          = p_file
      o_location_flag = w_file
    EXCEPTIONS
      rfc_error       = 1
      error_with_gui  = 2.
  IF sy-subrc <> 0.
    MESSAGE text-001 TYPE 'E'.
  ENDIF.                               " IF sy-subrc

 CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                = w_downld
        filetype                = 'ASC'
        has_field_separator     = 'X'
        read_by_line            = 'X'
      TABLES
        data_tab                = t_tab
      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.





application server:


OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

READ DATASET p_file INTO fs_tab.

CLOSE DATASET p_file.

Regards,

sravanthi

Former Member
0 Kudos

HI use open data set for opening file which is in application server.

use Read dataset for reading file from application server

close dataset for closing file which was opened.

If the file is in dev server use' gui_upload'.

0 Kudos

I know these options but my query is that file is neither in my system nor in application server. let us say, it is present in client system. How to take path of that file?

0 Kudos

hi Manish .

[Go through this link|]

Regards..

0 Kudos

Hi Manish,

Check this thread to fetch file from another R3 system:

Regards,

Chandra Sekhar

0 Kudos

>

> I know these options but my query is that file is neither in my system nor in application server. let us say, it is present in client system. How to take path of that file?

is there SAP GUI installed on that system(it is present in client system.)?

I assume yes.

Than can you not write upload program which have selection screen and taking a file path from selection screen and upload the file to application server.

than youo can easily read this file via your whole SAP system.

Amit.

Edited by: Amit Gujargoud on Sep 9, 2008 7:30 AM

Former Member
0 Kudos

You can upload one file from presentation server to an internal table in SAP by using the function module

GUI_UPLOAD.

use f4_filename to select the file from presentation server which will be uploaded.

After taking the filename in a variable call FM GUI_UPLOAD.

here is the code.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = V_FILE

FILETYPE = 'txt' " the file type of the file which will be uploaded.

HAS_FIELD_SEPARATOR = 'X ' " Give 'X 'as parameter

TABLES

DATA_TAB = i_table " the internal table name where the data will be uploaded.

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

OTHERS = 17.

IF SY-SUBRC <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO*

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.*

ENDIF.

__________________________________________________

upload data from Application Server

Otherwise if you want to upload data in SAP from Application server then you can use three functinal module in sequence.

They are

OPEN DATASET dsn FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc <> 0.

EXIT.

ENDIF.

It is used for opening the dataset which is nothing but a sequential file in application server.

READ DATASET dsn INTO rec.

WHILE sy-subrc <> 0.

WRITE / rec. READ DATASET dsn INTO rec.

ENDWHILE.

This module is used for reading the sequential file content from the application server.

CLOSE DATASET dsn.

This module is used for closing the sequential dataset in application server which is open.

you can use one function module F4_DXFILENAME to select the file in application server. after selecting the file name you can pass the file name in the three functional modules as dsn.

So dsn will contain the full path in application server .

So you don't need to remember the name of the file and path of the file dsn application server.So in run time you can choose a file from application server to upload the file name in SAp.

0 Kudos

File is neither in application server nor in presentation server.

0 Kudos

>

> File is neither in application server nor in presentation server.

where is the file than?

0 Kudos

File is in shared location of client, I have to take that file and run transaction code FLB2.

Steps are:

1) first take that file

2) Put either in application/presentation server

3) execute FLB2

Former Member
0 Kudos

Hi,

you said that the file may be in another client system.But as far my knowledge the client system may be another SAP or non-SAP system, but it should be uploaded to the XI server or an application server before uploading it to another R3 system.

The file from client system will be uploaded in an XI server with IDOC technique or any other and then you will fetch the file from XI server.

Actually for this a broad knowledge of XI is needed.

thanks.

Former Member
0 Kudos

no solutions