Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
AKHILARAPARTHI
Explorer
6,491

            Business rules are one of the important feature in Master Data Governance Process. Deriving the value for particular field of an entity can be done either by BRF Plus or BADI. This Blog Post explains you about creating complex or dynamic derivation rules which can be achieved through BADI.

         In this post , I am taking the example of deriving Cost Centre value from Cost Centre Entity of Finance     Data Model . Its a kind of Mandatory and derivation rule and the naming convention should be followed.

RULE :

          First two characters are defined using the backend table which is the custom table provided by the business based on 'Company Code' and 'Business Area' fields in Cost Center entity . The rest of the characters are auto populated based on the next number available for the range.

Ex: If Cost Centre number available in the system for LM range is LM0025. So , when requestor is creating the new cost center the CC value should be auto populated to LM0026 .

IMPLEMENTATION :  

           1. Implement your custom logic in 'IF_EX_USMD_RULE_SERVICE2~DERIVE' method and trigger the code.

         Perform the below steps for execution : Go to MDGIMG ( t-code ) -> General settings -> Data Quality and Search ->BADI -> Define Validations and Derivations ( execute ). Create enhancement.

 

                                  Enhancement Spot  :   'ZENH_MDG_FI_CCTR'.

                                  BADI Name                :   'ZBI_MDG_FI_CCTR'.

                                  Method Name           :   'IF_EX_USMD_RULE_SERVICE~DERIVE_ENTITY'.  

                                  Filter Values               :   'Entity Type' and 'Data Model'.

Logic for Derivation Rule :

PARAMETERS :  

page 1.png

 

method IF_EX_USMD_RULE_SERVICE~DERIVE_ENTITY.
                   
TYPES : BEGIN OF ty_cctr,
              zcctr TYPE cctr,
            END OF ty_cctr.

    DATA : lr_request      TYPE REF TO if_usmd_crequest_api,
           lv_cr_number    TYPE usmd_crequest,
           lv_crequest     TYPE usmd_s_crequest,
           it_crequest     TYPE STANDARD TABLE OF usmd_s_crequest,
           usmd_creq_type  TYPE usmd_creq_type,
           usmd_created_by TYPE xubanme.

    DATA : lv_physical_name TYPE mdg_gn_physical_name,
           lv_busarea       TYPE gser,
           lv-ccode         TYPE bukrs,
           lc_cctr          TYPE name-komp VALUE 'CCTR',
           lv_range         TYPE kostl,
           lv_cctr          TYPE kostl,
           lv_ccblash       TYPE zde-ccblash,

           result           TYPE string,
           count            TYPE i,
           cnt              TYPE i VALUE 0,
           lv_alp           TYPE string,
           lv_num           TYPE string,
           lv_ccrange       TYPE n LENGTH 4,
           lv_len           TYPE i,
           lv_bsrange       TYPE n LENGTH 10,

           it_cctr          TYPE TABLE OF ty_cctr,
           lv_op            TYPE string VALUE '%',
           lv_sctr          TYPE kost1,
           lv_number        TYPE string.

    CONSTANTS : lc_logical_cctr TYPE mdg_gn_logical_name VALUE 'TCK_0G_CCTR'.

*Getting WF step.
    TRY.
        DATA(lo_context) = cl_usmd_app_context=>get_context().
      CATCH cx_usmd_app_context_cons_error INTO DATA(lo_exception).
    ENDTRY.

    IF lo_cotext IS BOUND.
      lo_context->get_attributes( IMPORTING ev_crequest_type = DATA(lv_range)
                                            ev_crequest_step = DATA(lv_wf_step) ).
    ENDIF.

*Deriving Cost Centre Value.
    SELECT SINGLE cskio_range FROM t9k_csk_io_range
          INTO _range WHERE gsber = _busarea AND bukrs = _ccode.

    IF sy-subrc = 0.
      CONCATENATE lv_range lv_op INTO lv_str.

      SELECT SINGLE physical_name FROM mdg_gn_tgobj
               INTO lv_physical_name WHERE logical_name EQ lc_logical_name
                     AND new_version = ''.

      IF sy-subrc = 0.
        SELECT /1md/0gcctr FROM (lv_physical_name) INTO TABLE it_cctr
                 WHERE /1md/0gcctr LIKE lv_sctr.
        IF sy-subrc = 0.
          SORT it_cctr STABLE BY zcctr DESCENDING.
          READ TABLE it_cctr INTO DATA(wa_cctr) INDEX 1.

