MAI Templates Assignment BADI Implementation

Starting with SAP Focused Run FP01 BADI “BADI_TEMPLATE_ASSIGNMENT” is foreseen to be executed whenever a MAI configuration is done. In case an implementation is provided, it will be executed after all potential template candidates have been identified. This BADI Interface considers:

  • Already assigned templates, including manual assignments (which have been set application “Reconfigure Templates”)
  • Default templates which match the current product versions and software components which are installed on the current system

The method to be implemented contains the following parameters as follows:

  • IF_TEMPLATE_ASSIGNMENT~CHANGE_TMPL_ASSIGNMENTS_TO_MOS
  • IT_CONTEXT Importing Type CL_ALRT_CFG_MAI_API_ENQUIRY=>PASSED_TREE_ELEMENTS
  • IT_PRODUCT_MAPPING Importing Type    ACTPID_TO_CID_DIR_SORTED
  • CT_TEMPLATE_ASSIGNMENT_TO_MO Changing Type ACT_TMPL_ASSIGNMENT_TO_MO

Structure of the LMDB objects looks like this:

Structure of list of products has following structure:


1 "Get System type" for each Managed Object example:

Use the class cl_lmdb_mai_hier_tree_element to access the technical system or attributes which are related to the LMDB object.

Example

CL_LMDB_MAI_HIER_TREE_ELEMENT=> IF_LMDB_MAI_HIER_TREE_ELEMENT~GET_PARENT

                  (Host -> Logical Host -> Technical Instance -> Technical system)

                  (Database Instance -> Database)

CL_LMDB_MAI_HIER_TREE_ELEMENT=> IF_LMDB_MAI_HIER_TREE_ELEMENT~GET_GENERIC_CIM_PROPERTY_VALUE

                  Importing   CIM_CLASS_NAME  'SAP_ApplicationSystem'

                              PROPERTY_NAME   'itadministrationrole'

                  Returning   RESULT

Example of CIM Instance Properties values reading: “ITAdministrationRole”.

2 Get the Templates that can be assigned to the Managed Object

List of fitting templates

 DATA:

    iv_template_id      TYPE ac_guid,

    lr_context          TYPE REF TO cl_alrt_cfg_mai_api_enquiry=>passed_tree_element,

    lr_product          TYPE REF TO acpid_to_cid_dir,

    lr_template         TYPE REF TO acs_template_assignment,

    iv_searchstring     TYPE string VALUE '<my special Template>',

    template_assignment TYPE REF TO acs_tmpl_assignment_to_mo

    .

* multiple products can be assigned to a single LMDB object

LOOP AT it_product_mapping REFERENCE INTO lr_product WHERE context_id EQ lr_context->context_id.

   cl_mai_rep_initializer=>initialize( EXPORTING iv_technical_scenario = lr_product->tech_scenario "pass the technical scenario/monitoring use case (eg: T_SYS_MON for Technical system monitoring)"

 

IMPORTING eo_assignment_factory = DATA(lo_assignment_factory)

          eo_template_factory   = DATA(lo_template_factory) ).

TRY.

   DATA(lo_context_store) = cl_alrt_cfg_store_contextdir=>get_instance( ).

   DATA(lo_managed_object) = lo_context_store->get_context_model( iv_context_id = lr_context->context_id ).              "Pass the context id"

   DATA(li_assignment) = lo_assignment_factory->get_assignment( ii_managed_object   = lo_managed_object  io_template_factory = lo_template_factory  ).

   DATA(lt_fitting_templates) = li_assignment->get_fitting_templates( iv_technical_scenario = lr_product->tech_scenario ). "pass the technical scenario/monitoring use case" ).

CATCH cx_alrt_cfg_directory_root.

 

* do error handling here…

ENDTRY.

CHECK lt_fitting_templates IS NOT INITIAL.


3 Change the template assigned to the Managed Object

Choose one template that meet special requirement, for example, the template with name start with  Z_< ITAdministrationRole >, modify the template ID from CT_TEMPLATE_ASSIGNMENT_TO_MO.

Change template

LOOP AT lt_fitting_templates REFERENCE INTO lr_template.

    IF lr_template->template_ref->get_name( )  CS iv_searchstring.

        iv_template_id = lr_template->template_id.

    READ TABLE ct_template_assignment_to_mo

    WITH TABLE KEY

        context_id = lr_context->context_id product_id = lr_product->product_id REFERENCE INTO template_assignment.

        IF sy-subrc EQ 0.

            template_assignment->template_id = iv_template_id.

        ENDIF.

    ENDIF.

ENDLOOP.