Creating a Dynamic Date Filter for SAP Service & Asset Manager
A requirement during every SAP Service & Asset Manager project is to configure the data filters within the Mobile Application Integration Framework to determine what data is considered for synchronization to the mobile device. Many filter rule types are self explanatory - "User Profile Parameters" consider the parameter value maintained in SU3 while "Static Value in Range Table Format" allows you to explicitly declare filter values, while one, the "Filter Handler" is more complex.
A common requirement in projects is to
dynamically filter data based on a date range. To do this, we leverage a powerful Filter Rule Type called a "Filter Handler" and specifically the "oMDO Filter Rule - Date Range" Handler. Through this handler, we can dynamically define start and end dates for a date range based on the date of synchronization. This blog will explain how to use this handler and provide an example calculation.
Example - Using the "oMDO Filter Rule - Date Range" Handler
In our example, we wish to configure the "BASIC_FINISH_DATE" filter on the SAM2210_WORK_ORDER_GENERIC oMDO to return all work orders whose BASIC_FINISH_DATE is
this week.
To do this, navigate to the oMDO in transaction /SYCLO/CONFIGPANEL, we create a new Rule for the BASIC_FINISH_DATE of type "Filter Handler" and Handler "oMDO Filter Rule - Date Range". For the Input Parameter we use this: "CURRENT_DATE=CURR_WEEK_FIRST_DAY&FROM_DATE_OFFSET=0&TO_DATE_OFFSET=6"
If a synchronization is performed on Tuesday, August 22nd 2023, this rule will evaluate to a start date of 8/21/203 and an end date of 8/27/2023, thus giving us a date range of every date in this week.
A Screenshot of the WORK_ORDER_GENERIC oMDO
Parameter Options for the "oMDO Filter Rule - Date Range" Handler
So how does this work?
The input parameter string provides the rule with the input to dynamically calculate the date range. The idea is to establish a starting date for the calculation through the use of the CURRENT_DATE parameter, then determine the start and end of that range using the FROM_DATE_OFFSET and TO_DATE_OFFSET parameters which are integer values. The structure of the string is as follows:
"CURRENT_DATE=<current_date_param_value>&FROM_DATE_OFFSET=<integer>&TO_DATE_OFFSET=<integer>"
Note the exact syntax - the "=" between parameter name and value and the "&" between the three different parameters.
Because the CURRENT_DATE is the basis for the calculation, is it required. FROM_DATE_OFFSET and TO_DATE_OFFSET are optional.
Parameter: CURRENT_DATE
- Required (rule exits as blank if not provided)
- Determines the "CURRENT_DATE" which is used as the basis for the date range calculation. Is calculated based on the possible parameter values described below
- Possible Values:
- TODAY
- CURR_MONTH_FIRST_DAY
- CURR_MONTH_LAST_DAY
- PREV_MONTH_FIRST_DAY
- PREV_MONTH_LAST_DAY
- CURR_WEEK_FIRST_DAY
- Note - the first day of the week is considered to be a MONDAY in SAP.
Parameter: FROM_DATE_OFFSET
- Optional
- If not supplied, will return the CURRENT_DATE resolved above
- Determines the start of the date range by subtracting the parameter value from the date resolved from parameter CURRENT_DATE.
- Possible Values:
- Must only contain a positive integer value
Parameter: TO_DATE_OFFSET
- Optional
- If not supplied, will return the CURRENT_DATE resolved above
- Determines the start of the date range by adding the parameter value from the date resolved from parameter CURRENT_DATE.
- Possible Values:
- Must only contain a positive integer value
Then to tie it all together - If we consider the example Input Parameter string above - "CURRENT_DATE=CURR_WEEK_FIRST_DAY&FROM_DATE_OFFSET=0&TO_DATE_OFFSET=6" the calculation would proceed as follows:
- First, the rule will determine the first day of the current week "CURR_WEEK_FIRST_DAY". This will be calculated as 8/21/2023
- Second, the rule will subtract 0 (FROM_DATE_OFFSET) from that date to determine the start date of the range: 8/21/2023
- Finally, the rule will add 6 (TO_DATE_OFFSET) from that date to determine the end date of the range: 8/27/2028
Technical Note - if you want to see the logic in the backend, check ABAP class "/MFND/CL_CORE_DATE_RANGE_ORU" in SE24.
Hopefully this helps explain how to use this very useful Filter Handler!