Scenario: If I execute DTP in current month, it always picks only “Current month – 1” data.
If today’s date is 04/22/2016, based on the system date, it will calculate previous month First day and Last day. i.e. it will fetch 03/01/2016 to 03/31/2016.
If today’s date is 01/22/2016, based on the system date, it will calculate previous month First day and Last day. i.e. it will fetch 12/01/2015 to 12/31/2015.
Occasionally we need to filter the Date Characteristic InfoObject to extract only “Previous Month” data. Here the filter selection is not on SAP Content InfoObject, the filter selection is on Custom InfoObject.
If it is SAP Content InfoObject, we may have few SAP Customer exit/variables to use directly in DTP, but in this example I’m using Custom InfoObject which is created Data Type as DATS.
In DTP select the InfoObject and choose Create Routine and write/add the below Code in DTP Routine.
* Global code used by conversion rules
*$*$ begin of global – insert your declaration only below this line *-*
* TABLES: …
DATA: dt_range TYPE STANDARD TABLE OF rsdatrange,
btw LIKE STANDARD TABLE OF rsintrange,
wdt_range TYPE rsdatrange.
*$*$ end of global – insert your declaration only before this line *-*
*$*$ begin of routine – insert your code only below this line *-*
data: l_idx like sy–tabix.
read table l_t_range with key
fieldname = ‘ ‘.
l_idx = sy–tabix.
CALL FUNCTION ‘RS_VARI_V_LAST_MONTH’
* SYSTIME = ‘ ‘
p_datetab = dt_range
p_intrange = btw.
READ TABLE dt_range INTO wdt_range INDEX 1.
l_t_range–fieldname = ‘/BIC/<Your_InfoObject_Name>’.
l_t_range–option = ‘BT’.
l_t_range–sign = ‘I’.
l_t_range–low = wdt_range–low.
l_t_range–high = wdt_range–high.
* IF l_idx <> 0.
* MODIFY l_t_range INDEX l_idx.
* APPEND l_t_range.
*$*$ end of routine – insert your code only before this line *-*