2007 Dec 10 4:55 AM
Hi,
I have used the FM 'ALSM_EXCEL_TO_INTERNAL_TABLE' to upload an excel file from the presentation server. the FM is working fine but if i enter a wrong filename, the FM fails and logs out of SAP. How can i validate whether the entered filename actually exists before the uploading is done?
Thanks and Regards,
Amrita
Hi,
I have used the FM 'ALSM_EXCEL_TO_INTERNAL_TABLE' to upload an excel file from the presentation server. the FM is working fine but if i enter a wrong filename, the FM fails and logs out of SAP. How can i validate whether the entered filename actually exists before the uploading is done?
Thanks and Regards,
Amrita
2007 Dec 10 5:07 AM
Hi,
Handle the error after calling FM.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = 1
i_begin_row = 2
i_end_col = 8
i_end_row = 9999
TABLES
intern = l_t_table[]
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
Message Ixx(xxx) with 'Error during upload'.
STOP.
ENDIF.
2007 Dec 10 5:18 AM
Hi Ramesh,
I've done the sy- subrc check and used stop but it doesn't seem to be working.
Thanks and regards,
Amrita.
2007 Dec 10 5:08 AM
Amrita,
Use param for inut file as shown below
PARAMETER :
P_FILE TYPE RLGRAP-FILENAME OBLIGATORY DEFAULT
'C:\example.xls'.
use the below code for validation
----
AT SELECTION-SCREEN
----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
*--- Validating file
PERFORM VALIDATE_FILE USING P_FILE.
----
Form : validate_input_file
----
Description : To provide F4 help for file if read from PC
----
FORM VALIDATE_FILE USING F_FILE TYPE RLGRAP-FILENAME.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
FILE_NAME = F_FILE
EXCEPTIONS
MASK_TOO_LONG = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE S010(Z_MSGCLASS). " 'Error in getting filename'.
ENDIF.
ENDFORM. " validate_input_file
Reward if helpful,
Karthik
2007 Dec 10 5:08 AM
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = path1
i_begin_col = 1
i_begin_row = 1
i_end_col = 4
i_end_row = 60000
TABLES
intern = iexcel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
<b>IF sy-subrc <> 0 .
WRITE :/15 'FILE NOT UPLOADED. INVALID FILE NAME OR PATH.' COLOR 6 .
EXIT.
ENDIF.</b>
2007 Dec 10 5:09 AM
Hi
http://help.sap.com/saphelp_45b/helpdata/en/2a/fa02b7493111d182b70000e829fbfe/content.htm
see this prohgram once
EXCEL TO INTERNAL TABLE AND THEN TO APPLICATION
&----
*& Report ZSD_EXCEL_INT_APP
*&
&----
*&
*&
&----
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.
2007 Dec 10 5:12 AM
Hi Amrita,
You can check the sy-subrc value after Function Module is executed and then if sy-subrc value is not zeor indicates that there is some problem while uploading file then you display a message or do what you want to do if the file does not exits.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE
....
.
.
.
.
if sy-subrc ne 0.
write: 'error ehilr uploading file'.
endif.
Reward points if this is helpful.
Regards,
Ravi G
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |