Skip to Content

FSCM – Adding Custom Fields to Formula Editor

This blog explains how to add the custom attributes/fields to Formula Editor from the additional custom tabs of BP General Data and BP Credit Segment Data created through Business Data Toolset (BDT) for new credit scoring formulas.

BP Transaction: UKM_BP

Ways to add custom attributes / fields to Formula Editor: (SAP Provided Documentation)

With BAdI: Formula Parameters and Functions (UKM_EV_FORMULA), we can enhance the field and function selection of the formula editor.

You can either integrate your own fields that you have defined with BAdI: Additional Attributes for Business Partner (UKM_BP_ADD_FIELDS), or integrate fields from the following business partner structures:

  • UKM_S_BP_CMS
  • BP1010
  • BAPIBUS1006_ADDRESS
  • BAPIBUS1006_CENTRAL
  • BAPIBUS1006_CENTRAL_GROUP
  • BAPIBUS1006_CENTRAL_ORGAN
  • BAPIBUS1006_CENTRAL_PERSON

  BAdI methods:

  • ADD_FIELDS
  • FILL_FIELD

SAP Reference IMG for BAdI “UKM_EV_FORMULA”:

Financial Supply Chain Management -> Credit Management -> Credit Risk Monitoring -> Enhancements -> BAdI: Formula Parameters and Functions

But this post will explain how to add custom fields to Formula Editor instead of fields from above mentioned BP structures.

Define Formulas:

SAP Reference IMG to Define Formulas:

Financial Supply Chain Management -> Credit Management -> Credit Risk Monitoring -> Define Formulas

After defining new Formula (ex: ZSCORE), click on button “Formula Editor” to define the required formulas for custom fields.

Sample Code Snippet to add fields to Formula Editor:

Implement the BADI “UKM_EV_FORMULA” with below code in the method “ADD_FIELDS”.

METHOD if_ex_ukm_ev_formula~add_fields.

  CONSTANTS: lc_empty  TYPE sfbefsym VALUE ,
             lc_bp_gen
TYPE sfbefsym VALUE ‘ZTABLE’.
 
DATA: wa_operands TYPE sfbeoprnd.

  CASE i_key.
   
WHEN lc_empty.
     
CLEAR wa_operands.
      wa_operands
tech_name = ‘ZTABLE’. “Custom table
      wa_operands
descriptn = ‘Table Description’.
     
APPEND wa_operands TO ct_operands.
   
WHEN lc_bp_gen.
     
CLEAR wa_operands.
      wa_operands
tech_name = ‘ZTABLE-ZFIELD1’. “Custom Table Field
      wa_operands
descriptn = ‘Z-Field1 Description’.
      wa_operands
type = ‘CHAR20’.
     
APPEND wa_operands TO ct_operands.

      CLEAR wa_operands.
      wa_operands
tech_name = ‘ZTABLE-ZFIELD2’. “Custom Table Field
      wa_operands
descriptn = ‘Z-Field2 Description’.
      wa_operands
type = ‘INT4’.
     
APPEND wa_operands TO ct_operands.
   
WHEN OTHERS.
 
ENDCASE.

ENDMETHOD.

Sample Code Snippet to populate fields for Formula Calculations:

Implement the BADI “UKM_EV_FORMULA” with below code in the method “FILL_FIELD”.

METHOD if_ex_ukm_ev_formula~fill_field.

  DATA: ls_but000 TYPE but000.
 
DATA: lv_field1 TYPE ZTABLE-FIELD1,
        lv_field2
TYPE ZTABLE-FIELD2.
 
DATA: dref1 TYPE REF TO data,
        dref2
TYPE REF TO data.

  FIELD-SYMBOLS: <fs_field1> TYPE any,
                 <fs_field2>
TYPE any.

  CLEAR ls_but000.

* read partner from BP screen
 
CALL FUNCTION ‘BUP_BUPA_BUT000_GET’
   
IMPORTING
      e_but000
= ls_but000.

CASE i_fieldname.
   
WHEN ‘ZTABLE-FIELD1’.
     
CREATE DATA dref1 TYPE ZTABLE-FIELD1.

      ASSIGN dref1->* TO <fs_field1>.


     
SELECT SINGLE FIELD1
             
INTO lv_field1
            
FROM ZTABLE
       
WHERE partner = ls_but000partner.
     
IF sysubrc = 0.

        <fs_field1> = lv_field1.


       
