opensql+initialization method syntax

i.在ABAP编程中,使用for all entries in 是必不可少的语句,相信大家都使用过,例如:
data: begin of ig_bseg occurs 0,
          werks like bseg-werks,
          belnr  like bseg-belnr,
          gjahr  like bseg-gjahr,
          dmbtr like bseg-dmbtr,
        end of ig_bseg.
if not ig_bkpf[] is initial.
  select werks belnr gjahr dmbtr into corresponding fields of table ig_bseg
  from bseg for all entries in ig_bkpf
  where werks = ig_bkpf-werks and belnr = ig_bkpf-belnr and  gjahr = ig_bkpf-gjahr.
endif.
需要注意以下问题
1、首先,必须要判断For all entries in后面的内表是否为空,如果它为空的话,那么在where条件中的与内表中字段进行比较的结果全部为真,也就是全部满足条件,这会导致取出非常多的数据,极大地影响系统的性能。
2、对于上例,按照逻辑分析可以取出某个凭证的所有行项目,但是实际情况会与你预期的不一致,如果某个凭证的多个行项目的dmbtr值是完全一样的,那么在内表ig_bseg中你只会得到一行记录,而不是多行,它自动使用了distinct,或者说删除了重复的行,这是个非常致命的问题,会导致你的程序逻辑错误,而且很难以查找,解决的办法就是要保证内表ig_bseg中取出的数据必须要有主键字段,在本例中,需要再添加buzei字段。
ii.

REFRESH

 

Syntax

REFRESH itab.

Effect

This statement sets an internal table itab to its initial value, meaning that it deletes all rows of the internal table. The memory space required for the table is freed up to the initial memory size INITIAL SIZE. For itab, you must specify an internal table.

To delete all rows and free the entire memory space occupied by rows, you can use the statement FREE.

Note

The statement REFRESH itab acts for all internal tables like CLEAR itab[]. If an internal table itab has a header line, then the table body and not the header line is initialized. If the internal table itab has no header line, REFRESH itab acts like CLEAR itab. Therefore, you should always use CLEAR instead of REFRESH.


CLEAR

 

Syntax

CLEAR dobj [ {WITH val [IN {BYTE|CHARACTER} MODE] }
           | {WITH NULL} ].


Extras:

1. ... WITH val [IN {BYTE|CHARACTER} MODE]

2. ... WITH NULL

Effect

Without the optional additions, the data object dobj is assigned the type-specific initial value. The following applies:

  • The initial values are assigned to elementary data types according to the table of built-in ABAP types.

  • Reference variables are assigned null references.

  • Structures are set to their initial values component by component.

  • All rows in an internal table are deleted. All the memory required for the table, except for the initial memory requirement, is released (see Declaring Internal Tables). The FREE statement is used to release the memory space occupied by the rows of internal tables.

The optional additions allow you to fill the spaces of a data object with other values than the initial value.

Note

If dobj is an internal table with a header line, you must specify dobj[] to delete the rows, otherwise only the header line will be deleted.

Addition 1

... WITH val [IN {BYTE|CHARACTER} MODE]

Effect

If you use the WITH val addition and specify BYTE or CHARACTER MODE, all spaces are replaced either with the first byte or the first character in val. If dobj is of the type string or xstring (as of Release 6.10), the string is processed in its current length.

The IN BYTE and CHARACTER MODE additions can be used as of Release 6.10 (see also Processing Byte Strings and Character Strings). Without specification and before Release 6.10 the IN CHARACTER MODE addition applies. Depending on the addition, the data object dobj must be either byte-type or character-type and the data object val must be either byte-type or character type and have the length 1. Before Release 6.10, dobj and val must be flat. If dobj and val do not have the correct type and correct length in a non- Unicode program, they are still handled as if they do, independently of the actual type. In Unicode programs, this will cause a Syntax error or an exception that cannot be handled.

Example

The byte string hexstring as assigned a specific byte value over the entire current length.

DATA: hexstring TYPE xstring,
      hex       TYPE x LENGTH 1 VALUE 'FF'.
...
hexstring = '00000000'.
...
CLEAR hexstring WITH hex IN BYTE MODE.

Addition 2

... WITH NULL

Effect

This addition, which is not allowed in ABAP Objects, replaces all bytes of dobj with the value hexadecimal 0. In this case, the data object dobj must be flat.

Note

The WITH NULL addition should only be used for byte-type data objects and therefore be replaced with the CLEAR WITH val addition, which - in this context - at least ensures a higher level of security in Unicode programs.


FREE

 

Syntax

FREE dobj.

Effect

The FREE statement has the same effect as the CLEAR

statement for any data objects except internal tables.

For internal tables, FREE has the same effect as the REFRESH statement, though the entire memory area occupied by the table rows is released, and the initial memory area remains unoccupied. If dobj is a structure with table-like components, the memory of each table-like component is released.

Note

If dobj is an internal table with a header line, FREE has the same effect as REFRESH on the table body, and not the header line.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值