2014 Sep 10 8:13 AM
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.
2014 Sep 10 8:55 AM
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...
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
2014 Sep 10 8:55 AM
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...
2014 Sep 10 9:11 AM
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 }|.
2014 Sep 10 9:14 AM
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
2014 Sep 10 9:23 AM
2014 Sep 10 10:27 AM
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 }|.
2014 Sep 10 11:35 AM
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
2014 Sep 10 11:59 AM
Another downside is that they cannot be made translateable as easily as character literals (--> text elements).
2014 Sep 10 1:12 PM
Erm... isn't that the point? Use | | for non-translatable literals and '' for translatable?
2014 Sep 10 2:42 PM
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...
2020 Oct 25 11:00 PM
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |