ABAP FILTER对内表数据进行筛选

ABAP提供FILTER语法对内表数据进行筛选,
测试代码如下:

    SELECT *
      FROM marc
      INTO TABLE @lt_marc
      UP TO 1000 ROWS.

    IF value ='X'.

      DATA(table1) =
        FILTER #( lt_marc USING KEY group_marc               "按关键字筛选
                    WHERE matnr   = CONV #( to_upper( matnr ) ) AND
                          werks = CONV #( to_upper( werks ) ) ).

      cl_demo_output=>display( table1 ).

    ELSE.

      DATA(table2) =
        FILTER #( lt_marc EXCEPT USING KEY group_marc       "按关键字排除
                    WHERE matnr   = CONV #( to_upper( matnr ) ) AND
                          werks = CONV #( to_upper( werks ) ) ).

      cl_demo_output=>display( table2 ).

1.勾选筛选USING KEY,满足屏幕条件的数据从内表中被筛选出:ABAP FILTER对内表数据进行筛选_第1张图片
如下代码:

      DATA(table1) =
        FILTER #( lt_marc USING KEY group_marc               "按关键字筛选
                    WHERE matnr   = CONV #( to_upper( matnr ) ) AND
                          werks = CONV #( to_upper( werks ) ) ).

2.取消筛选EXCEPT USING KEY,则筛选内表中不满足条件的数据全都展示出来:
ABAP FILTER对内表数据进行筛选_第2张图片
如下代码:

      DATA(table2) =
        FILTER #( lt_marc EXCEPT USING KEY group_marc       "按关键字排除
                    WHERE matnr   = CONV #( to_upper( matnr ) ) AND
                          werks = CONV #( to_upper( werks ) ) ).

你可能感兴趣的:(ABAP语法,abap,sql)