Skip to Content
Technical Articles
Author's profile photo Andre Fischer

How to wrap long strings automatically in ADT

I am currently working on using json strings as input for my RAP generator tool.

Here I ran into the problem that I had to provide a (very) long json string as an input for a class that is run as a console application.

But also when using a simple json string such as this one (taken from Wikipedia) it is not possible to use cut & paste to work with it in ADT.

Error%20when%20using%20cut%20and%20paste%20with%20default%20editor%20settings

Error when using cut and paste with default editor settings

 

… unless you know which settings you have to change for your ABAP editor in ADT.

From the menu choose Window –> Preferences and there ABAP Development –>

Editors –> Source Code Editors or you search for source code editors in the Preferences dialogue.

Here you have to activate the check box Escape text when pasting into a string literal.

Preferences%20-%20Escape%20text%20when%20pasting%20into%20a%20string%20literal

Preferences – Escape text when pasting into a string literal

 

When you now use cut and paste and paste a long string, a json string or even an xml string to your source code within the placeholders for a literal

json_string = ''.

all strings will be wrapped automatically

Result

Result

 

 

 

Assigned Tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Jelena Perfiljeva
      Jelena Perfiljeva

      Good tip, thanks for sharing!

      I would've glanced right past this setting, would never think that "escape text" means "wrap text". To me, "escape" is more associated with "escape character" and not with wrapping. Note that the blog title also uses the word "wrap". 🙂 I'm wondering if wording can be possibly updated here.

      Author's profile photo Andre Fischer
      Andre Fischer
      Blog Post Author

      Hi Jelena,

      you are right. I will check with the developers.

      What also came to my mind whether this checkbox should be checked by default when using the default perspective?

      Best Regards,

      Andre

       

      Author's profile photo Andre Fischer
      Andre Fischer
      Blog Post Author

      The text has been updated.

      It now reads "Wrap and escape text when pasting into string literal" in my daily build.

      It will become available with the next update, I suppose.

       

      Author's profile photo Vijay Sharma
      Vijay Sharma

      Very useful. Thanks Andre Fischer  for sharing!!

       

      Author's profile photo Sandra Rossi
      Sandra Rossi

      I had used this option, it's perfect for this case but becomes horrible when it's copy/cut/paste expressions in string templates because { and } are automatically converted to \{ and \}. (technically it's not possible to know whether I want to keep the copied text as-is or to be escaped)

      Example (before/after copy/paste):

      (before)
      column_name = |{ sql_trace_line-object }~{ column_value_at_offset->name }|.
      
      (after cut/paste from right to left)
      column_name = |\{ column_value_at_offset->name \}{ sql_trace_line-object }~|.
      

      Maybe I should try again this option, because I see now that I may drag & drop instead of copy/cut/paste, without escaping { and } when the option is selected...

      Author's profile photo Andre Fischer
      Andre Fischer
      Blog Post Author

      Yep, drag and drop worked in this case.

      column_name = |{ column_value_at_offset->name }{ sql_trace_line-object }~|.
      Author's profile photo Attila Berencsi
      Attila Berencsi

      Hello,

      maybe a new entry in the context menu (right-click) of the Editor below Paste entry could be added. Like Paste with Wrapping etc. The list is too big already, I know, bu this would be easy and fancy for devs. Similar way like in Notepad++, the Copy and Copy with Syntax Highlighting feature, or managed paste operations in document editors.

      BR,Attila

      Author's profile photo Florian Henninger
      Florian Henninger

      Nice setting.. but why would someone have xml-strings or json-strings copy paste like that...

      so my golden rule is,

      Bart Simpsons Chalkboard

      (Image-Source: https://www.kotzendes-einhorn.de/blog/2010-12/bart-simpson-tafel-generator/)