Skip to Content

I recently came across a customer who wants to use a Design Studio result set into a custom table component, but wanted the result set as an array, instead of a JSON.  Those of you who have played around with the Design Studio SDK have probably encountered the two different kinds of result sets before. The first kind comes into play when the designer is asking for a subset of the result set (e.g. a single column), she gets two files back; one with the metadata structure and the second with the actual data.  The second kind of result set comes when the designer asks for the entire result set. It combines both into different forks in the same JSON structure.

This is a bit more complex than a simple array.  😉   So I created a small github project with a javascript library for doing this kind of transformation.

davidhstocker/SAPDSResultSetTransformer · GitHub

The centerpiece of the project is a javascript file containing a single function.  tuplesformatTransform.js contains the reformatIntoSimpleTuples() function.  reformatIntoSimpleTuples() transforms the single JSON result set into a list of tuples for easier consumption in some cases. 

reformatIntoSimpleTuples() takes two parameters:

  • zenResultSetJSON = the result set that you wish to transform.  It must be of the single JSON result set type as described in the Design Studio developers’ Guide.
  • displayType = the display type (‘key’ or ‘text’) that you wish to use.  You fill your result set tuple list with either key or text values.

reformatIntoSimpleTuples() holds most of its variables in the local scope.  It creates two in the global scope for use in other places:

  • headerTuple compresses the (potentially) multi-leveled header into a single header line, with the stacked text concatenated into each cell.
  • rowTuples contains each row with the following format: [row measure members1, rmm2, …, rmmN, row dimension members1, rdm2, …, rdmN, data1, data2, …, dataN]

So a the headers of a result set that looks like this:

Q1 2014 Q2 2014
Sales Cost Sales Cost
Boston
New York
Singapore

Would be transformed to this headerTuple: [“”, “Sales Q1 2014”, “Cost Q1 2014”, “Sales Q2 2014”, “Cost Q2 2014”]

Also included in the github repo are two sample files to demonstrate the function in action.

  • entureResultset.js contains an example result set; what resultset being fed to a Design Studio SDK component might look like.
  • html5.html is an example html file, with an SAP UI5 table.  The html file’s script calls reformatIntoSimpleTuples(), using the sample data from entureResultset.js and puts that data into the UI5 table.
To report this post you need to login first.

6 Comments

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

  1. Mike Howles

    Thanks, David.

    I ended up writing a similar utility library to “flatten” out the tuples into a more of a 2D array usage, but I’m sure yours takes a much more coherent approach 😉

    I especially like the simpleTuples example where you are concatenating a more complex multi-leveled columns scenario.  I’ve always called this “concatenating excess dimensions 😉 “.

    Great stuff.  I hope you do not mind if I take your example code and implement into a complete Design Studio extension example?

    (0) 
    1. David Stocker Post author

      Go right ahead.  I put it on Github, so that people will use it. 🙂   I do think you might need to make a small change.  There is a small bug in the “concatenating excess dimensions” step.  It should insert a space between the concatenated dimension/measure names, but it is not.  I forgot to fix it, but cringe every time I see it in action.

      (0) 
      1. Mike Howles

        Hey, David.

        I think I may have run into a bug in your function.  Let me explain:

        Everything works great when there is only one dimension in rows, however, if I’d like to include a 2nd or more, it looks like you are only returning the dimension’s member list values by index, where I think you mean to use the tuple’s index that refers back to that member index.

        Somewhere here in your code:

        //Add the leading row labels

          for (var j = 0; j < rowDimensions.length; j++) {

          if (typeof(rowDimensions[j][i]) != “undefined”){

          rowTuple.push(rowDimensions[j][i]);

          } else{

          rowTuple.push(“”);

          }

          }

        Here’s 2 screenshots which may help illustrate the current problem:

        Initial View setup, note 2 dimensions in rows:

        /wp-content/uploads/2014/07/ui5table1_499068.png

        At runtime, note the collapsed 2nd dimension values because of this issue:

        /wp-content/uploads/2014/07/ui5table2_499069.png

        I think this can be corrected with a line or 2 of code, and if I end up with some free time, I’ll post the change.

        (0) 
        1. David Stocker Post author

          Hi Michael,

          I’ll have to fix that.  I’d not tried it with a dataset that had more dimensions in the rows, unless you’ve already fixed it.  😉

          Cheers,

          dave

          (0) 
        2. VIPUL DESAI

          Hi Michael,

          Can you help me with the code to bind the dataset to the Table UI5 control.

          I realized that this works differently then the usual afterUpdate function in design studio.

          Regard’s,

          Vipul

          (0) 
  2. David Stocker Post author

    I had a chance to track down the bug that was causing the problem that Mike noticed and updated the GITHub project to reflect the algorithm changes in formatTransform.js.  There is a new file there, called multiDimensionResultset.js, which contains a resultset json that I grabbed off of a query on one of our demo systems.  Yeah, I’d not suppressed totals before grabbing the json.  🙂 Screen Shot 2015-02-12 at 18.42.20.png

    (0) 

Leave a Reply