Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member


You can achieve a lot with Personas scripting, but ultimately it is just driving existing SAPgui transactions. And that limits how much you can do with Personas. Or so I thought, until I discovered that you can call WebRFC functions from a Personas script. Here is the example that motivated me to investigate WebRFCs.

Sometimes the task you want to achieve is very simple, like looking up a user's real name or the description of a cost centre, using the "transaction free lookup" technique described in this document: Personas idioms. This technique is much quicker than running the transactions manually, but it is still running the transactions behind the scenes. Because the user interface is now much simpler, the overall response time can feel much longer. One way to make things more responsive is to call a Web RFC to do the lookup instead of calling a transaction. A Web RFC is an ABAP function called via HTTP and returning its results in the same way. WebRFCs are described in general in this blog by sebastian.steinhauer - WebRFC - simply calling an RFC from javascript. From Personas, calling a WebRFC is an action you can add to a script. You can pass values to it via the URL and values returned are put into Personas variables, from where they can be pasted into screen fields or otherwise manipulated as normal. Here is a simple example of looking up a user's name via both techniques, first the traditional method of calling SU01 (described in this blog - Personas scripting overview) and second by calling a WebRFC.



Notice how the second, WebRFC based lookup, feels so much faster.

I won't go into the detail of writing a WebRFC function and how it interacts with the HTML protocol - Sebastian's blog does that perfectly. I started with his example from that blog and wrote this function that simply looks up a user in USR03 and returns the corresponding name. This is a demo and not intended to be an example of good code :wink:
FUNCTION ZPERSO_TEST.
*"---------------------------------------------------------------------- *"
*"Local Interface:
*"  TABLES
*"      QUERY_STRING STRUCTURE  W3QUERY
*"      HTML STRUCTURE  W3HTML
*"      MIME STRUCTURE  W3MIME
*"  CHANGING
*"     REFERENCE(CONTENT_TYPE) LIKE  W3PARAM-CONT_TYPE DEFAULT
*"       'application/json'
*"     REFERENCE(CONTENT_LENGTH) LIKE  W3PARAM-CONT_LEN
*"     REFERENCE(RETURN_CODE) LIKE  W3PARAM-RET_CODE
*"----------------------------------------------------------------------
  DATA: name TYPE STRING.
  SORT QUERY_STRING DESCENDING.
  READ TABLE QUERY_STRING WITH KEY NAME = '_Name'.
  name = QUERY_STRING-VALUE.
  translate name to upper case.

  data: first like usr03-name1, last like usr03-name2.
  data: fullname(60) type c.

  select single name1 name2 from usr03 into (first, last) where bname = name.
  concatenate first last into fullname separated by space.

  DATA: htmldoc LIKE LINE OF HTML.
  CONCATENATE '{"results": [ {"key": "fullname", "value": "' fullname '"}]}' INTO htmldoc-line.
  INSERT htmldoc INTO TABLE HTML.
ENDFUNCTION.

I then call this function from a simple Personas script like this:



Step 2 in that script doesn't fit in the screenshot. The complete URL is:
https://wfs-ci.warwick.ac.uk/sap/bc/webrfc?_FUNCTION=ZPERSO_TEST&_Name={name}

Obviously you can use this technique to lookup anything, including data you might not be able to get easily from an SAP transaction. More intriguingly, a WebRFC can perform updates as well as lookups. I've always viewed Personas as just a way to "reskin" SAPgui, and perhaps use scripting for a bit of automation. However, it is also a way to build user interfaces to ABAP functions and so can be used to add completely new functionality. Would you build functionality that can only be used through a Personas interface? I'm not sure, but it is certainly an interesting idea and a technique I hadn't anticipated when I first started looking at Personas.

If you have suggestions for interesting things to use this technique for, do add them in the comments below!

 

Update: You'll notice that the "Call WebRFC" action in the script above has the server name hard-wired. That's obviously not ideal if you want to do your flavour development in a dev system and transport them. You can use a little bit of JavaScript to solve this problem, extracting the server & protocol details from the URL for the current page and using that to build the URL for the WebRFC call. tamas.hoznek has written the details here: Keeping the WebRFC URL dynamic in Personas.


56 Comments