个人收藏 Programming dynamic ALV in WebDynpro for ABAP

本文介绍如何在WebDynpro for ABAP中创建基于动态上下文节点的动态ALV,通过案例研究展示如何根据用户选择显示SFLIGHT表中的特定字段。
 

Programming dynamic ALV in WebDynpro for ABAP

Scenario: To create a dynamic ALV based on a dynamic context node in Web Dynpro for ABAP. As a Case study, we’ll use the SFLIGHT flight data to select which data fields we want to show in an ALV.

Procedure :

1.       First, we’ll create the ZWD_SFLIGHT Web Dynpro component.

2.       Next, we create a view

So, we have a WD component and a view. Now, we can insert a ViewContainerUIElement element in the view to show the ALV. The component’s name must be VCU_ALV.

We can activate in this moment.

3.       In the Used Components tab of the Web Dynpro Component, we have to define the SALV_WD_TABLE component in order to use the ALV component model within the view.

4.       Next, we must define a Controller Usage in the COMPONENTCONTROLLER and in the View Properties tab. To do that, press the button .

Then, we have an ALV component as well as its controller.

 5.       To show the ALV inside the View, we must embed the TABLE View of the SALV_WD_TABLE component. Go to the Window and select the ViewContainerUIElement (VCU_ALV) that we have created before.

6.       Then, select the next option.

7.       Now, we are ready to build the dynamic context node to give ALV its structure.

For example purposes, we’ll create 5 checkboxes which means the columns that can be showed (not necessary all of them) in the ALV. In this case, we’ll use CARRID, CONNID, FLDATE, PRICE and CURRENCY of SFLIGHT transparent table.

NOTE:   You also have to create a button and an event handler method where you will validate which checkboxes are marked in order to know which fields you will show in the ALV.

8.       We have to validate checkboxes entries to know which fields we must include in the ALV. Next code reads the context node and validates each checkbox in order to build the structure. 

******* First, read the context node: *******
DATA:
node_param TYPE REF TO if_wd_context_node,
elem_param TYPE REF TO if_wd_context_element,
stru_param TYPE if_v_main=>element_param .
* navigate from <CONTEXT> to <PARAM> via lead selection
node_param = wd_context->get_child_node( name = if_v_main=>wdctx_param ).
* get element via lead selection
elem_param = node_param->get_element( ).
* get all declared attributes
elem_param->get_static_attributes(
IMPORTING
static_attributes = stru_param ).
******* Next, validate which fields you will use as ALV columns *******
DATA: ls_component TYPE cl_abap_structdescr=>component,
lr_type TYPE REF TO cl_abap_datadescr,
lt_components TYPE cl_abap_structdescr=>component_table.
  IF stru_param-carrid = 'X'.
lr_type ?= cl_abap_typedescr=>describe_by_name( p_name = 'S_CARR_ID' ).
ls_component-name = 'CARRID'.
ls_component-type = lr_type .
APPEND ls_component TO lt_components.
ENDIF.
IF stru_param-connid = 'X'.
lr_type ?= cl_abap_typedescr=>describe_by_name( p_name = 'S_CONN_ID' ).
ls_component-name = 'CONNID'.
ls_component-type = lr_type .
APPEND ls_component TO lt_components.
ENDIF.
IF stru_param-fldate = 'X'.
lr_type ?= cl_abap_typedescr=>describe_by_name( p_name = 'S_DATE' ).
ls_component-name = 'FLDATE'.
ls_component-type = lr_type .
APPEND ls_component TO lt_components.
ENDIF.
IF stru_param-price = 'X'.
lr_type ?= cl_abap_typedescr=>describe_by_name( p_name = 'S_PRICE' ).
ls_component-name = 'PRICE'.
ls_component-type = lr_type .
APPEND ls_component TO lt_components.
ENDIF.
IF stru_param-currency = 'X'.
lr_type ?= cl_abap_typedescr=>describe_by_name( p_name = 'S_CURRCODE' ).
ls_component-name = 'CURRENCY'.
ls_component-type = lr_type .
APPEND ls_component TO lt_components.
ENDIF.
******* Next, create a new structure and assign it to a new dynamic context node *******
DATA: lr_root_info TYPE REF TO if_wd_context_node_info ,
lr_node_info TYPE REF TO if_wd_context_node_info,
lr_structdescr TYPE REF TO cl_abap_structdescr.
  call method cl_abap_structdescr=>create
exporting
p_components = lt_components
receiving
p_result = lr_structdescr.
* Get context node info
lr_root_info = wd_context->get_node_info( ).
* Generate new node with the dynamic structure
CALL METHOD lr_root_info->add_new_child_node
EXPORTING
name = 'DATA'
is_initialize_lead_selection = abap_false
static_element_rtti = lr_structdescr
is_static = abap_false
RECEIVING
child_node_info = lr_node_info.
* get instance of new node
DATA: dyn_node TYPE REF TO if_wd_context_node.
  dyn_node = wd_context->get_child_node( name = 'DATA' ).

******* Last, Get reference to model *******
DATA: lo_interfacecontroller type ref to iwci_salv_wd_table.
  lo_interfacecontroller =   wd_this->wd_cpifc_alv( ).

  lo_interfacecontroller->set_data( dyn_node ).

9.       Now, you need to create a Web Dynpro Application. 

10.   After that, let’s run our program. We can show an ALV table with a dynamic structure based on the checked fields.

数据驱动的两阶段分布鲁棒(1-范数和&infin;-范数约束)的电热综合能源系统研究(Matlab代码实现)内容概要:本文围绕“数据驱动的两阶段分布鲁棒(1-范数和&infin;-范数约束)的电热综合能源系统研究”展开,提出了一种结合数据驱动与分布鲁棒优化方法的建模框架,用于解决电热综合能源系统在不确定性环境下的优化调度问题。研究采用两阶段优化结构,第一阶段进行预决策,第二阶段根据实际场景进行调整,通过引入1-范数和&infin;-范数约束来构建不确定集,有效刻画风电、负荷等不确定性变量的波动特性,提升模型的鲁棒性和实用性。文中提供了完整的Matlab代码实现,便于读者复现和验证算法性能,并结合具体案例分析了不同约束条件下系统运行的经济性与可靠性。; 适合人群:具备一定电力系统、优化理论和Matlab编程基础的研究生、科研人员及工程技术人员,尤其适合从事综合能源系统、鲁棒优化、不确定性建模等相关领域研究的专业人士。; 使用场景及目标:①掌握数据驱动的分布鲁棒优化方法在综合能源系统中的应用;②理解1-范数和&infin;-范数在构建不确定集中的作用与差异;③学习两阶段鲁棒优化模型的建模思路与Matlab实现技巧,用于科研复现、论文写作或工程项目建模。; 阅读建议:建议读者结合提供的Matlab代码逐段理解算法实现细节,重点关注不确定集构建、两阶段模型结构设计及求解器调用方式,同时可尝试更换数据或调整约束参数以加深对模型鲁棒性的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值