Reproduced in this article: https://www.cnblogs.com/ricoo/p/10271919.html
This paper is undertaken by: https://www.cnblogs.com/seven1314pp/p/15958214.html After
This section describes the link jump between different views in the same window.
Premise: complete the previous step, and the MAIN view ALV is displayed.
1. Effect display
Click the underlined link of ALV material, and the page will jump to the material details page.
2. Implementation process
Based on the previous step, display the ALV material information on the MAIN page, and jump to the material details page by clicking the link under the ALV material.
The material details page mainly includes two parts: basic information and factory material details.
These two parts of information need to add two nodes (ZSMM_DETAIL - basic information ZSMM_ITEM - Factory material details) and an ALV component (factory material details).
2.1Context add node
2.1.1 enter the Componentcontroller component control page and add node ZSMM_DETAIL (basic information). If there is only one piece of recorded data, cardinality = 1 1 Selection=0.. one
Add node zsmm_ Item (factory material details), there may be more than one record data, then cardinality = 0 n selection = 0.. one
2.1.2 enter VIEW-MAIN as above and add a new node
2.2 add ALV components
Enter Componentcontroller to add ALV_DETAIL, as shown in the figure below:
Add ALV component to WINDOWS
2.3 new view MATERIAL_DETAIL
Add component ALV to property page_ Detail displays the factory material details.
The layout page is as follows: the basic information data is bound to the node ZSMM_DETAIL
Setting of Context node (the same as the operation in Section 2.1)
Attributes property page
Actions action event page
Methods page
2.4 jump between views
Set VIEW view MAIN, material_ Jump between details: the MAIN VIEW jumps to material through the ALV underline link_ Detail VIEW, material_ After the detail VIEW return button is triggered, return to the MAIN VIEW
2.4.1 setting the MAIN view: Inbound Plugs/Outbound Plugs
FROM_DETAIL from material_ Events for detail view
TO_DETAIL output parameters to MATERIAL_DETAIL view, the current parameter is empty.
2.4.2 setting MATERIAL_DETAIL view: Inbound Plugs/Outbound Plugs
2.5 WINDOWS nested view
Jump between views in a window.
2.6 code part
2.6.1 view MAIN METHODS: ON_LINK
Event on triggered by MATNR underline link of ALV line item in view MAIN_ LINK
Code part:
method on_link .
"definition
data:
lo_nd_detail type ref to if_wd_context_node, "node
lo_el_detail type ref to if_wd_context_element, "element
ls_detail type wd_this->element_zsmm_detail. "structure
**Main obtain ALV Select row record
data:
lo_nd_alv type ref to if_wd_context_node, "node
lt_alv type wd_this->elements_zsmm_material, "Body
ls_alv type wd_this->element_zsmm_material. "structure
"Get node
lo_nd_alv = wd_context->get_child_node( name = wd_this->wdctx_zsmm_material ).
"Get inner table
lo_nd_alv->get_static_attributes_table( importing table = lt_alv ).
"Get row record
if lt_alv[] is not initial.
read table lt_alv index r_param->index into ls_alv.
endif.
**Material_detail essential information
"Get node context-zsmm_material
lo_nd_detail = wd_context->get_child_node( name = wd_this->wdctx_zsmm_detail ).
"Get structure record
ls_detail = ls_alv.
"Get node element list
lo_el_detail = lo_nd_detail->get_element( ).
"Attribute assignment in node element
lo_el_detail->set_static_attributes( static_attributes = ls_detail ).
**Material_detail Material details
data:
lo_nd_item type ref to if_wd_context_node, "node
lo_el_item type ref to if_wd_context_element, "element
lt_item type wd_this->elements_zsmm_item, "Body
ls_item type wd_this->element_zsmm_item. "structure
"Node acquisition zsmm_item
lo_nd_item = wd_context->get_child_node( name = wd_this->wdctx_zsmm_item ).
select *
into corresponding fields of table lt_item
from marc
where matnr = ls_alv-matnr.
"Data binding node ZSMM_ITEM Binding data IT_ITEM
lo_nd_item->bind_table(
new_items = lt_item "data sheet
set_initial_elements = abap_true "abap_true Clear the original record and add a new record
).
"Jump to MATERIAL_DETAIL Material detail view
wd_this->fire_to_detail_plg( ).
endmethod.
Note: fire_to_detail_plg() is to set outbound plugs to in the MAIN view_ Jump method generated by detail.
2.6.2 view MATERIAL_DETAIL method: actionbt_ BACK
View material_ Button actionbt in detail_ Back triggers an event and returns to the MAIN view
Code part:
method ONACTIONBT_BACK .
"return MAIN view
wd_this->fire_to_main_plg( ).
endmethod.
Note: fire_to_main_plg() is in material_ Outbound plugs to in detail view_ Jump method generated by main.
2.6.3 initialize ALV component: ALV_ITEM
In view material_ ALV component is added to detail to display factory material details. ALV needs to be initialized.
Enter the Componentcontroller interface. METHODS method: INIT_ALV_DETAIL
Code part:
method INIT_ALV_DETAIL . data: lo_nd_item 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_detail( ). "Properties->component use if lo_cmp_alv->has_active_component( ) is initial. lo_cmp_alv->create_component( ). endif. * set data node lo_nd_item = wd_context->get_child_node( name = wd_this->wdctx_zsmm_item ). "context-node lo_cmpif_alv = wd_this->wd_cpifc_alv_detail( ). "Properties->component use lo_cmpif_alv->set_data( lo_nd_item ). * 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( 5 ). lo_config->if_salv_wd_table_settings~set_width( '100%' ). 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( 3 ). 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_chg type ref to cl_salv_wd_function, * lo_btn_chg type ref to cl_salv_wd_fe_button, * lo_fun_del type ref to cl_salv_wd_function, * lo_btn_del 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( 'BT_ADD' ). * create object lo_btn_add. * lo_btn_add->set_text( wd_assist->get_text( key = 'B01' ) ). * lo_btn_add->set_image_source( value = '~Icon/AddRow' ). * lo_fun_add->set_editor( lo_btn_add ). * * lo_fun_chg = lo_config->if_salv_wd_function_settings~create_function( 'BT_CHG' ). * create object lo_btn_chg. * lo_btn_chg->set_text( wd_assist->get_text( key = 'B02' ) ). * lo_btn_chg->set_image_source( value = '~Icon/EditChangedItem' ). * lo_fun_chg->set_editor( lo_btn_chg ). * * lo_fun_del = lo_config->if_salv_wd_function_settings~create_function( 'BT_DEL' ). * create object lo_btn_del. * lo_btn_del->set_text( wd_assist->get_text( key = 'B03' ) ). * lo_btn_del->set_image_source( value = '~Icon/DeletedItem' ). * lo_fun_del->set_editor( lo_btn_del ). * * lo_fun_save = lo_config->if_salv_wd_function_settings~create_function( 'BT_SAVE' ). * create object lo_btn_save. * lo_btn_save->set_text( wd_assist->get_text( key = 'B04' ) ). * lo_btn_save->set_image_source( value = '~Icon/Save' ). * 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, lo_checkbox type ref to cl_salv_wd_uie_checkbox, lr_link type ref to cl_salv_wd_uie_link_to_action, lv_field_name type string, lv_length type i. lt_columns = lo_config->if_salv_wd_column_settings~get_columns( ). 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' ) ). create object lo_input_field exporting value_fieldname = ls_column-id. lo_input_field->set_read_only_fieldname( value = 'FG_READ' ). lo_column->set_cell_editor( lo_input_field ). when 'WERKS'. "lo_column->set_width( value = '4' ). lo_header->set_text( value = wd_assist->get_text( key = 'A10' ) ). create object lo_input_field exporting value_fieldname = ls_column-id. lo_input_field->set_read_only_fieldname( value = 'FG_READ' ). lo_column->set_cell_editor( lo_input_field ). when 'EKGRP'. "lo_column->set_width( value = '3' ). lo_header->set_text( value = wd_assist->get_text( key = 'A11' ) ). create object lo_input_field exporting value_fieldname = ls_column-id. lo_input_field->set_read_only_fieldname( value = 'FG_READ' ). lo_column->set_cell_editor( lo_input_field ). when others. lo_column->set_visible( value = cl_wd_uielement=>e_visible-blank ). endcase. endloop. endmethod.
The above operations are basically completed.
2.7 testing
3. Focus
ALV components: try not to reuse components, and multiple views are easy to conflict.
Context node: node element attributes distinguish different business scenarios according to their purposes.
Relationship:
Windows->view->container->select_options/Table->Component use
Windows->view->Inbound/Outbound Plugs
Syntax concerns:
lo_nd_detail type ref to if_wd_context_node, "node
lo_el_detail type ref to if_wd_context_element, "element
lt_detail type wd_this->element_zsmm_detail. "Inner table
ls_detail type wd_this->element_zsmm_detail. "structure
"Get node ZSMM_DETAIL
lo_nd_detail = wd_context->get_child_node( name = wd_this->wdctx_zsmm_detail ).
"Get table data in node
lo_nd_alv->get_static_attributes_table( importing table = lt_detail ).
"Get row record
read table lt_detail index r_param->index into ls_detail
"Get node element
lo_el_detail = lo_nd_detail->get_element( ).
"Node element attribute assignment
lo_el_detail->set_static_attributes( static_attributes = ls_detail ).
"Node data binding
lo_nd_detail->bind_table( new_items = lt_detail set_initial_elements = abap_true ).