Posts

Showing posts from May, 2017

"Working days" and factory calendar in ABAP

 There are some functions and classes available to work with factory calendar. Some real life scenarios, however, could be more tricky than just finding next working day.  Say you need to know which date would be a 5th working day of any given month. Even if requirement has fixed number, it might not be very helpful, as factory calendars can be very different from basic calendar. Let's take the most simple example - 01.03.2017. 5th day of the months is Sunday, which makes 07.03.2017 the 5th working day. Holiday season, or any other business related reason, can push 5th working day to even later dates. That means, we really need to count working days to get the proper result.  Unfortunately, SAP systems do not have ready made functions to get just that (even though, such functions might be a part of some specific applications/module, but let's assume we have none or using SAP BW system, with only generic ABAP/4 functions available).  In our case we need to start f...

Debugging planning functions in SAP BI-IP

Image
SAP came up with the FOX scripting language, to make it easier for anyone with no solid programming experience, to create custom planning functions in SAP Integrated Planning. Some of the FOX operators were actually ahead of ABAP/4 of these times when FOX was introduced. So real analogue of FOX's "FOREACH" was only introduced with ABAP 7.40 release, as "FOR". Depending on business requirements, FOX formulas can become quite complex and include hundreds line of code, which could be a stumblingstone of support and enhancement of the existing solution, which was developed years back, by long forgotten consultants. Luckily, SAP has debugging option also for FOX based planning functions, which is however not as easy to reach as traditional ABAP/4 debugger. Due to it's non-ABAP nature, it is not possible to simply put an ABAP breakpoint in a FOX code, nor ABAP debugger can "just pick it up". Deep inside the application server, SAP translate FOX in...

Converting number to date data types

Image
ABAP seems to disregard leading zeros when implicit number conversions or even when N to D conversions. Let's say that while creating a new customer-exit variable, you need to combine a full 8 character date from standalone values for year, month and day i.e. '20151201' Depending on how you declare variables, result may or may not be just as expected. This works OK if you have two digit day or month number as 20171231. However, problem arise if your day or month number has only one number, so a leading zero must be used. For example, lets check inline declaration: DATA ( lv_day ) = 01 . It does not matter how many leading zeroes you add, ABAP will always disregard those and result will be not as expected: In that case, it is important to always specifically define length of each of the variables. We can even come back to old-fashion declaration to give it more clarity: lv_day TYPE NUM02 , lv_month TYPE NUM02 , lv_year TYPE NUMC4 . Or i...