‎2007 Dec 14 7:20 AM
Hi,
I have one field that should display todays date. I want to split the date and month
should come in the next field & year should come in another field. i have already written the split statement like this.
v_date = sy-datum.
split v_date at '.' into f1 f2 f3.
ztsh-tsyear = f1.
ztsh-tsmonth = f2.
Im getting the year but month is not coming.
Can anyone help me.
Shyja
‎2007 Dec 14 7:23 AM
‎2007 Dec 14 7:23 AM
Hi,
Instead of Split statment, use this code.
ztsh-year = sy-datum(4).
ztsh-tsmonth = sy-datum+4(2).
regards,
Santosh Thorat
‎2007 Dec 14 7:23 AM
‎2007 Dec 14 7:23 AM
Hi,
Every time the format of date will change so better to use fm to convert the date into current user format use fm
CALL FUNCTION 'CY_CONVERT_DATE'
EXPORTING
date_string_imp = lv_lfdate
IMPORTING
date_string_exp = lv_fdate1
date_exp = lv_fdate2.
then using offset u can read.
Otherwise do like this
this fm will convert the date into ddmmyyyy format then u can easily read the month n year
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = lv_date
IMPORTING
date_external = lv_date1
EXCEPTIONS
date_internal_is_invalid = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
lv_cday = lv_date1+0(2).
lv_month = lv_date1+3(2).
lv_year = lv_date1+6(4).
Regards,
Prashant
‎2007 Dec 14 7:24 AM
Hi,
Try this.It is working fine.
data: f1(4), f2(2), f3(2).
data v1 type datum.
v1 = sy-datum.
f1 = v1+0(4).
f2 = v1+4(2).
write 😕 f1, f2.
‎2007 Dec 14 7:24 AM
Hi Shyja, try this :
data : v_date(10).
write sy-datum to v_date. " using 'write' you get a readable format
split v_date at '.' into f1 f2 f3.
ztsh-tsyear = f3.
ztsh-tsmonth = f2.
ztsh-tsday = f1.
Hope this helps,
Erwan
‎2007 Dec 14 7:37 AM
Hi,
The date field will store like this: 20071214. So, you can use offset instead of split command. check the following example:
data: dt type sy-datum,
dd(2) type n,
mm(2) type n,
yy(4) type n.
dt = sy-datum.
write dt.
dd = dt+6(2).
mm = dt+4(2).
yy = dt+0(4).
write:/ dd,
/ mm,
/ yy.
Regards,
Bhaskar