Additional Blogs by Members
Showing results for 
Search instead for 
Did you mean: 
Active Contributor

Nowadays, everyone knows URL shortener services and even you don't know it you are using it.

Twitter automatically translates every URL into a shorter URL, Google has is own service and there are so many others...

In my last project I had to configure NWBC and I faced a problem. Do you know that URL for menu entries in PFCG is just 132 characters?

Usually this is enough, but in my case it was not...

I had to link Cognos reports, that believe me are really long URL and even more due to a bug with SAP Fiori Launchpad I had to apply a workaround to have my theme applied as described by note 2092412, and it generates long URLs.

So I decided to use shorten URL, but I had to face two problems:

  1. User have no access to URL shortening service (Internet access is limited)
  2. It is not in the security policy of the company to use an external service for shortening

The idea

Why do not use an URL shortening service in ABAP?

I checked on the SAP help and I didn't find any solution. In 2010 roel.vandenberge wrote a blog in order to integrate public URL shortening service with ABAP URL Shortener Service in ABAP, but it can't be used in my scenario due to constrain number 2.

Why do not create an URL shortening service in our ABAP system?

The approach

URL shortening concept is really simple: find a short string that identifies a long URL. Usually this short URL is a 6 characters long string...

So having this in mind I grouped the alphanumeric chars using this map:

0 → a
1 → b
25 → z
25 → A
51 → Z
52 → 0
61 → 9

Having a 6 character string as unique identifier and using this scale, it is like having 56,800,235,583 unique shorten URLs. Is that enough?

Where does this number come from?

Each short URL can be considered an unique ID, so for instance id 000000 is the short url aaaaaa, 000001 is aaaaab and so on till 56,800,235,583 that is short URL 999999

The solution

I have created a model class ZCL_T3G_AUS_MODEL that has the conversion logic from short URL to ID and viceversa, a transparent table that stores the short URL generated ZT3G_AUS_LINKS and I've also included a blacklisted/reserved table ZT3G_AUS_SLINKS.

Why a blacklisted/reserved list? I think that you don't want that a short URL is the name of your biggest competitor or an impolite word, even more you want to have some friendly short URL like <mycompanyname> or <myproductname> free for use for some specific links.

In SICF I created a new independent service named s (this can be whatever you want)

An HTTP Handler ZCL_T3G_AUS_HANDLER is associated to this service and it is responsible to translate the short URL to the original URL

Short URL example


Below an example of URL translation from the short url http://yukon.techedge.corp:xxxx/s/aaaaaf to my personal blog

If you try to link an unknown URL a 404 HTTP error is thrown

Here it is my Christmas present to the SCN Community.

Code is shared as open source on GitHub using SAPLink. It should be compatible also on lower releases, maybe some code syntax has to be adapted. Use it and if you have any suggestion just collaborate!

Code has been checked with DoctorZedGe and it has A+++ score

Top kudoed authors