Hi BI Experts
We have used document from this link http://scn.sap.com/people/durgesh.gandewar/blog/2012/02/14/financial-reporting-in-bi-over-various-time-frames for YTD creation but unfortunately I am getting only MTD values if I give month in MTD variable in bex analyzer and full total If I give month in YTD variable.Please find below the code used for your reference and also find query defination screenshot attached for your reference.
DATA: l_s_range TYPE rsr_s_rangesid.
DATA: loc_var_range LIKE rrrangeexit.
* MTD Input Variable
CASE I_VNAM.
WHEN 'ZVARMTD'.
DATA: lv_buper TYPE poper,
lv_gjahr TYPE bdatj.
" Get current fiscal period from system date.
IF i_step = 1.
CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
EXPORTING
i_date = sy-datum
i_periv = 'V6'
IMPORTING
e_buper = lv_buper
e_gjahr = lv_gjahr
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.
IF sy-subrc = 0.
"Current period is nothing but equal to Month to Date.
CLEAR l_s_range.
CONCATENATE lv_gjahr lv_buper INTO l_s_range-low.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
APPEND l_s_range TO e_t_range.
ENDIF.
endif.
" Year to Date Variable
WHEN 'ZVARYTD'.
IF i_step = 2.
CLEAR: l_s_range,loc_var_range.
LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZVARMTD'.
"In YTD calculation the lower limit will be always 1 and the higher limit will be
"current period, which is calculated based on the MTD value.
IF loc_var_range-low+4(3) = '001'.
l_s_range-low = loc_var_range-low.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
APPEND l_s_range TO e_t_range.
ELSE.
l_s_range-high = loc_var_range-low.
loc_var_range-low+4(3) ='001'.
l_s_range-low = loc_var_range-low.
l_s_range-sign = 'I'.
l_s_range-opt = 'BT'.
APPEND l_s_range TO e_t_range.
ENDIF.
EXIT.
ENDLOOP.
ENDIF.
"Last Year to Date Variable
WHEN 'ZVARLYTD'.
IF i_step = 2.
DATA: l_vy(4) TYPE c,
l_pe(3) TYPE c.
CLEAR: l_s_range,loc_var_range.
" In the last year to date, lower month will always be 1 and higher
" month will be MTD value. But the year for both of these calculations will be
" (MTD year) - 1.
LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZVARMTD'.
l_vy = loc_var_range-low+0(4).
l_pe = loc_var_range-low+4(3).
l_vy = l_vy - 1.
CONCATENATE l_vy l_pe INTO loc_var_range-low.
l_s_range-high = loc_var_range-low.
CLEAR loc_var_range-low.
CONCATENATE l_vy '001' INTO loc_var_range-low.
l_s_range-low = loc_var_range-low.
l_s_range-sign = 'I'.
l_s_range-opt = 'BT'.
APPEND l_s_range TO e_t_range.
EXIT.
ENDLOOP.
ENDIF.
endcase.
Please correct us where we went wrong.
Thank you in Advance.
Regards,
naresh.