on 2011 Nov 14 7:05 AM
HI All ,
i have created a web dynpro application for Uploading excel . Now i am not getting any workaround to convert X STRING to STRING . In SAP there is a FM HR_KR_XSTRING_TO_STRING but its not there in SRM so when i tried to copy the same in SRM and try to convert its getting converted in Junk characters . Please help me out in this .
Regards
Shankar
Request clarification before answering.
Hello Shankar,
Please find the code below:-
get single attribute
lo_el_upload_content->get_attribute(
EXPORTING
name = `FILE_CONTENT`
IMPORTING
value = lv_file_content ).
CALL FUNCTION 'SCP_CODEPAGE_BY_EXTERNAL_NAME'
EXPORTING
external_name = 'ISO-8859-1'
kind = 'H'
IMPORTING
sap_codepage = lv_codepage
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
lv_codepage = '1100'
ENDIF.
Converting the file contents to String
CALL FUNCTION 'LXE_COMMON_XSTRING_TO_STRING'
EXPORTING
in_xstring = lv_file_content
in_codepage = lv_codepage
IMPORTING
ex_string = lv_string
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc EQ 0.
SPLIT lv_string AT cl_abap_char_utilities=>newline INTO TABLE lt_excel_data.
ENDIF.
Regards,
Neelima
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI Nilema ,
I have tried ur code also but still the same result .
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,
lo_nd_sflight TYPE REF TO if_wd_context_node,
lo_el_sflight TYPE REF TO if_wd_context_element,
l_string TYPE string,
fs_table TYPE str_itab,
l_xstring TYPE xstring,
fields TYPE string_table,
lv_field TYPE string,
lv_codepage TYPE CPCODEPAGE.
DATA : t_table TYPE if_main=>element_datatab,
data_table TYPE if_main=>element_datatab.
get single attribute
break akedia.
wd_context->get_attribute(
EXPORTING
name = `DATASOURCE`
IMPORTING
value = l_xstring ).
CALL FUNCTION 'SCP_CODEPAGE_BY_EXTERNAL_NAME'
EXPORTING
external_name = 'ISO-8859-1'
KIND = 'H'
IMPORTING
SAP_CODEPAGE = lv_codepage
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2
.
IF sy-subrc <> 0.
lv_codepage = '1100'.
ENDIF.
CALL FUNCTION 'LXE_COMMON_XSTRING_TO_STRING'
EXPORTING
in_xstring = l_xstring
IN_CODEPAGE = lv_codepage
EX_CODEPAGE = '0000'
UNMASK_CRLF = ''
IMPORTING
EX_STRING = l_string
EXCEPTIONS
ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
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.
ENDLOOP.
lo_nd_sflight = wd_context->get_child_node( 'DATATAB' ).
lo_nd_sflight->bind_table( t_table1 ).
ENDMETHOD.
Hi,
use the below code to convert form Xstring to string.
data lv_filedata type xstring.
data lv_string type string.
DATA: lo_conv_x2c TYPE REF TO cl_abap_conv_in_ce.
lo_conv_x2c->convert( EXPORTING input = lv_filedata
IMPORTING data = lv_string ).
Regards,
Deviprasad
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ,
Ignore the previous code.i forgot one statement.
data lv_filedata type xstring.
data lv_string type string.
DATA: lo_conv_x2c TYPE REF TO cl_abap_conv_in_ce.
lo_conv_x2c = cl_abap_conv_in_ce=>create( ).
lo_conv_x2c->convert( EXPORTING input = lv_filedata
IMPORTING data = lv_string ).
regards,
Deviprasad
HI Deviprasad ,
Thanks for your reply but its not working its giving a dump .
Runtime Errors CONVT_CODEPAGE
Exception CX_SY_CONVERSION_CODEPAGE
Date and Time 14.11.2011 03:49:55
Short text
A character set conversion is not possible.
What happened?
At the conversion of a text from codepage '4110' to codepage '4103':
- a character was found that cannot be displayed in one of the two
codepages;
- or it was detected that this conversion is not supported
The running ABAP program 'CL_ABAP_CONV_IN_CE============CP' had to be
terminated as the conversion
would have produced incorrect data.
The number of characters that could not be displayed (and therefore not
be converted), is 2542. If this number is 0, the second error case, as
mentioned above, has occurred.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.