Show TOC

Background documentationCode Page in ICF Locate this document in the navigation structure

 

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.

Syntax Syntax

  1.  DATA: cvto_utf8 TYPE REF TO cl_abap_conv_out_ce.
  2.  DATA: codepage  TYPE string.
  3.  DATA: html_text TYPE string.
  4.  DATA: html_utf8 TYPE xstring
  5.  codepage = server->request->get_form_field( 'codepage' ).
  6.      IF codepage = '1'.
  7.       TRY.
  8.           CALL METHOD cl_abap_conv_out_ce=>create
  9.             EXPORTING
  10.               encoding = 'UTF-8'
  11.             RECEIVING
  12.               conv     = cvto_utf8.
  13.         CATCH cx_parameter_invalid_range .
  14.         CATCH cx_sy_codepage_converter_init .
  15.       ENDTRY.
  16.       CALL METHOD server->response->set_header_field(
  17.              name  = 'Content-Type'                         "#EC NOTEXT
  18.               value = 'text/html; charset=utf-8' ).
  19.       TRY.
  20.           CALL METHOD cvto_utf8->write
  21.             EXPORTING
  22.               data = html_text.
  23.         CATCH cx_sy_codepage_converter_init .
  24.         CATCH cx_sy_conversion_codepage .
  25.         CATCH cx_parameter_invalid_type .
  26.         CATCH cx_parameter_invalid_range .
  27.       ENDTRY.
  28. * conversion into UTF-8 unicode code page
  29.       html_utf8 = cvto_utf8->get_buffer( ).
  30. * set body as hexadecimal string
  31.       CALL METHOD server->response->set_data( data = html_utf8 ).
  32.     ELSE.
  33. *   automatic conversion of SAP_UC to utf-8 in a unicode system
  34.       CALL METHOD server->response->set_header_field(
  35.          name  = 'Content-Type' 
  36.          value = 'text/html' ).
  37.       CALL METHOD server->response->set_cdata( data = html_text ).
  38.     ENDIF.
End of the code.

More Information

For general information on code pages, see: