cancel
Showing results for 
Search instead for 
Did you mean: 

How to count days in month and year in Query

Former Member
0 Kudos
468

Hi,

I have problem generate query report on counting days in month and year. My report has only fiscal year/period variable.

The report has a formula where figure need to multiply with days in month and year

Example:

Jan Feb March

Inventory (RM) 1000 2000 3000

Cost of Sales (RM) 100 200 300

No. of days in month 31 28 31

No. of days in year 365 365 365

YTD Cost of Sales 100 200100 300200+100

YTD No of Days 31 3128 3128+31

YTD Inventory days (1000/100)31 days [2000/(200+100)](31+28 days)

YTD Inventory turn 365/YTD Inventory days

Formula :

YTD Inventory days = (Monthly inventory / YTD Cost of sales) x YTD No. days in a year

YTD Inventory turns = 365 / YTD inventory days

Please advice me on the solution.

Thank you.

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Thank you, problem solved.

Former Member
0 Kudos

Hi Mansi Dandavate,

Thanks for the solution but i also needs to calculate YTD no. of days. Example if my input 02.2009 the days will calculate days in january and days in february such as 31+28 = 59. Do i need to create a new formula variable based on this, since the days in month also i need in the row?

Appreciate if you can give the solution.

Thanks.

mansi_dandavate
Active Contributor
0 Kudos

Yes you need to create a selection option variable with customer exit for this...

It will take lower limit as 1st Jan 2009 and upper limit as last day of feb 2009...You can use the same function module to find the last day of the month...

Former Member
0 Kudos

Hi Mansi Dandavate,

I manage to solve the problem for count days in month but not year. Could you provide me the coding for this. I'm using 0P_FPER period/fiscal year. I have this coding for count days in month.

CASE i_vnam. " Variablenname

WHEN 'ZNUMDAY'.

DATA: l_firstday LIKE SY-DATUM,

l_lastday LIKE SY-DATUM,

ws_year(4) type c,

ws_mth(2) type c.

DATA: l_number_of_days TYPE INT4.

DATA: loc_var_range LIKE rrrangeexit.

clear : ws_year, ws_mth.

IF i_step = 2.

LOOP AT i_t_var_range INTO loc_var_range

WHERE vnam = '0P_FPER'.

EXIT.

ENDLOOP.

ws_year = loc_var_range-low(4).

ws_mth = loc_var_range-low+5(2).

CONCATENATE ws_year ws_mth '01' INTO l_firstday.

  • CONCATENATE loc_var_range-low '01' INTO l_firstday.

CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH'

EXPORTING

DAY_IN = l_firstday

IMPORTING

LAST_DAY_OF_MONTH = l_lastday .

l_number_of_days = l_lastday - l_firstday.

l_number_of_days = l_number_of_days + 1.

CLEAR l_s_range.

l_s_range-low = l_number_of_days .

l_s_range-sign = 'I'.

l_s_range-opt = 'EQ'.

APPEND l_s_range TO e_t_range.

ENDIF.

ENDCASE.

mansi_dandavate
Active Contributor
0 Kudos

Hi,

Its simple...

Just use the same FM 'SLS_MISC_GET_LAST_DAY_OF_MONTH'

Pass the first day of february for your particular year to this FM...

Then it will return how many days are in february...

If its 28 the no of days in year is 365 and if its 29 then its 366...

mansi_dandavate
Active Contributor
0 Kudos

Hi,

You can create two formula variables to count no of days in a month and year and in the exit you can find out how many no of days are present in the year and month...

Use the following funtion module...This will give you the last day of the month...

For no of days in year just chk if feb has 28 or 29 days and accordingly the year will have either 365 or 366....

SLS_MISC_GET_LAST_DAY_OF_MONTH

Former Member
0 Kudos

Hi Ahmed,

I am not to understand the following values

YTD Cost of Sales 100 200100 300200+100

YTD No of Days 31 3128 3128+31

Plz explain in more details . so that i can to answer u r question

Regards

Ram.