Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Require a demo program

Hi all

I need a demo program which will be used to download file on application server as well as on temp directories.

Its very urgent.

Rgrds

Mona

Tags:
Former Member
Former Member replied

hi,,,

check this....hope it will be useful

data: begin of it_data occurs 0 ,

field1(10),

field2(10),

field3(10),

end of it_data.

data: begin of itab1 occurs 0 ,

field1(10),

field2(10),

field3(10),

end of itab1.

parameters: p_file type rlgrap-filename default '.\myfile'..

at selection-screen on value-request for p_file .

perform get_file_name.

start-of-selection.

*perform populate_data.

  • perform upload_ps.

  • perform download_ps.

perform upload_as.

perform download_as.

&----


*& Form get_file_name

&----


  • text

----


form get_file_name .

  • Function module used for F4 help

call function 'F4_FILENAME'

exporting

program_name = syst-cprog

dynpro_number = syst-dynnr

importing

file_name = p_file.

endform. " get_file_name

&----


*& Form upload_ps

&----


  • From Flat file to itab

----


form upload_ps .

data: lv_filename type string.

lv_filename = p_file.

call function 'GUI_UPLOAD'

exporting

filename = lv_filename

filetype = 'ASC'

has_field_separator = 'X'

tables

data_tab = it_data

exceptions

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

others = 17.

if sy-subrc <> 0.

write:/ 'FiLe not found'.

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

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

else.

if not it_data[] is initial.

loop at it_data.

write:/ it_data.

endloop.

endif.

endif.

endform. " upload_ps

&----


*& Form download_ps

&----


  • itab to flat file

----


form download_ps .

data: lv_filename type string.

lv_filename = p_file.

call function 'GUI_DOWNLOAD'

exporting

  • BIN_FILESIZE = BIN_FILESIZE

filename = lv_filename

filetype = 'ASC'

write_field_separator = 'X'

tables

data_tab = it_data

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.

write:/ 'FILE NOT FOUND'.

else.

write:/ 'FILE DOWNLOADED'.

endif.

endform. " download_ps

&----


*& Form upload_as

&----


  • From itab to application server

----


form upload_as .

open dataset p_file for output in text mode encoding default.

loop at it_data.

transfer it_data to p_file.

endloop.

close dataset p_file.

endform. " upload_as

&----


*& Form download_as

&----


  • From application server to itab

----


form download_as .

open dataset p_file for input in text mode encoding default.

do.

read dataset p_file into itab1.

append itab1.

if sy-subrc <> 0.

exit.

endif.

enddo.

close dataset p_file.

if not itab1[] is initial.

loop at itab1.

write:/ itab1.

endloop.

endif.

endform. " download_as

&----


*& Form populate_data

&----


  • text

----


form populate_data .

it_data-field1 = 'aaa'.

it_data-field2 = 'bbb'.

it_data-field3 = 'ccc'.

append it_data.

clear it_data.

it_data-field1 = '111'.

it_data-field2 = '222'.

it_data-field3 = '333'.

append it_data.

clear it_data.

endform. " populate_data

pls reward if useful

cheers,

rekha

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question