增加一个整数
有时,ABAP 会因为非常简单的任务(例如在循环内递增整数)而让我抓狂……
这是我的尝试:
METHOD test.
DATA lv_id TYPE integer.
lv_id = 1.
LOOP AT x ASSIGNING <y>.
lv_id = lv_id+1.
ENDLOOP.
ENDMETHOD.
这会导致错误消息字段类型“I”不允许子字段访问。
Sometimes ABAP drives me crazy with really simple tasks such as incrementing an integer within a loop...
Here's my try:
METHOD test.
DATA lv_id TYPE integer.
lv_id = 1.
LOOP AT x ASSIGNING <y>.
lv_id = lv_id+1.
ENDLOOP.
ENDMETHOD.
This results in the error message Field type "I" does not permit subfield access.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您自己已经回答了这个问题,但为了让事情更清楚一点:
是一个算术表达式 - 将变量的值加 1。
是对字符变量的偏移操作。例如,如果变量包含
ABC
,则variable+1
为BC
。在处理 NUMC 时,这尤其令人困惑。例如,对于
variable = '4711'
,variable + 1
计算结果为4712
,而variable+1
是'711'
(字符序列)。您看到的错误发生是因为无法对非字符变量执行索引操作。
You already answered the question yourself, but to make things a bit clearer:
is an arithmetic expression - add 1 to the value of the variable.
is an offset operation on a character variable. For example, if variable contains
ABC
,variable+1
isBC
.This can be especially confusing when dealing with NUMCs. For example, with
variable = '4711'
,variable + 1
is evaluated to4712
, whereasvariable+1
is'711'
(a character sequence).The error you saw occurred because it's not possible to perform the index operation on a non-character-like variable.
你的意思是:
顺便说一下,当你循环内部表时,SY-TABIX 有循环计数器。
You mean like:
By the way, when you loop over an internal table, SY-TABIX has the loop counter.
呃,我明白了。
这是该死的空间...
有效...
Uh, I got it.
It's the f****** spaces...
works...
简单
数据:gv_inc类型I。
将此语句放入循环中
gv_inc = gv_inc + 1 。
Simple
DATA : gv_inc type I .
place this statement in loop
gv_inc = gv_inc + 1 .
从 SAP NetWeaver 版本 7.54 开始,您还可以使用:
而不是
快乐编码!
from SAP NetWeaver Version 7.54 you can also use:
Instead of
Happy coding!
如果您要增加每个循环周期,那么您可以直接获取表大小。
If you are going to increment every loop cycle than you can directly get the table size.