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

Displaying Error while uploading Excel Sheets

Former Member
0 Likes
2,401

Dear All,

we are uploading excel sheets into SAP Tables. While uploading we are specifying the location/path in the selection screen. Then we are displaying the message that 'All Files Loaded Successfully'. But if the files are not existing then also it is showing the same message. Plz help me in throwing the error message & screen shuld return to the selection screen again so that the user can enter the correct file.

I am enclosing the code for reference.

thanks in advance,

nishu

********************************************************

tables: bseg, zfi_tbl_qty, t001, tgsb.

data:

t_excel like alsmex_tabline occurs 0 with header line,

l_excelfile(128) type c,

l_excelfile1(128) type c,

l_excelfile2(128) type c,

l_excelfile3(128) type c.

data: begin of t_bukrs_tmp occurs 0,

bukrs like t001-bukrs,

end of t_bukrs_tmp.

data: begin of t_gsber_tmp occurs 0,

gsber like tgsb-gsber,

end of t_gsber_tmp.

ranges: r_bukrs_tmp for t001-bukrs,

r_gsber_tmp for tgsb-gsber.

data: begin of t_type,

bukrs like bseg-bukrs,

gsber like bseg-gsber,

count type i,

end of t_type.

data: l_charlen1 type i,

l_charlen2 type i.

data: t_type2 like t_type occurs 0 with header line,

t_type2_tmp like t_type occurs 0 with header line.

data: l_end_row type i,

l_endrow1 type i,

l_count type i,

v_bukrs like bseg-bukrs.

data : q_count type i value 1,

v_flag type i value 0,

v_gsber like t_type2-gsber.

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

parameter : p_file1 type rlgrap-filename obligatory,

p_file2 type rlgrap-filename obligatory,

p_file3 type rlgrap-filename obligatory,

p_file4 type rlgrap-filename obligatory.

selection-screen end of block b1.

*clearing the contents of database table before uploading a new file everytime

delete from zfi_tbl_qty.

*selection-screen

at selection-screen on value-request for p_file1.

call function 'KD_GET_FILENAME_ON_F4'

exporting

field_name = p_file1

changing

file_name = p_file1.

at selection-screen on value-request for p_file2.

call function 'KD_GET_FILENAME_ON_F4'

exporting

field_name = p_file2

changing

file_name = p_file2.

at selection-screen on value-request for p_file3.

call function 'KD_GET_FILENAME_ON_F4'

exporting

field_name = p_file3

changing

file_name = p_file3.

at selection-screen on value-request for p_file4.

call function 'KD_GET_FILENAME_ON_F4'

exporting

field_name = p_file4

changing

file_name = p_file4.

at selection-screen.

l_excelfile = p_file1.

l_excelfile1 = p_file2.

l_excelfile2 = p_file3.

l_excelfile3 = p_file4.

if l_excelfile = l_excelfile1 or l_excelfile = l_excelfile2 or l_excelfile = l_excelfile3

or l_excelfile1 = l_excelfile2 or l_excelfile1 = l_excelfile3 or l_excelfile2 = l_excelfile3.

message e010(zn) with 'Files with the same name found Please enter again. '.

endif.

start-of-selection.

select bukrs

from t001

into corresponding fields of table t_bukrs_tmp.

loop at t_bukrs_tmp.

r_bukrs_tmp-sign = 'I'.

r_bukrs_tmp-option = 'EQ'.

r_bukrs_tmp-low = t_bukrs_tmp-bukrs.

append r_bukrs_tmp.

endloop.

select gsber

from tgsb

into corresponding fields of table t_gsber_tmp.

loop at t_gsber_tmp.

r_gsber_tmp-sign = 'I'.

r_gsber_tmp-option = 'EQ'.

r_gsber_tmp-low = t_gsber_tmp-gsber.

append r_gsber_tmp.

endloop.

perform upload_table using l_excelfile 5 2 6 4000.

perform upload_table using l_excelfile1 5 2 6 4000.

perform upload_table using l_excelfile2 5 2 6 4000.

perform upload_table using l_excelfile3 5 2 6 4000.

message i010(zn) with 'Files Uploaded Successfully.'.

*****************Calling the subroutine

form upload_table using filename

i_begin_col type i

i_begin_row type i

i_end_col type i

i_end_row type i.

clear : t_excel.

refresh : t_excel.

v_flag = v_flag + 1.

call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'

exporting

filename = filename

i_begin_col = 5

i_begin_row = 2

i_end_col = 6

i_end_row = 4000

tables

intern = t_excel

exceptions

inconsistent_parameters = 1

upload_ole = 2

others = 3.

case v_flag.

when '1'.

perform fill_int_tab.

when '2'.

perform fill_int_tab.

when '3'.

perform fill_int_tab.

when '4'.

perform fill_int_tab.

endcase.

endform. "upload_table

*uploading data from internal table into database table

&----


*& Form fill_int_tab

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form fill_int_tab .

clear : t_type2, q_count.

refresh : t_type2.

describe table t_excel lines l_endrow1.

l_endrow1 = l_endrow1 / 2.

do.

loop at t_excel where row = q_count.

if t_excel-col = 1.

t_type2-gsber = t_excel-value.

elseif t_excel-col = 2.

t_type2-bukrs = t_excel-value.

