08-08-2007 8:21 AM
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
08-08-2007 9:42 AM
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>
08-08-2007 9:34 AM
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
08-08-2007 9:39 AM
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
08-08-2007 9:42 AM
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>
08-08-2007 9:52 AM
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
08-08-2007 1:01 PM
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
08-09-2007 8:18 AM
initial wal an explanation to line,not very good maybe but it wasn't suggested CODE.
08-09-2007 8:35 AM
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
08-09-2007 8:39 AM
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