Skip to Content

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 goo.gl 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 van den Berge 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)


SICF.PNG


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

http://<server_name>:<server_port>/s/aaaaaa

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

REDIRECT.PNG

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

404.PNG

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

Code Quality.PNG

To report this post you need to login first.

8 Comments

You must be Logged on to comment or reply to a post.

  1. Florian Henninger

    Hi Ivan,

    this is really cool. Thank you for sharing that. I never thought about this problem in ABAP but hey, it is good to know, that there is a ready to use solution.

    ~Florian

    PS: Your Code-Checker is funny.

    (0) 
  2. Gareth Ryan

    Really like this.  I currently have absolutely no use for it but fancy implementing it in one of our demo systems, just for the sake of it!

    Cheers,

    G.

    (0) 

Leave a Reply