Skip to Content
Jul 29, 2019 at 10:08 AM

Calculate last 6 months based on selected date



I have a requirement in BW to create a query where one enters a date and fetch data for last six months in two fields.

Rest all the fields should fetch data based on the selected date.

The process I followed is I wrote a customer exit which will calculate the data for last 180 days from the entered date.


IF i_step = 2.
data : w_date type d,
w_date1 type d.

CLEAR w_date.

LOOP AT i_t_var_range INTO lwa_var_rng WHERE vnam = '0P_CSDAT'.

w_date = lwa_var_rng-low.
w_date1 = w_date - 180.

CLEAR lwa_range.

lwa_range-low = w_date1.
lwa_range-high = lwa_var_rng-low.
lwa_range-sign = 'I'.
lwa_range-opt = 'BT'.
APPEND lwa_range TO e_t_range.

Now what happens is the field fetches the data but it does not fetch data for last six months instead of that it fetches overall records. Attached is the screenshot from Query designer. Please help.

Example. If I execute the query with the date as 30.06.2019 so it fetches the quantity since beginning till that date i.e. 6000 PC instead it should fetch 124 PC which is used in the last six months.