One useful class SAP has provided recently is the date formatter class to manage different type of dates that one encounters in the wild. So converting from external to internal formats and vice-versa is better now.
The class in question is CL_ABAP_DATFM. The following date formats are supported at the moment:
1 DD.MM.YYYY
2 MM/DD/YYYY
3 MM-DD-YYYY
4 YYYY.MM.DD
5 YYYY/MM/DD
6 YYYY-MM-DD
7 GYY.MM.DD
8 GYY/MM/DD
9 GYY-MM-DD
A YYYY/MM/DD
B YYYY/MM/DD
C YYYY/MM/DD
One example in which I am using it is converting from say format of DD.MM.YYYY to SAP’s internal format of YYYYMMDD.
TRY.CALL METHOD cl_abap_datfm=>conv_date_ext_to_intEXPORTINGim_datext = '01.01.2009'im_datfmdes = '1' " DD.MM.YYYY
IMPORTINGex_datint = sapdate.CATCH cx_abap_datfm_no_date cx_abap_datfm_invalid_datecx_abap_datfm_format_unknown cx_abap_datfm_ambiguous .* Invalide date formatENDTRY.
No comments:
Post a Comment