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 a DEC into date and time fields

Former Member
0 Likes
4,620

I have a decimal datatype DEC length 15 which contains a date and time information for eg: 20,080,428,193,043

I need to convert this into two fields containing date and time separately.

Foe eg: here should be:

2008/04/28 and 19:30:43

How can I do this?

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,509

Hi,

Check this sample code,

DATA:
* If it is of type DEC of lenght 15 and decimal 0,
* then it will not hold '20,080,428,193,043',
  w_dec      TYPE cifpuorout-req_tstamp,
                                       "value '20,080,428,193,043',
  w_date     TYPE sy-datum,
  w_time     TYPE sy-uzeit,
* If the value '20,080,428,193,043',then replace ',' with ''
  w_char(20) TYPE c VALUE '20,080,428,193,043'.

REPLACE ALL OCCURRENCES OF ',' IN w_char WITH ''.

CALL FUNCTION 'CACS_TIMESTAMP_GET_DATE'
  EXPORTING
    i_timestamp = w_char
  IMPORTING
    e_date      = w_date
    e_time      = w_time.

WRITE:/
  w_date,
  w_time.

Note: moving value's from char to dec is not allowed ,please check what value you are getting '20,080,428,193,043',

or '20080428193043'.

Regards

Adil

13 REPLIES 13
Read only

Former Member
0 Likes
2,509

hi use concatenate statement

Read only

0 Likes
2,509

Hi,

I am not into ABAP but from BW.

Can you please provide me the code?

Read only

Former Member
0 Likes
2,509

Hi,

Try this FM,

CACS_TIMESTAMP_GET_DATE

or

Try logic using offset.

Regards

Adil

Edited by: Syed Abdul Adil on Jul 31, 2008 3:33 PM

Read only

Former Member
0 Likes
2,509

first use replace all occurrences and then concatenate

replace all occurrences of ',' in v_char with ''.

concatenate v_char0(4) '/' v_char4(2) '/' v_char+6(2) into

v_date.

concatenate v_char8(2) ':' v_char10(2) ':' v_char+12(2) into

v_time.

write 😕 v_date , v_time.

Read only

Former Member
0 Likes
2,509

data:char(25) value '20,080,428,193,043' .

replace all occurrences of ',' in char with ' ' .

concatenate char0(4) '/' char4(2) '/' char+6(2) into char .

write:/ char.

Read only

0 Likes
2,509

Hi ,

It is not just one value I want to convert so I cannot specify a particular value.

I was just giving an example.

I will get DEC(15) values which I need to convert to date and time.

Read only

0 Likes
2,509

First move this DEC(15) variable to a type char15 variable.

Suppose this char variable is lv_date

Then first use

REPLACE all occurenceos of ',' with ''.

Then use

CONCATENATE lv_date(4) '/' lv_date4(2) '/' lv_date6(2) to lv_date.

Similarly you can fetch time in another variable.

Hope this clears your doubt.

Read only

Former Member
0 Likes
2,509

Hi,

try this,

20,080,428,193,043 remove commas and pass the value to this FM

CACS_TIMESTAMP_GET_DATE

result will be date and time .

Regards

Adil

Read only

Former Member
0 Likes
2,509

Hi,

I checked one more FM,

Just pass 20,080,428,193,043 to FM

CIF_GEN_CONVERT_TIMESTAMP.

Regards

Adil

Read only

Former Member
0 Likes
2,509

data:char(25) value '20,080,428,193,043',

char1(10),

char2(10) .

replace all occurrences of ',' in char with ' ' .

concatenate char0(4) '/' char4(2) '/' char+6(2) into char1 .

concatenate char8(2) ':' char10(2) ':' char+12(2) into char2 .

write:/ char1.

write:/ char2.

Read only

former_member217544
Active Contributor
0 Likes
2,509

Hi,

Use this syntax:

if v_timestamp is teh one which contains the value

CONVERT TIME STAMP v_timestamp

TIME ZONE SY-ZONLO

INTO DATE dat

TIME tim.

After executing this statement

'dat' holds the value of the DATE

and 'tim' holds the value of TIME.

Hope this will help.

Regards,

Swarna Munukoti.

Read only

0 Likes
2,509

Let me try these different options and I shall get back to you.

Read only

Former Member
0 Likes
2,510

Hi,

Check this sample code,

DATA:
* If it is of type DEC of lenght 15 and decimal 0,
* then it will not hold '20,080,428,193,043',
  w_dec      TYPE cifpuorout-req_tstamp,
                                       "value '20,080,428,193,043',
  w_date     TYPE sy-datum,
  w_time     TYPE sy-uzeit,
* If the value '20,080,428,193,043',then replace ',' with ''
  w_char(20) TYPE c VALUE '20,080,428,193,043'.

REPLACE ALL OCCURRENCES OF ',' IN w_char WITH ''.

CALL FUNCTION 'CACS_TIMESTAMP_GET_DATE'
  EXPORTING
    i_timestamp = w_char
  IMPORTING
    e_date      = w_date
    e_time      = w_time.

WRITE:/
  w_date,
  w_time.

Note: moving value's from char to dec is not allowed ,please check what value you are getting '20,080,428,193,043',

or '20080428193043'.

Regards

Adil