DESCRIBE DISTANCE

本文详细介绍了ABAP编程语言中DESCRIBEDISTANCE语句的功能与使用方法,该语句用于计算两个数据对象起始位置间的距离,并将结果存储在指定的数据对象中。文章解释了不同模式(如BYTE与CHARACTER)下的距离计算方式及注意事项。

DESCRIBE DISTANCE

Syntax 语法

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

Effect 作用

This statement assigns the distance between the starting positions of the data objects dobj1 and dobj2 to the data object dst, for which the data type i is expected. In case of deeper data types, the referenced data object is not relevant but the position of the internal reference (for strings and internal tables) or the reference variables. It is not important, in which order dobj1 and dobj2 are specified.

这个语句把数据对象dobj1dobj2的起始位置的距离赋给i类型的数据对象dst。如果是复杂数据类型,被参照的数据类型是不相关的除了内部参照的位置(对于字符串和内表)或者参考变量。Dobj1dobj2以哪种顺序被指定并不重要。

In Unicode programs, the addition MODE must be specified. The variant with the addition IN BYTE MODE determines the distance in bytes. The variant with the addition IN CHARACTER MODE converts the distance into characters that can be stored in this length according to the current character presentation. In non-Unicode programs and in releases prior to 6.10, the addition MODE can be omitted. In this case, the addition IN BYTE MODE is used implicitly. When you use this addition in IN CHARACTER MODE and the determined distance cannot be converted into a number of characters, an exception that cannot be handled is triggered.

unicode程序中,选项mode须发被指定。具有选项in byte mode的变式以字节判断距离。具有选项in character mode的变式根据当前字符的描述把距离转换成可以以这个长度保存的字符。在non-unicode程序和在6.10之前的版本中,选项mode可以被省略。这种情况下,选项in byte mode隐式地被使用。如果使用选项in character mode并且判断出来的距离不能被转换成若干字符,将会触发一个不可处理的异常。

Note

The distance between data objects should only be determined within the same structure and only the structure's components should be used because only they are always in a successive order in the memory. Note that the alignment gaps are counted as well. Therefore, use the addition IN BYTE MODE to avoid an exception that cannot be handled.

应当只能判断具有相同结构的数据对象之间的距离,应该只能使用结构的字段因为只有它们在内存中总是连续的。注意也要计算差异。所以,使用选项in byte mode来避免不可处理的异常。

Example 例子

Determination of the offset and length of a character-type fragment within the structure struc in bytes, access to the fragment using an offset / length access und an assignment to a field symbol of the type c. Since the structure is not purely character-type, a field symbol is used for the offset / length access. Otherwise, a syntax error occurs in a Unicode program. The field symbol is of the type x, because offset and length are determined in bytes. Due to the alignment gap before comp3, a different value is determined for off in Unicode system as in non-Unicode systems. In both cases, the field symbol <result> has the same content "Hey you!". 翻译略。有点绕口,呵呵

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

DATA: off TYPE i,
      len 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.

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

Exceptions

Non-Catchable Exceptions 不可捕捉的异常

  • Cause: Distance cannot be converted into characters.
    Runtime Error:
    UC_NO_CHAR_NUMBER

转载于:https://www.cnblogs.com/clsoho/archive/2010/03/10/1682400.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值