Skip to Content
Author's profile photo Stefan Foerster

SAP TM: BP type ahead search based on assigned org.unit

Relevance / Motivation

Once again – main motiviation is usability or user efficiency.
When using the type ahead search for Business Partners (BP) end users get too many similar proposed values and the relevant BP cannot be identified or even not found quick enough. One special Forwarder’s example: you have got many customer BPs for the same customer-company in your system – one BP per sales organization. Hence, when start typing the customer name you get the same customer proposed many times and you also need to type the country and/or city, but you (or users) don’t like to do that.
A similar Shipper’s example could be valid for the carrier side too. You might have many carrier BPs for the same carrier-company in your system – one carrier-BP per purchase organization.
Another rather simple reason could be that you have simply hundred thousands of BPs in your system and hence when start typing a name too many BPs come up with similar names.

This blog post explains how you could enhance SAP TM in order to use a special type ahead search help, which e.g. uses the sales org of the FWO to narrow down the number of relevant BPs. As a result the end user gets a more suitable hit list and can work more efficiently – see result section below.

Background

In SAP TM when typing any value into a BP ID field the relevant search help is executed on the fly and up to 10 applicable entries are auto-proposed in a drop down. While you type the search help is executed again and again and hence refines the hit list as you type. This feature is called type ahead search. In TM systems based on HANA DB this is a fuzzy search against all available fields of the search help. In a non HANA DB system the search is against the ID only unless you followed the proposed configuration of the blog post Businesspartner-and-orgunit-search-in-sap-tm-uis/

In case the BPs of concern are all assigned to org units, then the search help results could be further refined as usually the base document (TRQ/TOR) has got an org. unit assigned by default.

This enhancement basically introduces a new separate search help, which can use the org unit as a selection criteria. The BP collective search help is enhanced to insert the new elementary SH and an enhancement is made to force the system to take this SH if needed – dependent on the context. It is just another use case for the already exposed UI context determination.

Details of the enhancement

The following steps are required:

  1. Copy the DB view /SCMTMS/H_BUPAA to your own one and adjust yours
  2. Copy the function /SCMTMS/SH_BUPA_COMMON to your own one and adjust yours
  3. Copy the search help /SCMTMS/BUPAA to your own one and adjust yours
  4. Create an append SH for /SCMTMS/CSH_BUPA (in the GOTO menu option – F5
  5. Enhance the standard function /SCMTMS/CSH_BUPA_COMMON (SH exit of collective SH)
  6. Adjust the code for relevant UI config and/or relevant BP roles
  7. In case you use the “combined search” customzing, add your SH

 

Ad 1) Copy the DB view /SCMTMS/H_BUPAA to your own one and adjust yours

here: ZSTF_SH_BP_ORG

1a) Add the DB table /SCMB/D_BPTMORG and add the join conditions. See screenshot.

1b) Add the view fields org, org_function, eikto. See screenshot.

 

Ad 2) Copy the function /SCMTMS/SH_BUPA_COMMON to your own one and adjust yours

here: ZSTF_SH_BUPA_COMMON

Remove the old code and add your code.

DATA:
  lo_fpm              TYPE REF TO if_fpm,
  lo_fbi              TYPE REF TO /bofu/if_fbi_controller_new,
  ls_fpm_runtime_info TYPE fpm_s_runtime_info,
  lt_sh_selopt        TYPE ddshselops,
  ls_sh_selopt        TYPE ddshselopt,
  lt_shlp_tab         TYPE shlp_desct,
  lt_selopt_rcode     TYPE /scmtms/t_string_range,
  lt_selopt_roles     TYPE /scmtms/t_string_range,
  ls_selopt_rcode     TYPE /scmtms/s_string_range,
  ls_root_key         TYPE /bobf/s_frw_key,
  lt_root_key         TYPE /bobf/t_frw_key,
  lt_trq_data         TYPE /scmtms/t_trq_root_k,
  lv_sales_org_relevant.

