Wednesday 28 March 2012

Select Data in DTP Dynamically

Similarly to selecting parameters dynamically in the infopackage, as discussed in the previous post, we may need to select parameters dynamically in a DTP. In the post below I will review an example of how to make selections dynamically in the DTP. A practical application of this approach can be selection of records from a DSO by date range, say we want to select all records with Date From lower than [Today + 30 days] and Date To greater than [Today - 30 days].

In the Filter selections for the DTP we have to click on the “Routine create” button for the infoobject we want to use:


As DTP selections are stored as a range we have to populate fields of the table l_t_range with appropriate selection parameters.
For the object “Date From” the selection routine may look as follows (we select all records with the Date From before [Today + 30 days]):

form compute_RT_DATEF
  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.
          read table l_t_range with key
               fieldname = 'RT_DATEF'.
          l_idx = sy-tabix.
*....
DATA: cd TYPE D.
          cd = sy-datum.
          cd = cd + 30.
          l_t_range-fieldname = 'RT_DATEF'.
          l_t_range-sign = 'I'.
          l_t_range-option = 'LE'.
          l_t_range-low = cd.
          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.

2 comments:

  1. How to get list of all the target objects having dtp filters with attribute(field) dtp_filter_attr, for example 'FISCPER' ?

    ReplyDelete
  2. In SQL terms:

    select distinct t.tgt
    from
    rsbkselect a -- 'a' from filter_Attribute
    inner join rsbkrequest_v t -- 't' from request_Target
    ON t.requid = a.requid
    where
    a.field = dtp_filter_attr -- dtp_filter_attr = 'BUDAT'

    ReplyDelete