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

IF condition

Former Member
0 Likes
1,160

hello,

we have over 50k materials with starting of "K" and "M".

now i want to put some condition with all materials which is starting with "k".

so when i put this condition with if mara-matnr = 'K*'.

it gives the error.

how can i put this condition with if condition.

regards amit.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,026

Hi Amit,

you can use this condition in the select query but not in the IF condition...

Proceed like this: -

select all the materials starts from K ...

SELECT ...

FROM

INTO ITAB

WHERE matnr LIKE 'k%'.

This will select all materials starts with k inyour internal table ITAB.

Now process your logic on itab...for k materials.

Simillary do the same for M Materials....

Reward points for helpful answers.

Regards,

Hari krsihna

6 REPLIES 6
Read only

Former Member
0 Likes
1,026

if mara-matnr like 'k%'.

Read only

0 Likes
1,026

well,

if our material ends with "K" or "O"

then how can i put it into if condition like that....

if mara-matnr = '%K' will it works..

Read only

Former Member
0 Likes
1,026

Hi,

which error?

regards

Nicole

Read only

Former Member
0 Likes
1,027

Hi Amit,

you can use this condition in the select query but not in the IF condition...

Proceed like this: -

select all the materials starts from K ...

SELECT ...

FROM

INTO ITAB

WHERE matnr LIKE 'k%'.

This will select all materials starts with k inyour internal table ITAB.

Now process your logic on itab...for k materials.

Simillary do the same for M Materials....

Reward points for helpful answers.

Regards,

Hari krsihna

Read only

Former Member
0 Likes
1,026

retrieve all the materials into one internal table...

after that loop on that internal table and check the condition as per following.

here is a sample report...

REPORT ZNA_TEMP.

data: it_mara type table of mara,

wa_mara like line of it_mara.

data: a type c.

select * from mara into table it_mara up to 100 rows.

loop at it_mara into wa_mara.

a = wa_mara-matnr(+1). " this checks the first character of the variable.

if wa_mara-matnr(1) <> 'M' or wa_mara-matnr(1) <> 'K'.

delete it_mara index sy-tabix.

endif.

endloop.

Read only

Former Member
0 Likes
1,026

hi,

select the materials starting with K using the statement...

<b>select * from mara into table itab where matnr like'K%'.</b>

u can use the internal table itab for futher operation..

hope it helps..

Regards,

Viji