Introduction to filter in ABAP

    * FILTER operator is used to filter the internal table and getting the subset of data into a new internal table.

    * Previously, we filter the data by creating a loop with where condition and appending the data to new internal table.

    *  In SAP ABAP new syntax, instead of loop with where condition and appending the filtered data to new internal table, we can use filter operator.

    * There are 2 ways to apply the FILTER operator.

            - FILTER with single values - In this we pass the filtering values using WHERE condition and filtered data appears into new internal table.

            - FILTER with filter table - In this we need two internal tables. One internal table has the actual data on which filtering is applied and another is filtering internal table which has the filter values used for filtering.

Report

REPORT zab_rp_filter_new.

TABLES: vbak.

TYPESBEGIN OF ls_vbak,
         vbeln TYPE vbeln_va,
         vbtyp TYPE vbtypl,
       END OF ls_vbak.
DATA: lt_filter TYPE TABLE OF ls_vbak,
      lr_filter TYPE ls_vbak.

SELECT-OPTIONS : s_vbeln FOR vbak-vbeln.

IF s_vbeln IS NOT INITIAL.
  SELECT vbeln,vbtyp
    FROM vbak
    INTO TABLE @DATA(lt_vbak)
    WHERE vbeln IN @s_vbeln.
ENDIF.
IF
 lt_vbak IS NOT INITIAL.
  LOOP AT lt_vbak INTO DATA(lr_vbak).
    IF lr_vbak-vbtyp 'A'.
      lr_filter-vbeln lr_vbak-vbeln.
      lr_filter-vbtyp lr_vbak-vbtyp.
      APPEND lr_filter TO lt_filter.
      CLEARlr_filter.
    ENDIF.
  ENDLOOP.
ENDIF.

cl_demo_output=>displaylt_filter ).

Input



Output




********************************Thank You*****************************

Comments

Popular posts from this blog

New syntax for append- VALUE (new syntax 7.4+) in ABAP

Pf status and user command in factory method - OOPS ALV in ABAP

Add custom tab to me51n at item level in ABAP