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

Casting c to string in a methode calling

Torsten_
Product and Topic Expert
Product and Topic Expert
0 Likes
558

Hallo,

I've a methode with a string paramter like: code]methode(i_param TYPE string)[/code].

In the calling methode the parameter value

l_value

for i_param is stored in a variable from type c.

In java I would like call:

methode((string) l_value)

(For all java guys: I know that casting between basic types and objects are not possible, but I belive string isn't an object in ABAP)

Is there any simular way in ABAP or is this me way:

         DATA: l_value_string TYPE string. 
         MOVE l_value TO l_value_string. 
         methode( l_value_string ).

Torsten

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
518

Hello Torsten

If you are already working on SAP release 6.20 or higher then you can use static method <b>CL_ABAP_CONTAINER_UTILITIES=>FILL_CONTAINER_C</b>.

Regards

Uwe

Hallo,

I've a methode with a string paramter like: code]methode(i_param TYPE string)[/code].

In the calling methode the parameter value

l_value

for i_param is stored in a variable from type c.

In java I would like call:

methode((string) l_value)

(For all java guys: I know that casting between basic types and objects are not possible, but I belive string isn't an object in ABAP)

Is there any simular way in ABAP or is this me way:

         DATA: l_value_string TYPE string. 
         MOVE l_value TO l_value_string. 
         methode( l_value_string ).

Torsten

2 REPLIES 2
Read only

Peter_Inotai
Active Contributor
0 Likes
518

Hi Torsten,

There is no other way as far as I know...Might be in release 7.10, but I have no info about it.

Casting exist also in ABAP, but only for objects:

DATA: dref1 TYPE REF TO i, 
      dref2 TYPE REF TO data. 

CREATE DATA dref1. 
dref2 = dref1. 
CREATE DATA dref2 TYPE string. 

TRY. 
  dref1 ?= dref2. 
  CATCH cx_sy_move_cast_error. 
  ... 
ENDTRY. 

I agree, that it would be quite useful.

Best regards,

Peter

Read only

uwe_schieferstein
Active Contributor
0 Likes
519

Hello Torsten

If you are already working on SAP release 6.20 or higher then you can use static method <b>CL_ABAP_CONTAINER_UTILITIES=>FILL_CONTAINER_C</b>.

Regards

Uwe