10-24-2006 7:04 PM
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
10-24-2006 7: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
10-24-2006 7:08 PM
10-24-2006 7:10 PM
Hi
U should convert the SELECT-OPTIONS.
But I should know what you need to do exactly
Max
10-24-2006 7:17 PM
Hey max bianchi,
GI_WHERE = 'VBELN IN S_VBELN'.
Here s_vbeln is a select-options only.
That have maltiple values.
in select statement i want to pass the list of values in dynamiclly.
10-24-2006 7:19 PM
Hi
Ok! I understand but why do you need to do that?
Why don't you write simple
SELECT * FROM VBELN IN S_VBELN ?
Max
10-24-2006 7:24 PM
Hi Max,
in one single select statement sometimes i want to use <b>VBELN IN S_VBELN</b> sometimes <b>VKORG IN S_VKORG</b>.It will dynamically.We can't say,which one is comming durinf run time.
10-24-2006 7:32 PM
Hi Vara
I don't know which release you're using but here It occurs a dump if it doesn't use constant values.
Suresh
If you write this select:
SELECT * FROM VBAK WHERE VBELN IN S_VBELN
AND VKORG IN S_VKORG.
It should be ok for all your cases.
Max
10-24-2006 7:35 PM
Hi max,
For example i'm saying vbeln and vkorg.
In run time it will come other values also.
10-24-2006 7: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
10-24-2006 7:28 PM
Hey Vara,
can you tell how you decleared <b>GS_CONDITION-WHERE</b> variable?
10-24-2006 7:31 PM
GS_CONDITIOn-WHERE is a character string of length 600.
It is just a string. Depending on your requirement you can set the length of the string.
Regards,
Vara
10-24-2006 7:33 PM
Hey Vara,
Can u please tell me P_KUNNR is the parameter or select-options.
10-24-2006 7:35 PM
they are all select-options. I am not using any parameters. Fields with R_ are ranges.
I am using ECC 5.
Regards,
Vara
10-24-2006 7:50 PM
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
10-24-2006 7:33 PM
Hi,
You can use the FM ASEL_CEDST_2_RANGE_WHERE to build the where clause for select-options...
Thanks,
Naren
10-24-2006 7:38 PM
Hey Naren,
Can u please show your code what r the values we need to pass and it type also.
10-24-2006 7:44 PM
Hey Naren,
Can u please show your code what r the values we need to pass and it type also.
10-24-2006 7: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
10-24-2006 8:06 PM
Hey Naren,
This FM Reterns the values like this
ITAB_WHERE =
( MATNR EQ '000000000000001951' <b>OR</b>
MATNR EQ '000000000000003190' )
Insted of <b>OR</b> i need <b>AND</b>.
Is ther any way.
10-24-2006 8:20 PM
Hey Naren,
This FM Reterns the values like this
ITAB_WHERE =
( MATNR EQ '000000000000001951' <b>OR</b>
MATNR EQ '000000000000003190' )
Insted of <b>OR</b> i need <b>AND</b>.
Is ther any way.
10-24-2006 8:26 PM
10-24-2006 8:27 PM
10-24-2006 8:33 PM
Hi Rich Heilman,
Right now i'm using 4.6C only.
Message was edited by: Suresh Kumar
10-24-2006 8:41 PM
10-24-2006 8:54 PM
Hey Rich Heilman,
So what is the solution?I'm doeing R&D in last 14 hrs.
Thanks,
Suresh.
10-24-2006 8: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