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

CHECK condition in SELECT query.

Former Member
0 Likes
3,055

Need to use the check condition to check only the second digit .

Eg.   SELECT MATNR

           INTO WL_MATNR

           FROM MARA UP TO 1 ROWS

           WHERE MATNR =  PI_MATNR              

             AND   MTART  IN PI_MTART(Range Table but value can also be assigned as an constant)               

    ENDSELECT.

Here MTART should check only the second character of PI_MTART.

1 ACCEPTED SOLUTION
Read only

laurent_fournier2
Contributor
0 Likes
2,684

Hi,

I'm not very sure if I understand your question correctly but let me propose something.

You could use the "+" character.

In range PI_MTART, if you enter "+1++" it will select only materials that have "1" in the second digit of the material type. "+" stands for any one character .

To be more clear : "*1*" will select all the materials that have "1" in the type ( 0101,0001,0010 etc).

"+1++" will select all the materials that have "1" in the second place of the material type ( 0100,0110,0199 etc).

Regards.

11 REPLIES 11
Read only

alex_campbell
Contributor
0 Likes
2,684

You can use the LIKE keyword in the where condition, and use wildcards '_' and '%'. The F1 help for the LIKE keyword will give you more information. For example, if you only want to select records where the second letter of the material type is 'R':

  SELECT matnr INTO TABLE gi_mara
    FROM mara
   WHERE
mtart LIKE '_R%'.

Read only

0 Likes
2,684

Alex my Exact requirement is for example if mtart in table contains values like  01,02,03 and in our internal table ie PI_MTART  there are values like 11,12,13 .

Here it should check only the second value(Not a constant pattern of values) and so SY-SUBRC should be 0 in the above case when checked in where condition.

Read only

0 Likes
2,684

Hi 

If you loop through the range and then do the select for each individually you can specify the value of the search. Not efficient program but it will get the job done.

loop at yourrange.

SELECT MATNR  INTO yourwork_area FROM MARA UP TO 1 ROWS

           WHERE MATNR =  PI_MATNR              

             AND   MTART = PI_MTART+5 (2) .

             APPEND work_area TO youritab.            

    ENDSELECT.

Regards,

sifter

Read only

Former Member
0 Likes
2,684

Hi ,

first create Work area type PI_MTART.(i.e fs_mtart1, fs_mtart2 ) and range table (i.e PI_mtart)

loop at PI_MTART into  fs_mtart.

fs_mtart2-field = fs_mtart1-field+1(1).( if field length is 2 ).

append to fs_mtart2 to pi_mtart1.

endloop.

after that use the  PI_MTART1 instead of PI_MTART.

Regards.

Venkat.

Read only

Former Member
0 Likes
2,684

@ Jasd & Thandalam : Appreciate your efforts. But here the main key is that the

Where mtart  in PI_mtart  here mtart will contain values from table mara so we should check the

second digit of mtart ie (MARA-MTART for eg 01,02,03) we should consider *1,*2,*3 from mtart and should check with our PI_MTART second digit.

Read only

laurent_fournier2
Contributor
0 Likes
2,685

Hi,

I'm not very sure if I understand your question correctly but let me propose something.

You could use the "+" character.

In range PI_MTART, if you enter "+1++" it will select only materials that have "1" in the second digit of the material type. "+" stands for any one character .

To be more clear : "*1*" will select all the materials that have "1" in the type ( 0101,0001,0010 etc).

"+1++" will select all the materials that have "1" in the second place of the material type ( 0100,0110,0199 etc).

Regards.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,684

Just to extend what Former Member has mentioned your RANGE table should look like:

SIGNOPTIONLOWHIGH
ICP+1*
ICP+2*

This will look for Material types having '1' and '2' in the second position

BR,

Suhas

PS: If you read the online documentation you could have found the answer yourself

Read only

0 Likes
2,684

Hi Laurent,

              I value your effort. The actual requirement is " if you enter "+1++"  " here the second digit can be have four values.

For eg.  01,02,03,04  but what you proposed will only consider 01 .

Where mtart  in PI_mtar

eg. In mara table if mtart contains 01,02,03,04  and in our case we are taking four constant values for PI_mtart range table (11,22,33,44) so the output should be that in SELECT query it should  consider only the second digit of mtart(MARA table) & PI_mtart range table.

Read only

0 Likes
2,684

So create 4 lines in the range table :

+1++

+2++

+3++

+4++

All with sign I and option CP.

Am I understanding your problem correctly ?

Regards.

Read only

0 Likes
2,684

@ Suhas : .Thanks for your effort.

Read only

0 Likes
2,684

@ Laurent : .Thanks for your effort.