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

How to convert date automatically

Former Member
0 Likes
792

Hi,

I am doing function module. In that i created import export and exceptions,and written the code in the source code. See the function module code below.

DATA : l_date TYPE sy-datum VALUE '18000101'.


  IF date1+4(2) > '12'.
    RAISE ex_month.

  ELSEIF date1+6(2) > '31'.
    RAISE ex_day.
  ENDIF.

  IF date2+4(2) > '12'.
    RAISE ex_month.

  ELSEIF date2+6(2) > '31'.
    RAISE ex_day.
  ENDIF.

    no_days = abs( date1 - date2 ).

and called the function in the editor. see the code below.

data : no_days type i.

parameters: date1 type dats,
            date2 type dats.

call function 'Z50803_SD_FUNC_DAYSBTTWODATES1'
  exporting
    date1   = date1
    date2   = date2
  importing
    no_days = no_days
  exceptions
    dat     = 1
    mon     = 2
    day     = 3
    others  = 4.
if sy-subrc <> 0.
  case sy-subrc.
    when 1.
      write:/ 'please enter valid date'.
    when 2.
      write:/ 'Please enter valid month'.
    when 3.
      write:/ ' Please enter valid day'.
  endcase.
else.
  write:/ 'NO OF DAYS:', no_days.
endif.

.

My question is exceptions is not trigger in the output and in the selection screen the date farmat is (yyyy.mm.dd). If i enter the date any format i want to display the output.

plese help me ASAP.

Regards

Srinu

6 REPLIES 6
Read only

Former Member
0 Likes
709

Please reward points if helpful.

Read only

Former Member
0 Likes
709

Hi,

The date data type should alwyz be fixed.

Else use FM 'CONVERT_DATE_TO_INTERNAL' or 'CONVERT_DATE_TO_EXTERNAL' for changing the format.

Best regards,

Prashant

Read only

Former Member
0 Likes
709

DATA: var_dt(10) TYPE c.

CALL FUNCTION 'RP_FORMATING_DATE'

EXPORTING

date_i = var_dt

birth_date = 'X'

IMPORTING

date_o = gv_convtddate.

  • EXCEPTIONS

  • DATE_INVALID = 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.

CONCATENATE gv_convtddate6(2) gv_convtddate4(2) gv_convtddate+0(4)

INTO date1 SEPARATED BY '.'

Message was edited by:

sagar kekare

Read only

Former Member
0 Likes
709

hi,

you will have to convert the input which you give to yyyymmdd format,

hence you can use FM 'CONVERT_DATE_TO_INTERNAL'

regards,

ritika malhotra

Read only

Former Member
0 Likes
709

hi,

for the date to be changed to the system format you can use the function module :

CONVERT_DATE_TO_INTERNAL.

this will help you.

regards,

sohi

Read only

Former Member
0 Likes
709

hi ,

use the FM CONVERT_DATE_FORMAT to display the date in the ddmmyyyy format.

regards,

sandhya.