coverl 发表于 2015-9-20 07:52:18

如何在sap的screen中使用ListBox


  如何在sap的screen中使用ListBox
  1、拖入一个编辑控件到屏幕,设置“下拉”属性为“ListBox”
  2、设置Function-CODE,
  3、listbox的列表的取值有三种方法:
  A)默认取Dictionary;
B)使用“VRM_SET_VALUES"函数在PBO中设置 ,代码见后面代码
C)使用Process On Value-request事件和“F4IF_INT_Table_Value_request”函数设置输入帮助
其中C优于B,B优于A
  代码示例:(参见SAP的样例程序,rsdemo_dropdown_list)
  *屏幕事件
process before output.
module status_0100.
   module fill_carrid.
*
process after input.
module event_from_listbox.
module exit at exit-command.
  process on value-request.
field sflight-carrid module set_data_carrid.
  *程序
report rsdemo_dropdown_listbox .
  data init.
tables scarr.
  tables spfli.
tables sflight.
tables sbook.
data save_ok like sy-ucomm.
data ok_code like sy-ucomm.
  call screen 100.
  *&---------------------------------------------------------------------*
*&      Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_0100 output.
if init is initial.
    set pf-status 'GRUND'.
    set titlebar '100'.
  * preset of listboxes
    spfli-carrid = 'LH'.
    sflight-carrid = 'LH'.
    sbook-carrid = 'LH'.
endif.
  endmodule.                           " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&      Module SET_DATA_CARRID INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module set_data_carrid input.
types: begin of type_carrid,
         carrid like spfli-carrid,
         carrname like scarr-carrname,
         end of type_carrid.
  data itab_carrid type standard table of type_carrid with header line.
  select carrid carrname
                from scarr
                into corresponding fields of table itab_carrid.
  call function 'F4IF_INT_TABLE_VALUE_REQUEST'
       exporting
            retfield      = 'CARRID'
            value_org       = 'S'
       tables
            value_tab       = itab_carrid
       exceptions
            parameter_error = 1
            no_values_found = 2
            others          = 3.
if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
  
endmodule.                           " SET_DATA_CARRID INPUT
*&---------------------------------------------------------------------*
*&      Module FILL_CARRID OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module fill_carrid output.
* Do not use this process (but it works)
  type-pools vrm.
data values type vrm_values with header line.
  if init is initial.
    select * from scarr.
      values-text = scarr-carrname.
      values-key = scarr-carrid.
      append values.
    endselect.
    call function 'VRM_SET_VALUES'
         exporting
            id            = 'SBOOK-CARRID'
            values          = values[]
         exceptions
            id_illegal_name = 1
            others          = 2.
    if sy-subrc <> 0.
      message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
  endif.
scarr-carrid = 'LH'.
init = 'X'.
endmodule.                           " FILL_CARRID OUTPUT
*&---------------------------------------------------------------------*
*&      Module EVENT_FROM_LISTBOX INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module event_from_listbox input.
save_ok = ok_code.
clear ok_code.
case save_ok.
    when 'LISTBOX_2'.
      message i300(eu) with save_ok.
    when 'LISTBOX_3'.
      message i300(eu) with save_ok.
endcase.
endmodule.                           " EVENT_FROM_LISTBOX INPUT
*&---------------------------------------------------------------------*
*&      Module EXIT INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module exit input.
leave program.
endmodule.                           " EXIT INPUT
页: [1]
查看完整版本: 如何在sap的screen中使用ListBox