cancel
Showing results for 
Search instead for 
Did you mean: 

Date validation and conversion

Former Member
0 Kudos

Hi,

I have a screen field for date which is binded to a atrribute with domain DATUM.

when i enter date '01/07/2009' in to screen fiels and after any user action it is converted as '07.01.2009'.

Its not allowing to enter 13/07/2009 as it is assuming 13 as month.

when i enter date 2009/07/01 its converted as 01/07/2009 which is correct.

The date format selected in user settings is 'DD.MM.YYYY' , I wonder why the date is converted?

Please help.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Pavan,

This is normal, since the valid formats are DD.MM.YYYY and MM/DD/YYYY.

So it is normal that when u enter date as 01/07/2009 it converts it into 07.01.2009 because the system will read it as MM/DD/YYYY and similarly 17/01/2009 when it will read 17 as a month and give error.

If you still want to change this standard behaviour check Mehmet Dagnilak's solution towards the end of this thread

[]

Regards,

Radhika.

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Pavan,

You can check the date format before the initial page load and convert it to the specific format which you want .

Try this code , it may help you to solve your problem.

call function 'ITS_GET_USER_DEFAULTS'

exporting

bname = sy-uname

importing

datfm = date_fromat.

case date_fromat.

when 1."DD.MM.YYYY

concatenate v_date6(2) v_date4(2) v_date+0(4) into v_date1 separated by '/'.

when 2."MM/DD/YYYY

concatenate v_date6(2) v_date4(2) v_date+0(4) into v_date1 separated by '/'.

when 3."MM-DD-YYYY

concatenate v_date4(2) v_date6(2) v_date+0(4) into v_date1 separated by '/'.

when 4."YYYY.MM.DD

concatenate v_date0(4) v_date4(2) v_date+6(2) into v_date1 separated by '/'.

when 5."YYYY/MM/DD

concatenate v_date0(4) v_date4(2) v_date+6(2) into v_date1 separated by '/'.

when 6."YYYY-MM-DD

concatenate v_date0(4) v_date4(2) v_date+6(2) into v_date1 separated by '/'.

endcase.

Thanks,

Satya

Former Member
0 Kudos

Thanks Radhika.

+Conversion exit cant be used as the date validation is done before conversion exit applied. +

Former Member
0 Kudos

Pavan,

Conversion exit can be used because conversion exits are above date validations, i.e. if there is conv.exit, it is called first and no validation is done. I have applied this method and it works fine with Webdynpro Abap.

Here is the code I use:

I wonder why this forum can't display code correctly..

Edited by: Mehmet Dagnilak on Jul 27, 2009 4:42 PM

Former Member
0 Kudos

This in global data of function group:

data: date_separator value ' '.

function conversion_exit_zdate_input.

*"----


""Local Interface:

*" IMPORTING

*" VALUE(INPUT)

*" EXPORTING

*" VALUE(OUTPUT)

*"----


  • This conversion exit's aim is to allow user to use any valid date

  • separator and still conform to the user's date format settings.

  • It's aimed to be used in Webdynpro Abap applications.

*

  • Normally, in a Webdynpro Abap application, if the user enters date

  • using "/", WDA assumes that the user means MM/DD/YYYY irrespective of

  • user's date settings. So it's not possible to enter a date in

  • DD/MM/YYYY format.

  • This conversion exit first converts all separators used in the entry

  • to user's valid separator, then calls system functions to convert

  • it to an internal date value.

*

  • e.g. User's date format is DD.MM.YYYY

  • If user enters 1/2/3, it's converted to 1.2.3, then to 20030201

data: char_datum(10),

date_out type d.

clear output.

if input is initial.

exit.

endif.

  • Get date separator (.-/)

perform get_date_separator.

  • Replace all usable characters with valid date separator.

move input to char_datum.

replace all occurrences of '.' in char_datum with date_separator.

replace all occurrences of '-' in char_datum with date_separator.

replace all occurrences of '/' in char_datum with date_separator.

  • Call basis functionality to convert date to internal format

try.

call method cl_abap_datfm=>conv_date_ext_to_int

exporting

im_datext = char_datum

importing

ex_datint = date_out.

  • Catch all possible exceptions

catch cx_abap_datfm_no_date cx_abap_datfm_invalid_date

cx_abap_datfm_format_unknown cx_abap_datfm_ambiguous .

message e022.

endtry.

  • Return value

output = date_out.

endfunction.

&----


*& Form GET_DATE_SEPARATOR

&----


  • text

----


form get_date_separator.

data: l_datec(10).

check date_separator eq ' '.

write high_date to l_datec.

if l_datec ca '.'.

date_separator = '.'.

elseif l_datec ca '/'.

date_separator = '/'.

elseif l_datec ca '-'.

date_separator = '-'.

endif.

endform. " GET_DATE_SEPARATOR

Former Member
0 Kudos

I think code posting works now..

This in global data of function group:

data: date_separator value ' '.

Function:

function conversion_exit_zdate_input.
*"--------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(INPUT)
*"  EXPORTING
*"     VALUE(OUTPUT)
*"--------------------------------------------------------------------

* This conversion exit's aim is to allow user to use any valid date
* separator and still conform to the user's date format settings.
* It's aimed to be used in Webdynpro Abap applications.
*
* Normally, in a Webdynpro Abap application, if the user enters date
* using "/", WDA assumes that the user means MM/DD/YYYY irrespective of
* user's date settings. So it's not possible to enter a date in
* DD/MM/YYYY format.
* This conversion exit first converts all separators used in the entry
* to user's valid separator, then calls system functions to convert
* it to an internal date value.
*
* e.g. User's date format is DD.MM.YYYY
* If user enters 1/2/3, it's converted to 1.2.3, then to 20030201

  data: char_datum(10),
        date_out type d.

  clear output.
  if input is initial.
    exit.
  endif.

* Get date separator (.-/)
  perform get_date_separator.

* Replace all usable characters with valid date separator.
  move input to char_datum.
  replace all occurrences of '.' in char_datum with date_separator.
  replace all occurrences of '-' in char_datum with date_separator.
  replace all occurrences of '/' in char_datum with date_separator.

* Call basis functionality to convert date to internal format
  try.
      call method cl_abap_datfm=>conv_date_ext_to_int
        exporting
          im_datext = char_datum
        importing
          ex_datint = date_out.
*   Catch all possible exceptions
    catch cx_abap_datfm_no_date cx_abap_datfm_invalid_date
          cx_abap_datfm_format_unknown cx_abap_datfm_ambiguous .
      message e022.
  endtry.

* Return value
  output = date_out.

endfunction.

form get_date_separator.

  data: l_datec(10).

  check date_separator eq ' '.

  write high_date to l_datec.
  if l_datec ca '.'.
    date_separator = '.'.
  elseif l_datec ca '/'.
    date_separator = '/'.
  elseif l_datec ca '-'.
    date_separator = '-'.
  endif.

endform.                    " GET_DATE_SEPARATOR

Former Member
0 Kudos

I wanted the date 01/07/2009 to be converted as 01.07.2009. how can i get this done?

Please help.

Former Member
0 Kudos

Sorry..

when i enter date 2009/07/01 its converted as 01.07.2009 which is correct.