Personal Insights
Editing JSON embedded in ABAP strings
I have many unit tests which takes JSON as input, however editing JSON embedded in a ABAP string is a mess. And no, ecatt test data containers is not an option, never use it for anything in unit tests, but its a different story.
One option is to use string templates,
DATA(json) = |\{\n| &&
| "hello": 2\n| &&
|\}|.
It does require escaping the squiggly brackets, so I tend to do the following instead,
DATA(json) = `{` && |\n| &&
` "hello": 2` && |\n| &&
`}`.
Which is also a mess, but easy to add when using multi cursors.
After adding the JSON, I sometimes need to edit the JSON, and I typically mess it up, so the syntax is wrong or something else 😒
Lets add tooling to easily edit the JSON 😎
Introducing abap-json-editor, right click the start of the ABAP string to open an new editor. Changes in the JSON editor is automatically validated and reflected in the ABAP code,
Plus it allows for easy pasting of JSON from clipboard,
The extension will work with standalone ABAP files, files from ABAP fs by Marcello Urbani, plus on web only
Immediately released to everyone 😅 bug reports and fixes welcome on github.
Excellent!
If I'm not wrong, there's nothing in Eclipse/ADT to help in this (so nicely), hopefully SAP developers have probably subscribe to your blog posts and will include such a nice feature soon...
well, to be fair, I did spend a few hours messing around with the vscode API
Cool workaround! Hopefully ABAP will get multi line string literals at some point.
ADT has a feature to escape and line break contents when copy pasting it. But that doesn't help editing or reading anything later.
How to wrap long strings automatically in ADT | SAP Blogs
yea, hopefully 🙂
Your extension is good! Thank you!
However, for my opinion for unit tests more understandable would be use abap-structures like in the following
yea, its just a different kind of test
if the team knows JSON, and is used to transfer JSON, its a different world to know the ABAP language. If the input to the logic is JSON then I recommend testing it as JSON
Cool feature.
And some questions.
I'd like to know, did you often use VS Code to edit ABAP?
Or just some specific scenarios that like JSON-EDIT?
In your opinion, is VS Code better than ADT when edit abap except CDS?
I'd say I spend 80->90% of my time developing ABAP in vscode, in a standalone setup editing just files -> pushing -> git -> then pulling into the system with abapGit.
The rest of the time I use SE24/SE80, I dont do very much CDS.