Skip to Content

One common question people ask is, “How do I create a custom table in a Personas flavour?” The standard answer is that you can’t – Personas does not have a table object you can add to a flavour and while there is a “CopyTable” action to copy content from a standard table, there’s no “PasteTable” action to put it back. But maybe you can fake it using the objects and actions that do exist? I had a request for a Personas flavour that would have been best implemented as a custom table so I thought I’d give it a try!

The scenario I was given is PO Release. We have a good number of users that do very little but release purchase orders. Currently they do that via ME28 or ME29N, and need to know the intricacies of release codes and release groups. I wanted to try and build something that made this easier for them. The first step was to create a custom report that lists all the POs waiting for release with a release code they have access to, so they didn’t have to think about codes and groups. This isn’t a particularly complex report, but does require digging through a user’s profiles and authorisations. There are BAPIs to help with this. I won’t show the details of this report here, as that’s not the point of the blog. The end result is a report that looks like this:

Screen Shot 2014-02-17 at 11.09.26.png

I could build the release functionality into this report, but one thing that our existing Personas users like is being able to carry out tasks directly on the home screen (see Putting everything together – the finished Personas project). That means creating custom objects and scripts to copy data from transactions back to the home screen and manipulate it. What I needed to do was reproduce this table on the home screen, but as I said earlier there’s no Personas table object. What I ended up with was this:

How did I achieve this? Firstly all the fields are standalone fields. The “refresh” button calls the above report, uses “CopyTable” to extract the data, JavaScript to transfer the data to a lot of separate variables (ponum1, ponum2, ponum3, etc…), and then a lot of “PasteValue” options to put them in the custom text boxes. Making it scroll adds some complexity. Here’s the same video with a couple of hidden fields visible to see how the scrolling works:

The field on the right controls how many rows of the table in the original transaction to skip before copying. As you scroll down, this goes up. The field on the right is simply the number of rows in the table, and is used to stop the “scroll down” button from scrolling past the end of the table. The scroll buttons check that scrolling is possible based on these two fields, and adjust the number to skip as appropriate. Most of the hard work is done in a hidden button – let’s call it the “Fill” button. The script here is the most complex.

The first steps just initialise the “lines to skip” field and then run the report. Here I’m running it via SE38 – for productive use the report would have its own transaction code:

Screen Shot 2014-02-17 at 13.38.44.png

Screen Shot 2014-02-17 at 13.39.05.png

Next I copy the table and extract the data. It generates a separate variable for each value copied – ponum1, vendor1, date1, ponum2, vendor2, date2, etc. This is all done in two JavaScript steps, one to empty all these variables and the second to copy the values.

Screen Shot 2014-02-17 at 13.40.20.png

The second JavaScript is where we take into account which row to start the copy process – notice the use of the “first” variable

rows = args.po_list[0].length;
args.rows = rows;
first = parseInt(args.first);
if(rows-first > 1) {
    args.ponum1 = args.po_list[0][first+1];
    args.vendor1 = args.po_list[1][first+1];
    args.date1 = args.po_list[3][first+1];
    args.relcode1 = args.po_list[4][first+1];
}
if(rows-first > 2) {
    args.ponum2 = args.po_list[0][first+2];
    args.vendor2 = args.po_list[1][first+2];
    args.date2 = args.po_list[3][first+2];
    args.relcode2 = args.po_list[4][first+2];
}
if(rows-first > 3) {
    args.ponum3 = args.po_list[0][first+3];
    args.vendor3 = args.po_list[1][first+3];
    args.date3 = args.po_list[3][first+3];
    args.relcode3 = args.po_list[4][first+3];
}
if(rows-first > 4) {
    args.ponum4 = args.po_list[0][first+4];
    args.vendor4 = args.po_list[1][first+4];
    args.date4 = args.po_list[3][first+4];
    args.relcode4 = args.po_list[4][first+4];
}
if(rows-first > 5) {
    args.ponum5 = args.po_list[0][first+5];
    args.vendor5 = args.po_list[1][first+5];
    args.date5 = args.po_list[3][first+5];
    args.relcode5 = args.po_list[4][first+5];
}

That’s the interesting part over. Now we just head back to the home screen and paste everything into all the custom fields. Long and tedious… 🙂

Screen Shot 2014-02-17 at 13.49.53.png

Screen Shot 2014-02-17 at 13.50.08.png

Screen Shot 2014-02-17 at 13.50.37.png

Screen Shot 2014-02-17 at 13.50.49.png

Screen Shot 2014-02-17 at 13.51.39.png

Screen Shot 2014-02-17 at 13.52.01.png

With all that done in the hidden “fill” button, the scripts on the visible buttons are easy. The refresh button simply initialises the hidden “first” field to 0 and then pushes the “Fill” button. The “Scroll up” button subtracts 1 from “first”, unless it is 0 already, and pushes the “Fill” button. The “Scroll down” button adds 1, unless that would take us too far, and pushes “Fill”. In both cases you need to use JavaScript to do the arithmetic, but otherwise the scripts are straightforward.

Overall I’m very pleased with the effect, although I’d like to try and optimise the scrolling a little. I’m not sure my users would like the slow response time. It is also going to put a lot more load on the backend system, because it calls the report afresh for each scroll step. You wouldn’t want to do this unless the table was short and the report very quick. Consequently, I’m not sure I’d want to use this technique often – using a proper table on a proper SAPgui transaction would certainly be preferable. In the right context, though, and bearing all these things in mind, it might be useful occasionally. And it was fun building it!

Are there any situations where you’ve wanted a custom table in a Personas flavour, and this technique might work for you?

(I’ll blog the rest of the PO Release app separately – this blog is already long enough…)

To report this post you need to login first.

