‎2008 Dec 05 11:06 PM
Hi Experts,
I need ABAP code or a function module to split date into date, month and year. As I have very little knowledge in ABAP, I do not know how to do it. Kindly help me.
Thanks in advance,
With Kind Regards,
Kannan
‎2008 Dec 08 6:49 AM
Hi Kannan Jagadeesan,
To break the date into year, month and date, use this code.
Its working.
PARAMETERS : date TYPE sy-datum.
WRITE : / 'Date: ', date.
WRITE : / 'Year: ', date+0(4),
/ 'Month: ', date+4(2),
/ 'Date: ', date+6(2).
Hope this solves your problem.
Thanks & Regards.
Tarun Gambhir.
‎2008 Dec 05 11:34 PM
Hello Kannan
You can use a work area to cast the date variable an access every component of the date.
look at this code.
TYPES: BEGIN OF ty_date,
year TYPE n LENGTH 4,
month TYPE n LENGTH 2,
day TYPE n LENGTH 2,
END OF ty_date.
DATA wa_date TYPE ty_date.
wa_date = sy-datum.Access the year with wa_date-year, month with wa_date-month and day with wa_date-day
‎2008 Dec 06 1:33 AM
suppose ur date in v_date in dd/mm/yyyy format then do it like this
day = date+0(2).
mon = date+3(2).
year = date+6(4).
‎2008 Dec 06 2:12 AM
‎2008 Dec 06 3:13 AM
Hi,
You can using ABAP code to split date into date, month and year.
Try the code:
DATA: date(2) TYPE C,
month(2) TYPE C,
year(4) TYPE C.
year = sy-datum.
month = sy-datum+4(2).
date = sy-satum+6(2). Best Regards,
WIND LIN
‎2008 Dec 06 4:37 AM
Hi Kannan,
In SAP, the date is internally stored in the format YYYYMMDD.
So, to split the date into year, month and date, you could try this:
DATA: year(4) TYPE c,
month(2) TYPE c,
day(2) TYPE c.
year = sy-datum(4).
month = sy-datum+4(2).
day = sy-datum+6(2).
Thanks,
Dawood.
‎2008 Dec 06 5:24 AM
Hi Kannan,
There are various FM for getting the date in required format.
In Sap dates are internally stored as yyyymmdd format and to get it in require ddmmyyyy format use this fm.
CONVERT_DATE_FORMAT
Eg: input = 20080201 and output = 01.02.2008
There are also various other FM which u can use depending upon the requirement.
CONVERSION_EXIT_PDATE_OUTPUT
Eg: input = 24012008 and output = 24.01.2008
CONVERSION_EXIT_SDATE_OUTPUT
Eg: input = 20070201 and output = 01.FEB.2007
CONVERSION_EXIT_IDATE_INPUT
Eg: input = 01.02.2008 and Output = 20080201
CONVERSION_EXIT_LDATE_OUTPUT
Eg: input = 20070301 and output = 01. March 2007
CONVERSION_EXIT_PDATE_OUTPUT
Eg: input = 20070301 and output = 03.01.2007
Regards,
Anand
‎2008 Dec 06 7:27 AM
Hi,
if u r writing code in customer exit try with this
if varible name is zcedate.
when 'zcedate'.
clear l_s_range.
l_s_range-sign = 'i'.
l_s_range-opt = 'eq'.
l_s_range-low = sy-datum.
append l_s_range to e_t_range.
if it is date sy-datum.
if month sy-datum+4(2).
if year sy-datum+0(4).
u try like this if other cases what our experts said is ok.
thanks for giving this oppourtinity.
Thanks
k.sathish
‎2008 Dec 06 10:19 AM
Hello Kanan,
First use function module CONVERT_DATE_TO_INTERNAL to convert any formatted date
to SAP internal format DDMMYYYY.
Then access this data as:
day in DD = DDMMYYYY+0(2).
month MM = DDMMYYYY+3(2).
year yyyy = DDMMYYYY+5(4).
Regards,
santosh sarda.
‎2008 Dec 06 6:15 PM
Hi
Try this:
Data:C_date(8).
C_Date = Sy-datum.
C_year = C_date+0(4).
C_month = c_date+4(2).
c_day = c_date+6(2).
‎2008 Dec 08 6:49 AM
Hi Kannan Jagadeesan,
To break the date into year, month and date, use this code.
Its working.
PARAMETERS : date TYPE sy-datum.
WRITE : / 'Date: ', date.
WRITE : / 'Year: ', date+0(4),
/ 'Month: ', date+4(2),
/ 'Date: ', date+6(2).
Hope this solves your problem.
Thanks & Regards.
Tarun Gambhir.
‎2014 May 22 1:44 PM
Hello kannan,
I tried writing this program , it worked for me .
PARAMETERS : date(10) TYPE c default '24.12.2014',
dd(2) type c,
mm(2) type c,
yyyy(4) type c.
split date at '.' into dd mm yyyy.
WRITE : / 'Day: ', dd.
WRITE : / 'Month: ', mm.
WRITE : / 'Year: ', yyyy.
If you feel this program suits you try this as well.