Application Development and Automation 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: 
Read only

looking for FM

Former Member
0 Likes
597

i need a FM that i give the number of month 01,02....

and i get the date start and end date

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
564

You can do something like this, but you can't just use the month, you must know the year as well. Here you can see that we take the parameter date, and force that date to the 1st day of that month/year, then use this date to find the end of the month.




report zrich_0001 .


parameters: p_datum type sy-datum.

data: begin_date type sy-datum,
      end_date type sy-datum.

begin_date = p_datum.
begin_date+6(2) = '01' .

call function 'LAST_DAY_OF_MONTHS'
     exporting
          day_in            = begin_date
     importing
          last_day_of_month = end_date.


write:/ begin_date, end_date.

Regards,

Rich Heilman

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
565

You can do something like this, but you can't just use the month, you must know the year as well. Here you can see that we take the parameter date, and force that date to the 1st day of that month/year, then use this date to find the end of the month.




report zrich_0001 .


parameters: p_datum type sy-datum.

data: begin_date type sy-datum,
      end_date type sy-datum.

begin_date = p_datum.
begin_date+6(2) = '01' .

call function 'LAST_DAY_OF_MONTHS'
     exporting
          day_in            = begin_date
     importing
          last_day_of_month = end_date.


write:/ begin_date, end_date.

Regards,

Rich Heilman

Read only

0 Likes
564

hi,

Check this out

use FM

<b>'LAST_DAY_OF_MONTHS'</b>

Regards,

Santosh

Read only

0 Likes
564

FM "HR_JP_MONTH_BEGIN_END_DATE" (<u><b> get begin date and end date of a month)</b></u>

call function 'HR_JP_MONTH_BEGIN_END_DATE'

exporting

iv_date = ld_new_date

importing

ev_month_begin_date = s_begda-low

ev_month_end_date = s_begda-high.

Hope this’ll give you idea!!

<b>P.S award the points.!!! !!!</b>

Good luck

Thanks

Saquib Khan

"Some are wise and some are otherwise"

Read only

nablan_umar
Product and Topic Expert
Product and Topic Expert
0 Likes
564

Hi Liat,

Date field in SAP is stored with YYYYMMDD(8 characters field). So to find the month, look at position 5th and 6th of the field.

Month = GV_DATE+4(2).

To get the first date of the month, set position 7th and 8th as '01'.

GV_DATE+6(2) = '01'.

FirstDate = GV_DATE.

To get the last date of the month, add 31 days to the first date of the month, then set position 7th and 8th as '01', lastly deduct the date by 1.

NextMonth = FirstDate + 31.

NextMonth+6(2) = '01'.

LastDate = NextMonth - 1.

Read only

0 Likes
564

Please award points !!!

Thanks

SK