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

Asterisk logic

Former Member
0 Likes
3,088

Hi,

I am having a parameter p_MATNR. This field should also have asterisk logic(). for example if i enter material number '48hg' it should retrieve all the material numbers that match that pattern.

Can anybody provide me the logic for the above one.

Thanks...

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,341

Hi anil,

1. 1 -


> will give all MATNR containing 1 anywhere in the code.

2. just copy paste.

3.

report abc.

*----


DATA : MARA LIKE MARA OCCURS 0 WITH HEADER LINE.

DATA : MYMATNR LIKE MARA-MATNR.

PARAMETERS : S_MATNR LIKE MARA-MATNR.

*----


<b>MYMATNR = S_MATNR.

REPLACE ALL OCCURRENCES OF '*' IN MYMATNR WITH '%'.</b>SELECT * FROM MARA

INTO TABLE MARA

WHERE <b>MATNR LIKE MYMATNR.</b>

LOOP AT MARA.

WRITE 😕 MARA-MATNR.

ENDLOOP.

regards,

amit m.

Anil,

that is there in sap as built-in feature.

sujatha.

14 REPLIES 14
Read only

Former Member
0 Likes
2,341
IF p_matnr CA '*'.
ELSE.
CONCATENATE  p_matnr '*' INTO p_matnr.

ENDIF.
SELECT  matnr FROM MARA
              INTO TABEL itab
               WHERE matnr LIKE p_matnr.

Also u can do like this


ranges r_id for mara-matnr.
r_id-low = 'VP*'. (p_matnr)
r_id-sign = 'I'.
r_id-option = 'CP'.
append r_id.

select matnre 
    into table i_table
      from mara
where matnr in r_id.

Read only

sreeramkumar_madisetty
Active Contributor
0 Likes
2,341

Hi

For Parameter we can use Eq,> ,< only.

It cann't be possible your requirement with Parameters.

But it can be achieved with select-options.

Opt for select-option for your requirement.

Regards,

kumar

Read only

Former Member
0 Likes
2,341

Hi,

This can be achieved using RANGES in your code.

RANGES: gr_matnr FOR mara-matnr.

gr_matnr-sign = 'I'.

gr_matnr-option = 'CS'.

gr_matnr-low = p_matnr.

APPEND gr_matnr.

CLEAR: gr_matnr.

Use this in the WHERE clause saying:

WHERE matnr IN gr_matnr.

Please, let me know if further details are required from my side.

Thanks & Regards,

Goutham.

Read only

0 Likes
2,341

Hi,

With out using ranges and select-options can u provide the coding.

i need to do it only with parameters.

Thanks...

Read only

Former Member
0 Likes
2,341

Anil,

that is there in sap as built-in feature.

sujatha.

Read only

Former Member
0 Likes
2,341

if you are using select

select matnr into mara-matnr from mara where matnr like '048%'.

it wil fetch the data whose first 3 digit is 048.

if it is a select-option

then

S_op-low = '048*'.

s_op-sign = 'I'.

s_op-option = 'CP'.

append s_op.

regards

shiba dutta

Read only

Former Member
0 Likes
2,341
translate p_matnr using '*%'.

select matnr from mara into table itab where matnr like p_matnr.
Read only

Former Member
0 Likes
2,341

that meaans your select query should do like that...

just check my previous reply.

here

if p_matnr ca '*'.

concatenate p_matnr '%' into p_matnr.

endif.

select matnr into mara-matnr from mara where matnr like p_matnr.

regards

shiba dutta

Read only

0 Likes
2,341

Hi,

Thank u for ur reply.

Yes my requirement is same.

But it is not working. it is giving no records found.

Thanks..

Read only

0 Likes
2,341

Have u tried my code.

IF p_matnr CA '*'.
ELSE.
CONCATENATE  p_matnr '*' INTO p_matnr.
 
ENDIF.
SELECT  matnr FROM MARA
              INTO TABEL itab
               WHERE matnr LIKE p_matnr.

Read only

0 Likes
2,341

Hi anil,

have u tried my reply

search p_matnr for '*'.
if sy-subrc eq 0
translate p_matnr using '*%'.
endif.
 
select matnr from mara into table itab where matnr like p_matnr.

Read only

Former Member
0 Likes
2,341

Hi,

the code should be as follows :

replace all occurences of '*' in p_matnr with '%'.

then apply the select statement. In SAP, the '' is not determined by SAP if used in ABAP Code. Instead '%' works similar to ''.

Try it.

Please award points if helpful.

Thanks,

Himanshu.

Read only

Former Member
0 Likes
2,341

anil,

DATA: STR1 VALUE '*',

STR2 VALUE '%'.

parameters : p_matnr like mara-matnr.

AT selection-screen.

REPLACE STR1 WITH STR2 INTO p_matnr.

Start-of-selection.

select matnr into mara-matnr from mara where matnr like p_matnr.

Pl.s mark if useful

Read only

Former Member
0 Likes
2,342

Hi anil,

1. 1 -


> will give all MATNR containing 1 anywhere in the code.

2. just copy paste.

3.

report abc.

*----


DATA : MARA LIKE MARA OCCURS 0 WITH HEADER LINE.

DATA : MYMATNR LIKE MARA-MATNR.

PARAMETERS : S_MATNR LIKE MARA-MATNR.

*----


<b>MYMATNR = S_MATNR.

REPLACE ALL OCCURRENCES OF '*' IN MYMATNR WITH '%'.</b>SELECT * FROM MARA

INTO TABLE MARA

WHERE <b>MATNR LIKE MYMATNR.</b>

LOOP AT MARA.

WRITE 😕 MARA-MATNR.

ENDLOOP.

regards,

amit m.