Supported by
Supported by Inetum

Use & in SAPSript texts

images/thumbnail.png - Thumbnail

Let’s say you want to show an url in a SAPScript layout. You place the url in a SAPSCript text and assume everything will work fine. Because most times everything does work fine. It’s just that sometimes…

Disease

If you try to use this url:

https://era.uma.vez?ums=mulher&com=cara&de=bolacha

This will be printed:

https://era.uma.vez?ums=mulherde=bolacha

Strange, right?

Diagnostic

It’s not immediately obvious but the problem is that SAPScript variables are limited by &:

My name is &SY-UNAME&.

So, SAPScript looks at that url and sees variable &com=cara&, replacing it by its content. But since this is not really a variable, its content is empty. As a result both &s and whatever is between them mysteriously disappear.

Treatment

The solution is to let SAPScript know that those & are really &. E for that you need to escape them:

<(>&<)>

Why did they come up with such a far fetched escape sequence? Because it’s SAP. Anyway, just note it down and move on.

So, in order for the url to be correctly printed, this is what you must put in the SAPScript text:

https://era.uma.vez?ums=mulher<(>&<)>com=cara<(>&<)>de=bolacha

Problema solved.

Thank you David Ralo!

Greetings from Abapinho.