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 file upload

Former Member
0 Likes
689

Hi ,

I am using the following FM to upload an EXCEL file.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = p_file

I_BEGIN_COL = 1

I_BEGIN_ROW = 1

I_END_COL = 3

I_END_ROW = 4

TABLES

INTERN = t_datain2

  • EXCEPTIONS

  • INCONSISTENT_PARAMETERS = 1

  • UPLOAD_OLE = 2

  • OTHERS = 3

it works fine but, i have one more requirement, the number of lines in the excel sheet is going to decided according to the file that the user is going to upload. therefore i cannot hardcode the value i_end_row an i_col for the function module. i there any workaround for this.

Regards

Narendiran Rathinavelu.

Hi ,

I am using the following FM to upload an EXCEL file.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = p_file

I_BEGIN_COL = 1

I_BEGIN_ROW = 1

I_END_COL = 3

I_END_ROW = 4

TABLES

INTERN = t_datain2

  • EXCEPTIONS

  • INCONSISTENT_PARAMETERS = 1

  • UPLOAD_OLE = 2

  • OTHERS = 3

it works fine but, i have one more requirement, the number of lines in the excel sheet is going to decided according to the file that the user is going to upload. therefore i cannot hardcode the value i_end_row an i_col for the function module. i there any workaround for this.

Regards

Narendiran Rathinavelu.

7 REPLIES 7
Read only

Former Member
0 Likes
664

Hi Narendiran,

U can fix the no. of rows / no. of columns to maximum value, so that it will work for any excel sheet.

- Satya Priya

Read only

0 Likes
664

hi

is there anyway of dynamically determining this file length at runtime.

Regards

Narendiran Rathinavelu

Read only

0 Likes
664

i mean the number of rows or columns

Regards

Narendiran Rathinvelu

Read only

Former Member
0 Likes
664

Use this.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = p_file

  • FILETYPE = 'ASC'

has_field_separator = '#'

TABLES

data_tab = t_datain2[].

Read only

Former Member
0 Likes
664

hi

good

yes i think you can do this, check this example

call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'

exporting

filename = FILENM

i_begin_col = 1

i_begin_row = 1

i_end_col = 100

i_end_row = 30000

tables

intern = IEXCEL

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3.

if sy-subrc <> 0.

WRITE: / 'EXCEL UPLOAD FAILED ', FILENM, SY-SUBRC.

ELSE.

SORT IEXCEL BY row col.

LOOP AT IEXCEL.

IF NOHEADER = 'X'

AND IEXCEL-row = 1.

CONTINUE.

ENDIF.

tind = IEXCEL-col.

CONCATENATE 'DATA_TAB-VALUE_' tind INTO zwfeld.

ASSIGN (zwfeld) TO <fs1>.

<fs1> = IEXCEL-value.

AT END OF row.

APPEND data_tab.

WRITE:/ 'data_tab ', data_tab-value_0001, data_tab-value_0002,

data_tab-value_0003, data_tab-value_0004.

CLEAR data_tab.

ENDAT.

ENDLOOP.

endif.

thanks

mrutyun^

Read only

0 Likes
664

Hi,

thanks for the response, is there anyway of obtaining the number of lines and number of rows dynamicaly in this case.

Regards

Narendiran Rathinavelu

Read only

Former Member
0 Likes
664

Hi Narendiran,

After uploading the excel sheet with i_end_col and i_end_row set to max values, u can get the no.of rows and no. of columns from the table t_datain2. Like

declare one more table t_datain1 type t_datain2.

t_datain1[] = t_datain2[]

sort t_datain1 by row descending.

read table t_datain1 index 1. *Gets the no. of rows in XL

t_datain1[] = t_datain2[]

sort t_datain1 by col descending.

read table t_datain1 index 1.

*Gets the no. of columns in XL

-Satya Priya Vepakomma