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 BKPF based on time

Former Member
0 Likes
1,379

Hi,

I need to select from BKPF from 7am of the entry date on selection screen(p_cpudt) to 7am of the following day. I'm using the code below; select both days and then two delete statements but is there anyway of making it more efficient and doing it in one select? Because the select spans two days i cant just say time greater than 7am one day and less than 7am the next?

DATA: l_cpudt1 TYPE cpudt.

l_cpudt1 = p_cpudt + 1.

SELECT * INTO TABLE lt_bkpf

FROM bkpf

WHERE bukrs IN s_bukrs

AND blart IN s_blart

AND cpudt GE p_cpudt

AND cpudt LE l_cpudt1.

DELETE lt_bkpf

WHERE cpudt = l_cpudt1

AND cputm GT '07:00:00'.

DELETE lt_bkpf

WHERE cpudt = p_cpudt

AND cputm LT '07:00:00'.

1 ACCEPTED SOLUTION
Read only

JozsefSzikszai
Active Contributor
0 Likes
1,053

you can combine both conditions:

...
AND ( cpudt EQ p_cpudt AND cputm GE '070000' ) OR
( cpudt EQ l_cpudt1 AND cputm LE '065959' ).

Hi,

I need to select from BKPF from 7am of the entry date on selection screen(p_cpudt) to 7am of the following day. I'm using the code below; select both days and then two delete statements but is there anyway of making it more efficient and doing it in one select? Because the select spans two days i cant just say time greater than 7am one day and less than 7am the next?

DATA: l_cpudt1 TYPE cpudt.

l_cpudt1 = p_cpudt + 1.

SELECT * INTO TABLE lt_bkpf

FROM bkpf

WHERE bukrs IN s_bukrs

AND blart IN s_blart

AND cpudt GE p_cpudt

AND cpudt LE l_cpudt1.

DELETE lt_bkpf

WHERE cpudt = l_cpudt1

AND cputm GT '07:00:00'.

DELETE lt_bkpf

WHERE cpudt = p_cpudt

AND cputm LT '07:00:00'.

4 REPLIES 4
Read only

JozsefSzikszai
Active Contributor
0 Likes
1,054

you can combine both conditions:

...
AND ( cpudt EQ p_cpudt AND cputm GE '070000' ) OR
( cpudt EQ l_cpudt1 AND cputm LE '065959' ).

Read only

0 Likes
1,053

Hi Eric,

That worked thanks....i had tried that before but i was entering time as '07:00:00' insted of '070000' so that probably caused the problem.

Read only

Former Member
0 Likes
1,053

Hi,

Try to use ranges.

1. append the range for date with the yesterday's date in the range low field and todays date in the range's high field.

2. For time append the time in a range as 07:00:00 and give the options as 'GE'

Now you will have all the documents created from 7 am yesterday and documents created today.

The above can be done i one select statemet.

Here you will have to add one additional delete just to delete the documents that were created today after 7 am.

regards,

Advait

regards,

Advait

Read only

Former Member
0 Likes
1,053

Hi Dave,

Try with the below statement.

SELECT * INTO TABLE lt_bkpf

FROM bkpf

WHERE bukrs IN s_bukrs

AND blart IN s_blart

AND ( ( cpudt EQ p_cpudt AND erzet GT u2018070000u2019 )

OR ( erdat EQ sy-datum AND erzet LE '065959') ).

This select statement will solve your problem.

Regards,

Phani.