问题描述
是否有与 ABAP 程序的 ROW_NUMBER()
函数等效的函数?
Is there an equivalent for the ROW_NUMBER()
function for ABAP programs?
该函数在SQL中的用法如下:
This function is used as follows in SQL:
SELECT ROW_NUMBER() OVER (ORDER BY SomeField) AS Row, *
FROM SomeTable
它应该在哪里返回行号作为结果行中的第一列(我不确定它是结果集中的行号还是源表中的行号).我发现该语句可以在 SAP Business One 中使用,但似乎找不到与 Open SQL 等效的语句.
Where it should return the line number as the first column in the resulting rows (I'm unsure if it will be the line number in the result set or the line number in the source table). I've found that this statement can be used in SAP Business One but can't seem to find an Open SQL equivalent.
是否有一个或我将被迫手动遍历生成的 itab 以分配索引?
Is there one or will I be forced to manually loop over the resulting itab to assign indices?
推荐答案
如果这是为了存储行,则记录被保留以供以后在 ABAP 程序中访问,您不需要存储它.它在您循环时保留.类似的东西.
If this is for storing the row the record is kept on for later access within the ABAP program, you don't need to store it. It is kept as you loop through. SOmething like.
LOOP AT itab INTO wa_itab.
write /:sy-tabix "This is the index of the record within the table
ENDLOOP.
如果您正在修改内容然后将它们存储回表中,请为您的值添加一列并执行以下操作:数据:my_string TYPE 字符串.
If you are modifying the contents then storing them back into the table, add a column for your value and do something like:DATA: my_string TYPE string.
LOOP AT itab INTO wa_itab.
my_string = sy-tabix.
CONCATENATE some_text my_string more_text into wa_itab-my_field.
MODIFY itab FROM wa_itab. "Here you can leave out INDEX sy-tabix because it is inside a loop and the current line will be used.
CLEAR my_string.
ENDLOOP.
这篇关于ROW_NUMBER() 的打开 SQL 等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!