cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Coding in webdynpro abap

Former Member
0 Kudos

Hi Experts,

I am working as webdynpro abap consultant ,I need some help in dynamic coding.

Required Details.

1. Creating UI elements runtime based on the number of records coming from the sap Ztable.

2. Main UI elements to be displayed at runtime ( label,inputfield ) this UI elements should be displayed at runtime

3. If they are 10 records in Ztable then 10 UI labels and 10 UI inputfields should be displayed at rutime.

Kindly Provided Information, And it will be very greatful if you provided with some Documents.

Thanks & Regards.

Krishna ( SAP Consultant )

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Krishna kumar,

Dynamic Programming should be done in WDDOMODIFYVIEW method.

if ur getting 10 or more records from DB write the code like this in WDDOMODIFYVIEW.

data lv_times type i.

If first_time = abap_true.

Do lv_times times.  "lv_times is nothing but number of records that u got from DB

"dynamic UI Coding what ever ui need create it.

enddo.

endif.

and follow these links for dynamic programming.

http://wiki.sdn.sap.com/wiki/display/sandbox/Dynamic+programming+in+WebDynpro+ABAP

http://scn.sap.com/docs/DOC-25673

and also you can search in SDN.

Regards

Madhukiran.

Former Member
0 Kudos

Hi Madhu Kiran,

Thanks for the reply,I am doing same code that which you have given to me i am giving my logic

for example my table is ZDATA

and i have 2 recrods

frist record : NAME

second record : AGE

now when i am looping the values are not coming into the label.

i have return the code like this

  data lo_inp  type ref to cl_wd_input_field.

  data lo_label type ref to cl_wd_label.

i am looping the records from the table.

loop at lt_data into ls_data.

lo_label = cl_wd_label=>new_label( bind_text = ls_data-des ).

cl_wd_matrix_head_data=>new_matrix_head_data( element = lo_label ).

lo_container->add_child( the_child = lo_label ).

endloop.

but its going for dump  saying that ls_data-des is type compatiable with bind text.

then i have changed code like this.

lo_label = cl_wd_label=>new_label( bind_text = 'DATA.DES' ).

DATA.DES is nothing but CONTEXT NODE.

but i am not geting the out put

My requriment is

i have to get two labels with 2 input fields on the screen

frist label should be NAME and INPUTFIELD

second label should be AGE AND INPUTFIELD

This NAME and AGE are the 2 records which is coming from the backed table ZDATA.

Please suggest me in this requriment.

Waiting for Reply

Thanks & Regards

Krishna( sap consultant )

Former Member
0 Kudos

Hi Krishna,

Try this in your code. It'll work.

Replace

lo_label = cl_wd_label=>new_label( bind_text = ls_data-des ).

with

lo_label = cl_wd_label=>new_label( text = ls_data-des ).

Below is the sample code snippet for reference...

  data: lref_label type ref to cl_wd_label,
          lr_con type ref to cl_wd_uielement_container,
          lv_str type string value 'Test Label'.

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

  lref_label = cl_wd_label=>new_label( text = lv_str ).
  cl_wd_matrix_head_data=>new_matrix_head_data( element = lref_label ).

  call method lref_label->set_label_for
    exporting
      value = 'TXT'. " TXT is the ID of one of the Input Field in my view

  lr_con->add_child( lref_label ).

Regards,

Rohit

Former Member
0 Kudos

Hi Rohit,

Thanks for the mail, i am able to get the textview on the screen but un able to get input fields please provided me some information regarding this.The code which i have return i giving below please check the code and give suggestion on it.

CODE

DATA text TYPE string.

DATA lo_ui_root TYPE REF TO if_wd_view_element.
DATA lo_container TYPE REF TO cl_wd_uielement_container.

DATA lo_input TYPE REF TO cl_wd_input_field.
DATA lo_text TYPE REF TO cl_wd_text_view.

data inp type string.

IF first_time = 'X'.
   
SELECT * FROM ysaif_table1 INTO TABLE lt_tabel.
    lo_ui_root
= view->get_element( id = 'ROOTUIELEMENTCONTAINER' ).
    lo_container ?= lo_ui_root
.
    cl_wd_matrix_layout
=>new_matrix_layout( container = lo_container ).
   
LOOP AT lt_tabel INTO ls_tabel.
     
text = ls_tabel-des.
      lo_text
= cl_wd_text_view=>new_text_view( text = text ).
      cl_wd_matrix_head_data
=>new_matrix_head_data( element = lo_text ).
      lo_container
->add_child( the_child = lo_text ).

      HERE I AM GETING THE TEXT FROM THE Z TABLE no issuse with text_view ui

  BUT I AM NOT GETING INPUTFIELDS.AND THE CODE WHICH I WAS RETURN FOR THIS IS.

      lo_input = cl_wd_input_field=>new_input_field( bind_value = 'TABEL.INP'  ).

   here TABLE is nothing but context node which i was decleared in view context and the INP is an attribute in the TABLE node. i have created this based on the ztable (ysaif_table1)

structure.

and here its showing error that TABLE.INP ELEMENT CONTAIN NO VALUE.

then i changed the code to.

inp = ls_tabel-inp

lo_input = cl_wd_input_field=>new_input_field( bind_value =

inp.)

(here bind_value should be bind with which value at runtime)

      cl_wd_matrix_data=>new_matrix_data( element = inp).
      lo_container
->add_child( the_child = inp ).

AND THEN ALSO ITS NOT WORKING.

Please provided me with logic to display label,inputfield,group and what are the parameters should be bind at runtime based on the no of records geting from the ztable not static.

Waiting for the Reply.

Thanks & Regards.

Krishna 

Former Member
0 Kudos

Hi Krishna,

The code which you have written is fine. The code is working fine for me.

There may be some issue with the Cardinality of the Node (TABLE in your case). It'll work fine if you keep the cardinality as 1:1 or 1:N.

But if you set the Cardinality as 0:N or 0:1 then make sure your node is filled with some data i.e. Element before you call this code for dynamic UI element creation.

Try with adjusting the Cardinality of the Node.

Regards,

Rohit

Former Member
0 Kudos

Hi Rohit,

Thanks for the reply,and one more information regarding the dynamic,

I created BUTTON dynamical and created action for that,but i am  not geting the values that we enter on inputfield.

normal inputfield we use GET_STATIC_ATTRIBUTES method to get the the values of input field at runtime.But how to get the values of input fields (more then one input field ) dynamically at runtime.

Thanks & Regards.

Krishna.

Former Member
0 Kudos

HI Rohit,

I need Table ui element  in editable, and one action to insert a row.I am geting table but its in display mode.

please provided me with information.

Wating for Reply.

Thanks & Regards.

Krishna.

Former Member
0 Kudos

HI Madhu,

I need Table ui element  in editable, and one action to insert a row using dynamic coding.I am geting table but its in display mode.

please provided me with information.

Wating for Reply.

Thanks & Regards.

Krishna.

Former Member
0 Kudos

Hi Krishna,

To have a table as Editable, you need to pick the cell editor for each column accordingly.

First you need to decide which columns should be editable.

Then while Creating the binding for table element you can select appropriate cell editor like Input Field, Drop Down, LinkToURL etc against each column.

Select Textview as cell editor for the Columns which you want as non-editable.

Also you can create new question since this is already marked as Answered.

Regards,

Rohit

Former Member
0 Kudos

Hi Rohit,

I need to create table editable with dynamic coding

Thanks & Regards.

Krishna.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi All,

I have created multiple UI elements dynamically based on the ZTABLE_UIELEMENTS entries. Now i need to provide input value help or search help for those fields dynamically. It means in the above table i have field called INPUT_HELP, in this field they will maintain a table name from that table i need to retrieve the data and provide input help for that respective UI element.

Regards,

Srinivasa

Former Member
0 Kudos

HI Srinivasa,

I need Table ui element  in editable, and one action to insert a row using dynamic coding.I am geting table but its in display mode.

please provided me with information.

Wating for Reply.

Thanks & Regards.

Krishna.

amy_king
Active Contributor
0 Kudos

Hi Krishna,

Thomas Szucs wrote a three-part blog on dynamic programming that may be helpful to you.

Cheers,

Amy

Former Member
0 Kudos

HI Amy,

I need Table ui element  in editable, and one action to insert a row using dynamic coding.I am geting table but its in display mode.

please provided me with information.

Wating for Reply.

Thanks & Regards.

Krishna.