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 SY-DATUM

Former Member
0 Likes
5,439

Hi.. I am new in abap.

Tell me which function module which splits SY-DATUM into its constituents parts.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,826

Hi,

try this function module.

HR_IN_GET_DATE_COMPONENTS

OR

write : sy-datum+0(4).( gives year )

sy-datum+4(2) (gives month )

sy-datum+6(2) (gives day )

14 REPLIES 14
Read only

Former Member
0 Likes
2,826

Function modules hampers performance for a program as whole function group is load into program memory at runtime.

So if it is for minimal requirement

Use: offsets.

Data:W_Date type sy-datum value sy-datum,

W_month(2),

W_day(2),

W_year(4).

w_year = w_date+0(4).

w_month = w_date+4(2).

w_day = w_date+6(2).

Regards,

Gurpreet

Read only

Former Member
0 Likes
2,827

Hi,

try this function module.

HR_IN_GET_DATE_COMPONENTS

OR

write : sy-datum+0(4).( gives year )

sy-datum+4(2) (gives month )

sy-datum+6(2) (gives day )

Read only

Former Member
0 Likes
2,826

Hi Nimish

Welcome to SCN

i usuallu use HR_IN_GET_DATE_COMPONENETS

you do need to use MONTH in the FM even ie u r not goin to use it.

Regards

Sachin

Read only

0 Likes
2,826

data : date(2) type c,
       month(2) type c,
       year(4) type c.

date = sy-datum+6(2).
month = sy-datum+4(2).
year = sy-datum+0(4).
Read only

Former Member
0 Likes
2,826

.......

SORRY FOR POSTING AGAIN

Edited by: sachin sharma on Feb 19, 2009 12:42 PM

Read only

Former Member
0 Likes
2,826

not sure, but you can assign it to a string type variable then do the usual

str_year = str_var+0(4).

str_mon = str_var+4(2).

str_day = str_var+6(2).

regards,

Mon Magllanes

Read only

Former Member
0 Likes
2,826

Hi,

You can try this FM



CALL FUNCTION 'HR_IN_GET_DATE_COMPONENTS'
  EXPORTING
    IDATE                               = sy-datum
  IMPORTING
    DAY                                 = lv_day
    MONTH                               = lv_month
    YEAR                                = lv_year
    STEXT                               = lv_stext
    LTEXT                               = lv_ltext
EXCEPTIONS
   INPUT_DATE_IS_INITIAL               = 1
   TEXT_FOR_MONTH_NOT_MAINTAINED       = 2
   OTHERS                              = 3.

Thanks

Arun

Read only

Former Member
0 Likes
2,826

Hi ,

Better option will be to use offset , as the sy-datum is always of the format YYYYMMDD.

Regards,

Arun

Read only

Former Member
0 Likes
2,826

Hi,

I hope you know that using function module to the program includes the whole function group in the program till the program terminates which takes lots of space in the memory and might effect on runtime....

hence its better to use the normal code instead of going for a function module...

to split ituse offsets which would be the best way..

data = sy-datum+6(2).
month = sy-datum+4(2).
year = sy-datum+0(4).

ADDITIONAL INFORMATION :

to know more on data validations and leap year check you can go to wiki and type in the respective keywords say data validations and leap year.

Regards,

Siddarth

Read only

Former Member
0 Likes
2,826

hi:

Data:

my_date like sy-datum,

year(4),

month(2),

day(2).

year = my_date(4).

month = my_date+4(2).

day = my_date+6(2).

Another way is to use the function module HR_IN_GET_DATE_COMPONENTS

Regards

Shashi

Read only

faisalatsap
Active Contributor
0 Likes
2,826

Hi,

Test the following Sample Code.

DATA: date LIKE sy-datum,
      day(2),
      month(2),
      year(4),
      stext LIKE t247-ktx,
      ltext LIKE t247-ltx,
      userdate(10).

date = sy-datum.

CALL FUNCTION 'HR_IN_GET_DATE_COMPONENTS'
  EXPORTING
    idate                         = date
  IMPORTING
    day                           = day
    month                         = month
    year                          = year
    stext                         = stext
    ltext                         = ltext
    userdate                      = userdate
  EXCEPTIONS
    input_date_is_initial         = 1
    text_for_month_not_maintained = 2
    OTHERS                        = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

WRITE: / day,/ month,/ year, / stext, / ltext, / userdate.

Kind Regards,

Faisal

Edited by: Faisal Altaf on Feb 19, 2009 12:26 PM

Read only

Former Member
0 Likes
2,826
DATA: day(10) TYPE c,
      month(2) TYPE c,
      year(4) TYPE c,
      date type sy-datum.
date = sy-datum.
CALL FUNCTION 'HR_IN_GET_DATE_COMPONENTS'
  EXPORTING
    idate                               = date
 IMPORTING
   day                                 = day
   month                               = month
   year                                = year.
WRITE: day, month, year.
Read only

Former Member
0 Likes
2,826

CONVERT_DATE_TO_INTERN_FORMAT

Read only

Former Member
0 Likes
2,826

Hi

use the function module HR_IN_GET_DATE_COMPONENTS

Regards,

Anki Reddy