FIELD-SYMBOLS:
  <ls_sh_selopt>      TYPE ddshselopt,
  <ls_selopt_roles>   TYPE /scmtms/s_string_range,
  <ls_trq_root_data>  TYPE /scmtms/s_trq_root_k,
  <lt_any_node_data>  TYPE INDEX TABLE,
  <ls_selopt>         TYPE ddshselopt,
  <ls_interface>      TYPE ddshiface.


  CHECK callcontrol-step = 'PRESEL' AND shlp-shlpname = 'ZSTF_BUPAA_ORG'.

*---------------------------------------------------------------------------*
* enable the combined search customizing for a non HANA based search
  lt_shlp_tab[] = shlp_tab[].
  /scmb/cl_tya_sh_helper=>set_type_ahead_search_criteria(
    CHANGING
      ct_shlp_tab    = lt_shlp_tab
      cs_shlp        = shlp
      cs_callcontrol = callcontrol ).
  shlp_tab[] = lt_shlp_tab[].


*---------------------------------------------------------------------------*
* translate the party role codes as in the standard SH exit

  LOOP AT shlp-selopt ASSIGNING <ls_sh_selopt> WHERE shlpfield = 'PARTY_RCO'.

*   recognize here which partner ID shall be used as selection criteria
*   => table /SCMTMS/V_PA_ROL
    CASE <ls_sh_selopt>-low.
      WHEN '1'       " ordering party- OK
        OR 'TM002'   " prepaid agreement party- OK
        OR '6'       " shipper - OK
        OR '10'      " bill-to - OK
        OR 'TM003' . " prepaid bill-to - OK
        lv_sales_org_relevant = abap_true.

      WHEN OTHERS.
*       any other org unit ? - e.g. purchase org for carrier

    ENDCASE.

    MOVE-CORRESPONDING <ls_sh_selopt> TO ls_selopt_rcode.
    INSERT ls_selopt_rcode INTO TABLE lt_selopt_rcode.
    DELETE shlp-selopt.

  ENDLOOP.
  IF sy-subrc NE 0.
*   temporary workaround - fast order entry screens do not set the role code
*   ==> this elementary SH is currently only called if it is sales org relevant
    ls_selopt_rcode-sign = 'I'.
    ls_selopt_rcode-option = 'EQ'.
    ls_selopt_rcode-low = '1'.
    INSERT ls_selopt_rcode INTO TABLE lt_selopt_rcode.
    lv_sales_org_relevant = abap_true.
  ENDIF.

  CALL METHOD /scmtms/cl_bupa_sh_helper=>get_roles_for_party_rco
    EXPORTING
      it_selopt_rcodes = lt_selopt_rcode
    IMPORTING
      et_selopt_roles  = lt_selopt_roles.

  LOOP AT lt_selopt_roles ASSIGNING <ls_selopt_roles>.
    ls_sh_selopt-shlpname  = 'ZSTF_BUPAA_ORG'.
    ls_sh_selopt-shlpfield = 'RLTYP'.
    MOVE-CORRESPONDING <ls_selopt_roles> TO  ls_sh_selopt.
    INSERT ls_sh_selopt INTO TABLE shlp-selopt.
  ENDLOOP.


* assuming this piece of code is only executed from UI and not in batch mode...
  CHECK sy-batch IS INITIAL.
  lo_fpm = cl_fpm_factory=>get_instance( ).
  lo_fbi ?= /bofu/cl_fbi_controller_new=>get_instance( ).
  ls_fpm_runtime_info = lo_fpm->get_runtime_info( ).


* get the current instance
  lt_root_key = lo_fbi->mo_connector->mo_source_entity->get_self_keys(  ).
  READ TABLE lt_root_key INTO ls_root_key INDEX 1.
  CHECK sy-subrc = 0.
* read data of current instance directly from buffer or via retrieve via BOBF transaction manager
  READ TABLE lo_fbi->mt_node_buffer ASSIGNING FIELD-SYMBOL(<ls_node_buffer>)
     WITH KEY  bo_key    = /scmtms/if_trq_c=>sc_bo_key
               node_key  = /scmtms/if_trq_c=>sc_node-root.
  IF sy-subrc EQ 0.
    ASSIGN <ls_node_buffer>-t_data->* TO <lt_any_node_data>.

