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

Type conversions

Former Member
0 Likes
605

Hello,

How is type conversion done in a statement like

DATA: date type d,
      string(10) type c.
date = string + 1.

If string has the value "20071031", will 1 be added as a string (resulting in "200710311" which is then somehow converted to a date), like a number (resulting in "20071032" which is then somehow converted to a date) or like a date (resulting in "20071101")?

Regards,

Christoffer

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
583

Did you try typing it and running it?

DATA: date TYPE d,
      string(10) TYPE c.

string = '20071031'.

date = string + 1.

WRITE: / date, string.

Result: 00000000, 20071031.

( the intermediate result of "string + 1" will be 20071032, as it will be converted to a numeric for the "+1" operation ).

matt

4 REPLIES 4
Read only

matt
Active Contributor
0 Likes
584

Did you try typing it and running it?

DATA: date TYPE d,
      string(10) TYPE c.

string = '20071031'.

date = string + 1.

WRITE: / date, string.

Result: 00000000, 20071031.

( the intermediate result of "string + 1" will be 20071032, as it will be converted to a numeric for the "+1" operation ).

matt

Read only

Former Member
0 Likes
583

Hey here nothing will come to Date.

The type conversion is not possible.

Read only

0 Likes
583

Why do you believe it's not possible?

There are three types involved: characters, date and integer. Conversion rules exist between all of these types.

Regards,

Christoffer

Read only

Former Member
0 Likes
583

Hi,

Conversion rules exist between all of these types. but straight away u can not do this.

if the string is first converted as date field and then incremented

date = string .

date = date + 1.

u can get the result as 20071101

if string id incremented first and then u convert as date field u can get

string = 20071032 and date = 20071032 (not recommended )

the case u have discussed is not possible i think.