Scenario: If I execute DTP in current month, it always picks only “Current month – 1” data.

Example:


    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: …


  DATAdt_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 sytabix.
     
read table l_t_range with key
      fieldname
= ‘ ‘.
      l_idx
= sytabix.
*….

  CALL FUNCTION ‘RS_VARI_V_LAST_MONTH’ 
  * EXPORTING
  * SYSTIME          = ‘ ‘
  TABLES
  p_datetab 
= dt_range
  p_intrange
= btw.

READ TABLE dt_range INTO wdt_range INDEX 1.

      l_t_rangefieldname = ‘/BIC/<Your_InfoObject_Name>’.
      l_t_range
option = ‘BT’.
      l_t_range
sign = ‘I’.
      l_t_range
low = wdt_rangelow.
      l_t_range
high = wdt_rangehigh.

APPEND l_t_range.

*  IF l_idx <> 0.
*    MODIFY l_t_range INDEX l_idx.
*  ELSE.
*    APPEND l_t_range.
*  ENDIF.

*$*$ end of routine – insert your code only before this line        *-*

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Venkateswarlu Ravula

    Hi SKR,

    Thank you for sharing this simple code.

    There is a confusion in the title of the post and the example you provided.

    Title/Subject:

    How to write code in DTP to select Previous Month Data

    Example:

    Eg: If Current month is Jan-2016, the DTP should fetch Dec-2015 Data from Source and updates into Target object.

    Could you please correct, if I understood it wrongly. Thank you once again for shared this post.

    Best Regards

    Venkat…

    (0) 

Leave a Reply