Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SPLIT STATEMENT

Former Member
0 Likes
729

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
693

ztsh-tsyear = v_date+0(4).

ztsh-tsmonth = v_date+4(2).

6 REPLIES 6
Read only

Former Member
0 Likes
693

Hi,

Instead of Split statment, use this code.

ztsh-year = sy-datum(4).

ztsh-tsmonth = sy-datum+4(2).

regards,

Santosh Thorat

Read only

Former Member
0 Likes
694

ztsh-tsyear = v_date+0(4).

ztsh-tsmonth = v_date+4(2).

Read only

former_member386202
Active Contributor
0 Likes
693

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

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
693

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.

Read only

Former Member
0 Likes
693

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

Read only

Former Member
0 Likes
693

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