CL_ABAP_CONV_OUT_CE - Code Page and Endian Conversion (System Format -> External)
BAL Application Log Documentation ROGBILLS - Synchronize billing plansThis documentation is copyright by SAP AG.
Functionality
Instances of the class CL_ABAP_CONV_OUT_CE allow you to convert ABAP data objects to binary data. (That is, data in the system format is converted to an external format.)
You can convert character sets (for text data) and the byte order (for numeric data).
Additionally, there are static methods, which allow you to ascertain the hexadecimal or decimal value in the Unicode codepage for any character in the current codepage. These methods are:CL_ABAP_CONV_OUT_CE=>UCCP andCL_ABAP_CONV_OUT_CE=>UCCPI.
Relationships
- Converts binary data into ABAP data objects
- CL_ABAP_CONV_X2X_CE Converts ABAP data objects between two external binary formats. Binärformaten.
- Various attributes and methods for character sets and byte order
- CL_NLS_STRUC_CONTAINER Corrects alignment ofstructures in containers of type C (or STRING). You need to make this correction if East-Asian characters("full-width" characters in Chinese, Japanese, and Korean) are to be copied from a non-Unicode to aUnicode system or vice versa. You do not need to make the correction if you use the method CONVERT_STRUC from this class.
Example
In the following example, text from the system codepage is converted to UTF-8 and numbers from the system codepage are converted to little-endian format:
DATA:
text(4) TYPE c VALUE 'ABC',
int TYPE i VALUE 258.
DATA:
buffer1 TYPE xstring,
buffer2 TYPE xstring,
conv TYPE REF TO cl_abap_conv_out_ce.
conv = cl_abap_conv_out_ce=>create(
encoding = 'UTF-8'
endian = 'L' ).
conv->convert( EXPORTING data = text
IMPORTING buffer = buffer1 ).
conv->convert( EXPORTING data = int
IMPORTING buffer = buffer2 ).
Calling the CREATEmethod creates a conversion instance. The source codepage, the byte order used in the output buffer,or the type of error handling can be specified as parameters. The endian parameter is only relevant for the types DECFLOAT16, DECFLOAT34, F, I, and INT2.
After calling the CONVERT method, the buffer1 variable contains the 4 bytes 41424320 (hexadecimal) that represent the string"ABC" in UTF-8. The buffer2 variable contains the 4 bytes 02010000 that represent the value 258 in little-endian format.
For details refer to the documentation for the individual methods.
You can convert structures, as shown in the following example:
DATA:
BEGIN OF struc,
text(5) TYPE c,
int TYPE i,
END OF struc.
DATA:
buffer TYPE xstring,
conv TYPE REF TO cl_abap_conv_out_ce,
view TYPE REF TO cl_abap_view_offlen.
view = cl_abap_view_offlen=>create_legacy_view( struc ).
conv = cl_abap_conv_out_ce=>create(
encoding = '0120'
endian = 'B' ).
struc-text = 'Abc12'.
struc-int = 65538.
conv->convert_struc( EXPORTING data = struc
view = view
IMPORTING buffer = buffer ).
In this example, the CREATE_LEGACY_VIEW method is used to determine the layout generally usedin non-Unicode systems. (You can use the CREATE_UNICODE16_VIEW method to determine the layoutin Unicode systems.) The target codepage is specified as '0120'(SAP character set number forEBCDIC-Latin-1). At the end, the buffer(5) contains the bytes C18283F1F2 (for "Abc12") and buffer+8(4) contains the bytes 00010002 (for 65538).
The CL_ABAP_CONV_OUT_CE class contains additional methods that implement a stream-oriented model:The ABAP data objects are written sequentially to a binary output buffer. The methods are used as follows:
- See above.
- The system converts the data. Calling this method several times consecutively allows you to add the data to the output buffer sequentially.
- Gets the output buffer (binary strings) for further processing (writing data to a file, sending data by RFC, and so on).
- Individual attributes of the conversion instance can be reset. (This method is particularly used for deleting the output buffer while retaining the remaining attributes.)
DATA:
text(100) TYPE C VALUE 'ABC',
int TYPE I VALUE 258.
DATA:
buffer TYPE XSTRING,
conv TYPE REF TO cl_abap_conv_out_ce.
conv = cl_abap_conv_out_ce=>create(
encoding = 'UTF-8'
endian = 'L'
).
CALL METHOD conv->write( data = text n = 4 ).
CALL METHOD conv->write( data = int ).
buffer = conv->get_buffer( ).
The buffer variable now contains the hexadecimal string "4142432002010000", which is made up of:
- 4 bytes (hexadecimal "41424320") that represent the string "ABC" in UTF-8.
- 4 bytes (hexadecimal "02010000") that represent the value 258 in the little-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:
number_format(4) TYPE N VALUE '0101'.
DATA:
endian TYPE ABAP_ENDIAN,
conv TYPE REF TO cl_abap_conv_out_ce.
endian = cl_abap_char_utilities=>number_format_to_endian(
number_format
).
conv = cl_abap_conv_out_ce=>create(
encoding = 'UTF-8'
endian = endian
).
Notes
For details refer to the documentation for the individual methods.
Further information
General Material Data General Data in Customer Master
This documentation is copyright by SAP AG.
Length: 11682 Date: 20120526 Time: 075841 triton ( 257 ms )






