Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass selection option in dynamic where clause

Former Member
0 Kudos

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!!!

14 REPLIES 14

Former Member
0 Kudos

Hi,

I think this link might help you,

Regards,

Vishal

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

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

0 Kudos

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?

raymond_giuseppi
Active Contributor
0 Kudos

Look at this thread .

Regards

Former Member
0 Kudos

Version 4.6C.....

Use Function Module RH_DYNAMIC_WHERE_BUILD

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

Former Member
0 Kudos

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"?

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos
 TABLES: vbak.
DATA: condition TYPE string.
DATA: BEGIN OF itab OCCURS 0,
      vbeln LIKE vbak-vbeln,
      posnr LIKE vbap-posnr,
      END OF itab.
DATA: it_options TYPE rfc_db_opt OCCURS 0 WITH HEADER LINE.
SELECT-OPTIONS: s_vbeln FOR vbak-vbeln.
CONCATENATE 'VBELN' 'IN' 'S_VBELN' INTO condition SEPARATED BY space.

it_options-text = condition.
APPEND it_options.
CLEAR it_options.

SELECT vbeln
       posnr
       FROM vbap
       INTO TABLE itab
       WHERE (it_options).

LOOP AT itab.

  WRITE 'THANKS TO RICH/VIJAY'.

ENDLOOP.
...

Former Member
0 Kudos

be careful with spaces and dots

also maybe you have another 'where' in your clause