如何在select语句中统计内表某个字段的记录数?
我采用了 ty_marc 类型的内部表。 在此内部表中,我采用了 2 个字段 matnr 和 werks_d。 我想根据用户给出的条目来计算工厂(marc-werks)制造的材料数量。
我将代码编写为...
if so_matnr is not initial.
select matnr werks from marc
into table it_marc
where matnr in so_matnr.
endif.
loop at it_marc into w_marc.
write :/ w_marc-matnr. ( how to count total number of material eg:- material number : 100-100 to 100-110).
w_marc-werks.
endloop.
我想计算材料的总数并在同一内部表的另一个字段中显示计数。 注意:物料编号 100-100 可能有 10 种物料,因此我希望同一内表的另一个字段中的计数为 10,而 100-110 可能有 n 条记录,并且该字段中的计数应为 n。
I took a internal table of type ty_marc.
in this internal table i took 2 fields matnr and werks_d.
I want to count number of materials manufactured in the plant (marc-werks) based on the entry given by user.
I wrote the code as...
if so_matnr is not initial.
select matnr werks from marc
into table it_marc
where matnr in so_matnr.
endif.
loop at it_marc into w_marc.
write :/ w_marc-matnr. ( how to count total number of material eg:- material number : 100-100 to 100-110).
w_marc-werks.
endloop.
I want to count total number of material and display the count in another field of same internal table.
Note : there could be 10 material for material number 100-100, so i want the count as 10 in another field of same internal table and 100-110 could have n records and the count should be n in the field.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两个简单的选择。
如果您实际上并不关心工厂 (werks),请在
select
语句中使用group by
子句和count
函数。类似于:结构 it_marc_count 需要在第二个位置有一个整数字段(显然第一个位置有 matnr)。
如果您确实需要 werks,最简单的方法是按 matnr 对 it_marc 进行排序,然后在
loop at
循环中使用at end
和sum
结构(或者类似的东西)。 处理循环中的表条目 应该可以帮助你开始。There are two easy options.
If you don't actually care about the plant (werks), use the
group by
clause and thecount
function in yourselect
statement. Something like:Structure it_marc_count would need to have an integer field in the second position (and matnr in the first obviously).
If you do need werks, the easiest is to sort it_marc by matnr then use the
at end
andsum
constructs in theloop at
loop (or something similar). The examples at the end of Processing Table Entries in Loops should get you started.