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: 

DOWNLOAD A FILE FROM A BATCH JOB

Former Member
0 Kudos

Hi

I need to download a file to a network drive, but the program will run in Batch Job

How can I download the file since it is running in a batch job?

Thanks

8 REPLIES 8

Former Member
0 Kudos

You cannot.

Your options are 1) download it to the application server and then have it ftp-ed to the network drive or 2) have the network people mount the network location on the application server and then you can download it straight to the location as if it is an application server location.

rodrigo_paisante3
Active Contributor
0 Kudos

Hi,

Try to use the OPEN DATASET. You need to know the exact directory and the file to do this.

--- from the help ---

READ DATASET

Reads a record from the sequential file specified in dsn (a field or a literal) and stores it in the field f (usually a field string).

Binary mode (addition IN BINARY MODE in the OPEN DATASET statement:

Read from file in length of field f.

Text mode (addition IN TEXT MODE in the OPEN DATASET statement):

Read a line.

DATA:

dsn(20) VALUE '/usr/test.dat',

rec(80).

OPEN DATASET dsn.

IF sy-subrc = 0.

DO.

READ DATASET dsn INTO rec.

IF sy-subrc <> 0.

EXIT.

ELSE.

WRITE / rec.

ENDIF.

ENDDO.

ENDIF.

CLOSE DATASET dsn.

0 Kudos

My path is
Guadalajara01\Public\test.txt

But the file is not created there

Do u have any idea?

0 Kudos

I created a program here to run in background. It reads a file in the server, does the process and creates a new file, in the server too.

put your code here and we will help you better

Regards

0 Kudos

I don't want to read a file, I want to create a file in the network drive

DATA:

dsn(100) VALUE

'
Guadalajara01\Public\test.txt',

rec(80) value 'test'.

OPEN DATASET dsn for output in binary mode.

IF sy-subrc = 0.

DO 1 times.

TRANSFER rec to dsn.

EXIT.

ENDDO.

ENDIF.

CLOSE DATASET dsn.

0 Kudos

As I said, those are your two options unless of course your SAP application server is on NT as opposed to unix.

0 Kudos

Oh.. sorry!

But you can create the file with the TRANSFER command

OPEN DATASET dsn IN TEXT MODE FOR OUTPUT.

LOOP AT it_data INTO wa_data.

TRANSFER wa_data TO dsn.

ENDLOOP.

CLOSE DATASET dsn.

You will output line by line to the file.

This process transfer a record from internal table to the file.

Try it

regards

Sorry again.

I didnt see your source code with atention.

But i create a program that creates a file in my network drive. This code works fine.

DATA:

dsn(50) VALUE 'c:\test.txt',

rec(255).

DATA: ti_tmp(255) OCCURS 0,

wa_tmp(255).

OPEN DATASET dsn in text mode encoding utf-8 for input .

IF sy-subrc = 0.

DO.

READ DATASET dsn INTO rec.

IF sy-subrc <> 0.

EXIT.

ELSE.

WRITE / rec.

wa_tmp = rec.

APPEND wa_tmp TO ti_tmp.

ENDIF.

ENDDO.

ENDIF.

CLOSE DATASET dsn.

dsn = 'z:\test2.txt'.

break t001.

OPEN DATASET dsn IN TEXT MODE encoding utf-8 FOR OUTPUT.

LOOP AT ti_tmp INTO wa_tmp.

TRANSFER wa_tmp TO dsn.

ENDLOOP.

CLOSE DATASET dsn.

Message was edited by:

Rodrigo Paisante

Former Member
0 Kudos

Hi jorge,

1. normally basis team will not allow any direct connections.

2. so probably
concept may not work.

3. For such things, its always better to use FTP concept in abap.

There are be some Function modules which do the FTP and create the file.

4. In that case also, the other machine should have FTP service running,

and we should know that username and password for that machine user.

regards,

amit m.