Application Development 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: 

String templates

rainer_hbenthal
Active Contributor
0 Kudos

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

Tomas_Buryanek
Active Contributor
0 Kudos

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

Tomas_Buryanek
Active Contributor
0 Kudos

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 --

matt
Active Contributor
0 Kudos

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 }|.

0 Kudos

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

0 Kudos

Hi Matthew,

found something around this here

but... not available here...

matt
Active Contributor
0 Kudos

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 }|.

0 Kudos

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

0 Kudos

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

matt
Active Contributor
0 Kudos

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

0 Kudos

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...

Clemenss
Active Contributor
0 Kudos

Try conv time( s ).