简体   繁体   中英

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

I have my internal table it_mseg . In this table, there is a field called 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.

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.

I know that this is somehow done with Loop at it_mseg , but I just can't get it right.

EDIT: I want to do it with a loop, so I can do something more complex than just GE 10.

You can do it with LOOP, but even simplier with 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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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