Reputation: 99
I need to display a pop-up window with data from my database table field (Tab1-camp_type
).
At the moment I created a UI-Component (ZUIC_TYPES
), a table view (VWTYPES
) and added the necessary table field.
At the DO_PREPARE_OUTPUT
method of my context node, I wrote the code, which should give me all values from camp_type
field, but I get only one value repeated 37 times (there are 37 rows in my table).
How can I get all my data in the pop-up?
Here's my code:
DATA:lr_table TYPE REF TO crmc_mktpl_ctype,
lr_struct TYPE crmc_mktpl_ctype,
lt_tabledata TYPE TABLE OF crmc_mktpl_ctype,
ls_tabledata LIKE LINE OF lt_tabledata,
lr_camptype TYPE REF TO cl_bsp_wd_value_node,
lr_col TYPE REF TO cl_crm_bol_bo_col.
"fetch the data.
SELECT DISTINCT camp_type FROM crmc_mktpl_ctype INTO CORRESPONDING FIELDS OF TABLE lt_tabledata.
CHECK sy-subrc = 0.
"create collection object.
CREATE OBJECT lr_col.
CREATE DATA lr_table.
"create one empty value node with the required structure.
CREATE OBJECT lr_camptype
EXPORTING
iv_data_ref = lr_table.
"create value node for each record foound.
LOOP AT lt_tabledata INTO ls_tabledata.
"set the data into the value node.
lr_camptype->if_bol_bo_property_access~set_properties( is_attributes = ls_tabledata ).
"add node to the collection.
lr_col->if_bol_bo_col~add( lr_camptype ).
ENDLOOP.
"all records are processed. set the collection to the collection wrapper of
" context node to make it visible on web ui
me->typed_context->camptype->collection_wrapper->set_collection( lr_col ).
Upvotes: 1
Views: 1957
Reputation: 99
DO_PREPARE_OUTPUT
method write this code: TYPES: BEGIN OF ltype_attr_struct,
camp_type TYPE crm_mktpl_camptype,
description TYPE crm_mktpl_camptypetx, "Added by wizard
END OF ltype_attr_struct.
DATA: lr_table TYPE REF TO crmc_mktpl_ctype,
lr_struct TYPE crmc_mktpl_ctype,
lt_tabledata TYPE TABLE OF ltype_attr_struct,
ls_tabledata LIKE LINE OF lt_tabledata,
lr_camptype TYPE REF TO cl_bsp_wd_value_node,
lr_col TYPE REF TO cl_crm_bol_bo_col.
"fetch the data.
SELECT DISTINCT
A~camp_type,
B~description
FROM TabA AS A INNER JOIN
TabB AS B ON A~camp_type = B~camp_type AND B~langu = 'EN'
INTO TABLE @lt_tabledata.
CHECK sy-subrc = 0.
"create collection object.
CREATE OBJECT lr_col.
CREATE DATA lr_table.
"create one empty value node with the required structure.
CREATE OBJECT lr_camptype
EXPORTING
iv_data_ref = lr_table.
"create value node for each record foound.
LOOP AT lt_tabledata INTO ls_tabledata.
"set the data into the value node.
lr_camptype->if_bol_bo_property_access~set_properties( is_attributes = ls_tabledata ).
"add node to the collection.
lr_col->if_bol_bo_col~add( NEW cl_bsp_wd_value_node( iv_data_ref = REF ltype_attr_struct( ls_tabledata ) ) ).
ENDLOOP.
"all records are processed. set the collection to the collection wrapper of context node to make it visible on web ui
me->typed_context->camptype->set_collection( lr_col ).
me->typed_context->camptype->build_table( ).
gr_popup = me->comp_controller->window_manager->create_popup( iv_interface_view_name = 'ZUIC_CAMP_TYPES/MainWindow'
iv_usage_name = 'ZCUTypes'
iv_title = 'Title' ).
gr_popup->set_window_width( iv_width = 400 ).
gr_popup->set_window_height( iv_height = 600 ).
gr_popup->set_on_close_event( iv_event_name = 'PP_CTYPE_CLOSED'
iv_view = me ).
gr_popup->set_display_mode( if_bsp_wd_popup=>c_display_mode_surrounded ).
gr_popup->open( ).
P.S: GR_POPUP Instance Attribute
Public
Type
Ref To
IF_BSP_WD_POPUP
.
gr_popup it's attribute of class.
Upvotes: 0
Reputation: 916
You have only one node created (lr_camptype
) before the loop, so you are adding the same one several times. Remember that at each loop, you add a reference to the same object, so when it's later processed the object will contain only the latest value.
You should create one node per row, by moving the creation of the node inside the LOOP, as follows:
...
"create collection object.
CREATE OBJECT lr_col.
CREATE DATA lr_table.
"create value node for each record found.
LOOP AT lt_tabledata INTO ls_tabledata.
"create one empty value node with the required structure.
CREATE OBJECT lr_camptype " <=== must be inside the loop !
EXPORTING
iv_data_ref = lr_table.
"set the data into the value node.
lr_camptype->if_bol_bo_property_access~set_properties( is_attributes = ls_tabledata ).
"add node to the collection.
lr_col->if_bol_bo_col~add( lr_camptype ).
ENDLOOP.
...
Upvotes: 2