Skip to Content

    Usually Search Help source data from either Table or View. Sometimes data selection requirements are so complex, that view no mention table can not satisfy them. In this case developer has to leverage SELECT step of Search Help Exit in order to have a full flexibility of data selection. But flexibility of data selection comes with a price to handle Search Help Data Restrictions.

    In my blog I will demonstrate how gracfully apply Search Help Restrictions to data selection using CL_RSDRV_REMOTE_IPROV_SRV Class. For those who has BW background, this class should be familiar.

    Suppose that you need to create a Search Help that provides a list of released, not locked, not deleted and not confirmed Production Orders as displayed below

Search Help Restrictions 1 of 3.jpg

Data is sourced from multiple tables. Left Join and WHERE clause subqueries are used. The latter definintely goes beyond of ABAP view capabilities. That is why Search Help Exit with free style SQL is used. The complexity lies in dynamically appling Search Help Restrictions to SQL statement used to retrieve data

Search Help Restrictions 2 of 3.jpg

Search Help Restrictions 3 of 3.jpg

CL_RSDRV_REMOTE_IPROV_SRV Class dynamically generating SQL WHERE clause condition from Search Help Restrcions without any hardcoding

Search Help Exit Debugging 1 of 3.jpg

Search Help Exit Debugging 2 of 3.jpg

Search Help Exit Debugging 3 of 3.jpg

I innovatively used of CL_RSDRV_REMOTE_IPROV_SRV to generation of WHERE condition for multiple joined tables, whereas the class was ment to be used with single table only.

Below are step by step instructions how to implement the Search Help

1) Define LCL_REMOTE_IPROV_SRV Wrapper Class;

2) Define ZPROD_ORD_SHLP Search Help Exit;

3) Define ZPROD_ORD_SHLP Search Help.

Define LCL_REMOTE_IPROV_SRV Wrapper Class

DEFINE define_mapping_iobj_2_fld.

  wa_iobj_2_fldiobjnm = &1.
  wa_iobj_2_fld
fldnm  = &2.
 
INSERT wa_iobj_2_fld INTO TABLE wt_iobj_2_fld.

END-OF-DEFINITION.

*———————————————————————*
*      CLASS lcl_remote_iprov_srv DEFINITION
*———————————————————————*
CLASS lcl_remote_iprov_srv DEFINITION.

  PUBLIC SECTION.
   
METHODS:
      constructor,
      get_where_conditions
IMPORTING it_selops TYPE ddshselops
                         
RETURNING VALUE(rt_where) TYPE rsdr0_t_abapsource.
 
PRIVATE SECTION.
   
DATA:
      remote_iprov_srv   
TYPE REF TO cl_rsdrv_remote_iprov_srv.

ENDCLASS.

*———————————————————————*
*      CLASS lcl_remote_iprov_srv IMPLEMENTATION
*———————————————————————*
CLASS lcl_remote_iprov_srv IMPLEMENTATION.

*———————————————————————*
* constructor
*———————————————————————*
 
METHOD constructor.
 
DATA: wa_iobj_2_fld TYPE cl_rsdrv_remote_iprov_srv=>tn_s_iobj_fld_mapping,
        wt_iobj_2_fld
TYPE cl_rsdrv_remote_iprov_srv=>tn_th_iobj_fld_mapping.

    define_mapping_iobj_2_fld: ‘AUFNR’        ‘AUFK~AUFNR’,
                             
‘AUART’        ‘AUFK~AUART’,
                             
‘WERKS’        ‘AUFK~WERKS’,
                             
‘APRIO’        ‘AFKO~APRIO’,
                             
‘MATNR’        ‘AFPO~MATNR’,
                             
‘KUNNR’        ‘VBAK~KUNNR’,
                             
‘KDAUF’        ‘AUFK~KDAUF’,
                             
‘KDPOS’        ‘AUFK~KDPOS’.
   
CREATE OBJECT remote_iprov_srv
     
EXPORTING i_th_iobj_fld_mapping = wt_iobj_2_fld
                i_tablnm             
= ‘DUMMY’.

  ENDMETHOD.

*———————————————————————*
* get_where_conditions
*———————————————————————*
 
