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

error in select statement

Former Member
0 Likes
1,246

Hi frnds,

i am unable to write select statement given i need to check with the first 6 characters of CHARG field.

SELECT MATNR

WERKS

LGORT

CHARG

FROM MCHB

INTO TABLE IT_MCHB

FOR ALL ENTRIES IN IT_MARA

WHERE MATNR = IT_MARA-MATNR

AND WERKS = WERKS

AND LGORT = LGORT

AND CHARG+0(6) <= DATE_FRM

AND CHARG+0(6)>= DATE_TO.

above hilighted code giving me error.

I am getting error as field charg+0(6) is unknow.

regards,

sanjay

Edited by: sanjay jaju on Nov 12, 2008 12:32 PM

12 REPLIES 12
Read only

Former Member
0 Likes
1,203

Hi,

Tell me the error what u r getting

Kalp...

Read only

prasanth_kasturi
Active Contributor
0 Likes
1,203

hi,

or else pass that into a variable and use it for comparision

var = CHARG+0(6).

and use Var for comparision

regards

Prasanth

Read only

Former Member
0 Likes
1,203

Hi ,

It would definetly give an error ... the select query is looking for CHARG+0(6) in the table

which doesnt exist ...

u can get the validation done on the charg in later stages too if feasible

Regards

Renu

Read only

Former Member
0 Likes
1,203

How can take that with a variable.

how to compare we need to check it from the database table.

Read only

0 Likes
1,203

hi,

Sorry for the previous reply,

in where condition you must give a field in the table but CHARG+0(6) is not a field

You must bring all the data related to an internal table

then loop through the internal table check the requied condition and delete the unnecessary records

regards

Prasanth

Edited by: Prasanth Kasturi on Nov 12, 2008 12:41 PM

Read only

Former Member
0 Likes
1,203

Hi,

In Select query dont check that condition..After selection you can delete the internal table

delete lt_mchb where charg+0(6) <= sy-datum.

Regards,

Kalp..

Read only

Former Member
0 Likes
1,203

Hi,

It will definitely give error as it is checking for field CHARG+0(6) in database table MCHB that is not there. Select all the entries in IT_MCHB table:

SELECT MATNR
WERKS
LGORT
CHARG
FROM MCHB
INTO TABLE IT_MCHB
FOR ALL ENTRIES IN IT_MARA
WHERE MATNR = IT_MARA-MATNR
AND WERKS = WERKS
AND LGORT = LGORT.

Then loop into the entries and check the condition:

LOOP AT IT_MCHB INTO WA_MCHB.
    VAR1 = WA_MCHB-CHARG+0(6).                       "Declare variable of type char  (6 chars)
    IF VAR1<= DATE_FRM AND VAR1 >= DATE_TO. 
*Do Something
    ELSE.
* Delete the record from internal table
    ENDIF. 
ENDLOOP.

Regards,

Saba

Read only

i048168
Product and Topic Expert
Product and Topic Expert
0 Likes
1,203

Hi,

Please check this one out.

concatenate DATE_FRM '%' into DATE_FRM.

concatenate DATE_TO '%' into DATE_TO.

SELECT MATNR

WERKS

LGORT

CHARG

FROM MCHB

INTO TABLE IT_MCHB

FOR ALL ENTRIES IN IT_MARA

WHERE MATNR = IT_MARA-MATNR

AND WERKS = WERKS

AND LGORT = LGORT

AND CHARG <= DATE_FRM

AND CHARG >= DATE_TO.

Regards,

Vadi

Sorry, this won't workout. I forget the fact that the wild card characters will be applicable only to LIKE in the WHERE clause.

Edited by: Vadivelan B on Nov 12, 2008 1:10 PM

Read only

ThomasZloch
Active Contributor
0 Likes
1,203

What is the logic for the MCHB-CHARG values? So the first six characters seem to be a date, what about the other four? Assuming they contain only letters A to Z, you could fill DATE_FRM with e.g. "080101AAAA" and DATE_TO with "081112ZZZZ" and select WHERE CHARG BETWEEN DATE_FRM AND DATE_TO.

Or similar, depending on the actual logic in CHARG.

Thomas

Read only

Former Member
0 Likes
1,203

Hi

the problem could be that you are comparing the same CHARG+0(6) for two AND conditions which is not possible.

please remove one condition or put a or statemnet between them

Thanks

Nitin Sachdeva

Read only

Former Member
0 Likes
1,203

Hi

the problem could be that you are comparing the same CHARG+0(6) for two AND conditions which is not possible.

please remove one condition or put a or statemnet between them

Thanks

Nitin Sachdeva

Read only

Former Member
0 Likes
1,203

thanks