on 12-22-2008 12:13 PM
Dear All,
I am developing one application in Webdynpro (ABAP) , Where I need to dynamically insert fields in screen level.
For example : Field 1 field2 Buttton insert/Delete.
As mentioned in the above example I want dynamically to insert and delete FIELD 1 and Field2 by the end user .
As I am new to webdynpro I need step by step procedure to create the application as above.
Kindly Help me out to proceed further.
Regards,
Gokul Venkatesh
Hi All,
Thanks for Reply. Examples are working fine, but my scenario is if I press the button then only field should add. Kindly help me out to proceed further.
Regards,
Gokul Venkatesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gokul,
You can do the follwoing.
1. Create a global variable in either Assistance class or component controller of type IF_WD_VIEW.
2. In wddomodifyview method of the view where you want to add an element dynamically, pass the parameter VIEW of the method to the global variable created in the Step 1.
3. Now you can access this view in any method and use it the same way.
4. In the action handler for the button, just use the same code with the global variable created in step 1.
Example 3: Creating a Group ui element & embedding a pushbutton inside it
Place the coding below into your WDDOMODIFYVIEW to create the elements dynamically:
method WDDOMODIFYVIEW .
data: lr_container type ref to cl_wd_uielement_container,
lr_group type ref to cl_wd_group,
lr_caption type ref to cl_wd_caption,
lr_button type ref to cl_wd_button.
check first_time = abap_true.
lr_container ?= view->get_element( id = 'ROOTUIELEMENTCONTAINER' ).
cl_wd_matrix_layout=>new_matrix_layout( container = lr_container ).
lr_group = cl_wd_group=>new_group( id = 'GROUP1' ).
cl_wd_matrix_layout=>new_matrix_layout( container = lr_group ).
cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_group ).
lr_caption ?= cl_wd_caption=>new_caption( text = 'Caption For Group' ).
lr_group->set_header( lr_caption ).
lr_button = cl_wd_button=>new_button( ID = 'BUTTON1'
TEXT = 'SUBMIT'
design = '01'
on_action = 'TEST' ).
cl_wd_matrix_data=>new_matrix_data( element = lr_caption ).
cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_button ).
lr_container->add_child( the_child = lr_group ).
lr_group->add_child( the_child = lr_button ).
endmethod.
As how you can see on clicking the button we have defined an action (TEST) to be triggered. So create an corresponding event handler method (ONACTIONTEST) for the same.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Example 2 Creating a Group ui element & embedding textEdit elements inside it:
Put the below coding into your WDDOMODIFYVIEW method & execute:
METHOD wddomodifyview.
DATA: lr_container TYPE REF TO cl_wd_uielement_container,
lr_group TYPE REF TO cl_wd_group,
lr_caption_group TYPE REF TO cl_wd_caption,
lr_textedit TYPE REF TO cl_wd_text_edit,
lr_node_info TYPE REF TO if_wd_context_node_info,
lr_node TYPE REF TO if_wd_context_node,
lr_element TYPE REF TO if_wd_context_element,
lr_attribute_info TYPE wdr_context_attribute_info,
content TYPE string,
attribute_name TYPE string,
lv_textview_id TYPE string.
CHECK first_time = abap_true.
lr_node_info = wd_context->get_node_info( ).
CALL METHOD lr_node_info->add_new_child_node
EXPORTING
name = 'CHILD'
is_mandatory = abap_false
is_multiple = abap_true
is_multiple_selection = abap_true
is_singleton = abap_false
is_initialize_lead_selection = abap_true
is_static = abap_false
RECEIVING
child_node_info = lr_node_info.
lr_container ?= view->get_root_element( ).
cl_wd_matrix_layout=>new_matrix_layout( container = lr_container ).
lr_group = cl_wd_group=>new_group( id = 'GROUP' ).
lr_group->set_width( value = '50%' ).
cl_wd_matrix_layout=>new_matrix_layout( container = lr_group ).
cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_group ).
lr_caption_group = cl_wd_caption=>new_caption( text = 'Group Header' ).
lr_group->set_header( the_header = lr_caption_group ).
DO 4 TIMES.
MOVE sy-index TO attribute_name.
" Preparing the data to be displayed in the textEdit i.e, data for context attribute
CONCATENATE 'This'
'is the'
'data for textEdit number: '
attribute_name INTO content SEPARATED BY cl_abap_char_utilities=>newline.
CONCATENATE 'ATTR'
attribute_name INTO attribute_name.
" Condense the ID to ensure that the format is consistent with SAP standard
CONDENSE attribute_name NO-GAPS.
" Prepare properties of attribute & add to context node CHILD
lr_attribute_info-name = attribute_name.
lr_attribute_info-type_name = 'STRING'.
lr_attribute_info-value_help_mode = '0'.
lr_node_info->add_attribute( EXPORTING attribute_info = lr_attribute_info ).
lr_node = wd_context->get_child_node( name = 'CHILD' ).
lr_element = lr_node->create_element( ).
lr_element->set_attribute( name = attribute_name
value = content ).
lr_node->bind_element( new_item = lr_element
set_initial_elements = abap_false ).
" Compute the attribute path dynamically i.e, like CHILD.ATTR1
CONCATENATE 'CHILD.'
attribute_name INTO attribute_name.
CONDENSE attribute_name NO-GAPS.
lr_textedit = cl_wd_text_edit=>new_text_edit( cols = 10
rows = 5
width = '90%'
bind_value = attribute_name ).
cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_textedit ).
lr_group->add_child( the_child = lr_textedit ).
ENDDO.
lr_container->add_child( the_child = lr_group ).
ENDMETHOD.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gokul,
Welcome to WDA. If you are starting with dynamic programming in WDA then as how Suman had pointed out, its the best option to get started by reading Thomas Szuecs blog series. I would give you some code snippets below which you can check out. by pasting into your WDDOMODIFYVIEW method.
Example 1: Create context node & attributes dynamically & then create label & inputField dynamically on the view.
Put the below coding into your WDDOINIT method for creating the context node & attributes:
METHOD wddoinit .
DATA: lv_root_node TYPE REF TO if_wd_context_node,
lv_root_node_info TYPE REF TO if_wd_context_node_info,
lv_parent_node_info TYPE REF TO if_wd_context_node_info,
lv_child_node_info TYPE REF TO if_wd_context_node_info.
lv_root_node_info = wd_context->get_node_info( ).
CALL METHOD lv_root_node_info->add_new_child_node
EXPORTING
static_element_type = 'SFLIGHT'
name = 'FLIGHTS'
is_mandatory = abap_false
is_mandatory_selection = abap_false
is_multiple = abap_true
is_multiple_selection = abap_false
is_initialize_lead_selection = abap_true
RECEIVING
child_node_info = lv_parent_node_info.
CALL METHOD lv_parent_node_info->add_new_child_node
EXPORTING
static_element_type = 'SBOOK'
name = 'BOOKINGS'
is_mandatory = abap_false
is_mandatory_selection = abap_false
is_multiple = abap_true
is_multiple_selection = abap_false
is_initialize_lead_selection = abap_true
RECEIVING
child_node_info = lv_child_node_info.
data: lt_sflight type standard table of sflight,
lt_sbook type standard table of sbook.
select * from sflight into table lt_sflight.
select * from sbook into table lt_sbook.
lv_root_node = wd_context->get_child_node( name = 'FLIGHTS' ).
lv_root_node->bind_table( new_items = lt_sflight ).
lv_root_node = lv_root_node->get_child_node( name = 'BOOKINGS' ).
lv_root_node->bind_table( new_items = lt_sbook ).
ENDMETHOD.
Put the below coding into your WDDOMODIFYVIEW to create the label & inputField dynamically:
METHOD wddomodifyview .
DATA : lr_ui_root TYPE REF TO if_wd_view_element,
lr_container TYPE REF TO cl_wd_uielement_container.
CHECK first_time = abap_true.
lr_ui_root = view->get_root_element( ).
lr_container ?= lr_ui_root.
cl_wd_matrix_layout=>new_matrix_layout( container = lr_container ).
lr_container->set_width( value = '50%' ).
" Add UI elements to the container along with their layout properties
data : lr_label_carrid type ref to cl_wd_label,
lr_input_carrid type ref to cl_wd_input_field.
lr_input_carrid = cl_wd_input_field=>new_input_field( bind_value = 'FLIGHTS.CARRID'
id = 'INPUT_FIELD_CARRID' ).
lr_label_carrid = cl_wd_label=>new_label( id = 'LABEL_CARRID'
label_for = 'INPUT_FIELD_CARRID'
text = 'CARRID text from WDDOMODIFY View' ).
cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_label_carrid ).
cl_wd_matrix_data=>new_matrix_data( element = lr_input_carrid ).
lr_container->add_child( the_child = lr_label_carrid ).
lr_container->add_child( the_child = lr_input_carrid ).
ENDMETHOD.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gokul,
If this is the requirement i will suggest you to make use of visibility property of the fields as i dont think if you want to insert and delete fields depending on click of button dynamic programming really solves purpose..... we usually do dynamic programming when we are not sure what user might want at run time..... here what you can do is just bind the fields with visibility property and depending on the button that is clicked just hide and unhide the fields... it will be much simpler............
regards
Pranav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.