Basic data type list:
- 1. The variable length built-in type ( String, xString)
. 1) Type String
ABAP programs, string type is a character field of infinite length, and can be CHAR, D, T, I, N (F and P not tested) direct conversion,
but some of the string operation instruction can be used CHAR type, string type is not allowed, for example: SHIFT
within the system, built-in variable-length type ( string, xString) by referencing the actual data objects dynamically pinned address operation, and thus both built and reference types as belonging to the depth type.
2) .xstring type
of hexadecimal characters 0-9, AF composition string. Direct print output, the output value of the assignment or the literal sense, rather than Unicode strings decoded
Note: If the letter is, it must be capitalized, or not into the assignment
The DATA : XS the TYPE . Xstring XS = ' 303 132 ' . " String representing the 012 the WRITE : / XS.
But the output is still 303 132
- 2.X type
Hexadecimal characters 0-9, AF specific range: 00 ~ FF
Type X is a hexadecimal type, memory byte can represent the actual content, the use of two hexadecimal characters showing the contents stored in a byte. However, direct print output, the value of the literal sense or when the output of the assignment, rather than Unicode character decoded
如果未在 DATA 语句中指定参数<length>,则创建长度为 1
注:如果值是字母,则一定要大写,否则赋值不进
DATA: x2(2) TYPE x. x2 = '3AA'. WRITE : / x2.
输出赋值时字面上的值:3AA0
补充说明:
16(十进制) = 10(十六进制) 十六进制(Hexadecimal)是计算机中数据常用的表示方法。一个十六进制数由0~9,A~F组成(不区分大小写)。与十进制的对应关系为:0~9对应十进制的0~9;A~F对应十进制的10~15。十六进制“逢十六进一”
- 3. P类型(压缩型)数据
是一种压缩的定点数,其数据对象占据内存字节数和数值范围取定义时指定的整个数据大小和小数点后位数,如果不指定小数位,则将视为I类型。其有效数字位大小可以是从1~31位数字(小数点与正负号占用一个位置,半个字节),小数点后最多允许14个数字。
P类型的数据,可用于精确运算(这里的精确指的是存储中所存储的数据与定义时字面上所看到的大小相同,而不存在精度丢失问题——看到的就是内存中实实在在的大小)。
在使用P类型时,要先选择程序属性中的选项 Fixed point arithmetic(即定点算法,一般默认选中),否则系统将P类型看用整型。其效率低于I或F类型。"16 * 2 = 32表示了整个字面意义上允许的最大字面个数,而14表示的是字面上小数点后面允许的最大小数位,而不是指14个字节,只有这里定义时的16才表示16个字节
DATA: p(16) TYPE p DECIMALS 14 VALUE '12345678901234567.89012345678901'.
"正负符号与小数点固定要占用半个字节,一个字面上位置,并包括在这16个字节里面。
"16 * 2 = 32位包括了小数点与在正负号在内
"在定义时字面上允许最长可以达到32位,除去小数点与符号需占半个字节以后
"有效数字位可允许31位,这31位中包括了整数位与小数位,再除去定义时小
"数位为14位外,整数位最多还可达到17位,所以下面最多只能是17个9
DATA: p1(16) TYPE p DECIMALS 14 VALUE '-99999999999999999'."P类型是以字符串来表示一个数的,与字符串不一样的是,P类型中的每个数字位只会占用4Bit位,所以两个数字位才会占用一个字节。另外,如果定义时没有指定小数位,表示是整型,但小数点固定要占用半个字节,所以不带小数位与符号的最大与最小整数如下(最多允许31个9,而不是32个)
DATA: p1(16) TYPE p VALUE '+9999999999999999999999999999999'.
DATA: p2(16) TYPE p VALUE '-9999999999999999999999999999999'.其实P类型是以字符串形式来表示一个小数,这样才可以作到精确,就像Java中要表示一个精确的小数要使用BigDecimal一样,否则会丢失精度。