When I teach SAP MDM courses I often get asked if MDM can handle time-dependencies, with the most common request being to set values to change according to the current date. The short answer is no — while MDM has no problem storing date or time stamps it can’t act on them. The long answer is — anything is possible, with some creativity. The solution I provided to one of my clients doesn’t only use MDM features, but who ever said we must confine ourselves to what MDM can do on its own?
One of my customers wanted to change a value of a certain field in the main table whenever a specific date reaches, and let each record be changed on a different date. What I did was add another field to the main table, called “Change Date”, to hold the date on which the value of the other field (let’s say its name was “Time Dependent”) needs to change on, and I used automated imports and the operating system’s task scheduler with a short script to update the records that needed to be change every day. Here’s how it works:
1. Add field to store date
Add a field to store the date you want to act on. In this example I’ll call it “Change Date”, but obviously you could also call it “Johnny Bravo” or “Shala Lala”.
2. Create an import map and inbound port
Once I had the fields in place I created a dummy source file to build an import map on. I created a CSV file, we’ll see why later — that looked something like this:
date,new value
6/6/2009,X
Using Import Manager I created a very simple Import Map based on this source file — mapped the “date” source column to the field “Change Date” and “new value” to “Time Dependent”. In the Field Matching tab I told MDM to match on the Change Date field, and set the default import action to “Update All Mapped Fields”.
This setup meant that MDM will update the values of “Time Dependent” with the value from the column “new value” in the source file, but only in the records that have the date specified in the source file’s “Change Date” field. Once the map was created I defined an inbound port using that map.
3. Scheduling a nightly update
The next step was making sure records will be updated on the right date, automatically. To do that I used the operating system’s task scheduler — all operating systems have one, in Windows it’s the Task Scheduler, in UNIX it’s cron. That specific project used Windows, but the same thing can be done just as easily on a UNIX based system.
I created a scheduled task that ran a small, simple batch file. This batch file creates a CSV file to be imported (using the map created earlier) and places it in the inbound port’s Ready directory. The file looked something like this:
cd /location/of/inbound/port/Ready
echo date,new value > file.csv
echo %DATE%,X >> file.csv
If you are so fortunate to have never had the need to learn how to speak Windows Batch, I’ll translate: what this script does is create a CSV file that looks like the dummy file I used to create the import map, but it makes sure it has the current date as the value for the “date” field. It creates the file in the Ready directory of the inbound port, so it will be picked up by Import Server.
I scheduled the task to run everyday at midnight, and that’s it — every day all the records that are set to have one of their values changed that day will be updated using the import. You can extend this method to support multiple fields, and even multiple values, you just need a bit of creativity.