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

INTRODUCTION:


T-Code FD32 is deprecated in the S/4 HANA system, but there are many BDCs written in old client systems. Now, UKMBP_CMS is the table that needs to be updated.

Challenge: There is only one standard FM that does it UKM_DB_UKMBP_CMS_EXECUTE but this FM is doing direct updates into the table without any error handling as well as writing DML on the table and is not released for customer.

In this blog post, we will cover the class-methods:

  • CL_UKM_BUPA_FACTORY          ( Partner )

  • CL_UKM_BUSINESS_PARTNER ( Partner Credit Profile )

  • CL_UKM_ACCOUNT                     ( Partner Credit Segment )


to handle the requirement.

MAIN CONTENT:



  1. Declare a final local class for data & method.
    ************************************************************************
    * Class Declarations
    ************************************************************************
    CLASS lcl_fi_ukm000_update DEFINITION FINAL.
    ** INTERFACES
    PUBLIC SECTION.
    Constants: lc_error TYPE c VALUE 'E',
    lc_success TYPE c VALUE 'S'.

    **data:
    DATA:lo_facade TYPE REF TO cl_ukm_facade,
    lo_partner TYPE REF TO cl_ukm_business_partner,
    lo_bupa_factory TYPE REF TO cl_ukm_bupa_factory,

    lt_tpz22 TYPE SORTED TABLE OF tpz22 WITH NON-UNIQUE KEY ranking,
    lt_final TYPE STANDARD TABLE OF ty_s_final, “ Final table structure
    lt_bapiret TYPE SORTED TABLE OF bapiret2 WITH NON-UNIQUE KEY type number,
    lt_bapiret2 TYPE bapiret2_t,
    lt_bapiret_record TYPE SORTED TABLE OF bapiret2 WITH NON-UNIQUE KEY type number,
    lt_bapiret_total TYPE bapiret2_t.

    METHODS:
    maintain_bp_credit_details,
    update_credit_profile_segment,
    update_external_credit_info,
    update_additional_adj_info,
    update_identification.
    ENDCLASS.


  2. Update the Final table and then at End-of-selection call the main method MAINTAIN_BP_CREDIT_DETAILS.

  3. Declare implementation of class-methods,
    CLASS lcl_fi_ukm000_update IMPLEMENTATION.

    *&---------------------------------------------------------------------*
    *& Maintain BP - SAP CREDIT MANAGEMENT Details
    *&---------------------------------------------------------------------*
    METHOD maintain_bp_credit_details.
    DATA: lt_output TYPE SORTED TABLE OF ty_s_final WITH NON-UNIQUE KEY primary_key COMPONENTS kunnr
    WITH NON-UNIQUE SORTED KEY type_key COMPONENTS type ,
    ls_bupa_error TYPE mds_ctrls_error.

    CLEAR: lt_bapiret_record[], lt_bapiret_total[], lt_output[].
    lt_output[] = lt_final[].

    "*********here customer is BP only, make sure to ALPHA = IN if needed earlier**************
    LOOP AT lt_output[] INTO ls_final USING KEY type_key WHERE type IS INITIAL.
    CLEAR: ls_bupa_error, ls_bupa_error-messages[].
    "____________________ Lock BP___________________
    DATA(lo_bupa) = NEW cl_im_mds_bupa_lock( ).
    lo_bupa->if_ex_bupa_lock~lock(
    EXPORTING
    iv_partner = ls_final-kunnr
    CHANGING
    cs_error = ls_bupa_error ).

    IF ls_bupa_error-is_error IS INITIAL.
    " Process Updating the Data
    "__________________________"
    update_credit_profile_segment( ).
    update_external_credit_info( ).
    update_additional_adj_info( ).
    update_identification( ).

    IF line_exists( lt_bapiret_record[ type = lc_error ] ).
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    " Remove manually added success messages.
    DELETE lt_bapiret_record[] WHERE parameter = ls_final-kunnr AND type = lc_success.
    ELSE.
    lo_bupa_factory->save_all( i_upd_task = abap_false ). "For Factory methods

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' "For API Methods
    EXPORTING
    wait = abap_true.
    ENDIF.
    "____________________Unlock BP____________________
    lo_bupa->if_ex_bupa_lock~unlock(
    EXPORTING
    iv_partner = ls_final-kunnr
    CHANGING
    cs_error = ls_bupa_error ).
    ELSE.
    lt_bapiret_record[] = VALUE #( FOR ls_bapiret IN ls_bupa_error-messages
    ( parameter = |{ ls_final-kunnr }|
    type = ls_bapiret-type
    message = ls_bapiret-message
    )
    ) .
    ENDIF.
    APPEND LINES OF lt_bapiret_record[] TO lt_bapiret_total[].
    CLEAR: lt_bapiret_record[].
    ENDLOOP.
    display_data( ). " Display Final ALV table
    ENDMETHOD.

    *&---------------------------------------------------------------------*
    *& Update Credit Profile within Role UKM000 - SAP CREDIT MANAGEMENT
    *& Update Credit Segment at Header Level
    *&---------------------------------------------------------------------*
    METHOD update_credit_profile_segment.
    DATA: lo_account TYPE REF TO cl_ukm_account,
    ls_bp_credit_sgm TYPE ukm_s_bp_cms_sgm,
    ls_ukm_s_bp_cms TYPE ukm_s_bp_cms.
    CONSTANTS: lc_std TYPE ukm_limit_rule VALUE 'STANDARD'.

    "set & fetch Parent data
    lo_facade = cl_ukm_facade=>create( i_activity = cl_ukm_cnst_eventing=>bp_maintenance ).
    lo_bupa_factory = lo_facade->get_bupa_factory( ).
    lo_partner = lo_bupa_factory->get_business_partner( ls_final-kunnr ).

    " Fetch & update credit profile data
    lo_partner->get_bp_cms(
    IMPORTING
    es_bp_cms = ls_ukm_s_bp_cms
    ).
    ls_ukm_s_bp_cms-limit_rule = lc_std.
    ls_ukm_s_bp_cms-risk_class = ls_final-cre_risk.
    ls_ukm_s_bp_cms-own_rating = ls_final-db_paydex_score. " Credit score.
    ls_ukm_s_bp_cms-rating_chg_date = sy-datum.
    ls_ukm_s_bp_cms-rating_val_date = sy-datum + 1. " plus 1 days
    lo_partner->set_bp_cms(
    EXPORTING
    is_bp_cms = ls_ukm_s_bp_cms
    ).

    "Fetch & update credit segment data
    lo_account = lo_bupa_factory->get_credit_account(
    i_partner = ls_final-kunnr
    i_credit_sgmnt = CONV ukm_credit_sgmnt( ls_final-kkber ) ).

    lo_account->get_bp_cms_sgm(
    IMPORTING
    es_bp_cms_sgm = ls_bp_credit_sgm ).

    ls_bp_credit_sgm-x_limit_zero = abap_false.
    ls_bp_credit_sgm-credit_limit = ls_final-cred_lim.
    ls_bp_credit_sgm-limit_chg_date = sy-datum.
    ls_bp_credit_sgm-req_date = ls_final-ref_date.

    lo_account->set_bp_cms_sgm(
    EXPORTING
    is_bp_cms_sgm = ls_bp_credit_sgm
    ).

    APPEND VALUE #( parameter = |{ ls_final-kunnr }|
    type = lc_success
    message = |{ ls_final-kunnr } { TEXT-019 }|
    message_v1 = TEXT-019
    ) TO lt_bapiret_record[].
    ENDMETHOD.
    *&---------------------------------------------------------------------*
    *& Update BP External Credit Info - Credit Profile - UKM000 –
    *& this is independent of Partner class instance.
    *&---------------------------------------------------------------------*
    METHOD update_external_credit_info.
    DATA: lt_bp1012 TYPE STANDARD TABLE OF bp1012,
    lt_message TYPE tty_xo_message,
    lv_guid TYPE bu_partner_guid.

    CLEAR: lt_bapiret[], lt_bapiret2[].

    DATA(lv_score) = CONV bp_grade_rank( ls_final-tot_score ).
    SHIFT lv_score LEFT DELETING LEADING space.

    " date range should be beyond date_to & date_from.
    lt_bp1012 = VALUE #( ( grade_method = lc_grade_method_dnb "'DNB'
    grade = VALUE #( lt_tpz22[ ranking = lv_score ]-grade OPTIONAL ) "ls_final-dbrating
    flg_permit = abap_true
    text = ls_final-cust_group
    date_when = sy-datum
    date_from = sy-datum
    date_to = cl_reca_date=>add_to_date( id_years = 1 id_date = sy-datum )
    ) ).

    lt_message[] = fsbp_api_adapter=>execute_mo_specific_add( " will add new record - use change for changing
    i_partner = ls_final-kunnr
    i_partnerguid = lv_guid
    i_table_name = if_fsbp_const_xo_objects=>mo_bp1012
    i_check_authority = abap_false
    i_data_new = lt_bp1012[]
    ).
    IF lt_message[] IS NOT INITIAL.
    lt_bapiret[] = VALUE #( FOR ls_bapiret IN lt_message[]
    ( parameter = |{ ls_final-kunnr }|
    type = ls_bapiret-type
    message = ls_bapiret-message
    )
    ) .
    INSERT LINES OF lt_bapiret[] INTO TABLE lt_bapiret_record[]. " for sorted table - append dont work
    ENDIF.
    IF NOT line_exists( lt_bapiret[ type = lc_error ] ).
    APPEND VALUE #( parameter = |{ ls_final-kunnr }|
    type = lc_success
    message = |{ ls_final-kunnr } { TEXT-020 }|
    message_v1 = TEXT-020
    ) TO lt_bapiret_record[].
    ENDIF.

    ENDMETHOD.
    *&---------------------------------------------------------------------*
    *& Update BP Additional Adjustment - Credit Profile - UKM000
    *& this is independent of Partner class instance.
    *&---------------------------------------------------------------------*
    METHOD update_additional_adj_info.
    DATA: lt_bp3100 TYPE STANDARD TABLE OF bp3100,
    lt_message TYPE tty_xo_message,
    lv_guid TYPE bu_partner_guid..
    CONSTANTS: lc_addtype_50 TYPE bp_addtype VALUE 50,
    lc_data_type_01 TYPE bp_data_type VALUE 01.
    CLEAR: lt_bapiret[], lt_bapiret2[].

    " _____________Have to Add the Required Record _______________
    lt_bp3100[] = VALUE #( ( partner = ls_final-kunnr
    addtype = lc_addtype_50 "50
    data_type = lc_data_type_01 "01
    amnt = CONV bp_amnt( ls_final-dbtrade_ref_amt )
    addate = sy-datum
    datefr = sy-datum
    dateto = sy-datum
    text = ls_final-kraus
    ) ).
    lt_message[] = fsbp_api_adapter=>execute_mo_specific_add(
    i_partner = ls_final-kunnr
    i_partnerguid = lv_guid
    i_table_name = if_fsbp_const_xo_objects=>mo_bp3100
    i_check_authority = abap_false
    i_data_new = lt_bp3100[]
    ).
    IF lt_message[] IS NOT INITIAL.
    lt_bapiret[] = VALUE #( FOR ls_bapiret IN lt_message[]
    ( parameter = |{ ls_final-kunnr }|
    type = ls_bapiret-type
    message = ls_bapiret-message
    )
    ) .
    INSERT LINES OF lt_bapiret[] INTO TABLE lt_bapiret_record[]. " for sorted table - append dont work
    ENDIF.
    IF NOT line_exists( lt_bapiret[ type = lc_error ] ).
    APPEND VALUE #( parameter = |{ ls_final-kunnr }|
    type = lc_success
    message = |{ ls_final-kunnr } { TEXT-021 }|
    message_v1 = TEXT-021
    ) TO lt_bapiret_record[].
    ENDIF.

    ENDMETHOD.
    *&---------------------------------------------------------------------*
    *& Update BP Identification - Credit Profile - UKM000 or General
    *& This information is Generic irrespective of ROLE in BP
    *&---------------------------------------------------------------------*
    METHOD update_identification.
    "IDENTIFICATION
    DATA: lt_bapiret2 TYPE bapiret2_t,
    ls_id_upd TYPE bapibus1006_identification.
    CONSTANTS: lc_idcat_bup001 TYPE bu_id_category VALUE 'BUP001'.

    CLEAR: lt_bapiret[], lt_bapiret2[].

    ls_id_upd = VALUE #( idinstitute = ls_final-cust_group
    identrydate = sy-datum
    idvalidfromdate = sy-datum
    idvalidtodate = cl_reca_date=>add_to_date( id_years = 1 id_date = sy-datum )
    ).
    lo_partner->save_but0id(
    EXPORTING
    i_id_type = lc_idcat_bup001
    i_id_number = CONV bu_id_number( ls_final-kraus )
    i_identification = ls_id_upd
    IMPORTING
    et_return = lt_bapiret2 )
    .
    IF lt_bapiret2[] IS NOT INITIAL.
    lt_bapiret[] = VALUE #( FOR ls_bapiret IN lt_bapiret2[]
    ( parameter = |{ ls_final-kunnr }|
    type = ls_bapiret-type
    message = ls_bapiret-message
    )
    ) .
    INSERT LINES OF lt_bapiret[] INTO TABLE lt_bapiret_record[]. " for sorted table - append dont work
    ENDIF.
    IF NOT line_exists( lt_bapiret[ type = lc_error ] ).
    APPEND VALUE #( parameter = |{ ls_final-kunnr }|
    type = lc_success
    message = |{ ls_final-kunnr } { TEXT-022 }|
    message_v1 = TEXT-022
    ) TO lt_bapiret_record[].
    ENDIF.

    ENDMETHOD.
    ENDCLASS.

    Here DISPLAY_ALV is not declared as you can declare the factory ALV method on your own to display the Final table or LT_BAPIRET_TOTAL. Handle success & error text as per your requirement.

     

    Rest, you can trigger SAVE_ALL( I_UPD_TASK = ABAP_TRUE ) " X to handle the update and Fiori front-end update.

     

     

     

     

     

    Reference links:

    Comparison for SAP S/4HANA Basic Credit Management and Advanced Credit Management




    Topic page:

    ABAP Topic: https://community.sap.com/topics/abap,

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











9 Comments