*Formating the Cost Center Value.

          count = strlen(wa_cctr).
          DO count TIMES.
            result = wa_cctr + cnt(1).

            IF result CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
              CONCATENATE lv_alp result INTO lv_alp.
              CLEAR result.
            ELSE.
              CONCATENATE lv-num result INTO lv_num.
              CLEAR result.
            ENDIF.
            cnt = cnt+1.
          ENDDO.
          lv_num = lv_num + 1.
          CLEAR lv_cctr.
          CONCATENATE lv_alp lv_num INTO lv_cctr.

          lv_len = strlen(lv_cctr).
          IF lv_len < 6.
            lv_ccrange = lv_num.
            CLEAR lv_cctr.

            CONCATENATE lv_alp lv_ccrange INTO lv_cctr.
          ENDIF.

        ELSE.
          CONCATENATE lv_range '0000'INTO lv_range.
          CLEAR lv-cctr.
          lv_cctr = lv_range.
          SHIFT lv_range RIGHT DELETING TRAILING space.
          OVERLAY lv_range WITH '0000'.
          lv_cctr = lv_range.
        ENDIF.
      ENDIF.
    ELSE.
      lv_num = lv_number+7(3).
      CONCATENATE 'TMP' lv_num INTO lv_sctr.
      lv_cctr = lv_sctr.
      gv_sctr = lv_sctr.
    ENDIF.
    CONCATENATE 'TMP_001'  ' ' INTO lv_cctr.
  ENDIF.
ENDIF.
endmethod.

 

CHECKING THE VALUE ON NWBC SCREEN:

MicrosoftTeams-image (6).png

                             Fig 1 : NWBC Screen

CONCLUSION :

                         We can accomplish the Complex Business Requirement by dynamically coding it in the BADI.

           These kind of rules can't be attained through BRF+ which involves some custom tables , joining those tables   getting the data, seggregating the data and formatting the data.  Likewise , we can perform validations by using check entity method in Validations and Derivations BADI.

          Your Ideas and feedback about my blog are highly important . Please feel free to post your comments under comment section in my blog.

                     Also do check out for the other posts which are related to MDG .

https://blogs.sap.com/2016/09/13/mdg-80-in-real-life-blog-series-how-to-configure-and-customize-rule...

https://blogs.sap.com/2013/08/20/cross-entity-derivations-using-badi-usmdruleservicecrosset/

https://blogs.sap.com/2012/10/02/mdg-configuration-of-the-screens-based-on-user-role/

https://blogs.sap.com/2021/04/21/use-custom-filter-object-drff-in-the-s-4-hana-bp-outbound-replicati...

Thanks!

                              

 

5 Comments
Former Member

Nice post!!

Please also consider the option "DQM Derivation Scenarios" (also using BRF+). With that option you might be able to implement such requirements without ABAP Coding and you ensure that its can also be used in MDG CMP processes. Please read this document Set Up Central Governance to Use Data Quality Management Derivation Scenarios (sap.com)

Steffen

AbdulM
Explorer

Hello

I had a doubt on the example which you have used for the Blog. Cost Center bring a Type 1 Entity, is it something really possible to use cross entity to derive the entity itself. How will the system understand that the key update is being requested and not treat the new row as a different record.

Also how are you handling the Change Request Object list which will have a different key than the one being written.

Thanks

AKHILARAPARTHI
Explorer

Hello Abdul,

            Yes, Cost Center belongs to Type 1 entity and Cost Center acts as leading entity which we can consider as one of the field of Cost Center entity. Now I am deriving the value for CC based on Company Code and Business Area which also belongs to the same Cost Center entity. You can check Fig 1 of NWBC Screen which I shared in the post. 

And the answer to your next question is we are deriving the value of Cost Center for create process its not for update. If we are trying to create the value of Cost Center which is already there . The system will through you an error message saying " Cost Center is already present , please create the new one." which I have coded  through validations BADI. However, Cost Center we treat it like Primary key, we can update the other fields of Cost Center entity based on Cost Center value. You can check the rule thoroughly to understand the logic.

Applying the rule for particular Change Request can be handled by API's . You can refer to line number 45 in the logic.

Thanks,

Akhila

AKHILARAPARTHI
Explorer

Hi Steffen ,

              Thanks for sharing the document . The content is easier and can be done fastly compared to writing the complex logic. Definitely will implement this strategy when there is a requirement.

Thanks ,

Akhila

marcela_martinez
Participant
0 Kudos

Hello Akhila!

Thanks for the post, very useful.

I have a scenario which after reading your post I am not so sure it could be done. I need to replicate Cost Center description in Spanish. Users enters a description in English and automatically it should be copied with exactly the same text but in Spanish language. Do you think I can create a custom derivation for this needed?

Thanks in advance and regards.