In practical projects, especially some system integration projects, we often encounter scenarios where we need to receive and parse the binary stream sent from the remote end. The content of this binary stream may be some binary files, such as files in PDF, JPG and other formats, or may be text files. For text files, we need to restore the binary stream to human-readable text. This is the topic that this article will focus on.
Before starting this step, please be sure to complete the previous chapters:
How to upload local files in binary mode in ABAP report
In this pre-chapter, the text file is uploaded to the ABAP server in binary form to simulate a binary stream provided by a remote content provider (Content Provider). The type is xstring
. These binary The actual content of the stream is some text containing Chinese characters. Our task in this article is to convert these binary streams back into user-readable text, and then print them out.
We create a new text file, enter a Chinese character 汪
, save the file name as 汪-utf8.txt
, select UTF-8 for encoding.
The size of this file is displayed as 3 bytes. This is in line with our expected behavior, because UTF-8 is an implementation of Unicode, and the Unicode value of a Chinese character ranges from 0X4E00 to 0x9FA5, which requires 3 bytes if UTF-8 is encoded.
Next, we will perform various operations on the text file containing this Chinese character in the ABAP code.
See this article for details.
Summarize
When using ABAP to perform file operations containing Chinese characters, first of all, it is necessary to clarify which character set the current Chinese characters are encoded according to, and then find the number of the character set in the ABAP system from the ABAP database table TCP00, and ensure that it contains The binary stream of the Chinese content matches the incoming ABAP Encoding value, so that the correct processing result can be obtained.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。