METHOD get_where_conditions.
 
DATA: wa_selops TYPE ddshselopt.
 
DATA: wa_selection TYPE LINE OF cl_rsdrv_remote_iprov_srv=>tn_t_selection,
        wt_selection
TYPE cl_rsdrv_remote_iprov_srv=>tn_t_selection.

    LOOP AT it_selops INTO wa_selops.
     
MOVE-CORRESPONDING wa_selops TO wa_selection.
      wa_selectioninfoobject
= wa_selopsshlpfield.
     
APPEND wa_selection TO wt_selection.
   
ENDLOOP.
    remote_iprov_srv
->build_where_conditions(
     
EXPORTING i_t_selection = wt_selection
     
IMPORTING e_t_where    = rt_where ).

  ENDMETHOD.

ENDCLASS.

Define ZPROD_ORD_SHLP Search Help Exit

FUNCTION zprod_ord_shlp.
*”———————————————————————-
*”*”Local Interface:
*”  TABLES
*”      SHLP_TAB TYPE  SHLP_DESCT
*”      RECORD_TAB STRUCTURE  SEAHLPRES
*”  CHANGING
*”    VALUE(SHLP) TYPE  SHLP_DESCR
*”    VALUE(CALLCONTROL) LIKE  DDSHF4CTRL STRUCTURE  DDSHF4CTRL
*”———————————————————————-
 
data: rc      type i.

* EXIT immediately, if you do not want to handle this step
 
IF CALLCONTROLSTEP <> ‘SELONE’ AND
    CALLCONTROL
STEP <> ‘SELECT’ AND
   
” AND SO ON
    CALLCONTROL
STEP <> ‘DISP’.
   
EXIT.
 
ENDIF.

*”———————————————————————-
* STEP SELONE  (Select one of the elementary searchhelps)
*”———————————————————————-
* This step is only called for collective searchhelps. It may be used
* to reduce the amount of elementary searchhelps given in SHLP_TAB.
* The compound searchhelp is given in SHLP.
* If you do not change CALLCONTROL-STEP, the next step is the
* dialog, to select one of the elementary searchhelps.
* If you want to skip this dialog, you have to return the selected
* elementary searchhelp in SHLP and to change CALLCONTROL-STEP to
* either to ‘PRESEL’ or to ‘SELECT’.
 
IF CALLCONTROLSTEP = ‘SELONE’.
*  PERFORM SELONE ………
   
EXIT.
 
ENDIF.

*”———————————————————————-
* STEP PRESEL  (Enter selection conditions)
*”———————————————————————-
* This step allows you, to influence the selection conditions either
* before they are displayed or in order to skip the dialog completely.
* If you want to skip the dialog, you should change CALLCONTROL-STEP
* to ‘SELECT’.
* Normaly only SHLP-SELOPT should be changed in this step.
 
IF CALLCONTROLSTEP = ‘PRESEL’.
*  PERFORM PRESEL ……….
   
EXIT.
 
ENDIF.
*”———————————————————————-
* STEP SELECT    (Select values)
*”———————————————————————-
* This step may be used to overtake the data selection completely.
* To skip the standard seletion, you should return ‘DISP’ as following
* step in CALLCONTROL-STEP.
* Normally RECORD_TAB should be filled after this step.
* Standard function module F4UT_RESULTS_MAP may be very helpfull in this
* step.
** *********************************
** modified part starts here
** *********************************
 
IF CALLCONTROLSTEP = ‘SELECT’.
 
PERFORM STEP_SELECT TABLES RECORD_TAB SHLP_TAB
                     
CHANGING SHLP CALLCONTROL RC.
 
IF RC = 0.
    CALLCONTROL
STEP = ‘DISP’.
 
ELSE.
    CALLCONTROL
STEP = ‘EXIT’.
 
ENDIF.
   
EXIT. “Don’t process STEP DISP additionally in this call.
 
