Developer’s Journal: ABAP Search Help For HANA Data


In the last blog, I discussed techniques for accessing the HANA Catalog information from ABAP and how to create an ABAP internal table from a HANA object without a matching data dictionary object. You can probably tell that I’m building up to a tool which can function as a generic HANA catalog viewer, showing both metadata about HANA database objects and a content preview. Before I build that tool, I want to make selection of the catalog objects as simple as possible. Therefore I would like to implement an ABAP Search Help which gets its data from HANA instead of the underlying ABAP database. Ultimately I want it to work in the UI like the following video. Please note: I’m running NetWeaver 7.31 so I have the SuggestValues feature which was new in NetWeaver 7.02.  However ultimately the solution here is a normal Data Dictionary Search Help which could be used on any ABAP release level.

The source code for this example can be downloaded here. It contains the Search Help defintion, the Function Module/Group for the Search Help exit implementation and the DDic Structure with the search help binding which allows the connection between the importing parameters. Please note that you will also need to download the source code content from my previous blog as well.

Search Help Exit

Normally when an ABAP developer implements a Search Help, they only supply the name of the underlying table or view and all the selection work is done for them by the Search Help framework. In this case, however, I needed complete control over the selection logic so that I could use ADBC and my HANA Catalog Utility class from the previous blog in order to query the HANA database for available objects.

The definition of the Search Help itself isn’t all that special in this case. I need to know the currently selected Database Connection, Schema, and Object Type (Table or View) in order to perform a query. Therefore I map these fields as my importing parameters for the Search Help.

The major difference comes in the fact that the selection method is blank in this search help.  Instead I supply the name of a function module – ZHANA_OBJECT_SEARCH as the Search help exit. This function module must have a pre-defined interface, but can then function as the implementation of my search help.

Search Help Exit Function Module

All search help exit function modules, must have the same function interface so that it can be called by the search help framework.

 function zhana_object_search.
 *"*"Local Interface:

There are various control steps in the processing of the search help exit which can be used to over ride processing of the various search help events. The only one which we need to implement in this case is the callcontrol-step of SELECT. This is the primary query event of the search help. From this event we can read the current importing values from the shlp-selopt table.

 if callcontrol-step = 'SELECT'.

     data lr_model type ref to zcl_hana_catalog_utilities.
     data ls_search type zhana_obj_search.
     field-symbols <ls_selopt> type ddshselopt.
     data lx_root type ref to cx_root.

     read table shlp-selopt with key shlpfield = 'CON_NAME'
         assigning <ls_selopt>.
     if sy-subrc = 0.
       ls_search-con_name = <ls_selopt>-low.
     read table shlp-selopt with key shlpfield = 'SCHEMA'
         assigning <ls_selopt>.
     if sy-subrc = 0.
       ls_search-schema = <ls_selopt>-low.
     read table shlp-selopt with key shlpfield = 'OBJ_TYPE'
         assigning <ls_selopt>.
     if sy-subrc = 0.
       ls_search-obj_type = <ls_selopt>-low.
     read table shlp-selopt with key shlpfield = 'OBJ_NAME'
         assigning <ls_selopt>.
     if sy-subrc = 0.
       ls_search-obj_name = <ls_selopt>-low.

Now that we have all of our search input criteria, we can use the HANA Catalog Utilities class from the previous blog to search for all tables or views which match those criteria.   Here is a subset of that logic.  See the downloadable source code sample for complete implementation.

         create object lr_model
             iv_con_name = ls_search-con_name.

         if ls_search-obj_type = 'T'. "table
           data lt_tables type zhana_tables.
           field-symbols <ls_table> like line of lt_tables.

           lv_table = ls_search-obj_name.
           lt_tables = lr_model->get_hana_tables(
               iv_schema   = lv_schema    " Schema
               iv_table    = lv_table     " Table (can be wildcard with %)
               iv_max_rows = callcontrol-maxrecords ). " Maximum Number of Rows
 ****Map to LT_SHLP
           loop at lt_tables assigning <ls_table>.
             append initial line to lt_shlp assigning <ls_shlp>.
             <ls_shlp>-con_name = ls_search-con_name.
             <ls_shlp>-obj_type = ls_search-obj_type.
             <ls_shlp>-schema   = ls_search-schema.
             <ls_shlp>-obj_name = <ls_table>-table_name.

The final activity is to place the query results back into the search help. This is done by calling the function module  F4UT_RESULTS_MAP.

     call function 'F4UT_RESULTS_MAP'
         source_structure   = 'ZHANA_OBJ_SEARCH'
 *       apply_restrictions = abap_true
         shlp_tab           = shlp_tab
         record_tab         = record_tab
         source_tab         = lt_shlp
         shlp               = shlp
         callcontrol        = callcontrol
         illegal_structure  = 1
         others             = 2.
     if sy-subrc <> 0.

Structure for Parameter Mapping

The final step in order to get the input parameter mapping shown in the video to work within Web Dynpro is to map the search help into a data dictionary structure and the use that structure for the basis of the Web Dynpro Context Node.  The importing parameters from other attributes in this Context Node will then be transferred automatically by the framework (even for Suggest Values).

You can make the explicit assignment of the new search help to the OBJ_NAME field and then use the Generate Proposals button to automatically map the input fields of the search help to the corresponding fields of the structure.

The final step is to use this structure as the source Dictionary structure of the Context Node and you have the Value Help working as described in the video at the opening of this blog.




3 responses to “Developer’s Journal: ABAP Search Help For HANA Data”

  1. schucci says :

    Search Help, love the old school being brought into the modern day technology! Sweet!

  2. KK Ramamoorthy says :

    thanks for these detailed examples. goes back to my question during SAPPHIRE though, when business suite will run on HANA (instead of sidecar), does it make sense to change the kernel or the ABAP coding is going to change. i think you alluded to this in your first blog in this series. i guess ABAP syntax is changing but that’s a LOT of work. not just for SAP but for customers who have significantly enhanced their systems. i understand we can’t expect performance improvements without redesigning, but not sure if the customers are hearing the same story; tech guys get it, will customers get it? could be a significant investment; please tell me I am wrong.

    • Thomas Jung says :

      We are doing things at the Kernel level, but ultimately to get the maximum benefit code must be rewritten. However it isn’t like ever line of code needs be touched. Not even every SQL Statements. Well written SQL is already going to benefit from in-memory and columnar access in many cases without modification. However the areas which could receive the most benefit, also will need to push as much of the logic as possible down into HANA to get this benefit.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: