Skip to Content
avatar image
Former Member

Date validation and conversion

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    avatar image
    Former Member
    Jul 13, 2009 at 09:00 AM

    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

    [date-entered-as-ddmmyyyy-converts-to-mmddyyyy]

    Regards,

    Radhika.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 13, 2009 at 08:23 AM

    Sorry..

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 13, 2009 at 08:53 AM

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

    Please help.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 14, 2009 at 10:04 AM

    Thanks Radhika.

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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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
      

  • avatar image
    Former Member
    Jul 28, 2009 at 02:51 AM

    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

    Add comment
    10|10000 characters needed characters exceeded