Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8459

Re: Case Insensitive SELECT statement

$
0
0

You might want to do it like this:

 

Scenario:

Input field IV_NAME1_SEARCHSTRING in this Method is a search string which searches for case insensitive NAME1 field in vendor master LFA1.

 

Parameters of the Method

Params.JPG

Source code of Method

 

 

TYPES:
     TY_T_LFA1 TYPE TABLE OF LFA1 .     "Declared in the Public Section

 

METHOD select_vendor_native .  DATA:     o_cond                   TYPE REF TO cl_lib_seltab,     l_con_ref                TYPE REF TO cl_sql_connection,     l_stmt                    TYPE string,     l_stmt_ref               TYPE REF TO cl_sql_statement,     l_dref                     TYPE REF TO data,     l_res_ref                 TYPE REF TO cl_sql_result_set,     ls_lfa1                    TYPE lfa1,     lt_lfa1                     TYPE TABLE OF lfa1,     lv_found                  TYPE boolean,     lv_new_searchstring TYPE string,     lv_size_limit            TYPE i.  lv_new_searchstring = to_upper( replace( val = iv_name1_searchstring                                                                              sub  = |*|                                                                             with = |%|                                                                             occ  = 0 ) ).  lv_size_limit = iv_size_limit.  IF lv_size_limit < 0 OR lv_size_limit > gc_size_limit.    "100    lv_size_limit = gc_size_limit.  ENDIF.
* create the connecction to database object.  CREATE OBJECT l_con_ref.  l_stmt =     'SELECT * '    &&                   ' FROM  lfa1 '     &&                   ' WHERE upper(name1) LIKE  ''' && lv_new_searchstring && '''' &&                   ' AND mandt = ' && sy-mandt &&                   | FETCH FIRST | && lv_size_limit && ' ROW ONLY'.
* create the sql statement object  l_stmt_ref = l_con_ref->create_statement( ).  l_res_ref  = l_stmt_ref->execute_query( l_stmt ).
* set output structure  GET REFERENCE OF ls_lfa1 INTO l_dref.  l_res_ref->set_param_struct( l_dref ).
* show result  CLEAR et_lfa1.  WHILE l_res_ref->next( ) > 0.    APPEND ls_lfa1 TO et_lfa1.  ENDWHILE.  ev_found = boolc( et_lfa1 IS NOT INITIAL ).
* close the result set object  l_res_ref->close( ).
ENDMETHOD.

 

You need to follow the model above to meet your requirement for the PLPO table that you are using.

 

Hope this helps.

 

Sougata.


Viewing all articles
Browse latest Browse all 8459

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>