Creating and using Variant in Select Options with Web Dynpro for ABAP -1
As part of my work, I created a Webdynpro for ABAP application having the selection screen for accepting the user input. My user demanded to get the basic variant functionality in WDA application same as available in ABAP reports. I searched SDN for the available solution and found the solution suggested by Mr. Anantha Athuru (https://wiki.sdn.sap.com/wiki/x/boHzAQ). But this solution involves creating a dummy ABAP report having the same selection screen as WDA application and store variants over there. I thought there should be some better way. So here I am.
This example application contains customer number and plant two select options on Main View. The main view also has two buttons. The first button navigates to ‘Save Variant view’ and other button navigates to ‘Get Variants’ view. The solution can be described in following steps.
1. Create your application with select options. Your component will have to have the component WDR_SELECT_OPTIONS as “used component” in order to get select option functionality. You may create attributes for the instance of “select option handler class” (IF_WD_SELECT_OPTIONS) and range tables of customer and data selection data (type ref to data) in all views so they can be passed back and forth easily.
2. After entering the data in the selection screen, the user presses the “Save Variant” button. The action associated with button reads the select options to get the range tables first and fill the corresponding view attributes with them. Then it navigates to “Save Variant” view (passes the attribute with Fire plug event handler method). The view let the user enter the input for variant name, description and Global indicator.
3. The program prepares and stores the variant data in system table INDX (export to …database). Using table INDX places a restriction that the WDA component name can’t be more than 20 characters to get the correct results, though you are free to create a new clustered table with same table fields as INDX ( with more wide SRTFD field) or VARI to store variants. The variants are stored as following in this example.
Area (INDX-RELID) is populated with ‘YW’.
- The first 20 characters of user defined key (INDX-SRTFD) contains the WD component name. The last 2 characters are used to store the unique variant sequence number.
- The first 14 characters of INDX-PGMID contains the variant name, the 15th character contains ‘/’ if variant is global variant and rest 25 characters will contain the variant description.
- The field USERA contains the name of the user who created the variant.
- The program checks if there is no already existing variant this the same name.
- The range tables for customer and plant are referencing to data. They are made dereference and store the data in range internal tables (… type range of KUNNR, type range of WERKS_D because referenced data can’t be exported to database).
- The both tables are exported to database to ID ‘YW’ with key prepared in previous steps.
4. The retrieval process takes the following steps.
- Navigate to “Get Variant” view
- Read all the records from table INDX for area ‘YW’ and key having a pattern of 20 characters of WD component name.
- Only retain the records only that are either created by user or global.
- Get the variant name from first 14 characters of INDX-PGMID field, Global indicator from 15th character and description from 16-40 characters of same field.
- Show the results in a table and let user choose one variant. Once the variant is chosen, import from database the range tables using the ID and area from INDX record.
- Populate the referenced range tables (type ref to data) from customer and plant range table.
- Navigate to Main View and set the range tables for select option.
In next blog, I will provide the code and detail of the Saving Variant functionality.