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: 

Where are the Filter Values for a BAdI Implementation stored?

zeno_rummler
Advisor
Advisor
0 Kudos
2,961

All,

* preface:

I have a configuration report for GDPR with a maintenance user interface, a simple ALV grid. The report reads meta data of Business Objects and DB tables. In case there is a GDPR relevant DB field or Business object node element, an expert maintains the found entity as GDPR relevant (or not). A generator produces table data or code (depends on the metadata) for teh GDPR relevant entites, which can be transported. The code is used for fulfilling GDPR

* note:

ILM is not available in our system.

* the main chapter:

The generated code is used in a BAdI, which uses filter values. Filter values depend on the entities found. Easy! To have a complete generation routine, I'd like to fill the BAdI filter values also with the generator.

See transaction se20 -> Enhancement Implementation -> filter values in the tree on the left side

Where are the filter values stored?

Can I add filter values with a program?

Zeno

1 ACCEPTED SOLUTION

zeno_rummler
Advisor
Advisor
0 Kudos
747

I was able to create a BAdI implementation including filters. See below.

Zeno

METHOD /a1sspc/if_dpp_cc_badi~write.
  DATA ls_filter TYPE enh_badi_filter.
  DATA lo_tool TYPE REF TO if_enh_tool.
  DATA lo_badi_impl TYPE REF TO cl_enh_tool_badi_impl.
  DATA ls_impl_data TYPE enh_badi_impl_data.

  TRY.
      ls_filter = get_filter( ).
    CATCH cx_enh_badi_not_found .
      ...
  ENDTRY.

  TRY.
      lo_tool = cl_enh_factory=>get_enhancement( lock           = 'X'
                                               ddic_enh       = space
                                               enhancement_id = iv_enhancement_id ).
*                                            enhancement_id = '/A1SSPC/EI_SPC' ). "l_enh_name ).
      lo_badi_impl ?= lo_tool.
      lo_badi_impl->if_enh_object~set_locked( is_locked = abap_true ).
      ls_impl_data = lo_badi_impl->get_implementation( EXPORTING impl_name =  iv_impl_name ).
*                                    EXPORTING impl_name =  '/A1SSPC/BADI_ILM_OTD_TREE' ).
      create_filter( EXPORTING it_entity_id_constant = it_ilm_entity_id_constants
                               is_filter             = ls_filter
                     CHANGING  cs_impl_data          = ls_impl_data ).
      ls_impl_data-active = abap_true.
      write_implementation( EXPORTING io_badi_impl = lo_badi_impl
                                      is_impl_data = ls_impl_data
                            CHANGING  cv_trkorr    = cv_trkorr ).
...
ENDMETHOD.

METHOD get_filter.
  DATA(lo_bd_util) = NEW cl_enh_badi_def_utility( ).
  DATA(lt_badi_data) = lo_bd_util->get_badi_def_data( EXPORTING im_spot = gc_enhancement_spot_name ).
  READ TABLE lt_badi_data REFERENCE INTO DATA(lr_badi_data) WITH KEY badi_name = gc_badi_name.
  IF lines( lr_badi_data->filters ) EQ 1.
    READ TABLE lr_badi_data->filters INTO rv_filter_name INDEX 1.
  ENDIF.
ENDMETHOD.

METHOD create_filter.
  DATA lr_entity_id TYPE REF TO /a1sspc/s_dpp_cc_entity_const.
  DATA ls_root TYPE enh_badiimpl_filter_root.
  DATA ls_filter_tree TYPE enh_badiimpl_filter_tree.
  DATA ls_value TYPE enh_badiimpl_filter_value.
  DATA ls_filter TYPE enh_badiimpl_filter_id.
  DATA lv_root_filter_id TYPE int4.
  DATA lv_filter_id TYPE int4.

  CLEAR cs_impl_data-filter_root.
  CLEAR cs_impl_data-filter_tree.
  CLEAR cs_impl_data-filter_values.
  CLEAR cs_impl_data-filters.
  IF it_entity_id_constant IS NOT INITIAL.
    " Create filter
    ADD 1 TO lv_filter_id.
    lv_root_filter_id = lv_filter_id.
    ls_filter-filter_name       = is_filter-filter_name.
    ls_filter-id                = lv_root_filter_id.
    INSERT ls_filter INTO TABLE ls_root-filters.
    ls_root-root = 1.
    INSERT ls_root INTO TABLE cs_impl_data-filter_root.
    LOOP AT it_entity_id_constant REFERENCE INTO lr_entity_id.
      ADD 1 TO lv_filter_id.
      ls_value-id                 = lv_filter_id.
      ls_value-filter_name        = is_filter-filter_name.
      ls_value-filter_type        = 'C'.
      ls_value-compare            = '='.
      ls_value-filter_char_value1 = lr_entity_id->ilm_entity_id.
      ls_value-check_type         = is_filter-check_type.
      INSERT ls_value INTO TABLE cs_impl_data-filter_values.
      ls_filter_tree-parent = lv_root_filter_id.
      ls_filter_tree-child = lv_filter_id.
      INSERT ls_filter_tree INTO TABLE cs_impl_data-filter_tree.
    ENDLOOP.
  ENDIF.
ENDMETHOD.

METHOD write_implementation.
  " add badi implementation
  io_badi_impl->delete_implementation( impl_name = is_impl_data-impl_name ).
  io_badi_impl->add_implementation( is_impl_data ).
  " Save and activate
  io_badi_impl->if_enh_object~save( CHANGING trkorr    = cv_trkorr ).
  io_badi_impl->if_enh_object~activate( CHANGING trkorr    = cv_trkorr ).
  io_badi_impl->if_enh_object~generate( ).
  io_badi_impl->if_enh_object~unlock( ).
