![](/img/trans.png)
[英]How to delete DDIC table records which have different id than row number in internal table?
[英]How to count number of records of a field in internal table in select statment?
我使用了ty_marc類型的內部表。 在此內部表中,我使用了兩個字段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。
有兩個簡單的選項。
如果您實際上並不關心工廠(倉庫),請在select
語句中使用group by
子句和count
函數。 就像是:
select matnr, count(*)
from marc
where matnr in so_matnr
group by matnr
into table it_marc_count.
結構it_marc_count的第二個位置需要有一個整數字段(顯然,第一個位置需要有matnr)。
如果確實需要工作程序,最簡單的方法是按matnr排序it_marc,然后在loop at
循環(或類似方法)中使用at end
和sum
構造。 在循環中處理表條目末尾的示例應該可以幫助您入門。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.