通过一段简单的代码,介绍 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.
更多Jerry的原創文章,盡在:“汪子熙”:
總結
以上是生活随笔為你收集整理的通过一段简单的代码,介绍 ABAP 的预定义类型 c的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AMD立大功!《塞尔达传说:王国之泪》获
- 下一篇: 已知一个特殊字符的 unicode 编码