Supply Chain Management Blogs by SAP
Expand your SAP SCM knowledge and stay informed about supply chain management technology and solutions with blog posts by SAP. Follow and stay connected.
cancel
Showing results for 
Search instead for 
Did you mean: 
robinthakral
Advisor
Advisor
0 Kudos

INTRODUCTION:

We have been given a requirement where we must add a set of custom fields that would be calculated only to BP – Manage Credit Account (App ID F4596) – Credit Management.

Challenge: The current system is an S4 HANA system version 2021, where CFL (Custom Fields and Logic) has been introduced but is not available for the required App, but for higher versions, CFL can be directly used.

Solution: This app is a RAP OData Service-based application, so enhancing the consumption view will directly enable the view of the fields, that are not required to be stored in a database i.e., Virtual fields.

In this blog post, we will cover the

  • Extending the consumption view C_CreditMgmtAccountTP
  • Implementation of Virtual Element calculation class with interface IF_SADL_EXIT_CALC_ELEMENT_READ

to handle the requirement.


MAIN CONTENT
:

  1. From the Fiori Application, Fetch the service name with Network properties (F12)

robinthakral_4-1707568007001.png

2. Fetch the required consumption details as from Service Binding  and Definition.

robinthakral_5-1707568007005.png

robinthakral_6-1707568007009.png

3. Now, extend the view with respective template.

robinthakral_7-1707568007016.png

Here, add the required set of custom fields. Declaring them as VIRTUAL fields and handling the calculated with annotation

@ObjectModel.virtualElementCalculatedBy: ‘ABAP:<ZCLASS_NAME>’

Here, I have declared the DDIC data element, but you can use direct abap data type reference as well.

Can remove currency semantics, if don’t want to show it on the front end.

4. Then, Proceed to the global custom class declaration either in ADT or GUI (SE24).

 

************************************************************************
*                Class Declarations
************************************************************************

class ZFSCMCL_UKM_ACCOUNT_VE definition
  public
  create public .

public section.

  interfaces IF_SADL_EXIT .
  interfaces IF_SADL_EXIT_CALC_ELEMENT_READ .

  types:
    begin of GTY_BP_SGMNT,
           partner type bu_partner,
           credit_segment type UKM_CREDIT_SGMNT,
           seq            type syst_tabix,
         end   of gty_bp_sgmnt .
  types:
    gtt_bp_segment type STANDARD TABLE OF gty_bp_sgmnt with DEFAULT KEY .

protected section.
 methods CALC_CUSTOM_FIELDS
    importing
      !IT_ORIGINAL_DATA type STANDARD TABLE
      !IT_REQUESTED_CALC_ELEMENTS type IF_SADL_EXIT_CALC_ELEMENT_READ=>TT_ELEMENTS
    changing
      !CT_CALCULATED_DATA type STANDARD TABLE .
 methods CALC_AVG_MON_SALE_CL_RATIO
    importing
      !IV_PARTNER type BU_PARTNER
      !IV_SEGMENT type UKM_CREDIT_SGMNT
      !IV_ROW_NO type SY-TABIX
    changing
      !CT_CALCULATED_DATA type STANDARD TABLE .

ENDCLASS.

