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

Abap code for splitting date needed

Former Member
0 Likes
17,774

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

1 ACCEPTED SOLUTION
Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
5,626

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.

11 REPLIES 11
Read only

Former Member
0 Likes
5,626

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

Read only

Former Member
0 Likes
5,626

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).

Read only

Former Member
0 Likes
5,626

we can learn by surfing and Searching.:

http://www.sapabapsdmm.com/ABAP-Reporting-P14.htm

Read only

Former Member
0 Likes
5,626

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

Read only

Former Member
0 Likes
5,626

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.

Read only

Former Member
0 Likes
5,626

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

Read only

Former Member
0 Likes
5,626

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

Read only

Former Member
0 Likes
5,626

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.

Read only

Former Member
0 Likes
5,626

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).

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
5,627

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.

Read only

Former Member
0 Likes
5,626

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.