SAP BW DTP Filter with Routine

In my current project I have to filter data with a lot of logic. So I build some ABAP routines in a DTP filter to receive the necessary data. First you have to open the DataTransferProcess (DTP) in change mode and select the Filter button on the Extraction tab.

DTP Extraction tab
DTP Extraction tab

Then use the small icon on the right and create a routine.

DTP Filter
DTP Filter

Enter a name for the routine and you see the following screen.

Create ABAP routine
Create ABAP routine

And now we have the full power of ABAP to build some really cool stuff. My example is we read a hierarchy and select all leaves under a node and set the DTP Filter with it. Or you read the attributes of an InfoObject and select all entries which are equal to the attributes and enter them into the filter.

CONSTANTS: lc_iobjnm_zsaleschannel TYPE rsiobjnm VALUE 'ZSALESCHANNEL'.

 

DATA:

ls_rssh_hiedir TYPE rshiedir,

lt_rssh_hiedir TYPE rssh_t_hiedir,

ls_subtreesel TYPE rssh_s_nodebyname,

lt_hierarchy TYPE /bic/whzsaleschannel,

 

FIELD-SYMBOLS:

<ls_hierarchy> TYPE /bic/hzsaleschannel,

 

'Get all hierarchies from the object

CALL FUNCTION 'RSSH_HIER_OF_IOBJ_GET'

EXPORTING

i_objvers = rs_c_objvers-active

i_iobjnm = lc_iobjnm_zsaleschannel

i_langu = sy-langu

IMPORTING

e_t_rshiedir = lt_rssh_hiedir.

 

'Get technical hierarchy id to hierarchy name

CLEAR ls_rssh_hiedir.

 

READ TABLE lt_rssh_hiedir INTO ls_rssh_hiedir WITH KEY hienm = i_zsaleschannel_h

 objvers = rs_c_objvers-active.

 

'Sub-Tree to Note/Leaf

CLEAR: ls_subtreesel.

ls_subtreesel-iobjnm = lc_iobjnm_zsaleschannel

ls_subtreesel-nodename = i_node.

 

*Get Hierarchy Elements

CALL METHOD cl_rssh_hierarchy_func=>get

EXPORTING

i_objvers = rs_c_objvers-active

i_hieid = ls_rssh_hiedir-hieid

i_s_subtreesel = ls_subtreesel

IMPORTING

e_t_hiestrucall = lt_hierachy

After I have now all elements in an internal table, I can add them to the DTP Filter.

'Loop over the internal table and assign the value to the dtp filter

LOOP AT lt_hierarchy ASSIGNING <ls_hierarchy>.

l_t_range-fieldname = '/BIC/ZSALESCHANNEL'.

l_t_range-iobjnm = '/BIC/ZSALESCHANNEL'.

l_t_range-sign = 'I'.

l_t_range-option = 'EQ'.

l_t_range-low = <ls_hierarchy>-/bic/zsaleschannel.

 

IF l_idx <> 0.

MODIFY l_t_range INDEX l_idx.

ELSE.

APPEND l_t_range.

ENDIF.

 ENDLOOP.

DTP with active ABAP method
DTP with active ABAP method

author.


I am Tobias, I write this blog since 2014, you can find me on twitter and youtube. If you want you can leave me a paypal coffee donation. You can also contact me directly if you want.

Transport Dependency Check
Check the dependency of your transport requests before you want to transport your development to your productive system.
99,00 €

Write a comment

Comments: 4
  • #1

    Nadine Ngassi (Tuesday, 18 December 2018 18:50)

    Hi Tobias,
    I have read this code and want to know how to write a routine on a DTP to tell him to filter OUT some data which are into another DSO? I'll be glad to have an answer from you. I gave you here my email: nadine.jobangebot... googlemail.com. You change the ... with @
    My regards,
    nadine

  • #2

    Tobias (Wednesday, 19 December 2018 19:21)

    Hi Nadine,

    thanks for your Comment. You can filter values out by using the "l_t_range-sign = 'E' " instead of "l_t_range-sign = 'I'.". E means exclude and I means Include.

    Best regards,

    Tobias

  • #3

    Christian (Monday, 29 April 2019 16:06)

    Hi ! I am having a problem on method cl_rssh_hierarchy_func=>get while importing
    e_t_hiestrucall = lt_hierachy due to incompactibilities between both structures.
    I am trying to retrieve costelmnts from a hierarchy, but I cannot find the correct type of lt_hierachy . Do you have any idea how to find it?
    Thanks !

  • #4

    Tobias (Tuesday, 30 April 2019 10:47)

    Hi Christian,

    you need the hierarchy table of costelmnts. This is /BI0/WHCOSTELMNT.