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

Excel upload

Former Member
0 Likes
695

Hi experts,

i am trying to upload data from Excel file to an internal table. But the data is not uploaded correctly.

Can u please help me ?

my code is :

REPORT Z_R_BDA_UPLOAD .

DATA : ANSWER.

DATA : BEGIN OF T_SHED OCCURS 0,

SCH_TYP(3) TYPE C,

REF_NO(12) TYPE C,

DEST_DEPT(3) TYPE C,

SUB_CONT LIKE VBAP-NETWR,

EMP_NO(10) TYPE C,

FLAG_ID(3) TYPE C,

GAZ TYPE C,

TRAN_CODE(10) TYPE C,

TRAN_STAT(2) TYPE C,

LOAN_AMT LIKE VBAP-NETWR,

CTR LIKE VBAP-ZMENG,

END OF T_SHED.

CALL FUNCTION 'UPLOAD'

EXPORTING

  • CODEPAGE = ' '

  • FILENAME = ' '

FILETYPE = 'dat'

  • ITEM = ' '

  • FILEMASK_MASK = ' '

  • FILEMASK_TEXT = ' '

  • FILETYPE_NO_CHANGE = ' '

  • FILEMASK_ALL = ' '

  • FILETYPE_NO_SHOW = ' '

  • LINE_EXIT = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • SILENT = 'S'

  • IMPORTING

  • FILESIZE =

  • CANCEL =

  • ACT_FILENAME =

  • ACT_FILETYPE =

TABLES

DATA_TAB = T_SHED.

  • EXCEPTIONS

  • CONVERSION_ERROR = 1

  • INVALID_TABLE_WIDTH = 2

  • INVALID_TYPE = 3

  • NO_BATCH = 4

  • UNKNOWN_ERROR = 5

  • GUI_REFUSE_FILETRANSFER = 6

  • OTHERS = 7

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

ENDIF.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
669

Hi!

Try using fm ALSM_EXCEL_TO_INTERNAL_TABLE

Regards

Tamá

6 REPLIES 6
Read only

Former Member
0 Likes
670

Hi!

Try using fm ALSM_EXCEL_TO_INTERNAL_TABLE

Regards

Tamá

Read only

0 Likes
669

Hi,

Check this sample code;

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = p_file

I_BEGIN_COL = '12'

I_BEGIN_ROW = '1'

I_END_COL = '12'

I_END_ROW = '1'

TABLES

INTERN = IEXCEL1

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 IEXCEL1.

case IEXCEL1-col.

when '0001'.

WA_L1 = IEXCEL1-value.

ENDCASE.

ENDLOOP.

regards

Read only

Former Member
0 Likes
669

Hi,

the FM UPLOAD works properly only with CSV or TEXT files if you want to use excel upload then use this FM

ALSM_EXCEL_TO_INTERNAL_TABLE

in the itab you will get data by column row format.

reward if useful

vivekanand

Read only

Former Member
0 Likes
669

Sample Program

REPORT ZTEST_12 .

tables : zvbrp_1.

data : g_repid like sy-repid,

$v_start_col type i value '1',

$v_start_row type i value '1',

$v_end_col type i value '256',

$v_end_row type i value '65536',

gd_currentrow type i.

DATA : BEGIN OF it_table OCCURS 0,

vbeln LIKE zvbrp_1-vbeln,

posnr LIKE zvbrp_1-posnr,

uepos LIKE zvbrp_1-uepos,

netwr LIKE zvbrp_1-netwr,

matnr LIKE zvbrp_1-matnr,

END OF it_table.

data: itab like alsmex_tabline occurs 0 with header line.

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

parameters : p_file like rlgrap-filename obligatory.

selection-screen : end of block blk.

initialization.

g_repid = sy-repid.

at selection-screen on value-request for p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = g_repid

IMPORTING

FILE_NAME = p_file.

start-of-selection.

  • Get the data from XLS to Internal Table

perform upload_data.

&----


*& Form upload_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM upload_data.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = p_file

I_BEGIN_COL = $v_start_col

I_BEGIN_ROW = $v_start_row

I_END_COL = $v_end_col

I_END_ROW = $v_end_row

TABLES

INTERN = itab

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

write:/10 'File '.

ENDIF.

if sy-subrc eq 0.

read table itab index 1.

gd_currentrow = itab-row.

loop at itab.

if itab-row ne gd_currentrow.

append it_table.

clear it_table.

gd_currentrow = itab-row.

endif.

case itab-col.

when '0001'.

it_table-vbeln = itab-value.

when '0002'.

it_table-posnr = itab-value.

when '0003'.

it_table-uepos = itab-value.

when '0004'.

it_table-netwr = itab-value.

when '0005'.

it_table-matnr = itab-value.

endcase.

endloop.

endif.

append it_table.

ENDFORM. " upload_data

vbeln posnr uepos netwr matnr

10 10 0 0 1

10 20 10 2 2

10 30 10 3 3

10 40 0 0 4

10 50 40 5 5

10 60 0 6 6

20 10 0 7 7

20 20 0 0 8

20 30 20 9 9

20 40 20 10 10

Regards

Vasu

Read only

Former Member
0 Likes
669

You cant upload the file contents of excel like this..

This program will tell you how we can do this

REWARD IF USEFUL

REPORT YM_BDC_EXCEL_SHEET .

data: begin of itab occurs 0,

name(20) type c,

addre(20) type c,

end of itab.

DATA : ITAB1 LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.

DATA : B1 TYPE I VALUE 1,

C1 TYPE I VALUE 1,

B2 TYPE I VALUE 100,

C2 TYPE I VALUE 9999.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = 'C:\Documents and Settings\uday\Desktop'

I_BEGIN_COL = B1

I_BEGIN_ROW = C1

I_END_COL = B2

I_END_ROW = C2

TABLES

INTERN = itab1

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 itab1.

write:/ itab1.

Endloop.

Read only

Former Member
0 Likes
669

Hi Murugan,

Try this logic.

*To upload file

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lv_filename

TABLES

data_tab = it_file_ps[]

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.

SPLIT wa_file_ps AT ',' INTO WA_data.

APPEND wa_data TO it_data.

Hope this is helpful.

Reward all the helpful answers.

Regards

Nagaraj