Unified Demand Forecast (UDF) Modeling and Forecasting in Sequence
You are at the point where you are running modelling and forecasting with the Unified Demand Forecast as a part of SAP Customer Activity Repository (CAR). You have created many variants for modelling and forecasting which allow you to manage groups of products that you are modelling. All is right with the world.
The process that you developed to run these variants was very methodical and you are very proud of the skills you have developed. At first, running these variants, one after another, gives positive feedback that everything is working correctly. Occasionally, one of the variants has a problem that you need to research and eventually fix and proceed. After doing this a few times, you eventually reach a point where you want to automate this process. Relying on previous experience, you schedule all the variants to run at pre-defined times, so that one variant will end before the next one runs and again everything is again working to your satisfaction.
Then one day, one of the variants fails, and then another; a whole sequence of variants fail. A change was made to some configuration which had an effect in multiple variants and like dominoes, the failures occurred one after another. Nothing to do but fix the problem and rerun the variants, hmmmm? On another day, a configuration was changed and each variant takes longer to run than was expected. The original scheduled time between runs is too short and jobs run overlap, fighting for resources – the reason why you created multiple variants to begin with to solve this problem! What can you do?
First We Need a Plan
I made a lot of assumptions in my example above but do not worry, I’ll start (mostly) from the beginning and describe all the steps, including the assumptions, like already having variants. For the example below, we will use the service ‘Model By Hierarchy’ which models different nodes of the Product (merchandise) hierarchy for all stores. We need to develop a plan which breaks up the work into separate Variants.
Step 1: Creating the First Variant
Assume that we have a hierarchy Node ID in our plan, such as 1000 FASHION, for which we want to create a Variant. We need to go to the SAP NetWeaver Business Client (NWBC) or to the Portal and select Schedule Model and Forecasts under the Services menu.
From there we need to do the following things to create our Variant:
- Select the Variant Setup tab.
- Select the Service Name. Our example uses Model By Hierarchy.
- Enter a name for the Variant. The Variant name can be anything but should have meaning to you so that you might identify its contents based on its name. This will avoid confusion later on when searching through a list of Variants where only a small number were created by you. For my example, I will prefix the Variant name (and other identifiers below) with my initials, MS. Also, since the first Variant we will create, for Model By Hierarchy, is for a hierarchy Node ID R3051 FASHION MEN, we will use the name MS_MBH_R3051.Select the appropriate Master Data System.
- Select the Product tab under Variant Detail.
- Select Search by Hierarchy and use F4 to find the correct Product hierarchy from the list and press Ok.
- Press Apply.
- Select the hierarchy Node ID for this variant and press the Apply button at the bottom of the screen. In our example, the hierarchy Node ID would be R3051 FASHION MEN. The node you applied appears under the Variant Detail on the right side of the screen.
- Select the Location tab under Variant Detail.
- Select Search by Hierarchy Name.
- Select F4 to search for Hierarchies available in this master data system and select the correct merchandise hierarchy from the list and press OK.
- Press Apply.
- Select the hierarchy Node ID for this job and press the Apply bottom at the bottom of the screen. In our example we will be modeling all locations for different nodes of the Product Hierarchy. The node you applied appears under the Variant Detail on the right side of the screen.
- If you wish to select specific Sales Organizations, Distribution Channels and / or Order Channels:
- Select the Multichannel tab under Variant Detail
- Enter directly or select F4 to search for Sales Organization. Distribution Channel and / or Order Channel
- Press Save. A success message appears.
We have created our first Variant! Write down the name of the Variant we created, we will need it later.
Step 2: Creating a Job Name for the First Variant
Next we need to ensure that it is possible to execute this service:
Again, we need to go to the SAP NetWeaver Business Client (NWBC) or to the Portal and select Schedule Model and Forecasts under the Services menu. From there we need to do the following things to execute our variant and save the execution parameters to the variant:
- Select the Process Setup tab. If we left Schedule Model and Forecast from the previous step, return there and:
- Select the same Service Name that you selected for the Variant creation in Step 1. In our example, we selected Model By Hierarchy.
- Press F4 on the Variant and select Start Search. Select the Variant name that matches the Variant we created in Step 1. In our example, we entered MS_MBH_R3051. All of the information you entered in Step 1 will appear under the Variant Detail area.
- Enter a Job Name to be associated with this Variant. In Step 1, we created a Variant named MS_MBH_R3051. The Job Name can be anything you wish.
- Select the appropriate Time Series Source from the drop-down selection, in our example, we will enter POS_TS.
- If appropriate, enter values in the other fields of the Selection Criteria.
- Select Schedule Single Execution
- Press Refresh System Date and Time
- Enter a Date and Time for the job to be run in the future
- Press Execute.
A message will display with a Job ID.
Write down the Job ID along with the Job Name, Service Name and Variant you just entered.
Step 3: Verifying the Results of Job Execution
You should inspect the results of running this job using ABAP transaction SM37. Select jobs with your user id and the name of this job, restricting it to look within the right timeframe. The status will show on the Job Overview screen. If the job has already been run, it will be in Status ‘Finished’ or “Canceled’; if it has not yet run, it will be in Status ‘Released’.
It is important to verify that each Variant that you create and execute will finish successfully. If it does not, then you should investigate why it failed before scheduling again. You need to troubleshoot any jobs that show “Canceled” before including them in this series of scheduled activities.
Also, once you create a Variant and run it via Schedule Single Execution, the parameters used during the execution are persisted (resaved) in the Variant. This has one major implication: do not edit/reuse this Variant for other purposes by changing the parameters and executing. If you do so, those new parameters will be persisted into the Variant and future execution of the Variant during your scheduled activities will use those new parameter values!
Step 4: Creating and Testing the Rest of the Variants
You can now repeat Steps 1 through 3 until you have created all the Variants that you need to run your chain of jobs. At this point, you should have a list of all the following information about each piece you want to run as separate parts of a complete process: Variant Name, Service Name, Job Name and Job ID. Most of this information will be used in the following steps.
Step 5: Programmatically Executing a Job Using a Variant
Remember that list that we created? One of the pieces of information we saved was the Service Name we used for each Variant. Variants are stored based on the Scheduler Report that uses this service information. In our example, the service we specified was Model By Hierarchy. The Report /dmf/op_mod_hier_job runs a Model By Hierarchy job. Therefore, the Variant that we created in Step 1, MS_MBH_R3051, is saved as a Variant of Report /dmf/op_mod_hier_job. The following list shows the mapping of the service to the Scheduler Report which handles that service:
- Model By Hierarchy => /dmf/op_mod_hier_job
- Model By Product Location => /dmf/op_mod_prodloc_job
- Forecast By Hierarchy => /dmf/op_fcst_hier_job
- Forecast By Product Location => /dmf/op_fcst_prodloc_job
We now have all the information that we need to execute jobs based on the Variants we created:
- Report Name (based on the Service Name)
- Job Name
- Variant Name
From here it is a simple matter of writing your own report using the Background Processing System API calls to open, submit and close each job, sequentially, for each Variant that we created. You can submit your report using transaction SM36 and can be scheduled to run once or recurring periodically.
Since your new report submitted each of the jobs individually using the Background Processing System API calls, we can use ABAP transaction SM37 to verify that each of them completed successfully as described above in Step 3 using their Job Name.
You may also view the messages and statistics for a given job using the Model Status Report (/DMF/MOD_STATUS_REP). But that topic is for another day…
Summing It Up
Creating a Report to handle running multiple Variants is a great solution to the two problems we started this article with: 1) being able to schedule jobs at a specific time and, 2) making sure that all these jobs run sequentially without manual intervention. I would like to thank fellow developers Bonnie Barker and Greggory Scherer for their help in compiling the information that I used to write this article.