*   ... depending from which UI the BP search is triggered:
    IF ls_fpm_runtime_info-config_id   = '/SCMTMS/FWD_ORDER_OCEAN' AND "just an example
       lv_sales_org_relevant = abap_true.

*     here we know - it's a TRQ instance (as we know from which UI it is called)
      lt_trq_data = <lt_any_node_data>.
      READ TABLE lt_trq_data ASSIGNING <ls_trq_root_data> WITH KEY key = ls_root_key-key.
      IF sy-subrc EQ 0.

*       add the Sales Org as selection criteria
        IF NOT <ls_trq_root_data>-sales_org_id IS INITIAL.
          INSERT INITIAL LINE INTO TABLE shlp-selopt ASSIGNING <ls_selopt>.
          <ls_selopt>-shlpname  = 'ZSTF_BUPAA_ORG'.
          <ls_selopt>-shlpfield = 'ORG'.
          <ls_selopt>-sign      = 'I'.
          <ls_selopt>-option    = 'EQ'.
          <ls_selopt>-low       = <ls_trq_root_data>-sales_org_id.
        ENDIF.
      ENDIF.

    ENDIF.
  ENDIF.

 

 

Ad 3) Copy the search help /SCMTMS/BUPAA to your own one and adjust yours

here: ZSTF_BUPAA_ORG

3a) Add the org fields – see screenshot

3b) Add your view (step 1) as selection method

3c) Add your function (step 2) as search help exit

3d) Adjust the List-Position (LPos) sequence as required – see my proposal

 

Ad 4) Create an append SH for /SCMTMS/CSH_BUPA (in the GOTO menu option – F5)

here: ZSTF_BUPA_APPEND

4a) Include your copied elementary SH (step 4) -> “ZSTF_BUPAA_ORG”

4b) Maintain the assignment of UI fields – see screenshot

 

Ad 5) Enhance the standard function /SCMTMS/CSH_BUPA_COMMON (SH exit of collective SH)

This is required in order to make sure your elementary SH ist used if required and only then.

You need to do that as pre-exit.

DATA:
  lo_fpm              TYPE REF TO if_fpm,
  ls_fpm_runtime_info TYPE fpm_s_runtime_info,
  lv_sales_org_relevant.

FIELD-SYMBOLS:
  <ls_sh_interface_partner>   TYPE ddshiface,
  <ls_sh_interface>   TYPE ddshiface.

IF sy-uname = 'FOERSTER'.

* for the type ahead search:
*   - out of the available elementary SHs of the collective SH pick the address/Org search if required
  IF cl_web_dynpro=>valuehelpinfo-valuesuggest = abap_true.
    lo_fpm = cl_fpm_factory=>get_instance( ).
    ls_fpm_runtime_info = lo_fpm->get_runtime_info( ).

*   ... depending from which UI the BP search is triggered:
    IF ls_fpm_runtime_info-config_id   = '/SCMTMS/FWD_ORDER_OCEAN'. "just an example

*     recognize already here whether the party role is relevant for the sales org assignment
*     and hence whether at all the special search help shall be used
      READ TABLE shlp-interface ASSIGNING <ls_sh_interface>
        WITH KEY shlpfield = 'PARTY_RCO'.
      IF sy-subrc = 0.
        CASE <ls_sh_interface>-value.
          WHEN '1'      " ordering party- OK
            OR 'TM002'  " prepaid agreement party- OK
            OR '6'      " shipper - OK
            OR '10'     " bill-to - OK
            OR 'TM003'. " prepaid bill-to - OK
            lv_sales_org_relevant = abap_true.

          WHEN OTHERS.
*           no reason to use the sales org assignment
        ENDCASE.
        IF lv_sales_org_relevant = abap_false.
*         in the fast order entry screens, the role code is not set... ? => bug
*         temporary work around:
          READ TABLE shlp-interface ASSIGNING <ls_sh_interface_partner>
            WITH KEY shlpfield = 'PARTNER'.
          IF sy-subrc = 0.
            CASE <ls_sh_interface_partner>-valfield.
              WHEN 'ORDER_PARTY_ID'       .  " ordering party- OK
                <ls_sh_interface>-value = '1'.
                lv_sales_org_relevant   = abap_true.
              when  'SHIPPER_ID'          .  " shipper - OK
                <ls_sh_interface>-value = '6'.
                lv_sales_org_relevant   = abap_true.

              WHEN OTHERS.
