Skip to Content
author's profile photo Former Member
Former Member

Dynamic Where clause

Hey Guys,

I want to create the dynamic where clause.

DATA: GI_WHERE(72) OCCURS 0 WITH HEADER LINE.

SELECT *

INTO TABLE GI_VBAK

FROM VBAK

WHERE (<b>GI_WHERE</b>).

In that where clause contain ranges.

for eg.

GI_WHERE = <b>'VBELN IN S_VBELN'</b>.

Thanks,

Suresh.

Message was edited by: Suresh Kumar

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 06:06 PM

    Hi

    No! U can't do it, but only insert constant values in WHERE table:

    DATA: FIELD(30).

    SELECT *

    INTO TABLE GI_VBAK

    FROM VBAK

    WHERE (GI_WHERE).

    FIELD = 'VBELN ='.

    CONCATENATE FIELD '''0000000001''' INTO GI_WHERE.

    APPEND GI_WHERE.

    Max

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 06:22 PM

    Yes...You can use a dynamic where clause for select options also.

    for example

    CONCATENATE 'KAPPL' '=' 'C_KAPPL' 'AND'

    'KSCHL' 'IN' 'R_KSCHL' 'AND'

    'VKORG IN P_VKORG' 'AND'

    'VTWEG IN P_VTWEG' 'AND'

    'SPART IN P_SPART' 'AND'

    'KUNNR IN P_KUNNR' 'AND'

    'MATNR IN P_MATNR' 'AND'

    'DATBI >=' 'SY-DATUM' 'AND'

    'DATAB <=' 'SY-DATUM' INTO GS_CONDITION-WHERE SEPARATED BY SPACE.

    The above where clause worked fine in my program.

    Regards,

    Vara

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi

      It's good to know it works in release greater than 4.6.

      Anyway

      If you're using a release of Vara it seems it works, if you're using a release like mine it doesn't work.

      You should write something like this:

      SELECT VBELN FROM VBAK INTO TABLE T_ORDER WHERE VBELN IN SO_VBELN.

      *

      LOOP AT T_ORDER.

      CONCATENATE '''' T_ORDER-VBELN '''' INTO VALUE.

      IF SY-TABIX = 1.

      CONCATENATE 'VBELN = ' VALUE INTO GI_WHERE SEPARATED BY SPACE.

      ELSE.

      CONCATENATE 'OR VBELN = ' VALUE INTO GI_WHERE SEPARATED BY SPACE.

      ENDIF.

      APPEND GI_WHERE.

      ENDLOOP.

      SELECT *

      INTO TABLE GI_VBAK

      FROM VBAK

      WHERE (GI_WHERE).

      But it doesn't make sense because you read VBAK twice.

      I believe if you have a select-options like that:

      TABLES VBAK.

      SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN,

      S_VKORG FOR VBAK-VKORG,

      S_KUNAG FOR VBAK-KUNAG.

      You can use:

      SELECT * FROM VBAK WHERE VBELN IN S_VBELN

      AND VKORG IN S_VKORG

      AND KUNAG IN S_KUNAG.

      This select is better than to use an dynamic clause and it should be always fine.

      Max

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 06:33 PM

    Hi,

    You can use the FM ASEL_CEDST_2_RANGE_WHERE to build the where clause for select-options...

    Thanks,

    Naren

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 06:48 PM

    Hi,

    Check this example..

    TYPE-POOLS: rsds.

    TABLES: vbap.

    SELECT-OPTIONS so_matnr FOR vbap-matnr.

    DATA: itab_where(72) OCCURS 0 WITH HEADER LINE.

    DATA: t_where TYPE rsds_twhere WITH HEADER LINE,

    t_cedst TYPE STANDARD TABLE OF cedst,

    s_cedst LIKE LINE OF t_cedst.

    s_cedst-fnam = 'VBAP~MATNR'.

    LOOP AT so_matnr.

    MOVE-CORRESPONDING so_matnr TO s_cedst.

    APPEND s_cedst TO t_cedst.

    ENDLOOP.

    CALL FUNCTION 'ASEL_CEDST_2_RANGE_WHERE'

    EXPORTING

    id_tabname = 'VBAP'

    id_xwhere = 'X'

    TABLES

    it_cedst = t_cedst

    et_where = t_where

    EXCEPTIONS

    selection_not_found = 1

    OTHERS = 2.

    IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    READ TABLE t_where INDEX 1.

    itab_where[] = t_where-where_tab[].

    SELECT SINGLE * FROM vbap

    WHERE (itab_where).

    IF sy-subrc = 0.

    ENDIF.

    Please let me know if it works..

    Thanks,

    Naren

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 07:57 PM

    Hi,

    As Rich mentioned..You cannot have <b>AND</b> for MATNR..As single row cannot have two values for the same field..

    Thanks,

    Naren

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.