2021 Sep 27 8:53 AM
Hello,
I have a requirement to validate date format of BSEG-ZUONR.
If the date format is not equal to YYYY/MM/DD, we need to print error message saying 'date format is incorrect'.
Can anyone let me know how this can be achieved? can we write a regex?
Thanks in advance.
Regards,
Tejas.
2021 Sep 27 11:45 AM
If you are not in the mood to use regex anymore, because you have realized that to insure actual dates, a regex is not the way to do it, you can try something like
TRY.
cl_abap_datfm=>conv_date_ext_to_int(
EXPORTING
im_datext = bseg-zuonr
im_datfmdes = '5'
IMPORTING
ex_datint = DATA(date)
).
num8 = date.
WRITE num8 TO bseg-zuonr USING EDIT MASK '____/__/__'.
CATCH cx_abap_datfm_no_date cx_abap_datfm_invalid_date cx_abap_datfm_format_unknown cx_abap_datfm_ambiguous INTO DATA(oref).
MESSAGE oref->if_message~get_text( ) TYPE 'E'.
ENDTRY.
Put the code in some FI validation rule exit for example.
If you are not in the mood to use regex anymore, because you have realized that to insure actual dates, a regex is not the way to do it, you can try something like
TRY.
cl_abap_datfm=>conv_date_ext_to_int(
EXPORTING
im_datext = bseg-zuonr
im_datfmdes = '5'
IMPORTING
ex_datint = DATA(date)
).
num8 = date.
WRITE num8 TO bseg-zuonr USING EDIT MASK '____/__/__'.
CATCH cx_abap_datfm_no_date cx_abap_datfm_invalid_date cx_abap_datfm_format_unknown cx_abap_datfm_ambiguous INTO DATA(oref).
MESSAGE oref->if_message~get_text( ) TYPE 'E'.
ENDTRY.
Put the code in some FI validation rule exit for example.
2021 Sep 27 9:00 AM
CONSTANTS c_regex_ymd_slash TYPE string VALUE '(([12]\d{3})\/(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01]))'.
...
FIND REGEX c_regex_ymd_slash IN iv_date_analysed.
IF sy-subrc EQ space.
"blabla
RETURN.
ENDIF.
....
2021 Sep 27 9:12 AM
Antoher idea would be to try casting it to a date a deal with exceptions but I have a soft spot for regex 😉
2021 Sep 27 9:26 AM
c5e08e0478aa4727abc4482f5be390b2 how can you be sure the date format is YYYY/MM/DD ?
2021 Sep 27 9:30 AM
Assign it to a date, write it back using formatting, compare with source. Hmm, come to think of it, the efficiency of this approach is highly questionable 😛
2021 Sep 27 11:45 AM
If you are not in the mood to use regex anymore, because you have realized that to insure actual dates, a regex is not the way to do it, you can try something like
TRY.
cl_abap_datfm=>conv_date_ext_to_int(
EXPORTING
im_datext = bseg-zuonr
im_datfmdes = '5'
IMPORTING
ex_datint = DATA(date)
).
num8 = date.
WRITE num8 TO bseg-zuonr USING EDIT MASK '____/__/__'.
CATCH cx_abap_datfm_no_date cx_abap_datfm_invalid_date cx_abap_datfm_format_unknown cx_abap_datfm_ambiguous INTO DATA(oref).
MESSAGE oref->if_message~get_text( ) TYPE 'E'.
ENDTRY.
Put the code in some FI validation rule exit for example.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |