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

Saving file locally using open dataset

Former Member
0 Likes
8,342

I am trying to create a text file which has material, material group, material type. I want to save this file locally on my desktop, but I am not able to find this file after running my program.

This is only something like my fifth ABAP program, so I am still a beginer. I have included code to display the content of the file, and it seems to be alright. But I would like this file to be saved to my desktop PC.

Heres my code:

REPORT YABHINAV8.

tables : mara.

data matdim type string value 'c:\matdim.txt'.

data mdim type string.

data comma type string value ', '.

open dataset matdim for output in text mode encoding default.

select * from mara order by mtart matkl matnr.

concatenate mara-matnr comma mara-matkl comma mara-mtart into mdim.

transfer mdim to matdim.

endselect.

close dataset matdim.

open dataset matdim for input in text mode encoding default.

do.

read dataset matdim into mdim.

if sy-subrc = 0.

write / mdim.

else.

exit.

endif.

enddo.

close dataset matdim.

End of code.

Can anyone help me?

Thanks,

Al Lal

www.olap.wetpaint.com

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,967

Hi,

DATA : FNAME(60) VALUE 'your application server file name',

ep_bytes TYPE i.

DATA: BEGIN OF ITAB OCCURS 0,

REC(500),

END OF ITAB.

OPEN DATASET FNAME FOR INPUT IN TEXT MODE ENCODING

DEFAULT.

DO.

READ DATASET FNAME INTO ITAB-REC.

APPEND ITAB.

CLEAR ITAB.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET FNAME.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'c:\matdim.txt'

filetype = 'ASC'

write_field_separator = ','

IMPORTING

filelength = ep_bytes

TABLES

data_tab = ITAB

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22.

I am trying to create a text file which has material, material group, material type. I want to save this file locally on my desktop, but I am not able to find this file after running my program.

This is only something like my fifth ABAP program, so I am still a beginer. I have included code to display the content of the file, and it seems to be alright. But I would like this file to be saved to my desktop PC.

Heres my code:

REPORT YABHINAV8.

tables : mara.

data matdim type string value 'c:\matdim.txt'.

data mdim type string.

data comma type string value ', '.

open dataset matdim for output in text mode encoding default.

select * from mara order by mtart matkl matnr.

concatenate mara-matnr comma mara-matkl comma mara-mtart into mdim.

transfer mdim to matdim.

endselect.

close dataset matdim.

open dataset matdim for input in text mode encoding default.

do.

read dataset matdim into mdim.

if sy-subrc = 0.

write / mdim.

else.

exit.

endif.

enddo.

close dataset matdim.

End of code.

Can anyone help me?

Thanks,

Al Lal

www.olap.wetpaint.com

6 REPLIES 6
Read only

Former Member
0 Likes
3,967

If u want to download data on desktop then open dataset will not work.

Use GUI_DOWNLOAD function module

Read only

Former Member
0 Likes
3,967

Hi,

Open Dataset is used to load the file in the Application Server.

If u want to load the file on ur desktop u have to use the Function modules

GUI_UPLOAD and GUI_DOWNLOAD.

Thanks & Regards,

Roja Velagapudi.

Read only

Former Member
0 Likes
3,967

using open data set we can upload into application server. If you wish to store it locally use the below FM.

CONCATENATE fpath '.xls' " destination path

INTO ofname.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = ofname

filetype = 'ASC'

write_field_separator = 'X'

TABLES

data_tab = it_output

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Thanks,

Imran

Read only

Former Member
0 Likes
3,968

Hi,

DATA : FNAME(60) VALUE 'your application server file name',

ep_bytes TYPE i.

DATA: BEGIN OF ITAB OCCURS 0,

REC(500),

END OF ITAB.

OPEN DATASET FNAME FOR INPUT IN TEXT MODE ENCODING

DEFAULT.

DO.

READ DATASET FNAME INTO ITAB-REC.

APPEND ITAB.

CLEAR ITAB.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET FNAME.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'c:\matdim.txt'

filetype = 'ASC'

write_field_separator = ','

IMPORTING

filelength = ep_bytes

TABLES

data_tab = ITAB

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22.

Read only

0 Likes
3,967

Muralikrishna,

I had to understand your code because it was not working. I made some corrections to your code and it worked.

These are some of the corrections I made:

if sy-subrc = 0.

skip.

elseif.

exit.

endif.

Imagine, me a beginer making corrections to your code.

Thanks a lot for your help - I have assigned you full points.

Al Lal

Read only

Former Member
0 Likes
3,967

Hi you can refer to the sample code.

REPORT ZTXT_DOWNLOAD.

tables : mara.

data matdim type string value 'd:\matdim.txt'.

data: it_dtab type standard table of mara,

wa_dtab type mara.

select * from mara into table it_dtab order by mtart matkl matnr.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = matdim

  • FILETYPE = 'ASC'

  • APPEND = ' '

  • WRITE_FIELD_SEPARATOR = ' '

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE

  • SHOW_TRANSFER_STATUS = ABAP_TRUE

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = it_dtab

  • FIELDNAMES =

  • EXCEPTIONS

  • FILE_WRITE_ERROR = 1

  • NO_BATCH = 2

  • GUI_REFUSE_FILETRANSFER = 3

  • INVALID_TYPE = 4

  • NO_AUTHORITY = 5

  • UNKNOWN_ERROR = 6

  • HEADER_NOT_ALLOWED = 7

  • SEPARATOR_NOT_ALLOWED = 8

  • FILESIZE_NOT_ALLOWED = 9

  • HEADER_TOO_LONG = 10

  • DP_ERROR_CREATE = 11

  • DP_ERROR_SEND = 12

  • DP_ERROR_WRITE = 13

  • UNKNOWN_DP_ERROR = 14

  • ACCESS_DENIED = 15

  • DP_OUT_OF_MEMORY = 16

  • DISK_FULL = 17

  • DP_TIMEOUT = 18

  • FILE_NOT_FOUND = 19

  • DATAPROVIDER_EXCEPTION = 20

  • CONTROL_FLUSH_ERROR = 21

  • OTHERS = 22

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

Award points if useful..