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_but000-partner.
IF sy-subrc = 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_but000-partner.
IF sy-subrc = 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