on 01-06-2016 7:30 AM
Hi All
Can you please help me writing a piece of ABAP code, which I will have to use in DTP filter?
In my filter I have few restrictions, but one of them will have to be dynamic.
I need to take only values from April (04) to December (12) for current year. So for example in this year values which should be moved from one cube to another are only those, for which version is equal or grater to 04.2016. Of course the highest and equal values will be 12.2016
Next year values to be taken are from 04.2017 up to 12.2017 ( including 04 and 12) and so far.
I started by writing that:
data: v_month_min type /BI0/OICALMONTH.
data: v_month_max type /BI0/OICALMONTH.
l_t_range-sign = 'I'. * is integer
l_t_range-option = 'BT'. * take only values in between as defined below
l_t_range-low = v_month_min. * assign low value
v_month_min = ‘04’. * lowest value is month 04 (April)
l_t_range-high = v_month_max. * assign the highest value
v_month_max = ‘12’. * highest value is month 12 (December)
but I do not know what should be next.
Probably something like:
....
l_t_range-low = sy-datum+2(4).
......
Can you please help me finish it, probably there is a smarter way to have that code.
Thank you in advance for help.
BR
Michal
Hi Michal,
Your DTP filter routine for 0CALMONTH could look as follows:
* Local data declaration
DATA:
l_calmonth_low TYPE /bi0/oicalmonth,
l_calmonth_high TYPE /bi0/oicalmonth,
l_s_range TYPE rssdlrange.
* Initialization
CLEAR:
l_calmonth_low,
l_calmonth_high,
l_s_range.
* Prepare calendar month range
concatenate sy-datum+0(4) '04' into l_calmonth_low.
concatenate sy-datum+0(4) '12' into l_calmonth_high.
* Fill calendar month range
l_s_range-fieldname = i_fieldnm.
l_s_range-sign = rs_c_range_sign-including.
l_s_range-option = rs_c_range_opt-between.
l_s_range-low = l_calmonth_low.
l_s_range-high = l_calmonth_high.
APPEND l_s_range TO l_t_range.
* Set return code to OK
p_subrc = 0.
Best regards,
Sander
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sander
Thanks. it is very usefull.
I already spend some time and did that:
l_t_range-option = 'BT'.
"take only values in between as defined below
l_t_range-fieldname = 'CALYEAR'.
l_t_range-iobjnm = '0CALYEAR'.
l_t_range-low = sy-datum+0(4).
l_t_range-high = sy-datum+0(4).
"take calendar year, and skip day and month, format is: 2016.01.06
Concatenate l_t_range-low '04' into v_month.
"combine minimum version for April (04) and current year
l_t_range-low = v_month.
BREAK-POINT.
Concatenate l_t_range-high '12' into v_month.
" combine maximum version for December (12) and current year
l_t_range-high = v_month.
seems to be working, but I am still testing it.
Thanks again.
If my code will not work I will use yours.
BR
Michal
Your comment "take calendar year, and skip day and month, format is: 2016.01.06 is misleading and should be removed or amended. The internal representation of date types (and as you've used in your code) is 20160106. Misleading comments lead to maintenance errors and are dangerous.
fyi, as a programmer of far too many years experience in ABAP and BW, this is how I would do it.
data: date_range like line of l_t_range.
date_range-sign = rs_c_range_sign-including.
date_range-option = rs_c_range_opt-between.
date_range-fieldname = 'CALYEAR'.
date_range-iobjnm = '0CALYEAR'.
date_range-low = substring( val = sy-datum len = 4 ) && '04'. " April of current year
date_range-high =substring( val = sy-datum len = 4 ) && '12'. " December of current year
APPEND date_range TO l_t_range.
The reasons are
1. It is shorter and simpler and, in my view clearer. Clear, simple programming is cheaper and quicker to maintain. "It works" is not a sufficient criterion.
2. String slicing using sy-datum(4) etc. has problems - in some circumstances (assignment) it becomes syntactically incorrect in higher releases of ABAP.
This is incorrect:
l_t_range-sign = 'I'. * is integer
The I indicates that the range is inclusive. If it was E then it would be everything not between low and high.
Have you read the ABAP help on:
RANGES
String operations?
If you are going to be writing routines etc. in ABAP I strongly suggest you buy a book on ABAP programming and work through it (or get your employer to send you on a course). You can hardly be effective if you have to be given guidance on very basic ABAP operations.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.