
- Text to unicode codepoints how to#
- Text to unicode codepoints code#
Loop through the converted UTF-8 text until the end of xstring and parse each each character as per the UTF-8 Bit Distribution Logic shown below. Text to unicode codepoints code#
It’s found that code page 4102 is UTF-16BE Unicode / ISO/IEC 10646.
We can find the details of SAP code page by running the FM SCP_CODEPAGE_INFO. We can find default code page of the system by running the FM RFC_SYSTEM_INFO and checking the exporting parameter RFCSI_EXPORT-RFCCHARTYP. Convert the input string to UTF-8 Hex string (xstring) using ABAP Conversion APIs. Read input Unicode string from selection screen via parameter p_string. SET BIT iv_trgt_bit OF cv_trgt_str TO lv_bit. GET BIT iv_src_bit OF iv_src_str INTO DATA(lv_bit). * Copy HEX bits from source byte to target byteįORM copy_hex_bits USING iv_src_bit TYPE i Lv_unicode_cp = COND #( WHEN p_string+lv_cur_pos(1) IS NOT INITIAL PERFORM conv_utf8_2b USING lv_hex lv_unicode_cp. PERFORM conv_utf8_3b USING lv_hex lv_unicode_cp.ĪSSIGN lv_string_utf8+lv_xstr_idx(4) TO TYPE 'C'. PERFORM conv_utf8_4b USING lv_hex lv_unicode_cp.ĪSSIGN lv_string_utf8+lv_xstr_idx(6) TO TYPE 'C'. * apply codepoint conversion, if necessaryĪSSIGN lv_string_utf8+lv_xstr_idx(8) TO TYPE 'C'. * according to its UTF-8 bit distribution pattern and * Parse through the Hex string and identify each Unicode character
Lv_string_utf8 = lo_converter->get_buffer( ). Lo_converter->write( EXPORTING data = p_string ). PARAMETERS p_string TYPE char255 LOWER CASE.ĭATA(lo_converter) = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' ). SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME. REPORT zgp_emoji_conv NO STANDARD PAGE HEADING.ĬONSTANTS c_uc_codepoint TYPE string VALUE ''. *& Convert Emoji Characters in a Unicode String to Unicode Codepoints As & is an unsafe character in HTML context, it needs to be escaped with & and hence the expected output would be: Test emoji 😀 Now, as per the requirement, the emoji icon ?needs to be converted to 😀 (Code point in Hex). Test emoji ?Īs we see, this string has an emoji icon, technically a unicode character, whose code point is shown below: Let’s consider the below Unicode string as input.
How does UTF-8 bit distribution logic work?. Text to unicode codepoints how to#
How to perform bit manipulation in ABAP?. How to handle the conversion between the data types such as C, I and X and so on?.
How to convert from one code page to another in SAP?. How does SAP store the data in the default code page configured?. Though the need for such a solution is very uncommon, the key takeaways from this solution could be our better understanding in the following areas: Here in this article, I’m going to explain what the actual requirement was and how a ABAP solution was provided for the same. But the reality was quite different upon the realisation that I had bare understanding of how unicode data is stored using UTF-8 encoding. But, recently, there was a unique requirement, wherein it was required to convert the emoji characters in a unicode string to their equivalent Unicode code points in Hexadecimal so that they could be properly displayed in a HTML compliant client.Īs much as it appeared interesting at first, it seemed very straightforward as well. It is very rare that we get to deal with encoding schemes directly in ABAP.
In the recent times, Unicode has become the dominant encoding scheme, of which UTF-8 representation is quite popular, especially with web content. Character encodings are no alien to SAP systems or any computer systems for that matter, as they form the basis for data storage in and communication between computer systems.