8 Replies Latest reply: Apr 5, 2012 4:53 AM by SAP BI Learner

# Converting date interval into number key figure from variable selection  screen

Currently Being Moderated

Hi

I have requirement to get the number of days and days left in a report. This value should come from user input in variable selection screen.

For example: User select this date interval 01.03.2012 - 29.03.2012 ( = 29 days - number of fays)

and also I will get the number of days left for this month ( march )  2 days

I would like to get the values of number of days and number of days left from the user variable selection so I could calculate the amount by dividing the days with amount and gross sales

Example of my requirement

I

Amount Gross SalesNumber of daysnumber of days left
Product 110050292
Product 210050292
Product 310050292

Customer exit for the variable selection

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

IF i_step = 2.

CASE i_vnam.

*   To get current year date
WHEN 'ZC_DAY.

LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZCALENDAR'.
CLEAR: l_s_range.
ZT_DT1 = loc_var_range-low.
ZT_DT2 = loc_var_range-HIGH.
CALL FUNCTION 'DATE_CREATE'
EXPORTING
ANZAHL_JAHRE = 0
ANZAHL_KALTAGE = 0
ANZAHL_MONATE = 0
ANZAHL_TAGE = 0
DATUM_EIN = ZT_DT1
* DATUM_EIN_ULT = ' '
* ULTIMO_SETZEN = ' '
IMPORTING
DATUM_AUS = ZFIDAY .
* E_TT =
* E_ULTKZ =
CALL FUNCTION 'DATE_CREATE'
EXPORTING
ANZAHL_JAHRE = 0
ANZAHL_KALTAGE = 0
ANZAHL_MONATE = 0
ANZAHL_TAGE = 0
DATUM_EIN = ZT_DT2
* DATUM_EIN_ULT = ' '
* ULTIMO_SETZEN = ' '
IMPORTING
DATUM_AUS = ZLSDAY.
* E_TT =
* E_ULTKZ =
l_s_range-low = ZFIDAY .
l_s_range-high = ZLSDAY .
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
APPEND l_s_range TO e_t_range.

ENDLOOP.

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

thanks

Bhat

• ###### Re: Converting date interval into number key figure from variable selection  screen
Currently Being Moderated

Hi ,

U can find the No. of days by just substracting the first date with the last date.

and if u want to find the no.  of days left then it is better to follow the below logic .

fdate = loc_var_range-low.

ldate = loc_var_range-high.

data d1 type d.

d1 = ldate.

d1+6(2) = '01'.

d1 = d1 + 33.

d1+6(2) = '01'.

data no_of_days type n.

no_of_days = d1 - ldate.

Apply the logic in ur scenario , never try to call the function module for simple calculation also , that will degrade the loading performance.

Hope u got it,

Regards,

RaviChandra

• ###### Re: Converting date interval into number key figure from variable selection  screen
Currently Being Moderated

Hi,

Instead of writing all that lengthy code i can give you simple solution for finding the number of days difference based on user input.

Steps to be followed:

1. Create on formula variable say F1
2. In general tab----Global settings----Processing by Replacement path------Reference characteristic 0CALDAY.
3. Replacement path tab-----Replace variable with ---Variable
4. Give the technical name of User input variable created on 0CALDAY.
5. Use interval---Select the radio button Difference.
6. Currency/Unit tab---Dimension----Number

Save the formula variable and use it in your formula.This will give you the difference of days based on user entry.

I have tested it on my system and it works absolutely perfect.

Give a try to this solution for your other column also i ll provide you a workaround once you are done with it.

Hope that helps.

Regards,

AL

• ###### Re: Converting date interval into number key figure from variable selection  screen
Currently Being Moderated

Hi al,

Then where to pass the the first and last date that we give in the variable selection screen .

It looks to be interesting have to check .

Regards,

RaviChandra

• ###### Re: Converting date interval into number key figure from variable selection  screen
Currently Being Moderated

Hi Ravi,

In interval i have asked to select the radio button difference so whatever the value user will input in lower and upper limit it,the formula variable will calculate the difference based on the entered dates.During run time and it will give  the difference.

This is really amazing way after taking a look on that requirement it clicked me to try that way and it worked.

Hats off to SAP.

Regards, AL

• ###### Re: Converting date interval into number key figure from variable selection  screen
Currently Being Moderated

Hi AnshuL,

I have a query regard using the FYPER to retrieve the data for YTD. I saw your reply thinking that you can solve my issue as I see you have more ideas..

Also I want to know hoW to create MANUAL VARIABLE from REPLACEMENT VARIABLE..is it possible? I see not possible..

HI ALL SORRY INTERRUPT THE THREAD..

• ###### Re: Converting date interval into number key figure from variable selection  screen
Currently Being Moderated

Hi,

Thanks alot, Your method worked very well. What  I need now is how to get the number of days in a month for example.

If the start date is 02.04.2012 then I should get 31 days for April. I think I need user exit for it.

still looking for a function module in BW to get the number of days in a month.

thanks

• ###### Re: Converting date interval into number key figure from variable selection  screen
Currently Being Moderated

Hi,

As i mentioned in my last post for your other requirement also i would provide you easy solution.

SAP has delivered so many options in standard content itself,so code or exits should be the last option to hop on.

For getting number of days in a month you can make use of 0NUMDAY which is an attribute of 0CALMONTH.

If in case you don't find that in attributes tab of 0CALMONTH then you can install the same from BI Content and make use of it in your query.

Hope it suffice your requirement completely.

Regards,

AL

• ###### Re: Converting date interval into number key figure from variable selection  screen
Currently Being Moderated

Hi,

My requirement changed a bit. instead of using 0calday, I am now using 0FISCPER.

so whenever the user select a fiscal period e.g 004.2012

it should calculate the following :

- number of days between current date and begining of fiscal period i.e 04.04.2012 - 01.04.2012 = 3 days

- Number of days in the period / month of April = 30 days

I have now created two new formulas and included 2 customer exit variables and always get Abap debug error when I execute the report in RSRT. The logic to get the number of days in month / period is not working

Number of days = ZNUM_DAY

Number of days in a month = ZNUM_MONTH

i have now included the customer exit for the variables

* Number of days between two dates

data num_day type i.

data num_day_month  type i.

WHEN 'ZNUM_DAY'.
IF i_step = 2.
sdate = sy-datum.
sdate+6(2) = '01'.

edate = sy-datum.

CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
EXPORTING
I_DATE_FROM = sdate " start date
I_DATE_TO = edate "current date
IMPORTING
E_DAYS = num_day.
l_s_range-low = num_day.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
append l_s_range to e_t_range.
ENDIF.

* number of days in a month
WHEN 'ZC_NUM_DAYS_MONTH'.

CALL FUNCTION '/OSP/GET_DAYS_IN_MONTH'
EXPORTING
IV_DATE = sy-datum

IMPORTING
EV_DAYS = num_day_month.

l_s_range-low = num_day_month.

l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
append l_s_range to e_t_range.

how do I resolve it.

Bhat.