iT邦幫忙

2024 iThome 鐵人賽

DAY 27
0

Hi 大家好

今天來介紹如何在input介面建立下拉選單

宣告一個listbox下拉式選單

visible length 16 : 可見長度16

PARAMETERS:p_hbkid(5) type c as listbox visible length 16 obligatory.  

設定下拉式選單的選項

假設有元大、玉山兩家銀行

data: lwa_option type vrm_value,
        lt_option type vrm_values.     

  clear: lwa_option, lt_option.
  refresh: lt_option.

  lwa_option-key = '806'.
  lwa_option-text = '元大'.
  append lwa_option to lt_option.

  lwa_option-key = '808'.
  lwa_option-text = '玉山'.
  append lwa_option to lt_option.



  call function 'VRM_SET_VALUES'
    exporting
      id              = 'P_HBKID'
      values          = lt_option
    exceptions
      id_illegal_name = 1
      others          = 2.

lwa_option:用於存儲每個選項的key值跟敘述,類型為 vrm_value。
lt_option:用於存儲所有選項的內表,類型為 vrm_values,它是多行的 vrm_value 表格。
call 標準function 'VRM_SET_VALUES'

當使用者選擇了銀行

at selection-screen on p_hbkid   
perform  get_dropdown.

執行子程式 get_dropdown

讀取user選取的值

form get_dropdown .
  data: lt_values   type table of dynpread,
      lwa_values  type dynpread.

  clear: lwa_values, lt_values.
  refresh lt_values.
  lwa_values-fieldname = 'P_HBKID'.
  append lwa_values to lt_values.

  call function 'DYNP_VALUES_READ'
    exporting
      dyname                         = sy-cprog
      dynumb                         = sy-dynnr
*     TRANSLATE_TO_UPPER             = ' '
*     REQUEST                        = ' '
*     PERFORM_CONVERSION_EXITS       = ' '
*     PERFORM_INPUT_CONVERSION       = ' '
*     DETERMINE_LOOP_INDEX           = ' '
*     START_SEARCH_IN_CURRENT_SCREEN = ' '
*     START_SEARCH_IN_MAIN_SCREEN    = ' '
*     START_SEARCH_IN_STACKED_SCREEN = ' '
*     START_SEARCH_ON_SCR_STACKPOS   = ' '
*     SEARCH_OWN_SUBSCREENS_FIRST    = ' '
*     SEARCHPATH_OF_SUBSCREEN_AREAS  = ' '
    tables
      dynpfields                     = lt_values
    exceptions
      invalid_abapworkarea           = 1
      invalid_dynprofield            = 2
      invalid_dynproname             = 3
      invalid_dynpronummer           = 4
      invalid_request                = 5
      no_fielddescription            = 6
      invalid_parameter              = 7
      undefind_error                 = 8
      double_conversion              = 9
      stepl_not_found                = 10.
  if sy-subrc ne 0.
    message s208 with 'Read Dropdown List Error.' display like 'E'.
    stop.
  endif.

  read table lt_values with key fieldname = 'P_HBKID' into lwa_values.
  if sy-subrc = 0 and lwa_values-fieldvalue is not initial.
    g_hbkid = lwa_values-fieldvalue.
  else.
    message s208 with 'House Bank must be selected.' display like 'I'.
    stop.
  endif.
endform.                    " GET_DROPDOWN

以上是今天的分享!


上一篇
Day 26 ABAP實戰-銀行匯款媒體檔開發 (中)
下一篇
Day 28 使用ABAP連接外部Data base
系列文
從0開始的ABAP之旅 30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言