28 Sep How to Become a Macro Whisperer
Within the realms of SAP, there isn’t a functionality, in my mind, that comes closer to a love/hate relationship. Of course, I am talking about Macros: the one area in SAP that can make a planner’s life easier and make the creator of the macro look like a hero. What some people don’t know is that in order to achieve some of the desired results, there is a constant battle between trying to apply logic while constantly getting feedback from the system that your parameters don’t make sense, when you know that they do. So for today’s blog, I would like to make someone’s life easier, if even for a day. There are thousands of macros combinations, so let’s concentrate on one that seems popular and customers ask for frequently. Today we’re going to focus on how to create a macro that will pull values from the product master with specific criteria.
Say for example that the business requirement comes to you on Friday afternoon around 4pm like this – “Claudio, ECC allows me to combine my Safety Stock Quantity and Safety Days Supply. I can’t find that option in APO, which is not acceptable. So make it happen. And by the way, I only want this combination method to happen for my raw materials. Have a great weekend!” The good news is that you are no longer wondering what you were going to do this weekend; the bad news is that you know what you are going to be doing this weekend.
Here is the first rule of thumb: if at all possible, do not try and create a brand new macro from scratch; instead, reference other working macros. In fact, the first thing you should do is go to the macro workbench (/SAPAPO/ADVM) and pull up the planning book and data view that you’ll be working with. In this case, since we are dealing with Safety Stock calculation, there’s already a standard macro for it. So make a copy of it and that will be your starting point.
By doing a copy, we at least know that the standard macro works, and we’ll then have plenty of time to break it by putting different types of logic that the system won’t like. The key here is that we are not touching the standard Safety Stock macro and we can do with our copy as we please.
So the first thing we want to do is create a logic that will fetch the material type from the product master, since the requirement says that we only want the logic to apply for raw materials.
Every time we want to retrieve a value from the product master, we will use the –LAYOUTVARIABLE_SET function as shown above. So in common language, in this section, we are telling the system that we want to retrieve the 4th extra field value from the product master. Why extra field? Because, as I hope you know, material type does not come over standard to APO, so if you want it, it must be brought as an extra field (via BADi). The second part says that I want the value to be ROH, meaning raw materials. This will become clearer in a little bit.
The next step is to fetch the Safety Stock quantity from the product master with the following step:
So here again, we are using a LAYOUTVARIABLE_SET logic. Since this is a standard field in the product master, we will be using the MATLOC function. Here is a trick that will save you some headaches: if you try to get the field name from the Product Master transaction itself, it won’t work. Why? Well, that’s because our great friends at SAP decided to name the field in F1 as SAFTYC but in the table it is called SAFTY, so macro will only take SAFTY. Awesome, right?!?!
Product Master – SAFTYC
OK, so now we have one step to fetch the material type and another step to fetch the safety stock quantity. The next step in our logic is the decision statement and it looks like this:
Let’s decipher it, shall we?
The logic starts with an IF statement, that basically says if MATTTYPE = MATTYPEROH then continue. So that means that if the fetch value of MATTYPE from the extra field in the product master is equal to the MATTYPEROH value of, (you guessed it) ROH, then continue with the logic below.
So the second step says to take the safety stock quantity (SAFTYC1) and add to that (+) the safety days calculation. This area I did not change for the most part except for the workdays calculation. (More to come on that.)
So what happens if the material is not an ROH? Well then the macro will skip to the ELSE statement, which only has the safety days calculation, which is the standard (assuming stock method SZ).
Finally ending the macro with the ENDIF statement.
Now, going back to the workdays: why did I change that? Well, if the client comes back and says…..”This is nice and all, but in ECC, the Safety Days calculation happens on working days while in APO, I am seeing it in calendar days. I don’t like it; make it match.” What do you do? You make it match. To be able to do that, you would change the macro that calculates the working times, as show below.
That macro is the Determine Workdays
So, here we tell the system to pick up from the location master the planning calendar residing in the Receiving Calendar field, which in this case is a 5 days calendar.
So as a final step, you would deactivate the Working days which contains seven days and activate the one that contains five days.
And you are done!! Oh you want to actually see it in action?? OK, here you go…..
Let’s take Material A which is a raw material with 3 days of Safety Days and 50 units of Safety stock.
As expected, based on a constant demand of 100 units every bucket, the Safety Stock quantity is 350 – (300 from the Days Supply plus 50 for the safety stock quantity in the product master)
Now, what if we bring a material that is not a raw material but a WIP, will the safety stock value be added as well? Let’s look.
As expected, again, since this is not a raw material, the standard safety days calculation applies without adding the safety stock quantity of 50.
And just like that, you now know how to retrieve values from the product master while creating a pretty crafty IF statement and taking it to the next level of awesomeness.