In NET311 the topic component usage clone is discussed there. One example is also given there: The user of a Web Dynpro application can mark multiple lines of a table to display details for each selected data set. The details of one data set is displayed by one usage of a certain component. Thus, the number of component usages equals the number of marked lines, which is not known at design time.
The prerequisite for cloning any component usage is, that a single usage of this component has been defined at design time. Any controller having added the name of the static component usage to the list of used controllers / components can then create additional usages of the same component. Each component usage must have a unique name.
I will reuse the component created in the blog Step by Step to create UI elements and context node attribute in the runtime . After I maintain the content number and click create button, the label and text view together with their bound context node attribute will be generated in the runtime. The value of text view “Echo from Usage clone:” is returned by the cloned component usage.
(1) Create a simple component ZDYNAMICUSAGE which will be consumed as component usage later. Implement the echo method in component controller.
(2) In order to use component usage, there must be at least one static component usage.Also define usage of the interface controller in the consumer view controller.
(3) In method CREATE_CONTEXT, just enhance one line. ( In the original example, I just set the value of newly-generated context attribute to its attribute name)
method CREATE_CONTEXT .
CONSTANTS: cv_value type string value 'VALUE'.
data(lo_node) = wd_context->get_child_node( 'DYNAMIC' ).
data(lo_node_info) = lo_node->get_node_info( ).
data(lt_attributes) = lo_node_info->get_attributes( ).
DO iv_count TIMES.
DATA(lv_attribute_name) = cv_value && sy-index.
READ TABLE lt_attributes WITH KEY name = lv_attribute_name TRANSPORTING NO FIELDS.
IF sy-subrc <> 0.
data(ls_attribute_prop) = VALUE wdr_context_attribute_info( NAME = lv_attribute_name
TYPE_NAME = 'STRING' ).
lo_node_info->add_attribute( attribute_info = ls_attribute_prop ).
DATA(lv_value) = wd_this->get_value_by_index( sy-index ).
lo_node->set_attribute( name = lv_attribute_name value = lv_value ).
ENDIF.
ENDDO.
endmethod.
(4) Define one attribute in view controller, which is an internal table to store all references of component usage instance.
In view controller WDDOINT, insert the static component usage to the internal table. The internal table would have the first line as static component usage instance and all remaining ones for cloned component usage from the static one.
method WDDOINIT .
DATA(lo_static_usage) = wd_this->wd_cpuse_zclone_example( ).
APPEND lo_static_usage TO wd_this->gt_cmp_usages.
endmethod.
(5) Implement the method get_value_by_index which is called in step3. I will read the internal table gt_cmp_usages by index. Index 1 means this is a static component usage so I directly use the one return from wd_this->wd_cpuse_zclone_example( ). Or else the left one will be cloned from the static one. Since the usage name should be unique, so I use a prefix and an index to fulfill the uniqueness.
method GET_VALUE_BY_INDEX .
DATA(lo_static_com_usage) = wd_this->wd_cpuse_zclone_example( ).
DATA: lo_generic_usage TYPE REF TO if_wd_component_usage,
lo_interface_control TYPE REF TO ZIWCI_DYNAMICUSAGE.
READ TABLE wd_this->gt_cmp_usages ASSIGNING FIELD-SYMBOL(<usage>) INDEX iv_index.
CASE iv_index.
WHEN 1.
IF lo_static_com_usage->has_active_component( ) IS INITIAL.
lo_static_com_usage->create_component( ).
ENDIF.
lo_generic_usage = lo_static_com_usage.
WHEN OTHERS.
READ TABLE wd_this->gt_cmp_usages ASSIGNING FIELD-SYMBOL(<dyn_usage>) INDEX iv_index.
IF sy-subrc <> 0.
DATA(lv_usage_name) = 'DYNAMIC_USAGE' && sy-index.
data(lo_dyn_usage) = lo_static_com_usage->create_comp_usage_of_same_type( name = lv_usage_name ).
APPEND lo_dyn_usage TO wd_this->gt_cmp_usages.
ENDIF.
IF lo_dyn_usage->has_active_component( ) IS INITIAL.
lo_dyn_usage->create_component( ).
ENDIF.
lo_generic_usage = lo_dyn_usage.
ENDCASE.
lo_interface_control ?= lo_generic_usage->get_interface_controller( ).
rv_output = lo_interface_control->get_field_value( iv_index ).
endmethod.
In the debugger I would observe that every component usage in gt_cmp_usages are unique:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关推荐
SAP ABAP Web dynpro 跟踪调试工具的讲解。
### ABAP WebDynpro 开发知识点总结 #### 一、ABAP WebDynpro 概述 **ABAP WebDynpro** 是 SAP 提供的一种用于构建用户界面的技术框架,它允许开发者利用 ABAP 语言创建现代化的 Web 应用程序。WebDynpro 的核心...
SAP ABAP WebDynpro开发是基于SAP的NetWeaver技术平台上的一个重要开发工具。WebDynpro是SAP的Web应用框架,它允许开发人员通过ABAP编程语言创建交互式的Web界面和后台逻辑。它代表了SAP在企业级Web应用开发方面的...
SAP ABAP webdynpro实例
### Floor Plan Manager (FPM) in ABAP Web Dynpro #### 1. Introduction Floor Plan Manager (FPM) is a powerful and flexible user interface (UI) framework available in SAP’s ABAP platform. It enables ...
本节中主要记录WebDynpro For ABAP的基础操作.如各种UI Elment的使用,Context的使用等.
### ABAP WebDynpro 面试问题及答案解析 #### 1. ABAP UI 技术类型 **知识点:** ABAP UI 技术主要包括 WebDynpro for ABAP 和 BSP (Browser Session Processing)。 - **WebDynpro for ABAP**: 这是一种用于构建...
以下是使用 ABAP Web Dynpro 调用 BAPI 的详细步骤和相关知识点: 1. **创建 Web Dynpro Component** - 在 SAP 事务码 SE80 中,选择“Web Dynpro Comp./Intf”作为对象类别。 - 输入组件名称(例如 ZZ_00_...
SAP ABAP WEBDYNPRO HELLO WORLD
6-《Web Dynpro for ABAP - Component Usage.pdf》:组件是Web Dynpro的基本构建块,包含逻辑和视图元素。这部分内容会深入讲解如何复用和组合组件,以创建更复杂的业务流程。 学习Web Dynpro for ABAP,你需要理解...
Web Dynpro for ABAP是SAP提供的一种用于构建企业级Web应用程序的技术,它结合了 Dynpro 编程理念与Web应用程序的优势。Web Dynpro的主要特点是它的模型-视图-控制器(MVC)架构和数据绑定机制,使得开发更加高效且...
SAP Web Dynpro for ABAP 是 SAP 企业级应用程序开发中的一个重要组件,它提供了一种高效、用户友好的方式来构建复杂的企业级业务应用程序。Web Dynpro 是 SAP 的一种编程模型,专门设计用于构建富客户端应用程序,...
在本文中,我们将学习如何使用 SAP WEB Dynpro for ABAP 创建一个简单的 ALV 展示,展示 MARA 表中的数据。 首先,我们需要创建一个 WEB Dynpro 组件,添加 ALV 组件 SALV_WD_TABLE,并在 Component Controller 上...
【SAP Web Dynpro for ABAP】是一种强大的开发框架,专为在SAP环境中构建复杂的、用户友好的Web应用程序而设计。它结合了ABAP编程语言的优势与现代Web技术,提供了一个高度灵活和可定制的界面开发平台。下面将详细...
### Webdynpro中上传下载附件控件的使用方法 #### 一、概述 在Webdynpro应用程序中,处理文件上传和下载是非常常见的需求之一。本文档详细介绍了如何使用`FileUpload`和`FileDownload`控件来实现这些功能。通过...
综上所述,SAP Web Dynpro for ABAP中的图片上传与使用涉及到了视图context的管理、UI组件的定义、WDDOINIT方法中的属性设置,以及数据绑定的过程。掌握这些核心概念和技术细节,对于开发者来说至关重要,它能够帮助...
《Web Dynpro ABAP for Practitioners》一书由Ulrich Gellert和Ana Daniela Cristea撰写,旨在为读者提供深入理解与实践Web Dynpro ABAP技术的全面指南。此书聚焦于Web Dynpro ABAP,一种在SAP NetWeaver平台上构建...