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

upload excel file with function 'WS_UPLOAD' has error

Former Member
0 Likes
943

Hi all,

PARAMETERS: p_file LIKE rlgrap-filename.

my program use CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = p_file

FILETYPE = 'BIN'

TABLES

DATA_TAB = i_upload

But i_upload out have data can not read

ex: ÐÏ#ࡱ#á##########

#¤####mm/dd##8#¥#3

à######### ##x##@

######Sheet1…###@#

Actual are date and qty.

03122008 04122008

111 120

how solve this.......

thanks so much....

4 REPLIES 4
Read only

Former Member
0 Likes
740

Hi Nguyen,

Try this:

Use FM ALSM_EXCEL_TO_INTERNAL_TABLE

TYPES:

BEGIN OF ty_upload,

field1 TYPE c length 12,

field2 TYPE c length 12,

field3 TYPE c length 12,

END OF ty_upload.

DATA it_upload TYPE STANDARD TABLE OF ty_upload WITH DEFAULT KEY.

DATA wa_upload TYPE ty_upload.

DATA itab TYPE STANDARD TABLE OF alsmex_tabline WITH DEFAULT KEY.

FIELD-SYMBOLS: <wa> type alsmex_tabline.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = filename

i_begin_col = 1

i_begin_row = 1

i_end_col = 3

i_end_row = 65535

TABLES

intern = itab.

LOOP AT itab ASSIGNING <wa>.

CASE <wa>-col.

WHEN '0001'.

wa_upload-field1 = <wa>-value.

WHEN '0002'.

wa_upload-field2 = <wa>-value.

WHEN '0003'.

wa_upload-field3 = <wa>-value.

ENDCASE.

APPEND wa_upload TO it_upload.

CLEAR wa_upload.

ENDLOOP.

**********another way*******

TYPE-POOLS truxs.

tables : ztable.

types: begin of t_tab,

col1(5) type c,

col2(5) type c,

col3(5) type c,

end of t_tab.

data : itab type standard table of t_tab,

wa type t_tab.

data it_type type truxs_t_text_data.

parameter p_file type rlgrap-filename.

data ttab type tabname.

at selection-screen on value-request for p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

  • PROGRAM_NAME = SYST-CPROG

  • DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = 'P_FILE'

IMPORTING

FILE_NAME = p_file

.

start-of-selection.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

  • I_FIELD_SEPERATOR =

  • I_LINE_HEADER = 'X'

i_tab_raw_data = it_type

i_filename = p_file

tables

i_tab_converted_data = itab[]

EXCEPTIONS

CONVERSION_FAILED = 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.

end-of-selection.

loop at itab into wa.

ztable-col1 = wa-col1.

ztable-col2 = wa-col2.

ztable-col3 = wa-col3.

modify ztable.

endloop.

<b>Reward points if this helps.

Manish</b>

Read only

Former Member
0 Likes
740

Hi Tham,

This is to upload one excel file in CSV format to database table which i have created.

REPORT ZSDCCDTGTUPD .

TABLES: ZCCD_TGT.

DATA: BEGIN OF itab OCCURS 0,

kunnr TYPE zccd_tgt-kunnr,

FSCAL_YEAR TYPE zccd_tgt-FSCAL_YEAR,

VALUE(14) type c, "TYPE zccd_tgt-VALUE,

date1 TYPE zccd_tgt-date1,

END OF itab.

data : l_flnm type rlgrap-filename.

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

selection-screen skip 1.

parameters: p_flnm like rlgrap-filename obligatory.

selection-screen skip 1.

selection-screen end of block bk1.

at selection-screen on value-request for p_flnm.

call function 'F4_FILENAME'

exporting

program_name = syst-cprog

dynpro_number = syst-dynnr

importing

file_name = p_flnm.

.

start-of-selection.

clear l_flnm.

l_flnm = p_flnm.

call function 'WS_UPLOAD'

exporting

filename = l_flnm

filetype = 'dat'

tables

data_tab = ITAB

exceptions

conversion_error = 1

file_open_error = 2

file_read_error = 3

invalid_table_width = 4

invalid_type = 5

no_batch = 6

unknown_error = 7

gui_refuse_filetransfer = 8

others = 9.

LOOP AT ITAB.

zccd_tgt-kunnr = ITAB-kunnr.

zccd_tgt-FSCAL_YEAR = ITAB-FSCAL_YEAR.

zccd_tgt-VALUE = ITAB-VALUE.

zccd_tgt-date1 = ITAB-DATE1.

MODIFY ZCCD_TGT.

commit work.

ENDLOOP.

REPORT ZSDCCDTGTUPD .

TABLES: ZCCD_TGT.

DATA: BEGIN OF itab OCCURS 0,

