My requirement is to create Customer exit variable to calculate the Month to date (MTD) value (Quantity) in a query. I created a Customer exit variable for MTD (0CALDAY) in Query & wrote code in CMOD for the same as follows.
DATA: ZYEAR(4) TYPE N,
ZMON(2) TYPE N,
ZDAY(2) TYPE N.
IF I_STEP = 2.
LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE.
ZYEAR = LOC_VAR_RANGE-LOW+0(4).
ZMON = LOC_VAR_RANGE-LOW+4(2).
ZDAY = LOC_VAR_RANGE-LOW+6(2).
CONCATENATE ZYEAR ZMON '01' INTO L_S_RANGE-LOW.
CONCATENATE ZYEAR ZMON ZDAY INTO L_S_RANGE-HIGH.
L_S_RANGE-SIGN = 'I'.
L_S_RANGE-OPT = 'BT'.
APPEND L_S_RANGE TO E_T_RANGE.
I debugged this code by putting a break point & running the query in RSRT, the code is getting executed & i am getting the From & To dates in E_T_RANGE output.
But when I execute the Query, I am getting the output Quantity for FTD only, not MTD.
For example, if i give 05-12-2009 as variable input for 0CALDAY when i execute the query, i should get the summed up quantity for 01 Dec to 05 Dec in a single cell. But now, i am getting the summed up quantity for 05 Dec only.
Help me in resolving this.
I have put 0CALDAY in Filters section of the Query & restricted it with FTD variable. So, the date entered by the user is taken as FTD & quantity value is processed based on it.
But for MTD, i wrote Customer exit in CMOD for the Variable. I debugged the variable, it is properly getting the From & To values in E_T_RANGE. But somehow, the summed up value for this MTD is not coming, instead its showing the FTD value only.
"Instead of giving global filter you can go for local filter. ..." Could you please elaborate this? Also, if you have any standard code to calculate MTD, kindly let me know.
Hope your coding is working properly so, do below
Drag and Drop Chars in Row
Context Menu of Colum New Selection,
Select your KF (Revanue),
Drag and drop 0calday beneath of KF Restrict with variable (FTD)
FTD Variable should be : Manual Input, Mandatory, ready for input , single value,
Select your KF (Revanue)
Drag and drop 0calday beneath of KF Restrict with variable (MTD)
--- MTD Variable should be : Customer Exit, Not ready for input, Interval value.
Save and Execute. if your Coding is right you will be getting out put:
Customer Revanue (FTD) ---Revanue (MTD)
I am not an abaper , but in your coding i have not seen reading of your value from variable table..
You can try with below coding;;;;;
data: l_first_day_of_month type D,
l_s_var_range type rrrangeexit,
l_s_range1 type RSR_S_RANGESID.
if i_step = 2.
read table i_t_var_range into l_s_var_range
with key vnam = 'VAR_FTD'.
if sy-subrc = 0.
concatenate l_s_var_range-low+0(6) '01' into l_first_day_of_month.
l_s_range1-low = l_first_day_of_month.
l_s_range1-high = l_s_var_range-low.
l_s_range1-opt = 'BT'.
l_s_range1-sign = 'I'.
append l_s_range1 to e_t_range.
Note : here 'VAR_FTD' is one which user input during the execution of the query ..
The restrictios that are used in Characteristic Restrictions act as global restrictions for that query. This means that if you restrict Calmonth/Year = '01.2010' - '12.2010' at characteristic restrictions, this will be applicaable to all the key figures in the query.
Local restriction would be to restrict one particular key figure with required restrictions like in your case, right click on the particular key figure and click on edit button and then drag and drop the MTD variable you have created. Now this variable will be visible below the key figure. This acts as a restriction to this particular key figure. All the other key figures in the query would have FTD as restriction whereas this particular KF will have MTD as restriction.
Hope I have explained well.