Developer

Implementing a Filter for SALESORDERS_GET_ENTITYSET

Implement the OData $filter system query option for SALESORDERS_GET_ENTITYSET.

Procedure

  1. From the Class Builder screen for class ZCL_Z_EPM_RKT_DPC_EXT, open the implementation of the method SALESORDERS_GET_ENTITYSET.
  2. Reimplement the method with the following code that filters before calling the BAPI_EPM_BP_GET_LIST BAPI function. New code is highlighted in bold.
    method SALESORDERS_GET_ENTITYSET.
    
      DATA:ls_filter_select_options   TYPE /iwbep/s_mgw_select_option,
           ls_mgw_select_options      TYPE /iwbep/s_mgw_select_option,
           ls_mgw_range_options       TYPE /iwbep/s_cod_select_option,
           ls_range_soid              TYPE BAPI_EPM_SO_ID_RANGE,
           lt_range_soid              TYPE TABLE OF BAPI_EPM_SO_ID_RANGE,
           ls_range_buyername         TYPE BAPI_EPM_CUSTOMER_NAME_RANGE,
           lt_range_buyername         TYPE TABLE OF BAPI_EPM_CUSTOMER_NAME_RANGE.
      DATA:lv_soid_low(10)            TYPE N,
           lv_soid_high(10)           TYPE N,
           ls_max_rows                TYPE BAPI_EPM_MAX_ROWS.
    
      field-symbols: <fs_key> type /iwbep/s_mgw_name_value_pair.
      data: ls_company_name   type SNWD_COMPANY_NAME.
      data: lt_range          type table of BAPI_EPM_CUSTOMER_NAME_RANGE,
            ls_range          type          BAPI_EPM_CUSTOMER_NAME_RANGE,
            lv_bp_id(10)      type N.
    
    * Return all SalesOrders if no navigation path.
      if it_navigation_path is initial.
    *   Process filters
        LOOP AT it_filter_select_options INTO ls_filter_select_options.
          LOOP AT ls_filter_select_options-select_options INTO ls_mgw_range_options.
            TRANSLATE ls_filter_select_options-property TO UPPER CASE.
            CASE ls_filter_select_options-property.
              WHEN 'SOID'.
                lv_soid_low = ls_mgw_range_options-low.  "Workaround for adding leading zeros
                if ls_mgw_range_options-high is not initial.
                  lv_soid_high = ls_mgw_range_options-high.
                endif.
    
                MOVE-CORRESPONDING ls_mgw_range_options TO ls_range_soid.
    
                ls_range_soid-low = lv_soid_low.
                if ls_range_soid-high is not initial.
                  ls_range_soid-high = lv_soid_high.
                endif.
    
                APPEND ls_range_soid TO lt_range_soid.
              WHEN 'BUYERNAME'.
                MOVE-CORRESPONDING ls_mgw_range_options TO ls_range_BUYERNAME.
                APPEND ls_range_BUYERNAME TO lt_range_BUYERNAME.
            ENDCASE.
          ENDLOOP.
        ENDLOOP.
    
        ls_max_rows-bapimaxrow = is_paging-top.
    
        CALL FUNCTION 'BAPI_EPM_SO_GET_LIST'
         EXPORTING
          MAX_ROWS                = ls_max_rows
         TABLES
           SOHEADERDATA            = et_entityset
    *      SOITEMDATA              =
           SELPARAMSOID            = lt_range_soid
           SELPARAMBUYERNAME       = lt_range_buyername
    *      SELPARAMPRODUCTID       =
    *      RETURN                  =
                  .
      else.
    *   Navigation path from BusinessPartners. Return sales orders for a specific business partner.
    *   However, can only lookup using "Company Name", not BP_ID. So need to get Company Name using BP_ID first.
        read table it_key_tab assigning <fs_key> index 1.
        lv_bp_id = <fs_key>-value.
    
    *   Look up buyer name based on BP_ID
        select single company_name
          from snwd_bpa
          into ls_company_name
          where bp_id = lv_bp_id.
    
        ls_range-sign = 'I'.
        ls_range-option = 'EQ'.
        ls_range-low = ls_company_name.
        append ls_range to lt_range.
    
        CALL FUNCTION 'BAPI_EPM_SO_GET_LIST'
    *     EXPORTING
    *       MAX_ROWS                =
         TABLES
           SOHEADERDATA            = et_entityset
    *       SOITEMDATA              =
    *       SELPARAMSOID            =
           SELPARAMBUYERNAME       = lt_range
    *       SELPARAMPRODUCTID       =
    *       RETURN                  =
                  .
      endif.
    
    endmethod.
    
  3. Click the Activate icon.

  4. If you see any warnings, recheck the code, correct any mistakes, then click Activate again.
  5. Click Back to return to the Class Interface screen.