Professional Documents
Culture Documents
com/wiki/display/Snippets/ABAP++Function+module+for+converting+any+External+date+format+to+Internal+for mat
Description: This is function module can be used for converting any External date format to
Internal format.
The following SAP's external formats which can be found in the user settings are supported
The function module needs to created with the parameters as mentioned in the code.
FUNCTION z_convert_to_internal_format. *"---------------------------------------------------------------------*"*"Local interface: *" IMPORTING *" VALUE(IM_INPUT) TYPE CHAR10
*"----------------------------------------------------------------------
* DD.MM.YYYY IF im_input+2(1) = '.'. CONCATENATE im_input+6(4) im_input+3(2) im_input(2) INTO ex_output. ENDIF.
* MM-DD-YYYY IF im_input+2(1) = '-'. CONCATENATE im_input+6(4) im_input(2) im_input+3(2) INTO ex_output. ENDIF.
* YYYY.MM.DD IF im_input+4(1) = '.'. CONCATENATE im_input(4) im_input+5(2) im_input+8(2) INTO ex_output. ENDIF.
* YYYY/MM/DD IF im_input+4(1) = '/'. CONCATENATE im_input(4) im_input+5(2) im_input+8(2) INTO ex_output. ENDIF.
* YYYY-MM-DD IF im_input+4(1) = '-'. CONCATENATE im_input(4) im_input+5(2) im_input+8(2) INTO ex_output. ENDIF.
date EXCEPTIONS
= ex_output
plausibility_check_failed = 1 OTHERS = 2.
* Check if the output parameter is populated. otherwise raise an * exception. IF ex_output IS INITIAL OR sy-subrc <> 0. RAISE invalid_date. ENDIF.
ENDFUNCTION.
DATA: g_date TYPE c LENGTH 10. CALL FUNCTION 'SLS_MISC_CONVERT_TO_DATE' EXPORTING p_date * P_DATE_FORMAT IMPORTING p_date_string * EXCEPTIONS * ERROR_SELECTING_USER_DEFAULTS * OTHERS . IF sy-subrc <> 0. * Implement suitable error handling here =2 =1 = g_date = sy-datum =
found in USR01 table. Check DATFM field passing BNAME. Use domain value range of DATFM to