06-01-2006 6:02 PM
hello everyone,
I am using the function module: ALSM_EXCEL_TO_INTERNAL_TABLE to upload the excel file. In this, my internal table is defined as type 'table of <b>alsmex_tabline</b> with header line.'
But <b>alsmex_tabline</b> only takes max. value of 50 characters. I am getting 80 characters in my excel file for one of the columns. So 30 characters are being truncated.
Is there any other table which I can use so that characters don't get truncated after 50?
Thanks in advance.
Regards,
Fred.
06-01-2006 6:22 PM
Fred, you can not use any other table type other than ALSMEX_TABLINE because it is defined as such in the FM signature. The only way that you might be able to get around this limitation, is to copy the function module, create a new structure like ALSMEX_TABLINE, but have the 80 characters instead of the 50. Test it out, if all of your characters are coming, then that's it. If not, you may have to tweak some of the code in the function module to allow for the other 30 characters.
Regards,
Rich Heilman
06-01-2006 6:22 PM
Fred, you can not use any other table type other than ALSMEX_TABLINE because it is defined as such in the FM signature. The only way that you might be able to get around this limitation, is to copy the function module, create a new structure like ALSMEX_TABLINE, but have the 80 characters instead of the 50. Test it out, if all of your characters are coming, then that's it. If not, you may have to tweak some of the code in the function module to allow for the other 30 characters.
Regards,
Rich Heilman
06-01-2006 6:39 PM
Hi,
try out this function module given in this link:
http://www.sapdevelopment.co.uk/file/file_upexcel.htm
regards
srikanth
06-01-2006 6:48 PM
Hey Fred. I just spent a little time checking it out. You can do as I suggested early, copying the function module and making the adjustments.. I also created this program which uses all of the code in the function module, but it is implemented as a PERFORM. This way you don't have to copy the function module and make changes. Either way is good though.
report zrich_0001 .
types: begin of tintern,
row(4) type n,
col(4) type n,
<b> value(80) type c,</b>
end of tintern.
TYPES: ty_d_itabvalue TYPE <b>tintern-value,</b>
ty_t_itab TYPE <b>tintern</b> OCCURS 0,
begin of ty_s_senderline,
line(4096) type c,
end of ty_s_senderline,
ty_t_sender type ty_s_senderline occurs 0.
constants: gc_hex_tab type x value 9,
gc_esc value '"'.
data: iexcel type table of tintern with header line.
parameters: p_file type localfile,
p_bcol type i default 1,
p_brow type i default 1,
p_ecol type i default 99 ,
p_erow type i default 99.
perform upload_excel tables iexcel
using p_file p_bcol p_brow
p_ecol p_erow.
loop at iexcel.
write:/ iexcel-row, iexcel-col, iexcel-value.
endloop.
*---------------------------------------------------------------------*
* FORM upload_excel *
*---------------------------------------------------------------------*
form upload_excel tables intern
using filename i_begin_col i_begin_row
i_end_col i_end_row.
type-pools: ole2.
data: excel_tab type ty_t_sender.
data: ld_separator type c.
data: application type ole2_object,
workbook type ole2_object,
range type ole2_object,
worksheet type ole2_object.
data: h_cell type ole2_object,
h_cell1 type ole2_object.
field-symbols: <field>.
* Makro für Fehlerbehandlung der Methods
define m_message.
case sy-subrc.
when 0.
when 1.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
when others. raise upload_ole.
endcase.
end-of-definition.
* check parameters
*if i_begin_row > i_end_row. raise inconsistent_parameters. endif.
*if i_begin_col > i_end_col. raise inconsistent_parameters. endif.
* set seperator. Direct move is not sufficient (cause of hex type)
assign ld_separator to <field> type 'X'.
<field> = gc_hex_tab.
* open file in Excel
if application-header = space or application-handle = -1.
create object application 'Excel.Application'.
m_message.
endif.
call method of application 'Workbooks' = workbook.
m_message.
call method of workbook 'Open' exporting #1 = filename.
m_message.
* set property of application 'Visible' = 1.
* m_message.
get property of application 'ACTIVESHEET' = worksheet.
m_message.
* mark whole spread sheet
call method of worksheet 'Cells' = h_cell
exporting #1 = i_begin_row #2 = i_begin_col.
m_message.
call method of worksheet 'Cells' = h_cell1
exporting #1 = i_end_row #2 = i_end_col.
m_message.
call method of worksheet 'RANGE' = range
exporting #1 = h_cell #2 = h_cell1.
m_message.
call method of range 'SELECT'.
m_message.
* copy marked area (whole spread sheet) into Clippboard
call method of range 'COPY'.
m_message.
* Without control flush, CLPB_IMPORT does not find any data
call function 'CONTROL_FLUSH'
exceptions
others = 3.
* read clipboard into ABAP
call function 'CLPB_IMPORT'
tables
data_tab = excel_tab
exceptions
clpb_error = 1
others = 2.
if sy-subrc <> 0.
message a037(alsmex).
endif.
perform separated_to_intern_convert
tables excel_tab intern
using ld_separator.
* clear clipboard
refresh excel_tab.
call function 'CLPB_EXPORT'
tables
data_tab = excel_tab
exceptions
clpb_error = 1
others = 2.
* quit Excel and free ABAP Object - unfortunately, this does not kill
* the Excel process
call method of application 'QUIT'.
m_message.
free object application.
m_message.
endform.
*---------------------------------------------------------------------*
* FORM separated_to_intern_convert *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> I_TAB *
* --> I_INTERN *
* --> I_SEPARATOR *
*---------------------------------------------------------------------*
form separated_to_intern_convert tables i_tab type ty_t_sender
i_intern type ty_t_itab
using i_separator type c.
data: l_sic_tabix like sy-tabix,
l_sic_col type kcd_ex_col.
data: l_fdpos like sy-fdpos.
refresh i_intern.
loop at i_tab.
l_sic_tabix = sy-tabix.
l_sic_col = 0.
while i_tab ca i_separator.
l_fdpos = sy-fdpos.
l_sic_col = l_sic_col + 1.
perform line_to_cell_separat tables i_intern
using i_tab l_sic_tabix l_sic_col
i_separator l_fdpos.
endwhile.
if i_tab <> space.
clear i_intern.
i_intern-row = l_sic_tabix.
i_intern-col = l_sic_col + 1.
i_intern-value = i_tab.
append i_intern.
endif.
endloop.
endform. " SEPARATED_TO_INTERN_CONVERT
FORM line_to_cell_separat TABLES i_intern type ty_t_itab
USING i_line
i_row LIKE sy-tabix
ch_cell_col TYPE kcd_ex_col
i_separator TYPE c
i_fdpos LIKE sy-fdpos.
DATA: l_string TYPE ty_s_senderline.
DATA l_sic_int TYPE i.
CLEAR i_intern.
l_sic_int = i_fdpos.
i_intern-row = i_row.
l_string = i_line.
i_intern-col = ch_cell_col.
* csv Dateien mit separator in Zelle: --> ;"abc;cd";
IF ( i_separator = ';' OR i_separator = ',' ) AND
l_string(1) = gc_esc.
PERFORM line_to_cell_esc_sep USING l_string
l_sic_int
i_separator
i_intern-value.
ELSE.
IF l_sic_int > 0.
i_intern-value = i_line(l_sic_int).
ENDIF.
ENDIF.
IF l_sic_int > 0.
APPEND i_intern.
ENDIF.
l_sic_int = l_sic_int + 1.
i_line = i_line+l_sic_int.
ENDFORM.
*---------------------------------------------------------------------*
FORM line_to_cell_esc_sep USING i_string
i_sic_int TYPE i
i_separator TYPE c
i_intern_value type ty_d_itabvalue .
DATA: l_int TYPE i,
l_cell_end(2).
FIELD-SYMBOLS: <l_cell>.
l_cell_end = gc_esc.
l_cell_end+1 = i_separator .
IF i_string CS gc_esc.
i_string = i_string+1.
IF i_string CS l_cell_end.
l_int = sy-fdpos.
ASSIGN i_string(l_int) TO <l_cell>.
i_intern_value = <l_cell>.
l_int = l_int + 2.
i_sic_int = l_int.
i_string = i_string+l_int.
ELSEIF i_string CS gc_esc.
* letzte Celle
l_int = sy-fdpos.
ASSIGN i_string(l_int) TO <l_cell>.
i_intern_value = <l_cell>.
l_int = l_int + 1.
i_sic_int = l_int.
i_string = i_string+l_int.
l_int = strlen( i_string ).
IF l_int > 0 . MESSAGE x001(kx) . ENDIF.
ELSE.
MESSAGE x001(kx) . "was ist mit csv-Format
ENDIF.
ENDIF.
ENDFORM.
Regards,
Rich Heilman
06-01-2006 7:08 PM
11-21-2006 10:50 AM
Hi fellows,
I have tried out this piece of code on EC5 version of R/3 and am getting a Unicode related error. This occurs at the following line of code:
set seperator. Direct move is not sufficient (cause of hex type)
assign ld_separator to <field> type 'X'.
<field> = c_hex_tab.
The character/separator conversion for # is interpreted differently as something else and because it's used at some logic that populates my internal table, I then end up with junk data in my internal table. The output is as follows:
Excel Upload test
0001 0001 Column_Start#############
0002 0001 Accounting SpreadSheet Up-load#############
0003 0001 Record Type = 1#Transaction Code#Document Type#Company Code#Posting Date##Docume
0004 0001 Header_start#BBKPF-TCODE#BKPF-BLART#BKPF-BUKRS#BKPF-BUDAT##BKPF-BLDAT#BKPF-XBLNR
0005 0001 Record Type = 2#Posting Key#Account#Amount in Doc Curr#Amount in Local Currency#
0006 0001 Line_start#RF05A-NEWBS#RF05A-NEWKO#BSEG-WRBTR#BSEG-DMBTR#BSEG-DMBE2#BSEG-ZUONR#B
0007 0001 1#FB01#ZA#1200#2006-03-30##2006-03-30#MARCH 2006#TIME OFFICE DEDUCTIONS, Jnl 1/4
0008 0001 2#40#343400#-101 406.69########SUSPENSE REVERSALL-92314 CAT 3-8 WPL##
Any ideas please
11-21-2006 10:50 AM
Hi fellows,
I have tried out this piece of code on EC5 version of R/3 and am getting a Unicode related error. This occurs at the following line of code:
set seperator. Direct move is not sufficient (cause of hex type)
assign ld_separator to <field> type 'X'.
<field> = c_hex_tab.
The character/separator conversion for # is interpreted differently as something else and because it's used at some logic that populates my internal table, I then end up with junk data in my internal table. The output is as follows:
Excel Upload test
0001 0001 Column_Start#############
0002 0001 Accounting SpreadSheet Up-load#############
0003 0001 Record Type = 1#Transaction Code#Document Type#Company Code#Posting Date##Docume
0004 0001 Header_start#BBKPF-TCODE#BKPF-BLART#BKPF-BUKRS#BKPF-BUDAT##BKPF-BLDAT#BKPF-XBLNR
0005 0001 Record Type = 2#Posting Key#Account#Amount in Doc Curr#Amount in Local Currency#
0006 0001 Line_start#RF05A-NEWBS#RF05A-NEWKO#BSEG-WRBTR#BSEG-DMBTR#BSEG-DMBE2#BSEG-ZUONR#B
0007 0001 1#FB01#ZA#1200#2006-03-30##2006-03-30#MARCH 2006#TIME OFFICE DEDUCTIONS, Jnl 1/4
0008 0001 2#40#343400#-101 406.69########SUSPENSE REVERSALL-92314 CAT 3-8 WPL##
Any ideas please
11-21-2006 10:51 AM
Hi fellows,
I have tried out this piece of code on EC5 version of R/3 and am getting a Unicode related error. This occurs at the following line of code:
set seperator. Direct move is not sufficient (cause of hex type)
assign ld_separator to <field> type 'X'.
<field> = c_hex_tab.
The character/separator conversion for # is interpreted differently as something else and because it's used at some logic that populates my internal table, I then end up with junk data in my internal table. The output is as follows:
Excel Upload test
0001 0001 Column_Start#############
0002 0001 Accounting SpreadSheet Up-load#############
0003 0001 Record Type = 1#Transaction Code#Document Type#Company Code#Posting Date##Docume
0004 0001 Header_start#BBKPF-TCODE#BKPF-BLART#BKPF-BUKRS#BKPF-BUDAT##BKPF-BLDAT#BKPF-XBLNR
0005 0001 Record Type = 2#Posting Key#Account#Amount in Doc Curr#Amount in Local Currency#
0006 0001 Line_start#RF05A-NEWBS#RF05A-NEWKO#BSEG-WRBTR#BSEG-DMBTR#BSEG-DMBE2#BSEG-ZUONR#B
0007 0001 1#FB01#ZA#1200#2006-03-30##2006-03-30#MARCH 2006#TIME OFFICE DEDUCTIONS, Jnl 1/4
0008 0001 2#40#343400#-101 406.69########SUSPENSE REVERSALL-92314 CAT 3-8 WPL##
Any ideas please