Skip to content
NextLytics
Megamenü_2023_Über-uns

Shaping Business Intelligence

Whether clever add-on products for SAP BI, development of meaningful dashboards or implementation of AI-based applications - we shape the future of Business Intelligence together with you. 

Megamenü_2023_Über-uns_1

About us

As a partner with deep process know-how, knowledge of the latest SAP technologies as well as high social competence and many years of project experience, we shape the future of Business Intelligence in your company too.

Megamenü_2023_Methodik

Our Methodology

The mixture of classic waterfall model and agile methodology guarantees our projects a high level of efficiency and satisfaction on both sides. Learn more about our project approach.

Products
Megamenü_2023_NextTables

NextTables

Edit data in SAP BW out of the box: NextTables makes editing tables easier, faster and more intuitive, whether you use SAP BW on HANA, SAP S/4HANA or SAP BW 4/HANA.

Megamenü_2023_Connector

NextLytics Connectors

The increasing automation of processes requires the connectivity of IT systems. NextLytics Connectors allow you to connect your SAP ecosystem with various open-source technologies.

IT-Services
Megamenü_2023_Data-Science

Data Science & Engineering

Ready for the future? As a strong partner, we will support you in the design, implementation and optimization of your AI application.

Megamenü_2023_Planning

SAP Planning

We design new planning applications using SAP BPC Embedded, IP or SAC Planning which create added value for your company.

Megamenü_2023_Dashboarding

Dashboarding

We help you with our expertise to create meaningful dashboards based on Tableau, Power BI, SAP Analytics Cloud or SAP Lumira. 

Megamenü_2023_Data-Warehouse-1

SAP Data Warehouse

Are you planning a migration to SAP HANA? We show you the challenges and which advantages a migration provides.

Business Analytics
Megamenü_2023_Procurement

Procurement Analytics

Transparent and valid figures are important, especially in companies with a decentralized structure. SAP Procurement Analytics allows you to evaluate SAP ERP data in SAP BI.

Megamenü_2023_Reporting

SAP HR Reporting & Analytics

With our standard model for reporting from SAP HCM with SAP BW, you accelerate business activities and make data from various systems available centrally and validly.

Megamenü_2023_Dataquality

Data Quality Management

In times of Big Data and IoT, maintaining high data quality is of the utmost importance. With our Data Quality Management (DQM) solution, you always keep the overview.

Career
Megamenü_2023_Karriere-2b

Working at NextLytics

If you would like to work with pleasure and don't want to miss out on your professional and personal development, we are the right choice for you!

Megamenü_2023_Karriere-1

Senior

Time for a change? Take your next professional step and work with us to shape innovation and growth in an exciting business environment!

Megamenü_2023_Karriere-5

Junior

Enough of grey theory - time to get to know the colourful reality! Start your working life with us and enjoy your work with interesting projects.

Megamenü_2023_Karriere-4-1

Students

You don't just want to study theory, but also want to experience it in practice? Check out theory and practice with us and experience where the differences are made.

Megamenü_2023_Karriere-3

Jobs

You can find all open vacancies here. Look around and submit your application - we look forward to it! If there is no matching position, please send us your unsolicited application.

Blog
NextLytics Newsletter Teaser
Sign up now for our monthly newsletter!
Sign up for newsletter
 

How to implement fuzzy search with NextTables

◀ Back to Knowledge Base

Especially if you are working with a large list of possible entries, finding the right one can be challenging. In the “How to always find the right values with NextTables” article, you learned the possibilities of the search algorithm. In this article I will guide you step by step through the technical side of implementation.

At the end of this article, you will be able to customize your search results and enhance them with a context menu. You can see an example below.

Fuzzy Search

Technical implementation

In the How to implement a BAdI for NextTables article you have learned how to create a BAdI implementation. To make sure that the BAdI is executed only for a certain InfoObject, you have to setup the filter criteria accordingly. Please define the respective InfoObject in the filter settings. In our example we use the InfoObject /NLY/PERNR.

fuzzy search 2

The meta data of the search can be adjusted using the SET_META_EXIT method. For example, you can change the search bar to dropdown or activate and disable strict search.

fuzzy search 3

The dropdown search suites best for short result lists and always loads all values locally first. Then, the search is executed on the locally loaded values. Thus, dropdown is ideal for short lists. On the other hand, the search function is executed for the entered search term only (eventually it is executed multiple times, if you enter the letters quite slowly). Therefore, SEARCH setting suites best for objects with large master data selections.

You can find the sample code below.

METHOD /nly/if_search~set_meta_exit.

ch_s_search_info-min_char = '3'.
ch_s_search_info-searchmode = i_stype.
ch_s_search_info-searchname = i_searchname.
ch_s_search_info-strict = 'X'.
ch_s_search_info-searchstyle = 'SEARCH'.

ENDMETHOD.

The search logic is implemented in the implementing class. We will utilize the method /NLY/IF_SEARCH~DO_SEARCH_EXIT to customize the search. Double click on the method to create an implementation.

fuzzy search 4

In our coding, we define the table for the search results and the necessary variables. After checking the search term for consistency, we define the SQL query in the variable lv_sql. 

In this example we setup a view enhancing the personnel IDs with additional information such as company codes, addresses, cost centres etc. We also define the mode of the fuzzy search and weight the respective elements. Here, the family name NACHN is the most important element (weight 1.0), followed by first name (VORN) and ID (PERNR). Afterwards, the SQL query is executed.

