06-29-2012 4:45 PM
Hi Friends,
I have a requirement where in I have a selection screen with date parameter and radio buttons with 30 days, 60 days and 90 days.
I am extracting the materials numbers from A708 table with in the validity dates.
For expample:
{code}
IF P_90DAYS = GC_X.
CLEAR: GV_90DAYS.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
DATE = P_ERDAT
DAYS = '90'
MONTHS = '00'
SIGNUM = '+'
YEARS = '00'
IMPORTING
CALC_DATE = GV_90DAYS.
SELECT MATNR DATBI DATAB FROM A708
AND DATAB <= P_ERDAT
AND DATBI <= GV_90DAYS.
ENDIF.
{code}
Selection Screen:
Date: 06/30/2012
Radio button: 90 days
I am getting output as follows:
I tried different ways modifying my select statement but couldn't achive my required output. Since, the highlighted ones already expired from the date specified I do not want to see them.
Can some one help me with this?
Appreciate your time.
Thanks,
Nani.
06-29-2012 4:55 PM
06-29-2012 4:59 PM
You are using less than in both queries. Change it as per the bold below.
SELECT MATNR DATBI DATAB FROM A708
INTO TABLE GT_A708
WHERE KSCHL = 'ZDF1'
AND VKORG = '1000'
AND DATAB gt P_ERDAT
AND DATBI lt GV_90DAYS.
Regards,
Shravan
06-29-2012 5:10 PM
Thanks for the reply Chinmay and Shravan.
I tried the change datab >= p_erdat before. But, now my internal table is empty (no values). I need to display only validity dates between 06/30/2012 - 09/28/2012 only. If the date is 09/30/2012, it should not be dispalyed.
Thanks,
Nani.
06-29-2012 5:14 PM
You are using two date fields in the query, but showing only one on the data screen. Is that a mistake too. Use the correct date field in your query either DATAB or DATBI.
Regards,
Shravan
06-29-2012 6:04 PM
What exactly are you trying to achieve with:
---------------t1--------------------------t2------------------
[ A ] [ B ] [ C ] [ D ] [ E ]
having t1 = P_ERDAT, t2 = t1 + 90
and [ ] representing the validity of your objects.
Do you need only object C? or B, C, D?
If you need B, C, D you can use
AND DATAB < GV_90DAYS
AND DATBI > P_ERDAT.
and if you also need objects with an end of validity at exactly P_ERDAT or a start of validity at exactly GV_90DAYS, then you have to add the equality sign...
AND DATAB <= GV_90DAYS
AND DATBI >= P_ERDAT.
Kr,
Manu.
06-29-2012 6:06 PM
Hi nani,
really amusing to see the code of FM RP_CALC_DATE_IN_INTERVAL - the developers was payed per code line and did not make use of the fact that operator + and - are defined for dates. A good reason this function has never been released within SAP and for customers.
You may gain some transparaency using
CASE gc_x.
WHEN P_30DAYS .
gv_dabi_max = P_ERDAT + 30 -1.
WHEN P_60DAYS .
gv_dabi_max = P_ERDAT + 60 -1.
WHEN P_90DAYS .
gv_dabi_max = P_ERDAT + 90 -1.
ENDCASE.
SELECT MATNR DATBI DATAB
INTO CORRESPONDING FIELDS OF TABLE GT_A708
FROM A708
WHERE KSCHL = 'ZDF1'
AND VKORG = '1000'
AND DATAB >= P_ERDAT "Note: Start with P_ERDAT
AND DATBI <= gv_dabi_max.
This will get you all date ranges within n days. If you want everything that intersects the date range, it would be
AND DATAB >= gv_dabi_max
AND DATBI <= P_ERDAT "Note: Start with P_ERDAT
Regards,
Clemens Li
06-29-2012 7:09 PM
Thanks Shravan, Manu and Clemens.
Tried as you guys said. But no luck.
Parameter = 06/30/2012
Radio Button selected = 90 days
gv_date = parameter + 90 - 1. i.e. 09/27/2012
I need to dispaly materials within 06/30//2012 - 09/27/2012 (I that dispaly, I need to include dates 06/30/2012 and 09/27/2012 as well) from table A708.
Please suggest me any good ideas.
Thanks,
Nani.
06-29-2012 7:14 PM
Hi Nani,
From what I understand your code should have one of the below where clause or both.
Option1
AND DATAB gt P_ERDAT
AND DATAB lt GV_90DAYS
Option2
AND DATBI gt P_ERDAT
AND DATBI lt GV_90DAYS
Regards,
Shravan
06-29-2012 7:40 PM
you really tried this?
AND DATAB <= GV_90DAYS
AND DATBI >= P_ERDAT.
If this doesnt work you have an issue in other part of your where clause (KSCHL or VKORG)...
Manu.
06-29-2012 9:55 PM
Hi nani,
just copy my code as is. Try both variants.
You can use SE16 with A708 and use the options in selection screen for datab and datbi. Play a bit with <= to >= and the dates mentioned for gv_date and P_ERDAT to find out what will fulfill your requirement.
Regards
Clemens.