CLASS ZFSCMCL_UKM_ACCOUNT_VE IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZFSCMCL_UKM_ACCOUNT_VE->IF_SADL_EXIT_CALC_ELEMENT_READ~CALCULATE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_ORIGINAL_DATA               TYPE        STANDARD TABLE
* | [--->] IT_REQUESTED_CALC_ELEMENTS     TYPE        TT_ELEMENTS
* | [<-->] CT_CALCULATED_DATA             TYPE        STANDARD TABLE
* | [!CX!] CX_SADL_EXIT
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_sadl_exit_calc_element_read~calculate.

  CHECK it_original_data IS NOT INITIAL.
  CHECK it_requested_calc_elements IS NOT INITIAL.

  calc_custom_fields(
    EXPORTING
      it_original_data           = it_original_data
      it_requested_calc_elements = it_requested_calc_elements
    CHANGING
      ct_calculated_data         = ct_calculated_data ).

ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZFSCMCL_UKM_ACCOUNT_VE->IF_SADL_EXIT_CALC_ELEMENT_READ~GET_CALCULATION_INFO
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_REQUESTED_CALC_ELEMENTS     TYPE        TT_ELEMENTS
* | [--->] IV_ENTITY                      TYPE        STRING
* | [<---] ET_REQUESTED_ORIG_ELEMENTS     TYPE        TT_ELEMENTS
* | [!CX!] CX_SADL_EXIT
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_sadl_exit_calc_element_read~get_calculation_info.
* Provide calculation basis attributes
“ Declare constant attributes in utility class with fieldname declared in CDS view
“GC_FLD_AVG_MON_SALE_CL_RATIO Constant Type STRING	Average monthly sales/ CL ratio	‘AVGMONSALECLRATIO'
  CLEAR et_requested_orig_elements.

  IF IF line_exists( it_requested_calc_elements[ table_line = zfscmif_ukm_md_attr_c=>gc_fld_dynamic_payment_trend ] )
    OR line_exists( it_requested_calc_elements[ table_line = zfscmif_ukm_md_attr_c=>gc_fld_avg_mon_sale_cl_ratio ] )
    OR line_exists( it_requested_calc_elements[ table_line = zfscmif_ukm_md_attr_c=>gc_fld_age_prcnt_bl_15_dpd ] ) .
    INSERT if_ukm_md_attr_c=>gc_fld_business_partner      INTO TABLE et_requested_orig_elements.
 ENDIF.
ENDMETHOD.

* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Protected Method ZFSCMCL_UKM_ACCOUNT_VE->CALC_CUSTOM_FIELDS
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_ORIGINAL_DATA               TYPE        STANDARD TABLE
* | [--->] IT_REQUESTED_CALC_ELEMENTS     TYPE        IF_SADL_EXIT_CALC_ELEMENT_READ=>TT_ELEMENTS
* | [<-->] CT_CALCULATED_DATA             TYPE        STANDARD TABLE
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD calc_custom_fields.

    FIELD-SYMBOLS:
      <lv_calculated_value> TYPE any,
      <lv_partner>          TYPE bu_partner,
      <lv_exposure>         TYPE ukm_static_exposure_amt_main,
      <lv_segment>          TYPE ukm_credit_sgmnt,
      <lv_credit_limit>     TYPE ukm_credit_limit,
      <lv_avail_cred_limit> TYPE any.
    DATA: lt_bp_sgmnt           TYPE gtt_bp_segment.

    LOOP AT it_original_data
      ASSIGNING FIELD-SYMBOL(<ls_acct>).
      DATA(lv_account_tabix) = sy-tabix.

      ASSIGN COMPONENT if_ukm_md_attr_c=>gc_fld_business_partner      OF STRUCTURE <ls_acct> TO <lv_partner>.
      ASSIGN COMPONENT if_ukm_md_attr_c=>gc_fld_credit_segment        OF STRUCTURE <ls_acct> TO <lv_segment>.
    IF line_exists( it_requested_calc_elements[ table_line = zfscmif_ukm_md_attr_c=>gc_fld_avg_mon_sale_cl_ratio ] ).
        calc_avg_mon_sale_cl_ratio(
          EXPORTING
            iv_partner         = <lv_partner>
            iv_segment         = <lv_segment>
            iv_row_no          = lv_account_tabix
          CHANGING
            ct_calculated_data = ct_calculated_data ).
      ENDIF.
   ENDLOOP.
ENDMETHOD.

* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Protected Method ZFSCMCL_UKM_ACCOUNT_VE->CALC_AVG_MON_SALE_CL_RATIO
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_PARTNER                     TYPE        BU_PARTNER
* | [--->] IV_SEGMENT                     TYPE        UKM_CREDIT_SGMNT
* | [--->] IV_ROW_NO                      TYPE        SY-TABIX
* | [<-->] CT_CALCULATED_DATA             TYPE        STANDARD TABLE
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD calc_avg_mon_sale_cl_ratio.

    DATA(lr_custom_kpi) = zfscmcl_ukm_account_custom_kpi=>get_instance( iv_partner      = iv_partner                 " Business Partner Number
                                                                        iv_credit_sgmnt = iv_segment ).

    DATA(lv_avg_mon_sale_cl_ratio) = lr_custom_kpi->get_avg_mon_sale_cl_ratio( ).


    IF lv_avg_mon_sale_cl_ratio IS NOT INITIAL.

      ASSIGN COMPONENT zfscmif_ukm_md_attr_c=>gc_fld_avg_mon_sale_cl_ratio
        OF STRUCTURE ct_calculated_data[ iv_row_no ]
        TO FIELD-SYMBOL(<lv_calculated_value>).

      IF <lv_calculated_value> IS ASSIGNED.

        <lv_calculated_value> = lv_avg_mon_sale_cl_ratio.

      ENDIF.

    ENDIF.
ENDMETHOD.
ENDCLASS.

 

5. Declare implementation of class methods for instance processing, so it can be re-usable for other background processing.

 

*********************************************************************
*                Field Processing - Class Declarations
*********************************************************************
class ZFSCMCL_UKM_ACCOUNT_CUSTOM_KPI definition
  public
  create private .

public section.

  types:
    BEGIN OF gty_customer,
        partner  TYPE  bu_partner,
        customer TYPE kunnr,
      END OF gty_customer .
  types:
    gtt_customer TYPE STANDARD TABLE OF gty_customer with DEFAULT KEY .

  class-methods GET_INSTANCE
    importing
      !IV_PARTNER type BU_PARTNER optional
      !IV_CREDIT_SGMNT type UKM_CREDIT_SGMNT optional
    returning
      value(RV_REF) type ref to ZFSCMCL_UKM_ACCOUNT_CUSTOM_KPI .

methods GET_AVG_MON_SALE_CL_RATIO
    returning
      value(RV_AVG_MON_SALE_CL_RATIO) type ZDE_AVG_SL_CL_RT .
  class-data MV_PARTNER type BU_PARTNER .
  class-data MV_CREDIT_SGMNT type UKM_CREDIT_SGMNT .
  class-data MV_REF type ref to ZFSCMCL_UKM_ACCOUNT_CUSTOM_KPI .
ENDCLASS.
CLASS ZFSCMCL_UKM_ACCOUNT_CUSTOM_KPI IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZFSCMCL_UKM_ACCOUNT_CUSTOM_KPI=>GET_INSTANCE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_PARTNER                     TYPE        BU_PARTNER(optional)
* | [--->] IV_CREDIT_SGMNT                TYPE        UKM_CREDIT_SGMNT(optional)
* | [<-()] RV_REF                         TYPE REF TO ZFSCMCL_UKM_ACCOUNT_CUSTOM_KPI
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD get_instance.

    IF iv_partner      <> mv_partner
    OR iv_credit_sgmnt <> mv_credit_sgmnt.

      mv_partner      = iv_partner.
      mv_credit_sgmnt = iv_credit_sgmnt.

      CREATE OBJECT mv_ref.

    ENDIF.

    IF mv_ref IS NOT BOUND.

      CREATE OBJECT mv_ref.

      mv_partner      = iv_partner.
      mv_credit_sgmnt = iv_credit_sgmnt.

    ENDIF.

    rv_ref = mv_ref.

  ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZFSCMCL_UKM_ACCOUNT_CUSTOM_KPI->GET_AVG_MON_SALE_CL_RATIO
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RV_AVG_MON_SALE_CL_RATIO       TYPE        ZDE_AVG_SL_CL_RT
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD get_avg_mon_sale_cl_ratio.
   rv_avg_mon_sale_cl_ratio = “ Calculation logic
  ENDMETHOD.
ENDCLASS.

 

 

OUTPUT:

robinthakral_8-1707568007020.png

On the Front-end, you can do Annotations in extensions, ADAPT UI to add custom fields, or the front-end developer can create an Adaption Project and add the fields.

 

Reference links:
Custom Field: Credit Management - Business Partner Master Data - Account

Do give your comments and feedback.
Follow for more: Robin Thakral