cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically Creating UI ELEMENT Group in web dynpro ABAP?

0 Kudos

My scenario is :

    I have two input fields and one button that should be comes under the GROUP while displaying in the screen?

    How can i acheive  that ? can any one please tell me quickly?

    please be sure that is dynamically created

        eg: using  cl_wd_group->new_group

     i think everybody understood correctly

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

There is some solution for this.

1.Create a new group dynamically and the input filed and button also dynamically .

2. If you have fix UI element then why you want to make them dynamically you can set the visibility also.

3. If you have input field and button statically and group dynamically then add your group as child element of your TC, and remove the reference of input field and button from TC and add  that child to group.

0 Kudos

Hi,

not getting ........properly....

Actually every thing i am creating dynamically thats it...

Former Member
0 Kudos

Here is a sample code that work :

" For dynamic Programing we need to write code in modify view..

   IF first_time  = abap_true.

     DATA lr_container TYPE REF TO cl_wd_uielement_container.

     DATA: lr_matrix    TYPE REF TO cl_wd_matrix_head_data,

           lr_matrix_lay    TYPE REF TO cl_wd_matrix_layout.

     DATA: lr_group TYPE REF TO cl_wd_group,

           lr_label TYPE REF TO cl_wd_label,

           lr_input_field TYPE REF TO cl_wd_input_field,

           lr_button TYPE REF TO cl_wd_button.

*** getting reference  of first ROOTUIELEMENTCONTAINER

     lr_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).

     cl_wd_matrix_layout=>new_matrix_layout( lr_container ) .

*** Creating the group

     lr_group = cl_wd_group=>new_group( id = 'DYNAMIC_GROUP' enabled = abap_true ).

*** adding to root element but you can add it elsewhere if you want

     lr_container->add_child( lr_group ).

*** setting matrix layout head data for the group

     cl_wd_matrix_head_data=>new_matrix_head_data( lr_group ).

*** setting matrix layout for the group also

     cl_wd_matrix_layout=>new_matrix_layout( lr_group ).

*** Creating the inputfield assuming you have a context element to

*** bind for the value in the view 'MAINVIEW', node 'VALUES' and

*** element INPUTFIELD1. But you may want to generate it dynamicaly also...

     lr_input_field = cl_wd_input_field=>new_input_field(

         id         = 'DYNAMIC_IF1'

         bind_value = 'VALUES.INPUTFIELD1').

     lr_label = cl_wd_label=>new_label(

         text      = 'Label for dynamic input field 1'

         id        = 'DYNAMIC_LABEL1'

         label_for = 'DYNAMIC_IF1' ).

     lr_group->add_child( lr_label ).

     cl_wd_matrix_head_data=>new_matrix_head_data( lr_label ).

     lr_group->add_child( lr_input_field ).

     cl_wd_matrix_head_data=>new_matrix_data( lr_input_field ).

*** repeat for the other input field.

     lr_input_field = cl_wd_input_field=>new_input_field(

         id = 'DYNAMIC_IF2'

         bind_value = 'VALUES.INPUTFIELD2').

     lr_label = cl_wd_label=>new_label(

         text       = 'Label for dynamic input field 2'

         id         = 'DYNAMIC_LABEL2'

         label_for  = 'DYNAMIC_IF2' ).

     lr_group->add_child( lr_label ).

     cl_wd_matrix_head_data=>new_matrix_head_data( lr_label ).

     lr_group->add_child( lr_input_field ).

     cl_wd_matrix_head_data=>new_matrix_data( lr_input_field ).

*** create the button. Here you will have either to bind a generic action that will

*** determine which button has been clicked or generat a dynamic action too.

     lr_button = cl_wd_button=>new_button(

         id                  = 'DYNAMIC_BUTTON1'

*        on_action           =

         text                = 'Click me' ).

     lr_group->add_child( lr_button ).

     cl_wd_matrix_head_data=>new_matrix_head_data( lr_button ).

   ENDIF.

And the result :

ramakrishnappa
Active Contributor
0 Kudos

Hi,

It works in WDDOINIT() as well .

Regards,

Rama

Former Member
0 Kudos

It could but it's more complicated to get a reference to the view in WDDOINIT.

WDMODIFYVIEW is in fact dedicated for UI usage.

Former Member
0 Kudos

you should avoid to give full code and exact code to someone. Now you gave the code, now again if he got some issue, he may post that again, try to show path and let them walk on that and help them to achieve their destination.

Hope you will understand, what i want to say.

Good Day..

Former Member
0 Kudos

I'll try to follow the advise though I always give code with explanations so that it could be understood and not only copy/paste.

Former Member
0 Kudos

Actually this comes under spoon feeding and that is against the rule of SCN.

amy_king
Active Contributor
0 Kudos

Hi Chandra,

Giraud's post isn't against SCN's rules actually.

Everybody's style is different and while I agree it is of course beneficial to "learn by doing",  an exact answer is probably what we're all hoping for when we post a question .

Cheers,

Amy

amy_king
Active Contributor
0 Kudos

You have to do just a little work to get the view reference in WDDOINIT, but it's trivial once you get the hang of it...

DATA lo_view TYPE REF TO if_wd_view.

* This view object is the same as the VIEW parameter in WDDOMODIFYVIEW

lo_view ?= wd_this->wd_get_api( ).

Cheers,

Amy

Former Member
0 Kudos

speechless !!

Former Member
0 Kudos

Amy, check out this thread http://scn.sap.com/thread/3437565

Answers (1)

Answers (1)

ramakrishnappa
Active Contributor
0 Kudos