In case of error, you can define respective messages to be presented to the user. If the search query was executed successfully, the search results with respective context menu are prepared.

As the last step, you need to define the search as customer exit implemented. Otherwise, the standard search will be executed again, overwriting your results.

You can find the complete coding below:

  METHOD /nly/if_search~do_search_exit.

TYPES:
BEGIN OF ts_changes,
score TYPE decfloat34,
pernr TYPE /b787/oipernr,
nachn TYPE c LENGTH 40,
vorna TYPE c LENGTH 40,
pstlz TYPE c LENGTH 10,
stras TYPE c LENGTH 60,
ort01 TYPE c LENGTH 40,
emplstatus_txtmd TYPE c LENGTH 40,
bukrs TYPE c LENGTH 10,
bukrs_txtmd TYPE c LENGTH 40,
kostl TYPE c LENGTH 10,
kostl_txtmd TYPE c LENGTH 40,
orgeh TYPE c LENGTH 10,
orgid_txtmd TYPE c LENGTH 40,
plans TYPE c LENGTH 10,
plans_txtmd TYPE c LENGTH 40,
END OF ts_changes,
tt_changes TYPE TABLE OF ts_changes.

DATA: ls_search_result TYPE /nly/ts_search_result,
lv_sql TYPE string,
lo_t_table TYPE REF TO data,
l_search_term TYPE string.

* Search term
DATA(lv_search_term) = i_search_term.

FIELD-SYMBOLS:
<fs_s_table> TYPE ts_changes,
<fs_t_table> TYPE tt_changes.

REPLACE ALL OCCURRENCES OF '%20' IN lv_search_term WITH ` `.
REPLACE ALL OCCURRENCES OF '%22' IN lv_search_term WITH `"`.

IF lv_search_term IS INITIAL.
l_search_term = '*'.
ELSE.
l_search_term = |{ lv_search_term }|.
ENDIF.

CREATE DATA lo_t_table TYPE tt_changes.
ASSIGN lo_t_table->* TO <fs_t_table>.


lv_sql = |SELECT TOP 300 DISTINCT SCORE() AS SCORE, pernr, nachn, vorna, pstlz, stras, ort01, emplstatus_txtmd, bukrs, bukrs_txtmd, kostl, kostl_txtmd, orgeh, orgid_txtmd, plans, plans_txtmd |
&& |FROM "ZCDSPERSSEARCH" | " Personnel View
&& |WHERE CONTAINS(("NACHN", "VORNA", "PERNR", "STRAS", "ORT01", "BUKRS", "KOSTL", "ORGEH", "PLANS", "PLANS_TXTMD", "ORGID_TXTMD", "BUKRS_TXTMD", "KOSTL_TXTMD" ), '{ l_search_term }', FUZZY(0.7, 'similarCalculationMode=compare')|
&& | , weight (1, 0.8, 0.8, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.3, 0.3, 0.3, 0.3 )) |
&& |ORDER BY score() desc|.


TRY.
" Prepare SQL connection and statement
DATA(lo_result) =
cl_sql_connection=>get_connection(
)->create_statement(
)->execute_query( lv_sql ).

lo_result->set_param_table( REF #( <fs_t_table> ) ).

" Get result
lo_result->next_package( ).
lo_result->close( ).
CATCH cx_sql_exception INTO DATA(err).

" Error handling
DATA l_error(200) TYPE c.
l_error = |{ err->get_text( ) }|.

RAISE EXCEPTION TYPE /nly/cx_search_rest
EXPORTING
textid = /nly/cx_table_rest=>custom_message
msgv1 = l_error(50)
msgv2 = l_error+50(50)
msgv3 = l_error+100(50)
msgv4 = l_error+150(50).
ENDTRY.

LOOP AT <fs_t_table> ASSIGNING <fs_s_table>.
CLEAR ls_search_result.
ls_search_result-title_key = |{ <fs_s_table>-pernr alpha = out }|. " As search terms are handled in external format on the front end.
ls_search_result-title_desc = |{ <fs_s_table>-nachn } { <fs_s_table>-vorna } ({ <fs_s_table>-pernr ALPHA = out width = 1 }) |.
ls_search_result-sub_title = | { <fs_s_table>-plans_txtmd } in { <fs_s_table>-orgid_txtmd } |.
ls_search_result-content = |Adresse: { <fs_s_table>-stras } | && | { <fs_s_table>-ort01 } |
&& | <br>BuKrs: { <fs_s_table>-bukrs } { <fs_s_table>-bukrs_txtmd }|
&& | <br>Kost: { <fs_s_table>-kostl } { <fs_s_table>-kostl_txtmd }|
&& | <br>Score: { <fs_s_table>-score }|.
ls_search_result-score = <fs_s_table>-score * 100.
APPEND ls_search_result TO e_t_search_result.

ENDLOOP.


* set as customer exit implemented
e_is_implemented = abap_true.
ENDMETHOD.

As you implement your custom logic, please make sure that all involved pieces are activated, not only the implementing class. You need to activate the following objects:

  • implementing class together with methods
  • BAdI implementation
  • Enhancement implementation

Which License is needed for this feature Professional | Enterprise


Do you have a question regarding NextTables? Already a customer? Please click here for Support.