on 12-01-2009 2:29 PM
Hi Everyone,
I am unable to upload the excel file (.xls).
Its uploading in different format like this ## ࡱ #.
May be this the problem of conversion from XSTRING to STRING.
I am able to upload tab separeted TEXT (.txt) file but not excel file.
For conversion purpose i tried.
TRY.
CALL METHOD cl_abap_conv_in_ce=>create
EXPORTING
input = l_xstring
RECEIVING
conv = l_convin.
CALL METHOD l_convin->read
IMPORTING
data = l_string.
CATCH cx_root.
ENDTRY.
and
CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
EXPORTING
in_xstring = l_xstring
IMPORTING
out_string = l_string.
and
LXE_COMMON_XSTRING_TO_STRING
if any one have solution other than above .
please reply
Regards,
Sandeep Patel
Hi Patel,
We faced the similar problem in SAP netweaver 7.0 system and finally ended up in going for the flat file conversion.
Also tried opening the excel directly using the Microsoft Excel UI element from the WDA but it also resulted in the same conversion Problem.
Thanks,
Rajkumar.S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Sandeep ,
u proceed as follows :
1 read the table's data into an internal table using get_static_attributes_table
2. Convert Xstring to String data using FM HR_KR_XSTRING_TO_STRING
3. Now split the string at new line so as to make an internal table .
using cl_abap_char_utilities=>newline utility
4.now loop at the internal table and separate the content of this table separated by tab.
using cl_abap_char_utilities=>horizontal_tab
the following code cn help u :
DATA: lv_node TYPE REF TO if_wd_context_node,
lt_mara TYPE if_main=>elements_mara,
wa_mara TYPE if_main=>element_mara,
lead_selection_index TYPE i,
mara_string TYPE string,
mara_xstring TYPE xstring.
lv_node = wd_context->get_child_node( name = 'MARA' ).
CALL METHOD lv_node->get_static_attributes_table
IMPORTING
table = lt_mara.
LOOP AT lt_mara INTO wa_mara.
CONCATENATE mara_string
wa_mara-matnr
wa_mara-ersda
wa_mara-ernam
wa_mara-matkl
wa_mara-meins
cl_abap_char_utilities=>cr_lf INTO mara_string
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
ENDLOOP.
** Now you need to add the column headers & the desired extra information through coding to
** mara_string
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = mara_string
IMPORTING
buffer = mara_xstring.
CL_WD_RUNTIME_SERVICES=>attach_file_to_response( i_filename = 'TEMP.XLS'
i_content = mara_xstring
i_mime_type = 'EXCEL' ).
rgds,
amit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Amit,
first u decide what exaclty you want convey .
In steps you mention the xstring to string conversion(step 2) with FM HR_KR_XSTRING_TO_STRING before split.
In code you are doing different thing with different FM 'SCMS_STRING_TO_XSTRING'.
I think this FM 'SCMS_STRING_TO_XSTRING' convert from string to xstring but our requirment is opposite.
so please check & post and if posible test the code and post.
Regards,
Sandeep
hi Sandeep ,
i tried this one but not able get desired result.
i think this problem with not only with me .
lots of people faceing the same problem i come to know when search the forum.
{ they able upload the tab seperated file(.txt) but not the excel file(.xls) }
sandeep , pls convert ur excel file to tab delimted text first using the utilities cl_abap_char_utilities=>newline and cl_abap_char_utilities=>horizontal_tab
DATA : i_data TYPE STANDARD TABLE OF string,
fields TYPE string_table,
lv_field TYPE string.
SPLIT lv_string AT cl_abap_char_utilities=>newline INTO TABLE i_data.
* Bind With table Element.
LOOP AT i_data INTO lv_string.
SPLIT lv_string AT cl_abap_char_utilities=>horizontal_tab INTO TABLE fields.
ENDLOOP.
rgds,
amit
Hi Amit,
I tried all this thing which you mention now and earlier.
For your information here is my code
TYPES :
BEGIN OF str_itab,
name TYPE string,
id TYPE string,
status TYPE string,
END OF str_itab.
DATA:
t_table1 TYPE STANDARD TABLE OF str_itab.
DATA:
i_data TYPE STANDARD TABLE OF string,
l_string TYPE string,
fs_table TYPE str_itab,
l_xstring TYPE xstring,
fields TYPE string_table,
lv_field TYPE string.
DATA:
t_table TYPE if_main=>elements_data_tab,
data_table TYPE if_main=>elements_data_tab.
* get single attribute
wd_context->get_attribute( EXPORTING
name = `DATASOURCE`
IMPORTING value = l_xstring ).
CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
EXPORTING
in_xstring = l_xstring
IMPORTING
out_string = l_string.
* DATA:
* l_convin TYPE REF TO cl_abap_conv_in_ce,
* l_msgstr TYPE string.
* TRY.
* CALL METHOD cl_abap_conv_in_ce=>create
* EXPORTING
** encoding = im_encoding "optional
* input = l_xstring
* RECEIVING
* conv = l_convin.
*
* CALL METHOD l_convin->read
* IMPORTING
* data = l_string.
* CATCH cx_root.
* ENDTRY.
SPLIT l_string AT cl_abap_char_utilities=>newline INTO TABLE i_data.
LOOP AT i_data INTO l_string.
SPLIT l_string AT cl_abap_char_utilities=>horizontal_tab INTO
TABLE fields.
READ TABLE fields INTO lv_field INDEX 1.
fs_table-name = lv_field.
READ TABLE fields INTO lv_field INDEX 2.
fs_table-id = lv_field.
READ TABLE fields INTO lv_field INDEX 3.
fs_table-status = lv_field.
APPEND fs_table TO t_table1.
ENDLOOP.
DATA lo_nd_data_tab TYPE REF TO if_wd_context_node.
DATA lo_el_data_tab TYPE REF TO if_wd_context_element.
DATA ls_data_tab TYPE wd_this->element_data_tab.
* navigate from <CONTEXT> to <DATA_TAB> via lead selection
lo_nd_data_tab = wd_context->get_child_node( name =
wd_this->wdctx_data_tab ).
* Bind With table Element.
CALL METHOD lo_nd_data_tab->bind_table
EXPORTING
new_items = t_table1.
Thanks & Regards,
Sandeep
>they able upload the tab seperated file(.txt) but not the excel file(.xls)
That's correct. The above approaches only work when you file has been saved into a text format (text tab delimited or CSV or something like that). The native, binary XLS format is Microsoft propriatery and can't be processed directly in ABAP. There is no function module or class that can read this native format from the server side.
You have to consider either saving the Excel file into a text based format or using a newer version of Excel that uses the XML based file format. This format is then still technically still text based since it is XML. You can use any the XML parsing techniques in ABAP (Simple Transformation, XSLT, iXML, etc) to process the file.
Hi All,
I am trying to upload .xls file into my webdynpro application, I am facing some issue even though I am using the FM:'HR_KR_XSTRING_TO_STRING' ,-> my .xls file data is converting into text format, getting some garbage data.
My code is similar like below:
METHOD onactionon_upload .
TYPES : BEGIN OF str_itab,
name(10) TYPE c,
age(10) TYPE c,
END OF str_itab. DATA : t_table1 TYPE STANDARD TABLE OF str_itab,
i_data TYPE STANDARD TABLE OF string,
l_string TYPE string,
fs_table TYPE str_itab,
l_xstring TYPE xstring,
fields TYPE string_table,
lv_field TYPE string.
DATA : t_table TYPE if_main=>elements_data_tab,
data_table TYPE if_main=>elements_data_tab.
get single attribute
wd_context->get_attribute(
EXPORTING
name = `DATASOURCE`
IMPORTING
value = l_xstring ).
CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
EXPORTING
in_xstring = l_xstring
IMPORTING
out_string = l_string.
SPLIT l_string AT cl_abap_char_utilities=>newline INTO TABLE i_data.
Bind With table Element.
LOOP AT i_data INTO l_string.
SPLIT l_string AT cl_abap_char_utilities=>horizontal_tab INTO TABLE fields.
READ TABLE fields INTO lv_field INDEX 1.
fs_table-name = lv_field.
READ TABLE fields INTO lv_field INDEX 2.
fs_table-age = lv_field.
APPEND fs_table TO t_table1. "Append to the internal table
ENDLOOP.
Could you please help me...how to upload the .xls file into webdynro.
But I am able to upload .txt and .csv...but my client need only .xls file need to upload.
any idea on this.
Regards,
Naresh Kumar.
>But I am able to upload .txt and .csv...but my client need only .xls file need to upload.
it is unfortunate but you cannot do this. the XLS format is owned by Microsoft and is a closed format - you'd need a specially built and licensed application to load it. SAP does not have one of these.
Newer MS Excel versions are saving files in XLSX format by default which is an open format. There may soon be ways to read these into SAP.
However, you cannot read XLS files directly into SAP. Sorry - it doesn't support this.
Thomas Jung has already made much the same point earlier in the thread. Please do, at least, read the thread before posting.
Thanks,
Chris
Hi Everyone,
I am sure that this issue can be solved .
may be some function module is there.
Moderator will help on this issue.
Thanks & Regards
Sandeep Patel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
25 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.