ABAP URL shortener
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:
- User have no access to URL shortening service (Internet access is limited)
- 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)
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
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
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.
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.
Andrea Olivieri
do you remember the problem with the links in our PDF table? đŸ˜€
Thanks for putting a nice article with so much ease.
Nice Blog Ivan đŸ™‚ Something new with ABAP
Hi Ivan, though this is new to me, SAP has already provided an option if URL is more than 132 characters. you can just split URL and put it in SSM_VAR table, and everything is taken care of.
Good to know.
Here a Wiki page with an example
SAP GRC NFE 1.0 - User Role Using the SSM_VAR Table - Business Process Expert - SCN Wiki
Thanks Ivan for sharing the blog.... Thanks to Raghavendra for showing workaround.......
Hi @ivan.femia! I was so excited when searching Google for a URL shortener and finding this post. However, I'm having trouble getting it to work. I'm wondering if you can assist me. Might be that my expectations are too high, but hope not.
First, I've implemented the solution and it works great when working in SAP and calling the link from within SAP. In this case I create a short url and save it on a PO or any document. The user accesses the PO and click on the link and the correct URL opens. I guess in this case Raghavendra's comment about using SSM_VAR is valid.
Now - I was hoping your solution means I can add the URL to an email and send it out. When the recipient clicks on the link from any external source, SAP will convert it to the long URL and present it in the default browser. So I want to translate the URL on inbound messages also. In my case I send a Workflow Workitem and I want to user to be taken directly to the Workitem so they can analyse any errors.
Long URL - http://vsapdevci.vecnet.co.nz:8000/sap/bc/gui/sap/its/webgui?~transaction=*SWNWIEX P_WI_ID=12026291;P_APPL=UWL;P_ACTION=DISPLAY
Short URL - https://vsapdevci.vecnet.co.nz:44300/s/aaaaac and
http://vsapdevci.vecnet.co.nz:8000/s/aaaaac
When I place an infinate loop in IF_HTTP_EXTENSION~HANDLE_REQUEST() of class ZCL_T3G_AUS_HANDLER it enters the code when selecting the link from within SAP and I can debug it from there, but not when clicking the link from my email client.
Please help, I'm desperate for this to work.
Cheers,
Corné
Okay, it is as amazing as I thought! Thanks for sharing. It is extremely helpful.
The issue I had was that the path was hard-coded in program ZT3G_AUS_GENERATE to:
I added /sap and now the path is resolved.
Thanks again for your contribution.
Cheers,
Corné
Hi @Corné van de Ven,
I have a similar problem, I am supposed to be rendering this service link to external customers. I am able to open the shortened link via the Handler class but the same would give me a 404 error or page doesn't exist error when accessing outside of the company network.
Can you please shed some light on this on how to get this working? this is an amazing solution if it works for me because I am putting it on a QR code for scanning.
Thanks