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: 

Retreving Valid sales orders within the date range

Former Member
0 Kudos

Hi All,

I Had a date field in the selection screen which is not a manadatory.

If user enter date i need to retreive the valid sales orders which falls in the date range which is given in the selection screen.

I tried but its not coming correctly.

for eg:

I given range like 14.01.2012 to 31.01.2012...in the selection screen

when I cheked in VBAK table one sale order whose valid from date(ANGDT) is 14.01.2009 and valid todate(BNDDT) is 31.12.2012

                                        Another sale order whose valid from date(ANGDT) is 11.01.2009 and valid todate(BNDDT) is 15.12.2012

so both sale orders should come...

If i given range like 16.01.2012 to 31.01.2012  in the selection screen then only one sale order should come...i.e.

the sale order whose valid from date(ANGDT) is 14.01.2009 and valid todate(BNDDT) is 31.12.2012 should come...

For this what condition i need to give..

Is there any thoughts to acheive this..

Regards

Ram

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
0 Kudos

As I am not sure to understand you, so I give you my two answers related to my two understandings of your request...

- If you want that the whole order validity period is included in  the range :

WHERE VBAK-ANGDT GE RANGE-LOW AND VBAK-BNDDT LE RANGE-HIGH.

- If you want that the validity of the order and of the range overlap

WHERE VBAK-BNDDT GE RANGE-LOW AND VBAK-ANGDT LE RANGE-HIGH.

Regards,

Raymond

16 REPLIES 16

gouravkumar64
Active Contributor
0 Kudos

Hi,

Can u paste selection screen coding and select query coding part of report.

Gourav.

0 Kudos

in this s_date is my selection screen date...      

SELECT  vkbur vkorg vtweg vbeln kunnr angdt bnddt  bstdk spart
          INTO TABLE it_vbak FROM vbak
          WHERE vbeln IN s_vbeln
            AND angdt IN s_date
            AND bnddt IN s_date
            AND auart = 'DEP'
            AND vkorg = 'BEN'
            AND vkbur IN s_vkbur
            AND bstdk IN s_bstdk
            AND kunnr IN s_kunnr.

It is coming only whatever date is matched with the s_date that only..

But i want whatever records falling in between these date (given in s_date) as i mentioned above...

That means..

If given date range(s_date) like 14.01.2009 to 31.01.2009...in the selection screen

when I cheked in VBAK table one sale order whose valid from date(ANGDT) is 14.01.2009 and valid todate(BNDDT) is 31.12.2012

                                        Another sale order whose valid from date(ANGDT) is 11.01.2009 and valid todate(BNDDT) is 15.01.2009

so both sale orders should come...

If i given date range(s_date) like 16.01.2009 to 31.01.2009  in the selection screen then only one sale order should come...i.e.

the sale order whose valid from date(ANGDT) is 14.01.2009 and valid todate(BNDDT) is 31.12.2012 should come...

Regards

Raj

0 Kudos

Hi,

So ram hope  u got the answer from @raymond,

Gourav.

raymond_giuseppi
Active Contributor
0 Kudos

As I am not sure to understand you, so I give you my two answers related to my two understandings of your request...

- If you want that the whole order validity period is included in  the range :

WHERE VBAK-ANGDT GE RANGE-LOW AND VBAK-BNDDT LE RANGE-HIGH.

- If you want that the validity of the order and of the range overlap

WHERE VBAK-BNDDT GE RANGE-LOW AND VBAK-ANGDT LE RANGE-HIGH.

Regards,

Raymond

0 Kudos

Hi Raymond,

its fine...

I want  validity of the order and of the range overlap

If user enter only RANGE-LOW but did not enter high range i.e RANGE-HIGH then how it will be?

Regards

Ram

0 Kudos

Hi,

Hope u know the use of this try like this
IF p_beg IS INITIAL AND p_end IS NOT INITIAL.
     MESSAGE 'Enter the Beginning date' TYPE 'I' DISPLAY LIKE 'E'.
     LEAVE LIST-PROCESSING.
   ENDIF.
   IF p_beg IS NOT INITIAL AND p_end IS INITIAL.
     MESSAGE 'Enter the End date' TYPE 'I' DISPLAY LIKE 'E'.
     LEAVE LIST-PROCESSING.
   ENDIF.

Use it as per your requirement .

Gourav

0 Kudos

Hi,

Also like this

if p_beg gt p_end.
     MESSAGE 'Beginning date should be less than equal to End date' type 'I' DISPLAY LIKE 'E'.
     LEAVE LIST-PROCESSING.
   endif.


0 Kudos

Oops, once again two understandings, when range-high is initial, is the required range

- range-hich = range-low (order valid at the exact date, so like a SELECT-OPTIONS criteria)

- range-high= '99991231' (order valid after date)

Use another hidden field for range-high in the check or where options, fill this field with input range-high value if not initial else with input range-low or '99991231'

Regards,

Raymond

0 Kudos

No i am sking about user can enter only RANGE-LOW and he will not give RANGE-HIGH

And he wants to see the all orders of  valid from date (ANGDT) and valid todate (BNDDT) which fall in the RANGE-LOW date...

Regards

Ram

0 Kudos

Hi,

From low means angdt and  for high use system date(sy-datum) OR table-date in selection screen or

p_end = '99991231'.

and then validate like we are telling u,

Easy try this.

Gourav.

0 Kudos

Hi Raymond..

i wrote like below..

   IF s_bndt-high IS INITIAL.
  s_bndt-high = s_bndt-low.
ENDIF.
SELECT * FROM vbak
  INTO TABLE it_vbak
  WHERE bnddt GE s_bndt-low
    AND angdt LE s_bndt-high.

It's ok as of now...

but if they click on multiple selection button in the selection screen and given different dates under the single values tab...?

0 Kudos

As already written you could

- use a NO-EXTENSION on the select-options.

- or copy low to high in a LOOP and add a FOR ALL ENTRIES IN s_bndt, but don't forgetr  that this internal table should not be initial else every where criteria will be ignored, so if empty you will have to add a dummy record (initial/99991231) Better use first option .

Regards,

Raymond

0 Kudos

Hi,

Thanks Raymond and Gaurav...

I am closing this thread.

I had given points for ur answers..

Thanks a lot..

Happy weekend.

gouravkumar64
Active Contributor
0 Kudos

Hi,Hope u know like this,

SELECT-OPTIONS : s_per FOR pa0001-pernr NO INTERVALS.

for multiple selection

Gourav.

gouravkumar64
Active Contributor
0 Kudos

One last question no extension is the correct answer or no intervals???

Gourav.

0 Kudos

No extension is correct...i Know by mistake u typed like that...

any how thanks a  lot...

Happy weekend enjoy...........