Application Development and Automation 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: 
Read only

open dataset issue

Former Member
0 Likes
1,757

Hi all,

I am downloading a file through 'Open dataset' and 'Close dataset'. to the path: 'H:\test\filename.csv'. This is the local drive.

I have to use dataset commands as I cannot download by 'GUI_DOWNLOAD' function in background job. But the file is not downloaded by dataset commands.

Can you please advise where the issue could be. When I follow through in debug, there is no error displayed. Or is there any other way to download file in background. Thanks.

Regards,

FS

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,681

Hi,

Open Dataset command is used to access files on the

application server not the local desktop.

If you are running a job in backgroup it runs on the SAP server

not the local frontend.

Regards

Sudhir Atluru

14 REPLIES 14
Read only

Former Member
0 Likes
1,682

Hi,

Open Dataset command is used to access files on the

application server not the local desktop.

If you are running a job in backgroup it runs on the SAP server

not the local frontend.

Regards

Sudhir Atluru

Read only

Former Member
0 Likes
1,681

thanks for you r reply. Actually I also tried to send it to a server directory. But still it did not produce any file. Can you please send me some sample code. Thanks.

Regards,

FS

Read only

0 Likes
1,681

Hi FS,

Just search the forum there are lots of sample code on OPEN DATASET. Even if you just do F1 on this keyword you will get the info.

Regards,

Atish

Read only

Former Member
0 Likes
1,681

Actually I am using file type .cma (comma delimited). Is this the issue that file is not getting downloaded by dataset commands. If yes, then what type should I use. Thanks.

Regards,

FS

Read only

0 Likes
1,681

Hi,

No it can't be the issue. There must be something wrong in your coding. paste your whole code.

Regards,

Atish

Read only

Former Member
0 Likes
1,681
  • p_file = G:\ar_file.cma

open dataset p_file FOR OUTPUT IN binary mode message mess.

  • also tried above command with "IN TEXT MODE *ENCODING DEFAULT MESSAGE mess"

IF sy-subrc = 0.

loop at pt_export into gs_export.

TRANSFER gs_export TO p_file.

endloop.

endif.

close dataset p_file.

write: / 'Downloaded File', P_FILE(50),

(5) num_lines, 'lines'.

Regards,

FS

Read only

0 Likes
1,681

FS,

You want to read the data from file .So use like below.

DATA FNAME(60) VALUE 'G:\ar_file.cma'.

DATA: TEXT2(500).

OPEN DATASET FNAME FOR INPUT IN TEXT MODE.

DO.

READ DATASET FNAME INTO TEXT2 .

WRITE: / TEXT2.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET FNAME.

Read only

Former Member
0 Likes
1,681

Actually I want to download file to the server and I pasted my code in the above section. Please advise.

Regard,

FS

Read only

0 Likes
1,681

FS,

This is the simple code for EX;

DATA FNAME(60) VALUE 'myfile'.

TYPES: BEGIN OF LINE,

COL1 TYPE I,

COL2 TYPE I,

END OF LINE.

TYPES ITAB TYPE LINE OCCURS 10.

DATA: LIN TYPE LINE,

TAB TYPE ITAB.

DO 5 TIMES.

LIN-COL1 = SY-INDEX.

LIN-COL2 = SY-INDEX ** 2.

APPEND LIN TO TAB.

ENDDO.

OPEN DATASET FNAME FOR OUTPUT.

LOOP AT TAB INTO LIN.

TRANSFER LIN TO FNAME.

ENDLOOP.

CLOSE DATASET FNAME.

OPEN DATASET FNAME FOR INPUT.

DO.

READ DATASET FNAME INTO LIN.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

WRITE: / LIN-COL1, LIN-COL2.

ENDDO.

CLOSE DATASET FNAME.

Read only

0 Likes
1,681

Hi FS,

p_file = G:\ar_file.cma This can't be the file from application server. Just check with the basis for application server folder.

application server file starts like /<foldername>/file name.

Regards,

Atish

Read only

Former Member
0 Likes
1,681

looks like I am using the server directory path incorrectly:

Can you please correct it:

previously I used : G:\ar_file.txt

I tried :

/serv01/folder1/folder2/ar_file.txt

(serv01 = servername for G:\ drive)

But this is still not working. Can you please show me the correct path to use for the dataset command. Thanks.

Regard,

FS

Read only

0 Likes
1,681

FS,

Goto Tcode AL11 ther you can find all directories in Appl;ication server.But one thing you should have authoriztion to write file in directory.For that contact basis person.otherwise take any directory try to write file there.Do like trail and error method.

Ex; filepath :

/data/sapdata/reg_billing_prod_mda/ test.txt

Read only

0 Likes
1,681

FS,

Following is the program to find the directories available in Application Server.

REPORT ZFINDDIRECTORIES .

parameters: p_path like DXFIELDS-LONGPATH.

data: lv_opath like dxfields-longpath.

data: ev_server_name like btctgtsrvr-srvname,

server_name like msxxlist-name.

call 'C_SAPGPARAM'

id 'NAME' field 'rdisp/myname'

id 'VALUE' field ev_server_name.

if sy-subrc <> 0.

clear ev_server_name.

endif.

call function 'F4_DXFILENAME_TOPRECURSION'

exporting

i_location_flag = 'X'

i_server = server_name

i_path = p_path

importing

o_path = lv_opath .

write:/ lv_opath.

K.Kiran.

Read only

Former Member
0 Likes
1,681

Thanks guys,

I can send the files correctly to the application server. Can I use dataset command to Download and Upload from other servers within the network. Or is there any other command or function for that. Thanks.

Regards,

Faiq