通过一段简单的代码,介绍 ABAP 的预定义类型 c

简介: 通过一段简单的代码,介绍 ABAP 的预定义类型 c

下面这段代码,稍稍有些编程基础的朋友想必都能够理解:

定义了两个 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.


字符集:定义了字符的集合,比如 ASCII, EBCDIC 或者 Unicode. 字符集使用 code page 映射到字符表示集。


code page: 从字符集里某个字符到其位序列的映射关系统称。


每个 SAP 系统支持的 code page 在数据库表 TCP00 里维护。


unicode: 和具体语言无关的字符集合。是 UCS 字符集的子集(依照 ISO-10646)。可以使用 U+0000 到 U+10FFFF 之间的16进制数,来表示多达 1114111 个不同的字符。10FFFF:

unicode 字符集合通过通过 UTF 或者 UCS 字符集表示来访问。

UTF: Abbreviation of Universal Transformation Format 的缩写。 Unicode 字符集的不同方式的表示。

包括 UTF-8, UTF-16, UTF-32 和 UCS-2.


UTF8: 这里的 8 代表 8 bit,即一个字节。ASCII characters 用1个字节表示,其他欧洲字符用2个字节表示,大多数亚洲语言的字符用3个字节表示。

surrogate 区域中的特殊字符使用 4 个字节表示。


surrogate 区域:在区间 U+10000 到 U+10FFFF 之间的字符,包含一些音乐符号和特殊的亚洲语言字符。

UTF 8 和 UTF 32 里直接访问这些字符。ABAP 使用的是 UCS-2, 不支持 surrogate 区域里的字符,对于这些字符,ABAP 会解读成两个不同的字符。


UTF-16: 16 位的字符表示集。所有字符使用 16 位表示。surrogate 区域中的字符,使用 surrogate 来访问。

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 码。


UCS-2:是 UTF-16 的子集,也是 ABAP 编程在 unicode 系统里使用的字符表示集。


EBCDIC (Extended Binary Coded Decimal Interchange) also encodes each character using one byte, and can therefore also represent 256 characters. For example, EBCDIC 0697/0500 is an IBM format that has been used on the AS/400 platform (now known as IBM System i) for Western European fonts.

list buffer: Memory area for saving screen lists. Subdivided into list levels. For each dynpro sequence, the list buffer contains a hierarchy consisting of a basic list and up to 20 details lists.

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.

相关文章
|
1月前
|
存储 数据处理 开发者
ABAP 如何把 unicode 代码点转换成字符
ABAP 如何把 unicode 代码点转换成字符
19 0
|
20天前
|
存储
使用 ABAP 代码打印出 SAP CRM 系统里所有维护了 Sales Area 的 business partner id
使用 ABAP 代码打印出 SAP CRM 系统里所有维护了 Sales Area 的 business partner id
19 0
|
2月前
|
SQL 数据库
小技巧:如何让 ABAP OPEN SQL 代码具有自解释性(Self-Explained)
小技巧:如何让 ABAP OPEN SQL 代码具有自解释性(Self-Explained)
25 0
|
1月前
|
BI
工具分享 - 将一个 ABAP Function Group 内所有 Function Module 按照代码行数从高到低排序并显示试读版
工具分享 - 将一个 ABAP Function Group 内所有 Function Module 按照代码行数从高到低排序并显示试读版
15 0
|
1月前
|
存储
ABAP 代码从十进制转二进制的方法
ABAP 代码从十进制转二进制的方法
21 0
|
2月前
|
XML 持续交付 开发工具
SAPGUI 里 ABAP 代码导出成 PDF 格式的隐藏小技巧
SAPGUI 里 ABAP 代码导出成 PDF 格式的隐藏小技巧
27 0
|
2月前
|
XML 数据格式
使用 ABAP 代码将 Word 文档设置成只读
使用 ABAP 代码将 Word 文档设置成只读
22 0
|
6月前
|
存储 语音技术 UED
如何用 ABAP 代码进行文本转语音的输出工作
如何用 ABAP 代码进行文本转语音的输出工作
36 0
|
3月前
小技巧分享:如何使用动态断点快速找到成对的 ABAP 内存 IMPORT 和 EXPORT 的代码位置
小技巧分享:如何使用动态断点快速找到成对的 ABAP 内存 IMPORT 和 EXPORT 的代码位置
24 0
|
3月前
答知识星球朋友疑问:执行 ABAP 代码出现超时的原因,背后的理论和解决方案试读版
答知识星球朋友疑问:执行 ABAP 代码出现超时的原因,背后的理论和解决方案试读版
17 0

热门文章

最新文章