ABAP Help Document(8):3.1 数据类型

3.Predefined ABAP Types,Objects,Functions

3.1预定义数据类型

1.数字数据类型

示例:

"数据类型
FORM f_pre_data_type_number.
  "数值数据类型
  "b 1byte  0~255
  "s 2byte  -32,768 ~ +32,767
  "i 4byte  -2,147,483,648 ~ +2,147,483,647
  "p 1~16byte
  "(-10^(2len -1) +1) / (10^(+dec)) ~ (+10^(2len -1) -1) /(10^(+dec))

  "decfloat16 8byte  16位小数字,以尾数指数保存数字
  "1E385(1E-16 - 1) ~ -1E-383
  "+1E-383 ~ 1E385(1 - 1E-16)

  "decfloat34 16byte 34位小数位,
  "1E6145(1E-34 - 1) ~ -1E-6143
  "+1E-6143 and 1E6145(1 - 1E-34)

  "f 8byte 尾数,指数以二进制保存,符号位1,指数位11,尾数52位
  "可以表示17位小数浮点数
  "-1.7976931348623157E+308 ~ -2.2250738585072014E-308
  "+2.2250738585072014E-308 ~ +1.7976931348623157E+308

  DATA:p1 TYPE P LENGTH 2 DECIMALS 2 .
  "(-10^(2x2 -1) +1) / (10^2) ~ (+10^(2x2 -1) -1) / (10^2)
  "-9.99 ~ +9.99 in steps of 0.01
  p1 = '1.433'.
  WRITE:/ p1.

  DATA:max_val TYPE f.
  DATA:min_val TYPE f.
  PERFORM get_min_max_value USING p1 CHANGING min_val max_val.
  WRITE:/ 'min value',min_val,'max value',max_val.

ENDFORM.

"获取数据类型最大,最小值
FORM get_min_max_value
      USING i_val TYPE ANY
      CHANGING o_min TYPE f
               o_max TYPE f.
  "CL_ABAP_EXCEPTIONAL_VALUES类
  "获取数据类型最大,最小值
  FIELD-SYMBOLS:<fs_res> TYPE ANY.
  DATA:res_val TYPE REF TO DATA.

  res_val = CL_ABAP_EXCEPTIONAL_VALUES=>GET_MAX_VALUE( i_val ).
  IF res_val IS NOT INITIAL.
    ASSIGN res_val->* TO <fs_res>.
    o_max = <fs_res>.
  ENDIF.
  res_val = CL_ABAP_EXCEPTIONAL_VALUES=>GET_MIN_VALUE( i_val ).
  IF res_val IS NOT INITIAL.
    ASSIGN res_val->* TO <fs_res>.
    o_min = <fs_res>.
  ENDIF.
ENDFORM.

2.字符型数据

示例:

"预定义字符型数据类型
FORM f_pre_data_type_char.
  "字符型数据类型
  "c 1~262143 字符,初始值""
  "n 1~262143 数字字符,length个"0"
  "d 8 日期字符,"00000000"
  "t 6 时间字符,"000000"
  "string 可变长字符串,初始空
  DATA:lv_str TYPE string.
  lv_str = 'this is string'.
  DATA:lv_c1 TYPE C LENGTH 262143.
  lv_c1 = 'this is char'.
  DATA:lv_n1 TYPE N LENGTH 262143.
  lv_n1 = '1111111111111'.
  DATA:lv_d1 TYPE d.
  lv_d1 = '20200101'.
  DATA:lv_t1 TYPE t.
  lv_t1 = '010101'.
  WRITE:/ lv_str.
  WRITE:/ lv_c1.
  WRITE:/ lv_n1 RIGHT-JUSTIFIED.
  WRITE:/ lv_d1.
  WRITE:/ lv_t1.
ENDFORM

3.字节型数据

示例:

"字节型数据
FORM f_pre_data_type_byte.
  "字节型数据
  "x 1~524287,默认一个字节00-FF
  "xstring 可变字节  
ENDFORM.

4.通用数据类型

示例:

"通用数据类型
FORM f_pre_data_type_generic.

*c :Text field with a generic length
*clike :Character-like (c, d, n, t, string, and character-like flat structures);
  "in non-Unicode programs also x, xstring, and any flat structures
*csequence: Text-like (c, string)
*decfloat :Decimal floating point number (decfloat16, decfloat34)
*n :Numeric text with generic length
*numeric :Numeric (i (b, s), p, decfloat16, decfloat34, f)
*p :Packed number with generic length and generic number of decimal places

*simple :Elementary data type including structured types with exclusively character-like flat components
*object :Any object type (root class of the inheritance hierarchy)
*data :Any data type
*any :Any data type
*any table :Internal table with any table type

*hashed table :Hashed table
*index table :Index table
*sorted table :Sorted table
*standard table :Standard table
*table :Standard table

*x Byte field with generic length
*xsequence Byte-like (x, xstring)

"any,可以代表上述所有类型,除data,object;
"any,只能在type后,示例:type any,type any table;
"data,object, 在type ref to后,data指向任何数据类型指针,object指向任何对象类型;

"ABAP字典定义类型
*ACCP 6 Posting period n, Length 6
*CHAR 1-30000 Character string c, length m
*CLNT 3 Client c, Length 3
*CUKY 5 Currency key for currency fields c, Length 5
*CURR 1-31 Currency field in BCD format p, length (m+1)/2
*DATS 8 Date d
*DEC 1-31 Packed number BCD format p, length (m+1)/2
*DF16_DEC 1-15 Decimal floating point number stored in BCD format decfloat16
*DF16_RAW 16 Decimal floating point number stored in binary format decfloat16
*DF16_SCL 16 Decimal floating point number stored in binary format with subsequent scaling decfloat16
*DF34_DEC 1-31 Decimal floating point number stored in BCD format decfloat34
*DF34_RAW 34 Decimal floating point number stored in binary format decfloat34
*DF34_SCL 34 Decimal floating point number stored in binary format with subsequent scaling decfloat34
*FLTP 16 Floating point number f
*INT1 3 1-byte integer b
*INT2 5 2-byte integer s
*INT4 10 4-byte integer i
*LANG 1 Language c, Length 1
*LCHR 256-... long character string c, length m
*LRAW 256-... long byte string x, length m
*NUMC 1-255 Numeric text n, length m
*PREC 2 Obsolete data type s
*QUAN 1-31 Quantity field in BCD format p, length (m+1)/2
*RAW 1-255 Byte string x, length m
*RAWSTRING 256-... Byte string (BLOB) xstring
*SSTRING 1-1333 Character string string
*STRING 256-... Character string (CLOB) string
*TIMS 6 Time t
*UNIT 2-3 Unit key of a quantity field c, length m
"这些是ABAP内部定义Data type,Domain,使用需要创建对应Data type使用
ENDFORM.

 

 

posted @ 2021-04-21 21:13  渔歌晚唱  阅读(109)  评论(0编辑  收藏  举报