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: 

How to read file from remote file server

Former Member
0 Kudos

Hello Expert,

I need to read file from remote file server. The server name looks like below:

Server name: \\Server0123\logs$

UserName: Testuser

Password: Init123

I want to read file \\Server0123\logs$\Share\log.txt fromthe SAP system. Which function module I can use, or what procedure shall I follow?

I can access the file by setting "My Computer->Map Network Drive". But I don't know how to access it from SAP program. Can any expert give some idea?

Thanks & Best Regards,

Yong bo.

10 REPLIES 10

koolspy_ultimate
Active Contributor
0 Kudos

Hi,

The below link might be helpful to you.

Click Here

Regards,

Madhumahesh.

0 Kudos

HI Wu,

          As you are able to accesss the file from my computer, i believe you can try as below

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.

     CALL FUNCTION 'F4_FILENAME'

       exporting

            field_name = 'P_FILE'

       importing

            file_name  = p_file.

p_file is the name of the parameter on selection screen.

Regards,

Umar Syed.

0 Kudos

if CALL FUNCTION 'F4_FILENAME' does'nt work by itself, then try to create an R/3 Connection between your server and SAP using SM59.

Regards,

Umar Syed.

vinoth_aruldass
Contributor
0 Kudos

hi,

OPEN DATASET FNAME FOR INPUT IN BINARY MODE.

DO.

  READ DATASET FNAME INTO TEXT2 LENGTH LENG.

  WRITE: / SY-SUBRC, TEXT2, LENG.

  IF SY-SUBRC

<> 0.

    EXIT.

  ENDIF.

ENDDO.

CLOSE DATASET FNAME.

Fname should be your \\Server0123\logs$\Share\log.txt.

it works

regards,

Vinoth Aruldass

Venkat_Sesha
Employee
Employee
0 Kudos

Do one thing. This is the simplest way when it is a Text File.

Open Command Prompt CMD from Windows Start Run

Come to C:\> Drive. by using Cd.. cd..

Now enter the following command.

ftp Sanddrd.ga.xxx.com.          

Note : Sanddrd.ga.xxx.com this is the App server name from SAP logon Pad. If you want to upload data to DEV System. in the SAP Logon Pad right Click the system DEV and see the Appl server name.

Now give sapuser name and Password

Note : Some systems may have different user name and password here(may not be SAP username).

then use the below command

Put filename.txt

this will go the AL11 in SAP. to check in which folder it got placed.

use PWD in the command prompt.

Former Member
0 Kudos

Hi,

you need to create physical file path for reading the data from remote system.

Former Member
0 Kudos

Hello,

You can read a file from SAP either from Presentation server or Application server.

Create a program with PARAMETER : p_file LIKE rlgrap-filename

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'
   EXPORTING
     program_name        = syst-cprog
     dynpro_number       = syst-dynnr
*   FIELD_NAME          = ' '
   IMPORTING
     file_name           = p_file.


and use function module gui_upload to upload the data in SAP.


CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename              = p_file

          filetype              = 'ASC'
         TABLES
          data_tab              = lt_header
        EXCEPTIONS
          error_message         = 98
          OTHERS                = 99.

You can also use tcode CG3Z to upload data on application server path and then using open dataset and read dataset you can read file.

Regards,

Deepti

ravi_lanjewar
Contributor
0 Kudos

Hi,

First you transfer the file using FTP on applicaton server and then read the file using the open data set.

http://wiki.sdn.sap.com/wiki/display/Snippets/Executes+a+command+on+an+FTP+server.

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

Kind Regards

Ravishankar

Former Member
0 Kudos

Thanks all for your information.

Yes, I can create a shortcut to the remote file server in my local computer and read the file via "F4_FILENAME" in the frontend. But It's impossible to access the shortcut in the batch job.

So to access the remote file, it seems there are below two options:

1. Access the remote file via FTP

2. set up SAP Directory in AL11 to the remote file, then use open data set in the program.

Option 1 is impossible becase the remote file server is not possible to access with FTP.

So we have to turn to option 2. Can any expert tell me whether option 2 is possible or not? If yes, Can anyone tell me how to set up the connection to remote file server step by step? Thanks.

0 Kudos

Hi,

     if you want to access the file in background mode also, check the below link.

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/9831750a-0801-0010-1d9e-f8c64efb2...

it is basically explains saving a file form a background job, which means accessing the remote server, once you are able to access the server you can do both saving the file and reading it.

Hope it helps,

Regards,

Umar Syed.