How to Use a Drop Down Menu in LSMW
LSMW objects are usually written by the data migration specialists who will use them and do not require documentation as the programmer knows exactly what the software does. Often they are cobbled together in the 11th hour to triage issues discovered during a system test, UAT or even go-live with no time to include a helpful interface.
Sometimes, though, the tools are left behind to be used by professionals who are not programmers or database administrators and the interface can be used in lieu of training. This value-add makes an LSMW object more useful as anybody can use it instead of just the programmer who wrote it.
Mercifully, LSMW allows for the INITIALIZATION
code to be executed in the GLOBAL_DATA section Field Mapping and Conversion Rules. That is were the parameter and the code to populate the drop down menu are added.
Start by declaring variables that will be used to populate the drop down menu. These include standard structures that will later be passed to the VRM_SET_VALUES
function along with some variables used to determine who is currently online--more on that later.
data: it_Users type standard table of UINFO with header line. TYPE-POOLS: vrm. DATA: gt_list TYPE vrm_values. DATA: gwa_list TYPE vrm_value. DATA: gt_values TYPE TABLE OF dynpread, gwa_values TYPE dynpread. DATA: gv_selected_value(10) TYPE c. data: lUSR21 like USR21, lADRP like ADRP.
Next, create the parameter to be used as the drop down menu. It can be like most other parameters that use numbers or strings, but it must include the AS LISTBOX
and VISIBLE LENGTH
syntax to work.
parameters: p_user like USR01-BNAME AS LISTBOX VISIBLE LENGTH 20 obligatory, p_messag like SM04DIC-POPUPMSG obligatory.
In this case, this snippet was used to create an LSMW ojbect to send popup messages to users that are currently logged on to the system. This code populates the drop down with the names and user IDs of users who are online and then calls the VRM_SET_VALUES
function to populate the drop down parameter with the data from the internal table.
initialization. "Get list of users currently logged in . . . call function 'THUSRINFO' tables USR_TABL = it_Users. loop at it_Users where BNAME ne ''. gwa_list-key = it_Users-BNAME. select * from USR21 into lUSR21 where BNAME eq it_Users-BNAME. select * from ADRP into lADRP where PERSNUMBER eq lUSR21-PERSNUMBER. concatenate it_Users-BNAME ':' lADRP-NAME_FIRST lADRP-NAME_LAST into gwa_list-text separated by space. endselect. endselect. append gwa_list to gt_list. endloop. CALL FUNCTION 'VRM_SET_VALUES' EXPORTING id = 'P_USER' values = gt_list EXCEPTIONS id_illegal_name = 1 OTHERS = 2.
That is all that is required to include a drop down menu in LSMW. After the user selects a user and executes on this screen, the parameter is populated with the user ID selected in the drop down menu.