二维码

[教程] PROVIDING DROPDOWN LIST

Twilight发表于 2015-12-05 00:48lhx7300886 最后回复于 2017-03-03 09:08 [复制链接] 4868 1

When we know particular field will take some predefine values, then we will make it either a drop down or will provide a F4 help.

If number of predefined values is less, then we will choose drop down. If they are too many, then F4 help is a better way.

Let us make Process type field on search view as a drop down so that user will choose predefine values from the list.
drop down 1.jpg

There are two methods in which we need to code to make a particular field as a drop down.
1. GETTER P method: in this method we tell to the frame work that this particular field will act as a drop down.
2. GETTER V method:  Here we will provide the values to be shown in the drop down list.
As we want to provide the drop down list to the process type field on the search page, we need manipulate of above mentioned methods of that attribute.

Go to the search view, expand the context node and  choose the search context node and again expand the attributes.
drop down 2.jpg

Select the required attribute. Right click on it and choose the options GENERATE V GETTER and P-GETTER methods one by one to generate the corresponding methods.
drop down 3.jpg

Once you generate , you can see the methods generated under the attribute.
drop down 4.jpg

Double click on the GET_P_PROCESS_TYPE method and add the following code in that method.
  1. METHOD get_p_process_type.

  2.   CASE iv_property.
  3.     WHEN if_bsp_wd_model_setter_getter=>fp_fieldtype.
  4.       rv_value = cl_bsp_dlc_view_descriptor=>field_type_picklist.
  5.   ENDCASE.

  6. ENDMETHOD.
复制代码

Go to the V – getter method and copy paste the following code.
  1. METHOD get_v_process_type.
  2.   DATA:lt_keypair TYPE bsp_wd_dropdown_table,
  3.        ls_keypair LIKE LINE OF lt_keypair,
  4.        lt_values TYPE TABLE OF crmc_proc_type_t,
  5.        ls_values LIKE LINE OF lt_values,
  6.        lr_dropdown TYPE REF TO cl_crm_uiu_ddlb.

  7.   "bring the required values from the table.
  8.   SELECT * FROM crmc_proc_type_t INTO TABLE lt_values WHERE langu = 'E'.
  9.   IF sy-subrc = 0.
  10.     "take required values in the form of key-value pairs.
  11.     CLEAR ls_values.
  12.     LOOP AT lt_values INTO ls_values.
  13.       ls_keypair-key = ls_values-process_type.
  14.       ls_keypair-value = ls_values-p_description.
  15.       APPEND ls_keypair TO lt_keypair.
  16.       CLEAR ls_values.
  17.     ENDLOOP.

  18.     CREATE OBJECT lr_dropdown
  19.       EXPORTING
  20.         iv_source_type = 'T'.
  21.     "insert initial line in case user wants to choose blank values.
  22.     INSERT INITIAL LINE INTO lt_keypair INDEX 1.

  23.     "give the values we fetched.
  24.     lr_dropdown->set_selection_table( it_selection_table = lt_keypair ).
  25.   ENDIF.

  26.   rv_valuehelp_descriptor = lr_dropdown.

  27. ENDMETHOD.
复制代码

That’s it. We have created the drop down for particular field.  We can use any custom table and query it if we want to show the custom table data as a drop down.  Values should go always as key pairs. On the web ui, frame work only shows the values. Go for the drop downs when for small values of list.
Go and test the application to see the drop down list.
drop down 5.jpg
回复

使用道具 举报

lhx7300886
我想做个服务目录的下拉宽,学习了
回复 支持 反对

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表