Application Development 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: 

Q: LIKE or = in WHERE and READ...

Former Member
0 Kudos

Hi,

I have a problem with my code below. The problem is either in my SELECT-statement or in my READ-statement. I am having problems debugging so I cannot narrow it down. I have the following code:

SELECT DISTINCT MAT_SALES

FROM /BI0/PMAT_SALES

INTO TABLE i_mat_sales

WHERE /BIC/ZACCASGRP IS NULL

OR /BIC/ZACCASGRP LIKE ' '

OR /BIC/ZACCASGRP LIKE 'A1'

OR /BIC/ZACCASGRP LIKE 'C3'.

LOOP AT SOURCE_PACKAGE into source_wa.

T_INDEX = SY-TABIX.

READ TABLE I_MAT_SALES WITH KEY MSALE =

source_wa-MAT_SALES TRANSPORTING NO FIELDS.

IF SY-SUBRC NE 0.

DELETE SOURCE_PACKAGE INDEX T_INDEX.

ENDIF.

The MAT_SALES field and the ZACCASGRP fields are both of type CHAR, and I have changed my where to LIKE instead of = but for the READ is not possible to use LIKE.

Does anybody have any idea about what can be wrong in this code?

Thank you in advance,

Mikael

1 ACCEPTED SOLUTION

varma_narayana
Active Contributor
0 Kudos

Hi..

1. We cannot use LIKE in the READ TABLE statement.

2. In the select statement the use of LIKE is possible to get the values based on a pattern.

Code:

where matnr LIKE 'M1%' means all Matnr starts with M1

where matnr LIKE '%M1%' means all Matnr that contains M1

You have to use % for any combination of characters

and _ for single character in the LIKE operator.

<b>Check the code.</b>

SELECT DISTINCT MAT_SALES

FROM /BI0/PMAT_SALES

INTO TABLE i_mat_sales

WHERE <b>/BIC/ZACCASGRP IS INITIAL</b>

OR <b>/BIC/ZACCASGRP LIKE '%' </b>

OR<b> /BIC/ZACCASGRP LIKE 'A1%' </b> "Starts with A1

OR<b> /BIC/ZACCASGRP LIKE 'C3%'.</b>

LOOP AT SOURCE_PACKAGE into source_wa.

T_INDEX = SY-TABIX.

READ TABLE I_MAT_SALES WITH KEY MSALE =

source_wa-MAT_SALES TRANSPORTING NO FIELDS.

IF SY-SUBRC NE 0.

DELETE SOURCE_PACKAGE INDEX T_INDEX.

ENDIF.

<b>Reward if Helpful</b>

8 REPLIES 8

Former Member
0 Kudos

Hi Mikeal,

Im not clear about your problem. Could you please eloborate so that i can check if i can help you out if i can.

Regards,

Yogesh

Former Member
0 Kudos

Hi,

My question basically is: why does my code not work? It must be related either to the select statement (not all values are selected) or to the READ statement (comparing fails thus deleting the data package), but I cannot find the error.

Best regards,

Mikael

varma_narayana
Active Contributor
0 Kudos

Hi..

1. We cannot use LIKE in the READ TABLE statement.

2. In the select statement the use of LIKE is possible to get the values based on a pattern.

Code:

where matnr LIKE 'M1%' means all Matnr starts with M1

where matnr LIKE '%M1%' means all Matnr that contains M1

You have to use % for any combination of characters

and _ for single character in the LIKE operator.

<b>Check the code.</b>

SELECT DISTINCT MAT_SALES

FROM /BI0/PMAT_SALES

INTO TABLE i_mat_sales

WHERE <b>/BIC/ZACCASGRP IS INITIAL</b>

OR <b>/BIC/ZACCASGRP LIKE '%' </b>

OR<b> /BIC/ZACCASGRP LIKE 'A1%' </b> "Starts with A1

OR<b> /BIC/ZACCASGRP LIKE 'C3%'.</b>

LOOP AT SOURCE_PACKAGE into source_wa.

T_INDEX = SY-TABIX.

READ TABLE I_MAT_SALES WITH KEY MSALE =

source_wa-MAT_SALES TRANSPORTING NO FIELDS.

IF SY-SUBRC NE 0.

DELETE SOURCE_PACKAGE INDEX T_INDEX.

ENDIF.

<b>Reward if Helpful</b>

Former Member
0 Kudos

Hi

First of all you can instead of

OR /BIC/ZACCASGRP LIKE ' '

OR /BIC/ZACCASGRP LIKE 'A1'

OR /BIC/ZACCASGRP LIKE 'C3'.

you can write

OR /BIC/ZACCASGRP IN (' ','A1','C3').

Second.

/BIC/ZACCASGRP IS NULL you ask if it initial

/BIC/ZACCASGRP LIKE ' ' you ask if it empty

you need only one of them

and...

i dont think that in checking you need

TRANSPORTING NO FIELDS

plus

you can check if MSALE and

source_wa-MAT_SALES have same type...

also

LOOP AT I_MAT_SALES into wa_mat_sales.

DELETE SOURCE_PACKAGE where MAT_SALES = WA_MAT_SALES-MSALE.

ENDLOOP.

instead of your lines

LOOP AT SOURCE_PACKAGE into source_wa.

T_INDEX = SY-TABIX.

READ TABLE I_MAT_SALES WITH KEY MSALE =

source_wa-MAT_SALES TRANSPORTING NO FIELDS.

IF SY-SUBRC NE 0.

DELETE SOURCE_PACKAGE INDEX T_INDEX.

ENDIF.

Regards

Yossi

Message was edited by:

Yossi Rozenberg

Message was edited by:

Yossi Rozenberg

Former Member
0 Kudos

Hi,

Thanks for your replies. The "IS INITIAL" is not possible to write in a WHERE-statement, it gives ABAP syntax error which says that IS can only be followed by NULL or NOT NULL. MSALE and MAT_SALES are of the same data type and I have tried using wildcards % around my text, and also add conditions to accept capital/non-capital letters, for instance:

OR /BIC/ZACCASGRP LIKE '%a1%'

OR /BIC/ZACCASGRP LIKE '%A1%' etc...

But still it does not work.

Best regards,

Mikael

0 Kudos

initial wal an explanation to line,not very good maybe but it wasn't suggested CODE.

Former Member
0 Kudos

Hi,

This has been solved by a restructure of the entire routine, I still do not know what was the problem with the code in this thread.

BR Mikael

former_member194613
Active Contributor
0 Kudos

you start explaining what you want to select

SELECT DISTINCT MAT_SALES

FROM /BI0/PMAT_SALES

INTO TABLE i_mat_sales

WHERE /BIC/ZACCASGRP IS NULL

OR /BIC/ZACCASGRP LIKE ' '

OR /BIC/ZACCASGRP LIKE 'A1'

OR /BIC/ZACCASGRP LIKE 'C3'.

like 'A1 is the same = 'A1' you need the wildcards, I guess you want like '%A1%'.

Try this one first, and check whether the select works. Check database whether

records are there.

The initial one should also work, /BIC/ZACCASGRP eq ' '.

And forget the null, null values exit only on the database (when no entry not even an initial one was ever made) but not in ABAP.

This should work, but you should use a hashed table for i_MAT_SALES and

read with table key

LOOP AT SOURCE_PACKAGE into source_wa.

T_INDEX = SY-TABIX.

READ TABLE I_MAT_SALES WITH KEY MSALE =

source_wa-MAT_SALES TRANSPORTING NO FIELDS.

IF SY-SUBRC NE 0.

DELETE SOURCE_PACKAGE INDEX T_INDEX.

ENDIF.

Siegfried