[英]Loop at and sy-subrc relation
I have this problem during loop statement.我在循环语句中遇到了这个问题。
I have a loop:我有一个循环:
loop at lt assigning <ls> where <condition> (im using loop instead of reaf table coz i need to use GE and LE logical statements)
if sy-subrc = 0.
result = <ls>-FIELD.
else.
result = ''.
endif.
endloop.
So the problem is it skips the sy-subrc check.所以问题是它跳过了 sy-subrc 检查。 When loop executes and doesnt find a record (sy-subrc = 4) it doesnt assign '' into the result field and keepeing the initial statement instead.当循环执行并且没有找到记录(sy-subrc = 4)时,它不会将 '' 分配给结果字段,而是保留初始语句。
Whats the problem?有什么问题?
The return code is set after the loop (same for select
and other loop structures).返回码在循环之后设置(对于select
和其他循环结构相同)。 So you need something like:所以你需要这样的东西:
loop at lt assigning <ls> where <condition>"(im using loop instead of reaf table coz i need to use GE and LE logical statements)
endloop.
if sy-subrc = 0.
result = <ls>-FIELD.
else.
result = ''.
endif.
In this case you should use a read
-statement (you mention a problem with GE/LE - this may be worth another question).在这种情况下,您应该使用read
语句(您提到了 GE/LE 的问题 - 这可能值得另一个问题)。
Now you loop on all entries.现在您循环所有条目。
As an alternative you could stop after the first entry:作为替代方案,您可以在第一次输入后停止:
result = ''. "Initialize for not-found-entry.
loop at lt assigning <ls> where <condition>.
result = <ls>-FIELD. "Take the found entry
exit. "Stop after first entry
endloop.
Without the exit
you would get the last entry.如果没有exit
您将获得最后一个条目。 If the order is relevant, you may also add a relevant sort.如果订单相关,您还可以添加相关排序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.