2009 Dec 16 7:57 AM
Hi experts,
I have a query like this:
IF NOT i_name1 IS INITIAL.
SELECT kunnr
FROM kna1
INTO TABLE it_kna1
WHERE name1 EQ i_name1.
ENDIF.
Lets says KNA1 has some customer names like CABD, ZABY, PABQ, LABN.
Suppose a customer enters the customer name as AB, how can I use the wild characters in the query to ensure
that all these 4 names are fetched?
Thanks,
Ajay.
2009 Dec 16 8:27 AM
Use a [SELECT-OPTIONS|http://help.sap.com/abapdocu_70/en/ABAPSELECT-OPTIONS.htm] and not a PARAMETER for input and a [SELECT WHERE NAME IN SO-NAME |http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP_SELTAB.htm]statement to read.
SELECT-OPTIONS so-name1 FOR kna1-name1 NO-EXTENSION NO INTERVALS.
SELECT * FROM kna1 WHERE name1 IN so-name1.Regards,
Raymond
Hi experts,
I have a query like this:
IF NOT i_name1 IS INITIAL.
SELECT kunnr
FROM kna1
INTO TABLE it_kna1
WHERE name1 EQ i_name1.
ENDIF.
Lets says KNA1 has some customer names like CABD, ZABY, PABQ, LABN.
Suppose a customer enters the customer name as AB, how can I use the wild characters in the query to ensure
that all these 4 names are fetched?
Thanks,
Ajay.
2009 Dec 16 8:02 AM
Hi,
You can use like this :
IF NOT i_name1 IS INITIAL.
SELECT kunnr
FROM kna1
INTO TABLE it_kna1
WHERE name1 like '%AB%'.
ENDIF.
Regards,
Sunny
2009 Dec 16 8:14 AM
Hi Sunny,
Thanks for the valuable response. Is it possible to do some dynamic coding for this % thing. I mean if the user does not know the customer name, he can enter any combination.
Thanks,
Ajay.
2009 Dec 16 8:31 AM
Hi Ajay,
Try like below,
PARAMETERS: pattern TYPE string. " Enter dynamic combination of customer name
CONCATENATE '%' pattern '%' INTO pattern.
IF NOT i_name1 IS INITIAL.
SELECT kunnr
FROM kna1
INTO TABLE it_kna1
WHERE name1 like pattern.
ENDIF.
Thanks,
2009 Dec 16 8:44 AM
Hi,
If m not wrong, you are asking like if the pattern is changing then how it can be done?
IF that is the case, you should take that pattern into a variable concatenate % before and after the value and use this variable in your select query.
var = 'cd'.
concatenate '%' var '%' into var.
select abc
into xyz
from sss
where value like var.
Regards,
Sunny
2009 Dec 16 8:52 AM
hi ajay ,
who told it is not possible pls do this way
Don't worry You can use " Ranges : i_name1 like kn1-name1 . PASTE BELOW CODE IN YOUR FUNCTION MODULE
IT WILL RUN LIKE A BULLET .
Ranges : i_name1 like knA1-name1 .
MOVE 'I' TO i_NAME1-sign.
MOVE 'CP' TO I_NAME1 option.
MOVE I_NAME1 TO I_NAME1-low.
APPEND I_NAME1.
IF NOT i_name1 IS INITIAL.
SELECT kunnr
FROM kna1
INTO TABLE it_kna1
WHERE name1 EQ i_name1.
ENDIF.
rEGARDS
dEEPAK .
2009 Dec 16 8:53 AM
hi ajay ,
who told it is not possible pls do this way
Don't worry You can use " Ranges : i_name1 like kn1-name1 . PASTE BELOW CODE IN YOUR FUNCTION MODULE
IT WILL RUN LIKE A BULLET .
Ranges : i_name1 like knA1-name1 .
MOVE 'I' TO i_NAME1-sign.
MOVE 'CP' TO I_NAME1 option.
MOVE I_NAME1 TO I_NAME1-low.
APPEND I_NAME1.
IF NOT i_name1 IS INITIAL.
SELECT kunnr
FROM kna1
INTO TABLE it_kna1
WHERE name1 EQ i_name1.
ENDIF.
rEGARDS
dEEPAK .
2009 Dec 16 8:08 AM
Hi,
Use
SELECT kunnr
FROM kna1
INTO TABLE it_kna1
WHERE name1 LIKE '%AB%'.
2009 Dec 16 8:12 AM
2009 Dec 16 8:27 AM
Use a [SELECT-OPTIONS|http://help.sap.com/abapdocu_70/en/ABAPSELECT-OPTIONS.htm] and not a PARAMETER for input and a [SELECT WHERE NAME IN SO-NAME |http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP_SELTAB.htm]statement to read.
SELECT-OPTIONS so-name1 FOR kna1-name1 NO-EXTENSION NO INTERVALS.
SELECT * FROM kna1 WHERE name1 IN so-name1.Regards,
Raymond
2009 Dec 16 8:32 AM
Hi Raymond,
I am doing all this coding inside a FM. I think Select Options or Parameters cant be used inside a FM.
Any other workaround?
Thanks,
Ajay.
2009 Dec 16 8:37 AM
2009 Dec 16 8:42 AM
Hi Ajay,
try this:
REPLACE ALL OCCURRENCES OF '*' in i_name1 WITH '%'.
IF NOT i_name1 IS INITIAL.
SELECT kunnr
FROM kna1
INTO TABLE it_kna1
WHERE name1 LIKE i_name1.
ENDIF.
2009 Dec 16 8:48 AM
Hi Ajay,
Since u are coding inside FM, do like below.
Create an importing parameter(mandatory) for the FM which will get customer name comibation into the function module.
(Ex: Pattern type String) Cutomer name combinations are like AB, BA, CD..,
Now inside FM add below statement,
CONCATENATE '%' pattern '%' INTO pattern.
IF NOT i_name1 IS INITIAL.
SELECT kunnr
FROM kna1
INTO TABLE it_kna1
WHERE name1 like pattern.
ENDIF.
(Note: While calling above FM from any program, parameter Pattern(customer name combination) has to be passed)
Ex:
Parameters: pattern type string.
CALL FUNCTION 'ZTESTSERCH'
IMPORTING
pattern = pattern.
Thanks,
2009 Dec 16 8:53 AM
Hi ajay,
also, the user will not be able to enter anything within a function module.
You can pass the select-options table body (SO_NAME1[] as import parameter of TYPE TABLE to the function module.
Regards,
Clemens
2009 Dec 16 8:52 AM
hi ajay ,
who told it is not possible pls do this way
Don't worry You can use " Ranges : i_name1 like kn1-name1 . PASTE BELOW CODE IN YOUR FUNCTION MODULE
IT WILL RUN LIKE A BULLET .
Ranges : i_name1 like knA1-name1 .
MOVE 'I' TO i_NAME1-sign.
MOVE 'CP' TO I_NAME1 option.
MOVE I_NAME1 TO I_NAME1-low.
APPEND I_NAME1.
IF NOT i_name1 IS INITIAL.
SELECT kunnr
FROM kna1
INTO TABLE it_kna1
WHERE name1 EQ i_name1.
ENDIF.
rEGARDS
dEEPAK .
2009 Dec 16 8:52 AM
hi ajay ,
who told it is not possible pls do this way
Don't worry You can use " Ranges : i_name1 like kn1-name1 . PASTE BELOW CODE IN YOUR FUNCTION MODULE
IT WILL RUN LIKE A BULLET .
Ranges : i_name1 like knA1-name1 .
MOVE 'I' TO i_NAME1-sign.
MOVE 'CP' TO I_NAME1 option.
MOVE I_NAME1 TO I_NAME1-low.
APPEND I_NAME1.
IF NOT i_name1 IS INITIAL.
SELECT kunnr
FROM kna1
INTO TABLE it_kna1
WHERE name1 EQ i_name1.
ENDIF.
rEGARDS
dEEPAK .
2009 Dec 16 8:54 AM
hi ajay ,
who told it is not possible pls do this way
Don't worry You can use " Ranges : i_name1 like kn1-name1 . PASTE BELOW CODE IN YOUR FUNCTION MODULE
IT WILL RUN LIKE A BULLET .
Ranges : i_name1 like knA1-name1 .
MOVE 'I' TO i_NAME1-sign.
MOVE 'CP' TO I_NAME1 option.
MOVE I_NAME1 TO I_NAME1-low.
APPEND I_NAME1.
IF NOT i_name1 IS INITIAL.
SELECT kunnr
FROM kna1
INTO TABLE it_kna1
WHERE name1 EQ i_name1.
ENDIF.
rEGARDS
dEEPAK .
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |