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

Select statement

Former Member
0 Likes
1,081

Hi,

I am having a requirement where there is a selection screen in a report with material number.The select statement should fetch the material details from MARA table even if user enters the partial material number.

for example there is a material called G1240-094-1 in the database.

if suppose the user enters only a partial material number say

G1240-094* and eexcutes the program, the program should fetch the details of material G1240-094-1.

How can we write a select statement for this type of requirement?

Thanks,

Kumar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,060

select * from mara where matnr like val1.

endselect.

It might be that you need to replace the * with %.

Another option is:

select * from mara where matnr cp val1.

endselect.

In the last case it might be neccesary to remove the wildcard.

See the SAP help and look at the part about logical conditions.

Regards,

Arthur Parisius

9 REPLIES 9
Read only

Former Member
0 Likes
1,060

Hi

If you have select-option for material code it's very easy:

TABLES MARA.

SELECT-OPTIONS: SO_MATNR FOR MARA-MATNR.

DATA T_MARA TYPE STANDARD TABLE OF MARA.

START-OF-SELECTION.

  SELECT * FROM MARA INTO TABLE T_MARA WHERE MATNR IN SO_MATNR.

Max

Read only

Former Member
0 Likes
1,060

hi check this..

tables:mara .

data:v_matnr like mara-matnr.

selection-screen : s_matnr for mara-matnr.

start-of-selection.

select matnr

from mara

into v_matnr

where matnr in s_matnr.

write:/ v_matnr .

Read only

0 Likes
1,060

Hi Venkat,

You have not understood my requirement.

In the selection screen, suppose the user enters only partial material number like G123456-9 and executes the report. The user doesn't knows the correct material so he enters material number partially.

The actual material number is G123456-9-11.

parameters: p_matnr like mara-matnr.

data : begin of itab occurs 100,

matnr like mara-matnr,

end of itab.

select matnr from mara into table itab

where matnr = p_matnr.

if sy-subrc = 0.

endif.

How to code for this type of requirement?

IS there any wild card search possible in select statement?

Read only

0 Likes
1,060

Hi

If you have a parameter, u can use a range instead of select-option:

TABLES MARA.

SELECT-OPTIONS SO_MATNR FOR MARA-MATNR.

PARAMETERS: P_MATNR LIKE MARA-MATNR.

DATA: T_MARA TYPE STANDARD TABLE OF MARA.

RANGES: R_MATNR FOR MARA-MATNR.

DATA: V_LEN TYPE I,
      V_POS TYPE I,
      OK    TYPE C.

START-OF-SELECTION.

  V_LEN = STRLEN( P_MATNR ).

  DO V_LEN TIMES.
    IF P_MATNR+V_POS(1) = '*'.
      OK = 'X'.
      EXIT.
    ENDIF.
    V_POS = V_POS + 1.
  ENDDO.

  IF OK IS INITIAL.
    R_MATNR(3) = 'IEQ'.
    R_MATNR-LOW = P_MATNR.
  ELSE.
    R_MATNR(3) = 'ICP'.
    R_MATNR-LOW = P_MATNR.
  ENDIF.
  APPEND R_MATNR.

  SELECT * FROM MARA INTO TABLE T_MARA WHERE MATNR IN R_MATNR.

Read only

Former Member
0 Likes
1,061

select * from mara where matnr like val1.

endselect.

It might be that you need to replace the * with %.

Another option is:

select * from mara where matnr cp val1.

endselect.

In the last case it might be neccesary to remove the wildcard.

See the SAP help and look at the part about logical conditions.

Regards,

Arthur Parisius

Read only

Former Member
0 Likes
1,060

Hi,

This will work.

TABLES:mara .
PARAMETERS p_matnr TYPE mara-matnr.
DATA: 
  t_mara TYPE STANDARD TABLE OF mara,
  w_mara LIKE LINE OF t_mara.

CONCATENATE  p_matnr '%' INTO p_matnr.

SELECT * 
  FROM mara 
  INTO TABLE t_mara 
 WHERE matnr LIKE p_matnr.

LOOP AT t_mara INTO w_mara.
  WRITE:/
  w_mara-matnr,
  w_mara-ernam.
ENDLOOP.

Regards

Adil

Read only

0 Likes
1,060

Thank You Syed. It works..

Read only

0 Likes
1,060

Hi ,

Have you tried Max bianchi's or Venkat's code?

No need for wild cards logic if you use a select-option instead of a parameter.

The system will take care of the whole thing.

Regards,

Ravi

Read only

Former Member
0 Likes
1,060

hi check this...

tables:mara.

select-options: s_matnr for mara-matnr.

data : begin of itab occurs 100,

matnr like mara-matnr,

end of itab.

select matnr

from mara

into table itab

where matnr like 'G123456-%'.

if sy-subrc = 0.

loop at itab.

write:/ itab-matnr.

endloop.

endif.