ABAP中的基础数据类型(b,c,d,decfloat16,decfloat34,f,i,。。。
很多同学不太清楚ABAP语⾔中的基础数据类型(ABAP Type),本篇⽂章总结了,在ABAP语⾔中,预定义的数据类型以及其初始值和长度。
总的来说,在ABAP语⾔中,系统预定义了以下这些数据类型:
b, c, d, decfloat16, decfloat34, f, i, int8, n, p, s, string, t, x, xstring.
按照种类的不同,这些数据类型可以分为4⼤类:
1. Numeric Types - 数字类型
2. Character-like Types - 字符类类型
3. Byte Types - 字节类型
4. Date Types and Time Types - 时间和⽇期类型
1. Numeric types(数字类型)
⽤途:⽤于处理数字类型的数据
Type Length Standard
Length
Name value range
initial
value
b 1 byte
1-byte
integer
(internal)
0 to 2550
s 2 byte
2-byte
integer
(internal)
-32,768 to +32,7670
i 4 byte 4-byte
integer
-2,147,483,648 to +2,147,483,6470
int88 byte 8-byte
integer
-9,223,372,036,854,775,808 to +9,223,372,036,854,775,8070
p 1 to 16
bytes
8 byte
Packed
number
(-10^(2len-1) +1) / (10^(+dec)) to (+10^(2len-1) -1) /(10^(+dec))0
decfloat168 byte
Decimal
floating point
number with
16 places
Valid values are numbers between 1E385(1E-16 - 1) and -1E-383 for the
negative range, 0 and +1E-383 to 1E385(1 - 1E-16) for the positive range.
decfloat3416 byte
Decimal
floating point
number with
34 places
Valid values are numbers between 1E6145(1E-34 - 1) and -1E-6143 for the
negative range, 0 and +1E-6143 and 1E6145(1 - 1E-34) for the positive
range.
f8 byte
Binary
floating point
number with
17 places
Valid values are numbers between -1.7976931348623157E+308 and -
2.2250738585072014E-308 for the negative range and between
+2.2250738585072014E-308 and +1.7976931348623157E+308 for the
positive range, plus 0.
⽤法举例:
result TYPE decfloat34.
...
result = num1 / num2.
2. Character-Like Types(字符类类型)
⽤途:⽤于处理字符和字符串类型的数据
Type Length Default
Length
Name value range initial value
c 1 to 262,143
characters
One
character
Text field Any alphanumeric characters" " for every place
n 1 to 262,143
characters
One
character
Numeric
text field
自治地方Any alphanumeric characters, but the only valid values
are the digits 0 to 9
“0” for every
place
string Variable Text string As for type c Empty string with
length 0
⽤法举例:
DATA: flag TYPE c LENGTH 1,
html TYPE string.
3. Byte-Like Types(字节类型)
⽤途:⽤于字节类型的数据
Type Length Default Length Name value range initial value x 1 to 524,287 bytes 1 byte Byte field Any byte values, hexadecimal 00 to FF Hexadecimal 00 xstring Variable Byte string As for type x Empty string with length 0⽤法举例:
DATA hex TYPE xstring.
hex = cl_abap_codepage=>convert_to( `...` ).
4. Date Types and Time Types(⽇期和时间类型)
⽤途:⽤于⽇期和时间类型的数据
Type Length Default
Length
Name value range initial value
d
8
characters
Date
field
t “yyyymmdd”: “yyyy” (year): 0001 to 9999, “mm” (month): 01 to
12, “dd” (day): 01 to 31
“00000000”
t
6
characters
Time
field
“hhmmss”. “hh” (hours): 00 to 23, “mm” (minutes): 00 to 59, “ss”
(conds): 00 to 59.
“000000”
⽤法举例:
DATA (today ) = sy -datlo .DATA (now ) = sy -timlo .tomorrow = today + 1.
next_hour = ( now + 3600 ) / 3600 * 3600.
5. 数据字典中的内置数据类型(Built-In Data Types )
ABAP中的基础数据类型,可以在程序中直接使⽤。
基于ABAP中的基本数据类型,SAP在数据字典SE11中提供了⼀系列的内置数据类型,我们可以使⽤这些内置的数据类型,来定义更加有业务含义的类型,这也便是domain的data element的概念了。
SAP在数据字典中的内置数据类型(built-in data type),是基于基础数据类型(abap type) 定义的。
凤凰怎么画在ABAP的数字字典中,提供了37种预制类型。下图展⽰了Domain ----- 预制数据类型-----基础数据类型建的关系。
数据字典中的37种预制数据类型,可分为以下⼏类。
5.1 Numeric Types 相关的
Type
Valid Places m
Decimal Places n
Initial Value Meaning
ABAP Type
INT13
-0
1-byte integer, 0 to 255b爸爸妈妈对幼儿园的意见和建议
INT25
-02-byte integer, -32,768 to 32,767
s INT4
10-04-byte integer, -2,147,483,648 to +2,147,483,647i
INT819
-
8-byte integer, -9,223,372,036,854,775,808 to
+9,223,372,036,854,775,807
int8
DEC 1-31
0-m,maximum 14
0Packed number in BCD format
儿童水饺p, length m DIV 2 + 1,decimal places n
DF16_DEC 1-150-m,maximum 14
0Decimal floating point number stored in BCD format decfloat16
DF16_RAW 16-0
Decimal floating point number stored in binary
format
decfloat16
DF34_DEC 1-31
0-m,maximum 14
0Decimal floating point number stored in BCD format decfloat34
DF34_RAW 34-0
Decimal floating point number stored in binary
format
decfloat34
FLTP 16160Binary floating point number
f
Type Valid Places m
Decimal
Places n
Initial Value Meaning ABAP Type 5.2 Character-Like Types 相关的
Type Valid Places m
Initial Value Meaning ABAP Type CHAR 1-30000, maximum of 1333 for table fields
m blanks Character string c, length m LCHR 256-32000None long character string c, length m SSTRING 1-1333Empty string Character string string STRING
256-…
同日而语什么意思Empty string
Character string (CLOB)
string
5.3 Byte-Like Types 相关的
Type Valid Places m
Initial Value
Meaning ABAP Type RAW 1-32000 maximum of 255 for table fields
None Byte string x, length m LRAW 256-32000None Long byte string x, length m RAWSTRING
256-…
Empty string
出口合同
Byte string (BLOB)
xstring
5.4 Date Types/Time Types 相关的
Type Valid Places m
婚礼开场白主持词Initial Value Meaning
ABAP Type
DATS 800000000Date in the format YYYYMMDD d TIMS 6000000Time in the format HHMMSS t ACCP
6
6 blanks
Posting period in the format YYYYMM
n, length 6
5.5 ⼀些有特定含义的Character-Like Types:
Type Valid Places m
Initial Value Meaning ABAP Type NUMC 1-255m zeroes Numeric text
n, length m CLNT 3000Client c, length 3LANG
1
Blank
在太行山上歌词
Language key
c, length 1
5.6 ⾦额、数量相关的类型(Currency Fields and Quantity Fields)
Type Valid Places
m
Decimal Places
n
Initial
Value
Meaning ABAP Type
CURR1-311-m, maximum 140Currency field in BCD format p, length m DIV 2 + 1, decimal places
n
CUKY5- 5 blanks Currency key for currency
fields
c, length 5
QUAN1-310-m, maximum 140Quantity field in BCD format p, length m DIV 2 + 1, decimal places
n
UNIT2-3-2 or 3
blanks
Unit key of a quantity field c, length m
希望在你对ABAP数据类型有疑问的时候,本篇博客可以帮助到你 本博客专注于技术分享,⼲货满满,持续更新。 欢迎关注❤ 、点赞 、转发 !