cancel
Showing results for 
Search instead for 
Did you mean: 

Creating UI elements dynamically

Former Member
0 Kudos

Hi Every body ,

Thanks for replying my previous threads . My current requirment is i need to create UI elements on screen dynamically , but type of UI element also i ll decide in run time only .

pl help on this .

Thanks in advance ,

Vijay vorsu

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Vijay,

You can as well create UI elements dynamically. As how Thomas was pointing out you can do this in the WDDOMODIFYVIEW method. If you are a beginner at dynamic programming then I would suggest you to go through the 3 blog series of Thomas Szuecs. They are the best source for anyone starting over dynamic programming in WDA. Below are the links to the same:

[Introduction and Part I: Understanding UI Elements|/people/thomas.szcs/blog/2005/12/28/dynamic-programming-in-web-dynpro-abap--introduction-and-part-i-understanding-ui-elements]

[Part II: Handling ViewElements|/people/thomas.szcs/blog/2006/01/03/dynamic-programming-in-web-dynpro-abap--part-ii-handling-viewelements]

[Part III: Aggregations and DDIC-Binding of ViewElements|/people/thomas.szcs/blog/2006/02/22/dynamic-programming-in-web-dynpro-abap--part-iii-aggregations-and-ddic-binding-of-viewelements]

Regards,

Uday

Former Member
0 Kudos

Hi Uday ,

Thanks for quick reply . I worked on dynamic coding before. As i mentioned in my question , during coding i dont know which UI element has to be created . I will decide type of UI element also in runtime .

Example : we are giving the option to user to select which type of UI element has to be displayed on the screen . If user selects ( table , input field or drop down ) based on selection i have to create selected type of UI element on my screen . So i want to know how create any UI element dynamically .

Thanks in advance ,

Vijay

uday_gubbala2
Active Contributor
0 Kudos

Hi Vijay,

I dont quite understand your requirement. You mean to say that the end user can make a selection in portal and you want the UI to be then dynamically generated as per the UI element of his choice?

May be you can have a DropDown filled with the names of UI elements & then depending up on the value selected from the DropDown you can execute a Case structure. Within this case structure use your regular dynamic coding for each & every element type. So depending up on the kind of ui element the user has selected from the DropDown the corresponding "when block" would gets executed resulting in creation of the ui element.

This should help solve your problem but then again am not quite sure about the reason behind offering your users this kind of functionality. Is this a client requirement or you are just trying to test implementing 1 of your ideas?

Regards,

Uday

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You can be completely dynamic and even create the source code dynamically and execute it dynamically. Here is an example of dynamic coding:

                • Begin Dynamic Coding for Selection

  • This dyanamic code will create field symbols for each Select Option

  • that has a valid range table. It will then use each of these in

  • the where condition of the selection

data itab1 type table of string.

data prog type string.

data class type string.

data code_string type string.

data: sel_fields type if_wd_select_options=>tt_selection_screen_item.

field-symbols: <wa_fields> like line of sel_fields,

<wa_generic> type table.

wd_this->lv_sel_handler->get_selection_fields( importing et_fields = sel_fields ).

append `program.` to itab1.

append `class zz_main_dyn definition.` to itab1.

append ` public section.` to itab1.

append ` class-methods meth ` to itab1.

append ` importing ` to itab1.

append ` itab type ref to data ` to itab1.

append ` sel_fields TYPE if_wd_select_options=>tt_selection_screen_item. ` to itab1.

append `endclass.` to itab1.

append `class zz_main_dyn implementation.` to itab1.

append ` method meth.` to itab1.

append ` FIELD-SYMBOLS <table> TYPE ANY TABLE.` to itab1.

append ` ASSIGN itab->* TO <table>.` to itab1.

append ` field-symbols: <wa_field> like line of sel_fields.` to itab1.

"Removed bulk of logic

move '.' to code_string.

append code_string to itab1.

append ` endmethod.` to itab1.

append `endclass.` to itab1.

  • Compile the dynamic Class and check for generation errors

data: mess type string.

generate subroutine pool itab1 name prog message mess.

  • I debated if I wanted to display generation errors

  • They likely won't make any sense to an end user - they are really meant for serious troubleshooting

  • In the end I thought it was better to throw this error to the screen rather than dump when the class

  • attempts to be called.

if mess is not initial.

  • report message

l_message_manager->report_error_message(

message_text = mess ).

exit.

endif.

  • Prepare the parameters for the dynamic class call

concatenate `\PROGRAM=` prog `\CLASS=ZZ_MAIN_DYN` into class.

data: ptab type abap_parmbind_tab,

ptab_line type abap_parmbind.

ptab_line-name = 'ITAB'.

ptab_line-kind = cl_abap_objectdescr=>exporting.

get reference of stru_tab into ptab_line-value.

insert ptab_line into table ptab.

ptab_line-name = 'SEL_FIELDS'.

ptab_line-kind = cl_abap_objectdescr=>exporting.

get reference of sel_fields into ptab_line-value.

insert ptab_line into table ptab.

  • Call the Dynamic Class

call method (class)=>meth

parameter-table

ptab.

********End Dynamic Coding

But you could also have branching code with prebuilt templates depending upon how flexible you need to be.

Edited by: Thomas Jung on Jun 24, 2009 9:11 AM

Former Member
0 Kudos

Thanks Thomas ....

That solved my problem ....

Vijay vorsu

Answers (1)

Answers (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

That is what the WDDOMODIFYVIEW method of the Phase Model can be used for. All UI elements have classes and can be created dynamically within this special method. Have a look at the onlien help for WDDOMODIFYVIEW or the SAP demo application DEMODYNAMIC.