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: 

How to get month last date and first date without FM's

Former Member
0 Kudos

Hi Guru's,

How can we get month's first date and last date based on the date given in selection screen without FM's?Is it possible ?

Like if i give 05-Oct-2008 in the selection screen, i should get the output as 01-Oct-2008 to 31-Oct-2008.Without FM's???

Regards

Rakesh.

7 REPLIES 7

vinod_vemuru2
Active Contributor
0 Kudos

Hi Rakesh,

Why do u want to put ur own logic when SAP has already given

the functionality with the beauty of FMs. In fact u can find the first date of the month as it will be always 01.

From ur selectionscreen value get the month and year and get the first date like this.

eg: po_date = 20081005

then po_date+0(6) gives u YYYYMM value.

CONCATENATE po_date+0(6) '01' INTO l_date.

But for last date it is difficult to put ur logic because of leap year concept. Feb month may contain 28/29 days.

So better make use of standard functionality when it is available which takes care of all these things.

Thanks,

Vinod.

karol_seman
Active Participant
0 Kudos

Hi Rakesh,

it is simple, for first day always use 01 as substitution. For last day just create one internal table which has first field value from 1 to 12 and second field values 28, 30, 31 depending which month it is. Then just take substring sy-datum+4(2) and read with this internal table matching first field and substitute day in the date as value ftom the table second field.

This you can do for all months but February. For this month just do year sy-datum(4) modulo 4 and if you get 0 then use 29 otherwise 28.

Regards,

Karol

P.S.: Please close your answered questions. The ratio 49/49 is not nice and can happens that nobody will answer you ...

Former Member
0 Kudos

How is it possible that someone doesn't know how to determine the first and last date of a month? Is it really that difficult?

Former Member
0 Kudos

Why must it be without FMs? Is this an interview question?

Cheers,

Julius

Former Member
0 Kudos

Hi Rakesh

Last date is also simple..

Acc to ur example, s_date = 20081005

First date of current month , v_date = s_date+6(2) = '01'

Find the first date of next month as follows...

(31 is added as its the max num of days in a month)

v_date = v_date + 31

v_date+6(2) = '01'

This will be the first date of next month..

now

v_date = v_date - 1...

SO... v_date now contains the last date of current month...

Hope its explanatory...

Former Member
0 Kudos

Hi Rakesh,

You can implement this logic as follows:

You can have two internal tables, one containing the days as numbered 31, 28, 31, and so on with the month number. This holds good if the year is a common year. Another internal table contains days as numbered 31, 29, 31 and so on with the month number. This year would be a leap year.

An year can be calculated depending on the conditions:

Say date is given as 20081008

Concatenate 20081001 + 0(4) into l_date.

Divide l_date by 4 and remainder should be equal to 0.

Divide l_date by 400 and remainder should also be equal to 0.

Then the dominical year will be a leap year.

Now, if l_date divided by 100 and the remainder is 0 then the year is a common year.

So depending on this populate the first date and last date from the respective internal table

Regards,

Sumalatha N.

0 Kudos

Itzzzz nt that hard....

simplest logic is, last date of current month = first day of next month - 1 ...

( and look at my previous reply for finding the first day of next month...

And this works perfectly with the year change and leap years and everything.... )