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

How to upload file from Application Server?

Former Member
0 Likes
925

Dear Friends,

How to upload file from Application Server?

Plz. with example...

Regards,

Dharmesh

Dear Friends,

How to upload file from Application Server?

Plz. with example...

Regards,

Dharmesh

6 REPLIES 6
Read only

vinod_gunaware2
Active Contributor
0 Likes
874

Use

CG3Y and CG3Z transaction

USe AL11 to view file

Reading and Writing a text file from and to the application server

  • sy-subrc = 0 Record read from file

  • sy-subrc = 4 End of file reached

data: w_dataset1(27) value '/var/textfile.txt',

w_dataset2(27) value '/var/outfile.txt'.

data:begin of itab1 occurs 0, "Text file format

matnr(18), "MATERIAL NUMBER

bwkrs(4), "PLANT

end of itab1.

*Uploading of text file from Application server.

open dataset w_dataset1 for input in text mode.

do.

if sy-subrc <> 0.

exit.

endif.

read dataset w_dataset1 into itab1.

append itab1.

clear itab1.

enddo.

close dataset w_dataset1.

*Downloading of text file to Application server.

open dataset w_dataset2 for output in text mode.

loop at itable.

transfer itable to w_dataset2.

endloop.

close dataset w_dataset2.

regards

vinod

Read only

abdul_hakim
Active Contributor
0 Likes
874

hi use the below logic...

OPEN DATASET <filename> FOR INPUT IN TEXT MODE.

DO .

READ DATASET <filename> INTO <ur structure>.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

APPEND <ur structure> TO <itab>.

ENDDO.

Cheers,

Abdul

Read only

0 Likes
874

Hi,

check these Programs..

RPCIFU03 Download Unix File to PC

RPCIFU04 Upload PC File to Unix File

Regards

vijay

Read only

Former Member
0 Likes
874

Hi Dharmesh.

To read the file from the application server.

CONCATENATE path filename INTO file.

TRANSLATE file TO LOWER CASE.

MOVE: default_filename TO in_trailer-file_name,

interface_id TO in_trailer-interface_id.

OPEN DATASET file FOR INPUT IN TEXT MODE.

IF sy-subrc NE 0.

PERFORM process_msg USING '101' file '' ''.

MOVE: true TO abend_job.

ELSE.

DO.

READ DATASET file INTO infile.

IF sy-subrc NE 0.

total_recs = sy-index - 3.

EXIT.

ENDIF.

APPEND infile.

ENDDO.

CLOSE DATASET file.

ENDIF.

You will have the file contents in the table infile.

Thanks,

Susmitha

Read only

Former Member
0 Likes
874

Dharmesh,

If you want to upload file using abap code, see below for code

IF NOT tab[] IS INITIAL.

PERFORM open_dataset USING w_bkpf_pfilename.

PERFORM process_data.

PERFORM close_dataset USING w_bkpf_pfilename.

ENDIF.

&----


*& Form OPEN_DATASET

&----


  • Open dataset for appending in text mode

----


FORM open_dataset USING p_w_pfilename.

  • open file for appending in text mode

OPEN DATASET p_w_pfilename FOR APPENDING IN TEXT MODE.

IF sy-subrc NE 0.

MESSAGE e006 WITH p_w_pfilename 'file could not be open/close.'(101).

EXIT.

ENDIF.

ENDFORM. "OPEN_DATASET

&----


*& Form WRITE_FILE

&----


  • Create document header file

----


FORM write_file .

SORT tab BY XXXXX.

  • transfer data to file

LOOP AT tab INTO wa_tab.

MOVE-CORRESPONDING wa_tab TO st_file.

TRANSFER st_file TO w_pfilename.

ENDLOOP.

ENDFORM. " WRITE_BKPF_FILE

&----


*& Form close_dataset

&----


  • Close dataset

----


  • -->P_W_BKPF_PFILENAME text

----


FORM close_dataset USING p_w_pfilename.

CLOSE DATASET p_w_pfilename .

IF sy-subrc NE 0.

MESSAGE e006 WITH p_w_pfilename 'file could not be open/close.'(101).

ENDIF.

ENDFORM. " close_dataset

If you want to directly upload / download file from application server you can use transaction CG3Z and CG3Y.

Also you can check uploaded file content using transaction AL11.

Cheers,

Nilesh

Read only

Former Member
0 Likes
874

hi,

check the code for upload from application server.

tables: kna1.

types: begin of s_file,

customer type kna1-kunnr,

country type kna1-land1,

name type kna1-name1,

region type kna1-regio,

end of s_file.

*--Internal tables

data: it_file type s_file occurs 0 with header line.

&----


*-- Selection screen

&----


selection-screen: begin of block b1 with frame title text-001.

parameter: p_file type rlgrap-filename default 'C:/customer.txt'

obligatory.

selection-screen: end of block b1.

&----


*-- At selection screen

&----


at selection-screen on value-request for p_file.

perform file_help using p_file.

&----


*-- Process File

&----


start-of-selection.

perform upload_file using p_file.

&----


*-- write File data to o/p

&----


end-of-selection.

perform write_data.

&----


*& Form file_help

----


form file_help using p_p_file.

data: l_filepath type ibipparms-path.

call function 'F4_FILENAME'

  • EXPORTING

  • PROGRAM_NAME = SYST-CPROG

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

importing

file_name = l_filepath

.

p_p_file = l_filepath.

endform. " file_help

&----


*& Form upload_file

&----


form upload_file using p_p_file.

call function 'WS_UPLOAD'

exporting

filename = p_p_file

filetype = 'DAT'

  • IMPORTING

  • FILELENGTH =

tables

data_tab = it_file

exceptions

conversion_error = 1

file_open_error = 2

file_read_error = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

no_authority = 10

others = 11

.

if sy-subrc <> 0.

message i001.

endif.

endform. " upload_file

&----


*& Form write_data

&----


form write_data .

loop at it_file.

write:/ it_file-customer, it_file-country, it_file-name,

it_file-region.

endloop.

endform.

regards,

keerthi.