Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

no of days from calmonth

Former Member
0 Kudos
270

Hello gurus,

Is there a SAP Exit or function module that returns the no of days based on cal month or fiscal period?

Thank you,

Malli

1 ACCEPTED SOLUTION

Former Member
0 Kudos
94

Hi,

Check RP_CALC_DATE_IN_INTERVAL which will count number of days between given dates.

Also check SE37 and search with values:

DAYS

DATE

Regards,

Ville

13 REPLIES 13

Former Member
0 Kudos
95

Hi,

Check RP_CALC_DATE_IN_INTERVAL which will count number of days between given dates.

Also check SE37 and search with values:

DAYS

DATE

Regards,

Ville

0 Kudos
94

Hi Ville,

We in BW have a requirement to extract no of days based on a fisc period (0fper) value that the user enters - stored like 2005002.

I also checked SE37. There are no modules that return no. of days based on fisc period or cal month.

Would appreciate your advice.

Thank you,

Malli

0 Kudos
94

Hi Malli,

Maybe this will help you out:

Regards,

Ville

Former Member
0 Kudos
94

Hi,

Try :

  • Calculate the number of days in the month.

CALL FUNCTION 'HR_E_NUM_OF_DAYS_OF_MONTH'

EXPORTING

p_fecha = l_date

IMPORTING

number_of_days = l_number_of_days

EXCEPTIONS

OTHERS = 1.

regards

Aveek

0 Kudos
94

Hi Aveek,

I am an ABAP illiterate. Should I create a module for this code with variable declarations etc? Can you pls throw more light on it?

Thank you,

Malli

0 Kudos
94

Hi,

We use it to calculate start and end dates.

DATA: l_date TYPE d, "Date to calc number of days in month

l_number_of_days TYPE p. "Number of days in specified month

  • Create a date from the selection screen month and year. This date will be used to determine the number of days in the month.

l_date+0(4) = p_ems_year.

l_date+4(2) = p_ems_month.

l_date+6(2) = '01'.

  • Calculate the number of days in the month.

CALL FUNCTION 'HR_E_NUM_OF_DAYS_OF_MONTH'

EXPORTING

p_fecha = l_date

IMPORTING

number_of_days = l_number_of_days

EXCEPTIONS

OTHERS = 1.

  • Specify the begin and end date to be used when processing the EMS.

g_month_begda+0(4) = p_ems_year.

g_month_begda+4(2) = p_ems_month.

g_month_begda+6(2) = '01'.

g_month_endda+0(4) = p_ems_year.

g_month_endda+4(2) = p_ems_month.

g_month_endda+6(2) = l_number_of_days.

  • Move the period end date to the electronic file header.

MOVE: g_month_endda TO pos_header-endda,

g_month_endda TO neg_header-endda.

  • Format dates for display.

WRITE: g_month_begda TO g_formatted_begda DD/MM/YYYY,

g_month_endda TO g_formatted_endda DD/MM/YYYY.

0 Kudos
94

Aveek,

Thank you so much for the code. Unfortunately, the function 'HR_E_NUM_OF_DAYS_OF_MONTH' doesn't exist in the BW system.

I think I need to create an enhancement in cmod. I'm not sure how to go about it.

Malli

0 Kudos
94

Hi,

Try this link and reward with points if useful.

http://www.sappoint.com/abap/userexit.pdf

regards

Aveek

0 Kudos
94

It is indeed a useful document. Appreciate your help. I have awarded points.

Malli

0 Kudos
94

If you want to use an FM I assume you are going to write some ABAP to call this.

For FISCPER, you can use FM UMC_HR_FISCPER_TO_DATE (available in BW). This will return the start date and end date of a fiscal period. You can simply deduct the startdate from the enddate (and add 1) to get the no of days in the FISC period.

If you have CALMONTH , you can add ABAP code as below to get the no of days.

Let us say your CALMONTH is in var W_month.

data : w_date1 like sy-datum,

w_date2 like sy-datum,

w_days type i.

concatenate w_month '01' into w_date1.

w_date2 = w_date1 + 31.

w_date2+6(2) = '01'.

w_days = w_date2 - w_date1.

  • W_days holds the no of days in the month, w_date1 is first day of Calmonth , and w_date2 is first day of next month.

cheers,

0 Kudos
94

Hi Ajay,

Thank you for the input.I accomplished this already, although in a roundabout way.

Probably what you are suggesting is the most efficient way to do that.

Appreciate it.

Malli

Former Member
0 Kudos
94

Hi,

You can also try this:

*MOVE YEAR VALUE TO A VARIABLE

MOVE: S_GJAHR-LOW TO V_YEAR,

P_MONTH TO V_MONTH.

*RETRIEVE NUMBER OF DAYS IN MONTH

CALL FUNCTION 'NUMBER_OF_DAYS_PER_MONTH_GET'

EXPORTING

PAR_MONTH = V_MONTH

PAR_YEAR = V_YEAR

IMPORTING

PAR_DAYS = V_DAYS.

IF S_GJAHR-LOW = SY-DATUM+0(4)

AND V_MONTH = SY-DATUM+4(2)

AND V_DAYS > SY-DATUM+6(2).

IF V_MONTH = '01'.

V_MONTH = '12'.

V_YEAR = SY-DATUM+0(4) - 1.

ELSE.

V_MONTH = V_MONTH - 1.

V_YEAR = SY-DATUM+0(4).

ENDIF.

CALL FUNCTION 'NUMBER_OF_DAYS_PER_MONTH_GET'

EXPORTING

PAR_MONTH = V_MONTH

PAR_YEAR = V_YEAR

IMPORTING

PAR_DAYS = V_DAYS.

ENDIF.

regards

Aveek

Former Member
0 Kudos
94

Hi Malli,

You might find this usefull too:

http://www.ecediltd.com/la/sap-r3-bw@openitx.com/1050.html

Regards,

Ville