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

uploading data from excel

Former Member
0 Likes
521

Can somebody please explain me the steps in developing an ALV report to upload data from an excel file.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
503

Proceed as below:



start-of-selection.

   perform upload_data. "Use FM: GUI_UPLOAD if the data is in Presentation server or Dataset statements if the file is in Application Server.

   perform process_data. " Do Required Processing

   peform display_data.  " Build Field catalog and use for the ALV FM to display data

Regards

Eswar

3 REPLIES 3
Read only

Former Member
0 Likes
504

Proceed as below:



start-of-selection.

   perform upload_data. "Use FM: GUI_UPLOAD if the data is in Presentation server or Dataset statements if the file is in Application Server.

   perform process_data. " Do Required Processing

   peform display_data.  " Build Field catalog and use for the ALV FM to display data

Regards

Eswar

Read only

Former Member
0 Likes
503

Hi,

1. Get the data from excel to your internal table

2. Pass that internal table to ALV Function module..

Used to upload data from excel to itab.

check this simple prg

Here "RECORD1" is your internal table which ishaving the same no. of columns as in excel sheet.

DATA:IT_EXCEL LIKE TABLE OF ALSMEX_TABLINE WITH HEADER LINE.

DATA : i_fieldcat TYPE slis_t_fieldcat_alv.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-002.

PARAMETERS: P_FILE TYPE LOCALFILE OBLIGATORY .

SELECTION-SCREEN END OF BLOCK B1.

**********************AT SELECTION SCREEN EVENTS BEGINS***************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

STATIC = 'X'

CHANGING

FILE_NAME = P_FILE.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = P_FILE

I_BEGIN_COL = 1 "From 1st Column

I_BEGIN_ROW = 2 "From 2nd row

I_END_COL = 6 "Till 6th Column

I_END_ROW = 65536 "Till Row

TABLES

INTERN = IT_EXCEL

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3.

CLEAR IT_EXCEL.

DESCRIBE TABLE IT_EXCEL.

IF SY-TFILL = 0.

MESSAGE I937.

STOP.

ENDIF.

LOOP AT IT_EXCEL.

CASE IT_EXCEL-COL.

WHEN '0001'.

MOVE: IT_EXCEL-VALUE TO RECORD1-MATNR_005.

WHEN '0002'.

MOVE: IT_EXCEL-VALUE TO RECORD1-WERKS_006.

WHEN '0003'.

MOVE: IT_EXCEL-VALUE TO RECORD1-BUDAT_002.

WHEN '0004'.

MOVE: IT_EXCEL-VALUE TO RECORD1-BKTXT_004.

WHEN '0005'.

MOVE: IT_EXCEL-VALUE TO RECORD1-ERFMG_007.

WHEN '0006'.

MOVE: IT_EXCEL-VALUE TO RECORD1-ERFMG_008.

ENDCASE.

AT END OF ROW.

APPEND RECORD1.

CLEAR RECORD1.

ENDAT.

ENDLOOP.

Filling the field catelog..

w_fieldcat-tabname = RECORD1.

w_fieldcat-fieldname = 'Here Field1 NAME'.

w_fieldcat-outputlen = '6'.

w_fieldcat-col_pos = '1'.

w_fieldcat-row_pos = '1'.

w_fieldcat-seltext_l = c_seltext_l16.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-tabname = RECORD1.

w_fieldcat-fieldname = 'Here Field2 NAME'.

w_fieldcat-do_sum = c_x.

w_fieldcat-outputlen = '13'.

w_fieldcat-col_pos = '2'.

w_fieldcat-row_pos = '1'.

w_fieldcat-seltext_l = c_seltext_l1.''Here output display column name

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

Like you assign all internal table fields to field catelog

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = 'PROGRAME NAME'

it_fieldcat = i_fieldcat[]

TABLES

t_outtab = RECORD1.

Pls. reward if useful...

Read only

Former Member
0 Likes
503

Thanks for the reply and the sample code. It was helpful.