Pages

Wednesday 28 August 2013

BEx Reporting on 12 Months Rolling Periods using Posting Period (0FISCPER3)


Introduction


Here is the description of scenario. Your organization needs to do reporting on last one year data but on rolling period basis. That means user will input any month/year combination and starting from that month/year, you will have to report on previous 12 months. And you have come to know that it is not straight forward as instead of fiscal year/period (0FISCPER), your info provider contains fiscal year (0FISCYEAR) and posting periods (0FISCPER3). So below are the steps to follow and successfully achieve the desired result.


Frontend Setting

First of all you need to design your query in such a way that it can provide the right platform to achieve the desired output. Basic requirement for report is that user needs to input at least one month/year combination. For this you will require two user defined variables. Create them as below.

Create variables for posting period (0FISCPER3)


Create a variable named ZPER_P0 for posting period to store the initial value input by user as per below specifications using create variable wizard.
  1. Variable Type: Characteristic Value
  2. Processing Type: User Entry/Default Value
  3. Variable Entry: Mandatory
  4. Ready for Input selected
 
Now, create another 11 variables named ZPER_P1 to ZPER_P11 for posting period to store the rest of eleven values calculated automatically as per below specifications using create variable wizard.
  1. Variable Type: Characteristic Value
  2. Processing Type: Customer Exit
  3. Variable Entry: Mandatory
  4. Ready for Input
NOT selected  

Create variables for fiscal year (0FISCYEAR)

Create a variable named ZFYR_Y0 for fiscal year to store the initial value input by user as per below specifications using create variable wizard.
  1. Variable Type: Characteristic Value
  2. Processing Type: User Entry/Default Value
  3. Variable Entry: Mandatory
  4. Ready for Input selected
 
Now, create another 11 variables named ZFYR_Y1 to ZFYR_Y11 for fiscal year to store the rest of eleven values calculated automatically as per below specifications using create variable wizard.
  1. Variable Type: Characteristic Value
  2. Processing Type: Customer Exit
  3. Variable Entry: Mandatory
  4. Ready for Input
NOT selected
This finishes our front-end setting. Now it is time to fill those customer exit variables. Follow the below section of backend setting.

Backend Setting


Now we have created the necessary variables to do reporting on rolling periods. We have created one user entry variable for both posting period and fiscal year and eleven customer exit variable for both posting period and fiscal year. To fill those customer exit variable, now we need to write the code in RSR00001 exit (Customer Exit Global Variables in Reporting). To accomplish this task basic knowledge of ABAP is required. Follow the below steps to fill the values for variables.
  1. Create a project in CMOD (if you do not have any)
  2. Assign the enhancement RSR00001 to the project
  3. Save and activate the project
  4. Go to SMOD transaction
  5. Select RSR00001 as enhancement
  6. Select components and click Display
  7. Double click on EXIT_SAPLRRS0_001 function module
  8. Double click on ZXRSRU01 include
 
A code editor screen will appear; click on Change button icon to enable the code editor for input.


Logic for filling Posting Period Values


Now we want to fill the rest of the eleven posting period variables ZPER_P1 to ZPER_P11 in rolling back fashion. That means if user inputs value of posting period variable at selection screen as ‘003’ (March), than ZPER_P1 should have ‘002’ (February), ZPER_P2 should have ‘001’ (January), ZPER_P3 should have ‘012’ (December, of previous year) and so on.
To accomplish the above task logic is given below.
Step 1: Read the user input value at selection screen for first posting period variable i.e. ZPER_P0
Step 2: Subtract the index number of current processing variable from the user input value (Refer to code)
Step 3: If the subtraction is less than 1 than add 12 to the result
Step 4: Assign the result as value to currently being processed customer exit variable for posting period

Sample code for ZPER_P1 posting period variable


read table i_t_var_range into loc_var_range with key vnam = 'ZPER_P0'. "(Reference to step 1)
if sy-subrc = 0.
per = loc_var_range-low.
endif.
nper = per+58(2).
nper = nper - 1. "(reference to step 2, here 1 is subtracted because ZPER_P1)
if nper < 1.
nper = nper + 12. "(Reference to step 3)
endif.
per = nper.
lastper = per.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
l_s_range-low = lastper+57(3). "(Reference to step 4)
append l_s_range to e_t_range.


Logic for filling Fiscal Year Values

At this point we have filled correctly the posting period values but what about the corresponding year values. We also need to fill these fiscal year values correctly. For example, if month is getting changed from January to December than year should also change from 2008 to 2007. Now we will see in the following section how we populate ZFYR_Y1 to ZFYR_Y11 fiscal year variables.
To accomplish the above task, logic is given below.
Step 1: Read the user input value at selection screen for first fiscal year variable i.e. ZFYR_Y0
Step 2: Read the user input value at selection screen for first posting period variable i.e. ZPER_P0
Step 3: Subtract the index number of current processing variable from the user input value of posting period (Refer to code)
Step 4: If the result of posting period subtraction is less than 1 than subtract the fiscal year value by 1 (fiscal year is subtracted always by 1 for all variables created on fiscal year).
Step 5: Assign the new fiscal year value to currently being processed customer exit variable for fiscal year

Sample code for ZFYR_Y1 posting period variable

read table i_t_var_range into loc_var_range with key vnam = 'ZFYR_Y0'. "(Reference to step 1)
if sy-subrc = 0.
l_fiscyear = loc_var_range-low.
read table i_t_var_range into l_posper_rng with key vnam = 'ZPER_P0'. "(Reference to step 2)
if sy-subrc = 0.
l_posper_rng-low = l_posper_rng-low - 1. "(Reference to step 3)
if l_posper_rng-low < 1. "(Reference to step 4)
l_fiscyear = l_fiscyear - 1. "(Reference to step 5)
endif.
endif.
endif.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
l_s_range-low = l_fiscyear.
append l_s_range to e_t_range.


Create similar codes for rest of the variables for posting period and fiscal year. Do not forget to keep in mind the number of posting period or fiscal year variable you are processing e.g. index number of variable ZPER_P3 is 3.
Save and activate the code and project and now you are ready to report on rolling periods.

Enhancements
  • You can also use function module to omit the repeated block of logic e.g. subtracting the value from posting period variable
  • You can also use text variables to display the descriptive titles for month names like February, January etc. instead of pure numbers like 2, 1 etc. in the report output.
  • No comments:

    Post a Comment