|
原帖由 awarecan 于 2009-5-21 10:14 发表 ![]()
可能连last_value都不用声明,在at end of key里直接用itab也行。
data itab type table of xxx.
data found.
sort itab by key date.
loop itab.
at new key.
clear found.
end at.
if found is initial.
if itab-date >= 200903.
itab is your need
found = 'X'.
endif.
endif.
at end of key.
if found is initial.
itab is your need
endif.
end at.
endloop.
“程序 = 算法 + 数据结构”
上面这个算法非常好,我觉得这是实现楼主需求的最佳算法。另外我想补充几点数据结构或者说是ABAP语法的看法:
1. loop itab 在ABAP中的语句是loop at itab.
2. end at 在ABAP中是一个关键字endat.
3. at new f. at end of f. 要考虑f前面的字段。比如内表的字段是f1,f2,...fn. 如果使用at new f2这样的语句,结果会被f1影响。详细情况请debug。
4. at end of f.语句执行后,f后面的字段值会丢失(变成*)。
因此,要用楼上的算法写一个完整的程序实现楼主的需求,可能需要解决上面的几个问题。 |
|