Friday, December 24, 2010
Here are few function modules used to create dynamic WHERE clause.
  • CONVERT_SELECT_INTO_WHERE
  • ADSPC_CREATE_WHERE_CLAUSE
  • DYNSQL_GENERATE_WHERE_CLAUSE
  • FREE_SELECTIONS_RANGE_2_WHERE
The following sample program demonstrates on how to use Dynamic WHERE clause.  
REPORT  ztest_dynamic.
"---------------------------------------------------------------------------*
"Declaration
"---------------------------------------------------------------------------*
"Table for condition
DATA:
      wa_cond     TYPE string,
      it_cond     TYPE TABLE OF string.
"Variables
DATA:
      lv_cityfrom TYPE spfli-cityfrom.
"---------------------------------------------------------------------------*
"Selection Screen
"---------------------------------------------------------------------------*
PARAMETERS: city1(10) TYPE c, city2(10) TYPE c.

"---------------------------------------------------------------------------*
"Start of selection
"---------------------------------------------------------------------------*

START-OF-SELECTION.

  CONCATENATE 'CITYFROM = ''' city1 '''' INTO wa_cond.
  APPEND wa_cond TO it_cond.
  CLEAR  wa_cond.

  CONCATENATE 'OR CITYFROM = ''' city2 '''' INTO wa_cond.
  APPEND wa_cond TO it_cond.
  CLEAR  wa_cond.

  CONCATENATE 'OR CITYFROM = ''' 'BERLIN' '''' INTO wa_cond.
  APPEND wa_cond TO it_cond.
  CLEAR  wa_cond.
  "Check the Where wa_condition
  LOOP AT it_cond INTO wa_cond.
    WRITE wa_cond.
  ENDLOOP.
  SKIP.
  "Select Query with dynamic where clause
  SELECT  cityfrom
    INTO  lv_cityfrom
    FROM  spfli
   WHERE (it_cond).

    WRITE / lv_cityfrom.
  ENDSELECT.

0 comments:

Post a Comment

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.