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: 

Get dates from particular month and year....

former_member214928
Participant
0 Kudos
460

I need to get all the dates from particular month and year.

Input : Year & Month

Output: All the dates of that particular month & year selected.

Is there any FM provided by SAP or if you have fulfilled such kind of requirement kindly provide the code or guide me through it.

Please reply ASAP

1 ACCEPTED SOLUTION

former_member189849
Contributor
0 Kudos
338

Hi rahul,

Just copy the below code and run it and i hope it will help to you and its simple to understand or if you want only fm just this code convert to fm use as like as FM. 

PARAMETERS : p_month(2) TYPE n,

              p_year(4) TYPE n.

DATA: w_date TYPE d,

       w_offset TYPE i.

w_date+6(2) = '01'.

w_date+0(4) = p_year.

w_date+4(2) = p_month.

WRITE : / 'Month;',p_month , 40 'Year :' ,  p_year.

SKIP 3.

ULINE.

WRITE : /5 'Sun' , 10 'Mon' , 20 'Tue' ,30 'Wed' , 40 'Thu' , 50 'Fri' , 60 'Sat'.

SKIP.

WHILE w_date+4(2) = p_month.

   w_offset =  w_date  MOD 7.

   CASE w_offset.

     WHEN 1.

       WRITE : / w_date+6(2) UNDER 'Sun'.

     WHEN 2.

       WRITE :  w_date+6(2) UNDER 'Mon'.

     WHEN 3.

       WRITE :  w_date+6(2) UNDER 'Tue'.

     WHEN 4.

       WRITE :  w_date+6(2) UNDER 'Wed'.

     WHEN 5.

       WRITE :  w_date+6(2) UNDER 'Thu'.

     WHEN 6.

       WRITE :  w_date+6(2) UNDER 'Fri'.

     WHEN 0.

       WRITE :  w_date+6(2) UNDER 'Sat'.

   ENDCASE.

   w_date = w_date + 1.

ENDWHILE.

****

If you have any q's let me know.

Regards

Mahesh

5 REPLIES 5

amol_samte
Contributor
0 Kudos
338

Hi Rahul,

Use below FM u can get last day of month and year....once u got last day then u can calculate dates in months.

RP_LAST_DAY_OF_MONTHS

Regards,

Amol.

former_member282968
Contributor
0 Kudos
338

Hi Rahul,

Use DAY_ATTRIBUTES_GET give the inputs FACTORY_CALENDAR ( For India:IN),DATE_FROM and  DATE_TO ( for year and month give  for ex: from 01.10.2012 to 31.10.2012). The FM will list all the dates, weekday, day string and also holiday.

With regards,

Former Member
0 Kudos
338

Hi,

You can concatenate 01,month and year which becomes your first day of the month.

For last day you can use the FM RP_LAST_DAY_OF_MONTHS. as below:

concatenate '01' month year separated by '/' into first_date.

  CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'

       EXPORTING

            day_in            = first_date

       IMPORTING

            last_day_of_month = last_date.

Now you have the last date and the first date so you can get all the dates in between.

Hope it serves useful to you.

former_member189849
Contributor
0 Kudos
339

Hi rahul,

Just copy the below code and run it and i hope it will help to you and its simple to understand or if you want only fm just this code convert to fm use as like as FM. 

PARAMETERS : p_month(2) TYPE n,

              p_year(4) TYPE n.

DATA: w_date TYPE d,

       w_offset TYPE i.

w_date+6(2) = '01'.

w_date+0(4) = p_year.

w_date+4(2) = p_month.

WRITE : / 'Month;',p_month , 40 'Year :' ,  p_year.

SKIP 3.

ULINE.

WRITE : /5 'Sun' , 10 'Mon' , 20 'Tue' ,30 'Wed' , 40 'Thu' , 50 'Fri' , 60 'Sat'.

SKIP.

WHILE w_date+4(2) = p_month.

   w_offset =  w_date  MOD 7.

   CASE w_offset.

     WHEN 1.

       WRITE : / w_date+6(2) UNDER 'Sun'.

     WHEN 2.

       WRITE :  w_date+6(2) UNDER 'Mon'.

     WHEN 3.

       WRITE :  w_date+6(2) UNDER 'Tue'.

     WHEN 4.

       WRITE :  w_date+6(2) UNDER 'Wed'.

     WHEN 5.

       WRITE :  w_date+6(2) UNDER 'Thu'.

     WHEN 6.

       WRITE :  w_date+6(2) UNDER 'Fri'.

     WHEN 0.

       WRITE :  w_date+6(2) UNDER 'Sat'.

   ENDCASE.

   w_date = w_date + 1.

ENDWHILE.

****

If you have any q's let me know.

Regards

Mahesh

former_member189849
Contributor
0 Kudos
338

your requirement is fulfilled or not if not ask the questions or fulfilled just close the thread.

Regards

Mahesh