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 and text elements / translation ?

4,537

Hi all,

in a normal se38 report one could write someting like

DATA: two TYPE i VALUE 2.
WRITE:  
/ 'I have '(t01) && two && ' eyes.'(t02), "I have2 eyes.  <-- wrong spacing  
/ `I have ` && two && ` eyes.`,  "I have 2 eyes. <-- ok  
/ |I have | && two && | eyes.|.  "I have 2 eyes. <-- ok

The two text symbols T01 and T02 can be translated. But I would like to use string templates because I don't want to care about trailing spaces. You can not use text symbols with string templates as far as I know.

It results in a syntax error:

/ `I have `(t01) && ... <-- Syntax error
/ |I have |(t01) && ... <-- Syntax error

Without text elements the Code Inspector complains (informational): "Strings without text elements are not translated."

Is this crippled by design? Am I missing something?

BTW: I know CONCATENATE and pragmas and a few other ways to work around. That's not the question.

1 ACCEPTED SOLUTION
Read only

retired_member
Product and Topic Expert
Product and Topic Expert
2,904

What about embedded expressions inside string templates? These work as desired.

|{ 'I have'(t01) } |
|{ text-t01 } |
6 REPLIES 6
Read only

retired_member
Product and Topic Expert
Product and Topic Expert
2,905

What about embedded expressions inside string templates? These work as desired.

|{ 'I have'(t01) } |
|{ text-t01 } |
Read only

0 Likes
2,904

It looked promising until I tried. But you left out the important part: the trailing blank. It does not work with ` instead of '. More ideas?

Read only

2,904

I don't see your problem ....

|{ 'I have'(t01) } | && two && | { 'eyes'(t02) }.|

gives "I have 2 eyes."

Same for

|{ 'I have'(t01) } { two } { 'eyes'(t02) }.|
Read only

2,904

My fault. I tried to stick the space to the text. But it's hidden in what i thougt was syntax. Thank you very much for explaining.

For the records (and for my future reference because I will not remember this in 100 years): Here are the blanks:

Read only

2,904

"But it's hidden in what i thougt was syntax"

Without embeddeed expressions in { ... }, string templates are simply a kind of string literals |...| where blanks (and especially trailing blanks) are nothing but normal characters.

Their merit of course comes with embedded expressions |...{ ... }...{ ... }...|, where inside the curly brackets you have ABAP operand positions.

Therefore writing it as

|{ 'I have'(t01) } { two } { 'eyes'(t02) }.|
makes it more clear.
Read only

matt
Active Contributor
2,904

Just to note that using text elements to construct sentences like

'I have '(t01)&& two &&' eyes.'(t02)

is not a good idea, as word order varies from language to language. OK, for this sentence, it works at least in French and German, but you'd get problems with

You must check the table table_name

Since the German would be: Sie müssen die Tabelle table_name kontrollieren.