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

Implicit character or charactered structure --> to String Conversion

Former Member
0 Likes
1,063

Hi everybody,

that sounds trivial but i am struggeling.... which is the most elegant way to do a implicit "To-String" Conversion in ABAP Objects...

I have e.g.

data lok_string type string.

lok_string = wa.

m_object->addline( lok_string ).

which is working fine but is not elegant comaring with java.

i want

m_object->addline( wa ).

but this don't go when "wa" is a structured workarea with many "type c"s in it (and only these).

but since the explicit assignment "lok_string = wa." is working well, there could be a elegant implicit one?

(m_object->addline expects a string variable.)

Thank is aprreciated.

Regards

Hartmut

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,010

We can't understand. You must have forgotten something...

Hi everybody,

that sounds trivial but i am struggeling.... which is the most elegant way to do a implicit "To-String" Conversion in ABAP Objects...

I have e.g.

data lok_string type string.

lok_string = wa.

m_object->addline( lok_string ).

which is working fine but is not elegant comaring with java.

i want

m_object->addline( wa ).

but this don't go when "wa" is a structured workarea with many "type c"s in it (and only these).

but since the explicit assignment "lok_string = wa." is working well, there could be a elegant implicit one?

(m_object->addline expects a string variable.)

Thank is aprreciated.

Regards

Hartmut

6 REPLIES 6
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,011

We can't understand. You must have forgotten something...

Read only

0 Likes
1,010

sorry, I am getting more clear now, i am searching a conversion method which converts data from a character-structured workarea to a string, and which i can use as a functional method (say as part of an expression), for that i can ommit the help variables in the example above.

Regards

Hartmut

Read only

0 Likes
1,010

something like that ?


class lcl_xxx definition.
  public SECTION.
    class-methods addline IMPORTING charlike TYPE clike RETURNING VALUE(string) TYPE string.
endclass.
class lcl_xxx IMPLEMENTATION.
  method addline.
    string = charlike.
  endmethod.
endclass.
start-of-SELECTION.
data a type bapireturn.
data b type string.

b = lcl_xxx=>addline( charlike = a ).

Read only

0 Likes
1,010

Hi Sandra,

this is the right direction.... but i would like to have it as an nested expression... (since implicit conversion seams to be impossible)

like...

m_object->addline( lcl_xxx=>tostring( wa_head ) )

but this line above is not an valid abap objects syntax, unfortunatelly

... having:

class lcl_xxx definition.

public section.

class-methods tostring importing charlike type clike returning value(string) type string.

endclass.

class lcl_xxx implementation.

method tostring.

string = charlike.

endmethod.

endclass.

Best regards

Hartmut

Read only

0 Likes
1,010

Unfortunately, we must define intermediate variables. Be patient, nested functions will be available from release 7.10 (or 7.0 from unknown EHP)

Read only

0 Likes
1,010

That is ok for me, i am looking forward having this feature some day

Thanks for your help.

Best regards

Hartmut