ABAP: Counting table lines with a condition with REDUCE

With the REDUCE operator you can count entries in a table for which a condition is met.

DATA(lv_lines) = REDUCE i( INIT x = 0 FOR ls_mdpb IN lt_mdpb WHERE ( matnr = lv_matnr ) NEXT x = x + 1 ).
1