下面这段代码,稍稍有些编程基础的朋友想必都能够理解:
定义了两个 ABAP 变量,名称分别为 lv_c1 和 lv_c2, 类型为 c,c 是 ABAP 的预定义数据类型(predefined data type), 其初始值分别为 ‘汪’ 和 ‘a’.
通过关键字 BREAK-POINT, 使得执行这个报表时,自动触发调试器。在十六进制值显示字段里,观察到这两个变量值的16,分别为 6A6C 和 6100
本文通过这个例子展开对预定义类型 c 的介绍。
在 ABAP 帮助文档里,类型 c 的长度定义为 one character,1个字符。注意,千万不要将其误理解为 1个字节(one byte)
一个字符对应的字节数和该编程语言使用的 character representation (字符表示集)相关。
Character representation 是字符的二进制编码方式(Binary coding of characters)。
要将一个字符集分配给一个字符表示集,我们需要 code page.
每个 SAP 系统支持的 code page 在数据库表 TCP00 里维护。
10FFFF:
unicode 字符集合通过通过 UTF 或者 UCS 字符集表示来访问。
包括 UTF-8, UTF-16, UTF-32 和 UCS-2.
surrogate 区域中的特殊字符使用 4 个字节表示。
UTF 8 和 UTF 32 里直接访问这些字符。ABAP 使用的是 UCS-2, 不支持 surrogate 区域里的字符,对于这些字符,ABAP 会解读成两个不同的字符。
ABAP 编程语言支持 UCS-2,这是 UTF-16 的子集,但不支持 surrogates.
UTF-16可看成是UCS-2的父集。在没有辅助平面字符(surrogate code points)前,UTF-16 与 UCS-2 所指的是同一的意思。但当引入辅助平面字符后,就称为 UTF-16 了。现在若有软件声称自己支持 UCS-2 编码,那其实是暗指它不能支持在 UTF-16 中超过 2bytes 的字集。对于小于 0x10000 的 UCS 码,UTF-16 编码就等于UCS 码。
write: This statement formats the content of the data object dobj and writes it to the current page of the current list in the list buffer.
Output Length in the List
When a list is displayed or printed, the content stored in the list buffer is transferred to the list. Each character generally occupies one place in the list buffer.
However, a character can occupy more than one column in the list (this is particularly the case with East Asian characters). However, since the list only contains the same number of columns as there are places in the list buffer, this means the list can only display fewer characters than are saved in the list buffer. The list output is then shortened when passed from the list buffer to the list, left-justified output is shortened from the right, right-justified output is shortened from the left. Centered output is shortened by the alternate removal of the first blank from both sides, starting with the side with the most blanks, then other characters are removed on the right. If characters are removed when passed from the list buffer to the list, this is indicated on the left by the character < and on the right by the character >. On a displayed list, the entire list content can be displayed by choosing System → List → Unicode Display.
The length in bytes must be a multiple of the size of a Unicode character, regardless of the size of the Unicode character.