SAP Screen Personas
Create: Sebastian Steinhauer Jul 05, 2016 21:44
Last Update: Regina Sheynblat Feb 06, 2019 21:33
How to use the onSelect event of tables in scripting
SAP SCREEN PERSONAS KNOWLEDGE BASE - by Clemens Gantert , Regina Sheynblat , Sebastian Steinhauer
This article explains how a table's onSelect event can be used in conjuction with the table's selectedRowsAbsolute property to write scripts that do something specific with the selected row or rows.
Both table types, GUI table (GuiTableControl) and ALV (GuiGridView) provide an onSelect event. Both table types have a property selectedRowsAbsolute which provides the currently selected rows of the table. These can be used to create scripts that determine the selected row or rows and perform certain actions for each row.
Usage Patterns for the onSelect event and the selectedRowsAbsolute property
It's important to understand that only after the selectedRowsAbsolute property has been updated the onSelect event is called. In other words, the handler script "sees" the currently selected rows in the selectedRowsAbsolute property, even the row whose selection fired the onSelect event itself.
Tables come in single and multi-selection mode. For multi selection tables we recommend not to use the onSelect event but to create a scripting button. The script button's onClick script can read the selectedRowsAbsolute property of the the table, parse it and then perform the required actions. See example 2.
Example 1: onSelect event script for a single-select table
This example is based on report RSDEMO02, but can be used for any table as long as the "source" parameter of the onSelect event is used to access the table (Of course you have to adjust the column name).
Example 2: Script to process the selected rows of a multi-select table
The script below is also based on report RSDEMO02. You can set the report to turn the table into a multi-select table. We assume that in this case the script is triggered from a script button. This means we don't get the table into the script as 'source' parameter, but we have to access the table via the session.findById() method. A big part of the script is there to parse the selectedRowsAbsolute property. Remember that the property can contain ranges and leading and trailing semicolons. For instance ";2;5;8-10;14;" is a valid value.
The script defines utility function parseSelectedRowsAbsolute() which takes the raw selectedRowsAbsolute property and returns an JS array contain all selected row indices (as JS number, not string).
SAP Screen Personas, table, row selection, onSelectAvailable Events in Scripting