08-07-2019 12:53 PM
Hello all,
I have very simple requirement, where I need to print a text in output using text element.
I created a text Element like
001 Text1 &1 Text2.
In the program I am using this text element inside a loop. When I try to use "WITH", it is resulting error.
loop .....
Write:/ text-001 with lv_var1.
Endloop
Kindly guide me to resolve this.
Thanks
08-07-2019 1:13 PM
The "WITH" option only works if your using a message class and are giving messages.
For what you want to do I would place text-001 in a different variabel and then use REPLACE to change &1 with your other variable.
08-07-2019 1:13 PM
The "WITH" option only works if your using a message class and are giving messages.
For what you want to do I would place text-001 in a different variabel and then use REPLACE to change &1 with your other variable.
08-07-2019 2:03 PM
Thanks for your reply!
I am new to ABAP, I know that we cannot use "WITH" in write statement.
For understanding purpose only I used like that.
Your idea is good and it will work, is there any other way without creating temporary variable, in your case?
Thanks again!!
08-07-2019 2:09 PM
Follow the recommendation of Arthur & use the message class.
Otherwise, create 2 texts and do a lv_result = text-001 && lv_value && text-002.
08-07-2019 2:09 PM
From the top of my head I would say split your text element in to 2 different elements. You could then use
write:/ text-001, lv_var1, text-002.
08-07-2019 2:44 PM
I recommend to avoid splitting the string into multiple text elements. This can cause problems during translation, as the variable position may differ in various languages. Either use a message class or the REPLACE statement.
Whenever I cannot use message classes for any reason I do something like this to emulate the behavior
message = message_with_symbols.
REPLACE FIRST OCCURRENCE OF '&' IN message WITH variable1.
REPLACE FIRST OCCURRENCE OF '&' IN message WITH variable2.
...
REPLACE ALL OCCURRENCES OF '&1' IN message WITH variable1.
REPLACE ALL OCCURRENCES OF '&2' IN message WITH variable2.
08-07-2019 2:51 PM
The only reason I suggested splitting was because he asked for a way to try and realize it without a temporary variable. Personally I would go with the temporary variable and the replace option, and the reason would most likely be to prevent issues with translations like you indicated.
08-07-2019 3:17 PM
aparisius
My intention was to emphasize that a temp variable today is better than a translation issue tomorrow 🙂
08-07-2019 3:56 PM
DATA(message) = replace( val = 'Hello &1 how are you doing?'(001) sub = '&1' with = 'Angela' ).
08-07-2019 1:28 PM
Hi Karthick,
if you want to print the value of text-001 and lv_var1 together then you can write -
lv_var = text-001 && lv_var1.
then print using write statement.
08-07-2019 2:05 PM
Hi Bhupendra,
Thanks for your response.
I am using dynamic variable in between the text symbol.
So, your idea wont work in my case.
Suggest if you have any other idea.
Thank you
08-07-2019 3:32 PM
Hi
Either use a Message class text or Replace as has been explained bellow.
Data : l_text type string.
l_text = TEXT-I01.
REPLACE '&1' WITH v_inr INTO l_text .
REPLACE '&2' WITH y_tbr INTO l_text.
CONDENSE l_text.