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

Function module to convert date format (dd.mm.yyyy) to date value or integer format.

Former Member
0 Likes
7,570

Hi Experts ,

I have a requirement to convert date format (dd.mm.yyyy) to date value or integer format.

Input: 12/12/2014

Output: 40181630

I tried following FM but it is not working properly.

CONVERSION_EXIT_INVDT_OUTPUT

Please let me know if there is any other function module which will convert data format to date value.

Many thanks,

SK

1 ACCEPTED SOLUTION
Read only

raghug
Active Contributor
4,490
DATA: integer_date TYPE i.

    in_date = '12/12/2014'.


    TRY.
        cl_abap_datfm=>conv_date_ext_to_int(
          EXPORTING
            im_datext                    = in_date  
          IMPORTING
            ex_datint                    = internal_date
        ).

      CATCH cx_abap_datfm_no_date.    "

      CATCH cx_abap_datfm_invalid_date.    "

      CATCH cx_abap_datfm_format_unknown.    "

      CATCH cx_abap_datfm_ambiguous.    "

    ENDTRY.

  integer_date = internal_date.
 
4 REPLIES 4
Read only

Former Member
4,490

Hello Sivakiran, Maybe you should try FM: CONVERSION_EXIT_INVDT_INPUT

Read only

Sandra_Rossi
Active Contributor
0 Likes
4,490

You may use either the RSDAT conversion routine (SAP Library: Conversion Routine RSDAT), or use the generic input conversion released function module RS_CONV_EX_2_IN.

Read only

RaymondGiuseppi
Active Contributor
4,490

A simple move of the date field to an integer will convert a date to an integer. (SAP use a difference in days from 01.01.1901 where some other O/S or software use other reference)

To convert an external format to integer there are many FM (e.g. SE37 look for CONVERSION_EXIT_*DATE*_INPUT) and methods (like those of class cl_abap_datfm, e.g.CONV_DATE_EXT_TO_INT) that use current user configuration or a parameter for expected or plausible date format.

Regards,
Raymond

Read only

raghug
Active Contributor
4,491
DATA: integer_date TYPE i.

    in_date = '12/12/2014'.


    TRY.
        cl_abap_datfm=>conv_date_ext_to_int(
          EXPORTING
            im_datext                    = in_date  
          IMPORTING
            ex_datint                    = internal_date
        ).

      CATCH cx_abap_datfm_no_date.    "

      CATCH cx_abap_datfm_invalid_date.    "

      CATCH cx_abap_datfm_format_unknown.    "

      CATCH cx_abap_datfm_ambiguous.    "

    ENDTRY.

  integer_date = internal_date.