Skip to Content
avatar image
Former Member

How to pass selection option in dynamic where clause

I have to pass select option in dynamic where clause(i_where) of a select query in 4.6c as follows.

SELECT kschl

FROM <Database table>

INTO TABLE ITAB

WHERE (i_where).

In the program, i_where is getting populated as below

WHERE MATNR IN S_MATNR and

VKORG IN S_VKORG.

But its giving short dump in select query, If I hard code the select option values, it is working fine. How to pass selection options in dynamic where clause as required above.

Thanks in Advance for your help!!!

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

13 Answers

  • avatar image
    Former Member
    Oct 31, 2008 at 12:32 PM

    Hi,

    I think this link might help you,

    dynamic-where-clause

    Regards,

    Vishal

    Edited by: Vishal Jadhav on Oct 31, 2008 6:03 PM

    Edited by: Vishal Jadhav on Oct 31, 2008 6:04 PM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 31, 2008 at 12:33 PM

    Hello,

    Better use the filed symbol before passing it to select statement just assign the select-option to field symbol then pass the field symbol to select statement.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 31, 2008 at 12:36 PM

    Here :

    • Fill the where clause table

  • w_clause = ' f~bukrs = p_bukrs'.

  • APPEND w_clause TO i_clause.

  • w_clause = ' AND bstat = c_space'.

  • APPEND w_clause TO i_clause.

  • w_clause = ' AND f~budat IN so_budat'.

  • APPEND w_clause TO i_clause.

  • w_clause = ' AND f~belnr IN so_belnr'.

  • APPEND w_clause TO i_clause.

  • w_clause = ' AND f~gjahr IN r_year'.

  • APPEND w_clause TO i_clause.

  • w_clause = ' AND f~blart IN so_blart'.

  • APPEND w_clause TO i_clause.

  • w_clause = ' AND k~auart IN so_auart'.

  • APPEND w_clause TO i_clause.

  • select * from (tabname) into itab

    WHERE (i_clause).

    forgot to mention :

    declare the i_clause table like this :

    • TYPES : line(50) TYPE c.

    • DATA : i_clause TYPE STANDARD TABLE OF line,

    • w_clause LIKE LINE OF i_clause.

    regards,

    Advait

    Edited by: Advait Gode on Oct 31, 2008 1:41 PM

Add comment
10|10000 characters needed characters exceeded

  • Former Member

    Thanks for the inputs. I tried but still getting dump in the select query. My code is perfectly working in 4.7 and ECC versions. Is there any problem with 4.6C with dynamic where clause selections?

  • Nov 04, 2008 at 04:06 PM

    Look at this thread .

    Regards

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 24, 2011 at 03:35 PM

    Version 4.6C.....

    Use Function Module RH_DYNAMIC_WHERE_BUILD

    It will look like this...... MATNR IN ('1023222', '1045637')

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 24, 2011 at 07:39 PM

    SELECT kschl

    FROM <Database table>

    INTO TABLE ITAB

    WHERE (i_where).

    In the program, i_where is getting populated as below

    WHERE MATNR IN S_MATNR and

    VKORG IN S_VKORG.

    Did you mean to say:

    In the program, i_where is getting populated as below

    MATNR IN S_MATNR and

    VKORG IN S_VKORG

    Or do you actually have two instances of "where"?

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 25, 2011 at 07:42 AM

    Hi Srinivasa,

    try this -

    concatenate 'MATNR' 'IN' 'S_MATNR' 'AND' 'VKORG' 'IN' 'S_VKORG' into i_where separated by space.

    SELECT kschl

    FROM <Database table>

    INTO TABLE ITAB

    WHERE (i_where).

    Regards,

    Kamini

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 25, 2011 at 07:44 AM

    Hi Srinivasa,

    try this -

    concatenate 'MATNR' 'IN' 'S_MATNR' 'AND' 'VKORG' 'IN' 'S_VKORG' into i_where separated by space.

    SELECT kschl

    FROM <Database table>

    INTO TABLE ITAB

    WHERE (i_where).

    Regards,

    Kamini

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 25, 2011 at 07:44 AM

    Hi Srinivasa,

    try this -

    concatenate 'MATNR' 'IN' 'S_MATNR' 'AND' 'VKORG' 'IN' 'S_VKORG' into i_where separated by space.

    SELECT kschl

    FROM <Database table>

    INTO TABLE ITAB

    WHERE (i_where).

    Regards,

    Kamini

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 25, 2011 at 07:44 AM

    Hi Srinivasa,

    try this -

    concatenate 'MATNR' 'IN' 'S_MATNR' 'AND' 'VKORG' 'IN' 'S_VKORG' into i_where separated by space.

    SELECT kschl

    FROM <Database table>

    INTO TABLE ITAB

    WHERE (i_where).

    Regards,

    Kamini

    Add comment
    10|10000 characters needed characters exceeded