kunnr TYPE zccd_tgt-kunnr,

FSCAL_YEAR TYPE zccd_tgt-FSCAL_YEAR,

VALUE(14) type c, "TYPE zccd_tgt-VALUE,

date1 TYPE zccd_tgt-date1,

END OF itab.

data : l_flnm type rlgrap-filename.

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

selection-screen skip 1.

parameters: p_flnm like rlgrap-filename obligatory.

selection-screen skip 1.

selection-screen end of block bk1.

at selection-screen on value-request for p_flnm.

call function 'F4_FILENAME'

exporting

program_name = syst-cprog

dynpro_number = syst-dynnr

importing

file_name = p_flnm.

.

start-of-selection.

clear l_flnm.

l_flnm = p_flnm.

call function 'WS_UPLOAD'

exporting

filename = l_flnm

filetype = 'dat'

tables

data_tab = ITAB

exceptions

conversion_error = 1

file_open_error = 2

file_read_error = 3

invalid_table_width = 4

invalid_type = 5

no_batch = 6

unknown_error = 7

gui_refuse_filetransfer = 8

others = 9.

LOOP AT ITAB.

zccd_tgt-kunnr = ITAB-kunnr.

zccd_tgt-FSCAL_YEAR = ITAB-FSCAL_YEAR.

zccd_tgt-VALUE = ITAB-VALUE.

zccd_tgt-date1 = ITAB-DATE1.

MODIFY ZCCD_TGT.

commit work.

ENDLOOP.

kindly reward if found helpful.

cheers,

Hema.

Read only

Former Member
0 Likes
740

hi,

use 'ALSM_EXCEL_TO_INTERNAL_TABLE' function module to upload excel to internal table.

this function module uploads data from excel to internal table,

check this sample code

TYPE-POOLS truxs.

TABLES:zmatnr.

DATA : itab LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.

DATA row LIKE alsmex_tabline-row.

data : g_matnr like mara-matnr.

data : count type i.

data : itab_count type i.

data : gi_final like zmatnr occurs 0 with header line.

*data : begin of gi_final occurs 0,

mat_old like mara-matnr,

mat_new like mara-matnr,

end of gi_final.

***********************Selection Screen*************************

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETER : pfname LIKE rlgrap-filename OBLIGATORY.

select-options : records for count.

SELECTION-SCREEN END OF BLOCK b1.

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

*********************At Selection Screen*************************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR pfname.

PERFORM search.

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

START-OF-SELECTION.

perform process.

form process.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = pfname

i_begin_col = 1

i_begin_row = 2

i_end_col = 12

i_end_row = 65000

TABLES

intern = itab

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.

describe table itab lines itab_count.

row = 1.

loop at itab.

if itab-row row.

append gi_final.

clear gi_final.

endif.

case itab-col.

when '1'.

CLEAR G_MATNR.

gi_final-OLD_MATNR = itab-value.

CONCATENATE 'NEW' gi_final-old_matnr INTO itab-value.

gi_final-new_MATNR = itab-value.

endcase.

row = itab-row.

endloop.

append gi_final.

clear gi_final.

CALL FUNCTION 'PROGRESS_INDICATOR'

EXPORTING

I_TEXT = 'File Has Been Successfully Uploaded from Workstation ' .

if not gi_final[] is initial.

if not records-low is initial .

if not records-high is initial.

records-high = records-high + 1.

DESCRIBE TABLE gi_final LINES count.

IF records-high < count.

DELETE gi_final FROM records-high TO count.

ENDIF.

IF records-low <> 1.

IF records-low 0.

DELETE gi_final FROM 1 TO records-low.

ENDIF.

ENDIF.

endif.

endif.

endif.

IF NOT GI_FINAL[] IS INITIAL.

CALL FUNCTION 'PROGRESS_INDICATOR'

EXPORTING

I_TEXT = 'Processing zmatnr table'

I_OUTPUT_IMMEDIATELY = 'X'.

if itab_count count.

*

message i000 with 'records are not matching'.

*

exit.

*

else.

modify zmatnr from table gi_final.

message i000 with 'data base table modified successfully'.

endif.

endif.

endform.

&----


*& Form search

&----


text

-


--> p1 text

<-- p2 text

-


FORM search .

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

static = 'X'

CHANGING

file_name = pfname.

ENDFORM. " search

regards

siva

Read only

Former Member
0 Likes
740

Hi,

If you are looking to upload an Excel file (data existing in different columns of excel) GUI_UPLOAD will not work.

use FM : ALSM_EXCEL_TO_INTERNAL_TABLE.

If you are using CSV format excel file (this is basically comma seperated format), GUI_UPLOAD can be used.

Decide the logic based on ur excel file.