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

String templates

rainer_hbenthal
Active Contributor
0 Likes
4,452

I just played around with the string tempülates now available in one of our updated systems. So i tried

  type_descr = cl_abap_typedescr=>describe_by_data( s ).

  CASE type_descr->type_kind.

    WHEN cl_abap_typedescr=>typekind_time.
      r = |{ s time = user }|.

Where s is an importing parameter of a method having type CLIKE

but i got the error "Format directive TIME cannot be used on the embedded expression".

Inserting a helping variable

ltime type t

and

ltime=s;

r = |{ ltime time = user }|.

solves this, but thats exactly what i want to avoid: a helping variable just for type casting

Is there no way to solve this without a helping variable?

Please don't give hints to use concatenate or write into, i know these and i know how to use this. My intention is to get experience with string templates.

1 ACCEPTED SOLUTION
Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
0 Likes
3,662

Quote from F1 help:


This formatting option defines the format of a time. You can declare the option TIME only if the embedded expression has the data type t.

So you can not use it without putting type t there

Maybe it could be done with inline data/variable declaration. But i can't try it, since its not available in my ABAP version...

-- Tomas --
10 REPLIES 10
Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
0 Likes
3,663

Quote from F1 help:


This formatting option defines the format of a time. You can declare the option TIME only if the embedded expression has the data type t.

So you can not use it without putting type t there

Maybe it could be done with inline data/variable declaration. But i can't try it, since its not available in my ABAP version...

-- Tomas --
Read only

matt
Active Contributor
0 Likes
3,662

Beat me to it - this first example works, the second has Rainer's error.

DATA: s Type syuzeit.

  s = sy-uzeit.

DATA st TYPE string.

  st = |{ s TIME = USER }|.

DATA: s Type c length 10.

  s = sy-uzeit.

DATA st TYPE string.

  st = |{ s TIME = USER }|.

Read only

0 Likes
3,662

Embarrassing that i've read the online help but it doesnt made click in my head ...

And of course date = user has the same restriction. This type casting with dummy variables really drives me nuts, yesterday i had a method importing character length 15 and i had a string

Read only

0 Likes
3,662

Hi Matthew,

found something around this here

but... not available here...

Read only

matt
Active Contributor
0 Likes
3,662

I'm currently developing with them. Used with care they do make code more readable. The downside is that you lose the navigation by double click on the type.

DATA(s) = sy-uzeit.

DATA(st) = |{ s TIME = USER }|.

Read only

0 Likes
3,662

I'm more referring to the CONV() type cast function, also mentioned in the discussion below the blog, that would really help avoiding those temporary helping variables

Read only

0 Likes
3,662

Another downside is that they cannot be made translateable as easily as character literals (--> text elements).

Read only

matt
Active Contributor
0 Likes
3,662

Erm... isn't that the point? Use | | for non-translatable literals and '' for translatable?

Read only

0 Likes
3,662

Yup. Wait untill you see the first MESSAGE |You can't do { lv_action } with { lv_object }.| TYPE 'E'. Lesson learned: There's always someone who will miss the point...

Read only

Clemenss
Active Contributor
0 Likes
3,662

Try conv time( s ).