10-30-2012 9:23 AM
Hi There,
I have a requirement where i need to find a value based on date range. I can get this value. The issue comes up when i need to find the previous value than this value. How can this be handled. Based on these values we would require to perform some calculations on 2 values.
Please suggest.
Thanks,
puneet
10-30-2012 9:30 AM
10-30-2012 9:30 AM
10-30-2012 9:38 AM
DATA: var1 type var_type,
var2 type var_type.
SELECT SINGLE field INTO var1 WHERE key = condition1.
SELECT SINGLE field INTO var2 WHERE key = condition2.
IF var1 = var2.
...
ENDIF.
10-30-2012 9:45 AM
Hello,
Please provide more details on your requirement.
Regards,
Deepti
10-30-2012 10:04 AM
Hi Deepti,
The specific requirement i have is that i need to add a new field in infoset query tool. This field would be required to hold the value of percentage change between one value(selected based on date range) and need to be compared with the previous value of annual salary. So for this i need to retrieve both the values and have them, what could be the best way to get the values from DB? Please suggest.
Hope i am able to make it clear.
Thanks,
puneet
10-30-2012 9:50 AM
10-31-2012 5:41 AM
Hello Puneet,
Would it possible if you maintain custom table that keeps record of previous value and current value.
When you execute your program firt time then i guess both values ( previous and current) would be same and then you can write logic in your program to update this custom table with this values and also update infoset query with this 2 values.
Rgds,
Deepti
10-31-2012 10:49 AM
Hi Deepti,
It won't be possible solution, as it's just not required to compare the current and the last value. Consider a case it could be that there are 4 values and the comparison might be required between 2 or 1 etc..
So we might need to find the logic, plus it would be based on selection on dates which user enter's as per requirement to fetch the data.
Thanks,
Puneet
11-01-2012 3:30 AM
Ok..tell me how you calculate current value based on date range. what's your logic for this?? Also give me example that will explain wht is the current value and previous value you expect for date say 1/Nov/2012 entered by User of selection screen.
Rgds,
Deepti
11-01-2012 4:02 AM
Hi Deepti,
Let's take this example of data available
record 1 -> 01/01/2005-01/08/2005 50000
record 2 -> 02/08/2005-01/09/2007 70000
record 3 -> 02/09/2007-01/10/2008 80000
record 4 -> 02/10/2008-01/11/2009 90000
Now let's say the user queries on data in SAP reporting tool(ex PQAH) and gives the date range of query as 01.01.2003 to 01.01.2008 -> so as per this we need to use select statement to get the values and where condition would be our BEGDA. And as in reporting tools the data is displayed, this percentage change column would be a extra column added in infoset which will compare the 2 values and hold the value.
Hope i am able to explain you better now.
11-01-2012 5:54 AM
Hello Puneet,
Thanks for details..
For date 01.01.2003 to 01.01.2008, ideally you expect current value will be 200000 (approx) ( sum of record 1, 2 & 3) and Previous value?? Is there is any calculation for previous value. On what basis you want to calculate previous value?
Eventhough If we consider somehow you retrieve previous value then this will be applicable for date range 01.01.2003 to 01.01.2008. what if User enters date range 5/01/2008 to 10/01/2012, then in that case which previous value you consider..
11-01-2012 6:20 AM
Hey deepti,
thanks for replying and digging in.. see the last column would be based on this logic... the previous value would be same as the value in record and no need to sum !!
Dates Amt change
record 1 -> 01/01/2005-01/08/2005 50000 NA
record 2 -> 02/08/2005-01/09/2007 70000 rcrd2-rcrd1
record 3 -> 02/09/2007-01/10/2008 80000 rcrd3-rcrd2
record 4 -> 02/10/2008-01/11/2009 90000 rcrd4-rcrd3
Change column would hold a new value which is not provided by SAP, so this value will do the comparison between the amt's.
Hope this makes more clear.
thanks again..
-puneet
11-01-2012 6:53 AM
Puneet,
Lets try this way..
You can get tables entries in internal table based on date range entered on selection screen.
Now to find previous values, we need to play around with internal table.
Sort internal table either Ascending or Descending.
Loop internal table .
Read previous value based on sy-tabix.
( If you have sorted internal table ascending then get previous value = sy-tabix - 1, if internal table in sorted on descending then previous value will be = sy-tabix + 1)
ENDLOOP.
Hope above solution solved this issue.
Regards,
Deepti
10-31-2012 11:36 AM
Puneet,
You need to have 2 separate work area's for taking the values, lets say wa_current and wa_previous. You have already got the current value based on the date range. Now, using the start date STR_DATE, you need to get the previous value. This can be done by the simple select statement
SELECT <fields>
FROM <table>
UPTO 1 ROWS
INTO wa_previous
WHERE <condition n> = <Value>
AND <date condition field> LT <Start Date, STR_DATE>
ORDER BY <date field condition> DESCENDING.
This will get you the latest value.
Alternatively, if you require from some infotype you can also use the macro RP-PROVIDE-FROM-LAST. The macro to be used is
RP-PROVIDE-FROM-LAST Pxxxx SPACE BEGDA ENDDA.
Here your BEGDA can be 1 to 10 years before ENDDA and the ENDDA should be 1 day less then STR_DATE. You can get the latest value required.
Regards,
Hardik Mehta