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

DAT (spreadsheet) formatted file saved to app. server?

Former Member
0 Likes
977

Hello,

I would like to save a file in DAT (spreadsheet) format to an app. server. Essentially I want the functionality offered by System>List>Save-->Local file; however I want to save it to the app. server and not the pc.

The function module LIST_CONVERT_TO_DAT essentially is the one behind the menu option I mentioned above, but it is hard-wired to always save the file to the pc. Anyone know of a similar function (in fact, with the exact same functionality), but instead can save the file to the app. server?

Cheers,

Lee

1 ACCEPTED SOLUTION
Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
880

Hi Lee

You can use "OPEN DATASET" and related statements to load a file to the application server. Function modules "C13Z_FILE_UPLOAD_BINARY" and "C13Z_FILE_DOWNLOAD_BINARY" may also be utilized. Here is a procedure to save a file, read from presentation, into the app. server and read it from the app. server...

e.g.

<b>*-- Reading file from the presentation layer into an

*--internal table</b>

DATA gt_data TYPE TABLE OF text1000 WITH HEADER LINE .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = p_fname

filetype = 'BIN'

TABLES

data_tab = gt_data

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

OTHERS = 6 .

<b>*--Saving file to the application server</b>

DATA gv_dsn(30) TYPE c .

gv_dsn = '/usr/test.xls',

OPEN DATASET gv_dsn FOR OUTPUT .

LOOP AT gt_data .

TRANSFER gt_data TO gv_dsn .

ENDLOOP .

CLOSE DATASET gv_dsn .

<b>*-- Reading a file from application server into an

*--internal table</b>

DATA gv_filedsn(30) TYPE c .

gv_filedsn = '/usr/test.xls',

OPEN DATASET gv_filedsn .

DO .

READ DATASET gv_filedsn INTO gt_data2 .

IF sy-subrc NE 0 .

EXIT .

ENDIF .

APPEND gt_data2 .

ENDDO .

<b>*-- Downloading the file to the presentation layer from

*--the internal table</b>

DATA gv_down_fname LIKE rlgrap-filename .

gv_down_fname = 'D:\temp\after_down.doc' .

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = gv_down_fname

filetype = 'BIN'

TABLES

data_tab = gt_data2

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

OTHERS = 5

*--Serdar

Hello,

I would like to save a file in DAT (spreadsheet) format to an app. server. Essentially I want the functionality offered by System>List>Save-->Local file; however I want to save it to the app. server and not the pc.

The function module LIST_CONVERT_TO_DAT essentially is the one behind the menu option I mentioned above, but it is hard-wired to always save the file to the pc. Anyone know of a similar function (in fact, with the exact same functionality), but instead can save the file to the app. server?

Cheers,

Lee

3 REPLIES 3
Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
881

Hi Lee

You can use "OPEN DATASET" and related statements to load a file to the application server. Function modules "C13Z_FILE_UPLOAD_BINARY" and "C13Z_FILE_DOWNLOAD_BINARY" may also be utilized. Here is a procedure to save a file, read from presentation, into the app. server and read it from the app. server...

e.g.

<b>*-- Reading file from the presentation layer into an

*--internal table</b>

DATA gt_data TYPE TABLE OF text1000 WITH HEADER LINE .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = p_fname

filetype = 'BIN'

TABLES

data_tab = gt_data

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

OTHERS = 6 .

<b>*--Saving file to the application server</b>

DATA gv_dsn(30) TYPE c .

gv_dsn = '/usr/test.xls',

OPEN DATASET gv_dsn FOR OUTPUT .

LOOP AT gt_data .

TRANSFER gt_data TO gv_dsn .

ENDLOOP .

CLOSE DATASET gv_dsn .

<b>*-- Reading a file from application server into an

*--internal table</b>

DATA gv_filedsn(30) TYPE c .

gv_filedsn = '/usr/test.xls',

OPEN DATASET gv_filedsn .

DO .

READ DATASET gv_filedsn INTO gt_data2 .

IF sy-subrc NE 0 .

EXIT .

ENDIF .

APPEND gt_data2 .

ENDDO .

<b>*-- Downloading the file to the presentation layer from

*--the internal table</b>

DATA gv_down_fname LIKE rlgrap-filename .

gv_down_fname = 'D:\temp\after_down.doc' .

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = gv_down_fname

filetype = 'BIN'

TABLES

data_tab = gt_data2

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

OTHERS = 5

*--Serdar

Read only

0 Likes
880

Thanks Serdar, but I guess I should have explained myself a little better....the issue isn't really saving a file to the app. server or presentation layer (that's the easy stuff), but what I'm really after is a function that performs the same formatting as that done by the function LIST_CONVERT_TO_DAT (i.e. I need to convert an internal ABAP table or list to spreadsheet format ("DAT")). Note that I can't use LIST_CONVERT_TO_DAT because it's "hard-wired" to download the results to the presentation layer - I need to save my "dat-formatted" file to the app. server (and it needs to run in the background).

Read only

nablan_umar
Product and Topic Expert
Product and Topic Expert
0 Likes
880

Lee,

When you download your file to server, there is no option of file type when you download to PC. I have done this when downloading TAB delimited file to server.

...

LOOP at ITAB.

CLEAR LV_LINE.

CONCATENATE ITAB-FIELD1

ITAB-FIELD2

...

ITAB-FIELDN

INTO LV_LINE SEPARATED BY

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

TRANSFER LV_LINE TO SERVERFILENAME.

ENDLOOP.

...