前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >通过一段简单的代码,介绍 ABAP 的预定义类型 c

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

作者头像
Jerry Wang
发布2022-03-10 17:57:41
4180
发布2022-03-10 17:57:41
举报

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

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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
腾讯云 BI
腾讯云 BI(Business Intelligence,BI)提供从数据源接入、数据建模到数据可视化分析全流程的BI能力,帮助经营者快速获取决策数据依据。系统采用敏捷自助式设计,使用者仅需通过简单拖拽即可完成原本复杂的报表开发过程,并支持报表的分享、推送等企业协作场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档