zoukankan      html  css  js  c++  java
  • ABAP DESCRIBE语句

    DESCRIBE

    可参考反射RTTS

    DESCRIBE FIELD

    DESCRIBE FIELD dobj
      [
    TYPE typ [COMPONENTS com]]
      [
    LENGTH ilen IN {BYTE|CHARACTER} MODE]
      [
    DECIMALS dec]
      [
    OUTPUT-LENGTH olen]
      [
    HELP-ID hlp]
      [
    EDIT MASK
     mask].

    TYPE typ

    以下是不同类型的dobj返回的类型ID列表,ID大小写敏感:

     

    Numeric Data Type

    ID

    b

    b

    s

    s

    i

    I

    p

    P

    decfloat16

    a

    decfloat34

    e

    f

    F

     

    Character-Like Data Type

    ID

    c

    C

    string

    g

    n

    N

    d

    D

    t

    T

     

    Byte-Like Data Type

    ID

    x

    X

    xstring

    y

     

    Reference Type

    ID

    Data reference

    l

    Object reference

    r

     

    Complex Type

    ID

    Flat structure

    u

    Deep structure

    v

    Internal table

    h

     

    COMPONENTS选项是对结构的字段数进行统计,如果有内嵌的结构,则只算直接(最高级别的)内嵌的结构,且只算做1个。

     

    DATA: BEGIN OF struc1,
            comp1
    TYPE c LENGTH 1,
            comp2
    TYPE string,
           
    BEGIN OF struc2,
              comp1
    TYPE c LENGTH 1,
              comp2
    TYPE i,
           
    END OF struc2,
         
    END OF struc1,
          typ1 
    TYPE c LENGTH 1,
          comp1
    TYPE i,
          typ2 
    TYPE c LENGTH 1,
          comp2
    TYPE i.

    DESCRIBE FIELD: struc1        TYPE typ1 COMPONENTS comp1,
                    struc1
    -struc2 TYPE typ2 COMPONENTS comp2.
    WRITE:/ typ1,comp1,/ typ2,comp2.

    DESCRIBE FIELD: struc1        TYPE typ1,
                    struc1
    -struc2 TYPE typ2.
    WRITE:/ typ1,/ typ2.

    v          3

    u          2

    v        

    u        

    LENGTH ilen

    当使用IN CHARACTER MODE选项时,dobj必须是flat and character-like,针对deep data typesdobj,你只能使用IN BYTE MODE,并且此情况下返回的长度为引用所占长度(在SAP系统中每个reference的长度固定为8 bytes

     

    对于固定长度类型的dobj,是在创建这个变量时就已决定。如果字符串类型,则不会计算尾部空格,此时可以使用预置函数strlen来测定

    DATA: text  TYPE c LENGTH 1,
          blen 
    TYPE i,
          clen 
    TYPE i,
          bytes
    TYPE i.

    DESCRIBE FIELD text LENGTH blen IN BYTE MODE.
    DESCRIBE FIELD text LENGTH clen IN CHARACTER MODE.
    bytes
    = blen / clen.
    WRITE:/ blen,clen,bytes.

    2           1           2

    DECIMALS dec

    dobj的小数位

     

    DATA: TYPE p LENGTH 8 DECIMALS 4,
         
    i  TYPE i.
    DESCRIBE FIELD p DECIMALS i.
    WRITE:/ i.

             4

    OUTPUT-LENGTH olen

    测试dobj屏幕输出宽度,对于那些固定长度数据类型,输出宽度都是已经预置好的,对于strings,则为0

     

    Numeric Data Types

    Data Type

    Output length

    b

    3

    s

    5

    i

    11

    p

    2 x length of dobj (+ 1, if there is a decimal separator)

    decfloat16

    24

    decfloat34

    46

    f

    24

    注:上面表中的s类型显示宽度只有5位,不中以显示符号;i显示宽度为11,可以显示符号

     

    Character-like data types

    Data Type

    Output Length

    c

    Length of dobj, maximum 255

    string

    text field literals

    根据屏幕列表设置的最大宽度来决定。如果字符不满List设置的宽度时,left-justified输出时会在右边补空格,right-justified输出时会在左边补空格,centered outputs输出时两端补空格

    n

    Length of dobj, maximum 255

    d

    8

    t

    6

     

    Byte-Like Data Types

    Data Type

    Output Length

    x

    2 x length of dobj, maximum 255

    xstring

    2 x number of bytes contained

     

    DATA: date1 TYPE d,
          date2
    TYPE sy-datum,
          olen1
    TYPE i,
          olen2
    TYPE i.

    DESCRIBE FIELD date1 OUTPUT-LENGTH olen1.
    DESCRIBE FIELD date2 OUTPUT-LENGTH olen2.

    WRITE: / date1,date2,/ olen1,olen2.

    00000000 00.00.0000

             8          10

    HELP-ID hlp

    DATA: carrid TYPE spfli-carrid,
          hlp   
    TYPE string,
          struc 
    TYPE dfies-tabname,
          comp  
    TYPE dfies-fieldname.
    DESCRIBE FIELD carrid HELP-ID hlp.
    SPLIT hlp AT '-' INTO struc comp.
    WRITE:/ hlp, / struc,/ comp.
    CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
     
    EXPORTING
        tabname  
    =
    struc
        fieldname
    = comp
    .

    image010

    EDIT MASK mask

    If a conversion routine is assigned to the data object dobj by referring to a domain in ABAP Dictionary, two equals signs "==" precede the name of the conversion routine and the result is assigned to the data object mask.

    DATA: time    TYPE s_fltime,
          seconds
    TYPE i,
          msk    
    TYPE string.

    DESCRIBE FIELD time EDIT MASK msk.
    WRITE msk.
    seconds
    = 333.
    WRITE / seconds USING EDIT MASK msk.

    ==SDURA

      5:33

    image011

    DESCRIBE TABLE

    DESCRIBE TABLE itab [KIND knd] [LINES lin] [OCCURS n].

     

    不同的选项使你能够判断表类型、行数、初始化大小。另外,系统字段sy-tfill  sy-tleng 保存着表行数量和以字节计的表行长度。注:为了更详细的关于内表的信息,应用RTTS的方法代替语句describe table。没有指定一个附加项,语句describe table 只设置系统字段sy-tfill sy-tleng的值。

     

    a)         KIND knd

    标识为T 时代表标准表,为S时代表排序表,为H时代表哈希表。这些值在类型组SYDES中已被定义成常量sydes_kind-standed sydes_kind-sortedsydes_kind-hashed

     

    b)         LINES lin  内表表行数量

    注:在版本6.10中,内表表行的当前数量也可以用内建函数lines来判断

     

    c)         OCCURS n

    在内表用选项initial size 或者老式的选项ocurs创建期间决定内表所需要的初始化内存大小

    FORM sort_descending CHANGING itab TYPE ANY TABLE.
     
    DATA tabkind TYPE c LENGTH 1.
     
    DESCRIBE TABLE itab KIND tabkind.
     
    IF tabkind = sydes_kind-standard OR
         tabkind
    = sydes_kind-hashed.
       
    SORT itab DESCENDING.
     
    ELSEIF tabkind = sydes_kind-sorted.
       
    MESSAGE '...' TYPE 'E'.
     
    ELSE.
       
    MESSAGE '...' TYPE 'E'.
     
    ENDIF.
    ENDFORM.

    DESCRIBE DISTANCE

    DESCRIBE DISTANCE BETWEEN dobj1 AND dobj2 INTO dst
                             
    IN {BYTE|CHARACTER} MODE
    .

    dobj1 and dobj2两个变量地址起始位置的距离

     

    DATA: BEGIN OF struc,
            comp1
    TYPE i,
            comp2
    TYPE x LENGTH 1,
            comp3
    TYPE c LENGTH 4 VALUE 'Hey',
            comp4
    TYPE c LENGTH 4 VALUE 'you!',
            comp5
    TYPE x,
         
    END OF struc.
    DATA: off TYPE i,
          len
    TYPE i,
          len2
    TYPE i.

    FIELD-SYMBOLS: <hex>    TYPE x,
                   <result>
    TYPE c.

    DESCRIBE DISTANCE BETWEEN:
             struc      
    AND struc-comp3 INTO off IN BYTE MODE,
             struc
    -comp3 AND struc-comp5 INTO len IN BYTE MODE,
             struc      
    AND struc-comp1 INTO len2 IN BYTE MODE.

    ASSIGN: struc TO <hex> CASTING,
            <hex>+off
    (len) TO <result> CASTING.

    WRITE: / 'Offset off is', off,
           /
    'Length len is', len,
           /
    '<result> points to', <result>,
           / len2
    .

    Offset off is          6

    Length len is         16

    <result> points toHey you!

             0

  • 相关阅读:
    build、host和target选项
    第一篇博客
    C++中的new和delete
    新分类:C++复习笔记
    泛读英文小说推荐
    借助查询分析器对遗留项目进行分析
    程序员等级(非本人观点)
    线程并发时的四种数据同步方法
    单元测试之什么是优秀的单元测试
    多线程之进度条
  • 原文地址:https://www.cnblogs.com/jiangzhengjun/p/4292805.html
Copyright © 2011-2022 走看看