Jonathan Andre is a lead ABAP developer at IT Partners. Jon is also the President of Andre Technical Consulting LLC located out of Centreville, Virginia. Jon has over 6 years experience with SAP, with a concentration on ECC SD, MM, and IS-OIL modules. Jon’s focus has been in the areas of ABAP OOP and ABAP Web Dynpro. He can be reached at firstname.lastname@example.org
The last topic for this blog series will cover Screen Personas Scripting. This is by far the most powerful feature that Screen Personas offers. Scripting allows the automated execution of steps a user can perform, and can be used to populate fields and/or carry out actions.
To illustrate exactly how scripts are created and executed, we will revisit and complete the Sales Order – Quick Query control we mocked up in the blog SAP Screen Personas: Get Up and Running Quickly Using These Steps. This time, however, we will actually create a script to populate our text fields when we click the “Go” button.
Our first step will be to add a Script Button to our tool. The Script Button can be found on the Insert Tab near the Transactional Button we used extensively in past blogs.
Next, we will create a script to perform the actions of retrieving the data we wish to populate. To do this, we will have to exit the Flavor Editor and return the to main Persona Management screen, then click the Scripting button located in the bottom right corner
From here, we will hit the Create Script button, name our Script then Start Recording. The Start Recording feature will automatically record our actions in the scripting language. Any action performed, from navigating to a transaction to clicking a certain tab or field, is documented and repeatable by executing the recorded script.
Once the recording has begun, navigate to the transaction you wish to record. In this particular scenario, we will be navigating to VA03. As we do this, we will see the script populate with code that will navigate to the T-code.
Once we arrive in the VA03 initial screen we will enter a sales order number (14642) to allow us to proceed to the next screen. Our ultimate goal, however, is that we can replace this sales static order String with any sales order the user enters into the tool. We will get around to making this possible by editing our script manually later, but for now, we will just take note of the point in the script the sales order number is entered.
In the Overview section of VA03, we spot the first piece of information that we want to be returned to our Sales Order control tool in an automated fashion. We would like to store the Sold-To party for this Sales Order. The Scripting functionality provides an automation tool that will allow us to generate the code to find the value of this or any other on-screen element by selecting it.
Before we do this though, we will pause our script recording to avoid unintentionally recording any steps.
We will then navigate to the Inspector tab and select the Object Inspector tool
With the Object Inspector tool active, we can click on any screen element to reveal its attributes in the Inspector tool. We are searching for the “text” attribute of the Sold-To party field.
From here, we can click the Pencil icon next to the “text” attribute to automatically add the “session.findById” code into our script. The value of the variable added to our script contains whatever text is currently in the field.
To store this information and allow it to be returned to the Dashboard Sales Order tool, we need to place it in our own created variable. We accomplish this by typing the following code
Var [variable name] = [automatically populated variable by Inspector tool]
We will store the contents of this field in a variable named “cust”. This variable will always hold the value of this field, regardless of the particular value or the current sales order on the screen.
With the Recording still paused, we can repeat the Object Inspector, text, and variable creation pattern for each field until we have retrieved all of the information required from this screen and tab. In the for Sales Order Query Tool, we would still want to locate the Material and Quantity from this tab.
The final field we would like to retrieve from the VA03 transaction is Delivery Status, which is not on the Sales tab, but on the Shipping tab. To retrieve this information, we click Start Recording, navigate to the Shipping tab, turn off recording, then follow the same process as above to retrieve the value.
We now have all the information required to populate our Sales Order Query tool. We can now turn the recording back on and use the back button to navigate to the dashboard. Once there, we will use the variables we created in the VA03 transaction to populate the tools fields. We will follow a similar process using the Object Inspector but in reverse. We will find the id of the text field, but this time we will populate the text using the variables we created above.
Let’s look at the code a little closer, you can see we just used or variable “cust” as the source and left the target as it was generated when we hit the red pencil inside the Object Inspector tool. We will repeat this process for all the remaining target fields, which are “del_stat”, “mat”, and “quant”. The code will look like screen-shot below:
The final step to completing our script is to ensure that we aren’t passing the hard-coded value 14642 into the VA03 order field, but instead, the order number that is entered by the customer.
To do this, we scroll to the first line of our script and use the Object Inspector to find the text value of the Order Number and store it in a variable.
We then find where the original order number of “14642” was being passed in, and instead, change the code to pass in the value of our order variable “order”. The // you see is commenting out the line where we pass in the hard-coded value of “14642”.
Save your changes by hitting the “Save All Changes” button at the stop of the Scripting tool (which looks like an arrow going into a box). It is also a good time to Validate/Execute your script to check for bugs. Once completed, the last and final step is to attach our script to the “On Click” event of our Go button.
This is achieved by exiting the Script editor, opening the Flavor Editor, and selecting the Go button of our tool. Once selected, we navigate to the Insert tab and select the dropdown next to Scripting Events. The Scripting Events dropdown shows all possible events tied to a particular object. In this buttons case, the only available event is On Click. Appearing next to the On Click event will be a search field allowing you to search for scripts that are applicable to this event. Here I selected SO_LOOKUP, which is the script that was just created above.
We can finally give our new tool a test and should be pleased with the results. Enter in the Sales Order number of your choice and click the GO button!
Scripting is obviously a very powerful tool that can greatly simplify system interactions for the user. The example created a tool utilize scripting, but scripting can be used to populate standard fields on the screen as well, eliminating user error where values are known beforehand. The potential events that can be used go well beyond just clicking too. When a window or user area is loaded, refreshed, or even resized, a well-written script can automatically trigger field population, highlighting, or formatting to using specific logic improve the users experience.
SAP Screen Personas has a lot to offer in terms of improving the users experience with the system. It allows the robust SAP catalog of business software to be paired with a robust and customizable UI that is truly only limited by the users imagination.
Below are some links to help and a SAP Community WiKi on the subject. Cheers!