ENDMETHOD.

4 REPLIES 4

raymond_giuseppi
Active Contributor
0 Kudos
747

Did you perform some analyzis of methods such as CL_BADI_MAIN=>GET_SELECTED_IMPLEMENTATIONS and SELECT_IMPLS?

0 Kudos
747

Thanks Guiseppi, a helpful hint! I found the DB tables! I will figure out, if there is an API to use.

Zeno

zeno_rummler
Advisor
Advisor
0 Kudos
748

I was able to create a BAdI implementation including filters. See below.

Zeno

METHOD /a1sspc/if_dpp_cc_badi~write.
  DATA ls_filter TYPE enh_badi_filter.
  DATA lo_tool TYPE REF TO if_enh_tool.
  DATA lo_badi_impl TYPE REF TO cl_enh_tool_badi_impl.
  DATA ls_impl_data TYPE enh_badi_impl_data.

  TRY.
      ls_filter = get_filter( ).
    CATCH cx_enh_badi_not_found .
      ...
  ENDTRY.

  TRY.
      lo_tool = cl_enh_factory=>get_enhancement( lock           = 'X'
                                               ddic_enh       = space
                                               enhancement_id = iv_enhancement_id ).
*                                            enhancement_id = '/A1SSPC/EI_SPC' ). "l_enh_name ).
      lo_badi_impl ?= lo_tool.
      lo_badi_impl->if_enh_object~set_locked( is_locked = abap_true ).
      ls_impl_data = lo_badi_impl->get_implementation( EXPORTING impl_name =  iv_impl_name ).
*                                    EXPORTING impl_name =  '/A1SSPC/BADI_ILM_OTD_TREE' ).
      create_filter( EXPORTING it_entity_id_constant = it_ilm_entity_id_constants
                               is_filter             = ls_filter
                     CHANGING  cs_impl_data          = ls_impl_data ).
      ls_impl_data-active = abap_true.
      write_implementation( EXPORTING io_badi_impl = lo_badi_impl
                                      is_impl_data = ls_impl_data
                            CHANGING  cv_trkorr    = cv_trkorr ).
...
ENDMETHOD.

METHOD get_filter.
  DATA(lo_bd_util) = NEW cl_enh_badi_def_utility( ).
  DATA(lt_badi_data) = lo_bd_util->get_badi_def_data( EXPORTING im_spot = gc_enhancement_spot_name ).
  READ TABLE lt_badi_data REFERENCE INTO DATA(lr_badi_data) WITH KEY badi_name = gc_badi_name.
  IF lines( lr_badi_data->filters ) EQ 1.
    READ TABLE lr_badi_data->filters INTO rv_filter_name INDEX 1.
  ENDIF.
ENDMETHOD.

METHOD create_filter.
  DATA lr_entity_id TYPE REF TO /a1sspc/s_dpp_cc_entity_const.
  DATA ls_root TYPE enh_badiimpl_filter_root.
  DATA ls_filter_tree TYPE enh_badiimpl_filter_tree.
  DATA ls_value TYPE enh_badiimpl_filter_value.
  DATA ls_filter TYPE enh_badiimpl_filter_id.
  DATA lv_root_filter_id TYPE int4.
  DATA lv_filter_id TYPE int4.

  CLEAR cs_impl_data-filter_root.
  CLEAR cs_impl_data-filter_tree.
  CLEAR cs_impl_data-filter_values.
  CLEAR cs_impl_data-filters.
  IF it_entity_id_constant IS NOT INITIAL.
    " Create filter
    ADD 1 TO lv_filter_id.
    lv_root_filter_id = lv_filter_id.
    ls_filter-filter_name       = is_filter-filter_name.
    ls_filter-id                = lv_root_filter_id.
    INSERT ls_filter INTO TABLE ls_root-filters.
    ls_root-root = 1.
    INSERT ls_root INTO TABLE cs_impl_data-filter_root.
    LOOP AT it_entity_id_constant REFERENCE INTO lr_entity_id.
      ADD 1 TO lv_filter_id.
      ls_value-id                 = lv_filter_id.
      ls_value-filter_name        = is_filter-filter_name.
      ls_value-filter_type        = 'C'.
      ls_value-compare            = '='.
      ls_value-filter_char_value1 = lr_entity_id->ilm_entity_id.
      ls_value-check_type         = is_filter-check_type.
      INSERT ls_value INTO TABLE cs_impl_data-filter_values.
      ls_filter_tree-parent = lv_root_filter_id.
      ls_filter_tree-child = lv_filter_id.
      INSERT ls_filter_tree INTO TABLE cs_impl_data-filter_tree.
    ENDLOOP.
  ENDIF.
ENDMETHOD.

METHOD write_implementation.
  " add badi implementation
  io_badi_impl->delete_implementation( impl_name = is_impl_data-impl_name ).
  io_badi_impl->add_implementation( is_impl_data ).
  " Save and activate
  io_badi_impl->if_enh_object~save( CHANGING trkorr    = cv_trkorr ).
  io_badi_impl->if_enh_object~activate( CHANGING trkorr    = cv_trkorr ).
  io_badi_impl->if_enh_object~generate( ).
  io_badi_impl->if_enh_object~unlock( ).
ENDMETHOD.

0 Kudos
747

Improvements are welcome.

Note: this code is not yet productive but shows teh how-to. Catch statements are handled properly in productive code.