CL_ABAP_CONV_IN_CE - Code Page and Endian Conversion (External -> System Format)
RFUMSV00 - Advance Return for Tax on Sales/Purchases PERFORM Short ReferenceThis documentation is copyright by SAP AG.
Functionality
Instances of the class CL_ABAP_CONV_IN_CE allow you to convert binary data into valid ABAP data objects. (That is, data in an external format is converted to the system format.)
You can convert character sets (for text data) and the byte order (for numeric data).
There are also static methods that you can use to convert a hexadecimal or decimal Unicode value into a single character in the current codepage. These methods are:CL_ABAP_CONV_IN_CE=>UCCP andCL_ABAP_CONV_IN_CE=>UCCPI.
Relationships
- Converts ABAP data objects to an external binary format
- Converts of ABAP data objects between two external binary formats
- Various attributes and methods for character sets and byte order
- Corrects alignment of structures in containers of type C (or STRING). You need to make this correctionif East-Asian characters ("full-width" characters in Chinese, Japanese, and Korean) are to be copiedfrom a non-Unicode to a Unicode 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, UTF-8 text is converted into the system codepage and little-endian numbers are converted into the system format.
DATA:
text(100) TYPE c,
int TYPE i,
buffer(4) TYPE x,
conv TYPE REF TO cl_abap_conv_in_ce.
conv = cl_abap_conv_in_ce=>create(
encoding = 'UTF-8'
endian = 'L' ).
buffer = '41424320'.
conv->convert(
EXPORTING input = buffer
IMPORTING data = text ).
buffer = '02010000'.
conv->convert(
EXPORTING input = buffer
IMPORTING data = int ).
Calling the CREATEmethod creates a conversion instance. The source codepage, the byte order used in the input 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 text variable contains the character string "ABC" and the int variable contains the value 258.
For details refer to the documentation for the individual methods.
In the following example, the content of a binary string is stored in a structure afterthe conversion. The binary string, for example, was received by RFC or read from a file. In this example,the binary string has a layout generally used in non-Unicode systems. Therefore, the CREATE_LEGACY_VIEWmethod is called. (You can use the CREATE_UNICODE16_VIEW method to determine the layout in Unicode systems.)
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_in_ce,
view TYPE REF TO cl_abap_view_offlen.
conv = cl_abap_conv_in_ce=>create(
encoding = '0120'
endian = 'B' ).
view = cl_abap_view_offlen=>create_legacy_view( struc ).
buffer = 'C18283F1F250505000010002'.
conv->convert_struc(
EXPORTING input = buffer
view = view
IMPORTING data = struc ).
The content of the buffer variable is made up of
- 5 bytes (hexadecimal "C18283F1F2") that represent the string "Abc12" in EBCDIC-Latin-1 (SAP character set '0120')
- Alignment gap of 3 bytes; the content of these bytes ("505050") is ignored
- 4 bytes (hexadecimal "00010002") that represent the value 65538 in big-endian format
In both Unicode and non-Unicode systems, the example program has the following result:
- struc-text contains the characters "Abc12".
- struc-int contains the number 65538.
The CL_ABAP_CONV_IN_CE class contains additional methods that implement a stream-oriented model. The ABAP data objects are read sequentially from a binary input buffer. The methods are used as follows:
The system creates a conversion instance, and the input buffer (that is, the binary string that contains the data to be read) is specified as the parameter.
The system converts the data. Calling this method several times consecutively allows you to process data from the input buffer sequentially.
Individual attributes of the conversion instance can be reset. (This method is particularly used for restarting on a new input buffer while retaining the remaining attributes.)
In the following example, UTF-8 text is converted into the system codepage and little-endian numbers are converted into the system format.
DATA:
text(100) TYPE C,
int TYPE I.
DATA:
buffer TYPE XSTRING,
conv TYPE REF TO cl_abap_conv_in_ce.
buffer = '4142432002010000'.
conv = cl_abap_conv_in_ce=>create(
encoding = 'UTF-8'
endian = 'L'
input = buffer).
CALL METHOD conv->read(
EXPORTING n = 4
IMPORTING data = text ).
CALL METHOD conv->read(
IMPORTING data = int ).
The content of the buffer variable is made up of 4 bytes (hexadecimal "41424320") that represent the string"ABC" in UTF-8 and 4 bytes (hexadecimal "02010000") that represent the little-endian value 258. This data is converted into the corresponding values in the current system format:
- The text variable now contains the character string "ABC". (Note that the length specification n = 4 refers to the number of characters to be converted.)
- The int variable now has the value 258.
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,
buffer TYPE XSTRING,
conv TYPE REF TO cl_abap_conv_in_ce.
endian = cl_abap_char_utilities=>number_format_to_endian(
number_format
).
conv = cl_abap_conv_in_ce=>create(
encoding = 'UTF-8'
endian = endian
input = buffer
).
In the following example, the contents of a binary string are stored in a structure after the conversion.
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_in_ce,
view TYPE REF TO cl_abap_view_offlen.
view = cl_abap_view_offlen=>create_legacy_view( struc ).
buffer = 'C18283F1F250505000010001'.
conv = cl_abap_conv_in_ce=>create(
encoding = '0120'
endian = 'B'
input = buffer ).
CALL METHOD conv->read(
EXPORTING view = view
IMPORTING data = struc ).
The content of the buffer variable is made up of:
- 5 bytes (hexadecimal "C18283F1F2") that represent the string "Abc12" in EBCDIC-Latin-1 (SAP character set '0120')
- Alignment gap of 3 bytes; the content of these bytes ("505050") is ignored
- 4 Bytes (hexadecimal "00010001") that represent the value 65537 in big-endian format
In both Unicode and non-Unicode systems, the example program has the following result:
- struc-text contains the characters "Abc12".
- struc-int contains the number 65537.
Notes
For details refer to the documentation for the individual methods.
Further information
CPI1466 during Backup Fill RESBD Structure from EBP Component Structure
This documentation is copyright by SAP AG.
Length: 13662 Date: 20120526 Time: 075809 triton ( 307 ms )






