CL_ABAP_CONV_X2X_CE - Code Page and Endian Conversion Between External Formats

Addresses (Business Address Services)   BAL_S_LOG - Application Log: Log header data  
This documentation is copyright by SAP AG.

Functionality

Instances of the class CL_ABAP_CONV_X2X_CE allow you to convert text data between different character sets and numeric data between different number formats (byte order).

Using the class corresponds to transforming data from a binary input stream to a binary output stream: The data objects are read from the input buffer sequentially and written to an output buffer.

The class methods are normally used as follows:

CL_ABAP_CONV_X2X_CE=>CREATE
This creates a conversion instance. Among other options, you can specify the following as parameters:The input buffer (that is the binary string that contains the data to be read), the character formatat used in the input buffer, the byte order used in the input buffer, the character format to be used in the output buffer, or the byte order to be used in the output buffer.
CONVERT_C, CONVERT_...
This converts the data. Calling this method several times consecutively allows you to read data from the input buffer sequentially and add it to the end of the output buffer.
GET_OUT_BUFFER
This gets the output buffer, making it available for further processing (such as writing to a file, sending using RFC).
RESET
This allows you to reset individual attributes of the conversion instance. (This method is especiallydesigned for restarting on a new input buffer and deleting the output buffer while retaining the remaining attributes.)

Relationships

CL_ABAP_CONV_IN_CE
Converting Binary Data into ABAP Data Objects
CL_ABAP_CONV_OUT_CE
Converting ABAP Data Objects to a Binary Format.
CL_ABAP_CHAR_UTILITIES
Various Attributes and Methods for Character Sets and Byte Order

Example

In the following example, UTF-8 texts are converted to the codepage 1100 (Latin-1) and numbers are converted from little-endian to big-endian format:

DATA:

  in_buffer TYPE XSTRING,

  out_buffer TYPE XSTRING,

  conv TYPE REF TO cl_abap_conv_x2x_ce.

in_buffer = '414220C3B602010000'.

conv = cl_abap_conv_x2x_ce=>create(

         in_encoding = 'UTF-8'

         in_endian = 'L'

         out_encoding = '1100'

         out_endian = 'B'

         input = in_buffer

       ).

CALL METHOD conv->convert_c( n = 5 ).

CALL METHOD conv->convert_i( ).

out_buffer = conv->get_out_buffer( ).

The content of the in_buffer variable is made up of 5 bytes (hexadecimal "414220C3B6"), which represent 4 UTF-8 characters(A, B, SPACE, o-Umlaut), and 4 bytes (hexadecimal "02010000"), which representthe value 258 in little-endian format. This data is converted and the out_buffer variable now contains the hexadecimal string "414220F600000102". It is made up of:

  • 4 bytes (hexadecimal "414220F6"), which represent the above 4 characters in codepage 1100 (ISO-8859-1). Note that the length specification n =5 refers to the number of elementary characters to be converted. For multi-byte codepages like UTF-8 this means that the multi-byte character "C3B6" is counted in length 2.
  • 4 Bytes (hexadecimal "00000102"), which represent the value 258 in big-endian format.

If you have the desired byte order in the old format as expected byTRANSLATE ... NUMBER FORMAT (as an N(4) value), you can proceed as follows:

TYPE-POOLS: ABAP.

CLASS cl_abap_char_utilities DEFINITION LOAD.

DATA:

  in_number_format(4) TYPE N VALUE '0101',

  out_number_format(4) TYPE N VALUE '0000'.

DATA:

  in_endian TYPE ABAP_ENDIAN,

  out_endian TYPE ABAP_ENDIAN,

  conv TYPE REF TO cl_abap_conv_x2x_ce..

in_endian  = cl_abap_char_utilities=>number_format_to_endian(

               in_number_format

             ).

out_endian = cl_abap_char_utilities=>number_format_to_endian(

               out_number_format

             ).

conv = cl_abap_conv_x2x_ce=>create(

         in_encoding = 'UTF-8'

         in_endian = in_endian

         out_encoding = '1100'

         out_endian = out_endian

         input = in_buffer

       ).

Notes

For details refer to the documentation for the individual methods.

Further information



TXBHW - Original Tax Base Amount in Local Currency   General Data in Customer Master  
This documentation is copyright by SAP AG.


Length: 7738 Date: 20120526 Time: 075908     triton ( 160 ms )