GET REFERENCE OF <fs_field1> INTO rd_result.

      ENDIF.
   

     WHEN ‘ZTABLE-FIELD2’.
     
CREATE DATA dref2 TYPE ZTABLE-FIELD2.

      ASSIGN dref2->* TO <fs_field2>.

      SELECT SINGLE FIELD2

              INTO lv_field2
            
FROM ZTABLE
       
WHERE partner = ls_but000partner.

      IF sysubrc = 0.
        <fs_field2>
= lv_field2.
       
GET REFERENCE OF <fs_field2> INTO rd_result.

      ENDIF.
   

     WHEN OTHERS.

  ENDCASE.

ENDMETHOD.

Results:

Custom fields have been added to Formula Editor and required Formulas.

Transaction UKM_BP -> Select BP -> Select BP Role “SAP Credit Management” -> Go to “Credit Profile” tab -> Select the Rule -> Click on button “Calc. with Formula”.

Score will be calculated based on the field values populated from respective DB tables. We can toggle to Rule Evaluation to see the detailed scoring criteria.

Thanks

Gangadhar

9 Comments
You must be Logged on to comment or reply to a post.
  • Hi,

        Thanks for this explanation. Very helpful. I was wondering how do we add a custom function to the formula editor. I could not figure that out. Please suggest.

    Thanks in advance.

    Regards,

    – Nakul.

  • Hi Gangadharthank you sharing!
    Just to confirm – using your approach, the custom fields will be available for selection in the Formula Editor – and also, the system will populate the values of our custom fields every time the formula is executed ?

  • Hi Gangadhar,

     

    It was very helpful and it also worked when I am calculating from BP screen. But when I am  trying to achieve the same using Tcode: UKM_MASS_UPD2, I am not getting any values from FM ‘BUP_BUPA_BUT000_GET’. Without Business partner, I can’t do anything.

    Thanks in advance,

    Namrakant

     

  • Same problem here, in eventing in background, when a new sales order is created, there is no BP available, so alle calculated formuls are zero.

    The FB BUP_BUPA_BUT000_GET only works in some environments, like ukm_bp.

    Is there a solution somehow? It seems, that no documentation from SAP ist around in this issue. An example how to implement customer fields would be helpful.

    Once again:

    formulas are calculated by Trs. ukm_bp, va01, scase or ukm_mass_updx.
    We are not able to get BP or Credit Segment Values in all cases.

    Markus

    • Hi Markus,

      For UKM_MASS_UPD2, we got the partner from call stack in the BAdi implementation.

      FM –  UKM_MASSDATA_PROCESSING_UPD, global data LS_PARTNER-PARTNER. (Don’t go by the name, LS is a global variable here!). See if this works for you in case you have not done so already.

      Niraj

  • There is a difference between adding FIELDS or adding FUNCTIONS (which nobody unterstood by the SAP-Docu at first time)

    Fields are just Container for calculated or somehwere saved and read functions (like FIRSTNAME)
    Functions are executed with import parameters (mostly PARTNER, but some other parameters too and Return a value)

    If you would like to add a function, you have to use the BADI for IF_EX_UKM_EV_FORMULA in a different way, because there are two ways to add things.

     

    In our case the class ZCL_IM__UKM_EV_FORMULA

    Methode: IF_EX_UKM_EV_FORMULA~ADD_FIELDS

    METHOD if_ex_ukm_ev_formula~add_fields.

       DATAls_operands TYPE sfbeoprnd.
    CONSTANTSlc_empty TYPE sfbefsym VALUE space.

    CASE i_key.

    *Add Value (left side in ukm_formulas)
    CLEAR ls_operands.
    ls_operandstech_name ‘SFSGP’.
    ls_operandsdescriptn textsfs.
    ls_operandsicon ‘@7D@’.
    ls_operandstype .
    APPEND ls_operands TO ct_operands.

     

    *Add function (right side in ukm_formulas)
    WHEN ‘FUNCS’.
    CLEAR ls_operands.
    ls_operandstech_name ‘TEST’.
    ls_operandsclass ‘ZCL_IM__UKM_EV_FORMULA’.
            ls_operandsmethod ‘TEST’.
    APPEND ls_operands TO ct_operands.

    ENDCASE.

    this will create a FUNCTION named Test

    This can be used like this in formula editor (as example: Substitution TEST (PARTNER)

     

    yours, Markus