02-15-2007 6:26 AM
Hi all
I need to write a program in which I have to read data from Excel spread sheet and write these values in the database table.I have no idea about this.will please explain to me how to do this task.Its very urgent.
Thank you.
Regards
Giri
02-15-2007 6:29 AM
See the following ex:
REPORT ZFI_EXCEL .
*Read the data from the locally held spreadsheet
*Once read using this FM, the data will be held like:-
*ROW |COL |VALUE
*---|-|---
*0001 |0001 |2
*0001 |0002 |00000000001
*0001 |0003 |1
*0001 |0004 |
*0001 |0005 |2
*0001 |00010|SHORT TEXT for a/c
*0001 |00011|LONG TEXT a/c 0000000001
*.
*.
*0002 |0001 |2
*0002 |0002 |00000000002
*0002 |0003 |1
*0002 |0004 |
*0002 |0005 |2
*0002 |00010|SHORT TEXT for a/c
*0001 |00011|LONG TEXT a/c 0000000002
*
*etc........
data: begin of excel_tab occurs 0.
include structure alsmex_tabline.
data: end of excel_tab .
data: begin of itab occurs 0,
bldat like bkpf-bldat,
blart like bkpf-blart,
bukrs like bkpf-bukrs,
budat like bkpf-budat,
waers like bkpf-waers,
bschl like bseg-bschl,
hkont like bseg-hkont,
sgtxt like bseg-sgtxt,
end of itab.
data: process_tab_struct_tmp like itab.
field-symbols: <fs1>.
selection-screen: begin of block blk.
parameters: fname type rlgrap-filename.
selection-screen: end of block blk.
at selection-screen on value-request for fname.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = 'ZFI_EXCEL'
DYNPRO_NUMBER = '1000'
FIELD_NAME = 'FNAME'
IMPORTING
FILE_NAME = FNAME.
START-OF-SELECTION.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = FNAME
i_begin_col = 1
i_begin_row = 1
i_end_col = 24
i_end_row = 60000
tables
intern = EXCEL_TAB
LOOP AT EXCEL_TAB.
assign component excel_tab-col of structure
process_tab_struct_tmp to <fs1>.
<fs1> = excel_tab-value.
at end of row.
move-corresponding: process_tab_struct_tmp to itab. Move values to itab
append itab.
endat.
ENDLOOP.
LOOP AT ITAB.
WRITE:/2 ITAB-BLDAT,14(8) ITAB-BLART,20(10) ITAB-BUDAT.
ENDLOOP.
02-15-2007 6:28 AM
02-15-2007 6:29 AM
See the following ex:
REPORT ZFI_EXCEL .
*Read the data from the locally held spreadsheet
*Once read using this FM, the data will be held like:-
*ROW |COL |VALUE
*---|-|---
*0001 |0001 |2
*0001 |0002 |00000000001
*0001 |0003 |1
*0001 |0004 |
*0001 |0005 |2
*0001 |00010|SHORT TEXT for a/c
*0001 |00011|LONG TEXT a/c 0000000001
*.
*.
*0002 |0001 |2
*0002 |0002 |00000000002
*0002 |0003 |1
*0002 |0004 |
*0002 |0005 |2
*0002 |00010|SHORT TEXT for a/c
*0001 |00011|LONG TEXT a/c 0000000002
*
*etc........
data: begin of excel_tab occurs 0.
include structure alsmex_tabline.
data: end of excel_tab .
data: begin of itab occurs 0,
bldat like bkpf-bldat,
blart like bkpf-blart,
bukrs like bkpf-bukrs,
budat like bkpf-budat,
waers like bkpf-waers,
bschl like bseg-bschl,
hkont like bseg-hkont,
sgtxt like bseg-sgtxt,
end of itab.
data: process_tab_struct_tmp like itab.
field-symbols: <fs1>.
selection-screen: begin of block blk.
parameters: fname type rlgrap-filename.
selection-screen: end of block blk.
at selection-screen on value-request for fname.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = 'ZFI_EXCEL'
DYNPRO_NUMBER = '1000'
FIELD_NAME = 'FNAME'
IMPORTING
FILE_NAME = FNAME.
START-OF-SELECTION.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = FNAME
i_begin_col = 1
i_begin_row = 1
i_end_col = 24
i_end_row = 60000
tables
intern = EXCEL_TAB
LOOP AT EXCEL_TAB.
assign component excel_tab-col of structure
process_tab_struct_tmp to <fs1>.
<fs1> = excel_tab-value.
at end of row.
move-corresponding: process_tab_struct_tmp to itab. Move values to itab
append itab.
endat.
ENDLOOP.
LOOP AT ITAB.
WRITE:/2 ITAB-BLDAT,14(8) ITAB-BLART,20(10) ITAB-BUDAT.
ENDLOOP.
02-15-2007 6:31 AM
Hi Giri ,
Use the FM ALSM_EXCEL_TO_INTERNAL_TABLE this will read your exel file and convert it into an internal table , you then need to map this to your internal tablw which you will use to modify the database table.
Regards
Arun