Application Development and Automation 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: 
Read only

Wild Card Search in ABAP

Former Member
0 Likes
9,199

Hi,

I'm currently working on one of the search criteria to retrieve info from SAP DB. I would require wild card search for the characters and even numbers. Can any one please help me in this regards,

Ravi.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,254

Hi,

for suppose you need wild card search parameter like

data:patient(10) type c.

search : a*

TRANSLATE patient TO UPPER CASE.

replace all occurrences of '*' in patient with '%'.

select a

b

c

into table itab

where A like patient.

Regards,

Ravi

8 REPLIES 8
Read only

jaideepsharma
Active Contributor
0 Likes
4,254

Hi,

Can you please specify the query for which you want to use wild card characters ? Normally we use '%' sign for wild cards n ABAP.

KR Jaideep,

Edited by: Jaideep Sharma on Aug 18, 2009 4:20 PM

Read only

Former Member
0 Likes
4,254

Hi,

To perform a wild card search, use the characters + and *.

+ will match any single character, and * will match any string of characters.

However, * can only be used as a wildcard at the beginning or end of a string.

Regards,

Shamma

Read only

rainer_hbenthal
Active Contributor
0 Likes
4,254

If you want to have a wildcard in a where condition you only have the percentage sign, which will match by any character. So searching for L% will find all records starting with L.

Read only

Former Member
0 Likes
4,255

Hi,

for suppose you need wild card search parameter like

data:patient(10) type c.

search : a*

TRANSLATE patient TO UPPER CASE.

replace all occurrences of '*' in patient with '%'.

select a

b

c

into table itab

where A like patient.

Regards,

Ravi

Read only

Former Member
0 Likes
4,254

Hi,

With your queries, I think its possible to use just the wild card '%'.

Say N%, then it retrieves data starting with N

%N% retrieves data which has N anywhere in between

%N retrieves data ending with N.

Read only

0 Likes
4,254

Hi Ravi,

let us assume is_dsearch is structure consiting of required input fields,like fname,mname,dob,gender......

declare one variable for storing the dynaminc query based on inputs.

in my case it is lv_str type string.

IF NOT is_dsearch-fname IS INITIAL.

IF NOT lv_str IS INITIAL.

CONCATENATE lv_str 'AND' INTO lv_str SEPARATED BY space.

ENDIF.

TRANSLATE is_dsearch-fname TO UPPER CASE.

REPLACE ALL OCCURRENCES OF '*' IN is_dsearch-fname WITH '%'.

CONCATENATE lv_str 'name2 like IS_DSEARCH-fname' INTO lv_str SEPARATED BY space

ENDIF.

IF NOT is_dsearch-mname IS INITIAL. "if middle name is given

IF NOT lv_str IS INITIAL.

CONCATENATE lv_str 'AND' INTO lv_str SEPARATED BY space.

ENDIF.

TRANSLATE is_dsearch-mname TO UPPER CASE.

  • CONCATENATE is_dsearch-mname '%' INTO is_dsearch-mname. "for whild card search

REPLACE ALL OCCURRENCES OF '*' IN is_dsearch-mname WITH '%'.

CONCATENATE lv_str 'MID_NAME2 like IS_DSEARCH-mname' INTO lv_str SEPARATED BY space

ENDIF.

IF NOT is_dsearch-dob IS INITIAL. "if date of birth is given

IF NOT lv_str IS INITIAL.

CONCATENATE lv_str 'AND' INTO lv_str SEPARATED BY space.

ENDIF.

CONCATENATE lv_str 'date_of_birth eq IS_DSEARCH-dob' INTO lv_str SEPARATED BY space. "search based on date of birth

ENDIF.

like wise we need to write the code for preparing dynamic query for the rest fields too...

select x,y,z,k,l from ABC into table itab where ( lv_str).

Regards,

Ravi

Read only

0 Likes
4,254

Hi,

          

    if i am working in Standard Field Matnr i am getting problem to provide Wildcard search by using * and ?........

* is automatically getting its sap already providing

? i dont have any idea to start this one

can any one help me this issue.

Read only

Former Member
0 Likes
4,254

Hi Ravi,

To perform a wild card search, use the characters + and *.

+ will match any single character, and * will match any string of characters.

However, * can only be used as a wildcard at the beginning or end of a string.

With your queries, I think its possible to use just the wild card '%'.

Say N%, then it retrieves data starting with N.

%N% retrieves data which has N anywhere in between

%N retrieves data ending with N.

Regards,

Raj.