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: 

date problem

Former Member
0 Kudos

hi,

i have a selection screen with date field like,

select-options:s_date for sy-datum.

i want to display default values as 01.02.2006 and 28.02.2006.

how to do this? and this is not only for this month. if i execute the program in march the values should be 01.03.2006 and 31.03.2006.

i got the first value but how to find the months last day?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi Rich and Sekhar

thanks for ur answers. but i want a solution with out using function module.any way i got the answer.

once again thanks for ur answers.

data: num1 type i,

num2 type i.

select-options: s_date for sy-datum.

initialization.

num1 = sy-datum+6(2).

num2 = sy-datum+4(2).

num2 = num2 + 1.

s_date-low = sy-datum - num1.

s_date-low = s_date-low + 1.

s_date-high = sy-datum.

s_date-high+4(2) = num2.

s_date-high = s_date-high - num1.

append s_date.

14 REPLIES 14

Former Member
0 Kudos

Hi

Try to use fm LAST_DAY_OF_MONTHS

Move to it the first day of the month and it give you the last day.

Max

0 Kudos

Here is a small sample program. this will take today's date and find the first of the month and the last of the month and set the selection option range before throwing the selection screen.



report zrich_0004.



select-options: s_datum for sy-datum.


initialization.

  s_datum-sign = 'I'.
  s_datum-option = 'BT'.
  s_datum-low = sy-datum.
  s_datum-low+6(2) = '01'.

  call function 'LAST_DAY_OF_MONTHS'
       exporting
            day_in            = s_datum-low
       importing
            last_day_of_month = s_datum-high.

  append s_datum.
  .

Regards,

Rich Heilman

Former Member
0 Kudos

Hi Prasanth,

Move First day to the Sy-datum and USe At-selection screen event by using function : RE_LAST_DAY_OF_MONTH to populate the month end date.

Regards,

Lanka

0 Kudos

For LAst day of month try

RP_LAST_DAY_OF_MONTHS

Former Member
0 Kudos

Hi,

Pass the first day of the month in the FM LAST_DAY_OF_MONTHS & get the last day of the month.Then pass it to s_date-high in the initialization event.

Former Member
0 Kudos

use this FM RP_LAST_DAY_OF_MONTHS to get last day of month

Message was edited by: Sekhar

Former Member
0 Kudos

Try this........

*&---------------------------------------------------------------------*
*& Report  YCHATEST                                                    *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  YCHATEST                                .

DATA:L_DATE_LAST LIKE SY-DATUM,
     L_DATE(2),
     L_MONTH(2),
     L_YEAR(4),
     L_DATE1(2),
     L_MONTH1(2),
     L_YEAR1(4),
     L_DT(10).

.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TITLE.
SELECT-OPTIONS : S_DATE FOR L_DT .
SELECTION-SCREEN END OF BLOCK B1.

INITIALIZATION.

  CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
    EXPORTING
      DAY_IN                  = SY-DATUM
   IMPORTING
     LAST_DAY_OF_MONTH       =  L_DATE_LAST
* 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.

  S_DATE-SIGN = 'I'.
  S_DATE-OPTION = 'BT'.
  L_DATE = '01'.
  L_MONTH = SY-DATUM+4(2).
  L_YEAR = SY-DATUM+0(4).
  CONCATENATE L_DATE L_MONTH L_YEAR INTO S_DATE-LOW
              SEPARATED BY '.'.
  L_DATE1 = L_DATE_LAST+6(2).
  L_MONTH1 = SY-DATUM+4(2).
  L_YEAR1 = SY-DATUM+0(4).
  CONCATENATE L_DATE1 L_MONTH1 L_YEAR1 INTO S_DATE-HIGH
              SEPARATED BY '.'.
  APPEND S_DATE.
  CLEAR S_DATE.

Former Member
0 Kudos

hi Rich and Sekhar

thanks for ur answers. but i want a solution with out using function module.any way i got the answer.

once again thanks for ur answers.

data: num1 type i,

num2 type i.

select-options: s_date for sy-datum.

initialization.

num1 = sy-datum+6(2).

num2 = sy-datum+4(2).

num2 = num2 + 1.

s_date-low = sy-datum - num1.

s_date-low = s_date-low + 1.

s_date-high = sy-datum.

s_date-high+4(2) = num2.

s_date-high = s_date-high - num1.

append s_date.

0 Kudos

Why would you not want to use a function module?

Anyway, if you really don't want to go that way, you could do something also like this.



report zrich_0004.select-options: s_datum for sy-datum.

initialization.
  s_datum-sign = 'I'.
  s_datum-option = 'BT'.
  s_datum-low = sy-datum.
  s_datum-low+6(2) = '01'.
  s_datum-high = sy-datum.
  s_datum-high+4(2) =  s_datum-high+4(2) + 1.
  if s_datum-high+4(2) > 12.
    s_datum-high+4(2) = '01'.
    s_datum-high+0(4) = s_datum-high+0(4) + 1.
  endif.
  s_datum-high+6(2) = '01'.
  s_datum-high = s_datum-high - 1.
  append s_datum.

Any helpful answers here, please award points accordingly. Mark you post as solved if you problem is solved. Thanks

Regards,

Rich Heilman

0 Kudos

Hi

If you don't want to use a fm:

DATA: FIRST_DAY TYPE SY-DATUM,

LAST_DAY TYPE SY-DATUM,

MONTH(2) TYPE N.

INITIALIZATION.

MONTH = SY-DATUM+4(2).

CONCATENATE SY-DATUM(4) MONTH '01' INTO FIRST_DAY.

IF MONTH <> '12'.

MONTH = MONTH + 1.

CONCATENATE SY-DATUM(4) MONTH '01' INTO LAST_DAY.

LAST_DAY = LAST_DAY - 1.

ELSE.

CONCATENATE SY-DATUM(4) MONTH '31' INTO LAST_DAY.

ENDIF.

S_DATE(3) = 'IBT'.

S_DATE-LOW = FIRST_DAY.

S_DATE-HIGH = LAST_DAY.

APPEND S_DATE.

Max

0 Kudos

That logic doesn't work for December.

(The original poster's logic - not yours Max.)

Rob

Message was edited by: Rob Burbank

0 Kudos

Yes! You'are right...infact see my solution.

It's very strange to not want to use the FM, but the best solution is to see the code of a fm calculate last day.

Max

0 Kudos

Yes, it won't work for december, I am assuming that Max's will, haven't try it. I have modified my last post to handle it.

Regards,

Rich Heilman

Former Member
0 Kudos

hi Rich,

actually this question was asked in written test. in that he mentioned don't use any fuction modules(ofcourse i don't know about this function module till now).

at that time i did'nt got an idea for how to get the last day.

but seeing ur program only i got some idea.

thanks

prashanth