4
tips of date check and convert date with month text
source link: https://blogs.sap.com/2021/06/12/tips-of-date-check-and-convert-date-with-month-text/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Technical Articles
Posted on
June 12, 2021
Less than a 1 minute read
tips of date check and convert date with month text
0 Likes
35 Views
0 Comments
One small tip for a date validation check and convert into text with month text:
- using function module ‘DATE_CHECK_PLAUSIBILITY’ to check if it’s the valid date;
- get month texts from table t247 with a language key then concatenate.
*---------------------------------------------------------------------*
* FORM format_data_with_text *
*---------------------------------------------------------------------*
FORM format_data_with_text USING ip_date
CHANGING op_text.
DATA: lv_stext(3),
lv_date LIKE sy-datum,
lv_fcmnr TYPE fcmnr,
lv_suffix(2).
lv_date = ip_date+0(8).
CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
EXPORTING
date = lv_date
EXCEPTIONS
plausibility_check_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
op_text = ip_date.
ELSE.
CASE lv_date+7(1).
WHEN '1'.
lv_suffix = 'st'.
WHEN '2'.
lv_suffix = 'nd'.
WHEN '3'.
lv_suffix = 'rd'.
WHEN OTHERS.
lv_suffix = 'th'.
ENDCASE.
CLEAR: lv_stext.
lv_fcmnr = lv_date+4(2).
SELECT SINGLE ltx
INTO lv_stext
FROM t247 WHERE spras EQ 'EN'
AND mnr EQ lv_fcmnr.
* CONCATENATE lv_date+6(2) lv_suffix lv_stext lv_date+0(4)
INTO op_text SEPARATED BY space. " with date suffix
CONCATENATE lv_date+6(2) lv_stext lv_date+0(4)
INTO op_text SEPARATED BY space.
ENDIF.
ENDFORM.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK