简体   繁体   English

循环内表并使用 if 语句删除内表中的一行

[英]Loop at internal table and delete a row in the internal table using a if statement

I have my internal table it_mseg .我有我的内部表it_mseg In this table, there is a field called amnt .在此表中,有一个名为amnt的字段。

I want to check for each row in it_mseg , if the field amnt is greater equal 10. If it is, I want to delete it from the internal table.我想检查it_mseg每一行,如果字段amnt大于等于 10。如果是,我想从内部表中删除它。

So that at the end, when I display the table using ALV-Grid, only the rows where the value of the field amnt is lower equal 10 will be displayed.所以最后,当我使用 ALV-Grid 显示表格时,只会显示字段amnt的值amnt等于 10 的行。

I know that this is somehow done with Loop at it_mseg , but I just can't get it right.我知道这是Loop at it_msegLoop at it_mseg某种方式完成的,但我就是做对了。

EDIT: I want to do it with a loop, so I can do something more complex than just GE 10.编辑:我想用循环来做,所以我可以做一些比 GE 10 更复杂的事情。

You can do it with LOOP, but even simplier with DELETE:你可以用 LOOP 来做,但用 DELETE 更简单:

DELETE it_mseg WHERE amnt GT 10.

If you still want to do it with LOOP (because you want to check/change something else in the internal table):如果你仍然想用 LOOP 来做(因为你想检查/更改内部表中的其他内容):

LOOP AT it_mseg
     ASSIGNING FIELD-SYMBOL(<ls_mseg>).
  DATA(lv_tabix) = sy-tabix. "save sy-tabix for later use
... "do somthing else
  IF <ls_mseg>-amnt GT 10.
    DELETE it_mseg INDEX lv_tabix.
  ENDIF.
... "do something else
ENDLOOP.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM