cancel
Showing results for 
Search instead for 
Did you mean: 

create elemenst dynamically

Former Member
0 Kudos

Dear WebDynpro Experts,

is a possiblity existing to create elements dynamically.

e.g.

TextFields, Radio-Buttons etc

Thanks in advance

Spielwiese

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thank you for the efforts to help me.

I still have the problem, my question was not answered correctly

My question at the beginning was, is there a possibility

to create elements absolutely dynamical or generic only with

Web Dynpro Abap and not another technology like FLEX etc..

I dont know what I should learn in SAP between so many technologies

since I dont even master WD.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Just to be clear, I wasn't saying you should use flex. That just happened to be the UI element type that I was using in my dynamic example. This approach can be used with any WD UI elements. I'm not sure where you are not clear. You have examples of how to code in the WDDOMODIFYVIEW and there are suggestions to research RowReapter and MultiPane depending upon your detailed requirements. These are three different ways that you might be able to meet your requirement of dynamic UI element creation.

Former Member
0 Kudos

I do not dispute that I haven't get examples but the problem is I am looking for a way

that allows to create the entire element only with abap coding inside Web Dynpro Without creating a context element or attribur manually. As mentioned only with coding.

Certainly it is interesting being introduced into other technologies but in this case I really

need it only with WD

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

That is the code that has been pointed out to you. It is used to create any UI element you want using similar logic in WDDOMODIFYVIEW. You still need a context for binding to the UI elements. You can create this context dynamically as well using the context APIs. Is that the part you need help with? You still build the binding strings for the UI elements regardless of if the context they are bound to are dynamic or not.

For instance here is another eLearning video that shows dynamic context creation, dynamic controller/view mapping, and dynamic binding.

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/201ddd3b-b4ce-2b10-8883-880ae814...

Former Member
0 Kudos

thank you many times I will watch this video tomorrow.

I think this the solution

Regards

Sw

Answers (8)

Answers (8)

Former Member
0 Kudos

do you have more such videos this exactly what I am looking for

Former Member
0 Kudos

Ok . Thank you very much for all your help.

Is it possible generally to create an element absolut dynamically. I mean only with coding.

Without creating any attributes in the context. Suppose I want to develop something like a

formular generator.

Privously I dont know how many elements (TextInput, Checkbox, Radiobutton etc...) I need. I have thought to create a Z-Table for it and LOOP AT this table to the runtime

in order to READ which elements are needed. Afterwards they will be created regarding the table.

This is my idea. is it possible to implement such a req.

Regards

SW

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You can do this at runtime in code using the WDDOMODIFYVIEW method. You can loop through a table and use the loop passes to determine which UI elements you create. But you can also do the same without resorting to WDDOMODIFYVIEW. This is why we have the RowRepeater and MultiPane UI elements. They bind to a context node and general as many inner UI element repeating structures as there are elements in this node. If you just want a dynamic number of UI elements, this is a better way to go.

This eLearning exercise shows a use of a MultiPane to display a variable number of images with captions:

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/50d42644-91ef-2b10-228c-9e0ae75b...

Here is an example of how you could do this sort of thing in WDDOMODIFYVIEW. This is for a FlashIsland - I am inserting a dynamic number of DataSource Properties depending upon what ABAP internal table type structure I have. The ABAP data definition is built at runtime dynamically:

method wddomodifyview .
  if first_time = abap_true.
    data lo_nd_rich_catalog type ref to if_wd_context_node.
    data lt_rich_catalog type wd_this->elements_rich_catalog.
    lo_nd_rich_catalog = wd_context->get_child_node( name = wd_this->wdctx_rich_catalog ).
    lo_nd_rich_catalog->get_static_attributes_table( importing table = lt_rich_catalog ).

    field-symbols <wa_rich_cat> like line of lt_rich_catalog.
    data lr_ds type ref to cl_wd_gac_data_source.
    data lr_ds_prop type ref to cl_wd_gac_property.
    loop at  lt_rich_catalog assigning <wa_rich_cat>.
      lr_ds  ?= view->get_element( 'GACDATASOURCE' ).
      lr_ds_prop = cl_wd_gac_property=>new_gac_property(
           bind_value     = `SALES_DATA.` && <wa_rich_cat>-colid
           id             = `GACPROP` && <wa_rich_cat>-colid
           name           = <wa_rich_cat>-colid
           read_only      = ''
           view           = view ).
      lr_ds->add_property(
        exporting
          the_property = lr_ds_prop ).
    endloop.
  endif.
endmethod.

Former Member
0 Kudos

Hello Thomas, thank you for your reply.

I get the message elements_rich_catalog is unknown.

Regards

sas

Former Member
0 Kudos

use elements_<your context node name here>

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I imagine you would get an error if you just cut and pasted my code. It is specific to my application - hence the names of the elements, the binding strings, etc. This is just a sample to demonstrate the process. It doesn't necessarily even create the UI elements that you are wanting. As stated it creates FlashIslands DataSet Properties. Is that what you want to create dynamically?

Former Member
0 Kudos

hi,

elements_Test is unknown.

By the way what is FlashIslands ?????? I have never heard about ? is it FLEX ?

Is that the only way to implement the req.

if first_time = abap_true.
    data lo_nd_rich_catalog type ref to if_wd_context_node.
    data lt_rich_catalog type wd_this->elements_Test.
    lo_nd_rich_catalog = wd_context->get_child_node( name = wd_this->wdctx_rich_catalog ).
    lo_nd_rich_catalog->get_static_attributes_table( importing table = lt_rich_catalog ).

    field-symbols <wa_rich_cat> like line of lt_rich_catalog.
    data lr_ds type ref to cl_wd_gac_data_source.
    data lr_ds_prop type ref to cl_wd_gac_property.
    loop at  lt_rich_catalog assigning <wa_rich_cat>.
      lr_ds  ?= view->get_element( 'GACDATASOURCE' ).
      lr_ds_prop = cl_wd_gac_property=>new_gac_property(
           bind_value     = `SALES_DATA.` && <wa_rich_cat>-colid
           id             = `GACPROP` && <wa_rich_cat>-colid
           name           = <wa_rich_cat>-colid
           read_only      = ''
           view           = view ).
      lr_ds->add_property(
        exporting
          the_property = lr_ds_prop ).
    endloop.
  endif.
endmethod.

Edited by: spielwiese on Apr 9, 2009 3:07 PM

Former Member
0 Kudos

hi,

Have you created a Node with name Test and added to it attributes.

Also change this line from

lo_nd_rich_catalog = wd_context->get_child_node( name = wd_this->wdctx_rich_catalog )

to

lo_nd_rich_catalog = wd_context->get_child_node( name = wd_this->wdctx_test).

Thanx.

Former Member
0 Kudos

Hi Saurav

I have created a Node with name Test but which attritubtes must be inserted ?

I dont have any attributes ? Are they need , if so how must be they named in this

case ?

Thx

Sw

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>By the way what is FlashIslands

FlashIslands is a new Web Dynpro ABAP UI element in 7.01 that allows for the integration of Adobe Flash and Flex components.

>Is that the only way to implement the req.

No this is just an example to show you how you can use WDDOMODIFYVIEW to dynamically generate UI elements. There are different ways of coding in WDDOMODIFYVIEW. However they all come from the fact that each UI element has a class representation CL_WD_<UI ELEMENT ID> and view access to the VIEW object you can add, delete or modify UI elements.

But as I stated before, depending upon what you actually need to do, the MultiPane or RowReapter might actually be easier:

http://help.sap.com/saphelp_nw70ehp1/helpdata/en/df/da8b412bb5b35fe10000000a1550b0/frameset.htm

http://help.sap.com/saphelp_nw70ehp1/helpdata/en/44/93d3792e8c60d6e10000000a114a6b/frameset.htm

Former Member
0 Kudos

Thoma I thank you again,

what do I need for Flex components. Is it possible to develop within SE80 ?

Why is Flex so good ? What allows it to do and why this new technology.

I woul be glad if you could tell me that wit few words.

Thx

Sw

Former Member
0 Kudos

hi,

You need a Adobe Flex Builder, NetWeaver 7.0 with Enhancement Package 1.

Follow the link . It has many links for Adobe Flash Island.

https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/3861. [original link is broken] [original link is broken] [original link is broken]

Check out for Adobe Flash Islands for Web Dynpro ABAP

Also refer this link :

Thanx.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> Thoma I thank you again,

>

>

> what do I need for Flex components. Is it possible to develop within SE80 ?

>

> Why is Flex so good ? What allows it to do and why this new technology.

>

> I woul be glad if you could tell me that wit few words.

>

> Thx

> Sw

No you don't develop Adobe Flex in SE80. You still use Adobe Flex Builder for that step. However the compiled SWF gets uploaded to the MIME Repository and becomes an integrated part of the WDA application. Data and events flow bi-directionally between WDA and Flex via an XML interface - but from programming you can data binding and register actions against the Flex Component as though it was a native WDA UI element.

You can read more about it:

Plus there are tutorials and eLearnings listed here:

https://wiki.sdn.sap.com/wiki/display/EmTech/SAPRichIslandsforAdobe+Flash

Former Member
0 Kudos

hi,

what do you mean with attributes ?

I have created a new WebDynpro Projekt in the Workbench have have passed then

the code (above shown) within the main view's WDDOMODIFYVIEW method.

Thats all what I have done. For further steps pls. guide me step by step, bacuse

I dont understand so mauch about WD.

By the way, how can we speak about here about creating dynamically elements

if those steps are not enough up to now. What is still required ?

Pls help

Sw

Former Member
0 Kudos

hi,

In the left side you vl find Object Name where you must have given name to your component.

Object-> View -> Your View Name.

Double Click on your view Name, you will enter into a screen having various Tabs like

Property , Layout , Inbound ,Outbound , Context.

Go to Context. In the window Right click on Context and Create a Context Attribute.

Thanx.

arjun_thakur
Active Contributor
0 Kudos

Hi,

If we want to change any property of any UI element , we do it with the help of attributes. Go to the attribute tab of view, right click on context and then create attributes as told in my previous post.

I would suggest that you should try to understand the concepts of webdynpro abap first and then should try coding in it. For that you can refer this [doc|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/63a47dd9-0b01-0010-3d8e-de27242bf011].

I hope it helps.

Regards

Arjun

Former Member
0 Kudos

Hi,

Refer Standard Component Like Wdr_test_events.

I would suggest you to have a look at Std Components all Starting with WDR* .

For more concepts , you can search on sdn or you also have www.help.sap.com

Thanx.

Former Member
0 Kudos

Hi,

I get the following output.

I have tried your example coding

method WDDOMODIFYVIEW .


  if first_time eq abap_true.


    data: LR_CONTAINER type ref to CL_WD_UIELEMENT_CONTAINER,
    LR_RADIOBUTTON1 type ref to CL_WD_RADIOBUTTON,
    LR_RADIOBUTTON2 type ref to CL_WD_RADIOBUTTON,
    LR_FLOW_DATA type ref to CL_WD_FLOW_DATA.



    " bind text property will give TEXT that appears next to Radio Button
    CALL METHOD cl_wd_radiobutton=>new_radiobutton
      EXPORTING
        bind_selected_key = '01'
        BIND_TEXT         = 'Male'
      RECEIVING
        control           = LR_RADIOBUTTON1.


    " bind text property will give TEXT that appears next to Radio Button
    CALL METHOD cl_wd_radiobutton=>new_radiobutton
      EXPORTING
        bind_selected_key = '02'
        BIND_TEXT         = 'Female'
      RECEIVING
        control           = LR_RADIOBUTTON2.


    LR_FLOW_DATA = CL_WD_FLOW_DATA=>NEW_FLOW_DATA( element = LR_RADIOBUTTON1 ).
    LR_FLOW_DATA = CL_WD_FLOW_DATA=>NEW_FLOW_DATA( element = LR_RADIOBUTTON2 ).
    LR_CONTAINER ?= view->GET_ELEMENT( 'ROOTUIELEMENTCONTAINER' ).
    LR_CONTAINER->ADD_CHILD( LR_RADIOBUTTON1 ).
    LR_CONTAINER->ADD_CHILD( LR_RADIOBUTTON2 ).


  endif.


endmethod.

Error when processing your request 

Note 

The following error text was processed in the system E70 : Could not find attribute 01 
The error occurred on the application server apssap14_E70_00 and in the work process 0 . 
The termination type was: RABAX_STATE 
The ABAP call stack was: 
Method: IF_WD_CONTEXT_NODE_INFO~GET_ATTRIBUTE of program CL_WDR_CONTEXT_NODE_INFO======CP
Method: IF_WD_CONTEXT_ELEMENT~GET_ATTRIBUTE of program CL_WDR_CONTEXT_ELEMENT========CP
Method: GET_ATTRIBUTE_INTERNAL of program CL_WDR_VIEW_ELEMENT_ADAPTER===CP
Method: IF_NW7_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/C0STANDARD==============CP
Method: IF_NW7_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/C8STANDARD==============CP
Method: IF_NW7_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/C8STANDARD==============CP
Method: IF_NW7_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/C7STANDARD==============CP
Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program CL_WDR_VIEW_ADAPTER===========CP
Method: IF_WDR_NW7_DELTA_RENDERER~CALCULATE_DELTA_BLOCKS of program CL_WDR_VIEW_ADAPTER===========CP
Method: IF_WDR_NW7_DELTA_RENDERER~CALCULATE_DELTA_BLOCKS of program CL_WDR_WINDOW_CONTENT_ADAPTER=CP

arjun_thakur
Active Contributor
0 Kudos

Hi,

In the bind_selected_key and BIND_TEXT parameter we have to pass the name of the attribute with which we want to bind that property of the radio button.

Make three attributes say attr1, attr2, attr3 (all of the type string). Give default value of attr2 and attr3 after that code like this:


if first_time eq abap_true.
 
 
    data: LR_CONTAINER type ref to CL_WD_UIELEMENT_CONTAINER,
    LR_RADIOBUTTON1 type ref to CL_WD_RADIOBUTTON,
    LR_RADIOBUTTON2 type ref to CL_WD_RADIOBUTTON,
    LR_FLOW_DATA type ref to CL_WD_FLOW_DATA.
 
 
 
    " bind text property will give TEXT that appears next to Radio Button
    CALL METHOD cl_wd_radiobutton=>new_radiobutton
      EXPORTING
        bind_selected_key = 'ATTR1' "name of the first attribute
        BIND_TEXT         = 'ATTR2' "name of the second attribute

      RECEIVING
        control           = LR_RADIOBUTTON1.
 
 
    " bind text property will give TEXT that appears next to Radio Button
    CALL METHOD cl_wd_radiobutton=>new_radiobutton
      EXPORTING
        bind_selected_key = 'ATTR1'
        BIND_TEXT         = 'ATTR3' "name of the third attribute
      RECEIVING
        control           = LR_RADIOBUTTON2.
 
 
    LR_FLOW_DATA = CL_WD_FLOW_DATA=>NEW_FLOW_DATA( element = LR_RADIOBUTTON1 ).
    LR_FLOW_DATA = CL_WD_FLOW_DATA=>NEW_FLOW_DATA( element = LR_RADIOBUTTON2 ).
    LR_CONTAINER ?= view->GET_ELEMENT( 'ROOTUIELEMENTCONTAINER' ).
    LR_CONTAINER->ADD_CHILD( LR_RADIOBUTTON1 ).
    LR_CONTAINER->ADD_CHILD( LR_RADIOBUTTON2 ).
 
 
  endif.

Regards

Arjun

Former Member
0 Kudos

Hi

Use class methods to do this

cl_wd_[UI element]

Ex: cl_wd_table, cl_wd_tabstrip, cl_wd_button

Best Regards

Ravi Golla

Former Member
0 Kudos

hi

Check out this link . It has some videos on Dynammic Programming :

https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/3861. [original link is broken] [original link is broken] [original link is broken]

For your Ref :

Dynammic Radio buttons are created using following Code :

method wddomodifyview .

if first_time eq abap_true.

data: LR_CONTAINER type ref to CL_WD_UIELEMENT_CONTAINER,

LR_RADIOBUTTON1 type ref to CL_WD_RADIOBUTTON,

LR_RADIOBUTTON2 type ref to CL_WD_RADIOBUTTON,

LR_FLOW_DATA type ref to CL_WD_FLOW_DATA.

" bind text property will give TEXT that appears next to Radio Button

CALL METHOD cl_wd_radiobutton=>new_radiobutton

EXPORTING

bind_selected_key = '01'

BIND_TEXT = 'Male'

receiving

control = LR_RADIOBUTTON1.

" bind text property will give TEXT that appears next to Radio Button

CALL METHOD cl_wd_radiobutton=>new_radiobutton

EXPORTING

bind_selected_key = '02'

BIND_TEXT = 'Female'

receiving

control = LR_RADIOBUTTON2.

LR_FLOW_DATA = CL_WD_FLOW_DATA=>NEW_FLOW_DATA( element = LR_RADIOBUTTON1 ).

LR_FLOW_DATA = CL_WD_FLOW_DATA=>NEW_FLOW_DATA( element = LR_RADIOBUTTON2 ).

LR_CONTAINER ?= view->GET_ELEMENT( 'ROOTUIELEMENTCONTAINER' ).

LR_CONTAINER->ADD_CHILD( LR_RADIOBUTTON1 ).

LR_CONTAINER->ADD_CHILD( LR_RADIOBUTTON2 ).

endif.

endmethod.

Basics of dynammic Programming : ( taken from link -> /people/roger.sainsbury/blog/2008/02/01/practical-tips-for-developing-with-abap-webdynpro ).

Dynamic Programming using WDDOMODIFYVIEW

For each view, inside hook method WDDOMODIFYVIEW you are given a reference to the view itself. Using this it is possible to get references to the view's UI elements. Using methods of the various UI element classes, you can change the UI element properties directly, without them being bound to anything in the context.

Note that WDDOMODIFYVIEW is the only place you can get the view reference, and should be the only place where you make these kinds of changes.

Because the UI elements are not bound, this method has the advantage that you can still set the properties in the view layout, which will be your default values. You only need the dynamic programming to run when you want to change from those defaults.

Each of these three methods has its own advantages and disadvantages, and the best method to use may vary according to circumstances. Something you may wish to consider is the use of a bespoke configuration table to control the UI properties. Such a table will need these fields:

The data fields which you want to affect the layout. For example these could be Document Type, Company Code, application mode etc. These will be key fields.

Fields to identify the UI element. These will probably be Webdynpro Component, View name and Element name. These will also need to be key.

Simple flags for the four UI properties.

A free text comment field may be useful for explaining your logic in words .

thanx.

arjun_thakur
Active Contributor
0 Kudos

Hi Spielwiese,

Yes, it is very much possible to create UI elements dynamically.

Refer these blogs on dynamic progamming:

/people/thomas.szcs/blog/2005/12/28/dynamic-programming-in-web-dynpro-abap--introduction-and-part-i-understanding-ui-elements

/people/thomas.szcs/blog/2006/01/03/dynamic-programming-in-web-dynpro-abap--part-ii-handling-viewelements

/people/thomas.szcs/blog/2006/02/22/dynamic-programming-in-web-dynpro-abap--part-iii-aggregations-and-ddic-binding-of-viewelements

I hope it helps.

Regards

Arjun

Former Member
0 Kudos

in the modifiy method of view,

you can create the elements dynamically.

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/201ddd3b-b4ce-2b10-8883-880ae814...

Best regards,

Rohit