22 Comments

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

  1. David Liou

    Hi Steve,

    I really enjoyed reading this article. It was really informative. I am new to programming and personas. So I am still having some trouble with understanding some script/code. Do you have a video available where you go through all the steps? It would really help my company a lot. Appreciate any help you can give.

    Thanks,

    David

    (0) 
    1. Steve Rumsby Post author

      How much work have you done with Personas so far? This is definitely on the bleeding edge for Personas, and if you are new to it I’d start with something simpler and come back to this once you have a better feel for the product. Once you’ve built a few flavors and written a few scripts, the above blog post should make more sense. To be honest, I’m not sure a video of the whole process would help – most of it is pretty tedious clicking around.

      Are there specific things you’re not understanding? Perhaps it would be easier to start with those?

      Steve.

      (0) 
        1. Steve Rumsby Post author

          The report the data comes from has more lines, typically, than are displayed in the custom “table”. First is the line number in the source data that is displayed on the first line of the custom table. So scrolling down is just increasing first and re-drawing.

          (0) 
  2. Michael Dräyer

    Hi Steve

    Thanks for that inforamtive and interesting article. Personas 3.0 is, as you might know, in ramp-up. Do you know if there will be the possibility to create tables without having that lot of work like u obviously had?

    By the way: I admire your great staying power, tanks for sharing those “documentations” 😎

    (0) 
  3. Todd Barber

    Steve,

    Great article.  And to answer your question – yes, we could definitely use a table object (something like an ALV grid) that could be used on any screen.  The ability to copy the table without a paste table can be quite limiting.  Hopefully this will be added functionality in the future.

    Thanks,

    Todd

    (0) 
  4. Daniel Ruiz

    hi Steve,

    trying to use this personas version at this moment.. when I use the Copy Table on a table, I have a System.String[][] as return.. even thou the table contains at least a few rows of data..

    how do you actually get to access the table? – I’ve noticed your element naming convention seems slightly different from what I have here (ses[0]/wnd[0]/usrUSRAREA/tabstripTAB_GROUP_10/tabpageSUB_GROUP_10SAPLIQS07120/tblSAPLIQS0MASSNAHMEN_VIEWER) and I wonder if this is the issue.. or I might be clicking in some incorrect position of the element, trying over a column it does add something else into the element name, but again nothing is being returned..

    Cheers,
    D.

    PS: oh I see now.. even thou it does not print properly I still can access element using the matrix indexes..

    (0) 
    1. Steve Rumsby Post author

      Yes, in the JavaScript action you can treat the result of “Copy Table” as an array and access all the individual elements.

      If you have any other questions about this, do feel free to ask:-)

      Steve.

      (0) 
      1. Daniel Ruiz

        hi Steve,

        can you update the table back using the method above? – another question, does the F4 works on fields, for instance ‘DocNo’ in your example?

        I was just wondering how you updated the table on the original transaction, I cannot seem to find events for such..

        🙁

        Cheers,

        D.

        (0) 
        1. Steve Rumsby Post author

          This example is a read-only table, as you’ve noticed. Also, remember that there’s no connection between my fake table (really just a collection of text fields) and the original. Any connection would have to be built in the scripting. Honestly, I think it would be a lot of work and I’m not sure it would be worth it. I would start looking at other technologies if you needed writeable custom tables. That obviously depends on your scenario though.

          I’m not sure this gets significantly easier even in Personas v3.

          Steve.

          (0) 
          1. Daniel Ruiz

            hi Steve,

            yeah, read-only I’ve used http://www.datatables.net/ – it’s quite a nice result, pagination, scrolling, filtering, sorting etc etc – but to send the data back to Personas is actually consuming some of my time, I cannot seem to be able to access a table’s cell from scripting and neither modify the [][] on the table itself.

            I believe it might be easier on Personas 3, just from what I saw.. JS support is far easier there, and we can select and modify table cells, so I assume it works relatively easy.

            Cheers,

            D.

            (0) 
            1. Steve Rumsby Post author

              You can modify standard table cells via scripting, but the scripting editor doesn’t make it easy to get references to individual cells. Instead, use the recorder to record yourself entering data into cells, and the generated script will have the correct cell references.

              Steve.

              (0) 
  5. Rohith Brungi

    Hi Steve,

         I followed almost all articles from you,and gained knowledge on SAP Screen Persona’s from your articles,I developed couple of screens and now i had given a task to customize XK01 transaction.

        My main requirement is to replicate the table in third/fifth screen into first screen as shown below.

    Can we achieve it using Persona 2.0 version?

    As Shown Above,I want to replicate the same into first screen,can I achieve it?

    If yes,can u help me how to achieve it.

    (0) 
    1. Steve Rumsby Post author

      I think that would be a particularly difficult task. My guess is that it can’t be done, especially in Personas 2. I honestly wouldn’t try. It might be possible using UI5 tables in Personas 3, but even that is stretching Personas quite a lot. A display transaction might not be too bad, but a create transaction requires a lot of interactivity in the tables, and that’s just hard. You’d essentially be writing a UI5 app inside a SAPgui shell. You might as well skip Personas and go for a native UI5 app.

      Just my opinion.

      Steve.

      (0) 
      1. Rohith Brungi

        Thanks Steve for quick response.

            Can u help me giving the best approach for customizing the XK01 transaction using Persona into a single screen(if not how many screens we can go for),actually my customer need the total XK01 transaction to be in one screen….

        (0) 
        1. Steve Rumsby Post author

          The big problem is the tables. If you can design the screens to avoid the need for tables, then I don’t see a problem simplifying it to a single screen.

          However if your customer needs all vendor master creation in one screen, and needs those various tables to be part of it, my suggestion is that Personas is not the tool for the job. Consider building it as a UI5 app instead.

          Steve.

          (0) 

Leave a Reply