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

ABAP select statement !!

Former Member
0 Likes
1,470

Hi All,

I want to write a query on SOOD table like:

SELECT OBJTP OBJYR OBJNO OBJDES OWNNAM FROM SOOD INTO TABLE IT_SOOD

WHERE OBJDES LIKE 'String%' AND

( SDDAT BETWEEN LV_LASTRUN AND SY-DATUM ) AND

( SDTIM BETWEEN LV_LASTTIM AND SY-UZEIT ).

but this is not returning me data between the last run date/ last run time and current date/ time.

Can anybody suggest how to modify the above query in order to fetch correct data.

Thanks in Advance !!

Vivek

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,332

Hi Vivek Kulkarni,

Using Range is better option..

Also please check how you declared the fileds as mentioned below or not..

LV_LASTRUN type sy-datum.
LV_LASTTIM type SY-UZEIT.

Better to write code for Range and populate it and then pass it in select where condition using IN.

Searcg SCN for more help on how to use RANGE

Hope it will solve your problem..

Thanks & Regards

ilesh 24x7

ilesh Nandaniya

10 REPLIES 10
Read only

Former Member
0 Likes
1,332

Hi,

Try this

SELECT OBJTP OBJYR OBJNO OBJDES OWNNAM FROM SOOD INTO TABLE IT_SOOD
WHERE OBJDES LIKE 'String%' AND
( SDDAT BETWEEN LV_LASTRUN AND SY-DATUM ) *OR*
( SDTIM BETWEEN LV_LASTTIM AND SY-UZEIT ).

Regards,

Nandha

Read only

Former Member
0 Likes
1,332

You can pass the last run date , Current date into a range and last run time , current time into another range

and pass this in the where conditions ...

SELECT OBJTP OBJYR OBJNO OBJDES OWNNAM FROM SOOD INTO TABLE IT_SOOD

WHERE OBJDES LIKE 'String%' AND

SDDAT in r_sddat AND

SDTIM in r_UZEIT.

or ... U can write the coding as ...

SELECT OBJTP OBJYR OBJNO OBJDES OWNNAM FROM SOOD INTO TABLE IT_SOOD

WHERE OBJDES LIKE 'String%' AND

SDDAT >= LV_LASTRUN AND

SDDAT <= SY-DATUM AND

SDTIM >= LV_LASTTIM AND

SDTIM <= SY-UZEIT .

Read only

Former Member
0 Likes
1,333

Hi Vivek Kulkarni,

Using Range is better option..

Also please check how you declared the fileds as mentioned below or not..

LV_LASTRUN type sy-datum.
LV_LASTTIM type SY-UZEIT.

Better to write code for Range and populate it and then pass it in select where condition using IN.

Searcg SCN for more help on how to use RANGE

Hope it will solve your problem..

Thanks & Regards

ilesh 24x7

ilesh Nandaniya

Read only

0 Likes
1,332

are you sure that, the value 'String%' is of this pattern? i mean the S being upper case and others being in lower case?

because the domain for this field is LOWER CASE ticked, it stores the exact pattern

and you can also try creating a range for the date and time.

data: lv_datum type range of sy-datum,
     lv_uzeit type srange of sy-uzeit.

Read only

0 Likes
1,332

Hi All,

Thanks for replies.

problem solved using the comparison operators.

Thanks a Lot !!

Read only

0 Likes
1,332

Hi,

Can you post the final select query you used so that it will be helpful for others who face similar problem?

Regards,

Vikranth

Read only

Former Member
0 Likes
1,332

Hi,

Try this


SELECT OBJTP OBJYR OBJNO OBJDES OWNNAM FROM SOOD INTO TABLE IT_SOOD
WHERE OBJDES LIKE 'String%' AND
( SDDAT >= LV_LASTRUN AND SDTIM >= LV_LASTTIM )
AND
( SDDAT <= SY-DATUM AND SDTIM <= SY-UZEIT ).

Hope this helps.

BR,

Advait

Read only

christine_evans
Active Contributor
0 Likes
1,332

>

> Hi All,

>

> I want to write a query on SOOD table like:

>

> SELECT OBJTP OBJYR OBJNO OBJDES OWNNAM FROM SOOD INTO TABLE IT_SOOD

> WHERE OBJDES LIKE 'String%' AND

> ( SDDAT BETWEEN LV_LASTRUN AND SY-DATUM ) AND

> ( SDTIM BETWEEN LV_LASTTIM AND SY-UZEIT ).

>

> but this is not returning me data between the last run date/ last run time and current date/ time.

>

> Can anybody suggest how to modify the above query in order to fetch correct data.

>

> Thanks in Advance !!

> Vivek

If the last run date was 01.09.2009 and the last run time was 11:00, this code will pick up data for all dates from 01.09.2009 but only if the time value is > 11:00; so if there was a run at 09:00 on 03.09.2009 you won't pick up that record - and I'm assuming that you would want to pick up that record.

I think you should only be applying the time check to records where the date = LV_LASTRUN and for later records you should just be checking the date. Something like:

WHERE (      (            sddat = lv_lastrun   
                            AND  sdtim > lv_lasttim   ) 
                 OR  (            sddat > lv_lastrun )
                  )

Read only

sreeramkumar_madisetty
Active Contributor
0 Likes
1,332

Hi

Share your solution with others.

Regards,

Sreeram

Read only

0 Likes
1,332

Hi All,

I have revised the query using comparison operators as follows:

SELECT OBJTP OBJYR OBJNO OBJDES OWNNAM FROM SOOD INTO TABLE IT_SOOD

WHERE SDTIM >= LV_LASTTIM and SDDAT >= LV_LASTRUN and

OBJDES LIKE 'XXXXXX Purchasing Document%'.

So, now it is giving me desired output as: Selecting OBJTP OBJYR OBJNO OBJDES OWNNAM from SOOD table into internal table IT_SOOD where the time is greater than or equal to last run time and the date is greater than or equal to last run date and the string (OBJDES) like 'XXXXXX Purchasing Document%'.

Thanks for you support !!

Vivek