Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert unicode to Non unicode

Former Member
0 Kudos
8,934

Hi Team,

We have one option to convert Unicode to Non Unicode in the open data set statement. But my requirement is with out writing a data into file ,i need to convert from unicode data to non Unicode data in internal table level and sent this data to mail attachment .

Please help me to clarify my doubt.

How to convert the Unicode internal table data to non-Unicode interna; table data.

Thanks & Regards,

Srikanth

8 REPLIES 8

Former Member
0 Kudos
1,574

Try this object:

cl_abap_conv_in_ce

It alows you to convert from one encoding into an other:

data: lc_conv type ref to cl_abap_conv_in_ce.

  • Convert to UC SAP internal from UTF-8

lc_conv = cl_abap_conv_in_ce=>create(

encoding = 'UTF-8' " You can use here what you need

endian = 'L' ).

lc_conv->convert( exporting input = l_xstring

importing data = l_string ).

0 Kudos
1,574

Hi ,

Thanks For your reply.But i have one more doubt regarding this same issue.

I have implimented the code in my program and the encoding is 'ASC'.

I want to convert the text into ascii.

I got the dump.Please provide the encoding name of ASCII type.

Thanks & Regards,

Sri

0 Kudos
1,574

Hi:

These are the ABAP Classes available for Code Page conversions...

CL_ABAP_CONV_IN_CE ==> Conversion between "Any Code Page to System Code Page".

CL_ABAP_CONV_OUT_CE ==> Conversion between "System Code Page to Any Code Page".

CL_ABAP_CONV_X2X_CE ==> Conversion between "Any Code Page to Any Code Page".

For you case you can use the Last two.

Hope this helps.

Former Member
0 Kudos
1,574

Hi

Depending which characterset your result should be, you most likely need 1103 or 1102 as the character encoding to get your 'ASCII'.

So the code must look like this:

data: conv type ref to cl_abap_conv_out_ce.

conv = cl_abap_conv_out_ce=>create( encoding = '1103' ).

try.

call method conv->write( data = yourstring ).

catch CX_SY_CONVERSION_CODEPAGE.

  • If you want to know the error

endtry.

xbuffer = conv->get_buffer( ).

then you need to put into a string variable from xstring.

Rene

0 Kudos
1,574

Hi Rene,

As per your suggestion I have implement the code to convert the Unicode format to non-Unicode format and the data is converted properly .The Non-Unicode internal table data has passed into function module u201CSO_NEW_DOCUMENT_ATT_SEND_API1u201D .This function module should send non-Unicode file to external environment.

But when external environment is receiving data, they get the data into Unicode format.

So please help me to send the non-Unicode data to external environment through attachment.

Thanks & Regards,

Sri.

0 Kudos
1,574

I can help you, but I need to see the code you use to call the function SO_NEW_DOCUMENT_ATT_SEND_API1.

If you want to keep the encoding, you should send the data as binary and not text as you probably do now.

Rene

0 Kudos
1,574

Hi Rene ,

I have written the bellow code to send the non Unicode data to external system through mail. But this code is not working. The attachment shows as Unicode data

It_objbin1 having the complete data of attachment. Please check the code and suggest how to send the non-Unicode data through email attachment.

Please correct me to send the non-Unicode data to mail ....

****************Sample code ************

it_objbin1[] = it_objbin[].

Free it_objbin.

loop at it_objbin1.

l_string = it_objbin1-line.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

TEXT = l_string

  • MIMETYPE = ' '

  • ENCODING =

IMPORTING

BUFFER = l_xstring

EXCEPTIONS

FAILED = 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.

lc_conv = cl_abap_conv_in_ce=>create( encoding = '1103' ).

lc_conv->convert( exporting input = l_xstring

importing data = l_string1 ).

it_objbin-line = l_string1.

it_objbin-line = l_xstring.

append it_objbin.

*---setting name of file for csv

w_filename = 'OTM Successfull Invoices.xls'.

IF s_email IS NOT INITIAL.

  • build body of message

CONCATENATE 'Please find the attached successfull posting invoices document for your reference' ' ' INTO it_objtxt

SEPARATED BY space.

APPEND it_objtxt.

CLEAR it_objtxt.

it_reclist-receiver = ws_email.

it_reclist-rec_type = 'U'.

it_reclist-express = ' '.

it_reclist-com_type = 'INT'.

APPEND it_reclist.

*--Set title of object and email

CLEAR: w_text.

doc_chng-obj_descr = 'OTM Successfull Invoices'.

doc_chng-obj_name = 'OTM Successfull Invoices'.

ENDIF.

    • create the control table entry for the main email

DESCRIBE TABLE it_objtxt LINES tab_lines.

CLEAR it_objpack-transf_bin.

it_objpack-head_start = 1.

it_objpack-head_num = 0.

it_objpack-body_start = 1.

it_objpack-body_num = tab_lines.

it_objpack-doc_type = 'RAW'.

READ TABLE it_objtxt INDEX tab_lines.

it_objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_objtxt ).

APPEND it_objpack.

*Convert to correct format adding the carrage return with new line for every end of the line

CALL FUNCTION 'SO_RAW_TO_RTF'

TABLES

objcont_old = it_objbin

objcont_new = it_objbin.

PERFORM ASCII_CONVERSION.

DESCRIBE TABLE it_objbin LINES tab_lines.

it_objpack-head_start = 1.

it_objpack-head_num = 0.

it_objpack-body_start = 1.

it_objpack-body_num = tab_lines.

it_objpack-transf_bin = 'X'.

it_objpack-doc_type = 'XLS'.

it_objpack-obj_descr = w_filename.

it_objpack-OBJ_LANGU = 'E'.

READ TABLE it_objbin INDEX tab_lines.

it_objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_objbin ).

APPEND it_objpack.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

  • PUT_IN_OUTBOX =

commit_work = 'X'

TABLES

packing_list = it_objpack

  • object_header = it_objhead

contents_bin = it_objbin

contents_txt = it_objtxt

receivers = it_reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

Thanks & Regards,

Sri

0 Kudos
1,574

Hi

I am not sure I follow any longer what you want to do. here is part of your code changed:


  LOOP AT it_objbin1.
    CONCATENATE l_string it_objbin1-line INTO l_string.
  ENDLOOP.

  lc_conv = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' ).
  lc_conv->write( data   = l_string ).
  l_xstring = lc_conv->get_buffer( ).

  it_objbin = cl_document_bcs=>string_to_soli( ip_string = l_xstring  ).

To realy help you I need to understand what the orginal text is and what result you want in the email.

It looks like you convert and convert again and add linefeeds, so I am not sure with what you started and where you want to end up.