ENDIF.
*”———————————————————————-
* STEP DISP    (Display values)
*”———————————————————————-
* This step is called, before the selected data is displayed.
* You can e.g. modify or reduce the data in RECORD_TAB
* according to the users authority.
* If you want to get the standard display dialog afterwards, you
* should not change CALLCONTROL-STEP.
* If you want to overtake the dialog on you own, you must return
* the following values in CALLCONTROL-STEP:
* – “RETURN” if one line was selected. The selected line must be
*  the only record left in RECORD_TAB. The corresponding fields of
*  this line are entered into the screen.
* – “EXIT” if the values request should be aborted
* – “PRESEL” if you want to return to the selection dialog
* Standard function modules F4UT_PARAMETER_VALUE_GET and
* F4UT_PARAMETER_RESULTS_PUT may be very helpfull in this step.
 
IF CALLCONTROLSTEP = ‘DISP’.
*  PERFORM AUTHORITY_CHECK TABLES RECORD_TAB SHLP_TAB
*                          CHANGING SHLP CALLCONTROL.
   
EXIT.
 
ENDIF.
ENDFUNCTION.

** ********************************************************************
** selection of entries with correct text
** ********************************************************************

FORM STEP_SELECT TABLES RECORD_TAB SHLP_TAB TYPE SHLP_DESCT
                     
CHANGING SHLP TYPE SHLP_DESCR CALLCONTROL TYPE  DDSHF4CTRL RC.
DATA: wt_where TYPE rsdr0_t_abapsource.
DATA: wt_prod_ord_shlp TYPE TABLE OF zprod_ord_shlp.
DATA: remote_iprov_srv TYPE REF TO lcl_remote_iprov_srv.
CONSTANTS: c_dlfl    TYPE j_status  VALUE ‘I0076’,
          c_lkd     
TYPE j_status  VALUE ‘I0043’,
          c_rel     
TYPE j_status  VALUE ‘I0002’,
          c_cnf     
TYPE j_status  VALUE ‘I0009’,
          c_active 
TYPE abap_bool VALUE abap_false,
          c_inactive
TYPE abap_bool VALUE abap_true.

  CHECK shlpshlpname = ‘ZPROD_ORDER’.
 
CREATE OBJECT remote_iprov_srv.
  wt_where
= remote_iprov_srv->get_where_conditions( shlpselopt ).

  SELECT aufk~aufnr
        aufk~auart
        aufk~werks
        afko~aprio
        afpo~matnr
        vbak~kunnr
        aufk~kdauf
        aufk~kdpos
 
FROM ( ( aufk INNER JOIN afpo
                       
ON aufk~aufnr = afpo~aufnr )
               
INNER JOIN afko
                       
ON aufk~aufnr = afko~aufnr )
               
LEFT  JOIN vbak
                       
ON vbak~vbeln = aufk~kdauf
 
UP TO callcontrolmaxrecords ROWS
 
INTO CORRESPONDING FIELDS OF TABLE wt_prod_ord_shlp
 
WHERE (wt_where)
*  Released
   
AND aufk~objnr IN ( SELECT objnr
                       
FROM jest
                       
WHERE aufk~objnr = jest~objnr
                         
AND jest~stat  = c_rel
                         
AND jest~inact = c_active )
*  Not Deleted
   
AND aufk~objnr NOT IN ( SELECT objnr
                           
FROM jest
                           
WHERE objnr = aufk~objnr
                             
AND stat  = c_dlfl
                             
AND inact = c_active )
*  Not Locked
   
AND aufk~objnr NOT IN ( SELECT objnr
                           
FROM jest
                           
WHERE objnr = aufk~objnr
                             
AND stat  = c_lkd
                             
AND inact = c_active )
*  Not Confirmed
   
AND aufk~objnr NOT IN ( SELECT objnr
                           
FROM jest
                           
WHERE objnr = aufk~objnr
                             
AND stat  = c_cnf
                             
AND inact = c_active ).

  if sysubrc <> 0.
    RC
= sysubrc.
   
exit.
 
endif.

  record_tab[] = wt_prod_ord_shlp[].

ENDFORM.

Define ZPROD_ORD_SHLP Search Help

Define ZPROD_ORD_SHLP dummy source table

Search Help 1 of 2.jpg

Define ZPROD_ORD_SHLP Search Help refering ZPROD_ORD_SHLP dummy source and ZPROD_ORD_SHLP Seach Help Exit

Search Help 2 of 2.jpg

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply