Dynamically creating a component
Hey,
Does anybody know how to accomplish the following task:
I'm getting a name of a component as a string from and XML.
for example 'Label' or 'Textbox'. I then want to create an instance
of that component. as the following shows
var cType:String = data[0].component.toString();
var myComponent:*;
myComponent = new cType();
Any ideas?
Thanks
Josh
You can make things a bit easier. Use ApplicationDomain's
getDefinition() function. You can pass it the name of the class
(eg, "Label") and it will return the class definition, then you can
use the new operator to make an instance. You just need to link in
all of the classes you expect to use.
Similar Messages
-
Play effect on dynamically created visual component
Hi!
Can someone please explain to me, how do I play effect on a visual component created in actionscript?
Thanks, regardsYou can also set the target/targets property of the effect once you've created the instance in AS, just like you do in MXML code. So where in MXML you might have something like this:
<mx:Button id="button" click="mover.play()"/>
<mx:Move id="mover" target=""/>
you would do the equivalent in actionscript like this:
var button:Button = new Button();
var mover:Move = new Move();
mover.target = button;
button.addEventListener(MouseEvent.CLICK, clickHandler);
private function clickHandler(event:Event):void
mover.play();
There's no mystery here in launching effects from AS - it's the same properties and structures that you set up in MXML, just different syntactic ways of referring to the properties and events.
Chet. -
Dynamic created component, problem to set position
hello,
I want to create in dynamic way label component and put it on GridPanel in given position. How can I set this position(x,y) to created component?
thanks in advanceHi, Jeff.
Just don't want to cross post the same answer all over the forum. So I gave some inputs on the topic in this message: http://forums.sdn.sap.com/thread.jspa?messageID=11127647�
Hope this will help you. -
Finding Component on Dynamically Created UI
I am having a hard time regarding finding a particular component in my managed bean if your UI is dynamically created (say using an iterator..) especially
if you need that component during PPR.
As of the moment, I am doing this but its really ugly and is bound to be broken if I add another layout.
public void handleChange(ValueChangeEvent valueChangeEvent) {
UIComponent component = valueChangeEvent.getSource().getParent().getChildren().get(0).getChildren().getFacet("end").get(0).getChildren().get(1);
AdfFacesContext context = AdfFacesContext.getCurrentInstance();
context.addPartialTarget(component);
}This code wont work also, since at runtime, I wouldnt know the id of the component.
FacesContext facesCtx = FacesContext.getCurrentInstance();
facesCtx.getViewRoot().findComponent(name) ; Been thinking about this for sometime now. Help needed.you can use this instead
FacesContext.getCurrentInstance().getViewRoot().findComponent("<id>);
or
// used to locate region. Could also find any component
// located in the base ViewRoot()
public static UIComponent findComponentInRoot(String id) {
UIComponent component = null;
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext != null) {
UIComponent root = facesContext.getViewRoot();
component = findComponent(root, id);
return component;
// Recursive method which finds your component within JSFF
// regardless of facet or other UIComponents which may have children
public static UIComponent findComponent(UIComponent base, String id) {
if (id.equals(base.getId()))
return base;
UIComponent kid = null;
UIComponent result = null;
Iterator kids = base.getFacetsAndChildren();
while (kids.hasNext() && (result == null)) {
kid = (UIComponent) kids.next();
if (id.equals(kid.getId())) {
result = kid;
break;
result = findComponent(kid, id);
if (result != null) {
break;
return result;
} -
Creating a application dynamically for a component
Hi,
Does any one know how to create an application dynamically for a component, so without using SE80?
I already found class cl_wdy_md_application, but I do not know if this is the right direction. Maybe somebode already solved this issue.
Regards,
RemcoHi Thomas,
In SRM it is possible to call own made webdynpro components and fill them with data, and then process these data into a new shopping card. This can be done by filling a so called HOOK_URL. In SRM you have to do customizing and fill in the URL to be used of the WebDynpro application. So far, still no problems.
I have built a component by which an user can fill several Z tables and then he can display a form he has made by himself (a so called free order form). So the component will check all Z tables, and generate in one view, the context dynamically as also the layout dynamically. In all Z tables one field has been used as one of the keyfields and that is free order form name and this is also a parameter of the application so that this application knows which data to get from the Z tables to generate a form.
And because it is possible to generate more then one forms, I have create per form 1 application with the specific parameter, and this URL can be entered in the customizing of SRM.
This application creation I did myself, but now I want to accomplish, when the user creates a new form by filling specific tabels via webdynpro, that he can generate the application by himself.
Maybe I can create a FM/BAPI for the BDC recording and then call this from my web dynpro application as there is no API.
Do you maybe have another solution?
Regards,
Remco -
MethodnotFound Exception for dynamically created component(menuItem)
Hi
I have created menuItem component and tried to create Action Listener object and setting it to the component in the backing bean.
but it is throwing methodnot found exception.
javax.el.MethodNotFoundException: Method not found: [email protected]()
javax.faces.el.MethodNotFoundException: javax.el.MethodNotFoundException: Method not found: [email protected]()
at com.sun.faces.application.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:92)
Below is my code..
MenuItem item1 = new MenuItem();
item1.setValue(key);
Application app = FacesContext.getCurrentInstance().getApplication();
javax.faces.el.MethodBinding actionListener = app.createMethodBinding("#{breadCrumbBean.test}", null);
item1.setActionListener(actionListener);
Let me know whether i created actionListener object or not.
Any suggestions...
Thanks
Edited by: _user on Jan 20, 2011 9:27 PMHi,
I tried this it works for me...
Try to set as below...
MethodExpression ee = context.getApplication().getExpressionFactory().createMethodExpression(context.getELContext(), "#{breadCrumbBean.test}", String.class, new Class[] { });
item1.setActionExpression(ee);
Regards,
Suganth.G -
Problem with embeding the same view in dynamically created view container
Hello Experts,
I am getiing a dump when i try to embed the same view inside the dynamically created view container of
dynamically created tabs of a tabstrip
The requirement go like this, i have 2 views in which i have have to embed the 2nd view to view1 where i have an empty
tabstrip without tabs. During runtime i create tabs as well as view containers accordingly and then try to embed view2 in tabs.
I have put the below mentioned code in HANDLEIN,
DATA: lref_vcntlr TYPE REF TO if_wd_view_controller,
lref_comp TYPE REF TO if_wd_component_usage,
lv_embed_pos TYPE string.
lref_vcntlr = wd_this->wd_get_api( ).
lv_embed_pos = 'FILE_PERS_EDIT/VC_GENERAL'.
TRY.
CALL METHOD lref_vcntlr->do_dynamic_navigation
EXPORTING
source_window_name = 'FILE_PERSISTENCE_WND' " Window
source_vusage_name = 'FILE_PERS_EDIT_USAGE_1' " Source View usage
source_plug_name = 'TO_EDIT_LAYOUT' " Outbound plug
target_view_name = 'PERS_EDIT_LAYOUT' " Second view to be embedded
target_plug_name = 'IN' " Second view inboun plug
target_embedding_position = lv_embed_pos
RECEIVING
component_usage = lref_comp.
CATCH cx_wd_runtime_repository .
ENDTRY.
wd_this->fire_to_edit_layout_plg( ).
This works fine for the first time.
However onaction tab select i change the embeding position( 'FILE_PERS_EDIT/view container name of different tab') of the view2 an try to embed view2 in a different tab.
At this point i get a dump stating View2 already present in the window 'FILE_PERSISTENCE_WND' of component.
I think, the view2 embediing has to be removed before i add the view2 in a different tab
Kindly let me know how to remove view2 embedding from tab1 before i add a view2 to a different tab or is there any other
means to handle this problem?
Thanks & Best Regards,
Srini.Hello Srini,
I found a solution to your problem, because I had a similar task.
In WDDOINIT I changed the method do_dynamic_navigation to if_wd_navigation_services_new~prepare_dynamic_navigation:
DATA:
l_view_controller_api TYPE REF TO if_wd_view_controller.
l_view_controller_api = wd_this->wd_get_api( ).
TRY.
CALL METHOD l_view_controller_api->if_wd_navigation_services_new~prepare_dynamic_navigation
EXPORTING
source_window_name = 'WDW_MAIN'
source_vusage_name = 'VW_SUB_USAGE_1'
source_plug_name = 'TO_VW_CONTENT'
target_component_name = 'ZTEST_DYNAMIC'
target_view_name = 'VW_CONTENT'
target_plug_name = 'DEFAULT'
target_embedding_position = 'VW_MAIN/VC_TAB.VW_SUB/TAB1_VC'
RECEIVING
repository_handle = wd_this->g_rep_handle.
CATCH cx_wd_runtime_repository .
ENDTRY.
wd_this->fire_to_vw_content_plg( param1 = 'TAB1' ).
In the action I first deleted the navigation targets, then navigated to the empty-view and last I called my target view:
DATA:
lv_position TYPE string,
l_view_controller_api TYPE REF TO if_wd_view_controller,
lr_view_usage TYPE REF TO if_wd_rr_view_usage,
lr_view_***_t TYPE wdrr_vca_objects,
lr_view_*** LIKE LINE OF lr_view_***_t.
l_view_controller_api = wd_this->wd_get_api( ).
lr_view_usage = wd_this->g_view->get_view_usage( ).
lr_view_usage->delete_all_navigation_targets( plug_name = 'TO_VW_CONTENT' ).
CLEAR lv_position.
CONCATENATE 'VW_MAIN/VC_TAB.VW_SUB/' old_tab '_VC' INTO lv_position.
TRY.
l_view_controller_api->if_wd_navigation_services_new~do_dynamic_navigation(
source_window_name = 'WDW_MAIN'
source_vusage_name = 'VW_SUB_USAGE_1'
source_plug_name = 'TO_EMPTYVIEW'
target_component_name = 'ZTEST_DYNAMIC'
target_view_name = 'EMPTYVIEW'
target_plug_name = 'DEFAULT'
target_embedding_position = lv_position ).
CATCH cx_wd_runtime_repository.
ENDTRY.
CLEAR lv_position.
CONCATENATE 'VW_MAIN/VC_TAB.VW_SUB/' tab '_VC' INTO lv_position.
TRY.
wd_this->g_rep_handle = l_view_controller_api->if_wd_navigation_services_new~prepare_dynamic_navigation(
source_window_name = 'WDW_MAIN'
source_vusage_name = 'VW_SUB_USAGE_1'
source_plug_name = 'TO_VW_CONTENT'
target_component_name = 'ZTEST_DYNAMIC'
target_view_name = 'VW_CONTENT'
target_plug_name = 'DEFAULT'
target_embedding_position = lv_position ).
CATCH cx_wd_runtime_repository.
ENDTRY.
wd_this->fire_to_vw_content_plg( param1 = tab ).
Ann.: I my example, I had 3 views: VW_MAIN which embedds VW_SUB. VW_SUB has the tabs in it and VW_SUB embedds VW_CONTENT.
BR,
Roland -
Hi ,
I try to create a component in DC B from DC A.For this I use the method
wdThis.wdGetObjectComponentUsage().createComponent(componentName, dc);
where componentName = path of the webdynpro component
eg:com.sap.a1s.reui.plugins.fdt.expressions.decisiontable.ExDecisionTable
dc=<vendor name>/<dc name>
sap.com/a1s/reui/plugins/fdtexpr
But I keep getting the runtime error
com.sap.tc.webdynpro.services.exceptions.WDRuntimeException: Failed to create deployable object 'sap.com/a1s/reui/plugins/fdtexpr' since it is not a Web Dynpro object
I also tried using
sap.com/a1s~reui/plugins/fdtexpr
But get the same error.
can anyone please help regarding how to get the DC name ?
Regards
Souravhi Saurav,
I think problem is web dynpro framework is not getting deployable object,
just give try to,
sap.com/a1s~fdtexpr
not sure but just a try, also check if this link is of any help
View Methods / Dynamic component creation
regards
Message was edited by:
Abhijeet -
Uploading data from excel file to a dynamically created internal table
Hi,
I have a requirement where i have to upload data from an excel file into a database table. I would be able to determine the structure of the table only at runtime based on the user input.. so i have created an internal table dynamically.
Could you please tell me if its possible to upload data from an excel file to the dynamically created internal table using any function modules?
I thought of doing this by declaring a generic internal table of one field and then uploading the *.csv file into it and then splitting it based on "," and then assigning it to the field symbol referencing the internal table.. but my file length exceeds 132 characters and i'm only able to get data of lenght 132 char's in my internal table ( generic one).
Could anyone please show me a way around this.
Thanks in advance,
HarshaSure, check this out.
report zrich_0002.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: it_fldcat type lvc_t_fcat,
wa_it_fldcat type lvc_s_fcat.
type-pools : abap.
data: new_table type ref to data,
new_line type ref to data.
data: iflat type table of string.
data: xflat type string.
data: irec type table of string with header line.
data: tabix type sy-tabix.
data: file type string.
selection-screen begin of block b1 with frame title text .
parameters: p_file type rlgrap-filename default 'c:Test.csv'.
parameters: p_flds type i.
selection-screen end of block b1.
start-of-selection.
* Add X number of fields to the dynamic itab cataelog
do p_flds times.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = sy-index.
wa_it_fldcat-datatype = 'C'.
wa_it_fldcat-inttype = 'C'.
wa_it_fldcat-intlen = 10.
append wa_it_fldcat to it_fldcat .
enddo.
* Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
assign new_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
file = p_file.
call method cl_gui_frontend_services=>gui_upload
exporting
filename = file
changing
data_tab = iflat
exceptions
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
others = 17.
loop at iflat into xflat.
clear irec. refresh irec.
split xflat at ',' into table irec.
loop at irec.
tabix = sy-tabix.
assign component tabix of structure <dyn_wa> to <dyn_field>.
<dyn_field> = irec.
endloop.
append <dyn_wa> to <dyn_table>.
endloop.
* Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
Regards,
Rich Heilman -
Passing values to dynamically created internal table
Hi,
I have the flat file data as
f1,f2,f3........so on
where f1 f2 and f3 are field names.
I have a variable var which contains the data
V1,0001,0002.........so on
data: var type string.
The value of field f1 is v1
The value of field f2 is 0001
The value of field f3 is 0002.......so on
FIELD-SYMBOLS: <fs_1> TYPE STANDARD TABLE
I have dynamically created an internal table for fields f1 f2 f3 ...... using
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fieldcatalog
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
ASSIGN <fs_data>->* TO <fs_1>.
Now for <fs_1> I have to pass the corresponding values of the fields f1 f2 f3 .
How can i solve this.
Thanks and regards ,
Parvatha ReddyHi,
There is no data in <fs_1>.
I need to pass the data form the string var to the fields of <fs_1>..
I understand that you want to populate the internal table <fs_1>.
for that you fist need work area.. use below statement to create work area..
DATA: new_line TYPE REF TO data.
CREATE DATA new_line LIKE LINE OF <fs_1>.
ASSIGN new_line->* TO <fs_2>.
<fs_2> is not your work aread...
to assign value to each field of you work aread <fs_2>. use statement
ASSIGN COMPONENT 1 OF STRUCTURE <fs_2> TO <fs_3>.
<fs_3> = f1 .
now <fs_3> will point to the first field of work area <fs_2>, f1 is value from your string .. repeat above for each field in workarea, by increasing the component number. Once your work area is filled
append it to table.
append <fs_2> to <fs_1>
apologies if I am not getting the requiremnt correctly.. -
Adding f:Attribute dynamically to a dynamically created Button
Hi ,
I am trying to dynamically create a CommandButton and attach a f:Attribute to the same. But somehow I am not able to get hold of the correct API to do the same -
>RichCommandButton button=new RichCommandButton();
>button.setText("Ok");
>AttributeTag attr=new AttributeTag();
>attr.setValue("DC_OPERATION_BINDING", "bindings.DENY");
>button.getChildren().add(attr);
The issue is that the add method expects a UIComponent and attr is of type com.sun.faces.taglib.jsf_core.AttributeTaggues u can use it like
button.getAttributes().put(DC_OPERATION_BINDING", "bindings.DENY");
{code}
http://docs.oracle.com/cd/E17802_01/j2ee/j2ee/javaserverfaces/1.2/docs/api/javax/faces/component/UIComponent.html#getAttributes%28%29 -
Adding AJAX support for dynamically created panelGrid components
Hi everyone!
I would like to ask help from anyone who may have encountered similar problem before...
I have a panelGrid whose component is dynamically created by the backing bean. Here is my JSF code:
<h:panelGrid styleClass="panelGrid"
rowClasses="tsPanelGridRowClass" columns="8" cellpadding="0"
cellspacing="2" bgcolor="transparent" style="margin-left: 10px"
id="revCenterItemPanelGrid"
binding="#{pc_Touchscreen_pull_select_item.revCenterItemPanelGrid}">
</h:panelGrid>And here is the code for backing bean that adds content inside the panelGrid:
HtmlOutputText index = (HtmlOutputText) app.createComponent(HtmlOutputText.COMPONENT_TYPE);
index.setId("1");
index.setValue(String.valueOf(1));
index.setStyle("datagridtext");
revCenterItemPanelGrid.getChildren().add(index);On click of a button...
<a4j:commandButton value="Update"
styleClass="commandExButtonPou2" id="button1" reRender="revCenterItemPanelGrid"
actionListener="#{pc_Touchscreen_pull_select_item.doSortActionListener2}">
<f:attribute name="order" value="2"></f:attribute>
<f:attribute name="toggleState" value="off"></f:attribute>
</a4j:commandButton>the backing bean is supposed to update the value of the outputText
doSortActionListener2() {
HtmlOutputText index = (HtmlOutputText) app.createComponent(HtmlOutputText.COMPONENT_TYPE);
index.setId("2");
index.setValue(String.valueOf(2));
index.setStyle("datagridtext");
revCenterItemPanelGrid.getChildren().add(index);
}However, update doesn't seem to work. I have been successful in adding ajax support to a panelGrid that is not dynamically created but not for this one.
Has anyone encountered this error before? Any ideas?
Thanks in advance!Hi everyone!
I would like to ask help from anyone who may have encountered similar problem before...
I have a panelGrid whose component is dynamically created by the backing bean. Here is my JSF code:
<h:panelGrid styleClass="panelGrid"
rowClasses="tsPanelGridRowClass" columns="8" cellpadding="0"
cellspacing="2" bgcolor="transparent" style="margin-left: 10px"
id="revCenterItemPanelGrid"
binding="#{pc_Touchscreen_pull_select_item.revCenterItemPanelGrid}">
</h:panelGrid>And here is the code for backing bean that adds content inside the panelGrid:
HtmlOutputText index = (HtmlOutputText) app.createComponent(HtmlOutputText.COMPONENT_TYPE);
index.setId("1");
index.setValue(String.valueOf(1));
index.setStyle("datagridtext");
revCenterItemPanelGrid.getChildren().add(index);On click of a button...
<a4j:commandButton value="Update"
styleClass="commandExButtonPou2" id="button1" reRender="revCenterItemPanelGrid"
actionListener="#{pc_Touchscreen_pull_select_item.doSortActionListener2}">
<f:attribute name="order" value="2"></f:attribute>
<f:attribute name="toggleState" value="off"></f:attribute>
</a4j:commandButton>the backing bean is supposed to update the value of the outputText
doSortActionListener2() {
HtmlOutputText index = (HtmlOutputText) app.createComponent(HtmlOutputText.COMPONENT_TYPE);
index.setId("2");
index.setValue(String.valueOf(2));
index.setStyle("datagridtext");
revCenterItemPanelGrid.getChildren().add(index);
}However, update doesn't seem to work. I have been successful in adding ajax support to a panelGrid that is not dynamically created but not for this one.
Has anyone encountered this error before? Any ideas?
Thanks in advance! -
How to add a table (dynamic created) into a model attribute
i have dynamically created an internal table. Generally i use model-binding in a stateful MVC-Application.
Is there a possibiltity to transfer the dynamic table to a model. As far as i know generic attributes are not allowed in the modell class.
Every hint welcome
thx in advanceBy some miracle I do have this finally working. I will warn you up front that the code is not the cleanest (I have stuff copied in from all over the place. I probably have lots of unused variable references - but I am running out of time to clean it up further). Also I don't have all the logic to support all your different possible dynamic structure types. I always use SFLIGHT as my dyanmic structure. Therefore you will have to adapt the coding to lookup the actual structure type in use.
So I have a model that has an structure ITAB type ref to data. In my Model initialization I go ahead and dynamically redfine this to my specific type:
METHOD init.
SELECT SINGLE * FROM sflight INTO CORRESPONDING FIELDS OF isflight.
DATA: struct_type TYPE REF TO cl_abap_structdescr,
tabletype TYPE REF TO cl_abap_tabledescr.
struct_type ?= cl_abap_structdescr=>describe_by_name( 'SFLIGHT' ).
CREATE DATA me->itab TYPE HANDLE struct_type.
ENDMETHOD.
Then in my View I have the following:
<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<%@extension name="phtmlb" prefix="phtmlb" %>
<%@extension name="bsp" prefix="bsp" %>
<htmlb:content design="design2003" >
<htmlb:page title=" " >
<htmlb:form>
<phtmlb:matrix width="100%" >
<%
field-symbols: <wa> type any.
assign model->itab->* to <wa>.
* append initial line to <wa_itab> assigning <Wa>.
data: descriptor type ref to CL_ABAP_STRUCTDESCR.
descriptor ?= CL_ABAP_STRUCTDESCR=>describe_by_data( <wa> ).
data: flddescr type DDFIELDS.
flddescr = descriptor->GET_DDIC_FIELD_LIST( ).
field-symbols: <wa_field> like line of flddescr.
data: label type ref to cl_htmlb_label.
data: input type ref to CL_HTMLB_INPUTFIELD.
data: binding_string type string.
"Loop through each field in the structure Definition
loop at flddescr assigning <Wa_field>.
clear label.
clear input.
concatenate '//model/itab.'
<wa_field>-FIELDNAME
into binding_string.
label ?= cl_htmlb_label=>factory( _for = binding_string ).
input ?= cl_htmlb_inputfield=>factory( _value = binding_string ).
%>
<phtmlb:matrixCell row = "+1"
vAlign = "TOP" />
<bsp:bee bee="<%= label %>" />
<phtmlb:matrixCell col = "+1"
vAlign = "TOP" />
<bsp:bee bee="<%= input %>" />
<%
endloop.
%>
</phtmlb:matrix>
<htmlb:button id="Test" onClick="Test" text="Submit"/>
</htmlb:form>
</htmlb:page>
The key to making this work are custom getter/setters. In your model class, you can copy from the template methods (Like GETM_S_XYZ for the metadata structure method). Copy them and remove the _ on the front of the name. Then change XYZ to the name of the attribute you are binding for. The following are my custom methods.
method get_m_s_itab .
* uses ****************************************************************
* data ****************************************************************
* code ****************************************************************
* method is supposed to return either info about a specific component
* of a structure (component is not initial -> return ref to
* if_bsp_metadata_simple) or the complete structure
* (component is initial -> return ref to if_bsp_metadata_struct)
data: l_attribute_ref type ref to data,
l_attr_ref type ref to data,
l_exception type ref to cx_root,
l_ex type ref to cx_sy_conversion_error,
l_ex_bsp type ref to cx_bsp_conversion_exception,
l_ex2 type ref to cx_bsp_t100_exception,
l_type type i,
l_index type i,
l_name type string,
l_component type string,
l_getter type string.
data: l_field_ref type ref to data,
l_dfies_wa type dfies,
rtti type ref to cl_abap_elemdescr.
data: crap type string,
rest type string,
t_index(10) type c.
split attribute_path at '[' into crap rest.
split rest at ']' into t_index crap.
****Dummy Object to avoid dumps
create object metadata type cl_bsp_metadata_simple
exporting info = l_dfies_wa.
call method if_bsp_model_util~disassemble_path
exporting
path = attribute_path
importing
name = l_name
index = l_index
component = l_component
type = l_type.
data: l_dataref type string.
****Dynamically determine your actual structure - for this demo
****I just hardcode SFLIGHT
concatenate 'SFLIGHT-' l_component into l_dataref.
data: field type ref to data.
****Create a data object of the specified type
try.
create data field type (l_dataref).
catch cx_sy_create_data_error.
exit.
endtry.
rtti ?= cl_abap_typedescr=>describe_by_data_ref( field ).
l_dfies_wa = rtti->get_ddic_field( ).
clear metadata.
create object metadata type cl_bsp_metadata_simple
exporting info = l_dfies_wa.
endmethod.
method get_s_itab .
* uses ****************************************************************
* data ****************************************************************
* code ****************************************************************
* get the given value of the component of the struct, e.g.
* field-symbols: <l_comp> type any.
* assign component component of structure XYZ to <l_comp>.
* value = <l_comp>.
data: l_attr_ref type ref to data,
l_field_ref type ref to data.
data: l_attribute_ref type ref to data,
l_exception type ref to cx_root,
l_ex type ref to cx_sy_conversion_error,
l_ex2 type ref to cx_bsp_t100_exception,
l_type type i,
l_index type i,
l_name type string,
l_component type string,
l_getter type string,
rtti type ref to cl_abap_elemdescr.
field-symbols: <o_data> type any,
<n_data> type any.
*Test
call method if_bsp_model_util~disassemble_path
exporting
path = attribute_path
importing
name = l_name
index = l_index
component = l_component
type = l_type.
* get a field reference for the assignment
field-symbols: <wa> type any,
<l_comp> type any.
assign me->itab->* to <wa>.
assign component l_component of structure <wa> to <l_comp>.
get reference of <l_comp> into l_field_ref.
****Dynamically determine your actual structure - for this demo
****I just hardcode SFLIGHT
data: l_dataref type string.
concatenate 'SFLIGHT-' l_component into l_dataref.
data: field type ref to data.
****Create a data object of the specified type
try.
create data field type (l_dataref).
catch cx_sy_create_data_error.
exit.
endtry.
assign l_field_ref->* to <o_data>.
assign field->* to <n_data>.
move <o_data> to <n_data>.
* call conversion routine
try.
value = if_bsp_model_util~convert_to_string(
data_ref = field
attribute_path = attribute_path
no_conversion_exit = 0 ).
catch cx_sy_conversion_error into l_ex.
me->errors->add_message_from_exception(
condition = attribute_path
exception = l_ex
dummy = value ).
catch cx_bsp_t100_exception into l_ex2.
me->errors->add_message_from_t100(
condition = attribute_path
msgid = l_ex2->msgid
msgno = l_ex2->msgno
msgty = l_ex2->msgty
p1 = l_ex2->msgv1
p2 = l_ex2->msgv2
p3 = l_ex2->msgv3
p4 = l_ex2->msgv4
dummy = value ).
endtry.
endmethod.
method set_s_itab .
* uses ****************************************************************
* data ****************************************************************
* code ****************************************************************
* assign the given value to the component of the struct, e.g.
* field-symbols: <l_comp> type any.
* assign component component of structure XYZ to <l_comp>.
* <l_comp> = value.
data: l_attr_ref type ref to data,
l_field_ref type ref to data.
data: l_attribute_ref type ref to data,
l_exception type ref to cx_root,
l_ex type ref to cx_sy_conversion_error,
l_ex_bsp type ref to cx_bsp_conversion_exception,
l_ex2 type ref to cx_bsp_t100_exception,
l_type type i,
l_index type i,
l_name type string,
l_component type string,
l_getter type string,
rtti type ref to cl_abap_elemdescr.
field-symbols: <o_data> type any,
<n_data> type any.
*Test
call method if_bsp_model_util~disassemble_path
exporting
path = attribute_path
importing
name = l_name
index = l_index
component = l_component
type = l_type.
* get a field reference for the assignment
field-symbols: <wa> type any,
<l_comp> type any.
assign me->itab->* to <wa>.
assign component l_component of structure <wa> to <l_comp>.
get reference of <l_comp> into l_field_ref.
****Dynamically determine your actual structure - for this demo
****I just hardcode SFLIGHT
data: l_dataref type string.
concatenate 'SFLIGHT-' l_component into l_dataref.
data: field type ref to data.
****Create a data object of the specified type
try.
create data field type (l_dataref).
catch cx_sy_create_data_error.
exit.
endtry.
assign field->* to <n_data>.
move <l_comp> to <n_data>.
* call conversion routine
try.
if_bsp_model_util~convert_from_string(
data_ref = field
value = value
attribute_path = attribute_path
use_bsp_exceptions = abap_true
no_conversion_exit = 0 ).
catch cx_sy_conversion_error into l_ex.
me->errors->add_message_from_exception(
condition = attribute_path
exception = l_ex
dummy = value ).
catch cx_bsp_conversion_exception into l_ex_bsp.
me->errors->add_message_from_exception(
condition = attribute_path
exception = l_ex_bsp
dummy = value ).
catch cx_bsp_t100_exception into l_ex2.
me->errors->add_message_from_t100(
condition = attribute_path
msgid = l_ex2->msgid
msgno = l_ex2->msgno
msgty = l_ex2->msgty
p1 = l_ex2->msgv1
p2 = l_ex2->msgv2
p3 = l_ex2->msgv3
p4 = l_ex2->msgv4
dummy = value ).
endtry.
if <n_data> is initial.
clear <l_comp>.
else.
move <n_data> to <l_comp>.
endif.
endmethod.
I know that is a LOT of nasty code without too much explanation. I'm afriad there isn't time right now to expand on how it works too much. Between my day job and trying to finish the BSP book, there just isn't much time left. Like I said before there is a very large section in the book on this topic that hopefully explains it. The book will be out in December or early January - but perhaps I will get some time before then to write up something on SDN about this. -
Appending values to dynamically created fieldsymbol
Hi ,
I have a requirement to append values to dynamically created fieldsymbols
from internal table .
I am using the following code but it dosnt work
<F4> declared as line of <dyn_table>.
loop at it_tab into wa_tab .( this contain the data to be appended to dyn fieldsymbol)
loop at it_fieldcat into wa_fieldcat. ( this contains the fieldnames )
case wa_final_fieldcat-FIELDNAME.
when 'AAA'.
v_field_name = 'AAA.
when 'BBB'.
v_field_name = 'BBB'.
endcase.
ASSIGN COMPONENT v_field_name of STRUCTURE wa_tab to <F4>.
endloop.
append <f4> to <dyn_table>
********************************************8
But only get one value i.e field BBB value appended to
<dyn_table>.
is there any way i can do the append to field symbol looping through internal
table ?
thanks
raji done it in alv so take the part you need .
1) to create dynamic table : CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
also create dynamic fieldcatalog .
2) you can pull data just one time from the DB to dynamic table
so i take the data in regulare it table and in the and i put it
in the dynamic table
hope i help , if you didnt understand some part , say so .
DATA : LT_FCAT TYPE LVC_T_FCAT ,
lo_struct TYPE REF TO data,
LV_STRUC_NAME TYPE TABNAME VALUE 'YMM_ST_TNUOT_MLY'.
REFRESH ls_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = LV_STRUC_NAME
I_BYPASSING_BUFFER = 'X'
CHANGING
CT_FIELDCAT = IT_COLUM_HEADER
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE e402(mo) WITH lv_struc_name.
EXIT.
ENDIF.
DATA INDX(3) .
IF G_COUNETR_NUMBER_OF_KOSTL > 0 .
DO G_COUNETR_NUMBER_OF_KOSTL TIMES.
INDX = SY-INDEX.
SHIFT INDX LEFT DELETING LEADING SPACE.
CONCATENATE 'KOSTL' INDX INTO LS_FCAT-FIELDNAME.
LS_FCAT-INTTYPE = 'I'.
LS_FCAT-COL_POS = 27 + SY-INDEX .
CONCATENATE TEXT-028 INDX INTO LS_FCAT-COLTEXT.
LS_FCAT-OUTPUTLEN = 10.
APPEND LS_FCAT TO IT_COLUM_HEADER.
ENDDO.
ENDIF.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_COLUM_HEADER
IMPORTING
EP_TABLE = GT_TABLE
EXCEPTIONS
GENERATE_SUBPOOL_DIR_FULL = 1
OTHERS = 2.
ASSIGN GT_TABLE->* TO <DYN_TABLE>.
*--> Arbeitsbereich dynamisch erzeugen
CREATE DATA LO_STRUCT LIKE LINE OF <DYN_TABLE>.
ASSIGN LO_STRUCT->* TO <WA>.
LOOP AT IT_COLUM_HEADER INTO LS_FCAT.
IF LS_FCAT-FIELDNAME NE 'MANDT'.
ADD 1 TO LS_FCAT-COL_POS.
PERFORM TRANSLATE_HEADER.
MODIFY IT_COLUM_HEADER FROM LS_FCAT.
ENDIF.
ENDLOOP.
============= assigning to dynamic table
DATA : FIELD(10) ,
INDX1(3) .
DATA: WA_DREF TYPE REF TO DATA.
DATA : FS_SUM_GL LIKE LINE OF IT_YMM_ST_TNUOT_MLY.
CREATE DATA LP_DATA LIKE LINE OF <DYN_TABLE>.
ASSIGN LP_DATA->* TO <LS_LINE>.
LOOP AT IT_YMM_ST_TNUOT_MLY.
MOVE-CORRESPONDING IT_YMM_ST_TNUOT_MLY TO <LS_LINE>.
INSERT <LS_LINE> INTO TABLE <DYN_TABLE>.
ENDLOOP .
DATA L_COUNTER_ROLL TYPE I .
LOOP AT <DYN_TABLE> INTO <LS_LINE> .
MOVE-CORRESPONDING <LS_LINE> TO FS_SUM_GL.
CLEAR : FIELD , INDX1 , L_COUNTER_ROLL .
L_COUNTER_ROLL = 1 .
LOOP AT IT_EKKN WHERE EBELN = FS_SUM_GL-EBELN.
AND EBELP = FS_SUM_GL-EBELP.
IF SY-SUBRC = 0 .
INDX1 = L_COUNTER_ROLL.
SHIFT INDX1 LEFT DELETING LEADING SPACE.
CONCATENATE 'KOSTL' INDX1 INTO FIELD .
ASSIGN COMPONENT FIELD OF STRUCTURE <LS_LINE> TO <FS1>.
<FS1> = IT_EKKN-KOSTL .
MODIFY <DYN_TABLE> INDEX SY-TABIX FROM <LS_LINE> .
L_COUNTER_ROLL = L_COUNTER_ROLL + 1 .
ENDIF.
ENDLOOP .
ENDLOOP . -
Hi,
is it possible to create dynamically a type ? I take a look on class CL_ABAP_TYPEDESCR but i can't create a new type, so is there a solution ?
CheersWith all due respect to all, I think he means to create dynamic data types by means of RTTS.
@ ToraTora
Like this
"example table
DATA: BEGIN OF it OCCURS 3,
pernr TYPE persno,
kostl TYPE kostl,
endda TYPE endda,
END OF it.
"data references
DATA: r_type_struct TYPE REF TO cl_abap_structdescr,
r_type_table TYPE REF TO cl_abap_tabledescr,
r_data_tab TYPE REF TO data,
r_data_str TYPE REF TO data.
" 1. ------------- filling example table IT
it-pernr = '12345678'.
it-kostl = '0112345678'.
it-endda = sy-datum.
APPEND it.
it-pernr = '45678909'.
it-kostl = '3452345678'.
it-endda = sy-datum - 1.
APPEND it.
" 2. ------------ components structure type
gs_comp-name = 'PERNR'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'PERSNO' ).
APPEND gs_comp TO gt_comp.
gs_comp-name = 'KOSTL'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'KOSTL' ).
APPEND gs_comp TO gt_comp.
gs_comp-name = 'BEGDA'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'BEGDA' ).
APPEND gs_comp TO gt_comp.
" 3. ------------- create structure type
TRY.
r_type_struct = cl_abap_structdescr=>create(
p_components = gt_comp ).
CATCH cx_sy_struct_creation .
ENDTRY.
" 4. ------------- create table type
TRY.
r_type_table = cl_abap_tabledescr=>create( r_type_struct ).
CATCH cx_sy_table_creation .
ENDTRY.
" 5. -------------- create table based on RTTS types
CREATE DATA: r_data_tab TYPE HANDLE r_type_table,
r_data_str TYPE HANDLE r_type_struct.
FIELD-SYMBOLS: <fs_table> TYPE INDEX TABLE,
<fs_wa> TYPE ANY.
ASSIGN: r_data_tab->* TO <fs_table>,
r_data_str->* TO <fs_wa>.
You can also create any component you want without knowledge about data element it is refering to (without using methods describe_by_name or describe_by_data ).
So the 2nd step could be replaced with
gs_comp-name = 'PERNR'.
gs_comp-type ?= cl_abap_datadescr=>get_n( 8 ). "PERNR if of type N(8)
APPEND gs_comp TO gt_comp.
gs_comp-name = 'KOSTL'.
gs_comp-type ?= cl_abap_elemdescr=>get_c( 10 ). "C(10)
APPEND gs_comp TO gt_comp.
gs_comp-name = 'BEGDA'.
gs_comp-type ?= cl_abap_elemdescr=>get_d( ). "D
APPEND gs_comp TO gt_comp.
Regards
Marcin
Maybe you are looking for
-
C5180 will not scan to file. only options are scan and reprint or scan to memory card. this just started a week ago. tried everything listed on hp troubleshooting. Running vista home 64 bit. i have uninstalled and reinstalled driver at least 3 times,
-
Hi there, I am quite new at Dreamweaver and would like to know if and how it is possible to use an image as a background which fits all monitors. There are a few examples to be found on the internet where this is done.( www.wetransfer.com) Whenever y
-
SRM/External catalog in ECC Web Dynpro for ABAP
Hi SRM experts! Currently I'm developing new WB4A application in ECC and I faced one problem. Functionality will be let say light version of IW31 and same as in ERP transaction I would like to call catalog (external or SRM) and pass back selected mat
-
I'm trying configure a mapping in the obj.conf file on Iplanet. This is what I want, https://www.mywebserver.com/myportal --> https://weblogic:7001/myportal From the edocs, I've only been able to do the following, https://www.mywebserver.com/myportal
-
Grey CC Icon with Spinning wheel won't open
The CC icon on my taskbar won't open and if I hover my mouse over it there is just the rainbow wheel of death. I can't use the updater or uninstaller because it says that CC is still running and asks me to close it (which I can't do either). What d