Hi,

To understand the requirement correctly :

Do you need to create the GROUP , input fields & button dynamically and arrange them ?

or

Dynamically create only Group and arrange the existing input fields & buttons inside the group?

Regards,

Rama

0 Kudos

Hi rama...!

dynamically i need to create all the group input field , button and that should be arranged inside that group....this is my scenario......

Former Member
0 Kudos

Hello Sri,

Then it won't be much difficult for you to develop this.  Just create a group under the root TC.and give matrix layout and then create other UI element under that group.\

you can use this document as reference for creation of dynamic UI.. ..

for creation of new group.

data: lri_Uwe_1 type ref to CL_WD_GROUP.
   lri_Uwe_1 = cl_wd_group=>new_group(.....).

for creation of input field..

data: lri_Uwe_2 type ref to CL_WD_INPUT_FIELD.
   lri_Uwe_2 = cl_wd_input_field=>new_input_field(.........).

for button,,
data: lri_Uwe_4 type ref to CL_WD_BUTTON.

lri_Uwe_4 = cl_wd_button=>new_button(-------).


0 Kudos

Hi Agarwal,

         I had created this but i am getting the dump like ''NULL OBJECT REFERENCE" if am creating a group . otherwise without group i will not get the dump

          please check my code below

code:

*  Instance for dynamic UI creation.

   DATA: lr_lbl_vbeln TYPE REF TO cl_wd_label,

         lr_inp_vbeln TYPE REF TO cl_wd_input_field,

         lo_nd_zvbap  TYPE REF TO if_wd_context_node,

         lr_text_view TYPE REF TO cl_wd_text_view,

         lr_button    TYPE REF TO cl_wd_button,

         lr_container TYPE REF TO cl_wd_uielement_container,

         lr_mat_h_data TYPE REF TO cl_wd_matrix_head_data,

         lr_mat_data   TYPE REF TO cl_wd_matrix_data,

         lr_grp_cont   TYPE REF TO cl_wd_group.

   ********************************************************************

*Creating the node

   lo_nd_zvbap = wd_context->get_child_node( name = wd_this->wdctx_zvbap ).

********************************************************************

   IF first_time = abap_true.

     lr_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).

********************************************************************

*Creating the Group Dynamically.

     CALL METHOD cl_wd_group=>new_group

       EXPORTING

         id                  = 'GRP_CONT'

         design              = `01`

         enabled             = abap_true

         has_content_padding = abap_true

         scrolling_mode      = `02`

         visible             = `02`

       RECEIVING

         control             = lr_grp_cont.

* layout settings.

     lr_mat_h_data  = cl_wd_matrix_head_data=>new_matrix_head_data( lr_grp_cont ).

     lr_grp_cont->set_layout_data( lr_mat_h_data ).

********************************************************************

*Creating the label Field Dynamically.

     CALL METHOD cl_wd_label=>new_label

       EXPORTING

         design    = cl_wd_label=>e_design-emphasized

         enabled   = 'X'

         id        = 'LB_VBELN'

         label_for = 'VBELN'

         text      = 'Sales Order Number'

       RECEIVING

         control   = lr_lbl_vbeln.

* Layout Allingment.

     lr_mat_h_data = cl_wd_matrix_head_data=>new_matrix_head_data( lr_lbl_vbeln ).

     lr_lbl_vbeln->set_layout_data( lr_mat_h_data ).

********************************************************************

*Creating the input Field Dynamically.

     CALL METHOD cl_wd_input_field=>new_input_field

       EXPORTING

         bind_value = 'I_VEBLN.VBELN'

         id         = 'VBELN'

       RECEIVING

         control    = lr_inp_vbeln.

* Layout Allingment.

     lr_mat_data = cl_wd_matrix_data=>new_matrix_data( lr_inp_vbeln ).

     lr_inp_vbeln->set_layout_data( lr_mat_data ).

********************************************************************

*Creating the Button Dynamically.

     CALL METHOD cl_wd_button=>new_button

       EXPORTING

         enabled   = 'X'

         id        = 'B1'

         on_action = 'GET_DATA'

         text      = 'GET DATA'

       RECEIVING

         control   = lr_button.

* Layout Allingment.

     lr_mat_h_data = cl_wd_matrix_head_data=>new_matrix_head_data( lr_button ).

     lr_button->set_layout_data( lr_mat_h_data ).

********************************************************************

*Adding Child Nodes

     CALL METHOD lr_container->add_child

       EXPORTING

         index     = 2

         the_child = lr_grp_cont.

     CALL METHOD lr_container->add_child

       EXPORTING

         index     = 3

         the_child = lr_lbl_vbeln.

     CALL METHOD lr_container->add_child

       EXPORTING

         index     = 4

         the_child = lr_inp_vbeln.

     CALL METHOD lr_container->add_child

       EXPORTING

         index     = 5

         the_child = lr_button.


Former Member
0 Kudos

maybe this could work without two things :

1- not using the set_layout_data( lr_mat_h_data ) method

2- not giving index parameter to the method add_child of the container. Just call add_child in order.

also you could use :

cl_wd_matrix_layout=>new_matrix_layout( lr_container ) .

after :

lr_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).



Former Member
0 Kudos

some changes..

You need to assign some layout for group by..

     cl_wd_matrix_layout=>new_matrix_layout(
       container =
lr_grp_cont     ).

you need to add group to container and other element to group.

CALLMETHOD  lr_grp_cont ->add_child

       EXPORTING

         index     = 3

         the_child = lr_lbl_vbeln.

like this..