将其他日期格式转换成当前用户定义的日格式.

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 in this function module.

DD.MM.YYYY
MM/DD/YYYY
MM-DD-YYYY
YYYY.MM.DD
YYYY/MM/DD
YYYY-MM-DD

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
*"  EXPORTING
*"     VALUE(EX_OUTPUT) TYPE  SYDATUM
*"  EXCEPTIONS
*"      INVALID_DATE
*"----------------------------------------------------------------------

* Get the format.

* 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.

* 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.

* Check the valid date.
  CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
       EXPORTING
            date                      = ex_output
       EXCEPTIONS
            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. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值