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

Date calculation

rainer_hbenthal
Active Contributor
0 Likes
676

I need to do some date calculations. The programming is taking the current date and needs to build a date range. Starting date is first of current month. This is easy. Enddate ist last day of month +3. So starting in December, the date range needs to be

1.12.yyyy to 28.02.yyyy. According to leap years it meight be 29.02.yyyy. Is there an easy way to calaculate this without programming so much rules like month can have 28, 30 or 31 days or may be 29 is valid, too?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
633

Hello Rainer,

This is what u want.


DATA: LV_DATE LIKE SY-DATUM.
DATA: RA_DATE TYPE RANGE OF SY-DATUM  WITH HEADER LINE.
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
     EXPORTING
          DAY_IN            = DATE
     IMPORTING
          LAST_DAY_OF_MONTH = LV_DATE
     EXCEPTIONS
          DAY_IN_NO_DATE    = 1
          OTHERS            = 2.
IF SY-SUBRC <> 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
DATE+6(2) = '01'.
*DO.
RA_DATE-SIGN = 'I'.
RA_DATE-OPTION = 'BT'.
RA_DATE-LOW =  DATE.
RA_DATE-HIGH =  LV_DATE + 3.
APPEND RA_DATE.

LOOP AT RA_DATE.
  WRITE: RA_DATE-LOW, 25 RA_DATE-HIGH.
ENDLOOP.

Vasanth

5 REPLIES 5
Read only

Former Member
0 Likes
633

Hi,


  DATA: gd_factorydat LIKE scal-facdate,
        gd_resdate    LIKE sy-datum.

* Convert date to factory date
  CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
       EXPORTING
            date                = p_paydate  "Starting date
            factory_calendar_id = 'GB'
       IMPORTING
            factorydate         = gd_factorydat. "Factory calender date

* Add n number of days to factory date, ignors non working days
  gd_factorydat =  gd_factorydat + p_days.

Regards

Sudheer

Read only

0 Likes
633

This code does not return factory date. The trasnfer rules never finish. I am sure I am missing additional code.

Read only

Former Member
0 Likes
633

Hi,

he function module CALCULATE_DATE also adds/subtracts days and months to/from a date. The following website also demonstrates a number of ways to add days/months taking into account working and non working days if that is any use. http://www.sapdevelopment.co.uk/tips/date/datehome.htm

CALL FUNCTION 'CALCULATE_DATE'

EXPORTING

  • DAYS = '0'

months = '01'

start_date = p_date

IMPORTING

result_date = p_date.

<b>Reward points</b>

Regarsd

Read only

Former Member
0 Likes
634

Hello Rainer,

This is what u want.


DATA: LV_DATE LIKE SY-DATUM.
DATA: RA_DATE TYPE RANGE OF SY-DATUM  WITH HEADER LINE.
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
     EXPORTING
          DAY_IN            = DATE
     IMPORTING
          LAST_DAY_OF_MONTH = LV_DATE
     EXCEPTIONS
          DAY_IN_NO_DATE    = 1
          OTHERS            = 2.
IF SY-SUBRC <> 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
DATE+6(2) = '01'.
*DO.
RA_DATE-SIGN = 'I'.
RA_DATE-OPTION = 'BT'.
RA_DATE-LOW =  DATE.
RA_DATE-HIGH =  LV_DATE + 3.
APPEND RA_DATE.

LOOP AT RA_DATE.
  WRITE: RA_DATE-LOW, 25 RA_DATE-HIGH.
ENDLOOP.

Vasanth

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
633

Hi,

Try this fm.

data l_day type p.

CALL FUNCTION 'HR_E_NUM_OF_DAYS_OF_MONTH'

EXPORTING

p_fecha = sy-datum

IMPORTING

number_of_days = l_day.

write l_day.

Message was edited by:

Jayanthi Jayaraman