Each application must relate the representation of the texts in its response document (in the body of the document) to a suitable code page. The following example shows you how to convert a text into the UTF-8 code page and present it as part of a HTML page. For this purpose, the header field Content Type is set to ‘text/html’ and the character set is set to utf-8. This tells the partner how to represent the HTML text.
DATA: cvto_utf8 TYPE REF TO cl_abap_conv_out_ce. DATA: codepage TYPE string. DATA: html_text TYPE string. DATA: html_utf8 TYPE xstring … codepage = server->request->get_form_field( 'codepage' ). … IF codepage = '1'. TRY. CALL METHOD cl_abap_conv_out_ce=>create EXPORTING encoding = 'UTF-8' RECEIVING conv = cvto_utf8. CATCH cx_parameter_invalid_range . CATCH cx_sy_codepage_converter_init . ENDTRY.
CALL METHOD server->response->set_header_field( name = 'Content-Type' "#EC NOTEXT value = 'text/html; charset=utf-8' ).
TRY. CALL METHOD cvto_utf8->write EXPORTING data = html_text. CATCH cx_sy_codepage_converter_init . CATCH cx_sy_conversion_codepage . CATCH cx_parameter_invalid_type . CATCH cx_parameter_invalid_range . ENDTRY. * conversion into UTF-8 unicode code page html_utf8 = cvto_utf8->get_buffer( ).
* set body as hexadecimal string CALL METHOD server->response->set_data( data = html_utf8 ).
ELSE. * automatic conversion of SAP_UC to utf-8 in a unicode system CALL METHOD server->response->set_header_field( name = 'Content-Type' value = 'text/html' ).
CALL METHOD server->response->set_cdata( data = html_text ). ENDIF.
|
For general information on code pages, see: