赋值语句的两种方式

我们赋值的时候可以 destination = source 比如 gc_d = gc_s  有时候可以看到等号前有个问好

gc_d ?= gc_s 这是因为gc_s不是一个静态类型,而是一个引用类型,而且gc_d的类型要比gc_s更加泛化一些。

 

更加详细内容,参见ABAP文档

Syntax

MOVE source {TO|?TO} destination.

destination {=|?=} source.

Effect

Both these statements assign the content of the operand source to the data object destination. The variants with the language element TO or the assignment operator = are valid for all assignments between operands that are not reference variables, and for assignments between reference variables for which the static type of source is more specific than or the same as the static type of destination(narrowing cast).

Variants with the language element ?TO or the assignment operator ?= (casting operator ) must be used if the source and destination are reference variables and the static type of source is more general than the static type of destination (widening cast). For assignments between operands that are not reference variables, use of the question mark ? is not permitted.

The data object destination can be any data object that can be listed at a write position, and the data object source can be a data object, a predefined function or a functional method (as of release 6.10). The data type of the data object destination must either be compatible with the data type of source, or it must be possible to convert the content of source into the data type of destination according to one of the conversion rules.

Notes
  • If source and/or destination are field symbols, then, as in all ABAP commands, the system works with the content of the data objects to which the field symbols point. The actual pointer content of a field symbol can only be changed using the statement ASSIGN or the addition ASSIGNING when processing internal tables (value semantics). If source and destination are reference variables, the reference contained in source is assigned to destination (reference semantics).
  • Strings and internal tables are addressed internally using references. When assignments are made between strings and between internal tables (as of release 6.10), only the reference is transferred, for performance reasons. After the assignment, the actual string or the actual table body of the source as well as the target object are addressed (sharing). When the object is accessed to change it, the sharing is canceled and a copy of the content is made. The sharing is displayed in the memory consumption display of the ABAP debugger and in the Memory Inspector tool (as of release 6.20).
  • Obsolete Form: MOVE PERCENTAGE



Exceptions

Catchable Exceptions

CX_SY_CONVERSION_NO_NUMBER

  • Cause: Operand cannot be interpreted as number
    Runtime Error: CONVT_NO_NUMBER (catchable)

CX_SY_CONVERSION_OVERFLOW

  • Cause: Overflow with arithmetic operation (type P, with specified length)
    Runtime Error: BCD_FIELD_OVERFLOW (catchable)
  • Cause: Operand too large or (intermediate) result too large
    Runtime Error: CONVT_OVERFLOW (catchable)

CX_SY_MOVE_CAST_ERROR

  • Cause: Source or target variable are not reference variables
    Runtime Error: MOVE_CAST_REF_ONLY

Non-Catchable Exceptions

  • Cause: Source field (type P) does not contain correct BCD format.
    Runtime Error: BCD_BADDATA
  • Cause: Assignment for deep structures not permitted if these overlap.
    Runtime Error: MOVE_COMPLEX_OVERLAP
  • Cause: Type conflict with the assignment between object references.
    Runtime Error: MOVE_INTERFACE_NOT_SUPPORTED,
    Runtime Error: MOVE_IREF_NOT_CONVERTIBLE,
    Runtime Error: MOVE_IREF_TO_OREF,
    Runtime Error: MOVE_OREF_NOT_CONVERTIBLE
  • Cause: Type conflict with the assignment between data references.
    Runtime Error: MOVE_DREF_NOT_COMPATIBLE
  • Cause: Assignment between the types involved not supported.
    Runtime Error: MOVE_NOT_SUPPORTED
  • Cause: Constants and literals must not be overwritten.
    Runtime Error: MOVE_TO_LIT_NOTALLOWED
  • Cause: onstants and literals must not be overwritten.
    Runtime Error: MOVE_TO_LIT_NOTALLOWED_NODATA
  • Cause: During a loop in an internal table, an attempt was made to overwrite a reference variable that is linked with the internal table by REFERENCE INTO.
    Runtime Error: MOVE_TO_LOOP_REF

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值