endif.

endloop.

l_charlen1 = strlen( t_type2-bukrs ).

l_charlen2 = strlen( t_type2-gsber ).

if ( t_type2-bukrs <> ' ' and t_type2-gsber <> ' ' ).

if ( l_charlen1 = 4 and l_charlen2 = 4 ).

append t_type2. clear t_type2.

endif.

endif.

q_count = q_count + 1.

if q_count > l_endrow1.

exit.

endif.

enddo.

t_type2_tmp[] = t_type2[].

clear t_type2.

refresh t_type2.

loop at t_type2_tmp where bukrs in r_bukrs_tmp

and gsber in r_gsber_tmp.

move-corresponding t_type2_tmp to t_type2.

append t_type2.

endloop.

sort t_type2 by bukrs gsber.

loop at t_type2.

clear v_gsber.

l_count = l_count + 1 .

v_gsber = t_type2-gsber.

at end of gsber.

zfi_tbl_qty-company_code = t_type2-bukrs.

zfi_tbl_qty-barea = v_gsber.

zfi_tbl_qty-comb = l_count.

if v_flag = 1.

zfi_tbl_qty-type = 'A'. " Item 1

endif.

if v_flag = 2.

zfi_tbl_qty-type = 'B'. " Item 2

endif.

if v_flag = 3.

zfi_tbl_qty-type = 'C'. " Item 3

endif.

if v_flag = 4.

zfi_tbl_qty-type = 'D'. " Item 4

endif.

insert zfi_tbl_qty from zfi_tbl_qty.

clear l_count.

endat.

endloop.

endform. " fill_int_tab

1 ACCEPTED SOLUTION
Read only

rahulkavuri
Active Contributor
0 Likes
1,349

Hope this is what u are looking for...

in the other case if the files are not existing on the system then automatically a message is displayed that

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = V_FILE

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = IT_SALES

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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

ENDIF.

use <b>format_message</b> function module to get errors if there are any while uploading the records in excel sheet

6 REPLIES 6
Read only

rahulkavuri
Active Contributor
0 Likes
1,350

Hope this is what u are looking for...

in the other case if the files are not existing on the system then automatically a message is displayed that

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = V_FILE

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = IT_SALES

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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

ENDIF.

use <b>format_message</b> function module to get errors if there are any while uploading the records in excel sheet

Read only

Former Member
0 Likes
1,349

Hi Nishu,

After using the perform statements, check the no. of records in the tables using sy-dbcnt. if it matches the no. of records loaded from excel sheet , give success message ,in the else part u can give the failure message.

Hope this helps. Award points if helpful.

regards,

keerthi.

Read only

Former Member
0 Likes
1,349

hi

instead of FM

'KD_GET_FILENAME_ON_F4'

Use this code


CALL FUNCTION 'F4_FILENAME'
      EXPORTING
        PROGRAM_NAME  = SYST-CPROG
        DYNPRO_NUMBER = SYST-DYNNR
        FIELD_NAME    = 'P_UNIX'
      IMPORTING
        FILE_NAME     = P_HEADER.

if p_header is initial 
message e000 with 'erroe file doesn't exist'.


Read only

sbhutani1
Contributor
0 Likes
1,349

Hi nishu,

You can use FM F4_filename for getting the file name and dont forget to set the filter to *.xls. it will solve your problem.

Regards

Sumit Bhutani

Ps reward points if helpful

Read only

Former Member
0 Likes
1,349

Hi,

After calling the Fn.module 'ALSM_EXCEL_TO_INTERNAL_TABLE'

Check if sy-subrc = '2'.

Message 'File not Found Message'.

endif.

Regards,

Kalyan

Read only

Former Member
0 Likes
1,349

hi,

as you are updating from 4 different files, it would be good to inform the user each file upload status.

i mean success or failure in uploading the each file status.

for that instead of using MESSAGE for all the files one time, its better to use WRITE statement to display the message to the user.

here i noticed few places where error can occur

1) uploading the excel data into your internal table.

after the function module call,

if sy-subrc <> 0.

based on the V_FLAG , we know which file this error happened. accordingly display the error message

like

if sy-subrc <> 0.

WRITE : 'Error occurred in Uploading the data from the file'.

if v_Flag = 1.

write 😕 l_excelfile. "here give some color to notice error occurred

elseif v_flag = 2.

write 😕 l_excelfile1.

and so on..

endif.

this way we can display the user what happened to each file if upload is went wrong.

2) insert..

if sy-subrc <> 0.

again by using V_FLAG display the error/success message to the user for each file insert.

one more change you have to do in the program is :

at selection-screen on value-request for p_file1.

in this event you are calling the function module for F4 help 4 times. instead you can write a FORM & call that form in all these 4 events.

as below.

at selection-screen on value-request for p_file1.

perform provide_f4_help chaning p_file1.

at selection-screen on value-request for p_file2.

perform provide_f4_help chaning p_file2.

at selection-screen on value-request for p_file3.

perform provide_f4_help chaning p_file3.

at selection-screen on value-request for p_file4.

perform provide_f4_help chaning p_file4.

form provide_f4_help changing p_filename.

*--here call that F4 help function module.

endform.

Regards

Srikanth

Message was edited by: Srikanth Kidambi