*               no reason to use the sales org assignment
            ENDCASE.
          ENDIF.
        ENDIF.
        IF lv_sales_org_relevant = abap_true.
          DELETE shlp_tab WHERE shlpname NE 'ZSTF_BUPAA_ORG'.
          EXIT. " no other SH shall be used but this one
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.

ENDIF.

 

Ad 6) Adjust the code for relevant UI config and/or relevant BP roles

In the provided code adjust / add the right UI configuration(s), for which the type ahead search shall be applied. Also adjust / add the right BP role codes, which are relevant for the sales org based search.

 

Ad 7) In case you use the “combined search” customzing in your non-HANA-DB system (as explained in blog Businesspartner-and-orgunit-search-in-sap-tm-uis), then copy the /SCMTMS/BUPAA customizing entries to your elementary SH (of step 3).

 

 

 

Result => improved user efficiency

Comprehensive FWO view: Without the enhancement

 

But: Sales Org assignment available…

 

Comprehensive FWO view: With the enhancement in place => only the sales org relevant BP comes

 

Fast order entry screen: Without the enhancement

 

 

Fast order entry screen: With the enhancement in place => only the sales org relevant BP comes

Assigned Tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Suresh Babu Muthusamy
      Suresh Babu Muthusamy

      Thanks for the enhancement and this works great for us.  It is really a very valid and useful enhancement in our project (LSP scenairo) where we use customers name same with multiple Organizational Unit.

      Author's profile photo Selvakumar Murugesan
      Selvakumar Murugesan

      Dear Stefan,

       

      How to bring this Customer Org. Data tab for the sold-to party role. or where to make this Sold-to Party- Sales Org.(TM Forwarding House) connection in the BP transaction. Currently I am using S4 1809 version.

       

       

       

      Thanks in advance

      Author's profile photo Stefan Foerster
      Stefan Foerster
      Blog Post Author

      In S/4 the TM uses the roles FLCU00 and FLCU01 for the sold-to party. When you assign the role FLCU01 there is a button to navigate to the "Sales and Distribution" data. Here you assign the Sales.Org. Not sure whether the enhancement still works - I guess the code would need to be adjusted in S/4 TM.

      Author's profile photo Selvakumar Murugesan
      Selvakumar Murugesan

      Dear Stefan,

      Thanks for your swift reply.

      Through role FLCU01, the system is accepting only SD related sales org. Whereas in TM, Org unit is defined through PPOCE there (Roles: Sales Org, Purchase Org and Forwarding house) can be maintained. As per my understanding there should be an relation between this sales org. and Business partner(sold-to party) created.

      Please correct me if I am wrong.

      Attached here is screenshot for reference.

      Error%3A%20While%20creating%20an%20order%28FWO%29

      Error: While creating an order(FWO)

      Forwarding house defined through PPOCE/PPOME

      BP with FLCU01 role assigned

      Author's profile photo Selvakumar Murugesan
      Selvakumar Murugesan

      screenshot continued...BP%20with%20FLCU01%20role%20assigned

      BP with FLCU01 role assigned

      Author's profile photo Selvakumar Murugesan
      Selvakumar Murugesan

      Forwarding%20house%20role%20defined%20through%20PPOCE/PPOME

      Forwarding house role defined through PPOCE/PPOME

      Author's profile photo Stefan Foerster
      Stefan Foerster
      Blog Post Author

      You actually put the correct relation already between your sales org 5000 and the org unit OAF-FWH-01. In PPOME the field "BSG Org. Unit" at the bottom right corner is set to 5000 and that is the mapping between this org. unit and the sales org.

      Author's profile photo Selvakumar Murugesan
      Selvakumar Murugesan

      Okay, In that case.

      What could be a reason for this error “Org Unit XXX: No data maintained for Business Partner XXXX”.

       

      Thank you.