WDA基础八:ROWREPEATER的使用

时间:2023-01-04 08:23:17

这玩意不知道什么时候用^_^

组件:Row-Repeater

1.新建WDA程序并激活  ZLYWDA02

2.进入VIEW,创建CONTEXT:

WDA基础八:ROWREPEATER的使用

表:0..n

选择行:单选

初始化选择行

3.创建循环节点  右键HCONTEXT创建循环节点HCONTEXT_REC

给HCONTEXT添加属性:

TEXT:STRING       显示

CARRID:STRING   第一层

CONNID:STRING   第二层

VIEW的INIT中初始化节点:

METHOD WDDOINIT .
TYPES:
BEGIN OF TYP_FLIGHT,
CARRID TYPE STRING,
CONNID TYPE STRING,
NAME TYPE STRING,
END OF TYP_FLIGHT. DATA:
LS_FLIGHT TYPE TYP_FLIGHT,
LT_FLIGHT TYPE STANDARD TABLE OF TYP_FLIGHT. * set the internal table
CLEAR:LS_FLIGHT.
LS_FLIGHT-CARRID = 'CA-01'.
LS_FLIGHT-CONNID = 'CA-01-CO-01'.
LS_FLIGHT-NAME = 'CA-01-CO-01:item1'.
APPEND LS_FLIGHT TO LT_FLIGHT.
CLEAR:LS_FLIGHT.
LS_FLIGHT-CARRID = 'CA-01'.
LS_FLIGHT-CONNID = 'CA-01-CO-01'.
LS_FLIGHT-NAME = 'CA-01-CO-01:item2'.
APPEND LS_FLIGHT TO LT_FLIGHT.
CLEAR:LS_FLIGHT.
LS_FLIGHT-CARRID = 'CA-01'.
LS_FLIGHT-CONNID = 'CA-01-CO-01'.
LS_FLIGHT-NAME = 'CA-01-CO-01:item3'.
APPEND LS_FLIGHT TO LT_FLIGHT.
CLEAR:LS_FLIGHT.
LS_FLIGHT-CARRID = 'CA-01'.
LS_FLIGHT-CONNID = 'CA-01-CO-02'.
LS_FLIGHT-NAME = 'CA-01-CO-02:item1'.
APPEND LS_FLIGHT TO LT_FLIGHT.
CLEAR:LS_FLIGHT.
LS_FLIGHT-CARRID = 'CA-01'.
LS_FLIGHT-CONNID = 'CA-01-CO-03'.
LS_FLIGHT-NAME = 'CA-01-CO-03:item1'.
APPEND LS_FLIGHT TO LT_FLIGHT.
CLEAR:LS_FLIGHT.
LS_FLIGHT-CARRID = 'CA-02'.
LS_FLIGHT-CONNID = 'CA-02-CO-01'.
LS_FLIGHT-NAME = 'CA-02-CO-01:item1'.
APPEND LS_FLIGHT TO LT_FLIGHT.
CLEAR:LS_FLIGHT.
LS_FLIGHT-CARRID = 'CA-03'.
LS_FLIGHT-CONNID = 'CA-03-CO-01'.
LS_FLIGHT-NAME = 'CA-03-CO-01:item1'.
APPEND LS_FLIGHT TO LT_FLIGHT.
CLEAR:LS_FLIGHT.
LS_FLIGHT-CARRID = 'CA-03'.
LS_FLIGHT-CONNID = 'CA-03-CO-02'.
LS_FLIGHT-NAME = 'CA-03-CO-02:item1'.
APPEND LS_FLIGHT TO LT_FLIGHT.
CLEAR:LS_FLIGHT.
LS_FLIGHT-CARRID = 'CA-04'.
LS_FLIGHT-CONNID = 'CA-04-CO-01'.
LS_FLIGHT-NAME = 'CA-04-CO-01:item1'.
APPEND LS_FLIGHT TO LT_FLIGHT.
SORT LT_FLIGHT BY CARRID CONNID NAME.
* set the context
DATA:
LO_NODE TYPE REF TO IF_WD_CONTEXT_NODE,
LO_ELEM TYPE REF TO IF_WD_CONTEXT_ELEMENT,
LO_NODE_REC TYPE REF TO IF_WD_CONTEXT_NODE,
LO_ELEM2 TYPE REF TO IF_WD_CONTEXT_ELEMENT,
LO_NODE_REC2 TYPE REF TO IF_WD_CONTEXT_NODE,
LS_CONTEXT TYPE WD_THIS->ELEMENT_HCONTEXT,
LW_CARRID TYPE STRING,
LW_CONNID TYPE STRING.
LOOP AT LT_FLIGHT INTO LS_FLIGHT.
* new Carrid, 1st level.
* IF LW_CARRID <> LS_FLIGHT-CARRID.
IF LW_CARRID <> LS_FLIGHT-CONNID.
LW_CARRID = LS_FLIGHT-CONNID.
CONCATENATE '1st level:'
LS_FLIGHT-CARRID
INTO LS_CONTEXT-TEXT.
LS_CONTEXT-CARRID = LS_FLIGHT-CARRID.
LS_CONTEXT-CONNID = LS_FLIGHT-CONNID.
* node
LO_NODE = WD_CONTEXT->GET_CHILD_NODE( NAME = 'HCONTEXT' ).
* bind structure
LO_ELEM = LO_NODE->BIND_STRUCTURE( NEW_ITEM = LS_CONTEXT
SET_INITIAL_ELEMENTS = ABAP_FALSE ).
* create dependent node for recurion
LO_NODE_REC = LO_ELEM->GET_CHILD_NODE( 'HCONTEXT_REC' ).
ENDIF.
* for the 2rd level
CONCATENATE '2rd level:'
LS_FLIGHT-NAME
INTO LS_CONTEXT-TEXT.
LS_CONTEXT-CARRID = LS_FLIGHT-CARRID.
LS_CONTEXT-CONNID = LS_FLIGHT-CONNID.
* bind
LO_NODE_REC->BIND_STRUCTURE( NEW_ITEM = LS_CONTEXT
SET_INITIAL_ELEMENTS = ABAP_FALSE ).
ENDLOOP.
ENDMETHOD.

效果:

WDA基础八:ROWREPEATER的使用