Showing posts with label abap. Show all posts
Showing posts with label abap. Show all posts

Day of Last Period ABAP Function

Sometimes, in the course of your BW work, you will encounter a situation where the business requirement is to get the day of the last fiscal period. This is due to the fact that you want to populate, say calday infoobject, but the datasource only contains information in FISCPER format like 002.2008 for February 2008 for example.

So how do you overcome this? How to derive the last day in that period? Well the easy way is to use this built-in ABAP function in your transformation rules / or transfer rules etc:

CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
EXPORTING
I_GJAHR = your_fiscal_year
I_MONMIT = 00
I_PERIV = your_fiscal_variant
I_POPER = your_fiscal_month
IMPORTING
E_DATE = output_last_day_of_period
EXCEPTIONS
INPUT_FALSE = 1
T009_NOTFOUND = 2
T009B_NOTFOUND = 3
OTHERS = 4
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

result = output_last_day_of_period.

So how to use this function? You need to replace the following fields which is highlighted in bold above, 'your_fiscal_year', and 'your_fiscal_month', should be replaced by the fiscal year and fiscal month respectively, in this case, you can derive this from fiscper from datasource. Remember, that 'your_fiscal_month', must be in 'financial format', meaning that its length is 3 and not 2 as usual. Remember to also populate the 'your_fiscal_variant', without this, the program will return with an exception error most likely.

This function will return 'output_last_day_of_period', and you can use this value to populate your calday in the transformation rules / transfer rules as you like!

Presto! That's easy isn't it?

SAP BW Customer Enhancement (CMOD)

When I started to 'play' around with SAP Business Warehouse (BW aka BI), I thought that I would forever leave the role as a "programmer" behind. I thought, finally, I can concentrate more on "configuration" and "designing".

Well today proves that inevitably, it all boils down to good ol' hacks. You see, I want to create this report which includes a Quarter-to-date (QTD) columns. But, instead of creating a variable where the user enters which quarter the month resides in, I want to be able to use the existing 0FISCPER variable already created previously. So, what I need to do is create a customer Exit variable which will take the value of 0FISCPER variable, and find the appropriate QTD range.

Unfortunately, this customer Exit, can only be created using ABAP codes, and not just a simple Formula thingy. So here's what I did:


  • Went into SAP enhancement screen (T-code: CMOD) and create a new project.
  • Add the following enhancement assignment: RSR00001 (Enhancements for global variables in reporting)
  • Adopt the existing include sample functions and start changing the include file 'ZXRSRU01'.

Here's some descriptive info on what you need to do in the function:

I_VNAM: The variable name.
i_t_var_range: contains all the information about the other query variables available in BW.
l_s_range_low: Is the low limit value of the variable. For non-interval variable, this is the value.
l_s_range_high: Is the high limit value of the variable. Make sense only for interval type variables.
l_s_range-sign: denotes whether it's 'I' inclusive, or 'E' exclusive. Again, make sense for interval type only.
l_s_range-opt: what type of variable, either 'EQ' equal-type, or 'BT' between-type (interval).

Another lesson that I learn in ABAP is that:

some_variable = A + B

not equal to:

concatenate A B into some_variable

In other words, string not the same as add operation. I assumed it's like Java fixed string, which is not.

All in all, it's a good experience :)