‎2007 Jul 18 11:17 AM
Hi,
I want to upload an excel file from presentation server to application server using
FM gui_upload. Can anyone tell how can i do it.
Message was edited by:
manish arora
‎2007 Jul 18 11:21 AM
You have a ready made transaction for the same.
CG3Z.
You can make use of it.
Regards,
Ravi
‎2007 Jul 18 11:23 AM
‎2007 Jul 18 11:22 AM
hi..
Use FM GUI_UPLOAD, save the file in tab delimited format and use the FM.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lcl_filename
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = i_input
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.
‎2007 Jul 18 11:34 AM
‎2007 Jul 18 11:22 AM
hi,
chk this sample code,
tables: lfa1.
&----
*int table declaration
&----
data: begin of it_lfa1 occurs 0,
vendor like lfa1-lifnr,
land1 like lfa1-land1,
name1 like lfa1-name1,
ort01 like lfa1-ort01,
end of it_lfa1.
&----
*selection screen
&----
selection-screen: begin of block b1 with frame title text-001.
parameters: 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.
&----
*start-of-selection
&----
start-of-selection.
perform upload_file using p_file.
&----
*end of selection
&----
end-of-selection.
perform write_data.
&----
*& Form file_help
&----
text
----
-->P_P_FILE text
----
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
&----
text
----
-->P_P_FILE text
----
form upload_file using p_p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = p_p_file
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE = VIRUS_SCAN_PROFILE
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH = FILELENGTH
HEADER = HEADER
TABLES
data_tab = it_lfa1
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.
MESSAGE I000(ZZ) WITH 'UNABLE TO UPLOAD'.
ENDIF.
endform. " upload_file
&----
*& Form write_data
&----
text
----
--> p1 text
<-- p2 text
----
form write_data .
loop at it_lfa1.
write:/ it_lfa1-vendor,
it_lfa1-land1,
it_lfa1-name1,
it_lfa1-ort01.
endloop.
endform. " write_data
do reward if it helps,
regards,
priya
‎2007 Jul 18 11:23 AM
Hi!
For example I will upload the excel with an FTP program (f.e. Smartftp). You just need the FTP settings of the server (IP, path, username, password) and have rights to the directory.
Regards
Tamá
‎2007 Jul 18 11:23 AM
Upload file with the help of this FM -
ALSM_EXCEL_TO_INTERNAL_TABLE
Then do your mapping or what ever calculation require and download it to application server with the help of OPEN DATASET command.
But his program will not run in background mode as no presentation server is available there.
Refer the links -
http://www.sapdevelopment.co.uk/file/file_upexcel.htm
Regards,
Amit
Reward all helpful replies.
‎2007 Jul 18 1:24 PM
HI
TRY THIS PROGRAM
REWARD IF USEFULL
REPORT ZSD_EXCEL_INT_APP.
parameter: file_nm type localfile.
types : begin of it_tab1,
f1(20),
f2(40),
f3(20),
end of it_tab1.
data : it_tab type table of ALSMEX_TABLINE with header line,
file type rlgrap-filename.
data : it_tab2 type it_tab1 occurs 1,
wa_tab2 type it_tab1,
w_message(100) TYPE c.
at selection-screen on value-request for file_nm.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
PROGRAM_NAME = SYST-REPID
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
STATIC = 'X'
MASK = ' '
CHANGING
file_name = file_nm
EXCEPTIONS
MASK_TOO_LONG = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
start-of-selection.
refresh it_tab2[].clear wa_tab2.
file = file_nm.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '10'
i_end_row = '35'
tables
intern = it_tab
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop at it_tab.
case it_tab-col.
when '002'.
wa_tab2-f1 = it_tab-value.
when '004'.
wa_tab2-f2 = it_tab-value.
when '008'.
wa_tab2-f3 = it_tab-value.
endcase.
at end of row.
append wa_tab2 to it_tab2.
clear wa_tab2.
endat.
endloop.
data : p_file TYPE rlgrap-filename value 'TEST3.txt'.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
*--- Display error messages if any.
IF sy-subrc NE 0.
MESSAGE e001(zsd_mes).
EXIT.
ELSE.
*---Data is downloaded to the application server file path
LOOP AT it_tab2 INTO wa_tab2.
TRANSFER wa_tab2 TO p_file.
ENDLOOP.
ENDIF.
*--Close the Application server file (Mandatory).
CLOSE DATASET p_file.
loop at it_tab2 into wa_tab2.
write : / wa_tab2-f1,wa_tab2-f2,wa_tab2-f3.
endloop.