Skip to Content
0

Routine to filter required data .

Dec 31, 2016 at 09:07 AM

480

avatar image

Hi experts ,

we are doing full load from psa --> cube with around 10 million records. It loads completely 2016 and 2017 ( forecast ) data. My target is to load only 6-7 months data. As in , the dtp should pick data of only last 3 months and next 3 months based on system date. Please suggest if i should write a code in dtp routine or start or end routine and please help me with the code as well.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Pruthvi Renukarya Jan 03, 2017 at 09:02 AM
0

You can use below pseudo code to filter at start routine:

Data: lv_month(6) type n.

lv_month = sy-datum+0(6).

DELETE source_package WHERE calmonth NOT BETWEEN lv_month - 3 AND lv_month + 3.

Share
10 |10000 characters needed characters left characters exceeded
Francisco Milán Campos Jan 04, 2017 at 01:26 AM
0

Hi Dinesh,

If you want to filter the data you have in the PSA by comparing the date values against a dynamic range based on the system date, you can proceed as follows:

1. Double-click on the DTP and click on the "Display <-> Change" button
2. Go to the "Extraction" Tab
3. Click on the "Filter" button
4. Click on the "Create routine" button (the button name might be displayed as "Routine anlegen") to add the ABAP routine you will be using to dynamically filter on Calendar Day (or any other field where you store the date, for example Transaction Date, etc.),
5. Once you access the ABAP Editor you can enter the code below (some minor adjustments might be required).

Good luck,

Francisco Milán.

*&---------------------------------------------------------------------*
*&  Include           RSBC_SEL_ROUTINE_TPL
*&---------------------------------------------------------------------*

program conversion_routine.
* Type pools used by conversion program
type-pools: rsarc, rsarr, rssm.
tables: rssdlrange.
* Global code used by conversion rules
*$*$ begin of global - insert your declaration only below this line  *-*
* TABLES: ...
* DATA:   ...
*$*$ end of global - insert your declaration only before this line   *-*
* -------------------------------------------------------------------
*     Fieldname       = CALDAY
*     data type       = DATS
*     length          = 000008
* -------------------------------------------------------------------
form compute_CALDAY
  tables l_t_range structure rssdlrange
  using i_r_request type ref to IF_RSBK_REQUEST_ADMINTAB_VIEW
        i_fieldnm type RSFIELDNM
  changing p_subrc like sy-subrc.
*       Insert source code to current selection field
*$*$ begin of routine - insert your code only below this line        *-*
  data: l_idx     like sy-tabix.
  DATA: today     LIKE sy-datum.
  DATA: date_to   TYPE sy-datum.
  DATA: date_from TYPE sy-datum.

  today = sy-datum.

* Calculate "Date From" (System Date minus 3 months), the day part
* is set to the first day of the month, e.g. if current date is 
* Jan 3 2017, "Date From" will be Oct 1 2016
  date_from = today.
  date_from+6(2) = '01'.
  DO 3 TIMES.
    SUBTRACT 1 FROM date_from.
    date_from+6(2) = '01'.
  ENDDO.
  l_t_range-low = date_from.

* Calculate "Date To" (System Date plus 3 months), the day part
* is set to the last day of the month, e.g. if current date is 
* Jan 3rd 2017, "Date To" will be Apr 30 2017
  date_to = today.
  date_to+6(2) = '01'.
  DO 4 TIMES.
    ADD 31 TO date_to.
    date_to+6(2) = '01'.
  ENDDO.
  SUBTRACT 1 FROM date_to.
  l_t_range-high = date_to.

  l_t_range-fieldname = 'CALDAY'.
  l_t_range-sign =  'I'.
  l_t_range-option = 'BT'.

  if l_idx <> 0.
    modify l_t_range index l_idx.
  else.
    append l_t_range.
  endif.

  p_subrc = 0.

*$*$ end of routine - insert your code only before this line         *-*
endform.
Share
10 |10000 characters needed characters left characters exceeded
Poonam Hemrajani Jan 06, 2017 at 03:53 AM
0

Hi Dinesh

I am not sure what is your source system, you should be able to filter the data in the info package before it comes to the PSA.

Also if possible use date functions to identify the date , if you using string functions then you will have to think about leap year.

Poonam

Share
10 |10000 characters needed characters left characters exceeded
Francisco Milán Campos Jan 12, 2017 at 05:47 PM
0

Hi Dinesh,

In case you want to filter the data before loading the PSA you can perform the following steps:

1. Double click on the InfoPackage.
2. Click on the "Data Selection" Tab.
3. Enter 6 (ABAP Routine) in the column "Type (Variable Change to Selection Values with Background Processing)" for the CALDAY InfoObject or for any other other field where you store the date.
4. Once you access the ABAP Editor you can enter the code that I provided in my previous post (and as mentioned earlier, some minor adjustments might be required).

Kind regards,

Francisco Milán.

Share
10 |10000 characters needed characters left characters exceeded