zoukankan      html  css  js  c++  java
  • WDA-3-ALV查询

     主要是梳理下WebDynpro For ABAP开发过程:

    1.创建WebDynpro组件

    2.创建WebDynpro应用

    1.创建WebDynpro组件

     1.1创建

     路径:选择Package-->创建-->Web Dynpro-->WebDynpro组件(接口)

      

     

     1.2WebDynpro组件

      已使用的组件 中增加ALV 及Select Options组件,然后保存。

     

     标准组件:

     SALV_WD_TABLE      显示ALV数据表

     WDR_SELECT_OPTIONS    区间查询条件

     POWL_UI_COMP       POWL个人对象工作清单

     1.3 CompentController

     Properties标签页中创建控制范围

     

     

     

     创建数据结构:ZSMM1801_MATERIAL

     

     Context创建Node

     

     

     Cardinality参数:

     The following values are possible:

    • 1..1 : The node contains exactly one instance that must always be instantiated
    • 0..1 : The node contains exactly one instance that does not have to be instantiated
    • 1..n : The node can contain multiple instances and at least one of them must be instantiated
    • 0..n : The node can contain multiple instances and none of them must be instantiated

     The default is 1..1.

     Selection参数:

     The following values are possible:

      1..1 : Exactly one instance (table row) must be selected. It is automatically the lead selection.

      0..1 : No more than one instance (table row) can be selected. It is automatically the lead selection.

      1..n : Any number of instances can be selected, but at least one must be selected. One of them is the lead selection.

      0..n : Any number of instances can be selected, but none must be selected. One of the selected ones is the lead selection.

     The default is 0..1.

     

     上述Context设置完成,进入Attributes之前需要先创建辅助类ZCL_MM_SEARCH_MATERIAL:

     事务代码:SE24

     

     

     

     

     

     

     类保存并激活,然后维护WebDynpro组件辅助类:

     

     转到ComponentController 维护Attributes标签页。

     

     维护Methods标签页

     

     1.4VIEW设置

     打开MAIN主视图

      设置ROOTUIELEMENTCONTAINER:

      A.增加两个PANEL控件:TRY_SEL 查询条件  TRY_ALV 显示ALV

      B.TRY_SEL增加控件ViewContainerUIElement(VC_SEL)、控件ButtonRow(BTNR_SEARCH)、控件Button(BTN_SEARCH)

      C.TRY_ALV增加控件TransparentContainer(TC_DISPLAY)、控件ViewContainerUIElement(VC_ALV)

      设置完成后界面如下:

      

      上图中文本资源的设置可用两种方式:

      事务代码:SE63

      事务代码:SOTR_EDIT

      

      

      保存后维护相关控件的文本,如下所示:

      

      控件BTN_SEARCH图标维护:

      

      控件BTN_SEARCH按钮事件

      

      

      维护Context标签页:

      

      维护Attributes标签页如下所示:

      

      维护Action标签页

       

      维护Methods标签页

      

      VIEW视图设置完成,代码部分后面具体讲述。

     1.5Windows

      维护Windows窗口,选择VC_SEL右键选择嵌套视图

      

      

      Select options维护完成后,继续维护VC_ALV嵌套视图。

      

      维护完成后如下图所示:

      

      其他标签页设置如下:

      

      

      

      

      上述步骤完成后,整个WebDynpro组件相关设置就结束了,下一步进入代码设置环节。

     1.6代码部分

      注意事件执行先后顺序:WDA-WebDynpro事件执行先后顺序

       ComponentController维护Methods相关方法:

      

      组件初始化WDDOINIT方法:

    method wddoinit .
      free:  wd_this->go_sel.
      clear: wd_this->gv_message.
      
      "初始Select-options
      wd_this->init_sel( ).
      "初始ALV
      wd_this->init_alv( ).
    
    endmethod.

      INIT_ALV方法:

    method init_alv .
      data:
        lo_nd_zsmm_mat type ref to if_wd_context_node,
        lo_cmp_alv     type ref to if_wd_component_usage,
        lo_cmpif_alv   type ref to iwci_salv_wd_table,
        lo_config      type ref to cl_salv_wd_config_table.
    
    * alv component usage
      lo_cmp_alv = wd_this->wd_cpuse_alv_mat( ).
      if lo_cmp_alv->has_active_component( ) is initial.
        lo_cmp_alv->create_component( ).
      endif.
    
    * set data node
      lo_nd_zsmm_mat = wd_context->get_child_node( name = wd_this->wdctx_zsmm_material ).
      lo_cmpif_alv  = wd_this->wd_cpifc_alv_mat( ).
      lo_cmpif_alv->set_data( lo_nd_zsmm_mat ).
    
    * configure alv
      lo_config = lo_cmpif_alv->get_model( ).
    
    * table settings
      lo_config->if_salv_wd_table_settings~set_fixed_table_layout( value = abap_true ).
      lo_config->if_salv_wd_table_settings~set_visible_row_count( 11 ).
      lo_config->if_salv_wd_table_settings~set_footer_visible( if_salv_wd_c_table_settings=>footer_visible_on_demand ).
      lo_config->if_salv_wd_table_settings~set_scrollable_col_count( 11 ).
      lo_config->if_salv_wd_table_settings~set_read_only( abap_false ).
      lo_config->if_salv_wd_table_settings~set_data_check( if_salv_wd_c_table_settings=>data_check_on_cell_event ).
    
      lo_config->if_salv_wd_std_functions~set_view_list_allowed( abap_false ).
      lo_config->if_salv_wd_std_functions~set_pdf_allowed( abap_false ).
      lo_config->if_salv_wd_std_functions~set_edit_check_available( abap_false ).
      lo_config->if_salv_wd_std_functions~set_edit_insert_row_allowed( abap_false ).
      lo_config->if_salv_wd_std_functions~set_edit_append_row_allowed( abap_false ).
      lo_config->if_salv_wd_std_functions~set_edit_delete_row_allowed( abap_false ).
    
    ** table toolbar
    *  data:
    *    lo_fun_add    type ref to cl_salv_wd_function,
    *    lo_btn_add    type ref to cl_salv_wd_fe_button,
    *    lo_fun_new    type ref to cl_salv_wd_function,
    *    lo_btn_new    type ref to cl_salv_wd_fe_button,
    *    lo_fun_chg    type ref to cl_salv_wd_function,
    *    lo_btn_chg    type ref to cl_salv_wd_fe_button,
    *    lo_fun_invite type ref to cl_salv_wd_function,
    *    lo_btn_invite type ref to cl_salv_wd_fe_button,
    *    lo_fun_save   type ref to cl_salv_wd_function,
    *    lo_btn_save   type ref to cl_salv_wd_fe_button.
    *
    *  lo_fun_add = lo_config->if_salv_wd_function_settings~create_function( 'ADD' ).
    *  create object lo_btn_add.
    *  lo_btn_add->set_text( wd_assist->get_text( key = 'ADD' ) ).
    *  lo_fun_add->set_editor( lo_btn_add ).
    *
    *  lo_fun_new = lo_config->if_salv_wd_function_settings~create_function( 'NEW' ).
    *  create object lo_btn_new.
    *  lo_btn_new->set_text( wd_assist->get_text( key = 'NEW' ) ).
    *  lo_fun_new->set_editor( lo_btn_new ).
    *
    *  lo_fun_chg = lo_config->if_salv_wd_function_settings~create_function( 'CHG' ).
    *  create object lo_btn_chg.
    *  lo_btn_chg->set_text( wd_assist->get_text( key = 'CHG' ) ).
    *  lo_fun_chg->set_editor( lo_btn_chg ).
    *
    *  lo_fun_invite = lo_config->if_salv_wd_function_settings~create_function( 'INVITE' ).
    *  create object lo_btn_invite.
    *  lo_btn_invite->set_text( wd_assist->get_text( key = 'INV' ) ).
    *  lo_fun_invite->set_editor( lo_btn_invite ).
    *
    *  lo_fun_save = lo_config->if_salv_wd_function_settings~create_function( 'SAVE' ).
    *  create object lo_btn_save.
    *  lo_btn_save->set_text( wd_assist->get_text( key = 'SAV' ) ).
    *  lo_fun_save->set_editor( lo_btn_save ).
    
    * table columns and column header
      data:
        lt_columns         type salv_wd_t_column_ref,
        ls_column          type salv_wd_s_column_ref,
        lo_column          type ref to cl_salv_wd_column,
        lo_header          type ref to cl_salv_wd_column_header,
        lo_dropdown_by_key type ref to cl_salv_wd_uie_dropdown_by_key,
        lo_input_field     type ref to cl_salv_wd_uie_input_field,
        lo_text_view       type ref to cl_salv_wd_uie_text_view,
        lv_field_name      type string,
        lv_length          type i.
    
    
      lt_columns = lo_config->if_salv_wd_column_settings~get_columns( ).
      
     
     "ALV输出字段 loop at lt_columns into ls_column. lo_column
    = ls_column-r_column. lo_header = lo_column->get_header( ). lo_header->set_ddic_binding_field( if_salv_wd_c_column_settings=>ddic_bind_none ). case ls_column-id. when 'MATNR'. "lo_column->set_width( value = '18' ). lo_header->set_text( value = wd_assist->get_text( key = 'A01' ) ). when 'ERNAM'. "lo_column->set_width( value = '12' ). lo_header->set_text( value = wd_assist->get_text( key = 'A02' ) ). when 'ERSDA'. "lo_column->set_width( value = '8' ). lo_header->set_text( value = wd_assist->get_text( key = 'A03' ) ). when 'MTART'. "lo_column->set_width( value = '4' ). lo_header->set_text( value = wd_assist->get_text( key = 'A04' ) ). when 'MBRSH'. "lo_column->set_width( value = '1' ). lo_header->set_text( value = wd_assist->get_text( key = 'A05' ) ). when 'MATKL'. "lo_column->set_width( value = '9' ). lo_header->set_text( value = wd_assist->get_text( key = 'A06' ) ). when 'MEINS'. "lo_column->set_width( value = '3' ). lo_header->set_text( value = wd_assist->get_text( key = 'A07' ) ). when 'GROES'. "lo_column->set_width( value = '32' ). lo_header->set_text( value = wd_assist->get_text( key = 'A08' ) ). when 'SPART'. "lo_column->set_width( value = '2' ). lo_header->set_text( value = wd_assist->get_text( key = 'A09' ) ). when 'WERKS'. "lo_column->set_width( value = '4' ). lo_header->set_text( value = wd_assist->get_text( key = 'A10' ) ). when 'EKGRP'. "lo_column->set_width( value = '3' ). lo_header->set_text( value = wd_assist->get_text( key = 'A11' ) ). when others. lo_column->set_visible( value = cl_wd_uielement=>e_visible-blank ). endcase. endloop. endmethod.

      设置文本元素(A01-->A11):

      

      

      

      INIT_SEL方法:

    method init_sel .
      data:
        lo_cmp_selopt   type ref to if_wd_component_usage,
        lo_cmpif_selopt type ref to iwci_wdr_select_options.
    
    * alv component usage
      lo_cmp_selopt = wd_this->wd_cpuse_select_opt( ).
      if lo_cmp_selopt->has_active_component( ) is initial.
        lo_cmp_selopt->create_component( ).
      endif.
      lo_cmpif_selopt = wd_this->wd_cpifc_select_opt( ).
    
    * sets the helper reference
    * wd_this->go_selopt = wd_this->wd_cpifc_cmp_sel_opt( ).
      wd_this->go_sel = lo_cmpif_selopt->init_selection_screen( ).
      call method wd_this->go_sel->set_global_options
        exporting
          i_display_btn_cancel  = abap_false
          i_display_btn_check   = abap_false
          i_display_btn_reset   = abap_false
          i_display_btn_execute = abap_false.
    
      data lo_field type ref to data.
    
      define mcr_add_selopt.
        free lo_field.
        lo_field = wd_this->go_sel->create_range_table( &2 ).
        wd_this->go_sel->add_selection_field(
          i_id           = &1
          it_result      = lo_field
          i_description  = &3 ).
      end-of-definition.
    
      define mcr_add_parameter_d.
        free lo_field.
        create data lo_field type (&2).
        wd_this->go_sel->add_parameter_field(
          i_id           = &1
          i_value        = lo_field
          i_description  = &3
          i_as_dropdown  = abap_true
          it_value_set   = &4 ).
      end-of-definition.
    
      data: lv_text type string.
    
      clear: lv_text.
      lv_text = wd_assist->get_text( key = 'S01' ).
      mcr_add_selopt    'BU_WERKS'    'WERKS_D' lv_text.
    
      clear: lv_text.
      lv_text = wd_assist->get_text( key = 'S02' ).
      mcr_add_selopt    'BU_MATNR'    'MATNR'  lv_text.
    endmethod.

      文本元素(S01,S02)设置方式同上。

      BT_SEARCH查询按钮方法:

      进入视图VIEW-MAIN,点击查询按钮,获取事件onAction:BT_SEARCH,双击事件。

      

      设置ONACTIONBT_SEARCH事件触发方法:wd_comp_controller->bt_search( ).

      

      注意:WD_COMP_CONTROLLER 是继承COMPONENTCONTROLLER的接口

      

      维护COMPONENTCONTROLLER的方法BT_SEARCH

      

    method bt_search .
      data:
        lo_data     type ref to data,
        lt_sel_item type if_wd_select_options=>tt_selection_screen_item.
    
      field-symbols:
        <fs_bu_werks> type table,
        <fs_bu_matnr> type table,
        <fs_sel_item> like line of lt_sel_item.
    
      clear: wd_this->gv_message.
    
      wd_this->go_sel->get_selection_screen_items(
        importing
          et_selection_screen_items = lt_sel_item ).
    
      loop at lt_sel_item assigning <fs_sel_item>.
        case <fs_sel_item>-m_id.
          when 'BU_WERKS'.
            assign <fs_sel_item>-mt_range_table->* to <fs_bu_werks>.
          when 'BU_MATNR'.
            assign <fs_sel_item>-mt_range_table->* to <fs_bu_matnr>.
        endcase.
      endloop.
    
      data lo_nd_zsmm_mat type ref to if_wd_context_node.
      data lt_zsmm_mat type wd_this->elements_zsmm_material.
      data ls_zsmm_mat type wd_this->element_zsmm_material.
    
      lo_nd_zsmm_mat = wd_context->get_child_node( name = wd_this->wdctx_zsmm_material ).
    
      data:
        lt_material type table of zsmm1801_material.
    
      field-symbols:
        <fs_material> type zsmm1801_material.
    
      select *
        into corresponding fields of table lt_material
        from mara as a
       inner join marc as b
          on a~matnr = b~matnr
       where a~matnr in <fs_bu_matnr>
         and b~werks in <fs_bu_werks>.
    
      loop at lt_material assigning <fs_material>.
        move-corresponding <fs_material> to ls_zsmm_mat.
        append ls_zsmm_mat to lt_zsmm_mat.
        clear:ls_zsmm_mat.
      endloop.
    
      "Data binding
      lo_nd_zsmm_mat->bind_table( new_items = lt_zsmm_mat set_initial_elements = abap_true ).
    endmethod.

       BT_ALV_FUN(ALV状态栏新增按钮—当前测试未设置,后续讲解)方法:

      上述代码完成后进行校验并激活。

    2.创建WebDynpro应用程序

     2.1创建WebDynpro应用程序

     选择WebDynpro组件并创建WebDynpro应用程序:

     

     

     

     

     保存。

     2.2测试

     

     出现如上错误,应该是辅助类的继承问题,可以在COMPONENTCONTROLLER方法WDDOINIT中设置断点进行调试,看看在运行哪一步骤出错,然后针对问题进行处理。

     问题调整后再测试运行:

    点击查询按钮:

    至此,ALV的查询完成。

  • 相关阅读:
    OpenJDK源码研究笔记(十二):JDBC中的元数据,数据库元数据(DatabaseMetaData),参数元数据(ParameterMetaData),结果集元数据(ResultSetMetaDa
    Java实现 LeetCode 257 二叉树的所有路径
    Java实现 LeetCode 257 二叉树的所有路径
    Java实现 LeetCode 257 二叉树的所有路径
    Java实现 LeetCode 242 有效的字母异位词
    Java实现 LeetCode 242 有效的字母异位词
    Java实现 LeetCode 242 有效的字母异位词
    Java实现 LeetCode 241 为运算表达式设计优先级
    Java实现 LeetCode 241 为运算表达式设计优先级
    Java实现 LeetCode 241 为运算表达式设计优先级
  • 原文地址:https://www.cnblogs.com/ricoo/p/10213558.html
Copyright © 2011-2022 走看看