Topper
Topper

Reputation: 99

Difference between both Translate elements in ABAP

I don´t get it, what´s the difference between both elements in ABAP:

The old TRANSLATE element:

TRANSLATE l_value USING '" '.

The new translate element:

l_value = translate( val = l_value from = '"' to = ' ' )
or 
l_value = translate( val = l_value from = '"' to = space )

The old element works fine. The character is replaced by a space.

But the new one doesn't set a space, it´s shifting the text to left.

I don´t get it.. Do I do something wrong?

Another question:

I´m using the same code to replace cl_abap_char_utilities=>horizontal_tab to SPACE.

But how can I replace horizontal_tabs with the old translate element?

Upvotes: 0

Views: 560

Answers (1)

peterulb
peterulb

Reputation: 2988

It's mentioned in the documentation of the translate function:

from and to are character-like expression positions. If they have a fixed length, trailing blanks are ignored.

If you want to replace it with space, use a text string literal instead of a text field literal (see docu).

l_value = translate( val = l_value from = '"' to ` ` ).

For you second question, to use the old TRANSLATE just concatenate the required values and pass the variable to USING or use String Templates.

Upvotes: 3

Related Questions