How to use ABAP routine in Infopackage, where Fiscal month range is based on current month.
The Scenario
In R/3, a custom table is created which will be loaded by some calculation. Client wants to create process chain which will run automatically on every end of the month. The problem in Automation is that client have different selection on different month. Following are the conditions on different months.
Example |
|||||
Current Month |
FISCPER from |
FISCPER to |
Current Month |
FISCPER from |
FISCPER to |
Jan |
Nov |
|
Jan-11 |
011/2010 |
|
Feb |
no action |
|
Feb-11 |
000/1900 |
|
Mar |
no action |
|
Mar-11 |
000/1900 |
|
Apr |
Dec |
Feb |
Apr-11 |
012/2010 |
002/2011 |
All other months |
Current – 2 |
|
May-11 |
003/2011 |
|
The another problem is it is based on Fiscal period ‘K4’ which have 16 fiscal periods. If we give only one month then it will miss special months from 13 to 16.
Solution
To solve this problem and to make the dynamic selection, we write the ABAP routine in InfoPackage selection.
Create Infopackage with full load. In selection option write ABAP routine for FISCPER.
This is an example of a code sample:
//This is a code sample block
* Insert source code to current selection field
*$*$ begin of routine – insert your code only below this line *-*
data: l_idx like sy-tabix,
lv_dateN LIKE sy-datum,
lv_dateL LIKE sy-datum,
lv_lasttolast LIKE sy-datum.
DATA: lastday TYPE i.
data: currentmonth TYPE i,
febdays TYPE i,
feblastday LIKE sy-datum.
DATA: v_fscprN TYPE t009b-poper,
v_fscyrN TYPE t009b-bdatj,
v_fiscperN TYPE /BI0/SFISCPER-FISCPER,
v_fscprL TYPE t009b-poper,
v_fscyrL TYPE t009b-bdatj,
v_fiscperL TYPE /BI0/SFISCPER-FISCPER.
read table l_t_range with key
fieldname = ‘FISCPER’.
l_idx = sy-tabix.
*….
CLEAR l_t_range-high.
CLEAR lv_dateN.
CLEAR lv_dateL.
* This will extract the current month from the current date.
currentmonth = sy-datum+4(2).
* This function gets the last day of the month.
CALL FUNCTION ‘SLS_MISC_GET_LAST_DAY_OF_MONTH’
EXPORTING
DAY_IN = sy-datum
IMPORTING
LAST_DAY_OF_MONTH = lv_dateN
.
* This function gets the last day of the last month. Here we get the last two months
CALL FUNCTION ‘SLS_MISC_GET_LAST_DAY_OF_MONTH’
EXPORTING
DAY_IN = lv_dateN
IMPORTING
LAST_DAY_OF_MONTH = lv_lasttolast
.
* Creating dates on based of above conditions given in Table.
IF currentmonth = 1.
lv_dateL = lv_dateN – lv_dateN+6(2) – 31.
lv_dateN = lv_dateN – lv_dateN+6(2) – 31.
elseif currentmonth = 2.
lv_dateL = ‘19000101’.
lv_dateN = ‘19000101’.
elseif currentmonth = 3.
lv_dateL = ‘19000101’.
lv_dateN = ‘19000101’.
elseif currentmonth = 4.
lv_dateL = lv_dateN – lv_dateN+6(2) – 31.
CALL FUNCTION ‘SLS_MISC_GET_LAST_DAY_OF_MONTH’
EXPORTING
DAY_IN = lv_dateL
IMPORTING
LAST_DAY_OF_MONTH = feblastday.
febdays = feblastday+6(2).
lv_dateL = lv_dateN – lv_dateN+6(2) – 31 – febdays – 31.
lv_dateN = lv_dateN – lv_dateN+6(2) – 31.
- else.
* This line will subtract the total no of day in current month so it will give previous
* month’s last date.
lv_dateL = lv_dateN – lv_dateN+6(2) – lv_lasttolast+6(2).
* This line will add 1 day in the last day of
* the current month, give the next month.
lv_dateN = lv_dateN – lv_dateN+6(2) – lv_lasttolast+6(2).
- endif.
*———————————————————————–
*convert dates in Period…..
CALL FUNCTION ‘DATE_TO_PERIOD_CONVERT’
EXPORTING
I_DATE = lv_dateL
I_PERIV = ‘K4’
IMPORTING
E_BUPER = v_fscprL
E_GJAHR = v_fscyrL.
CONCATENATE v_fscyrL v_fscprL INTO v_fiscperL.
CALL FUNCTION ‘DATE_TO_PERIOD_CONVERT’
EXPORTING
I_DATE = lv_dateN
I_PERIV = ‘K4’
IMPORTING
E_BUPER = v_fscprN
E_GJAHR = v_fscyrN.
CONCATENATE v_fscyrN v_fscprN INTO v_fiscperN.
*———————————————————————–
l_t_range-low = v_fiscperL.
l_t_range-option = ‘BT’.
l_t_range-high = v_fiscperN.
modify l_t_range index l_idx.
p_subrc = 0.
New NetWeaver Information at SAP.com
Very Helpfull