Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP 7.4 FILTER # Performance

kuanchin
Explorer
1,635

Dear Expert,

Good afternoon, would like to get advice :

Looping an internal table i_material and called BAPI_MATERIAL_STOCK_REQ_LIST.

After that, APPENDING MRP items into another internal table gt_mrp_items.

After the LOOP of i_material , records with this 3 type of MRP elements (AR ; SB ; BB) will be FILTER to individual internal table such as gt_mrp_ar ; gt_mrp_sb and gt_mrp_bb for different logic.

LOOP AT i_material INTO DATA(lwa_material).
* Calling this bapi to get details for materials
  CALL FUNCTION 'BAPI_MATERIAL_STOCK_REQ_LIST'
    EXPORTING
      plant = l_plant
      get_item_details = abap_true
      get_ind_lines = abap_true
      material_long = lwa_material-matnr
      selection_rule = gc_rule
    IMPORTING
      return = lwa_return
    TABLES
      mrp_items = lt_mrp_items.

  IF lwa_return-type = gc_s.
    APPEND LINES OF lt_mrp_items TO gt_mrp_items.
**(A)**
    DATA(lt_mrp_ar) = FILTER #( gt_mrp_items USING KEY mrp_element_ind WHERE mrp_element_ind = 'AR' ).
    APPEND LINES OF lt_mrp_ar TO gt_mrp_ar
  ENDIF.
ENDLOOP.

**(B)**
DATA(gt_mrp_ar) = FILTER #( gt_mrp_items USING KEY mrp_element_ind WHERE mrp_element_ind = 'AR' ).

My question, shall I FILTER # after the LOOP or within the LOOP ?

(A) or (B) which one more efficient ?

Kindly advice.

Many thanks.

Kuan.

4 REPLIES 4

DoanManhQuynh
Active Contributor
276

Hello.

I think it would be better to filter outside the loop. its not because of the FILTER statement but your code when you do inside the loop you need 1 more helper variable ( LT_MRP_AR ) then APPEND which make it slower than just direct filter it.

DATA(LT_MRP_AR) = FILTER #( GT_MRP_ITEMS USING KEY MRP_ELEMENT_IND WHERE MRP_ELEMENT_IND = 'AR' ).
 APPEND LINES OF LT_MRP_AR TO GT_MRP_AR.

GT_MRP_AR = FILTER #( GT_MRP_ITEMS USING KEY MRP_ELEMENT_IND WHERE MRP_ELEMENT_IND = 'AR' ).

0 Kudos
276

Dear Quynh,

Thanks for your information.

Very appreciate.

Best Regards,

Kuan.

matt
Active Contributor
0 Kudos
276

Please in future use the code button in the editor when posting code. I've done it for you this time.

Also - gc_s as a constant for 'S'? Really? You know the idea of constants is to fix values and make your code more understandable. How about gc_success?

kuanchin
Explorer
0 Kudos
276

Dear Matthew,

Sorry for late reply. And thanks for your help -> Posting code.

Will try to made the variable more 'meaningful' in future.

Thanks a lot.

Best Regards,

Kuan.