‎2008 Jul 28 11:57 AM
Hi Friends,
I have an Excel file in my desktop. I want this to be transfered to a table in the Development Server.
Kindly guide me to to do this.
TIA.
Regards,
Mark K
‎2008 Jul 28 12:00 PM
Hi
Use the function module 'ALSM_EXCEL_TO_INTERNAL_TABLE'
just go through the following code... this would give you idea
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = p_file
i_begin_col = 1
i_begin_row = 1
i_end_col = 5
i_end_row = 4
tables
intern = t_tab
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 t_tab.
assign component t_tab-col of structure t_mara to <fs_mara>.
write t_tab-value to <fs_mara>.
at end of row.
append t_mara.
endat.
endloop.regards
padma
‎2008 Jul 28 12:00 PM
Hi
Use the function module 'ALSM_EXCEL_TO_INTERNAL_TABLE'
just go through the following code... this would give you idea
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = p_file
i_begin_col = 1
i_begin_row = 1
i_end_col = 5
i_end_row = 4
tables
intern = t_tab
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 t_tab.
assign component t_tab-col of structure t_mara to <fs_mara>.
write t_tab-value to <fs_mara>.
at end of row.
append t_mara.
endat.
endloop.regards
padma
‎2008 Jul 28 12:02 PM
hi,
Upload the excel file data on to internal table and loop through the internal table to populate on to the required databased table using INSERT statement .. Check out the below link to get the data on to internal table from excel ..
‎2008 Jul 28 12:04 PM
‎2008 Jul 28 12:17 PM
Hi,
Calling this function module you can select the file
call function 'F4_FILENAME'
exporting
field_name = gc_file_idoc
importing
file_name = p_idoc.
And Using this function module u can fetch the contenets of the excel sheet to internal table
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = p_job
i_begin_col = lc_col1
i_begin_row = lc_row1
i_end_col = lc_col2
i_end_row = lc_row2
tables
intern = gt_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.
Hope its helpful
Regards,
Bhanu
‎2008 Jul 28 1:52 PM
Hi,
In this program in 7th row have the data,
so where your data start from that row and column have to specify.
DATA: i_h_str TYPE TABLE OF h_str ,
i_im_str TYPE TABLE OF im_str ,
wa_h_str TYPE h_str ,
wa_im_str TYPE im_str .
DATA: i_excel TYPE TABLE OF alsmex_tabline ,
wa_excel TYPE alsmex_tabline .
DATA : ind TYPE int4.
DATA: row1 TYPE int4 ,
col1 TYPE int4 .
PARAMETERS: fname TYPE localfile .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR fname .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
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 = 90
i_end_row = 65000
TABLES
intern = i_excel
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 i_excel INTO wa_excel.
row1 = wa_excel-row .
col1 = wa_excel-col .
READ TABLE i_excel INTO wa_excel WITH KEY row = row1 col = col1 .
IF sy-subrc = 0 .
IF wa_excel-col = 1 AND wa_excel-row < 6.
wa_h_str-dt = wa_excel-value .
ELSEIF wa_excel-col = 2 AND wa_excel-row < 6.
wa_h_str-dr = wa_excel-value .
ELSEIF wa_excel-col = 1 AND wa_excel-row > 6 .
wa_im_str-pk = wa_excel-value .
ELSEIF wa_excel-col = 2 AND wa_excel-row > 6 .
wa_im_str-acc = wa_excel-value .
ELSEIF wa_excel-col = 3 AND wa_excel-row > 6 .
wa_im_str-amo = wa_excel-value .
ELSEIF wa_excel-col = 4 AND wa_excel-row > 6 .
wa_im_str-taxa = wa_excel-value .
ELSEIF wa_excel-col = 5 AND wa_excel-row > 6 .
wa_im_str-taxc = wa_excel-value .
ELSEIF wa_excel-col = 6 AND wa_excel-row > 6 .
wa_im_str-ord = wa_excel-value .
ENDIF .
ENDIF .
AT END OF row .
IF row1 < 6 .
APPEND wa_h_str TO i_h_str .
CLEAR: WA_H_STR .
ELSEIF row1 > 5 .
APPEND wa_im_str TO i_im_str .
CLEAR: WA_IM_STR .
ENDIF .
ENDAT.
CLEAR: wa_im_str.
ENDLOOP.
LOOP AT i_im_str INTO wa_im_str .
W_UPLOAD-NEWBS = WA_IM_STR-PK.
W_UPLOAD-NEWKO = WA_IM_STR-ACC.
W_UPLOAD-WRBTR = wa_im_str-amo.
APPEND W_UPLOAD TO T_UPLOAD.
CLEAR W_UPLOAD.
endloop.
Thanking you.
Subash
‎2008 Jul 29 5:59 AM
Hi
Try the transcation code "CG3Z" to upload a file to Application server.
Hope it helps.
Murthy
‎2008 Jul 29 6:03 AM
Hi!
Check out this sample code
REPORT z_file3.
DATA: fname(40),
w_line TYPE i VALUE 1,
w_file TYPE rlgrap-filename.
DATA:
t_tab LIKE
TABLE OF ALSMEX_TABLINE
WITH HEADER LINE.
DATA: fs_tab LIKE LINE OF t_tab.
w_file = 'C:\Documents and Settings\ABC\Desktop\Book1.xls'.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = w_file
i_begin_col = 1
i_begin_row = 1
i_end_col = 10
i_end_row = 100
tables
intern = t_tab
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.
ELSE.
WRITE: 'UPLOAD SUCCESSFUL'.
ENDIF.
fname = '.\z_file.xls'.
OPEN DATASET fname FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT t_tab INTO fs_tab.
TRANSFER fs_tab TO fname.
ENDLOOP.
IF sy-subrc EQ 0.
WRITE: / 'FILE OPENED ON APPS SERVER'.
ELSE.
WRITE: / 'FILE COULD NOT BE OPENED'.
ENDIF.
Regards
Abhijeet